guoyujie
1 天以前 91b61fe723df498d62c596372521d426299f0f8b
north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java
@@ -93,6 +93,7 @@
                //删除材料出库明细的数据
                materialInventoryMapper.deleteMaterialOutboundDetail(materialOutboundId);
                materialInventoryMapper.updateMaterialOutbound(materialOutbound, materialOutboundId);
                materialInventoryMapper.deleteMaterialLog(materialOutboundId);
                oddNumber = materialOutboundId;
                log.setFunction("saveMaterialOutbound修改:"+oddNumber);
            } else {
@@ -114,13 +115,16 @@
                        materialInventoryMapper.insertMaterialOutboundDetail(materialOutboundDetail, oddNumber, materialOutboundDetailMaximum + 1);
                        //修改物料库存表出库数量
                        materialInventoryMapper.updateMaterialInventoryAvailableOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
                    if(materialOutboundDetail.getUseId()!=null){
                        //修改优化工程表出库数量
                        materialInventoryMapper.updateMaterialInventoryAvailableOptOut(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
                    }/*else{
                        String projectNo="";
                        if(materialOutboundDetail.getUseId()!=null){
                            projectNo = materialInventoryMapper.selectProjectNo(materialOutboundDetail.getUseId());
                            //修改优化工程表出库数量
                            materialInventoryMapper.updateMaterialInventoryAvailableOptOut(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
                        }/*else{
                        //修改物料库存表出库数量
                        materialInventoryMapper.updateMaterialInventoryAvailableOut(materialOutboundDetail.getId(), materialOutboundDetail.getOutboundQuantity());
                    }*/
                        }*/
                        String json="";
                        MaterialStore materialStore=materialStoreMapper.getSelectMaterialStoreById(Long.valueOf(materialOutboundDetail.getMaterialCode()));
                        json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
@@ -140,6 +144,7 @@
                        materialLog.setInventoryId(materialOutboundDetail.getId());
                        materialLog.setInventoryArea(materialInventory.getInventoryArea());
                        materialLog.setRemarks(materialOutboundDetail.getRemarks());
                        materialLog.setProjectNo(projectNo);
                        materialLog.setOperator(object.get("userName").toString());
                        materialLog.setOperateTime(LocalDate.now());
                        materialLogMapper.insert(materialLog);
@@ -163,7 +168,7 @@
            sysError.setError(e+Arrays.toString(e.getStackTrace()));
            sysError.setFunc("saveMaterialOutbound");
            sysErrorService.insert(sysError);
            saveState = "false1";
            saveState = "false";
        }
        return saveState;
@@ -196,21 +201,22 @@
            //查询物料是否存在
            Integer MaterialInventoryCount=0;
            List<MaterialInventory> MaterialInventoryCount;
            if (materialInventory.getDateOfManufacture()!=null){
                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(materialCode,materialInventory.getDateOfManufacture());
            }else{
                MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCountNull(materialCode);
            }
            if(MaterialInventoryCount==1){
            if(MaterialInventoryCount.size()==1){
                materialInventory.setId(MaterialInventoryCount.get(0).getId());
                if (materialInventory.getDateOfManufacture()!=null){
                    materialInventoryMapper.updateMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
                }else{
                    materialInventoryMapper.updateMaterialInventoryNull(materialCode,singlePieceArea,totalArea,materialInventory);
                }
                log.setFunction("saveMaterialInventory修改");
            }else if(MaterialInventoryCount==0) {
            }else if(MaterialInventoryCount.isEmpty()) {
                materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
                log.setFunction("saveMaterialInventory新增");
            }else {
@@ -221,6 +227,9 @@
            MaterialStore materialStore=materialStoreMapper.getSelectMaterialStoreById(materialCode);
            json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
            MaterialLog materialLog=new MaterialLog();
            if(materialInventory.getDateOfManufacture()!=null){
                materialLog.setOperationOrderNumber(materialInventory.getDateOfManufacture().toString());
            }
            materialLog.setOperateType("物料新增");
            materialLog.setMaterialCode(materialCode);
            materialLog.setMaterialName(convertString(json,"\"name\""));
@@ -338,7 +347,10 @@
                    for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailLists) {
                        //还原物料库存数
                        materialInventoryMapper.updateMaterialInventoryAvailableInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
                        if(materialOutboundDetail.getUseId()!=null){
                            //还原优化工程库存数
                            materialInventoryMapper.updateMaterialInventoryAvailableOptInt(materialOutboundDetail.getUseId(), materialOutboundDetail.getOutboundQuantity());
                        }
                    }
                }
@@ -482,10 +494,12 @@
                List<MaterialOutboundDetail> materialOutboundDetailList = materialInventoryMapper.getIsNotMaterialOutboundDetail(materialOutboundId);
                if (!materialOutboundDetailList.isEmpty()) {
                    for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailList) {
                        if(materialOutboundDetail.getUseId()!=null){
                            //修改物料库存数量
                            materialInventoryMapper.updateMaterialInventoryInventoryPlanQuantityOut(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
                        }else{
                            materialInventoryMapper.updateMaterialInventoryInventoryOut(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
                        }
                    }
                }
@@ -494,9 +508,13 @@
                List<MaterialOutboundDetail> materialOutboundDetailList = materialInventoryMapper.getIsNotMaterialOutboundDetail(materialOutboundId);
                if (!materialOutboundDetailList.isEmpty()) {
                    for (MaterialOutboundDetail materialOutboundDetail : materialOutboundDetailList) {
                        if(materialOutboundDetail.getUseId()!=null){
                            //修改物料库存数量
                            materialInventoryMapper.updateMaterialInventoryInventoryPlanQuantityInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
                        }else{
                            materialInventoryMapper.updateMaterialInventoryInventoryInt(materialOutboundDetail.getInventoryId(), materialOutboundDetail.getOutboundQuantity());
                        }
                    }
@@ -584,7 +602,7 @@
                    //查询物料是否存在
                    Integer MaterialInventoryCount=0;
                    List<MaterialInventory> MaterialInventoryCount;
                    if (returningWarehouseDetail.getDateOfManufacture()!=null){
                        MaterialInventoryCount = materialInventoryMapper.getMaterialInventoryCount(returningWarehouseDetail.getId(),returningWarehouseDetail.getDateOfManufacture());
                    }else{
@@ -592,7 +610,7 @@
                    }
                    if(MaterialInventoryCount>0){
                    if(!MaterialInventoryCount.isEmpty()){
                        if (returningWarehouseDetail.getDateOfManufacture()!=null){
                            materialInventoryMapper.updateMaterialInventoryReturning(returningWarehouseDetail.getId(),singlePieceArea,totalArea,returningWarehouseDetail);
                        }else{
@@ -1004,7 +1022,86 @@
    }
    public String cancelMaterialAdditionRecord(Map<String,Object> object) {
        String saveState = "true";
        //设置回滚点
        Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint();
        try {
            Log log = new Log();
            log.setOperatorId(object.get("userId").toString());
            log.setOperator(object.get("userName").toString());
            log.setFunction("cancelMaterialAdditionRecord物料新增撤销");
            log.setContent(object.toString());
            //获取对象集合循环进行新增修改
            List<MaterialLog> materialLoglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("materialAdd")), MaterialLog.class);
            if (!materialLoglist.isEmpty()){
                for (MaterialLog materialLog : materialLoglist) {
                    //查询物料是否存在
                    List<MaterialInventory> MaterialInventoryList;
                    if (materialLog.getOperationOrderNumber()!=null){
                        MaterialInventoryList = materialInventoryMapper.getMaterialInventoryCount(materialLog.getMaterialCode(), LocalDate.parse(materialLog.getOperationOrderNumber()));
                    }else{
                        MaterialInventoryList = materialInventoryMapper.getMaterialInventoryCountNull(materialLog.getMaterialCode());
                    }
                    if(MaterialInventoryList.size()==1){
                        if(MaterialInventoryList.get(0).getAvailableQuantity()>=materialLog.getQuantity()){
                            if (materialLog.getOperationOrderNumber()!=null){
                                materialInventoryMapper.updateMaterialInventoryOut(materialLog.getMaterialCode(),materialLog.getQuantity(),materialLog.getOperationOrderNumber());
                            }else{
                                materialInventoryMapper.updateMaterialInventoryNullOut(materialLog.getMaterialCode(),materialLog.getQuantity());
                            }
                            materialInventoryMapper.deleteMaterialLogById(materialLog.getId());
                        }else{
                            return "false1";
                        }
                    }else{
                        return "false2";
                    }
                }
            }
            logService.saveLog(log);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
            //将异常传入数据库
            SysError sysError = new SysError();
            sysError.setError(e+Arrays.toString(e.getStackTrace()));
            sysError.setFunc("cancelFinishedGoodsInventoryStorage");
            sysErrorService.insert(sysError);
            saveState = "false";
        }
        return saveState;
    }
    public Map<String, Object> getOptimizeOutboundReport(String type, Integer pageNum, Integer pageSize, List<String> selectDate, MaterialLog materialLog) {
        Integer offset = (pageNum-1)*pageSize;
        String endDate = LocalDate.now().toString();
        String startDate = LocalDate.now().minusDays(15).toString();
        if(selectDate !=null && selectDate.size()==2){
            if(!selectDate.get(0).isEmpty()){
                startDate = selectDate.get(0);
            }
            if(!selectDate.get(1).isEmpty()){
                endDate = selectDate.get(1);
            }
        }
        Map<String, Object> map = new HashMap<>();
        map.put("data", materialInventoryMapper.getOptimizeOutboundReport(offset, pageSize,startDate, endDate, materialLog,type));
        map.put("total", materialInventoryMapper.getOptimizeOutboundReportTotal(offset, pageSize,startDate, endDate, materialLog,type));
        List<String> list = new ArrayList<>();
        list.add(startDate);
        list.add(endDate);
        map.put("selectDate",list);
        return map;
    }
}