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; /** *
  • @ClassName: SyncTableJob *
  • @Description: 同步任务执行器,获取SYNC_DATA_BASIC表格的数据进行推送到中心 *
  • @author 方承 *
  • @date 2017年5月5日 *
  • */ public class SyncPushToCenterJob { @Value("${center.syncpush.url}") private String CENTER_SYNCPUSH_URL; @Value("${isNodePushToCenter}") private boolean isNodePushToCenter; 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") && isNodePushToCenter){ List dataList = syncDataBasicService.selectList(new EntityWrapper().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); } } } } } }