自动化立体仓库 - WMS系统
zyx
2024-02-02 00b8e7a256d8508043784f061a4afe5b1107d9aa
src/main/java/com/zy/asrs/utils/PlaExcelListener.java
@@ -5,8 +5,12 @@
import com.core.common.Cools;
import com.core.common.SpringUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Mat;
import com.zy.asrs.entity.Node;
import com.zy.asrs.entity.Pla;
import com.zy.asrs.entity.param.GlobleParameter;
import com.zy.asrs.service.MatService;
import com.zy.asrs.service.NodeService;
import com.zy.asrs.service.PlaService;
import com.zy.common.entity.MatExcel;
import com.zy.common.entity.PlaExcel;
@@ -23,6 +27,9 @@
 */
@Slf4j
public class PlaExcelListener extends AnalysisEventListener<PlaExcel> {
    private static final String OWNER_HZ = "海正生物";
    private static final String OWNER_HNE = "海诺尔";
    private int total = 0;
    private Long userId;
@@ -54,6 +61,8 @@
    @Override
    public void invoke(PlaExcel excel, AnalysisContext ctx) {
        PlaService plaService = SpringUtils.getBean(PlaService.class);
        NodeService nodeService = SpringUtils.getBean(NodeService.class);
        MatService matService = SpringUtils.getBean(MatService.class);
        Date now = new Date();
        // 商品
@@ -65,23 +74,93 @@
            pla = excel;
            pla.setStep(2);
            pla.setCreateTime(new Date());
            pla.setStatus(GlobleParameter.PLA_STATUS_0);
            pla.setModifyTime(new Date());
            pla.setStatus(GlobleParameter.PLA_STATUS_00);
            pla.setStockFreeze(1);
            pla.setWeightAnfme(pla.getWeight());
            Mat mat = matService.selectByMaktx(pla.getBrand());
            if(Cools.isEmpty(mat)){
                throw new CoolException("无法找到对应的牌号信息,牌号=" + pla.getBrand());
            }
            pla.setMatnr(mat.getMatnr());
            try {
                pla.setType(getType(mat.getMatnr()));
                //车间、产线、主体
                setPla(pla);
            }catch (Exception e){
                log.info(e.getMessage() + "Pla: " + pla.getBatch());
                throw new CoolException(e.getMessage());
            }
            if(!Cools.isEmpty(pla.getLocNo())){
                Node node = nodeService.selectByUuid(pla.getLocNo());
                if(Cools.isEmpty(node)){
                    throw new CoolException("未能找到相应的库位信息,库位编号=" +pla.getLocNo());
                    //log.info("未能找到相应的库位信息,库位编号={}",pla.getLocNo());
                }
                pla.setStash(node.getParentName());
                pla.setLocNo(node.getUuid());
                pla.setStatus(GlobleParameter.PLA_STATUS_1);
                pla.setPakinTime(new Date());
            }
            if (!plaService.insert(pla)) {
                throw new CoolException("保存商品信息失败,商品编码:" + excel.getMatnr());
            }
            total++;
        }else if (pla.getStatus().equals(GlobleParameter.PLA_STATUS_0)){
        }else if (pla.getStatus().equals(GlobleParameter.PLA_STATUS_00)){
            excel.setId(pla.getId());
            excel.setCreateTime(pla.getCreateTime());
            excel.setModifyTime(pla.getModifyTime());
            excel.setModifyTime(new Date());
            excel.setStep(2);
            excel.setStatus(GlobleParameter.PLA_STATUS_0);
            excel.setStatus(GlobleParameter.PLA_STATUS_00);
            BeanUtils.copyProperties(excel,pla);
            plaService.updateById(pla);
            total++;
        }
    }
    private String getType(String matnr){
        String type = matnr.substring(0,3);
        if(Cools.eq(type,"301")){
            return "纯树脂";
        }
        if (Cools.eq(type,"302")){
            return "改性树脂";
        }
        if (Cools.eq(type,"303")){
            return "副产物";
        }
        if (Cools.eq(type,"304")){
            return "委托加工产品";
        }
        if (Cools.eq(type,"305")){
            return "丙交酯";
        }
        return "";
    }
    private void setPla(Pla pla){
        String batch = pla.getBatch();
        String line = batch.substring(8,10);
        pla.setLine(line);
        if("纯树脂".equals(pla.getType())){
            if("01".equals(line) || "02".equals(line)){
                pla.setOwner(OWNER_HZ);
                pla.setWorkshop("一车间");
            }else {
                pla.setOwner(OWNER_HNE);
                pla.setWorkshop("三车间");
            }
        }else if ("改性树脂".equals(pla.getType())){
            if ("01".equals(line) || "02".equals(line) || "03".equals(line) || "04".equals(line)){
                pla.setOwner(OWNER_HNE);
                pla.setWorkshop("二车间");
            }
        }
    }
    /**
     * 所有数据解析完成了调用
     * 适合事务