package com.ld.igds.sh.timer;
|
|
import com.ld.igds.models.*;
|
import com.ld.igds.sh.service.impl.HApiShServiceImpl;
|
import com.ld.igds.util.ContextUtil;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang3.time.DateFormatUtils;
|
import org.apache.commons.lang3.time.DateUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 定时保存稻谷出入库信息到接口表中
|
* @author chen
|
*
|
*/
|
@Slf4j
|
@Component(ShScheduled.BEAN_ID)
|
public class ShScheduled {
|
|
public static final String BEAN_ID = "sh.shScheduled";
|
|
@Autowired
|
private HApiShServiceImpl hApiShService;
|
|
|
/**
|
* 每天23:30执行一次
|
*/
|
@Scheduled(cron = "0 30 23 * * ?")
|
public void scheduled() {
|
log.info("==========系统定时获取稻谷入库信息==========");
|
Date endTime = new Date();
|
Date startTime = DateUtils.addDays(endTime, -1);
|
// doExe(ContextUtil.getDefaultCompanyId(), startTime, endTime);
|
}
|
|
|
public void doExe(String companyId, Date startTime, Date endTime) {
|
|
List<InoutRecord> inList = hApiShService.listInoutRecordByDay(companyId, startTime, endTime, null, "113");
|
log.info("==========系统定时获取稻谷入库信息==========");
|
if(null == inList || inList.isEmpty()){
|
log.warn("==========系统未获取到当前时间段内稻谷出入库数据==========");
|
return;
|
}
|
for (InoutRecord inoutRecord : inList) {
|
if("IN".equals(inoutRecord.getType())){
|
saveToLsRkjlD(inoutRecord);
|
}
|
if("OUT".equals(inoutRecord.getType())){
|
saveToLsCcsslD(inoutRecord);
|
}
|
}
|
}
|
|
/**
|
* 稻谷入库记录
|
* @param data
|
*/
|
public void saveToLsRkjlD(InoutRecord data){
|
ToLsRkjlD dto = new ToLsRkjlD();
|
dto.setNf(data.getFoodYear());
|
dto.setRq(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
|
dto.setFcqkCch(data.getPlateNum());
|
dto.setFcqkLldw(data.getCustomerName());
|
dto.setFcqkLssl(data.getSettleWeight());
|
dto.setJsqkRksl(data.getSettleWeight());
|
//dto.setJsqkKszs(data.getDeSum()); TODO
|
|
List<CheckItem> checkItems = hApiShService.listInoutChecks(data.getCompanyId(), data.getCheckId());
|
if(null != checkItems && checkItems.size() > 0){
|
for (CheckItem checkItem : checkItems) {
|
//杂质
|
if("C01".equals(checkItem.getStandardId())){
|
dto.setJsqkZlSf(Double.valueOf(checkItem.getValue()));
|
}
|
//杂质
|
if("C02".equals(checkItem.getStandardId())){
|
dto.setJsqkZlZz(Double.valueOf(checkItem.getValue()));
|
}
|
//出糙
|
if("C09".equals(checkItem.getStandardId())){
|
dto.setJsqkZlCc(Double.valueOf(checkItem.getValue()));
|
}
|
//谷外糙米
|
if("C12".equals(checkItem.getStandardId())){
|
dto.setJsqkZlGwcm(Double.valueOf(checkItem.getValue()));
|
}
|
//含黄
|
if("C99".equals(checkItem.getStandardId())){
|
dto.setJsqkZlHh(Double.valueOf(checkItem.getValue()));
|
}
|
}
|
}
|
|
dto.setDataDate(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
|
dto.setUpdateTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
hApiShService.saveToLsRkjlD(dto);
|
log.info("==========系统定时保存稻谷入库信息到接口表中={}==========", dto);
|
}
|
|
public void saveToLsCcsslD(InoutRecord data){
|
|
ToLsCcsslD dto = new ToLsCcsslD();
|
|
dto.setNf(data.getFoodYear());
|
dto.setRq(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
|
dto.setChh(data.getPlateNum());
|
dto.setThdw(data.getCustomerName());
|
dto.setThc(data.getDepotId());
|
dto.setFcsl(data.getSettleWeight());
|
// dto.setJcs(data.getCurStorage() - data.getSettleWeight()); TODO
|
|
dto.setDataDate(DateFormatUtils.format(data.getCompleteTime(), "yyyy-MM-dd"));
|
dto.setUpdateTime(DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
|
|
hApiShService.saveToLsCcsslD(dto);
|
log.info("==========系统定时保存稻谷出库信息到接口表中={}==========", dto);
|
}
|
|
}
|