Browse Source

问题处理

yzc 1 year ago
parent
commit
262a5dfb5e

+ 3 - 0
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractOutboundRecordsMapper.java

@@ -7,6 +7,8 @@ import com.fjhx.sale.entity.contract.vo.ContractOutboundRecordsVo;
 import com.ruoyi.common.utils.wrapper.IWrapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 
 /**
  * <p>
@@ -20,4 +22,5 @@ public interface ContractOutboundRecordsMapper extends BaseMapper<ContractOutbou
 
     Page<ContractOutboundRecordsVo> getPage(@Param("page") Page<Object> page, @Param("ew") IWrapper<ContractOutboundRecords> wrapper);
 
+    List<ContractOutboundRecordsVo> getList(@Param("ew") IWrapper wrapper);
 }

+ 6 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractOutboundRecordsService.java

@@ -5,6 +5,9 @@ import com.fjhx.sale.entity.contract.dto.ContractOutboundRecordsSelectDto;
 import com.fjhx.sale.entity.contract.po.ContractOutboundRecords;
 import com.fjhx.sale.entity.contract.vo.ContractOutboundRecordsVo;
 import com.ruoyi.common.core.service.BaseService;
+import com.ruoyi.common.utils.wrapper.IWrapper;
+
+import java.util.List;
 
 
 /**
@@ -18,4 +21,7 @@ import com.ruoyi.common.core.service.BaseService;
 public interface ContractOutboundRecordsService extends BaseService<ContractOutboundRecords> {
 
     Page<ContractOutboundRecordsVo> getPage(ContractOutboundRecordsSelectDto dto);
+
+    List<ContractOutboundRecordsVo> getList(IWrapper wrapper);
+
 }

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractOutboundRecordsServiceImpl.java

@@ -55,4 +55,9 @@ public class ContractOutboundRecordsServiceImpl extends ServiceImpl<ContractOutb
         });
         return page;
     }
+
+    @Override
+    public List<ContractOutboundRecordsVo> getList(IWrapper wrapper) {
+        return baseMapper.getList(wrapper);
+    }
 }

+ 27 - 8
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -3126,14 +3126,33 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         }
 
         //修改订单出库状态
-        this.update(q -> q
-                        .eq(Contract::getId, contractId)
-//                .set(Contract::getOutboundStatus, 1)
-//                .set(Contract::getOutboundTime, new Date())
-                        .set(Contract::getStatus, 75)//已发货
-                        .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
-                        .set(BasePo::getUpdateTime, new Date())
-        );
+        //统计出库数量
+        boolean flag = true;
+        List<ContractProduct> list = contractProductService.list(q -> q.eq(ContractProduct::getQuantity, contractId));
+        for (ContractProduct contractProduct : list) {
+            List<ContractOutboundRecordsVo> cor = contractOutboundRecordsService.getList(IWrapper.getWrapper()
+                    .eq("cor", ContractOutboundRecords::getContractProductId, contractProduct.getId())
+                    .in("coi.status", 10, 30, 60)
+            );
+            if (ObjectUtil.isEmpty(cor)) {
+                cor = new ArrayList<>();
+            }
+            BigDecimal outCount = cor.stream()
+                    .map(ContractOutboundRecords::getQuantity)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            if (contractProduct.getQuantity().compareTo(outCount) > 0) {
+                flag = false;
+                break;
+            }
+        }
+        if (flag) {
+            this.update(q -> q
+                    .eq(Contract::getId, contractId)
+                    .set(Contract::getStatus, 75)//已发货
+                    .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
+                    .set(BasePo::getUpdateTime, new Date())
+            );
+        }
 
         ContractVo contract = baseMapper.detail(contractId);
         Assert.notEmpty(contract, "查询不到销售订单信息!");

+ 3 - 1
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -52,7 +52,9 @@
                                                      IFNULL(sum(cp.quantity), 0)  AS quantity,
                                                      IFNULL(sum(cor.quantity), 0) AS deliverQuantity
                                               FROM contract_product cp
-                                                       LEFT JOIN contract_outbound_records cor ON cp.contract_id = cor.contract_id
+                                                       LEFT JOIN contract_outbound_records cor ON cp.id = cor.contract_product_id
+                                                       LEFT JOIN contract_outbound_info coi ON cor.record_id = coi.id
+                                              WHERE coi.`status` in (30, 60)
                                               GROUP BY cp.contract_id) t1) t4 ON t4.contract_id = t1.id) t1
               GROUP BY t1.id) t1
             ${ew.customSqlSegment}

+ 6 - 0
hx-sale/src/main/resources/mapper/contract/ContractOutboundRecordsMapper.xml

@@ -8,4 +8,10 @@
                  JOIN contract_outbound_info coi ON cor.record_id = coi.id
             ${ew.customSqlSegment}
     </select>
+    <select id="getList" resultType="com.fjhx.sale.entity.contract.vo.ContractOutboundRecordsVo">
+        SELECT cor.*
+        FROM contract_outbound_records cor
+                 JOIN contract_outbound_info coi ON cor.record_id = coi.id
+            ${ew.customSqlSegment}
+    </select>
 </mapper>