zhangyuewww 2 years ago
parent
commit
a498be8079

+ 508 - 50
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/WarehouseInOutInfoServiceImpl.java

@@ -922,6 +922,67 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                     }
                                 }
                             }
+                            //常用库之间的移库
+                            else{
+                                //查收货库
+                                InOutWarehouseTask inOutWarehouseTask1 = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                        .eq("relevance_id", inOutWarehouseTask.getRelevanceId())
+                                        .eq("in_out_flag", "2")
+                                        .eq("delete_flag", "0"));
+                                //更新所在仓库收购库存
+                                ContractInventoryDistribution contractInventoryDistribution1=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                        .eq("comp_id",inOutWarehouseTask1.getCompId()).eq("inventory_type","3").eq("warehouse",inOutWarehouseTask.getWarehouseName())
+                                        .eq("locus_warehouse",inOutWarehouseTask1.getWarehouseName())
+                                        .eq("goods_name",warehouseInOutInfo.getGoodsName()));
+                                if (contractInventoryDistribution1!=null){
+                                    contractInventoryDistribution1.setInventory(contractInventoryDistribution1.getInventory()+warehouseInOutInfo.getNetWeight());
+                                    contractInventoryDistributionService.updateById(contractInventoryDistribution1);
+                                }
+                                else {
+                                    ContractInventoryDistribution contractInventoryDistribution2=new ContractInventoryDistribution();
+                                    contractInventoryDistribution2.setId(IdGenerator.generateUUID());
+                                    contractInventoryDistribution2.setCompId(inOutWarehouseTask.getCompId());
+                                    //所属仓库  发货库
+                                    contractInventoryDistribution2.setWarehouse(inOutWarehouseTask.getWarehouseName());
+                                    contractInventoryDistribution2.setInventory(warehouseInOutInfo.getNetWeight());
+                                    //所在仓库  收货
+                                    contractInventoryDistribution2.setLocusWarehouse(inOutWarehouseTask1.getWarehouseName());
+                                    contractInventoryDistribution2.setGoodsName(warehouseInOutInfo.getGoodsName());
+                                    contractInventoryDistribution2.setInventoryType("3");
+                                    contractInventoryDistributionService.insert(contractInventoryDistribution2);
+
+                                }
+                            }
+                        }
+                        //入库时更新汽运报表卸车数据
+                        TranSettlementReport tranSettlementReport = tranSettlementReportService.selectOne(new EntityWrapper<TranSettlementReport>()
+                                .eq("car_id", warehouseInOutInfo.getCarId()));
+                        if (tranSettlementReport!=null) {
+                            tranSettlementReport.setUnloadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            tranSettlementReport.setUnloadingImg(warehouseInOutInfo.getAddressUrl());
+                            //损耗
+                            tranSettlementReport.setLossWeight(tranSettlementReport.getLoadingWeight() - tranSettlementReport.getUnloadingWeight());
+                            //汽运类型
+                            if (tranSettlementReport.getTranTypeKey().equals(NumberConstant.CONSTANT1)) {
+                                //结算重量
+                                if ("0".equals(tranSettlementReport.getManualFlag())) {
+                                    //卸车不为空时,结算重量=装卸取小
+                                    tranSettlementReport.setSettlementWeight(tranSettlementReport.getLoadingWeight() > tranSettlementReport.getUnloadingWeight() ? tranSettlementReport.getUnloadingWeight() : tranSettlementReport.getLoadingWeight());
+                                }
+                                if (tranSettlementReport.getTransportPrice()!=null) {
+                                    //扣款
+                                    if (tranSettlementReport.getLossWeight() <= (tranSettlementReport.getLoadingWeight() / 1000)) {
+                                        tranSettlementReport.setDeductionAmount("0");
+                                        //应付=单价x结算重量-扣款
+                                        tranSettlementReport.setAmountIngPayable(tranSettlementReport.getTransportPrice() * tranSettlementReport.getSettlementWeight());
+                                    } else {
+                                        tranSettlementReport.setDeductionAmount(String.format("%.2f", (Float.valueOf(tranSettlementReport.getLoadingWeight() - tranSettlementReport.getUnloadingWeight()) - (tranSettlementReport.getLoadingWeight() / 1000)) * Float.valueOf(tranSettlementReport.getTransportPrice())));
+                                        //应付=单价x结算重量-扣款
+                                        tranSettlementReport.setAmountIngPayable(tranSettlementReport.getTransportPrice() * tranSettlementReport.getSettlementWeight() - Float.valueOf(tranSettlementReport.getDeductionAmount()));
+                                    }
+                                }
+                            }
+                            tranSettlementReportService.updateById(tranSettlementReport);
                         }
                     }
                     //常用库退库入库类型
@@ -1183,6 +1244,14 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                 else if ("1".equals(warehouseInOutInfo.getInOutFlag()) && "1".equals(warehouseBaseInfo.getWarehouseType())) {
                     //常用库销售出库类型
                     if ("1".equals(warehouseInOutInfo.getInOutTypeKey())) {
+                        //更新合同销售库存
+                        ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                .eq("comp_id",warehouseBaseInfo.getCompId()).eq("inventory_type","1").eq("contract_no",warehouseInOutInfo.getContractNo())
+                                .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                        if (contractInventoryDistribution!=null){
+                            contractInventoryDistribution.setSaleStorage(contractInventoryDistribution.getSaleStorage()+warehouseInOutInfo.getNetWeight());
+                            contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                        }
                         //他运的销售合同
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                                 .eq("contract_no", warehouseInOutInfo.getContractNo())
@@ -1364,6 +1433,59 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                         warehouseInOutInfoService.updateById(warehouseInOutInfo);
                                         tranCarInfoService.insert(tranCarInfo);
                                     }
+                                    //生成汽运报表
+                                    TranSettlementReport tranSettlementReport = new TranSettlementReport();
+                                    tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+                                    tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+                                    tranSettlementReport.setId(IdGenerator.generateUUID());
+                                    if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+                                        tranSettlementReport.setTranType("汽运");
+                                        tranSettlementReport.setTranTypeKey("1");
+                                    } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+                                        tranSettlementReport.setTranType("火运");
+                                        tranSettlementReport.setTranTypeKey("2");
+                                    } else {
+                                        tranSettlementReport.setTranType("船运");
+                                        tranSettlementReport.setTranTypeKey("3");
+                                    }
+                                    tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+                                    tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+                                    tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                                    //运输单价不为空
+                                    if (tranProcessInfo.getTranPrice()!=null){
+                                        //应付
+                                        tranSettlementReport.setAmountIngPayable(Float.valueOf(tranProcessInfo.getTranPrice()) * tranSettlementReport.getSettlementWeight());
+                                        //未付
+                                        tranSettlementReport.setAmountNotPayable(Float.valueOf(tranProcessInfo.getTranPrice()) * tranSettlementReport.getSettlementWeight());
+                                        tranSettlementReport.setTransportPrice(Float.valueOf(tranProcessInfo.getTranPrice()));
+                                    }
+                                    tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+                                    tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                                    tranSettlementReportService.insert(tranSettlementReport);
+                                    boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+                                    // 不是退回的单子
+                                    if (isStartWorkflow) {
+                                        Workflow workflow = workflowService
+                                                .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+                                        // 没配置审核流程,直接结束并处理信息
+                                        if (workflow == null) {
+                                            throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                                        }
+                                        // 开启审核流
+                                        else {
+
+                                            // 设置状态 已提交审核
+                                            tranSettlementReport.setWorkflowId(workflow.getId());
+                                            tranSettlementReportService.updateById(tranSettlementReport);
+                                            workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                        }
+                                    }
+                                    // 退回的单子 再启用
+                                    else {
+
+                                        tranSettlementReportService.updateById(tranSettlementReport);
+                                        workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
+                                    }
                                 }
                             } else {
                                 throw new YException(YExceptionEnum.TRANTASK_NOT_CREATED_ERROR);
@@ -1400,11 +1522,28 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                     }
                     //常用库移库出库类型
                     if ("移库出库".equals(warehouseInOutInfo.getInOutType())) {
+                        //更新合同移库库存
+                        ContractInventoryDistribution contractInventoryDistribution1=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                .eq("comp_id",warehouseBaseInfo.getCompId()).eq("inventory_type","1").eq("contract_no",warehouseInOutInfo.getContractNo())
+                                .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                        if (contractInventoryDistribution1!=null){
+                            contractInventoryDistribution1.setRemoveStorage(contractInventoryDistribution1.getRemoveStorage()+warehouseInOutInfo.getNetWeight());
+                            contractInventoryDistributionService.updateById(contractInventoryDistribution1);
+                        }
                         InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
                                 .eq("move_task_no", warehouseInOutInfo.getContractNo())
                                 .eq("in_out_flag", "1")
                                 .eq("delete_flag", "0"));
                         if (inOutWarehouseTask != null) {
+                            //更新所属仓库收购库存
+                            ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                    .eq("comp_id",inOutWarehouseTask.getCompId()).eq("inventory_type","3").eq("warehouse",inOutWarehouseTask.getWarehouseName())
+                                    .eq("locus_warehouse",inOutWarehouseTask.getWarehouseName())
+                                    .eq("goods_name",warehouseInOutInfo.getGoodsName()));
+                            if (contractInventoryDistribution!=null){
+                                contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()-warehouseInOutInfo.getNetWeight());
+                                contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                            }
                             //自运出库时手动加的车
                             if ("1".equals(warehouseInOutInfo.getSelfLoading())) {
                                 List<TranCarInfo> tranCarInfoList = tranCarInfoService.selectList(new EntityWrapper<TranCarInfo>()
@@ -1419,6 +1558,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                             .eq("info_id", tranTaskInfo.getId()));
                                     tranCarInfo.setProcessId(tranProcessInfo.getId());
                                     tranCarInfo.setInfoId(tranTaskInfo.getId());
+                                    warehouseInOutInfo.setFreight(tranProcessInfo.getTranPrice());
                                     tranCarInfo.setTranPrice(String.valueOf(tranProcessInfo.getTranPrice() != null ? tranProcessInfo.getTranPrice() : 0f));
                                 } else {
                                     throw new YException(YExceptionEnum.TRANTASK_NOT_CREATED_ERROR);
@@ -1450,61 +1590,114 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                 warehouseInOutInfoService.updateById(warehouseInOutInfo);
                                 tranCarInfoService.insert(tranCarInfo);
                             }
-                        }
-                    }
-                    //运费大于0生成运费结算报表数据
-                    if (warehouseInOutInfo.getFreight() != null && warehouseInOutInfo.getFreight() > 0) {
-                        //生成汽运报表
-                        TranSettlementReport tranSettlementReport = new TranSettlementReport();
-                        tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
-                        tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
-                        tranSettlementReport.setId(IdGenerator.generateUUID());
-                        if ("汽运".equals(warehouseInOutInfo.getOutType())) {
-                            tranSettlementReport.setTranType("汽运");
-                            tranSettlementReport.setTranTypeKey("1");
-                        } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
-                            tranSettlementReport.setTranType("火运");
-                            tranSettlementReport.setTranTypeKey("2");
-                        } else {
-                            tranSettlementReport.setTranType("船运");
-                            tranSettlementReport.setTranTypeKey("3");
-                        }
-                        tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
-                        tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
-                        tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-                        //应付
-                        tranSettlementReport.setAmountIngPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
-                        //未付
-                        tranSettlementReport.setAmountNotPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
-                        tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-                        tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
-                        tranSettlementReport.setTransportPrice(Float.valueOf(warehouseInOutInfo.getFreight()));
-                        tranSettlementReportService.insert(tranSettlementReport);
-                        boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
-                        // 不是退回的单子
-                        if (isStartWorkflow) {
-                            Workflow workflow = workflowService
-                                    .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
-                            // 没配置审核流程,直接结束并处理信息
-                            if (workflow == null) {
-                                throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                            //生成汽运报表
+                            TranSettlementReport tranSettlementReport = new TranSettlementReport();
+                            tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+                            tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+                            tranSettlementReport.setId(IdGenerator.generateUUID());
+                            if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("汽运");
+                                tranSettlementReport.setTranTypeKey("1");
+                            } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("火运");
+                                tranSettlementReport.setTranTypeKey("2");
+                            } else {
+                                tranSettlementReport.setTranType("船运");
+                                tranSettlementReport.setTranTypeKey("3");
                             }
-                            // 开启审核流
+                            tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+                            tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+                            tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            //运输单价不为空
+                            if (warehouseInOutInfo.getFreight()!=null){
+                                //应付
+                                tranSettlementReport.setAmountIngPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                //未付
+                                tranSettlementReport.setAmountNotPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                tranSettlementReport.setTransportPrice(Float.valueOf(warehouseInOutInfo.getFreight()));
+                            }
+                            tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+                            tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            tranSettlementReportService.insert(tranSettlementReport);
+                            boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+                            // 不是退回的单子
+                            if (isStartWorkflow) {
+                                Workflow workflow = workflowService
+                                        .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+                                // 没配置审核流程,直接结束并处理信息
+                                if (workflow == null) {
+                                    throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                                }
+                                // 开启审核流
+                                else {
+
+                                    // 设置状态 已提交审核
+                                    tranSettlementReport.setWorkflowId(workflow.getId());
+                                    tranSettlementReportService.updateById(tranSettlementReport);
+                                    workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                }
+                            }
+                            // 退回的单子 再启用
                             else {
 
-                                // 设置状态 已提交审核
-                                tranSettlementReport.setWorkflowId(workflow.getId());
                                 tranSettlementReportService.updateById(tranSettlementReport);
-                                workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
                             }
                         }
-                        // 退回的单子 再启用
-                        else {
-
-                            tranSettlementReportService.updateById(tranSettlementReport);
-                            workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
-                        }
                     }
+                    //运费大于0生成运费结算报表数据
+//                    if (warehouseInOutInfo.getFreight() != null && warehouseInOutInfo.getFreight() > 0) {
+//                        //生成汽运报表
+//                        TranSettlementReport tranSettlementReport = new TranSettlementReport();
+//                        tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+//                        tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+//                        tranSettlementReport.setId(IdGenerator.generateUUID());
+//                        if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+//                            tranSettlementReport.setTranType("汽运");
+//                            tranSettlementReport.setTranTypeKey("1");
+//                        } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+//                            tranSettlementReport.setTranType("火运");
+//                            tranSettlementReport.setTranTypeKey("2");
+//                        } else {
+//                            tranSettlementReport.setTranType("船运");
+//                            tranSettlementReport.setTranTypeKey("3");
+//                        }
+//                        tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+//                        tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+//                        tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+//                        //应付
+//                        tranSettlementReport.setAmountIngPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+//                        //未付
+//                        tranSettlementReport.setAmountNotPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+//                        tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+//                        tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+//                        tranSettlementReport.setTransportPrice(Float.valueOf(warehouseInOutInfo.getFreight()));
+//                        tranSettlementReportService.insert(tranSettlementReport);
+//                        boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+//                        // 不是退回的单子
+//                        if (isStartWorkflow) {
+//                            Workflow workflow = workflowService
+//                                    .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+//                            // 没配置审核流程,直接结束并处理信息
+//                            if (workflow == null) {
+//                                throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+//                            }
+//                            // 开启审核流
+//                            else {
+//
+//                                // 设置状态 已提交审核
+//                                tranSettlementReport.setWorkflowId(workflow.getId());
+//                                tranSettlementReportService.updateById(tranSettlementReport);
+//                                workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+//                            }
+//                        }
+//                        // 退回的单子 再启用
+//                        else {
+//
+//                            tranSettlementReportService.updateById(tranSettlementReport);
+//                            workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
+//                        }
+//                    }
                     TranCarInfo tranCarInfo = tranCarInfoService.selectById(warehouseInOutInfo.getCarId());
                     if (tranCarInfo != null) {
                         //将发货数据同步到派车表
@@ -1585,6 +1778,14 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                 else if ("1".equals(warehouseInOutInfo.getInOutFlag()) && "2".equals(warehouseBaseInfo.getWarehouseType())) {
                     //临时库销售出库类型 且为自动创建的临时库时(采购报表进数据,销售报表也进数据)
                     if ("1".equals(warehouseInOutInfo.getInOutTypeKey()) && "1".equals(warehouseBaseInfo.getCreateType())) {
+                        //更新合同销售库存
+                        ContractInventoryDistribution contractInventoryDistribution1=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                .eq("comp_id",warehouseBaseInfo.getCompId()).eq("inventory_type","1").eq("contract_no",warehouseInOutInfo.getContractNo())
+                                .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                        if (contractInventoryDistribution1!=null){
+                            contractInventoryDistribution1.setSaleStorage(contractInventoryDistribution1.getSaleStorage()+warehouseInOutInfo.getNetWeight());
+                            contractInventoryDistributionService.updateById(contractInventoryDistribution1);
+                        }
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                                 .eq("contract_no", warehouseBaseInfo.getWarehouseName())
                                 .eq("deliver_type", "1")
@@ -1714,6 +1915,14 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                     }
                     //临时库移库出库类型 且为自动创建的临时库时进采购报表
                     if ("3".equals(warehouseInOutInfo.getInOutTypeKey()) && "1".equals(warehouseBaseInfo.getCreateType())) {
+                        //更新合同移库库存
+                        ContractInventoryDistribution contractInventoryDistribution1=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                .eq("comp_id",warehouseBaseInfo.getCompId()).eq("inventory_type","1").eq("contract_no",warehouseInOutInfo.getContractNo())
+                                .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                        if (contractInventoryDistribution1!=null){
+                            contractInventoryDistribution1.setRemoveStorage(contractInventoryDistribution1.getRemoveStorage()+warehouseInOutInfo.getNetWeight());
+                            contractInventoryDistributionService.updateById(contractInventoryDistribution1);
+                        }
                         //按出库重量结算
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                                 .eq("contract_no", warehouseBaseInfo.getWarehouseName())
@@ -1826,6 +2035,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                         .eq("info_id", tranTaskInfo.getId()));
                                 tranCarInfo.setProcessId(tranProcessInfo.getId());
                                 tranCarInfo.setTranPrice(String.valueOf(tranProcessInfo.getTranPrice() != null ? tranProcessInfo.getTranPrice() : 0f));
+                                warehouseInOutInfo.setFreight(tranProcessInfo.getTranPrice());
                                 tranCarInfo.setInfoId(tranTaskInfo.getId());
                             } else {
                                 throw new YException(YExceptionEnum.TRANTASK_NOT_CREATED_ERROR);
@@ -1866,6 +2076,59 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                             warehouseInOutInfo.setTranCarNo(tranCarNo);
                             warehouseInOutInfoService.updateById(warehouseInOutInfo);
                             tranCarInfoService.insert(tranCarInfo);
+                            //生成汽运报表
+                            TranSettlementReport tranSettlementReport = new TranSettlementReport();
+                            tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+                            tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+                            tranSettlementReport.setId(IdGenerator.generateUUID());
+                            if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("汽运");
+                                tranSettlementReport.setTranTypeKey("1");
+                            } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("火运");
+                                tranSettlementReport.setTranTypeKey("2");
+                            } else {
+                                tranSettlementReport.setTranType("船运");
+                                tranSettlementReport.setTranTypeKey("3");
+                            }
+                            tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+                            tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+                            tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            //运输单价不为空
+                            if (warehouseInOutInfo.getFreight()!=null){
+                                //应付
+                                tranSettlementReport.setAmountIngPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                //未付
+                                tranSettlementReport.setAmountNotPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                tranSettlementReport.setTransportPrice(Float.valueOf(warehouseInOutInfo.getFreight()));
+                            }
+                            tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+                            tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            tranSettlementReportService.insert(tranSettlementReport);
+                            boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+                            // 不是退回的单子
+                            if (isStartWorkflow) {
+                                Workflow workflow = workflowService
+                                        .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+                                // 没配置审核流程,直接结束并处理信息
+                                if (workflow == null) {
+                                    throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                                }
+                                // 开启审核流
+                                else {
+
+                                    // 设置状态 已提交审核
+                                    tranSettlementReport.setWorkflowId(workflow.getId());
+                                    tranSettlementReportService.updateById(tranSettlementReport);
+                                    workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                }
+                            }
+                            // 退回的单子 再启用
+                            else {
+
+                                tranSettlementReportService.updateById(tranSettlementReport);
+                                workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
+                            }
                         }
                     }
                     if (warehouseBaseInfo != null) {
@@ -1891,6 +2154,9 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                 }
             }
         }
+        cacheComponent.delPrefixKey(Const.ADMIN_CONTRACTINFO);
+        cacheComponent.delPrefixKey(Const.ADMIN_WEIGHINGINFO);
+        cacheComponent.delPrefixKey(Const.ADMIN_WEIGHINGINFO_NUM);
         return warehouseInOutInfo.getId();
     }
 
@@ -2052,8 +2318,6 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
     @Override
     @Transactional(rollbackFor = Exception.class)
     public String insertOrUpdateInOutTask(WarehouseInOutInfo warehouseInOutInfo) {
-
-        cacheComponent.delPrefixKey(Const.ADMIN_CONTRACTINFO);
         // 根据传参id判断是否是新增
         //  空是新增
         if (StringUtils.isEmpty(warehouseInOutInfo.getId())) {
@@ -3197,6 +3461,36 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                 }
                             }
                         }
+                        //入库时更新汽运报表卸车数据
+                        TranSettlementReport tranSettlementReport = tranSettlementReportService.selectOne(new EntityWrapper<TranSettlementReport>()
+                                .eq("car_id", warehouseInOutInfo.getCarId()));
+                        if (tranSettlementReport!=null) {
+                            tranSettlementReport.setUnloadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            tranSettlementReport.setUnloadingImg(warehouseInOutInfo.getAddressUrl());
+                                //损耗
+                            tranSettlementReport.setLossWeight(tranSettlementReport.getLoadingWeight() - tranSettlementReport.getUnloadingWeight());
+                                //汽运类型
+                                if (tranSettlementReport.getTranTypeKey().equals(NumberConstant.CONSTANT1)) {
+                                    //结算重量
+                                    if ("0".equals(tranSettlementReport.getManualFlag())) {
+                                        //卸车不为空时,结算重量=装卸取小
+                                        tranSettlementReport.setSettlementWeight(tranSettlementReport.getLoadingWeight() > tranSettlementReport.getUnloadingWeight() ? tranSettlementReport.getUnloadingWeight() : tranSettlementReport.getLoadingWeight());
+                                    }
+                                    if (tranSettlementReport.getTransportPrice()!=null) {
+                                        //扣款
+                                        if (tranSettlementReport.getLossWeight() <= (tranSettlementReport.getLoadingWeight() / 1000)) {
+                                            tranSettlementReport.setDeductionAmount("0");
+                                            //应付=单价x结算重量-扣款
+                                            tranSettlementReport.setAmountIngPayable(tranSettlementReport.getTransportPrice() * tranSettlementReport.getSettlementWeight());
+                                        } else {
+                                            tranSettlementReport.setDeductionAmount(String.format("%.2f", (Float.valueOf(tranSettlementReport.getLoadingWeight() - tranSettlementReport.getUnloadingWeight()) - (tranSettlementReport.getLoadingWeight() / 1000)) * Float.valueOf(tranSettlementReport.getTransportPrice())));
+                                            //应付=单价x结算重量-扣款
+                                            tranSettlementReport.setAmountIngPayable(tranSettlementReport.getTransportPrice() * tranSettlementReport.getSettlementWeight() - Float.valueOf(tranSettlementReport.getDeductionAmount()));
+                                        }
+                                    }
+                                }
+                                tranSettlementReportService.updateById(tranSettlementReport);
+                        }
                     }
 
                     //常用库退库入库类型
@@ -3740,6 +4034,59 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                         warehouseInOutInfoService.updateById(warehouseInOutInfo);
                                         tranCarInfoService.insert(tranCarInfo);
                                     }
+                                    //生成汽运报表
+                                    TranSettlementReport tranSettlementReport = new TranSettlementReport();
+                                    tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+                                    tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+                                    tranSettlementReport.setId(IdGenerator.generateUUID());
+                                    if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+                                        tranSettlementReport.setTranType("汽运");
+                                        tranSettlementReport.setTranTypeKey("1");
+                                    } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+                                        tranSettlementReport.setTranType("火运");
+                                        tranSettlementReport.setTranTypeKey("2");
+                                    } else {
+                                        tranSettlementReport.setTranType("船运");
+                                        tranSettlementReport.setTranTypeKey("3");
+                                    }
+                                    tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+                                    tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+                                    tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                                    //运输单价不为空
+                                    if (tranProcessInfo.getTranPrice()!=null){
+                                        //应付
+                                        tranSettlementReport.setAmountIngPayable(Float.valueOf(tranProcessInfo.getTranPrice()) * tranSettlementReport.getSettlementWeight());
+                                        //未付
+                                        tranSettlementReport.setAmountNotPayable(Float.valueOf(tranProcessInfo.getTranPrice()) * tranSettlementReport.getSettlementWeight());
+                                        tranSettlementReport.setTransportPrice(Float.valueOf(tranProcessInfo.getTranPrice()));
+                                    }
+                                    tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+                                    tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                                    tranSettlementReportService.insert(tranSettlementReport);
+                                    boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+                                    // 不是退回的单子
+                                    if (isStartWorkflow) {
+                                        Workflow workflow = workflowService
+                                                .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+                                        // 没配置审核流程,直接结束并处理信息
+                                        if (workflow == null) {
+                                            throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                                        }
+                                        // 开启审核流
+                                        else {
+
+                                            // 设置状态 已提交审核
+                                            tranSettlementReport.setWorkflowId(workflow.getId());
+                                            tranSettlementReportService.updateById(tranSettlementReport);
+                                            workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                        }
+                                    }
+                                    // 退回的单子 再启用
+                                    else {
+
+                                        tranSettlementReportService.updateById(tranSettlementReport);
+                                        workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
+                                    }
                                 }
                             } else {
                                 throw new YException(YExceptionEnum.TRANTASK_NOT_CREATED_ERROR);
@@ -3813,6 +4160,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                     tranCarInfo.setProcessId(tranProcessInfo.getId());
                                     tranCarInfo.setInfoId(tranTaskInfo.getId());
                                     tranCarInfo.setTranPrice(String.valueOf(tranProcessInfo.getTranPrice() != null ? tranProcessInfo.getTranPrice() : 0f));
+                                    warehouseInOutInfo.setFreight(tranProcessInfo.getTranPrice());
                                 } else {
                                     throw new YException(YExceptionEnum.TRANTASK_NOT_CREATED_ERROR);
                                 }
@@ -3843,6 +4191,59 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                 warehouseInOutInfoService.updateById(warehouseInOutInfo);
                                 tranCarInfoService.insert(tranCarInfo);
                             }
+                            //生成汽运报表
+                            TranSettlementReport tranSettlementReport = new TranSettlementReport();
+                            tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+                            tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+                            tranSettlementReport.setId(IdGenerator.generateUUID());
+                            if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("汽运");
+                                tranSettlementReport.setTranTypeKey("1");
+                            } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("火运");
+                                tranSettlementReport.setTranTypeKey("2");
+                            } else {
+                                tranSettlementReport.setTranType("船运");
+                                tranSettlementReport.setTranTypeKey("3");
+                            }
+                            tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+                            tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+                            tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            //运输单价不为空
+                            if (warehouseInOutInfo.getFreight()!=null){
+                                //应付
+                                tranSettlementReport.setAmountIngPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                //未付
+                                tranSettlementReport.setAmountNotPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                tranSettlementReport.setTransportPrice(Float.valueOf(warehouseInOutInfo.getFreight()));
+                            }
+                            tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+                            tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            tranSettlementReportService.insert(tranSettlementReport);
+                            boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+                            // 不是退回的单子
+                            if (isStartWorkflow) {
+                                Workflow workflow = workflowService
+                                        .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+                                // 没配置审核流程,直接结束并处理信息
+                                if (workflow == null) {
+                                    throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                                }
+                                // 开启审核流
+                                else {
+
+                                    // 设置状态 已提交审核
+                                    tranSettlementReport.setWorkflowId(workflow.getId());
+                                    tranSettlementReportService.updateById(tranSettlementReport);
+                                    workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                }
+                            }
+                            // 退回的单子 再启用
+                            else {
+
+                                tranSettlementReportService.updateById(tranSettlementReport);
+                                workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
+                            }
                         }
                     }
                     if (warehouseInOutInfo.getWeighingManagement() != null) {
@@ -4014,6 +4415,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                             contractInventoryDistribution1.setSaleStorage(contractInventoryDistribution1.getSaleStorage()+warehouseInOutInfo.getNetWeight());
                             contractInventoryDistributionService.updateById(contractInventoryDistribution1);
                         }
+                        //自运销售合同
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                                 .eq("contract_no", warehouseBaseInfo.getWarehouseName())
                                 .eq("deliver_type", "1")
@@ -4065,6 +4467,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                 workflowService.activateInstance(stockPurchaseReceiptReport.getWorkflowId(), stockPurchaseReceiptReport.getId());
                             }
                         }
+                        //他运销售合同
                         ContractManagementInfo contractManagementInfoSale = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                                 .eq("contract_no", warehouseInOutInfo.getContractNo())
                                 .eq("deliver_type", "2")
@@ -4286,6 +4689,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                                         .eq("info_id", tranTaskInfo.getId()));
                                 tranCarInfo.setProcessId(tranProcessInfo.getId());
                                 tranCarInfo.setTranPrice(String.valueOf(tranProcessInfo.getTranPrice() != null ? tranProcessInfo.getTranPrice() : 0f));
+                                warehouseInOutInfo.setFreight(tranProcessInfo.getTranPrice());
                                 tranCarInfo.setInfoId(tranTaskInfo.getId());
                             } else {
                                 throw new YException(YExceptionEnum.TRANTASK_NOT_CREATED_ERROR);
@@ -4326,6 +4730,59 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                             warehouseInOutInfo.setTranCarNo(tranCarNo);
                             warehouseInOutInfoService.updateById(warehouseInOutInfo);
                             tranCarInfoService.insert(tranCarInfo);
+                            //生成汽运报表
+                            TranSettlementReport tranSettlementReport = new TranSettlementReport();
+                            tranSettlementReport.setCompId(warehouseBaseInfo.getCompId());
+                            tranSettlementReport.setCarId(warehouseInOutInfo.getCarId());
+                            tranSettlementReport.setId(IdGenerator.generateUUID());
+                            if ("汽运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("汽运");
+                                tranSettlementReport.setTranTypeKey("1");
+                            } else if ("火运".equals(warehouseInOutInfo.getOutType())) {
+                                tranSettlementReport.setTranType("火运");
+                                tranSettlementReport.setTranTypeKey("2");
+                            } else {
+                                tranSettlementReport.setTranType("船运");
+                                tranSettlementReport.setTranTypeKey("3");
+                            }
+                            tranSettlementReport.setContractNo(warehouseInOutInfo.getContractNo());
+                            tranSettlementReport.setCarNo(warehouseInOutInfo.getCarNo());
+                            tranSettlementReport.setSettlementWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            //运输单价不为空
+                            if (warehouseInOutInfo.getFreight()!=null){
+                                //应付
+                                tranSettlementReport.setAmountIngPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                //未付
+                                tranSettlementReport.setAmountNotPayable(Float.valueOf(warehouseInOutInfo.getFreight()) * tranSettlementReport.getSettlementWeight());
+                                tranSettlementReport.setTransportPrice(Float.valueOf(warehouseInOutInfo.getFreight()));
+                            }
+                            tranSettlementReport.setLoadingImg(warehouseInOutInfo.getAddressUrl());
+                            tranSettlementReport.setLoadingWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
+                            tranSettlementReportService.insert(tranSettlementReport);
+                            boolean isStartWorkflow = org.apache.commons.lang3.StringUtils.isBlank(tranSettlementReport.getWorkflowId());
+                            // 不是退回的单子
+                            if (isStartWorkflow) {
+                                Workflow workflow = workflowService
+                                        .findLatestWorkflowByBusinessCodeByApp(tranSettlementReport.getCompId(), "TRANSPORTATION-SETTLEMENT-REPORT");
+                                // 没配置审核流程,直接结束并处理信息
+                                if (workflow == null) {
+                                    throw new YException(YExceptionEnum.PURCHASE_ORDER_ERROR);
+                                }
+                                // 开启审核流
+                                else {
+
+                                    // 设置状态 已提交审核
+                                    tranSettlementReport.setWorkflowId(workflow.getId());
+                                    tranSettlementReportService.updateById(tranSettlementReport);
+                                    workflowService.startInstance(workflow.getId(), tranSettlementReport.getId());
+                                }
+                            }
+                            // 退回的单子 再启用
+                            else {
+
+                                tranSettlementReportService.updateById(tranSettlementReport);
+                                workflowService.activateInstance(tranSettlementReport.getWorkflowId(), tranSettlementReport.getId());
+                            }
                         }
                     }
                     if (warehouseBaseInfo != null) {
@@ -4340,6 +4797,7 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                 }
             }
         }
+        cacheComponent.delPrefixKey(Const.ADMIN_CONTRACTINFO);
         cacheComponent.delPrefixKey(Const.ADMIN_WEIGHINGINFO);
         cacheComponent.delPrefixKey(Const.ADMIN_WEIGHINGINFO_NUM);
         return warehouseInOutInfo.getWeighingManagement().getId();