SyncPushToCenterJob.java 2.71 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
package com.lyms.hospital.job;

import java.util.List;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.lyms.base.common.entity.sys.SyncDataBasic;
import com.lyms.base.common.service.sys.SyncDataBasicService;
import com.lyms.sync.channel.ChannelData;
import com.lyms.util.HttpUtils;
import com.lyms.util.JsonUtils;

/**
* <li>@ClassName: SyncTableJob
* <li>@Description: 同步任务执行器,获取SYNC_DATA_BASIC表格的数据进行推送到中心
* <li>@author 方承
* <li>@date 2017年5月5日
* <li>
*/
public class SyncPushToCenterJob {
@Value("${center.syncpush.url}")
private String CENTER_SYNCPUSH_URL;
private static final int ERROR_COUNT_MAX = 4;
private static Logger log = LoggerFactory.getLogger(SyncPushToCenterJob.class);

@Autowired
private SyncDataBasicService syncDataBasicService;
public void excute() {
if(null != CENTER_SYNCPUSH_URL && CENTER_SYNCPUSH_URL.startsWith("http")){
List<SyncDataBasic> dataList = syncDataBasicService.selectList(new EntityWrapper<SyncDataBasic>().where("IFSUC=0").and("ERROR_COUNT < {0}", ERROR_COUNT_MAX));
if(dataList != null && dataList.size() > 0){
log.debug("=======开始进行 SYNC_DATA_BASIC 表格数据的推送到中心=======");
for(SyncDataBasic entity : dataList){
try{
ChannelData data = JsonUtils.jsonToBean(entity.getData(), ChannelData.class);
data.setRemote(CENTER_SYNCPUSH_URL);
log.debug("节点推送数据:"+ToStringBuilder.reflectionToString(data));
String result = HttpUtils.REMOTE.post(data);
if(result == null){//远程无法访问等情况
syncDataBasicService.errorCountAdd(entity.getId());
return;
}
ChannelData model = JsonUtils.jsonToBean(result, ChannelData.class);
if(model.isSuccess()){
entity.setIfsuc(1);
syncDataBasicService.updateById(entity);
}
}catch (Exception e) {
syncDataBasicService.errorCountAdd(entity.getId());
log.error("【SYNC_DATA_BASIC】表格数据的的推送到中心错误:SyncDataBasic = {} {}",JSONObject.toJSON(entity),e);
}
}
}
}
}
}