zhangyuewww 2 gadi atpakaļ
vecāks
revīzija
81889d49de

+ 15 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/entity/WarehousingOrder.java

@@ -300,6 +300,21 @@ public class WarehousingOrder extends BaseModel<WarehousingOrder> {
      */
     @TableField(exist = false)
     private Double money;
+    /**
+     * 出入库任务编号
+     */
+    @TableField(exist = false)
+    private String inOutTaskNo;
+    /**
+     * 发货库
+     */
+    @TableField(exist = false)
+    private String sendWarehouseName;
+    /**
+     * 移库出库任务号
+     */
+    @TableField(exist = false)
+    private String sendTaskId;
 
     @Override
     protected Serializable pkVal() {

+ 14 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/mapper/WarehousingOrderMapper.java

@@ -44,6 +44,20 @@ public interface WarehousingOrderMapper extends BaseMapper<WarehousingOrder> {
      * @return
      */
     List<WarehousingOrder> getPurchaseListByCondition(Map<String, Object> pageView);
+    /**
+     * 移库入库单
+     *
+     * @param pageView
+     * @return
+     */
+    List<WarehousingOrder> getMoveListByCondition(Map<String, Object> pageView);
+    /**
+     * 退库入库单
+     *
+     * @param pageView
+     * @return
+     */
+    List<WarehousingOrder> getReturnListByCondition(Map<String, Object> pageView);
     /**
      * 根据条件查询货源总数
      *

+ 1 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/ContractManagementInfoServiceImpl.java

@@ -204,6 +204,7 @@ public class ContractManagementInfoServiceImpl extends ServiceImpl<ContractManag
             warehousingOrder.setCustomer(contractManagementInfo.getSeller());
             warehousingOrder.setAvgCost(contractManagementInfo.getUnitContractPrice());
             warehousingOrder.setCompId(contractManagementInfo.getCompId());
+            warehousingOrder.setDeliveryWarehouse(contractManagementInfo.getContractNo());
             warehousingOrder.setGoodsName(contractManagementInfo.getContractGoodsInfo().getGoodsName());
             warehousingOrder.setContractNo(contractManagementInfo.getContractNo());
             warehousingOrder.setInWarehouseWeight(contractManagementInfo.getFinalTradingVolume());

+ 11 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/InOutWarehouseTaskServiceImpl.java

@@ -618,6 +618,16 @@ public class InOutWarehouseTaskServiceImpl extends ServiceImpl<InOutWarehouseTas
                     .orderBy("update_date", false));
             inOutWarehouseTaskList=inOutWarehouseTaskList1;
         }
+        //收购入库
+        else if("3".equals(inOutWarehouseTask.getFlag())){
+            List<InOutWarehouseTask> inOutWarehouseTaskList1 = this.selectList(new EntityWrapper<InOutWarehouseTask>()
+                    .eq("comp_id", AuthSecurityUtils.getCurrentUserInfo().getCompId())
+                    .eq("task_status_key", "5")
+                    .eq("warehouse_name", inOutWarehouseTask.getWarehouseName())
+                    .eq("in_out_type","收购入库")
+                    .orderBy("update_date", false));
+            inOutWarehouseTaskList=inOutWarehouseTaskList1;
+        }
         //入库
         else {
             List<InOutWarehouseTask> inOutWarehouseTaskList1 = this.selectList(new EntityWrapper<InOutWarehouseTask>()
@@ -625,6 +635,7 @@ public class InOutWarehouseTaskServiceImpl extends ServiceImpl<InOutWarehouseTas
                     .eq("task_status_key", "5")
                     .eq("warehouse_name", inOutWarehouseTask.getWarehouseName())
                     .ne("in_out_type","销售出库")
+                    .ne("in_out_type","收购入库")
                     .ne("in_out_type","移库出库")
                     .orderBy("update_date", false));
             inOutWarehouseTaskList=inOutWarehouseTaskList1;

+ 44 - 4
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/TranSettlementReportServiceImpl.java

@@ -23,10 +23,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.text.SimpleDateFormat;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -58,6 +56,8 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
     private ITranProcessInfoService tranProcessInfoService;
     @Autowired
     private IInOutWarehouseTaskService inOutWarehouseTaskService;
+    @Autowired
+    private IExpenseInfoService expenseInfoService;
 
 
 
@@ -323,6 +323,46 @@ public class TranSettlementReportServiceImpl extends ServiceImpl<TranSettlementR
         Float money = tranSettlementReport.getMoney();
         //付款多条
         if (!CollectionUtils.isEmpty(tranSettlementReportList)) {
+            ExpenseInfo expenseInfo=new ExpenseInfo();
+            expenseInfo.setId(IdGenerator.generateUUID());
+            expenseInfo.setCompId(tranSettlementReportList.get(0).getCompId());
+            expenseInfo.setAmountMoney(Double.valueOf(String.valueOf(money)));
+            expenseInfo.setExpensesType("2");
+            expenseInfo.setExpenseName("运费");
+            SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
+            Integer num=expenseInfoService.expenseCount(expenseInfo);
+            String no = "YF"+df.format(new Date())+(num+1);
+            expenseInfo.setCostNo(no);
+            InOutWarehouseTask inOutWarehouseTask=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                    .eq("comp_id",tranSettlementReportList.get(0).getCompId())
+                    .eq("contract_no",tranSettlementReportList.get(0).getContractNo()));
+            if (inOutWarehouseTask!=null){
+                if ("销售出库".equals(inOutWarehouseTask.getInOutType())){
+                    expenseInfo.setCostType("运费-销售");
+                }
+                else if ("退库".equals(inOutWarehouseTask.getInOutType())){
+                    expenseInfo.setCostType("运费-退库");
+                }
+            }
+            else {
+                InOutWarehouseTask inOutWarehouseTask1=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                        .eq("comp_id",tranSettlementReportList.get(0).getCompId())
+                        .eq("in_out_flag","1")
+                        .eq("move_task_no",tranSettlementReportList.get(0).getContractNo()));
+                if (inOutWarehouseTask1!=null){
+                    if ("移库出库".equals(inOutWarehouseTask1.getInOutType())){
+                        expenseInfo.setCostType("运费-移库");
+                        expenseInfo.setWarehouseName(inOutWarehouseTask1.getWarehouseName());
+                    }
+                }
+            }
+            expenseInfo.setExpensesPurpose(tranSettlementReportList.get(0).getContractNo());
+            expenseInfo.setAgent(AuthSecurityUtils.getStaffById(AuthSecurityUtils.getCurrentUserId()).getStaffName());
+            expenseInfo.setStatusFlag(StatusEnum.COST_PAID.getFlag());
+            expenseInfo.setStatus(StatusEnum.COST_PAID.getName());
+            expenseInfo.setAddressUrl(tranSettlementReport.getPaymentScreenshot());
+            expenseInfo.setUnallocatedAmount(Double.valueOf(String.valueOf(money)));
+            expenseInfoService.insert(expenseInfo);
             //汽运
             if ("1".equals(tranSettlementReportList.get(0).getTranTypeKey())){
                 for (TranSettlementReport tranSettlementReport1 : tranSettlementReportList) {

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

@@ -101,6 +101,8 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
     @Autowired
     private IInOutWarehouseTaskService inOutWarehouseTaskService;
     @Autowired
+    private IWarehousingOrderService warehousingOrderService;
+    @Autowired
     private ITranTaskInfoService tranTaskInfoService;
     @Autowired
     private ITranProcessInfoService tranProcessInfoService;
@@ -922,37 +924,37 @@ 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);
-
-                                }
-                            }
+//                            //常用库之间的移库
+//                            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>()
@@ -1244,13 +1246,44 @@ 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);
+                        //查出库任务关联的货源
+                        InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                .eq("in_out_task_no", warehouseInOutInfo.getInOutTaskNo()));
+                        List<SourceRelationInfo> sourceRelationInfoList =sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                                .eq("task_id", inOutWarehouseTask.getId())
+                                .eq("delete_flag", "0"));
+                        if (!CollectionUtils.isEmpty(sourceRelationInfoList)){
+                            for (SourceRelationInfo sourceRelationInfo:sourceRelationInfoList){
+                                //查货源关联的入库单
+                                WarehousingOrder warehousingOrder=warehousingOrderService.selectById(sourceRelationInfo.getSourceId());
+                                if ("采购入库".equals(warehousingOrder.getInType())){
+                                    //更新采购合同库存销售量
+                                    ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                            .eq("comp_id",warehousingOrder.getCompId()).eq("inventory_type","1").eq("contract_no",warehousingOrder.getContractNo())
+                                            .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                                    if (contractInventoryDistribution!=null){
+                                        contractInventoryDistribution.setInStorage(contractInventoryDistribution.getInStorage()-warehouseInOutInfo.getNetWeight()*sourceRelationInfo.getProportion());
+                                        contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                                    }
+                                }
+                                else if ("收购入库".equals(warehousingOrder.getInType())){
+                                    //查收购合同原始货源仓库
+                                    InOutWarehouseTask inOutWarehouseTask1=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                            .eq("comp_id", warehousingOrder.getCompId())
+                                            .eq("contract_no", warehousingOrder.getContractNo())
+                                            .eq("delete_flag", "0"));
+                                    //更新收货库库点库存剩余量 (所在仓库为出货库、所属仓库为原始货源仓库、货名一致)
+                                    ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                            .eq("comp_id",warehousingOrder.getCompId()).eq("inventory_type","3").eq("locus_warehouse",warehouseInOutInfo.getWarehouseName())
+                                            .eq("warehouse",inOutWarehouseTask1.getWarehouseName())
+                                            .eq("goods_name",warehouseInOutInfo.getGoodsName()));
+                                    if (contractInventoryDistribution!=null){
+                                        contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()-warehouseInOutInfo.getNetWeight()*sourceRelationInfo.getProportion());
+                                        contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                                    }
+                                }
+                            }
+
                         }
                         //他运的销售合同
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
@@ -1522,28 +1555,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);
-                        }
+//                        //更新合同移库库存
+//                        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);
-                            }
+//                            //更新所属仓库收购库存
+//                            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>()
@@ -1778,13 +1811,28 @@ 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);
+                        //查出库任务关联的货源
+                        InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                .eq("in_out_task_no", warehouseInOutInfo.getInOutTaskNo()));
+                        List<SourceRelationInfo> sourceRelationInfoList =sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                                .eq("task_id", inOutWarehouseTask.getId())
+                                .eq("delete_flag", "0"));
+                        if (!CollectionUtils.isEmpty(sourceRelationInfoList)){
+                            for (SourceRelationInfo sourceRelationInfo:sourceRelationInfoList){
+                                //查货源关联的入库单
+                                WarehousingOrder warehousingOrder=warehousingOrderService.selectById(sourceRelationInfo.getSourceId());
+                                //临时库只有采购入库情况
+                                if ("采购入库".equals(warehousingOrder.getInType())){
+                                    //更新采购合同库存销售量
+                                    ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                            .eq("comp_id",warehousingOrder.getCompId()).eq("inventory_type","1").eq("contract_no",warehousingOrder.getContractNo())
+                                            .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                                    if (contractInventoryDistribution!=null){
+                                        contractInventoryDistribution.setInStorage(contractInventoryDistribution.getInStorage()-warehouseInOutInfo.getNetWeight()*sourceRelationInfo.getProportion());
+                                        contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                                    }
+                                }
+                            }
                         }
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
                                 .eq("contract_no", warehouseBaseInfo.getWarehouseName())
@@ -1915,14 +1963,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);
-                        }
+//                        //更新合同移库库存
+//                        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())
@@ -3430,36 +3478,36 @@ 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);
-
-                                }
-                            }
+//                            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>()
@@ -3840,13 +3888,43 @@ 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);
+                        //查出库任务关联的货源
+                        InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                .eq("in_out_task_no", warehouseInOutInfo.getInOutTaskNo()));
+                        List<SourceRelationInfo> sourceRelationInfoList =sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                                .eq("task_id", inOutWarehouseTask.getId())
+                                .eq("delete_flag", "0"));
+                        if (!CollectionUtils.isEmpty(sourceRelationInfoList)){
+                            for (SourceRelationInfo sourceRelationInfo:sourceRelationInfoList){
+                                //查货源关联的入库单
+                                WarehousingOrder warehousingOrder=warehousingOrderService.selectById(sourceRelationInfo.getSourceId());
+                                if ("采购入库".equals(warehousingOrder.getInType())){
+                                    //更新采购合同库存销售量
+                                    ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                            .eq("comp_id",warehousingOrder.getCompId()).eq("inventory_type","1").eq("contract_no",warehousingOrder.getContractNo())
+                                            .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                                    if (contractInventoryDistribution!=null){
+                                        contractInventoryDistribution.setInStorage(contractInventoryDistribution.getInStorage()-warehouseInOutInfo.getNetWeight()*sourceRelationInfo.getProportion());
+                                        contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                                    }
+                                }
+                                else if ("收购入库".equals(warehousingOrder.getInType())){
+                                    //查收购合同原始货源仓库
+                                    InOutWarehouseTask inOutWarehouseTask1=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                            .eq("comp_id", warehousingOrder.getCompId())
+                                            .eq("contract_no", warehousingOrder.getContractNo())
+                                            .eq("delete_flag", "0"));
+                                    //更新收货库库点库存剩余量 (所在仓库为出货库、所属仓库为原始货源仓库、货名一致)
+                                    ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                            .eq("comp_id",warehousingOrder.getCompId()).eq("inventory_type","3").eq("locus_warehouse",warehouseInOutInfo.getWarehouseName())
+                                            .eq("warehouse",inOutWarehouseTask1.getWarehouseName())
+                                            .eq("goods_name",warehouseInOutInfo.getGoodsName()));
+                                    if (contractInventoryDistribution!=null){
+                                        contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()-warehouseInOutInfo.getNetWeight()*sourceRelationInfo.getProportion());
+                                        contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                                    }
+                                }
+                            }
                         }
                         //检斤表
                         WeighingManagement weighingManagement = weighingManagementService.selectOne(new EntityWrapper<WeighingManagement>()
@@ -4125,27 +4203,27 @@ 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);
-                        }
+//                        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);
-                            }
+//                            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>()
@@ -4409,13 +4487,28 @@ public class WarehouseInOutInfoServiceImpl extends ServiceImpl<WarehouseInOutInf
                             .eq("delete_flag", "0"));
                     //临时库销售出库类型 且为自动创建的临时库时(采购报表进数据,销售报表也进数据)
                     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);
+                        //查出库任务关联的货源
+                        InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                .eq("in_out_task_no", warehouseInOutInfo.getInOutTaskNo()));
+                        List<SourceRelationInfo> sourceRelationInfoList =sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                                .eq("task_id", inOutWarehouseTask.getId())
+                                .eq("delete_flag", "0"));
+                        if (!CollectionUtils.isEmpty(sourceRelationInfoList)){
+                            for (SourceRelationInfo sourceRelationInfo:sourceRelationInfoList){
+                                //查货源关联的入库单
+                                WarehousingOrder warehousingOrder=warehousingOrderService.selectById(sourceRelationInfo.getSourceId());
+                                //临时库只有采购入库情况
+                                if ("采购入库".equals(warehousingOrder.getInType())){
+                                    //更新采购合同库存销售量
+                                    ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                            .eq("comp_id",warehousingOrder.getCompId()).eq("inventory_type","1").eq("contract_no",warehousingOrder.getContractNo())
+                                            .eq("warehouse",warehouseInOutInfo.getWarehouseName()));
+                                    if (contractInventoryDistribution!=null){
+                                        contractInventoryDistribution.setInStorage(contractInventoryDistribution.getInStorage()-warehouseInOutInfo.getNetWeight()*sourceRelationInfo.getProportion());
+                                        contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                                    }
+                                }
+                            }
                         }
                         //自运销售合同
                         ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
@@ -4550,13 +4643,13 @@ 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);
-                        }
+//                        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())

+ 211 - 95
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/WarehousingOrderServiceImpl.java

@@ -261,58 +261,60 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
         Map<String, Object> pageView = new HashMap<>();
         pageView.put("beforeDay", beforeDay);
         //成本
-        List<WarehousingOrder> costList = baseMapper.getGoodCostListByCondition(pageView);
+//        List<WarehousingOrder> costList = baseMapper.getGoodCostListByCondition(pageView);
         //收购
         List<WarehousingOrder> dataList = baseMapper.getAcquisitionListByCondition(pageView);
         if (!CollectionUtils.isEmpty(dataList)){
             for (WarehousingOrder warehousingOrder1:dataList) {
-                if(warehousingOrder1.getGoodsName().contains("玉米")&&!warehousingOrder1.getGoodsName().contains("潮粮")){
-                    costList.forEach(warehousingOrder -> {
-                        if ("玉米".equals(warehousingOrder.getGoodsName())){
-                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
-                        }
-                    });
-                }
-                else {
-                    costList.forEach(warehousingOrder -> {
-                        if (warehousingOrder1.getGoodsName().equals(warehousingOrder.getGoodsName())){
-                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
-                        }
-                    });
-                }
+//                if(warehousingOrder1.getGoodsName().contains("玉米")&&!warehousingOrder1.getGoodsName().contains("潮粮")){
+//                    costList.forEach(warehousingOrder -> {
+//                        if ("玉米".equals(warehousingOrder.getGoodsName())){
+//                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
+//                        }
+//                    });
+//                }
+//                else {
+//                    costList.forEach(warehousingOrder -> {
+//                        if (warehousingOrder1.getGoodsName().equals(warehousingOrder.getGoodsName())){
+//                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
+//                        }
+//                    });
+//                }
                 List<PaymentManagement> paymentManagementList = paymentManagementService.selectList(new EntityWrapper<PaymentManagement>()
                         .eq("customer_name",warehousingOrder1.getGoodsSource())
-                        .eq("warehouse_name",warehousingOrder1.getWarehouseName())
+                        .eq("contract_no",warehousingOrder1.getContractNo())
                         .eq("goods_name",warehousingOrder1.getGoodsName())
                         .ne("status", "待结算")
-                        .ge("update_date", beforeDay));
+                        .ge("settlement_date", beforeDay));
                 WarehousingOrder warehousingOrder = new WarehousingOrder();
                 warehousingOrder.setId(IdGenerator.generateUUID());
                 warehousingOrder.setBaseId(warehousingOrder1.getBaseId());
+                warehousingOrder.setContractNo(warehousingOrder1.getContractNo());
                 warehousingOrder.setIdentifyId(warehousingOrder1.getIdentifyId());
                 warehousingOrder.setWarehouseName(warehousingOrder1.getWarehouseName());
                 warehousingOrder.setGoodsSource(warehousingOrder1.getGoodsSource());
                 warehousingOrder.setCustomer(warehousingOrder1.getGoodsSource());
                 warehousingOrder.setCompId(warehousingOrder1.getCompId());
                 warehousingOrder.setGoodsName(warehousingOrder1.getGoodsName());
-                warehousingOrder.setAvgCost(warehousingOrder1.getAvgCost());
                 warehousingOrder.setInType("收购入库");
                 double weight = (paymentManagementList.stream().mapToDouble(PaymentManagement::getNetWeight).sum())/1000;
                 warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(weight)));
                 warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(weight)));
                 double money = paymentManagementList.stream().mapToDouble(PaymentManagement::getAmountIngPayable).sum();
+                //收购成本=总应付/总重量
+                warehousingOrder.setAvgCost(money/weight);
                 warehousingOrder.setAmountNotPayable(money);
                 warehousingOrder.setAmountEdPayable(0d);
                 warehousingOrder.setIssuingTime(new Date());
                 warehousingOrder.setGrainFund(money);
                 this.insert(warehousingOrder);
-                //更新收购库存
+                //更新库点库存 (所在仓库所属仓库货名一致)
                 ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
                     .eq("comp_id",warehousingOrder1.getCompId()).eq("inventory_type","3").eq("locus_warehouse",warehousingOrder1.getWarehouseName())
-                    .eq("warehouse_id",warehousingOrder1.getBaseId())
+                    .eq("warehouse",warehousingOrder1.getWarehouseName())
                     .eq("goods_name",warehousingOrder1.getGoodsName()));
                 if (contractInventoryDistribution!=null){
-                    contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()+warehousingOrder1.getInWarehouseWeight());
+                    contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()+weight);
                     contractInventoryDistributionService.updateById(contractInventoryDistribution);
                 }
                 else {
@@ -320,7 +322,7 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                     contractInventoryDistribution1.setId(IdGenerator.generateUUID());
                     contractInventoryDistribution1.setCompId(warehousingOrder1.getCompId());
                     contractInventoryDistribution1.setWarehouseId(warehousingOrder1.getBaseId());
-                    contractInventoryDistribution1.setInventory(Double.valueOf(String.valueOf(warehousingOrder.getInWarehouseWeight())));
+                    contractInventoryDistribution1.setInventory(weight);
                     contractInventoryDistribution1.setWarehouse(warehousingOrder1.getWarehouseName());
                     contractInventoryDistribution1.setLocusWarehouse(warehousingOrder1.getWarehouseName());
                     contractInventoryDistribution1.setGoodsName(warehousingOrder1.getGoodsName());
@@ -338,26 +340,26 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
             .eq("contract_no",dataList1.get(0).getContractNo())
             .eq("comp_id",dataList1.get(0).getCompId()));
             for (WarehousingOrder warehousingOrder1:dataList1) {
-                if(warehousingOrder1.getGoodsName().contains("玉米")&&!warehousingOrder1.getGoodsName().contains("潮粮")){
-                    costList.forEach(warehousingOrder -> {
-                        if ("玉米".equals(warehousingOrder.getGoodsName())){
-                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
-                        }
-                    });
-                }
-                else {
-                    costList.forEach(warehousingOrder -> {
-                        if (warehousingOrder1.getGoodsName().equals(warehousingOrder.getGoodsName())){
-                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
-                        }
-                    });
-                }
+//                if(warehousingOrder1.getGoodsName().contains("玉米")&&!warehousingOrder1.getGoodsName().contains("潮粮")){
+//                    costList.forEach(warehousingOrder -> {
+//                        if ("玉米".equals(warehousingOrder.getGoodsName())){
+//                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
+//                        }
+//                    });
+//                }
+//                else {
+//                    costList.forEach(warehousingOrder -> {
+//                        if (warehousingOrder1.getGoodsName().equals(warehousingOrder.getGoodsName())){
+//                            warehousingOrder1.setAvgCost(warehousingOrder.getAvgCost());
+//                        }
+//                    });
+//                }
                 List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                         .eq("status", "已提交")
                         .eq("contract_no",warehousingOrder1.getContractNo())
                         .eq("warehouse_name",warehousingOrder1.getWarehouseName())
                         .eq("in_out_type", "采购入库")
-                        .ge("update_date", beforeDay));
+                        .ge("in_out_date", beforeDay));
                 WarehousingOrder warehousingOrder = new WarehousingOrder();
                 warehousingOrder.setId(IdGenerator.generateUUID());
                 warehousingOrder.setBaseId(warehousingOrder1.getBaseId());
@@ -365,7 +367,6 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                 warehousingOrder.setGoodsSource(warehousingOrder1.getContractNo());
                 warehousingOrder.setInType("采购入库");
                 warehousingOrder.setCustomer(contractManagementInfo.getSeller());
-                warehousingOrder.setAvgCost(warehousingOrder1.getAvgCost());
                 warehousingOrder.setCompId(warehousingOrder1.getCompId());
                 warehousingOrder.setGoodsName(warehousingOrder1.getGoodsName());
                 warehousingOrder.setContractNo(warehousingOrder1.getContractNo());
@@ -377,6 +378,7 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                 }
                 warehousingOrder.setAmountNotPayable(money);
                 warehousingOrder.setAmountEdPayable(0d);
+                warehousingOrder.setAvgCost(money/weight);
                 warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(weight)));
                 warehousingOrder.setIssuingTime(new Date());
                 warehousingOrder.setGrainFund(money);
@@ -394,7 +396,7 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                     contractInventoryDistribution1.setId(IdGenerator.generateUUID());
                     contractInventoryDistribution1.setCompId(warehousingOrder1.getCompId());
                     contractInventoryDistribution1.setInStorage(Double.valueOf(String.valueOf(warehousingOrder.getInWarehouseWeight())));
-                    contractInventoryDistribution1.setWarehouse(warehousingOrder1.getContractNo());
+                    contractInventoryDistribution1.setWarehouse(warehousingOrder1.getWarehouseName());
                     contractInventoryDistribution1.setContractNo(warehousingOrder1.getContractNo());
                     contractInventoryDistribution1.setGoodsName(warehousingOrder1.getGoodsName());
                     contractInventoryDistribution1.setInventoryType("1");
@@ -404,65 +406,179 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
             }
         }
         //移库入库
-        List<WarehouseInOutInfo> warehouseInOutInfoList1 = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
-                .eq("status", "已提交")
-                .eq("in_out_type", "移库入库")
-                .ge("update_date", beforeDay));
-        if (!CollectionUtils.isEmpty(warehouseInOutInfoList1)) {
-            for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList1) {
-                WarehousingOrder warehousingOrder = new WarehousingOrder();
-                warehousingOrder.setId(IdGenerator.generateUUID());
-                warehousingOrder.setBaseId(warehouseInOutInfo.getBaseId());
-                InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
-                        .eq("in_out_task_no", warehouseInOutInfo.getInOutTaskNo()));
-                warehousingOrder.setMoveTaskNo(inOutWarehouseTask.getMoveTaskNo());
-                warehousingOrder.setWarehouseInOutId(warehouseInOutInfo.getId());
-                warehousingOrder.setWarehouseName(warehouseInOutInfo.getWarehouseName());
-                //货源为发货库
-                warehousingOrder.setGoodsSource(inOutWarehouseTask.getSendWarehouse());
-                warehousingOrder.setCompId(inOutWarehouseTask.getCompId());
-                warehousingOrder.setCarNo(warehouseInOutInfo.getCarNo());
-                warehousingOrder.setIssuingTime(new Date());
-                warehousingOrder.setDeliveryWarehouse(inOutWarehouseTask.getSendWarehouse());
-                warehousingOrder.setGoodsName(warehouseInOutInfo.getGoodsName());
-                warehousingOrder.setAvgCost(Double.valueOf(String.valueOf(warehouseInOutInfo.getCost())));
-                warehousingOrder.setInType("移库入库");
-                warehousingOrder.setContractNo(warehouseInOutInfo.getContractNo());
-                warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-                warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-                this.insert(warehousingOrder);
+        List<WarehousingOrder> dataList2 = baseMapper.getMoveListByCondition(pageView);
+        if (!CollectionUtils.isEmpty(dataList2)){
+            for (WarehousingOrder warehousingOrder1:dataList2) {
+                List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
+                        .eq("status", "已提交")
+                        .eq("in_out_task_no",warehousingOrder1.getInOutTaskNo())
+                        .eq("in_out_type", "移库入库")
+                        .ge("in_out_date", beforeDay));
+                double weight = warehouseInOutInfoList.stream().mapToDouble(WarehouseInOutInfo::getNetWeight).sum();
+                //查移库出库任务货源
+                List<SourceRelationInfo> sourceRelationInfoList =sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                        .eq("task_id", warehousingOrder1.getSendTaskId())
+                        .eq("delete_flag", "0"));
+                if (!CollectionUtils.isEmpty(sourceRelationInfoList)){
+                    for (SourceRelationInfo sourceRelationInfo:sourceRelationInfoList){
+                        //查货源关联的入库单
+                        WarehousingOrder warehousingOrder2=this.selectById(sourceRelationInfo.getSourceId());
+                        WarehousingOrder warehousingOrder = new WarehousingOrder();
+                        warehousingOrder.setId(IdGenerator.generateUUID());
+                        warehousingOrder.setBaseId(warehousingOrder1.getBaseId());
+                        warehousingOrder.setWarehouseName(warehousingOrder1.getWarehouseName());
+                        warehousingOrder.setInType("移库入库");
+                        warehousingOrder.setDeliveryWarehouse(warehousingOrder1.getSendWarehouseName());
+                        warehousingOrder.setMoveTaskNo(warehousingOrder1.getMoveTaskNo());
+                        warehousingOrder.setContractNo(warehousingOrder2.getContractNo());
+                        //取货源入库单成本
+                        warehousingOrder.setAvgCost(warehousingOrder2.getAvgCost());
+                        warehousingOrder.setCompId(warehousingOrder1.getCompId());
+                        warehousingOrder.setGoodsName(warehousingOrder1.getGoodsName());
+                        warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(weight*sourceRelationInfo.getProportion())));
+                        warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(weight*sourceRelationInfo.getProportion())));
+                        warehousingOrder.setIssuingTime(new Date());
+                        if ("采购入库".equals(warehousingOrder2.getInType())){
+                            warehousingOrder.setGoodsSource(warehousingOrder2.getContractNo());
+                            //更新入货库采购合同库存入库量
+                            ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                    .eq("comp_id",warehousingOrder1.getCompId()).eq("inventory_type","1").eq("contract_no",warehousingOrder2.getContractNo())
+                                    .eq("warehouse",warehousingOrder1.getWarehouseName()));
+                            if (contractInventoryDistribution!=null){
+                                contractInventoryDistribution.setInStorage(contractInventoryDistribution.getInStorage()+weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                            }
+                            else {
+                                ContractInventoryDistribution contractInventoryDistribution1=new ContractInventoryDistribution();
+                                contractInventoryDistribution1.setId(IdGenerator.generateUUID());
+                                contractInventoryDistribution1.setCompId(warehousingOrder1.getCompId());
+                                contractInventoryDistribution1.setInStorage(weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistribution1.setWarehouse(warehousingOrder1.getWarehouseName());
+                                contractInventoryDistribution1.setContractNo(warehousingOrder2.getContractNo());
+                                contractInventoryDistribution1.setGoodsName(warehousingOrder1.getGoodsName());
+                                contractInventoryDistribution1.setInventoryType("1");
+                                contractInventoryDistributionService.insert(contractInventoryDistribution1);
+
+                            }
+                            //更新出货库采购合同库存移出量
+                            ContractInventoryDistribution contractInventoryDistribution1=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                    .eq("comp_id",warehousingOrder1.getCompId()).eq("inventory_type","1").eq("contract_no",warehousingOrder2.getContractNo())
+                                    .eq("warehouse",warehousingOrder1.getSendWarehouseName()));
+                            if (contractInventoryDistribution1!=null){
+                                contractInventoryDistribution1.setRemoveStorage(contractInventoryDistribution1.getRemoveStorage()+weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistributionService.updateById(contractInventoryDistribution1);
+                            }
+                        }
+                        else if ("收购入库".equals(warehousingOrder2.getInType())){
+                            //查收购合同原始货源仓库
+                            InOutWarehouseTask inOutWarehouseTask=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                    .eq("comp_id", warehousingOrder2.getCompId())
+                                    .eq("contract_no", warehousingOrder2.getContractNo())
+                                    .eq("delete_flag", "0"));
+                            warehousingOrder.setGoodsSource(inOutWarehouseTask.getWarehouseName());
+                            //更新收货库库点库存 (所在仓库为入货库、所属仓库为原始货源仓库、货名一致)
+                            ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                    .eq("comp_id",warehousingOrder1.getCompId()).eq("inventory_type","3").eq("locus_warehouse",warehousingOrder1.getWarehouseName())
+                                    .eq("warehouse",inOutWarehouseTask.getWarehouseName())
+                                    .eq("goods_name",warehousingOrder1.getGoodsName()));
+                            if (contractInventoryDistribution!=null){
+                                contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()+weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                            }
+                            else {
+                                ContractInventoryDistribution contractInventoryDistribution1=new ContractInventoryDistribution();
+                                contractInventoryDistribution1.setId(IdGenerator.generateUUID());
+                                contractInventoryDistribution1.setCompId(warehousingOrder1.getCompId());
+                                contractInventoryDistribution1.setWarehouseId(warehousingOrder1.getBaseId());
+                                contractInventoryDistribution1.setInventory(weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistribution1.setWarehouse(warehousingOrder1.getWarehouseName());
+                                contractInventoryDistribution1.setLocusWarehouse(warehousingOrder1.getWarehouseName());
+                                contractInventoryDistribution1.setGoodsName(warehousingOrder1.getGoodsName());
+                                contractInventoryDistribution1.setInventoryType("3");
+                                contractInventoryDistributionService.insert(contractInventoryDistribution1);
+
+                            }
+                            //更新发货库库点库存 (所在仓库为发货库、所属仓库为原始货源仓库、货名一致)
+                            ContractInventoryDistribution contractInventoryDistribution1=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                    .eq("comp_id",warehousingOrder1.getCompId()).eq("inventory_type","3").eq("locus_warehouse",warehousingOrder1.getSendWarehouseName())
+                                    .eq("warehouse",warehousingOrder1.getSendWarehouseName())
+                                    .eq("goods_name",warehousingOrder1.getGoodsName()));
+                            if (contractInventoryDistribution1!=null){
+                                contractInventoryDistribution1.setInventory(contractInventoryDistribution1.getInventory()-weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistributionService.updateById(contractInventoryDistribution1);
+                            }
+                        }
+                        this.insert(warehousingOrder);
+                    }
+                }
             }
         }
-
         //退库
-        List<WarehouseInOutInfo> warehouseInOutInfoList2 = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
-                .eq("status", "已提交")
-                .eq("in_out_type", "退库")
-                .ge("update_date", beforeDay));
-        if (!CollectionUtils.isEmpty(warehouseInOutInfoList2)) {
-            for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList2) {
-                WarehousingOrder warehousingOrder = new WarehousingOrder();
-                warehousingOrder.setId(IdGenerator.generateUUID());
-                warehousingOrder.setBaseId(warehouseInOutInfo.getBaseId());
-                InOutWarehouseTask inOutWarehouseTask = inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
-                        .eq("in_out_task_no", warehouseInOutInfo.getInOutTaskNo()));
-                warehousingOrder.setWarehouseInOutId(warehouseInOutInfo.getId());
-                warehousingOrder.setWarehouseName(warehouseInOutInfo.getWarehouseName());
-                warehousingOrder.setStatusFlag(StatusEnum.PENDING_PAYMENT.getFlag());
-                warehousingOrder.setStatus(StatusEnum.PENDING_PAYMENT.getName());
-                //货源为发货库
-                warehousingOrder.setGoodsSource(inOutWarehouseTask.getAgent()+"(退)");
-                warehousingOrder.setCompId(inOutWarehouseTask.getCompId());
-                warehousingOrder.setCarNo(warehouseInOutInfo.getCarNo());
-                warehousingOrder.setIssuingTime(new Date());
-                warehousingOrder.setDeliveryWarehouse(warehouseInOutInfo.getCarNo());
-                warehousingOrder.setGoodsName(warehouseInOutInfo.getGoodsName());
-                warehousingOrder.setAvgCost(Double.valueOf(String.valueOf(warehouseInOutInfo.getCost())));
-                warehousingOrder.setInType("退库");
-                warehousingOrder.setContractNo(warehouseInOutInfo.getContractNo());
-                warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-                warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-                this.insert(warehousingOrder);
+        List<WarehousingOrder> dataList3 = baseMapper.getMoveListByCondition(pageView);
+        if (!CollectionUtils.isEmpty(dataList3)){
+            for (WarehousingOrder warehousingOrder1:dataList3) {
+                List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
+                        .eq("status", "已提交")
+                        .eq("in_out_task_no",warehousingOrder1.getInOutTaskNo())
+                        .eq("in_out_type", "退库")
+                        .ge("in_out_date", beforeDay));
+                double weight = warehouseInOutInfoList.stream().mapToDouble(WarehouseInOutInfo::getNetWeight).sum();
+                //查退库任务货源
+                List<SourceRelationInfo> sourceRelationInfoList =sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                        .eq("task_id", warehousingOrder1.getSendTaskId())
+                        .eq("delete_flag", "0"));
+                if (!CollectionUtils.isEmpty(sourceRelationInfoList)){
+                    for (SourceRelationInfo sourceRelationInfo:sourceRelationInfoList){
+                        WarehousingOrder warehousingOrder2=this.selectById(sourceRelationInfo.getSourceId());
+                        WarehousingOrder warehousingOrder = new WarehousingOrder();
+                        warehousingOrder.setId(IdGenerator.generateUUID());
+                        warehousingOrder.setBaseId(warehousingOrder1.getBaseId());
+                        warehousingOrder.setWarehouseName(warehousingOrder1.getWarehouseName());
+                        warehousingOrder.setInType("退库");
+                        warehousingOrder.setContractNo(warehousingOrder2.getContractNo());
+                        //取货源入库单成本
+                        warehousingOrder.setAvgCost(warehousingOrder2.getAvgCost());
+                        warehousingOrder.setCompId(warehousingOrder1.getCompId());
+                        warehousingOrder.setGoodsName(warehousingOrder1.getGoodsName());
+                        warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(weight*sourceRelationInfo.getProportion())));
+                        warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(weight*sourceRelationInfo.getProportion())));
+                        warehousingOrder.setIssuingTime(new Date());
+                        if ("采购入库".equals(warehousingOrder2.getInType())){
+                            warehousingOrder.setGoodsSource(warehousingOrder2.getContractNo());
+                        }
+                        else if ("收购入库".equals(warehousingOrder2.getInType())){
+                            //查收购合同原始收货库
+                            InOutWarehouseTask inOutWarehouseTask=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                                    .eq("comp_id", warehousingOrder1.getCompId())
+                                    .eq("contract_no", warehousingOrder1.getContractNo())
+                                    .eq("delete_flag", "0"));
+                            warehousingOrder.setGoodsSource(inOutWarehouseTask.getWarehouseName());
+                            //更新库点库存 (所在仓库为退货库、所属仓库为原始库、货名一致)
+                            ContractInventoryDistribution contractInventoryDistribution=contractInventoryDistributionService.selectOne(new EntityWrapper<ContractInventoryDistribution>()
+                                    .eq("comp_id",warehousingOrder1.getCompId()).eq("inventory_type","3").eq("locus_warehouse",warehousingOrder1.getWarehouseName())
+                                    .eq("warehouse",inOutWarehouseTask.getWarehouseName())
+                                    .eq("goods_name",warehousingOrder1.getGoodsName()));
+                            if (contractInventoryDistribution!=null){
+                                contractInventoryDistribution.setInventory(contractInventoryDistribution.getInventory()+weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistributionService.updateById(contractInventoryDistribution);
+                            }
+                            else {
+                                ContractInventoryDistribution contractInventoryDistribution1=new ContractInventoryDistribution();
+                                contractInventoryDistribution1.setId(IdGenerator.generateUUID());
+                                contractInventoryDistribution1.setCompId(warehousingOrder1.getCompId());
+                                contractInventoryDistribution1.setWarehouseId(warehousingOrder1.getBaseId());
+                                contractInventoryDistribution1.setInventory(weight*sourceRelationInfo.getProportion());
+                                contractInventoryDistribution1.setWarehouse(warehousingOrder1.getWarehouseName());
+                                contractInventoryDistribution1.setLocusWarehouse(warehousingOrder1.getWarehouseName());
+                                contractInventoryDistribution1.setGoodsName(warehousingOrder1.getGoodsName());
+                                contractInventoryDistribution1.setInventoryType("3");
+                                contractInventoryDistributionService.insert(contractInventoryDistribution1);
+
+                            }
+                        }
+                        this.insert(warehousingOrder);
+                    }
+                }
             }
         }
         return "OK";

+ 23 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/service/impl/WeighingManagementServiceImpl.java

@@ -302,6 +302,29 @@ public class WeighingManagementServiceImpl extends ServiceImpl<WeighingManagemen
         }
         //收购业务
         if("1".equals(weighingManagement1.getManagementType())&&"3".equals(weighingManagement1.getServiceManagementType())){
+            //更新任务已完成量
+            InOutWarehouseTask inOutWarehouseTask=inOutWarehouseTaskService.selectOne(new EntityWrapper<InOutWarehouseTask>()
+                    .eq("comp_id", weighingManagement1.getCompId())
+                    .eq("contract_no", weighingManagement1.getContractNo())
+                    .eq("delete_flag", "0")
+                    .orderBy("update_date", false));
+            if (inOutWarehouseTask!=null){
+                //可超出重量
+                Float overNeight = 0.0f;
+                ContractManagementInfo contractManagementInfo = contractManagementInfoService.selectOne(new EntityWrapper<ContractManagementInfo>()
+                        .eq("comp_id", weighingManagement1.getCompId())
+                        .eq("contract_no", weighingManagement1.getContractNo()));
+                //合同溢短装
+                if (contractManagementInfo != null) {
+                    overNeight = inOutWarehouseTask.getWeight() * (contractManagementInfo.getOverShort() / 100);
+                }
+                inOutWarehouseTask.setCompletedQuantity(inOutWarehouseTask.getCompletedQuantity() + weighingManagement.getNetWeight()/1000);
+                if (inOutWarehouseTask.getCompletedQuantity() > inOutWarehouseTask.getWeight() + overNeight) {
+                    throw new YException(YExceptionEnum.TASK_WEIGHT_EXCEEDED_ERROR);
+                } else {
+                    inOutWarehouseTaskService.updateById(inOutWarehouseTask);
+                }
+            }
             //查关联的付款信息
             PaymentManagement paymentManagement=paymentManagementService.selectOne(new EntityWrapper<PaymentManagement>()
                     .eq("relation_id",weighingManagement1.getRelationId())

+ 6 - 2
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/ExpenseInfoMapper.xml

@@ -33,7 +33,9 @@
         </if>
         <if test="searchKeyWord != null and searchKeyWord != ''">
             AND (lower(expense_name) like lower(CONCAT('%',#{searchKeyWord},'%'))
-            OR lower(agent) like lower(CONCAT('%',#{searchKeyWord},'%')))
+            OR lower(agent) like lower(CONCAT('%',#{searchKeyWord},'%'))
+            OR lower(warehouse_name) like lower(CONCAT('%',#{searchKeyWord},'%'))
+            OR lower(contract_no) like lower(CONCAT('%',#{searchKeyWord},'%')))
         </if>
     </select>
     <!-- 费用管理列表查询 -->
@@ -78,7 +80,9 @@
         </if>
         <if test="searchKeyWord != null and searchKeyWord != ''">
             AND (lower(expense_name) like lower(CONCAT('%',#{searchKeyWord},'%'))
-            OR lower(agent) like lower(CONCAT('%',#{searchKeyWord},'%')))
+            OR lower(agent) like lower(CONCAT('%',#{searchKeyWord},'%'))
+            OR lower(warehouse_name) like lower(CONCAT('%',#{searchKeyWord},'%'))
+            OR lower(contract_no) like lower(CONCAT('%',#{searchKeyWord},'%')))
         </if>
         <if test="startDate != null">
             AND (DATE_FORMAT(create_date,"%Y%m%d") &gt;=

+ 62 - 6
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/WarehousingOrderMapper.xml

@@ -134,7 +134,8 @@
             pm.warehouse_name as warehouseName,
             pm.customer_name as goodsSource,
             pm.comp_id as compId,
-            pm.update_date as updateDate,
+            pm.contract_no as contractNo,
+            pm.settlement_date as updateDate,
             wbi.id as baseId,
             iai.id as identifyId,
             pm.goods_name as goodsName
@@ -144,8 +145,8 @@
         WHERE
             pm.delete_flag = '0'
             and pm.status !='待结算'
-			and pm.update_date> #{beforeDay}
-        group BY pm.warehouse_name,pm.customer_name,pm.goods_name,DATE_FORMAT(pm.update_date,"%Y%m%d")
+			and pm.settlement_date> #{beforeDay}
+        group BY pm.contract_no,pm.customer_name,pm.goods_name,DATE_FORMAT(pm.settlement_date,"%Y%m%d")
     </select>
     <!-- 采购入库单查询 -->
     <select id="getPurchaseListByCondition" parameterType="Map"
@@ -157,7 +158,7 @@
             wbi.comp_id as compId,
             wio.goods_name as goodsName,
             wbi.id as baseId,
-            wio.update_date as updateDate
+            wio.in_out_date as updateDate
         FROM warehouse_in_out_info wio
         LEFT JOIN warehouse_base_info wbi on wbi.id=wio.base_id
         WHERE
@@ -165,8 +166,8 @@
             and wio.status ='已提交'
             and wio.in_out_type ='采购入库'
             and wbi.warehouse_type='1'
-            and wio.update_date> #{beforeDay}
-        group BY wio.warehouse_name,wio.contract_no,DATE_FORMAT(wio.update_date,"%Y%m%d")
+            and wio.in_out_date> #{beforeDay}
+        group BY wio.warehouse_name,wio.contract_no,DATE_FORMAT(wio.in_out_date,"%Y%m%d")
     </select>
     <!-- 根据条件查询货源总数 -->
     <select id="getGoodSourceCountByCondition" parameterType="Map" resultType="java.lang.Integer">
@@ -261,4 +262,59 @@
         GROUP BY
             case when (wioi.goods_name not like '%潮粮%' and wioi.goods_name like '%玉米%') then  '玉米'  else wioi.goods_name end;
     </select>
+    <!-- 移库入库单查询 -->
+    <select id="getMoveListByCondition"
+            parameterType="Map"
+            resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehousingOrder">
+        SELECT
+            wio.id,
+            wio.warehouse_name AS warehouseName,
+            wio.in_out_task_no AS inOutTaskNo,
+            wbi.comp_id AS compId,
+            wio.goods_name AS goodsName,
+            wbi.id AS baseId,
+            iowt1.warehouse_name AS sendWarehouseName,
+            iowt1.id as sendTaskId,
+            iowt.move_task_no AS moveTaskNo,
+            wio.update_date AS updateDate
+        FROM
+            warehouse_in_out_info wio
+                LEFT JOIN warehouse_base_info wbi ON wbi.id = wio.base_id
+                LEFT JOIN in_out_warehouse_task iowt ON iowt.in_out_task_no = wio.in_out_task_no
+                AND iowt.delete_flag = '0'
+                LEFT JOIN in_out_warehouse_task iowt1 ON iowt1.move_task_no = iowt.move_task_no and iowt1.in_out_flag=1
+                AND iowt1.delete_flag = '0'
+        WHERE
+            wio.delete_flag = '0'
+          and wio.status ='已提交'
+          and wio.in_out_type ='移库入库'
+          and wbi.warehouse_type='1'
+          and wio.in_out_date> #{beforeDay}
+        group BY wio.in_out_task_no,DATE_FORMAT(wio.in_out_date,"%Y%m%d")
+    </select>
+    <!-- 退库入库单查询 -->
+    <select id="getReturnListByCondition" parameterType="Map"
+            resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehousingOrder">
+        SELECT
+            wio.id,
+            wio.warehouse_name AS warehouseName,
+            wio.in_out_task_no AS inOutTaskNo,
+            wbi.comp_id AS compId,
+            wio.goods_name AS goodsName,
+            wbi.id AS baseId,
+            iowt.id as sendTaskId,
+            wio.update_date AS updateDate
+        FROM
+            warehouse_in_out_info wio
+                LEFT JOIN warehouse_base_info wbi ON wbi.id = wio.base_id
+                LEFT JOIN in_out_warehouse_task iowt ON iowt.in_out_task_no = wio.in_out_task_no
+                AND iowt.delete_flag = '0'
+        WHERE
+            wio.delete_flag = '0'
+          and wio.status ='已提交'
+          and wio.in_out_type ='退库'
+          and wbi.warehouse_type='1'
+          and wio.in_out_date> #{beforeDay}
+        group BY wio.in_out_task_no,DATE_FORMAT(wio.in_out_date,"%Y%m%d")
+    </select>
 </mapper>