package com.zy.common.service.erp.task;
|
|
import com.alibaba.fastjson.JSON;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.core.common.Cools;
|
import com.zy.asrs.entity.MatCode;
|
import com.zy.asrs.entity.WaitPakin;
|
import com.zy.asrs.service.MatCodeService;
|
import com.zy.asrs.service.OutStockMainService;
|
import com.zy.asrs.service.OutStockService;
|
import com.zy.asrs.service.WaitPakinService;
|
import com.zy.asrs.utils.VersionUtils;
|
import com.zy.common.service.erp.ErpService;
|
import com.zy.common.service.erp.dto.InStockDto;
|
import com.zy.common.service.erp.entity.*;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.scheduling.annotation.Scheduled;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.PostConstruct;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* erp任务控制器
|
* Created by vincent on 2020/11/27
|
*/
|
@Slf4j
|
@Component
|
public class ErpScheduler {
|
|
@Autowired
|
private ErpService erpService;
|
@Autowired
|
private MatCodeService matCodeService;
|
@Autowired
|
private WaitPakinService waitPakinService;
|
@Autowired
|
private OutStockMainService outStockMainService;
|
@Autowired
|
private OutStockService outStockService;
|
|
private Map<Integer, M_item> itemMap = new HashMap<>();
|
|
/**
|
* 原材料
|
*/
|
// @Scheduled(cron = "0/3 * * * * ? ")
|
// @PostConstruct
|
public void inStockExecute(){
|
// List<M_item> item = erpService.getItem();
|
// for (M_item item1 : item) {
|
// itemMap.put(item1.getMitemid(), item1);
|
// }
|
|
List<InStockDto> readyInStock = erpService.getReadyInStock();
|
for (InStockDto dto : readyInStock) {
|
for (InStockBillEntry entry : dto.getInStockBillEntries()) {
|
// if (entry.getFNumber() == null && itemMap.containsKey(entry.getFItemID())) {
|
// entry.setFNumber(itemMap.get(entry.getFItemID()).getMnumber());
|
// boolean b = erpService.updateFnumber(entry.getFItemID(), entry.getFNumber());
|
// if (b) {
|
// System.err.println(entry.getFItemID() + ": " + entry.getFNumber());
|
// }
|
// }
|
|
MatCode matCode = matCodeService.selectById(entry.getFnumber());
|
if (null != matCode) {
|
// 生成入库通知单
|
WaitPakin waitPakin = new WaitPakin();
|
waitPakin.setMemo("原材料");
|
waitPakin.setStatus("Y"); // 状态
|
waitPakin.setIoStatus("N"); // 入出状态
|
waitPakin.setAppeTime(new Date());
|
waitPakin.setModiTime(new Date());
|
VersionUtils.setWaitPakIn(waitPakin, matCode);
|
waitPakin.setMnemonic(entry.getFSourceBillNo()); // todo:luxiaotao 单据编号
|
waitPakin.setSupplier(dto.getInStockBill().getFBillNo()); // todo:luxiaotao 通知单号
|
Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>()
|
.eq("supplier", waitPakin.getSupplier())
|
.eq("matnr", waitPakin.getMatnr())
|
.isNull("zpallet");
|
WaitPakin one = waitPakinService.selectOne(wrapper);
|
try {
|
if (one == null) {
|
waitPakin.setAnfme(entry.getFAuxQty());
|
if (!waitPakinService.insert(waitPakin)) {
|
log.error("{}原材料入库通知单的{}物料数据处理失败", waitPakin.getSupplier(), waitPakin.getMatnr());
|
}
|
}
|
// else {
|
// waitPakin.setAnfme(one.getAnfme() + entry.getFAuxQty());
|
// waitPakinService.update(waitPakin, wrapper);
|
// }
|
} catch (Exception e) {
|
e.printStackTrace();
|
System.out.println(JSON.toJSON(waitPakin));
|
}
|
}
|
}
|
if (!erpService.haveReadInStock(dto.getInStockBill().getFBillNo())) {
|
log.error("{}原材料入库通知单已读失败", dto.getInStockBill().getFBillNo());
|
}
|
}
|
|
}
|
|
|
/**
|
* 成品
|
*/
|
@Scheduled(cron = "0/5 * * * * ? ")
|
// @PostConstruct
|
public void inCPICMOExecute(){
|
// List<M_item> item = erpService.getItem();
|
// for (M_item item1 : item) {
|
// itemMap.put(item1.getMitemid(), item1);
|
// }
|
|
List<CPICMO> cpicmos = erpService.getReadyCPICMO();
|
for (CPICMO cpicmo : cpicmos) {
|
// if (Cools.isEmpty(cpicmo.getFnumber()) && itemMap.containsKey(cpicmo.getFItemID())) {
|
// cpicmo.setFnumber(itemMap.get(cpicmo.getFItemID()).getMnumber());
|
// boolean b = erpService.updateCFnumber(cpicmo.getFItemID(), cpicmo.getFnumber());
|
// if (b) {
|
// System.err.println(cpicmo.getFItemID() + ": " + cpicmo.getFnumber());
|
// }
|
// }
|
MatCode matCode = matCodeService.selectById(cpicmo.getFnumber());
|
if (null != matCode) {
|
// 生成入库通知单
|
WaitPakin waitPakin = new WaitPakin();
|
waitPakin.setMemo("成品");
|
waitPakin.setStatus("Y"); // 状态
|
waitPakin.setIoStatus("N"); // 入出状态
|
waitPakin.setAppeTime(new Date());
|
waitPakin.setModiTime(new Date());
|
VersionUtils.setWaitPakIn(waitPakin, matCode);
|
waitPakin.setMnemonic(cpicmo.getFSourceBillNo()); // todo:luxiaotao 单据编号
|
waitPakin.setSupplier(cpicmo.getFBillNo()); // todo:luxiaotao 通知单号
|
Wrapper<WaitPakin> wrapper = new EntityWrapper<WaitPakin>()
|
.eq("supplier", waitPakin.getSupplier())
|
.eq("matnr", waitPakin.getMatnr())
|
.isNull("zpallet");
|
WaitPakin one = waitPakinService.selectOne(wrapper);
|
if (one == null) {
|
waitPakin.setAnfme(cpicmo.getFAuxQty());
|
if (!waitPakinService.insert(waitPakin)) {
|
log.error("{}成品入库通知单的{}物料数据处理失败", waitPakin.getSupplier(), waitPakin.getMatnr());
|
}
|
}
|
if (!erpService.haveReadCPICMO(cpicmo.getFBillNo())) {
|
log.error("{}成品入库通知单已读失败", cpicmo.getFBillNo());
|
}
|
}
|
}
|
}
|
|
@Scheduled(cron = "0/5 * * * * ? ")
|
public void syncMat(){
|
List<M_item> items = erpService.getItem();
|
for (M_item item : items) {
|
MatCode matCode = matCodeService.selectById(item.getMnumber());
|
if (matCode == null) {
|
matCode = new MatCode();
|
VersionUtils.setMatCode(matCode, item);
|
matCode.setAppeTime(new Date());
|
matCode.setModiTime(new Date());
|
boolean insert = matCodeService.insert(matCode);
|
if (insert) {
|
log.info("=====>> 新增物料成功 : {}", JSON.toJSONString(item));
|
} else {
|
log.error("=====>> 新增物料失败!!! : {}", JSON.toJSONString(item));
|
}
|
} else {
|
VersionUtils.setMatCode(matCode, item);
|
matCode.setModiTime(new Date());
|
boolean b = matCodeService.updateById(matCode);
|
if (b) {
|
log.info("=====>> 更新物料成功 : {}", JSON.toJSONString(item));
|
} else {
|
log.error("=====>> 更新物料失败!!! : {}", JSON.toJSONString(item));
|
}
|
}
|
// 更新完之后删除
|
erpService.deleteItem(item.getMnumber());
|
}
|
}
|
|
/**
|
* 成品出库-发货通知单表头
|
*/
|
@Scheduled(cron = "0/15 * * * * ? ")
|
public void syncOutStock(){
|
List<OutStockBill> result = erpService.syncOutStock();
|
for (Integer i = 0; i < result.size(); i++) {
|
OutStockBill main = outStockMainService.selectOne(new EntityWrapper<OutStockBill>().eq("FBrNo", result.get(i).getFBrNo()).and().eq("FInterID", result.get(i).getFInterID()));
|
if (null == main) {
|
if (!outStockMainService.insert(result.get(i))) {
|
log.info("出库通知主表OutStockBill同步失败");
|
};
|
} else {
|
|
}
|
}
|
}
|
|
/**
|
* 成品出库-发货通知单表体
|
*/
|
@Scheduled(cron = "0/15 * * * * ? ")
|
public void syncOutStockDetail(){
|
List<OutStockBillEntry> result = erpService.syncOutStockDetail();
|
for (Integer i = 0; i < result.size(); i++) {
|
OutStockBillEntry main = outStockService.selectOne(new EntityWrapper<OutStockBillEntry>().eq("FInterID", result.get(i).getFInterID()).and().eq("FEntryID", result.get(i).getFEntryID()));
|
if (null == main) {
|
if (!outStockService.insert(result.get(i))) {
|
log.info("出库通知明细表OutStockBillEntry同步失败");
|
};
|
}
|
}
|
}
|
|
/**
|
* 原材料出库
|
*/
|
// @Scheduled(cron = "0/3 * * * * ? ")
|
public void outStockExecute(){
|
|
}
|
|
}
|