|
|
@@ -57,7 +57,7 @@ public class IcCardService {
|
|
|
+ "from XF_AccTransDetail_push left join XF_AccHead on XF_AccTransDetail_push.AccNo=XF_AccHead.AccNo left join Tx_EmpCard on Tx_EmpCard.CardID=XF_AccHead.CardID "
|
|
|
+ "left join RS_EMP ON RS_EMP.EmpSysID=XF_AccHead.EmpSysID where XF_AccTransDetail_push.SendStatus=? order by AccTransDay desc";
|
|
|
|
|
|
- private static final String updateSql = "update XF_AccTransDetail_push set SendStatus = ? where GUID in (?)";
|
|
|
+ private static final String updateSql = "update XF_AccTransDetail_push set SendStatus = ? where GUID in (";
|
|
|
|
|
|
public IcCard find() {
|
|
|
return icCardRepository.find();
|
|
|
@@ -82,39 +82,41 @@ public class IcCardService {
|
|
|
if (null != card && dynamicDataSourceRegister.contains(card) && null != school) {
|
|
|
DynamicDataSourceContextHolder.set(card);
|
|
|
try {
|
|
|
- doTask();
|
|
|
+ doTask(school.getName());
|
|
|
} finally {
|
|
|
DynamicDataSourceContextHolder.clear();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void doTask(){
|
|
|
+ private void doTask(String schoolName){
|
|
|
//1.准备本次需要传输的数据->转移至中间表
|
|
|
jdbcTemplate.execute(insertSql);
|
|
|
//2.获取本次传输的数据
|
|
|
List<AccTransDetail> resultList = jdbcTemplate.query(getDataSql, new BeanPropertyRowMapper<>(AccTransDetail.class), "待上传");
|
|
|
- //3.传输
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
- MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
|
|
|
- requestEntity.add("data", JSON.toJSONString(resultList));
|
|
|
- requestEntity.add("school", schoolService.find().getName());
|
|
|
- HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(requestEntity, headers);
|
|
|
- ResponseEntity<Result> response = restTemplate.postForEntity(targetURL, resultList, Result.class);
|
|
|
- if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
- Result<String> result = response.getBody();
|
|
|
- if (!result.isSuccess()) {
|
|
|
- ExceptionCode.ERROR_UNKNOWN.occur(result.getMessage());
|
|
|
- }else {
|
|
|
- //更新发送的数据
|
|
|
- String ids = result.getData();
|
|
|
- if (!StringUtils.isEmpty(ids)){
|
|
|
- jdbcTemplate.update(updateSql, "已上传", ids);
|
|
|
+ if (resultList.size() > 0) {
|
|
|
+ //3.传输
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+ MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
|
|
|
+ requestEntity.add("data", JSON.toJSONString(resultList));
|
|
|
+ requestEntity.add("school", schoolName);
|
|
|
+ HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(requestEntity, headers);
|
|
|
+ ResponseEntity<Result> response = restTemplate.postForEntity(targetURL, httpEntity, Result.class);
|
|
|
+ if (response.getStatusCode() == HttpStatus.OK) {
|
|
|
+ Result<String> result = response.getBody();
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ ExceptionCode.ERROR_UNKNOWN.occur(result.getMessage());
|
|
|
+ } else {
|
|
|
+ //更新发送的数据
|
|
|
+ String ids = result.getData();
|
|
|
+ if (!StringUtils.isEmpty(ids)) {
|
|
|
+ jdbcTemplate.update(updateSql + ids + ")", "已上传");
|
|
|
+ }
|
|
|
}
|
|
|
+ } else {
|
|
|
+ ExceptionCode.ERROR_UNKNOWN.occur("IC卡消费记录发送失败");
|
|
|
}
|
|
|
- } else {
|
|
|
- ExceptionCode.ERROR_UNKNOWN.occur("IC卡消费记录发送失败");
|
|
|
}
|
|
|
}
|
|
|
}
|