自动化立体仓库 - WMS系统
1
ZY
2025-03-29 c65db22f67af8018ae7105ea00d8743e42835e13
src/main/java/com/zy/common/service/erp/task/ErpScheduler.java
@@ -1,28 +1,19 @@
package com.zy.common.service.erp.task;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.AllLocDetl;
import com.zy.asrs.entity.InventoryVariance;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Tag;
import com.zy.asrs.service.AllLocDetlService;
import com.zy.asrs.service.InventoryVarianceService;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.TagService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.common.service.erp.ErpService;
import com.zy.common.service.erp.entity.Goods;
import com.zy.common.service.erp.entity.WlzhVStRd;
import lombok.Synchronized;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
@@ -44,55 +35,17 @@
    @Autowired
    private InventoryVarianceService inventoryVarianceService;
    //@Scheduled(cron = "0/5 * * * * ? ")
    @Synchronized
    @Transactional
    public synchronized void syncMat() {
        Tag top = tagService.getTop();
        List<Goods> goods = erpService.selectGoods(0);
        Date now = new Date();
        if (!Cools.isEmpty(goods)) {
            for (Goods good : goods) {
                Mat mat = matService.selectByMatnr(good.getMaterialNO());
                if (mat == null) {
                    mat = new Mat();
                    mat.setTagId(top.getId());
                    mat.setMatnr(good.getMaterialNO());
//                    mat.setMaktx(good.getBarCode());
                    mat.setSpecs(good.getProdSpec());
                    mat.setModel(good.getBatch());
                    mat.setWeight(good.getNWT());
                    mat.setUnits(good.getNumOfBobbins()==null?null:good.getNumOfBobbins().doubleValue());
                    mat.setManuDate(good.getProdDate());
                    mat.setCreateTime(now);
                    mat.setSku(good.getLocation());
                    if (!Cools.isEmpty(good.getLastUpdatedDate())) {
                        mat.setUpdateTime(DateUtils.convert(good.getLastUpdatedDate().substring(0, 19)));
                    }
                    if (!matService.insert(mat)) {
                        throw new CoolException(good.getBarCode() + "商品同步失败");
                    }
                }
                int state = 1;
                if (!erpService.updateStateForGoods(good.getBarCode(), state)) {
                    throw new CoolException(good.getBarCode() + "商品修改State为"+state+"失败");
                }
            }
        }
    }
    //@Scheduled(cron = "0/5 * * * * ? ")
    @Synchronized
    @Transactional
    //@Scheduled(cron = "0 0 2 * * ? ")
    public void syncLocDetl(){
        log.info("库存差异信息清除");
        inventoryVarianceService.deleteAll();
        List<InventoryVariance> inventoryVariances = new ArrayList<>();
        log.info("与ERP比对开始");
        int pageSize = 500;
        int pageNumber = 0;
        while (true){
            List<InventoryVariance> inventoryVariances = new ArrayList<>();
            List<WlzhVStRd> wlzhVStRds = erpService.selectPage(pageSize, pageNumber);
            if(wlzhVStRds.size() < pageSize){
                break;
@@ -101,19 +54,17 @@
            //ERP库存与立库库存比对
            compileStock(wlzhVStRds,inventoryVariances);
            pageNumber ++;
            inventoryVarianceService.insertBatch(inventoryVariances);
        }
        inventoryVarianceService.insertBatch(inventoryVariances);
    }
    private void compileStock(List<WlzhVStRd> wlzhVStRds, List<InventoryVariance> inventoryVariances){
        wlzhVStRds.forEach(wlzhVStRd -> {
            String matnr = wlzhVStRd.getCInvCode();
            String matnr = wlzhVStRd.getCinvcode();
            String csocode = wlzhVStRd.getCsocode();
            String isoseq = wlzhVStRd.getIsoseq();
            Double iQuantity = wlzhVStRd.getIQuantity();
            Double iQuantity = wlzhVStRd.getIquantity();
            Double anfme = 0.0;