package com.fzzy.async.fzzy40.impl;
|
|
import com.fzzy.api.Constant;
|
import com.fzzy.api.entity.*;
|
import com.fzzy.api.service.ApiTriggerService;
|
import com.fzzy.api.utils.ContextUtil;
|
import com.fzzy.api.utils.DateUtil;
|
import com.fzzy.api.view.repository.Api1202Rep;
|
import com.fzzy.api.view.repository.Api1203Rep;
|
import com.fzzy.api.view.repository.ApiLogRep;
|
import com.fzzy.api.view.repository.GbCheckItemRep;
|
import com.fzzy.async.fzzy40.entity.Fz40CheckItem;
|
import com.fzzy.async.fzzy40.entity.Fz40InoutRecord;
|
import com.fzzy.async.fzzy40.entity.Fz40InoutRecordItem;
|
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1202Rep;
|
import com.fzzy.async.fzzy40.repository.Fzzy40Sync1203Rep;
|
import com.fzzy.async.fzzy40.repository.Fzzy40SyncInoutRecordItemRep;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.apache.commons.lang.time.DateUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
/**
|
* 粮食入库检验信息
|
*/
|
@Slf4j
|
@Component
|
public class Fzzy40Sync1203 {
|
|
/**
|
* 入库类型
|
*/
|
private final static String INOUT_TYPE_IN = "IN";
|
|
@Autowired
|
private Fzzy40Sync1202Rep fzzySync1202Rep;
|
@Autowired
|
private Fzzy40SyncInoutRecordItemRep fzzy40SyncInoutRecordItemRep;
|
@Autowired
|
private Fzzy40Sync1203Rep fzzySync1203Rep;
|
@Autowired
|
private ApiTriggerService apiTriggerService;
|
@Autowired
|
private Api1202Rep api1202Rep;
|
@Autowired
|
private Api1203Rep api1203Rep;
|
@Autowired
|
private GbCheckItemRep gbCheckItemRep;
|
@Autowired
|
private ApiLogRep apiLogRep;
|
|
/**
|
* 粮食入库检验信息
|
*
|
* @param deptId
|
* @param start
|
* @param end
|
*/
|
public void syncData(String kqdm, String deptId, Date start, Date end) {
|
|
log.info("-------------1203接口数据开始同步------------------");
|
|
//同步数据,只记录失败的信息
|
ApiLog apiLog = new ApiLog();
|
apiLog.setType(ApiLog.TYPE_SYNC);
|
apiLog.setKqdm(deptId);
|
apiLog.setUploadTime(new Date());
|
apiLog.setInteId(Constant.API_CODE_1203);
|
apiLog.setStatus(99);
|
apiLog.setId(ContextUtil.getUUID());
|
try {
|
//获取粮食入库记录信息
|
List<Fz40InoutRecord> list = fzzySync1202Rep.listInoutRecord(deptId, INOUT_TYPE_IN, start, end);
|
|
if (null == list || list.isEmpty()) {
|
log.info("-------------没有获取到粮食入库信息------------------");
|
return;
|
}
|
|
Api1203 apiData;
|
List<Fz40CheckItem> fz40CheckItems;
|
List<GbCheckItem> gbCheckList;
|
String jyxm;
|
String jyz;
|
String zkj;
|
String zkl;
|
List<Api1203> api1203List;
|
List<Api1202> api1102List;
|
List<Fz40InoutRecordItem> listInoutRecordItem;
|
List<String> listIds;
|
for (Fz40InoutRecord sysData : list) {
|
listIds = new ArrayList<>();
|
//判断是否为船运
|
if (StringUtils.isNotEmpty(sysData.getTransType()) && sysData.getTransType().equals("3")) {
|
listInoutRecordItem = fzzy40SyncInoutRecordItemRep.findDataByRecordId(sysData.getId());
|
if (null != listInoutRecordItem && listInoutRecordItem.size() > 0) {
|
int idNum = Integer.valueOf(sysData.getId().substring(12)) * 100 + 10001;
|
|
for (Fz40InoutRecordItem fz40InoutRecordItem : listInoutRecordItem) {
|
if ("DEL".equals(fz40InoutRecordItem.getRecordStatus())) {
|
continue;
|
}
|
listIds.add(Constant.INOUT_TYPE_14 + sysData.getId().substring(4, 10) + String.valueOf(idNum).substring(1));
|
idNum++;
|
}
|
} else {
|
listIds.add(Constant.INOUT_TYPE_14 + sysData.getId().substring(4));
|
}
|
} else {
|
listIds.add(Constant.INOUT_TYPE_14 + sysData.getId().substring(4));
|
}
|
|
//获取入库质检信息
|
fz40CheckItems = fzzySync1203Rep.listInoutCheckItem(sysData.getCheckId(), deptId.substring(0, 4));
|
if (null == fz40CheckItems || fz40CheckItems.isEmpty()) {
|
log.info("-------------没有获取到当前入库质检信息--------------");
|
continue;
|
}
|
|
for (String listId : listIds) {
|
//查询粮食入库信息,若为空则不进行同步上传
|
api1102List = api1202Rep.getDataById(listId);
|
if (null == api1102List || api1102List.isEmpty()) {
|
continue;
|
}
|
|
apiData = new Api1203();
|
|
apiData.setRkjydh(api1102List.get(0).getRkywdh());
|
//货位代码
|
apiData.setHwdm(api1102List.get(0).getHwdm());
|
apiData.setRkywdh(api1102List.get(0).getRkywdh());
|
if (null == sysData.getFullWeightTime()) {
|
sysData.setFullWeightTime(DateUtils.addMinutes(sysData.getRegisterTime(), 5));
|
}
|
|
//判断业务时间与单据号是否匹配,若不匹配,则更改业务时间为单据号所在的时间
|
String time = apiData.getRkjydh().substring(2, 8);
|
if (sysData.getCheckTime() != null) {
|
String isCheckTime = DateFormatUtils.format(sysData.getCheckTime(), "yyMMdd");
|
if (!isCheckTime.equals(time)) {
|
int difDay = DateUtil.difDay1(sysData.getRegisterTime(), sysData.getCheckTime());
|
if (difDay == 0) {
|
apiData.setRkjydh("14" + isCheckTime + "01" + api1102List.get(0).getRkywdh().substring(10));
|
} else {
|
apiData.setRkjydh("14" + isCheckTime + String.format("%02d", difDay) + api1102List.get(0).getRkywdh().substring(10));
|
}
|
}
|
}
|
|
//船运使用入库单据号做质检单号
|
if (StringUtils.isNotEmpty(sysData.getTransType()) && sysData.getTransType().equals("3")) {
|
apiData.setRkjydh(api1102List.get(0).getRkywdh());
|
}
|
|
apiData.setQyrxm(sysData.getCheckUser());
|
//扦样方式 2-智能随机
|
apiData.setQyfs("2");
|
|
//检测项,检测值,增扣价及增扣量
|
jyxm = "";
|
jyz = "";
|
zkj = "";
|
zkl = "";
|
for (Fz40CheckItem fz40CheckItem : fz40CheckItems) {
|
gbCheckList = gbCheckItemRep.findByBizCode(fz40CheckItem.getStandardId());
|
|
if (gbCheckList == null || gbCheckList.isEmpty()) {
|
continue;
|
}
|
if (StringUtils.isEmpty(fz40CheckItem.getValue())) {
|
continue;
|
}
|
jyxm += "," + gbCheckList.get(0).getCode();
|
jyz += "," + fz40CheckItem.getValue();
|
zkj += ",0.0";
|
zkl += ",0.0";
|
}
|
if (jyxm.length() > 0) {
|
jyxm = jyxm.substring(1);
|
}
|
if (jyz.length() > 0) {
|
jyz = jyz.substring(1);
|
}
|
apiData.setJyxm(jyxm);
|
apiData.setJyz(jyz);
|
apiData.setZkj(StringUtils.isEmpty(zkj) ? "" : zkj.substring(1));
|
apiData.setZkl(StringUtils.isEmpty(zkl) ? "" : zkl.substring(1));
|
if ("UNPASS".equals(sysData.getCheckStatus())) {
|
apiData.setJyjg("0");
|
} else {
|
apiData.setJyjg("1");
|
}
|
apiData.setJyrxm(sysData.getCheckUser());
|
if (null == sysData.getCheckTime()) {
|
sysData.setCheckTime(DateUtils.addMinutes(sysData.getFullWeightTime(), -5));
|
}
|
if (sysData.getCheckTime().after(sysData.getEmptyWeightTime())) {
|
sysData.setCheckTime(DateUtils.addMinutes(sysData.getFullWeightTime(), -5));
|
}
|
apiData.setJysj(sysData.getCheckTime());
|
if (null == sysData.getSampleTime()) {
|
sysData.setSampleTime(DateUtils.addMinutes(sysData.getCheckTime(), -1));
|
}
|
if (sysData.getSampleTime().after(sysData.getCheckTime())) {
|
sysData.setSampleTime(DateUtils.addMinutes(sysData.getCheckTime(), -1));
|
}
|
apiData.setQysj(sysData.getSampleTime());
|
|
//粮食品种
|
String mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSPZ, sysData.getFoodVariety());
|
apiData.setLspzdm(mappingCode);
|
|
//保管员复核
|
apiData.setBgyfh(apiData.getJyjg());
|
apiData.setSpaqzbsfhg("1");
|
|
//粮食等级
|
mappingCode = apiTriggerService.getMappingCode(Constant.TRIGGER_P_LSDJ, sysData.getFoodLevel());
|
apiData.setLsdd(mappingCode);
|
|
//操作标志及最后更新时间
|
apiData.setZhgxsj(sysData.getCompleteTime());
|
|
//业务id、库区编码、同步时间
|
apiData.setBizId(sysData.getId());
|
apiData.setKqdm(kqdm);
|
apiData.setSyncTime(new Date());
|
|
api1203List = api1203Rep.getDataById(apiData.getRkjydh());
|
if (null == api1203List || api1203List.isEmpty()) {
|
apiData.setCzbz(Constant.CZBZ_I);
|
} else {
|
apiData.setCzbz(api1203List.get(0).getCzbz());
|
}
|
|
api1203Rep.save(apiData);
|
log.info("1203---同步数据:{}", apiData.toString());
|
}
|
}
|
} catch (Exception e) {
|
log.error("---同步失败----{}", e);
|
apiLog.setResult("同步失败:" + e.getMessage());
|
apiLogRep.save(apiLog);
|
}
|
}
|
|
public static void main(String[] args) {
|
//判断业务时间与单据号是否匹配,若不匹配,则更改业务时间为单据号所在的时间
|
String id = "142508200001";
|
String time = id.substring(2, 8);
|
|
String isCheckTime = "250821";
|
if (!isCheckTime.equals(time)) {
|
int difDay = 2;
|
String idd = "14" + isCheckTime + difDay + id.substring(9);
|
System.out.println(idd);
|
}
|
|
}
|
}
|