package com.fzzy.async.fzzy40.impl;
|
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.entity.Api1105;
|
import com.fzzy.api.entity.Api1303;
|
import com.fzzy.api.entity.ApiLog;
|
import com.fzzy.api.service.ApiCommonService;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.view.repository.Api1303Rep;
|
import com.fzzy.api.view.repository.ApiLogRep;
|
import com.fzzy.async.fzzy40.entity.Fz40Pest;
|
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1303Rep;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang.StringUtils;
|
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 Fzzy40Sync1303 {
|
|
|
@Autowired
|
private Fzzy40Sync1303Rep fzzy40Sync1303Rep;
|
@Autowired
|
private ApiCommonService commonService;
|
@Autowired
|
private Api1303Rep api1303Rep;
|
@Autowired
|
private ApiLogRep apiLogRep;
|
|
/**
|
* 同步并封装保存虫害检测数据
|
*
|
* @param deptId 系统对应库区编码
|
* @param start 起始时间
|
* @param end 截止时间
|
*/
|
public void syncData(String kqdm, String deptId, Date start, Date end) {
|
|
log.info("-------------1303接口数据开始同步------------------");
|
|
//同步数据,只记录失败的信息
|
ApiLog apiLog = new ApiLog();
|
apiLog.setType(ApiLog.TYPE_SYNC);
|
apiLog.setKqdm(deptId);
|
apiLog.setUploadTime(new Date());
|
apiLog.setInteId(Constant.API_CODE_1303);
|
apiLog.setStatus(99);
|
apiLog.setId(ContextUtil.getUUID());
|
try {
|
|
List<Fz40Pest> list = fzzy40Sync1303Rep.findPestByReceiveDate(start, end);
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
Date syncTime = new Date();
|
Api1303 api1303;
|
Api1105 api1105;
|
List<Api1303> api1303List;
|
for (Fz40Pest fz40Pest : list) {
|
//获取货位信息
|
api1105 = commonService.getApi1105Cache(fz40Pest.getDepotId());
|
if (null == api1105) {
|
continue;
|
}
|
|
api1303 = new Api1303();
|
api1303.setHcjcdh(api1105.getHwdm() + fz40Pest.getBatchId());
|
api1303.setJcsj(fz40Pest.getReceiveDate());
|
api1303.setHwdm(api1105.getHwdm());
|
|
//检查害虫方法,0-远程、1-人工、2-其他
|
api1303.setJchcff("0");
|
//发生部位,坐标填写:x,y,z
|
api1303.setFsbw(null);//非必填字段
|
|
//害虫种类。多个用#隔开#TODO >> 待优化调整
|
api1303.setHczl("21212");
|
|
//虫口密度值集合
|
if(StringUtils.isEmpty(fz40Pest.getPoints())){
|
continue;
|
}
|
String ckmdzjh = this.geeCkmdzjh(fz40Pest.getPestMax(), fz40Pest.getPoints());
|
api1303.setCkmdzjh(ckmdzjh);
|
|
//虫粮等级判定,531-基本无虫粮、532-一般虫粮、533严重虫粮、534危害虫粮
|
api1303.setCldjpd("531");
|
if (fz40Pest.getPestMax() > 5) {
|
api1303.setCldjpd("532");
|
}
|
if (fz40Pest.getPestMax() > 30) {
|
api1303.setCldjpd("533");
|
}
|
|
api1303.setZhgxsj(syncTime);
|
|
api1303.setBizId(fz40Pest.getBatchId());
|
api1303.setKqdm(api1105.getKqdm());
|
api1303.setSyncTime(syncTime);
|
api1303List = api1303Rep.getDataByHcjcdh(api1303.getHcjcdh());
|
if (null == api1303List || api1303List.isEmpty()) {
|
api1303.setCzbz(Constant.CZBZ_I);
|
} else {
|
api1303.setCzbz(api1303List.get(0).getCzbz());
|
}
|
api1303Rep.save(api1303);
|
}
|
|
} catch (Exception e) {
|
log.error("---同步失败----{}", e);
|
apiLog.setResult("同步失败:" + e.getMessage());
|
apiLogRep.save(apiLog);
|
}
|
|
}
|
|
/**
|
* 头/kg,指粮食害虫值集合,与
|
* 害虫种类顺序对应,用“|”分
|
* 隔,多个取样点用英文半角“,”
|
* 分隔,按照取样点示意图标识顺
|
* 序排列。
|
*
|
* @param pestMax
|
* @param points
|
* @return
|
*/
|
private String geeCkmdzjh(int pestMax, String points) {
|
|
if (StringUtils.isEmpty(points)) return "0";
|
|
String[] attr = points.split(";");
|
|
String result = "";
|
for (String str : attr) {
|
result += str.split(",")[1] + ",";
|
}
|
return result.substring(0, result.length() - 1);
|
}
|
|
|
}
|