package com.ld.igds.timer.zcl;
|
|
import com.alibaba.fastjson.JSON;
|
import com.ld.igds.common.impl.CommonDataServiceImpl;
|
import com.ld.igds.grain.dto.GrainData;
|
import com.ld.igds.grain.dto.GrainParam;
|
import com.ld.igds.grain.service.CoreGrainService;
|
import com.ld.igds.models.Depot;
|
import com.ld.igds.timer.zcl.dto.InteGrainDto;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.Map;
|
|
/**
|
* @author: vince
|
* @version:
|
* @data:2019年12月7日
|
*/
|
@Slf4j
|
@Component
|
public class InteGrainScheduled {
|
|
public static String COMPANY_IDS = "4003,5307,5311,5315,5332";
|
|
@Autowired
|
private CoreGrainService grainService;
|
@Autowired
|
private CommonDataServiceImpl commonDataService;
|
@Autowired
|
private InteGrainManager inteGrainManager;
|
|
/**
|
* 每天9点和22点执行执行
|
*/
|
@Scheduled(cron = "0 0 9,22 * * ?")
|
public void scheduled() {
|
log.info("系统定时将粮情存入中储粮的数据表中……");
|
try {
|
Date time = new Date();
|
step0(time);
|
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 获取需要上传中储粮的组织编码
|
*
|
* @param time
|
* @throws Exception
|
*/
|
private void step0(Date time) throws Exception {
|
String[] companyIds = COMPANY_IDS.split(",");
|
if (companyIds.length < 1) {
|
log.info("暂无组织需要将粮情存入中储粮的数据表……");
|
return;
|
}
|
|
log.info("=====开始推送组织-({})粮情到中储粮需要的表中=====", Arrays.toString(companyIds));
|
for (String companyId : companyIds) {
|
step1(time, companyId);
|
}
|
|
}
|
|
private void step1(Date time, String companyId) throws Exception {
|
InteGrainDto inteGrainDto = null;
|
Map<String, GrainData> grainMap = null;
|
GrainParam param = new GrainParam();
|
GrainData grain = null;
|
Depot depot = null;
|
param.setCompanyId(companyId);
|
param.setCheckDate(time);
|
grainMap = grainService.queryCheckDateMap(param);
|
if (grainMap == null) {
|
log.info("==========没有获取到组织={}的粮情数据取消推送==========", companyId);
|
return;
|
}
|
log.info("grainMap=" + grainMap.toString());
|
for (String depotId : grainMap.keySet()) {
|
grain = grainMap.get(depotId);
|
if (grain == null) {
|
continue;
|
}
|
depot = commonDataService.getCacheDepot(grain.getCompanyId(), depotId);
|
log.debug("grain=" + grain.toString());
|
log.info("depot=" + depot.toString());
|
log.info(JSON.toJSONString(grain));
|
inteGrainDto = new InteGrainDto();
|
inteGrainDto.setCompanyId(depot.getCompanyId());
|
inteGrainDto.setDepotId(depot.getId());
|
inteGrainDto.setDepotName(depot.getName());
|
inteGrainDto.setBatchId(grain.getBatchId());
|
inteGrainDto.setUuid(grain.getCompanyId() + grain.getDepotId() + grain.getBatchId());
|
inteGrainDto.setHumidityIn(grain.getHumidityIn());
|
inteGrainDto.setHumidityOut(grain.getHumidityOut());
|
inteGrainDto.setTempIn(grain.getTempIn());
|
inteGrainDto.setTempOut(grain.getTempOut());
|
inteGrainDto.setReceiveDate(grain.getReceiveDate());
|
inteGrainDto.setTempList(grain.getPoints());
|
|
inteGrainDto.setCheckUser(grain.getCheckUser());
|
inteGrainDto.setCable(grain.getCable());
|
inteGrainDto.setCableCir(grain.getCableCir());
|
inteGrainDto.setWeather(grain.getWeather());
|
inteGrainDto.setRemark(grain.getRemark());
|
|
log.debug("grainTempList=" + inteGrainDto.toString());
|
|
|
inteGrainManager.toSaveGrain(inteGrainDto);
|
}
|
|
log.info("==========定时推送组织={}的粮情到中储粮的表中 推送完成!==========", companyId);
|
}
|
|
}
|