zhangyuewww il y a 1 an
Parent
commit
f7a2f4855e

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

@@ -117,6 +117,10 @@ public class SourceRelationInfo extends BaseModel<SourceRelationInfo> {
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @TableField(exist = false)
     private Date issuingTimeOther;
+    /**
+     * 合同编号
+     */
+    private String contractNo;
     @Override
     protected Serializable pkVal() {
         return this.id;

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

@@ -111,43 +111,125 @@ public class InOutWarehouseTaskServiceImpl extends ServiceImpl<InOutWarehouseTas
                 if (CollectionUtils.isNotEmpty(sourceRelationInfoList)) {
                     for (int i=0;i<sourceRelationInfoList.size();i++){
                         SourceRelationInfo sourceRelationInfo=sourceRelationInfoList.get(i);
-                        sourceRelationInfo.setId(IdGenerator.generateUUID());
-                        sourceRelationInfo.setTaskId(inOutWarehouseTask.getId());
-                        sourceRelationInfo.setIssuingTime(sourceRelationInfo.getIssuingTimeOther());
-                        //最后一次循环
-                        if (i==sourceRelationInfoList.size()-1){
-                            double proportion=0d;
-                            List<SourceRelationInfo> sourceRelationInfoList1=sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
-                            .eq("task_id",sourceRelationInfo.getTaskId()));
-                            if (CollectionUtils.isNotEmpty(sourceRelationInfoList1)){
-                                //比例和
-                                proportion = (sourceRelationInfoList1.stream().mapToDouble(SourceRelationInfo::getProportion).sum()) ;
-                            }
-                            sourceRelationInfo.setProportion(1-proportion);
-
-                        }
-                        else {
-                            //计算比例
-                            sourceRelationInfo.setProportion(sourceRelationInfo.getEstimateOutWarehouseWeight() / Double.valueOf(String.valueOf(inOutWarehouseTask.getWeight())));
-                        }
-                        sourceRelationInfoService.insert(sourceRelationInfo);
-                        //退库勾选标识
-                        if (sourceRelationInfo.getWarehouseInOutId() != null) {
-                            WarehouseInOutInfo warehouseInOutInfo = warehouseInOutInfoService.selectById(sourceRelationInfo.getWarehouseInOutId());
-                            warehouseInOutInfo.setReturnTickFlag(sourceRelationInfo.getReturnTickFlag());
-                            warehouseInOutInfoService.updateById(warehouseInOutInfo);
-                        }
-                        //出库
-                        else {
-                            WarehousingOrder warehousingOrder = warehousingOrderService.selectById(sourceRelationInfo.getSourceId());
-                            if (warehousingOrder != null) {
-                                warehousingOrder.setOutWarehouseWeight(warehousingOrder.getOutWarehouseWeight() + sourceRelationInfo.getEstimateOutWarehouseWeight());
+//                        //退库勾选标识
+//                        if (sourceRelationInfo.getWarehouseInOutId() != null) {
+//                            WarehouseInOutInfo warehouseInOutInfo = warehouseInOutInfoService.selectById(sourceRelationInfo.getWarehouseInOutId());
+//                            warehouseInOutInfo.setReturnTickFlag(sourceRelationInfo.getReturnTickFlag());
+//                            warehouseInOutInfoService.updateById(warehouseInOutInfo);
+//                        }
+                        Double weight = Double.valueOf(String.valueOf(sourceRelationInfo.getEstimateOutWarehouseWeight()));
+                        List<WarehousingOrder> warehousingOrderList=warehousingOrderService.selectList(new EntityWrapper<WarehousingOrder>()
+                                .eq("comp_id",inOutWarehouseTask.getCompId())
+                                .eq("warehouse_name",inOutWarehouseTask.getWarehouseName())
+                                .eq("goods_name",sourceRelationInfo.getGoodsName())
+                                .gt("surplus_weight",0)
+                                .eq("contract_no",sourceRelationInfo.getContractNo())
+                                .orderBy("issuing_time"));
+                        for (WarehousingOrder warehousingOrder:warehousingOrderList){
+                            WarehousingOrder warehousingOrder1 = warehousingOrderService.selectById(warehousingOrder.getId());
+                            //预计出库重量大于入库单剩余重量
+                            if (weight >= warehousingOrder1.getSurplusWeight()) {
+                                weight = weight - warehousingOrder1.getSurplusWeight();
+                                SourceRelationInfo sourceRelationInfo1=new SourceRelationInfo();
+                                sourceRelationInfo1.setId(IdGenerator.generateUUID());
+                                sourceRelationInfo1.setTaskId(inOutWarehouseTask.getId());
+                                sourceRelationInfo1.setSourceId(warehousingOrder1.getId());
+                                sourceRelationInfo1.setGoodsSource(warehousingOrder1.getGoodsSource());
+                                sourceRelationInfo1.setAvgCost(warehousingOrder1.getAvgCost());
+                                sourceRelationInfo1.setIssuingTime(warehousingOrder1.getIssuingTime());
+                                sourceRelationInfo1.setGoodsName(warehousingOrder1.getGoodsName());
+                                sourceRelationInfo1.setContractNo(warehousingOrder1.getContractNo());
+                                sourceRelationInfo1.setEstimateOutWarehouseWeight(Float.valueOf(String.valueOf(warehousingOrder1.getSurplusWeight())));
+                                sourceRelationInfo1.setSurplusWeight(sourceRelationInfo1.getEstimateOutWarehouseWeight());
+                                sourceRelationInfo1.setWarehouseName(warehousingOrder1.getWarehouseName());
+                                //计算比例
+                                sourceRelationInfo1.setProportion(Double.valueOf(String.valueOf(sourceRelationInfo1.getEstimateOutWarehouseWeight() / inOutWarehouseTask.getWeight())));
+                                sourceRelationInfoService.insert(sourceRelationInfo1);
+                                //全部出库
+                                warehousingOrder1.setOutWarehouseWeight(warehousingOrder1.getInWarehouseWeight());
+                                //修改入库单剩余重量
+                                warehousingOrder1.setSurplusWeight(0d);
+                                warehousingOrderService.updateById(warehousingOrder1);
+                            } else if (weight > 0) {
+                                Double weightTmp = weight - warehousingOrder1.getSurplusWeight();
+                                SourceRelationInfo sourceRelationInfo1=new SourceRelationInfo();
+                                sourceRelationInfo1.setId(IdGenerator.generateUUID());
+                                sourceRelationInfo1.setTaskId(inOutWarehouseTask.getId());
+                                sourceRelationInfo1.setSourceId(warehousingOrder1.getId());
+                                sourceRelationInfo1.setGoodsSource(warehousingOrder1.getGoodsSource());
+                                sourceRelationInfo1.setAvgCost(warehousingOrder1.getAvgCost());
+                                sourceRelationInfo1.setContractNo(warehousingOrder1.getContractNo());
+                                sourceRelationInfo1.setIssuingTime(warehousingOrder1.getIssuingTime());
+                                sourceRelationInfo1.setGoodsName(warehousingOrder1.getGoodsName());
+                                sourceRelationInfo1.setEstimateOutWarehouseWeight(Float.valueOf(String.valueOf(weight)));
+                                sourceRelationInfo1.setSurplusWeight(sourceRelationInfo1.getEstimateOutWarehouseWeight());
+                                sourceRelationInfo1.setWarehouseName(warehousingOrder1.getWarehouseName());
+                                if (i==sourceRelationInfoList.size()-1) {
+                                    //比例
+                                    Double proportion = 0d;
+                                    //最后一次循环
+                                    List<SourceRelationInfo> sourceRelationInfoList1 = sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+                                            .eq("task_id", sourceRelationInfo1.getTaskId()));
+                                    if (CollectionUtils.isNotEmpty(sourceRelationInfoList1)) {
+                                        //分摊比例和
+                                        proportion = (sourceRelationInfoList1.stream().mapToDouble(SourceRelationInfo::getProportion).sum());
+                                    }
+                                    sourceRelationInfo1.setProportion(1 - proportion);
+                                }
+                                else{
+                                    sourceRelationInfo1.setProportion(Double.valueOf(String.valueOf(sourceRelationInfo1.getEstimateOutWarehouseWeight() / inOutWarehouseTask.getWeight())));
+                                }
+                                sourceRelationInfoService.insert(sourceRelationInfo1);
+                                //部分出库
+                                warehousingOrder1.setOutWarehouseWeight(warehousingOrder1.getOutWarehouseWeight()+weight);
                                 //修改入库单剩余重量
-                                warehousingOrder.setSurplusWeight(warehousingOrder.getSurplusWeight() - sourceRelationInfo.getEstimateOutWarehouseWeight());
-                                warehousingOrderService.updateById(warehousingOrder);
+                                warehousingOrder1.setSurplusWeight(warehousingOrder1.getSurplusWeight()-weight);
+                                warehousingOrderService.updateById(warehousingOrder1);
+                                weight = weightTmp;
+                            } else {
+                                break;
                             }
                         }
                     }
+//                    for (int i=0;i<sourceRelationInfoList.size();i++){
+//                        SourceRelationInfo sourceRelationInfo=sourceRelationInfoList.get(i);
+//                        sourceRelationInfo.setId(IdGenerator.generateUUID());
+//                        sourceRelationInfo.setTaskId(inOutWarehouseTask.getId());
+//                        sourceRelationInfo.setIssuingTime(sourceRelationInfo.getIssuingTimeOther());
+//                        //最后一次循环
+//                        if (i==sourceRelationInfoList.size()-1){
+//                            double proportion=0d;
+//                            List<SourceRelationInfo> sourceRelationInfoList1=sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
+//                            .eq("task_id",sourceRelationInfo.getTaskId()));
+//                            if (CollectionUtils.isNotEmpty(sourceRelationInfoList1)){
+//                                //比例和
+//                                proportion = (sourceRelationInfoList1.stream().mapToDouble(SourceRelationInfo::getProportion).sum()) ;
+//                            }
+//                            sourceRelationInfo.setProportion(1-proportion);
+//
+//                        }
+//                        else {
+//                            //计算比例
+//                            sourceRelationInfo.setProportion(sourceRelationInfo.getEstimateOutWarehouseWeight() / Double.valueOf(String.valueOf(inOutWarehouseTask.getWeight())));
+//                        }
+//                        sourceRelationInfoService.insert(sourceRelationInfo);
+//                        //退库勾选标识
+//                        if (sourceRelationInfo.getWarehouseInOutId() != null) {
+//                            WarehouseInOutInfo warehouseInOutInfo = warehouseInOutInfoService.selectById(sourceRelationInfo.getWarehouseInOutId());
+//                            warehouseInOutInfo.setReturnTickFlag(sourceRelationInfo.getReturnTickFlag());
+//                            warehouseInOutInfoService.updateById(warehouseInOutInfo);
+//                        }
+//                        //出库
+//                        else {
+//                            WarehousingOrder warehousingOrder = warehousingOrderService.selectById(sourceRelationInfo.getSourceId());
+//                            if (warehousingOrder != null) {
+//                                warehousingOrder.setOutWarehouseWeight(warehousingOrder.getOutWarehouseWeight() + sourceRelationInfo.getEstimateOutWarehouseWeight());
+//                                //修改入库单剩余重量
+//                                warehousingOrder.setSurplusWeight(warehousingOrder.getSurplusWeight() - sourceRelationInfo.getEstimateOutWarehouseWeight());
+//                                warehousingOrderService.updateById(warehousingOrder);
+//                            }
+//                        }
+//                    }
                 }
             }
             //出库任务,入库任务,赋值关联id
@@ -422,6 +504,7 @@ public class InOutWarehouseTaskServiceImpl extends ServiceImpl<InOutWarehouseTas
             for (InOutWarehouseTask inOutWarehouseTask1 : inOutWarehouseTaskList) {
                 List<SourceRelationInfo> sourceRelationInfoList = sourceRelationInfoService.selectList(new EntityWrapper<SourceRelationInfo>()
                         .eq("task_id", inOutWarehouseTask1.getId())
+                        .orderBy("contract_no")
                         .eq("delete_flag", "0"));
                 if (CollectionUtils.isNotEmpty(sourceRelationInfoList)) {
                     inOutWarehouseTask1.setSourceRelationInfoList(sourceRelationInfoList);

+ 52 - 29
winsea-haixin-plugin-yiliangyiyun/src/main/resources/mapper/WarehousingOrderMapper.xml

@@ -345,6 +345,7 @@
     </select>
     <!-- 根据条件查询货源总数 -->
     <select id="getGoodSourceCountByCondition" parameterType="Map" resultType="java.lang.Integer">
+        SELECT count(1) from(
         SELECT
         COUNT(id)
         FROM warehousing_order
@@ -367,65 +368,87 @@
             DATE_FORMAT(#{endDate},"%Y%m%d"))
         </if>
         <if test="searchKeyWord != null and searchKeyWord != ''">
-            AND (lower(goods_source) like lower(CONCAT('%',#{searchKeyWord},'%')))
+            AND (lower(contract_no) like lower(CONCAT('%',#{searchKeyWord},'%')))
         </if>
         <if test="baseId != null and baseId != ''">
             AND base_id= #{baseId}
         </if>
-        <if test="flag != null and flag != ''">
-            <if test="flag == 0">
-                order by issuing_time
-            </if>
-            <if test="flag == 1">
-                order by avg_cost
-            </if>
-        </if>
+        GROUP BY contract_no,goods_name
+        ) tt
     </select>
     <!-- 根据条件查询货源列表 -->
     <select id="getGoodSourceListByCondition" parameterType="Map"
             resultType="com.yh.saas.plugin.yiliangyiyun.entity.WarehousingOrder">
         SELECT
-        id,
-        comp_id as compId,
-        goods_source as goodsSource,
-        warehouse_name as warehouseName,
-        goods_name as goodsName,
-        in_type as inType,
-        surplus_weight as surplusWeight,
-        avg_cost as avgCost,
-        issuing_time as issuingTimeElse,
-        issuing_time as issuingTimeOther
-        FROM warehousing_order
+        wo.id,
+        wo.comp_id AS compId,
+        wo.goods_source AS goodsSource,
+        wo.contract_no AS contractNo,
+        wo.warehouse_name AS warehouseName,
+        wo.goods_name AS goodsName,
+        wo.in_type AS inType,
+        (
+        SELECT
+        sum( wo1.surplus_weight )
+        FROM
+        warehousing_order wo1
         WHERE
-        delete_flag = '0'
+        wo1.contract_no = wo.contract_no
+        AND wo1.comp_id = wo.comp_id
+        AND wo1.delete_flag = 0
+        AND wo1.surplus_weight > 0
+        AND wo1.warehouse_name = wo.warehouse_name
+        AND wo1.goods_name = wo.goods_name
+        ) AS surplusWeight,
+        (
+        SELECT
+        ROUND( AVG( wo2.avg_cost ), 3 )
+        FROM
+        warehousing_order wo2
+        WHERE
+        wo2.warehouse_name = wo.warehouse_name
+        AND wo2.contract_no = wo.contract_no
+        AND wo2.goods_name = wo.goods_name
+        AND wo2.delete_flag = 0
+        AND wo2.comp_id = wo.comp_id
+        AND wo2.surplus_weight > 0
+        ) AS avgCost,
+        wo.issuing_time AS issuingTimeElse,
+        wo.issuing_time AS issuingTimeOther
+        FROM
+        warehousing_order wo
+        WHERE
+        wo.delete_flag = '0'
         <if test="searchType != null and searchType != ''">
             <if test="searchType == 1">
-                AND surplus_weight >0
+                AND  wo.surplus_weight >0
             </if>
         </if>
         <if test="goodsName != null and goodsName != ''">
-            AND goods_name= #{goodsName}
+            AND  wo.goods_name= #{goodsName}
         </if>
         <if test="startDate != null">
-            AND (DATE_FORMAT(create_date,"%Y%m%d") &gt;=
+            AND (DATE_FORMAT( wo.create_date,"%Y%m%d") &gt;=
             DATE_FORMAT(#{startDate},"%Y%m%d"))
         </if>
         <if test="endDate != null">
-            AND (DATE_FORMAT(create_date,"%Y%m%d") &lt;=
+            AND (DATE_FORMAT( wo.create_date,"%Y%m%d") &lt;=
             DATE_FORMAT(#{endDate},"%Y%m%d"))
         </if>
         <if test="searchKeyWord != null and searchKeyWord != ''">
-            AND (lower(goods_source) like lower(CONCAT('%',#{searchKeyWord},'%')))
+            AND (lower( wo.contract_no) like lower(CONCAT('%',#{searchKeyWord},'%')))
         </if>
         <if test="baseId != null and baseId != ''">
-            AND base_id= #{baseId}
+            AND  wo.base_id= #{baseId}
         </if>
+        GROUP BY
+        wo.contract_no,wo.goods_name
         <if test="flag != null and flag != ''">
             <if test="flag == 0">
-                order by issuing_time
+                order by  wo.issuing_time
             </if>
             <if test="flag == 1">
-                order by avg_cost
+                order by  wo.avg_cost
             </if>
         </if>
         <if test="currentPage != null and currentPage != ''">