package com.fzzy.async.fzzy40.impl;
|
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.entity.Api1105;
|
import com.fzzy.api.entity.Api1304;
|
import com.fzzy.api.entity.ApiLog;
|
import com.fzzy.api.service.ApiCommonService;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.view.repository.Api1304Rep;
|
import com.fzzy.api.view.repository.ApiLogRep;
|
import com.fzzy.async.fzzy40.entity.Fz40Gas;
|
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1304Rep;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 虫害检测数据同步
|
*
|
* @author chen
|
* @date 2022-09-08 09:51
|
*/
|
@Slf4j
|
@Component
|
public class Fzzy40Sync1304 {
|
|
@Autowired
|
private Fzzy40Sync1304Rep fzzySync1304Rep;
|
@Autowired
|
private ApiCommonService commonService;
|
@Autowired
|
private Api1304Rep api1304Rep;
|
|
@Autowired
|
private ApiLogRep apiLogRep;
|
|
/**
|
* 同步并封装保存气体检测数据
|
*
|
* @param deptId 系统对应库区编码
|
* @param start 起始时间
|
* @param end 截止时间
|
*/
|
public void syncData(String kqdm, String deptId, Date start, Date end) {
|
log.info("-------------1304接口数据开始同步------------------");
|
//同步数据,只记录失败的信息
|
ApiLog apiLog = new ApiLog();
|
apiLog.setType(ApiLog.TYPE_SYNC);
|
apiLog.setKqdm(deptId);
|
apiLog.setUploadTime(new Date());
|
apiLog.setInteId(Constant.API_CODE_1304);
|
apiLog.setStatus(99);
|
apiLog.setId(ContextUtil.getUUID());
|
try {
|
List<Fz40Gas> list = fzzySync1304Rep.findByReceiveDate(start, end);
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
Date syncTime = new Date();
|
Api1304 api1304;
|
Api1105 api1105;
|
List<Api1304> api1304List;
|
for (Fz40Gas fz40Gas : list) {
|
//获取货位信息
|
api1105 = commonService.getApi1105Cache(fz40Gas.getDepotId());
|
if (null == api1105) {
|
continue;
|
}
|
|
api1304 = new Api1304();
|
// api1304.setQtndjcdh(api1105.getHwdm() + DateFormatUtils.format(gas.getReceiveDate(), "yyyyMMdd") + String.valueOf(index).substring(1));
|
api1304.setQtndjcdh(api1105.getHwdm() + fz40Gas.getBatchId());
|
api1304.setJcsj(fz40Gas.getReceiveDate());
|
api1304.setHwdm(api1105.getHwdm());
|
|
api1304 = updateGasInfo(api1304, fz40Gas.getPoints());
|
|
api1304.setZhgxsj(syncTime);
|
|
api1304.setBizId(fz40Gas.getBatchId());
|
api1304.setKqdm(api1105.getKqdm());
|
api1304.setSyncTime(syncTime);
|
api1304List = api1304Rep.getDataByQtndjcdh(api1304.getQtndjcdh());
|
if (null == api1304List || api1304List.isEmpty()) {
|
api1304.setCzbz(Constant.CZBZ_I);
|
} else {
|
api1304.setCzbz(api1304List.get(0).getCzbz());
|
}
|
api1304Rep.save(api1304);
|
}
|
} catch (Exception e) {
|
log.error("---同步失败----{}", e);
|
apiLog.setResult("同步失败:" + e.getMessage());
|
apiLogRep.save(apiLog);
|
}
|
}
|
|
/**
|
* 获取对应气体浓度集合:passCode,co2,o2,ph3,n2;passCode,co2,o2,ph3,n2;
|
*
|
* @param points
|
* @return
|
*/
|
private Api1304 updateGasInfo(Api1304 api1304, String points) {
|
String[] attr = points.split(";");
|
|
String[] arrt2;
|
String o2 = "", co2 = "", ph3 = "";
|
for (String temp : attr) {
|
arrt2 = temp.split(",");
|
o2 += arrt2[2] + ",";
|
co2 += arrt2[1] + ",";
|
ph3 += arrt2[3] + ",";
|
}
|
|
api1304.setYqhlzjh(o2);
|
api1304.setEyhthlzjh(co2);
|
api1304.setLhqndzjh(ph3);
|
return api1304;
|
}
|
|
}
|