guoyuji
2024-10-30 f2b7487e3722ce3218a8e23a6ac18c1b78fe6a2c
north-glass-erp/src/main/java/com/example/erp/service/mm/MaterialInventoryService.java
@@ -14,6 +14,7 @@
import com.example.erp.entity.userInfo.SysError;
import com.example.erp.mapper.mm.BasicWarehouseTypeMapper;
import com.example.erp.mapper.mm.MaterialInventoryMapper;
import com.example.erp.mapper.mm.MaterialLogMapper;
import com.example.erp.mapper.mm.MaterialStoreMapper;
import com.example.erp.service.userInfo.LogService;
import com.example.erp.service.userInfo.SysErrorService;
@@ -44,6 +45,8 @@
    SysErrorService sysErrorService;
    @Autowired
    LogService logService;
    @Autowired
    MaterialLogMapper materialLogMapper;
    public String saveMaterialOutbound(Map<String,Object> object) {
        String saveState = "true";
@@ -55,6 +58,8 @@
            materialOutboundId = object.get("materialOutboundId").toString();
        }
        Log log = new Log();
        log.setOperatorId(object.get("userId").toString());
        log.setOperator(object.get("userName").toString());
        log.setContent(object.toString());
        try {
            MaterialOutbound materialOutbound = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialOutbound.class);
@@ -109,6 +114,28 @@
                        //修改物料库存表出库数量
                        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);
                        MaterialLog materialLog=new MaterialLog();
                        materialLog.setOperationOrderNumber(oddNumber);
                        materialLog.setOperationNumber(materialOutboundDetailMaximum + 1);
                        materialLog.setOperateType("物料出库");
                        materialLog.setMaterialCode(Long.valueOf(materialOutboundDetail.getMaterialCode()));
                        materialLog.setMaterialName(convertString(json,"\"name\""));
                        materialLog.setProducer(materialInventory.getProducer());
                        materialLog.setUnit(convertString(json,"\"unit\""));
                        materialLog.setWidth(convertDouble(json,"\"width\""));
                        materialLog.setHeight(convertDouble(json,"\"height\""));
                        materialLog.setThickness(convertDouble(json,"\"thickness\""));
                        materialLog.setQuantity(materialOutboundDetail.getOutboundQuantity());
                        materialLog.setSinglePieceArea(materialOutboundDetail.getSinglePieceArea());
                        materialLog.setInventoryId(materialOutboundDetail.getId());
                        materialLog.setInventoryArea(materialInventory.getInventoryArea());
                        materialLog.setRemarks(materialOutboundDetail.getRemarks());
                        materialLog.setOperator(object.get("userName").toString());
                        materialLog.setOperateTime(LocalDate.now());
                        materialLogMapper.insert(materialLog);
                    }else{
                        TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
                        return "false1";
@@ -154,6 +181,8 @@
                materialCode = Long.valueOf(object.get("materialCode").toString());
            }
            Log log = new Log();
            log.setOperatorId(object.get("userId").toString());
            log.setOperator(object.get("userName").toString());
            log.setContent(object.toString());
            MaterialInventory materialInventory = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), MaterialInventory.class);
@@ -168,6 +197,27 @@
                materialInventoryMapper.insertMaterialInventory(materialCode,singlePieceArea,totalArea,materialInventory);
                log.setFunction("saveMaterialInventory新增");
            }
            String json="";
            MaterialStore materialStore=materialStoreMapper.getSelectMaterialStoreById(materialCode);
            json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
            MaterialLog materialLog=new MaterialLog();
            materialLog.setOperateType("物料新增");
            materialLog.setMaterialCode(materialCode);
            materialLog.setMaterialName(convertString(json,"\"name\""));
            materialLog.setProducer(materialInventory.getProducer());
            materialLog.setUnit(convertString(json,"\"unit\""));
            materialLog.setWidth(convertDouble(json,"\"width\""));
            materialLog.setHeight(convertDouble(json,"\"height\""));
            materialLog.setThickness(convertDouble(json,"\"thickness\""));
            materialLog.setQuantity(materialInventory.getInventoryQuantity());
            materialLog.setSinglePieceArea(singlePieceArea);
            materialLog.setInventoryId(materialInventory.getId());
            materialLog.setInventoryArea(materialInventory.getInventoryArea());
            materialLog.setRemarks(materialInventory.getRemarks());
            materialLog.setOperator(object.get("userName").toString());
            materialLog.setOperateTime(LocalDate.now());
            materialLogMapper.insert(materialLog);
            logService.saveLog(log);
        } catch (Exception e) {
            TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint);
@@ -269,6 +319,8 @@
            }
            Log log = new Log();
            log.setContent(object.toString());
            log.setOperatorId(object.get("userId").toString());
            log.setOperator(object.get("userName").toString());
            log.setFunction("deleteMaterialOutbound删除:"+materialOutboundId);
            logService.saveLog(log);
@@ -405,6 +457,8 @@
                returningId = object.get("returningId").toString();
            }
            Log log = new Log();
            log.setOperatorId(object.get("userId").toString());
            log.setOperator(object.get("userName").toString());
            log.setContent(object.toString());
            ReturningWarehouse returningWarehouse = JSONObject.parseObject(JSONObject.toJSONString(object.get("title")), ReturningWarehouse.class);
@@ -448,8 +502,8 @@
                    json=materialStore.getJson().substring(1, materialStore.getJson().length() - 1);
                    double width= convert(json,"\"width\"");
                    double height=convert(json,"\"height\"");
                    double width= convertDouble(json,"\"width\"");
                    double height= convertDouble(json,"\"height\"");
                    DecimalFormat decimalFormat = new DecimalFormat("#0.00");
                    singlePieceArea= Double.parseDouble(decimalFormat.format(width * height / 100000));
                    totalArea= Double.parseDouble(decimalFormat.format(singlePieceArea * returningWarehouseDetail.getReturnQuantity()));
@@ -485,6 +539,25 @@
                    materialInventoryMapper.updateReturningWarehouseDetail(oddNumber, returningWarehouseDetailMaximum + 1,MaterialInventoryId.get(0).getId());
                    MaterialLog materialLog=new MaterialLog();
                    materialLog.setOperationOrderNumber(oddNumber);
                    materialLog.setOperationNumber(returningWarehouseDetailMaximum + 1);
                    materialLog.setOperateType("物料返库");
                    materialLog.setMaterialCode(returningWarehouseDetail.getId());
                    materialLog.setMaterialName(convertString(json,"\"name\""));
                    materialLog.setProducer(returningWarehouseDetail.getProducer());
                    materialLog.setUnit(convertString(json,"\"unit\""));
                    materialLog.setWidth(convertDouble(json,"\"width\""));
                    materialLog.setHeight(convertDouble(json,"\"height\""));
                    materialLog.setThickness(convertDouble(json,"\"thickness\""));
                    materialLog.setQuantity(returningWarehouseDetail.getReturnQuantity());
                    materialLog.setSinglePieceArea(singlePieceArea);
                    materialLog.setInventoryArea(returningWarehouseDetail.getInventoryArea());
                    materialLog.setRemarks(returningWarehouseDetail.getRemarks());
                    materialLog.setOperator(object.get("userName").toString());
                    materialLog.setOperateTime(LocalDate.now());
                    materialLogMapper.insert(materialLog);
                }
@@ -649,7 +722,6 @@
            if(surplusMaterials!=null){
                SurplusMaterials surplusMaterials1=materialInventoryMapper.selectSurplusMaterialsCount(surplusMaterials);
                if(surplusMaterials1!=null){
                    System.out.println(surplusMaterials1);
                    materialInventoryMapper.updateSurplusMaterialsIntQuantity(surplusMaterials1);
                    materialInventoryMapper.insertSurplusMaterialsLog(surplusMaterials1,creator,type);
                }else{
@@ -712,7 +784,7 @@
    }
    public double convert(String json,String string) {
    public String convertString(String json,String string) {
        Map<String, Object> map = new HashMap<>();
        String[] keyValues = json.split(",");
        for (String keyValue : keyValues) {
@@ -721,7 +793,19 @@
                map.put(pair[0], pair[1]);
            }
        }
        double number=0.0;
        return map.get(string).toString().replace("\"","");
    }
    public Double convertDouble(String json,String string) {
        Map<String, Object> map = new HashMap<>();
        String[] keyValues = json.split(",");
        for (String keyValue : keyValues) {
            String[] pair = keyValue.split(":");
            if (pair.length == 2) {
                map.put(pair[0], pair[1]);
            }
        }
        Double number=0.0;
        if(map.get(string)!=null){
            String[] widthStrings = map.get(string).toString().split("\\D+");
            for (String numberString : widthStrings) {