zhangyuewww 3 년 전
부모
커밋
4b1a066a86

+ 2 - 2
winsea-haixin-plugin-yiliangyiyun/src/main/java/com/yh/saas/plugin/yiliangyiyun/entity/SourceRelationInfo.java

@@ -83,8 +83,8 @@ public class SourceRelationInfo extends BaseModel<SourceRelationInfo> {
     /**
      * 出单时间
      */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @DateTimeFormat(pattern = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date issuingTime;
     /**
      * 车牌号

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

@@ -59,5 +59,12 @@ public interface WarehousingOrderMapper extends BaseMapper<WarehousingOrder> {
      * @return
      */
     List<WarehousingOrder> getGoodSourceListByCondition(Map<String, Object> pageView);
+    /**
+     * 根据条件查询当日货名成本
+     *
+     * @param pageView
+     * @return
+     */
+    List<WarehousingOrder> getGoodCostListByCondition(Map<String, Object> pageView);
 
 }

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

@@ -197,7 +197,7 @@ public class ExpenseInfoServiceImpl extends ServiceImpl<ExpenseInfoMapper, Expen
             String staffName = this.billOperateHisService.getStaffAndName();
             // 插入操作历史
             this.billOperateHisService.saveBillOperateHis(expenseInfo.getId(), NumberConstant.EXPENSE_MANAGEMENT, staffName, null,
-                    "收款"+"("+expenseInfo.getAmountMoney()+")", null, expenseInfo.getRemark());
+                    "收款", null, expenseInfo.getRemark());
         }
         //支出
         else
@@ -221,7 +221,7 @@ public class ExpenseInfoServiceImpl extends ServiceImpl<ExpenseInfoMapper, Expen
             String staffName = this.billOperateHisService.getStaffAndName();
             // 插入操作历史
             this.billOperateHisService.saveBillOperateHis(expenseInfo.getId(), NumberConstant.EXPENSE_MANAGEMENT, staffName, null,
-                    "请款"+"("+expenseInfo.getAmountMoney()+")", null, expenseInfo.getRemark());
+                    "请款", null, expenseInfo.getRemark());
             boolean isStartWorkflow = StringUtils.isBlank(expenseInfo.getWorkflowId());
             // 不是退回的单子
             if (isStartWorkflow) {
@@ -288,7 +288,7 @@ public class ExpenseInfoServiceImpl extends ServiceImpl<ExpenseInfoMapper, Expen
             String staffName = this.billOperateHisService.getStaffAndName();
             // 插入操作历史
             this.billOperateHisService.saveBillOperateHis(expenseInfo.getId(), NumberConstant.EXPENSE_MANAGEMENT, staffName, null,
-                    "确认"+"("+expenseInfo.getAmountMoney()+")", null, expenseInfo.getRemark());
+                    "确认", null, expenseInfo.getRemark());
         }
         //完成收款
         else if ("1".equals(expenseInfo.getFlag())){
@@ -463,7 +463,7 @@ public class ExpenseInfoServiceImpl extends ServiceImpl<ExpenseInfoMapper, Expen
         String staffName = this.billOperateHisService.getStaffAndName();
         // 插入操作历史
         this.billOperateHisService.saveBillOperateHis(expenseInfo.getId(), NumberConstant.EXPENSE_MANAGEMENT, staffName, null,
-                "付款"+"("+expenseInfo.getAmountMoney()+")", null, "");
+                "付款", null, "");
         return "ok";
     }
 

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

@@ -237,21 +237,36 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
      * 每天16.30点更新
      */
     @Transactional
-    @Scheduled(cron = "0 11 10 * * ?")
+    @Scheduled(cron = "0 03 11 * * ?")
     public String addInfo() {
         //当天零点
-        SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd 10:11:00");
+        SimpleDateFormat now = new SimpleDateFormat("yyyy-MM-dd 11:03:00");
         Calendar c = Calendar.getInstance();
         c.setTime(new Date());
         c.add(Calendar.DATE, -1);
         String beforeDay=now.format(c.getTime());
         Map<String, Object> pageView = new HashMap<>();
         pageView.put("beforeDay", beforeDay);
-
+        //成本
+        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());
+                        }
+                    });
+                }
                 List<PaymentManagement> paymentManagementList = paymentManagementService.selectList(new EntityWrapper<PaymentManagement>()
                         .eq("customer_name",warehousingOrder1.getGoodsSource())
                         .eq("warehouse_name",warehousingOrder1.getWarehouseName())
@@ -266,6 +281,7 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                 warehousingOrder.setGoodsSource(warehousingOrder1.getGoodsSource());
                 warehousingOrder.setCompId(warehousingOrder1.getCompId());
                 warehousingOrder.setGoodsName(warehousingOrder1.getGoodsName());
+                warehousingOrder.setAvgCost(warehousingOrder1.getAvgCost());
                 warehousingOrder.setInType("收购入库");
                 double weight = paymentManagementList.stream().mapToDouble(PaymentManagement::getNetWeight).sum();
                 warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(weight)));
@@ -282,6 +298,20 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
         List<WarehousingOrder> dataList1 = baseMapper.getPurchaseListByCondition(pageView);
         if (!CollectionUtils.isEmpty(dataList1)){
             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());
+                        }
+                    });
+                }
                 List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                         .eq("status", "已提交")
                         .eq("contract_no",warehousingOrder1.getContractNo())
@@ -294,6 +324,7 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                 warehousingOrder.setWarehouseName(warehousingOrder1.getWarehouseName());
                 warehousingOrder.setGoodsSource(warehousingOrder1.getContractNo());
                 warehousingOrder.setInType("采购入库");
+                warehousingOrder.setAvgCost(warehousingOrder1.getAvgCost());
                 warehousingOrder.setCompId(warehousingOrder1.getCompId());
                 warehousingOrder.setGoodsName(warehousingOrder1.getGoodsName());
                 warehousingOrder.setContractNo(warehousingOrder1.getContractNo());
@@ -313,76 +344,6 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                 this.insert(warehousingOrder);
             }
         }
-        //收购
-//        List<PaymentManagement> paymentManagementList = paymentManagementService.selectList(new EntityWrapper<PaymentManagement>()
-//                .ne("status", "待结算")
-//                .ge("update_date", beforeDay));
-//        if (!CollectionUtils.isEmpty(paymentManagementList)) {
-//            for (PaymentManagement paymentManagement : paymentManagementList) {
-//                warehousingOrder.setId(IdGenerator.generateUUID());
-//                WarehouseBaseInfo warehouseBaseInfo = warehouseBaseInfoService.selectOne(new EntityWrapper<WarehouseBaseInfo>()
-//                        .eq("comp_id", paymentManagement.getCompId())
-//                        .eq("warehouse_name", paymentManagement.getWarehouseName()));
-//                warehousingOrder.setBaseId(warehouseBaseInfo.getId());
-//                IdentityAuthenticationInfo identityAuthenticationInfo = identityAuthenticationInfoService.selectOne(new EntityWrapper<IdentityAuthenticationInfo>()
-//                        .eq("comp_id", paymentManagement.getCompId())
-//                        .eq("customer_number_card", paymentManagement.getCustomerNumberCard()));
-//                if(identityAuthenticationInfo!=null) {
-//                    warehousingOrder.setIdentifyId(identityAuthenticationInfo.getId());
-//                }
-//                QualityInspectionManagement qualityInspectionManagement=qualityInspectionManagementService.selectOne(new EntityWrapper<QualityInspectionManagement>()
-//                        .eq("relation_id", paymentManagement.getRelationId()));
-//                warehousingOrder.setWarehouseInOutId(qualityInspectionManagement.getWarehouseInOutId());
-//                warehousingOrder.setWarehouseName(paymentManagement.getWarehouseName());
-//                warehousingOrder.setGoodsSource(paymentManagement.getCustomerName());
-//                warehousingOrder.setCompId(paymentManagement.getCompId());
-//                warehousingOrder.setCarNo(paymentManagement.getCarNo());
-//                warehousingOrder.setGoodsName(paymentManagement.getGoodsName());
-//                warehousingOrder.setInType("收购入库");
-//                warehousingOrder.setInWarehouseWeight(paymentManagement.getNetWeight());
-//                warehousingOrder.setSurplusWeight(paymentManagement.getNetWeight());
-//                warehousingOrder.setAmountNotPayable(paymentManagement.getAmountIngPayable());
-//                warehousingOrder.setAmountEdPayable(0d);
-//                warehousingOrder.setIssuingTime(new Date());
-//                warehousingOrder.setGrainFund(paymentManagement.getAmountIngPayable());
-//                this.insert(warehousingOrder);
-//            }
-//        }
-        //采购入库
-//        List<WarehouseInOutInfo> warehouseInOutInfoList = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
-//                .eq("status", "已提交")
-//                .eq("in_out_type", "采购入库")
-//                .ge("update_date", beforeDay));
-//        if (!CollectionUtils.isEmpty(warehouseInOutInfoList)) {
-//            for (WarehouseInOutInfo warehouseInOutInfo : warehouseInOutInfoList) {
-//                warehousingOrder.setId(IdGenerator.generateUUID());
-//                warehousingOrder.setBaseId(warehouseInOutInfo.getBaseId());
-//                WarehouseBaseInfo warehouseBaseInfo=warehouseBaseInfoService.selectById(warehouseInOutInfo.getBaseId());
-//                warehousingOrder.setWarehouseInOutId(warehouseInOutInfo.getId());
-//                if(warehouseInOutInfo.getPositionId()!=null){
-//                    warehousingOrder.setWarehouseName(warehouseInOutInfo.getWarehouseName());
-//                }
-//                //区分采购合同产生的临时库
-//                else {
-//                    warehousingOrder.setWarehouseName(warehouseInOutInfo.getWarehouseName()+"(临)");
-//                }
-//                warehousingOrder.setWarehouseName(warehouseInOutInfo.getWarehouseName());
-//                warehousingOrder.setGoodsSource(warehouseInOutInfo.getContractNo());
-//                warehousingOrder.setCarNo(warehouseInOutInfo.getCarNo());
-//                warehousingOrder.setInType(warehouseInOutInfo.getInOutType());
-//                warehousingOrder.setCompId(warehouseBaseInfo.getCompId());
-//                warehousingOrder.setGoodsName(warehouseInOutInfo.getGoodsName());
-//                warehousingOrder.setContractNo(warehouseInOutInfo.getContractNo());
-//                warehousingOrder.setInWarehouseWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-//                warehousingOrder.setAmountNotPayable(warehouseInOutInfo.getCost()*warehouseInOutInfo.getNetWeight());
-//                warehousingOrder.setAmountEdPayable(0d);
-//                warehousingOrder.setSurplusWeight(Float.valueOf(String.valueOf(warehouseInOutInfo.getNetWeight())));
-//                warehousingOrder.setIssuingTime(new Date());
-//                warehousingOrder.setGrainFund(warehouseInOutInfo.getCost()*warehouseInOutInfo.getNetWeight());
-//                this.insert(warehousingOrder);
-//            }
-//        }
-
         //移库入库
         List<WarehouseInOutInfo> warehouseInOutInfoList1 = warehouseInOutInfoService.selectList(new EntityWrapper<WarehouseInOutInfo>()
                 .eq("status", "已提交")
@@ -445,20 +406,6 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                 this.insert(warehousingOrder);
             }
         }
-        //当天零点
-        SimpleDateFormat now1 = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
-        Calendar a = Calendar.getInstance();
-        a.setTime(new Date());
-        a.add(Calendar.DATE, 0);
-        String time=now1.format(c.getTime());
-        //查询当天生成的数据
-        List<WarehousingOrder> list = this.selectList(new EntityWrapper<WarehousingOrder>()
-        .ge("create_date",time));
-//
-//        String goodsName = warehousingOrder1.getGoodsName();
-//        if(goodsName.contains("玉米")&&!goodsName.contains("潮粮")){
-//            goodsName = "玉米";
-//        }
         return "OK";
 
     }
@@ -589,6 +536,8 @@ public class WarehousingOrderServiceImpl extends ServiceImpl<WarehousingOrderMap
                     warehousingOrder1.setAmountNotPayable(warehousingOrder1.getAmountNotPayable()-warehousingOrder1.getRequestFunds());
                     warehousingOrder1.setAmountEdPayable(warehousingOrder1.getAmountEdPayable()+warehousingOrder1.getRequestFunds());
                     warehousingOrder1.setRequestFunds(0d);
+                    warehousingOrder1.setStatusFlag("");
+                    warehousingOrder1.setStatus("");
                     this.updateById(warehousingOrder1);
                 }
             }

+ 119 - 63
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/ContractManagementInfoMapper.xml

@@ -694,77 +694,133 @@
             resultType="com.yh.saas.plugin.yiliangyiyun.entity.ContractManagementInfo">
         SELECT
             '采购重量' AS type,
-            SUM( wioi.net_weight )+ IFNULL( SUM( wioi4.net_weight ), 0 )+ IFNULL( SUM( wioi2.net_weight ), 0 )- IFNULL( SUM( wioi3.net_weight ), 0 ) AS profit
+            SUM(
+                IFNULL((
+                           SELECT
+                               sum( IFNULL( wioi.net_weight, 0 ) )
+                           FROM
+                               warehouse_in_out_info wioi
+                           WHERE
+                               wioi.base_id = wbi1.id
+                             AND wioi.status_flag = '3'
+                             AND ( wioi.in_out_type = '采购入库' OR wioi.in_out_type = '收购入库' )
+                             AND wioi.delete_flag = '0'
+                             AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &gt;=
+                                  DATE_FORMAT(#{startDate},"%Y%m%d"))
+                             AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &lt;=
+                                  DATE_FORMAT(#{endDate},"%Y%m%d"))
+                       ),
+                       0
+                    )) + SUM(
+                IFNULL((
+                           SELECT
+                               sum( IFNULL( wioi4.net_weight, 0 ) )
+                           FROM
+                               warehouse_in_out_info wioi4
+                           WHERE
+                               wioi4.base_id = wbi2.id
+                             AND wioi4.status_flag = '3'
+                             AND wioi4.in_out_type = '移库入库'
+                             AND wioi4.delete_flag = '0'
+                             AND (DATE_FORMAT(wioi4.in_out_date,"%Y%m%d") &gt;=
+                                  DATE_FORMAT(#{startDate},"%Y%m%d"))
+                             AND (DATE_FORMAT(wioi4.in_out_date,"%Y%m%d") &lt;=
+                                  DATE_FORMAT(#{endDate},"%Y%m%d"))
+                       ),
+                       0
+                    )) + SUM(
+                IFNULL((
+                           SELECT
+                               sum( IFNULL( wioi2.net_weight, 0 ) )
+                           FROM
+                               warehouse_in_out_info wioi2
+                           WHERE
+                               wioi2.base_id = wbi2.id
+                             AND wioi2.status_flag = '3'
+                             AND wioi2.in_out_type = '销售出库'
+                             AND wioi2.delete_flag = '0'
+                             AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &gt;=
+                                  DATE_FORMAT(#{startDate},"%Y%m%d"))
+                             AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &lt;=
+                                  DATE_FORMAT(#{endDate},"%Y%m%d"))
+                       ),
+                       0
+                    )) - SUM(
+                IFNULL((
+                           SELECT
+                               sum( IFNULL( wioi3.net_weight, 0 ) )
+                           FROM
+                               warehouse_in_out_info wioi3
+                           WHERE
+                               wioi3.base_id = wbi2.id
+                             AND wioi3.status_flag = '3'
+                             AND wioi3.in_out_type = '退库'
+                             AND wioi3.delete_flag = '0'
+                             AND (DATE_FORMAT(wioi3.in_out_date,"%Y%m%d") &gt;=
+                                  DATE_FORMAT(#{startDate},"%Y%m%d"))
+                             AND (DATE_FORMAT(wioi3.in_out_date,"%Y%m%d") &lt;=
+                                  DATE_FORMAT(#{endDate},"%Y%m%d"))
+                       ),
+                       0
+                    )) AS profit
         FROM
             warehouse_base_info wbi
-                LEFT JOIN warehouse_in_out_info wioi ON wioi.base_id = wbi.id
-                AND wbi.warehouse_type = '1'
-                AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &gt;=
-                     DATE_FORMAT(#{startDate},"%Y%m%d"))
-                AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &lt;=
-                     DATE_FORMAT(#{endDate},"%Y%m%d"))
-                AND wioi.status_flag = '3'
-                AND ( wioi.in_out_type = '采购入库' OR wioi.in_out_type = '收购入库' )
-                AND wioi.delete_flag = '0'
-                LEFT JOIN warehouse_in_out_info wioi2 ON wioi2.base_id = wbi.id
-                AND wbi.warehouse_type = '2'
-                AND wbi.create_type = '1'
-                AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &gt;=
-                     DATE_FORMAT(#{startDate},"%Y%m%d"))
-                AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &lt;=
-                     DATE_FORMAT(#{endDate},"%Y%m%d"))
-                AND wioi2.status_flag = '3'
-                AND wioi2.in_out_type = '销售出库'
-                AND wioi2.delete_flag = '0'
-                LEFT JOIN warehouse_in_out_info wioi3 ON wioi3.base_id = wbi.id
-                AND wbi.warehouse_type = '2'
-                AND wbi.create_type = '1'
-                AND (DATE_FORMAT(wioi3.in_out_date,"%Y%m%d") &gt;=
-                     DATE_FORMAT(#{startDate},"%Y%m%d"))
-                AND (DATE_FORMAT(wioi3.in_out_date,"%Y%m%d") &lt;=
-                     DATE_FORMAT(#{endDate},"%Y%m%d"))
-                AND wioi3.status_flag = '3'
-                AND wioi3.in_out_type = '退库'
-                AND wioi3.delete_flag = '0'
-                LEFT JOIN warehouse_in_out_info wioi4 ON wioi4.base_id = wbi.id
-                AND wbi.warehouse_type = '2'
-                AND wbi.create_type = '1'
-                AND (DATE_FORMAT(wioi4.in_out_date,"%Y%m%d") &gt;=
-                     DATE_FORMAT(#{startDate},"%Y%m%d"))
-                AND (DATE_FORMAT(wioi4.in_out_date,"%Y%m%d") &lt;=
-                     DATE_FORMAT(#{endDate},"%Y%m%d"))
-                AND wioi4.status_flag = '3'
-                AND wioi4.in_out_type = '移库入库'
-                AND wioi4.delete_flag = '0'
+                LEFT JOIN warehouse_base_info wbi1 ON wbi1.id = wbi.id
+                AND wbi1.warehouse_type = '1'
+                AND wbi1.delete_flag = '0'
+                LEFT JOIN warehouse_base_info wbi2 ON wbi2.id = wbi.id
+                AND wbi2.warehouse_type = '2'
+                AND wbi2.delete_flag = '0'
+                AND wbi2.create_type = '1'
         WHERE
-            wbi.comp_id =  #{compId}
-          AND wbi.delete_flag = '0' UNION ALL
+            wbi.comp_id = #{compId}
+            AND wbi.delete_flag = '0'
+        UNION ALL
         SELECT
             '销售重量' AS type,
-            SUM( wioi1.net_weight )- IFNULL( SUM( wioi2.net_weight ), 0 ) AS profit
+            SUM(
+                IFNULL((
+                           SELECT
+                               sum( IFNULL( wioi1.net_weight, 0 ) )
+                           FROM
+                               warehouse_in_out_info wioi1
+                           WHERE
+                               wioi1.base_id = wbi.id
+                             AND wioi1.status_flag = '3'
+                             AND wioi1.in_out_type = '销售出库'
+                             AND wioi1.delete_flag = '0'
+                             AND (DATE_FORMAT(wioi1.in_out_date,"%Y%m%d") &gt;=
+                                  DATE_FORMAT(#{startDate},"%Y%m%d"))
+                             AND (DATE_FORMAT(wioi1.in_out_date,"%Y%m%d") &lt;=
+                                  DATE_FORMAT(#{endDate},"%Y%m%d"))
+                       ),
+                       0
+                    ))- SUM(
+                IFNULL((
+                           SELECT
+                               sum( IFNULL( wioi2.net_weight, 0 ) )
+                           FROM
+                               warehouse_in_out_info wioi2
+                           WHERE
+                               wioi2.base_id = wbi.id
+                             AND wioi2.status_flag = '3'
+                             AND wioi2.in_out_type = '退库'
+                             AND wioi2.delete_flag = '0'
+                             AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &gt;=
+                                  DATE_FORMAT(#{startDate},"%Y%m%d"))
+                             AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &lt;=
+                                  DATE_FORMAT(#{endDate},"%Y%m%d"))
+                       ),
+                       0
+                    )) AS profit
         FROM
             warehouse_base_info wbi
-                LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.base_id = wbi.id
-                AND wioi1.in_out_type = '销售出库'
-                AND wioi1.delete_flag = '0'
-                AND (DATE_FORMAT(wioi1.in_out_date,"%Y%m%d") &gt;=
-                     DATE_FORMAT(#{startDate},"%Y%m%d"))
-                AND (DATE_FORMAT(wioi1.in_out_date,"%Y%m%d") &lt;=
-                     DATE_FORMAT(#{endDate},"%Y%m%d"))
-                AND wioi1.status_flag = '3'
-                LEFT JOIN warehouse_in_out_info wioi2 ON wioi2.base_id = wbi.id
-                AND wbi.warehouse_type = '1'
-                AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &gt;=
-                     DATE_FORMAT(#{startDate},"%Y%m%d"))
-                AND (DATE_FORMAT(wioi2.in_out_date,"%Y%m%d") &lt;=
-                     DATE_FORMAT(#{endDate},"%Y%m%d"))
-                AND wioi2.status_flag = '3'
-                AND wioi2.in_out_type = '退库'
-                AND wioi2.delete_flag = '0'
         WHERE
-            wbi.comp_id =  #{compId}
-          AND wbi.delete_flag = '0' UNION ALL
-        SELECT
+            wbi.comp_id = #{compId}
+            AND wbi.delete_flag = '0'
+            AND wbi.warehouse_type = '1'
+       UNION ALL
+       SELECT
             '支付粮款' AS type,
             IFNULL( sum( ei1.amount_money ), 0 ) - IFNULL( sum( ei2.amount_money ), 0 )+ IFNULL( sum( ei3.amount_money ), 0 ) - IFNULL( sum( ei4.amount_money ), 0 ) AS profit
         FROM

+ 28 - 32
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/WarehouseBaseInfoMapper.xml

@@ -786,40 +786,36 @@
     <select id="getWarehouseChartByCondition" parameterType="Map"
             resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehouseBaseInfo">
         SELECT
-        wioi.goods_name AS goodsName,
-        SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 ) ) -sum( pm.amount_ing_payable ) AS profit
+            pm.goods_name AS goodsName,
+            SUM( IFNULL( sri.proportion, 1 ) * IFNULL( ssrr.amount_ing_receivable, 0 )) - sum( pm.amount_ing_payable ) AS profit
         FROM
-        warehouse_in_out_info wioi
-        LEFT JOIN warehouse_base_info wbi ON wbi.id = wioi.base_id
-        AND wbi.delete_flag = 0
-        LEFT JOIN quality_inspection_management qim ON qim.warehouse_in_out_id = wioi.id
-        AND qim.delete_flag = 0
-        LEFT JOIN payment_management pm ON pm.relation_id = qim.relation_id
-        AND pm.delete_flag = 0
-        LEFT JOIN warehousing_order war ON war.base_id = wbi.id  AND war.in_type = '收购入库'
-        AND war.comp_id = wbi.comp_id
-        AND war.delete_flag = '0'
-        LEFT JOIN source_relation_info sri ON sri.source_id = war.id
-        AND sri.delete_flag = '0'
-        LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
-        AND iowt.in_out_flag = 1
-        AND iowt.in_out_type_key = 1
-        AND iowt.delete_flag = '0'
-        LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
-        AND wioi1.car_no = sri.car_no
-        AND wioi1.delete_flag = 0
-        AND wioi1.status_flag = 3
-        LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.contract_no = iowt.contract_no
-        AND ssrr.warehouse_record_id = wioi1.id
-        AND ssrr.delete_flag = 0
+            payment_management pm
+                LEFT JOIN warehouse_base_info wbi ON wbi.warehouse_name = pm.warehouse_name
+                AND wbi.comp_id = pm.comp_id
+                AND wbi.delete_flag = 0
+                LEFT JOIN warehousing_order war ON war.base_id = wbi.id
+                AND war.in_type = '收购入库'
+                AND war.comp_id = wbi.comp_id
+                AND war.delete_flag = '0'
+                LEFT JOIN source_relation_info sri ON sri.source_id = war.id
+                AND sri.delete_flag = '0'
+                LEFT JOIN in_out_warehouse_task iowt ON iowt.id = sri.task_id
+                AND iowt.in_out_flag = 1
+                AND iowt.in_out_type_key = 1
+                AND iowt.delete_flag = '0'
+                LEFT JOIN warehouse_in_out_info wioi1 ON wioi1.in_out_task_no = iowt.in_out_task_no
+                AND wioi1.delete_flag = 0
+                AND wioi1.status_flag = 3
+                and wioi1.in_out_flag = 1
+                LEFT JOIN stock_sale_receipt_report ssrr ON ssrr.warehouse_record_id = wioi1.id
+                AND ssrr.delete_flag = 0
         WHERE
-        wioi.in_out_type = '收购入库'
-        AND wioi.status_flag = '3'
-        AND wbi.comp_id= #{compId}
-        AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &gt;=
-        DATE_FORMAT(#{startDate},"%Y%m%d"))
-        AND (DATE_FORMAT(wioi.in_out_date,"%Y%m%d") &lt;=
-        DATE_FORMAT(#{endDate},"%Y%m%d"))
+            pm.delete_flag = 0
+            AND wbi.comp_id = #{compId}
+            AND (DATE_FORMAT(pm.create_date,"%Y%m%d") &gt;=
+            DATE_FORMAT(#{startDate},"%Y%m%d"))
+            AND (DATE_FORMAT(pm.create_date,"%Y%m%d") &lt;=
+            DATE_FORMAT(#{endDate},"%Y%m%d"))
         GROUP BY
         wioi.goods_name;
     </select>

+ 21 - 0
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/WarehousingOrderMapper.xml

@@ -218,4 +218,25 @@
             LIMIT ${startRecord}, ${pageSize}
         </if>
     </select>
+    <!-- 根据条件查询当日货名成本 -->
+    <select id="getGoodCostListByCondition" parameterType="Map"
+            resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehousingOrder">
+        SELECT
+            case when (wioi.goods_name not like '%潮粮%' and wioi.goods_name like '%玉米%') then  '玉米'  else wioi.goods_name end as goodsName,
+            SUM(IFNULL(spr.amount_ing_payable,0)+IFNULL(pm.amount_ing_payable,0)) /SUM(wioi.net_weight) AS avgCost
+        FROM
+            warehouse_in_out_info wioi
+            LEFT JOIN warehouse_base_info wbi ON wbi.id = wioi.base_id
+            AND wbi.delete_flag = 0
+            LEFT JOIN payment_management pm ON pm.payment_no = wioi.contract_no and wioi.in_out_type='收购入库'
+            AND pm.delete_flag = 0
+            LEFT JOIN stock_purchase_receipt_report spr on spr.warehouse_record_id=wioi.id and spr.delete_flag=0 and wioi.in_out_type='采购入库'
+        WHERE
+            (wioi.in_out_type = '收购入库' OR wioi.in_out_type = '采购入库')
+            AND wioi.status_flag = '3'
+            AND wbi.comp_id = #{compId}
+            and wioi.update_date> #{beforeDay}
+        GROUP BY
+            case when (wioi.goods_name not like '%潮粮%' and wioi.goods_name like '%玉米%') then  '玉米'  else wioi.goods_name end;
+    </select>
 </mapper>