mrzhssss
2021-12-16 36b08172e90b5b03878145e5496edf1eb4a1af6d
src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
@@ -16,6 +16,7 @@
import com.zy.common.service.erp.ErpService;
import com.zy.common.service.erp.dto.InStockDto;
import com.zy.common.service.erp.entity.*;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
@@ -23,6 +24,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -52,15 +54,33 @@
    /**
     * 原材料入库单
     */
    @Scheduled(cron = "0/5 * * * * ? ")
    @Scheduled(cron = "0/30 * * * * ? ")
    @Synchronized
//    @PostConstruct
    public void inStockExecute(){
//        inStock的表头和表身
        List<InStockDto> readyInStock = erpService.getReadyInStock();
        for (InStockDto dto : readyInStock) {
            //同一单号存在相同物料编码数据,该单号不予处理
            Number fnumberCount = erpService.QueryFnumberInCount(dto.getInStockBill().getFInterID());
            if(fnumberCount.intValue() > 1){
                if (!erpService.haveReadInStock(dto.getInStockBill().getFBillNo(),-1)) {
                    log.error("标记原材料入库通知单已读InStockBill为-1失败[FBillNo={},FInterID={}]", dto.getInStockBill().getFBillNo(),dto.getInStockBill().getFInterID());
                }
                continue;
            }
            log.info("走到一号位置");
            if (Cools.isEmpty(dto) || Cools.isEmpty(dto.getInStockBillEntries())) {
                continue;
            }
            log.info("走到二号位置");
            for (InStockBillEntry entry : dto.getInStockBillEntries()) {
                MatCode matCode = matCodeService.selectById(entry.getFnumber());
                if (null != matCode) {
                    // 生成入库通知单
                    log.info("走到三号位置");
                    WaitPakin waitPakin = new WaitPakin();
                    waitPakin.setMemo("原材料");
                    waitPakin.setStatus("Y");    // 状态
@@ -95,12 +115,13 @@
                            }
                        }
                    } catch (Exception e) {
                        log.error("fail", e);
                        e.printStackTrace();
                        System.out.println(JSON.toJSON(waitPakin));
                    }
                }
            }
            if (!erpService.haveReadInStock(dto.getInStockBill().getFBillNo())) {
            if (!erpService.haveReadInStock(dto.getInStockBill().getFBillNo(),1)) {
                log.error("标记原材料入库通知单已读InStockBill失败[FBillNo={}]", dto.getInStockBill().getFBillNo());
            }
        }
@@ -111,11 +132,22 @@
    /**
     * 成品入库单
     */
    @Scheduled(cron = "0/5 * * * * ? ")
    @Scheduled(cron = "0/20 * * * * ? ")
    @Synchronized
//    @PostConstruct
    public void inCPICMOExecute(){
        List<CPICMO> cpicmos = erpService.getReadyCPICMO();
        for (CPICMO cpicmo : cpicmos) {
            //同一单号存在相同物料编码数据,该单号不予处理
            Number fnumberCount = erpService.QueryFnumberCPICMOCount(cpicmo.getFInterID());
            if(fnumberCount.intValue() > 1){
                if (!erpService.haveReadCPICMO(cpicmo.getFInterID(),-1)) {
                    log.error("标记成品入库通知单已读CPICMO为-1失败[Fnumber={},FInterID={}]", cpicmo.getFnumber(),cpicmo.getFInterID());
                }
                continue;
            }
            MatCode matCode = matCodeService.selectById(cpicmo.getFnumber());
            if (null != matCode) {
                // 生成入库通知单
@@ -151,14 +183,15 @@
                        log.info("同步更新成品入库通知单CPICMO失败[FBillNo={},Fnumber={}]", waitPakin.getSupplier(), waitPakin.getMatnr());
                    }
                }
                if (!erpService.haveReadCPICMO(cpicmo.getFBillNo())) {
                if (!erpService.haveReadCPICMO(cpicmo.getFInterID(),1)) {
                    log.error("标记成品入库通知单已读CPICMO失败[FBillNo={}]", cpicmo.getFBillNo());
                }
            }
        }
    }
    @Scheduled(cron = "0/5 * * * * ? ")
    @Scheduled(cron = "0/30 * * * * ? ")
    @Synchronized
    public void syncMat(){
        List<M_item> items = erpService.getItem();
        for (M_item item : items) {
@@ -193,11 +226,22 @@
     * 成品出库 发货通知单表头,表明细
     */
    @Scheduled(cron = "0/15 * * * * ? ")
    @Synchronized
    @Transactional
    public void syncOutStock(){
        List<OutStockBill> outStockBills = erpService.syncOutStock();
        for (Integer i = 0; i < outStockBills.size(); i++) {
            OutStockBill outStockBill = outStockBills.get(i);
            //同一单号存在相同物料编码数据,该单号不予处理
            Number fnumberCount = erpService.QueryFnumberOutCount(outStockBill.getFInterID());
            if(fnumberCount.intValue() > 1){
                if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID(),-1)) {
                    log.error("更新出库通知单读取状态为-1失败[FBrNo={},FInterID={}]", outStockBill.getFBrNo(),outStockBill.getFInterID());
                }
                continue;
            }
            OutStockBill main = outStockMainService.selectOne(new EntityWrapper<OutStockBill>().eq("FBillNo",outStockBill.getFBillNo()).and().eq("FInterID", outStockBill.getFInterID()));
            if (null == main) {
                outStockBill.setFflag_rw(1);
@@ -214,6 +258,7 @@
                    if (null == one) {
//                        String Fnumber = (Cools.isEmpty(outStockBillEntry.getFSourceBillNo())) ? outStockBillEntry.getFnumber() : outStockBillEntry.getFnumber()+"|"+outStockBillEntry.getFSourceBillNo();
//                        outStockBillEntry.setFnumber(Fnumber);  //产品代码|生产单号
                        outStockBillEntry.setFAmount(new BigDecimal(0));
                        if (!outStockService.insert(outStockBillEntry)) {
                            log.info("提取出库通知明细表OutStockBillEntry失败[FBrNo={},FInterID={},FEntryID={}]",outStockBillEntry.getFBrNo(),
                                    outStockBillEntry.getFInterID(),outStockBillEntry.getFEntryID());
@@ -226,6 +271,7 @@
                    } else {
                        // 数量有变化进行更新
                        if (Double.doubleToLongBits(one.getFAuxQty().doubleValue()) != Double.doubleToLongBits(outStockBillEntry.getFAuxQty().doubleValue())) {
                            outStockBillEntry.setFAmount(new BigDecimal(0));
                            if (!outStockService.update(outStockBillEntry, wrapper)) {
                                log.info("同步更新通知明细表OutStockBillEntry失败[FBrNo={},FInterID={},FEntryID={}]",outStockBillEntry.getFBrNo(),
                                        outStockBillEntry.getFInterID(),outStockBillEntry.getFEntryID());
@@ -242,7 +288,7 @@
            }
            if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID())) {
            if (!erpService.haveReadOutBill(outStockBill.getFBillNo(),outStockBill.getFInterID(),1)) {
                log.error("更新出库通知单读取状态失败[FBrNo={},FInterID={}]", outStockBill.getFBrNo(),outStockBill.getFInterID());
            }
        }