Bläddra i källkod

申购 采购 作废问题处理

yzc 1 år sedan
förälder
incheckning
16e48d2dd4

+ 0 - 5
hx-admin/pom.xml

@@ -46,11 +46,6 @@
 
         <dependency>
             <groupId>com.fjhx</groupId>
-            <artifactId>hx-sale</artifactId>
-        </dependency>
-
-        <dependency>
-            <groupId>com.fjhx</groupId>
             <artifactId>hx-account</artifactId>
         </dependency>
 

+ 18 - 18
hx-purchase/src/main/java/com/fjhx/purchase/entity/purchase/po/Purchase.java

@@ -89,24 +89,6 @@ public class Purchase extends BasePo {
     private String currency;
 
     /**
-     * 采购明细列表
-     */
-    @TableField(exist = false)
-    private List<PurchaseDetail> purchaseDetailList;
-
-    /**
-     * 发票总金额
-     */
-    @TableField(exist = false)
-    private BigDecimal sumInvoiceMoney;
-
-    /**
-     * 付款总金额
-     */
-    @TableField(exist = false)
-    private BigDecimal sumPayMoney;
-
-    /**
      * 维多利亚扩展json
      */
     private String victoriatouristJson;
@@ -130,4 +112,22 @@ public class Purchase extends BasePo {
      * 归属项目组
      */
     private Long teamId;
+    //============================
+    /**
+     * 采购明细列表
+     */
+    @TableField(exist = false)
+    private List<PurchaseDetail> purchaseDetailList;
+
+    /**
+     * 发票总金额
+     */
+    @TableField(exist = false)
+    private BigDecimal sumInvoiceMoney;
+
+    /**
+     * 付款总金额
+     */
+    @TableField(exist = false)
+    private BigDecimal sumPayMoney;
 }

+ 2 - 0
hx-purchase/src/main/java/com/fjhx/purchase/entity/purchase/vo/PurchaseVo.java

@@ -59,4 +59,6 @@ public class PurchaseVo extends Purchase {
      */
     private BigDecimal amountSum;
 
+    private String contractCode;
+
 }

+ 24 - 56
hx-sale/src/main/java/com/fjhx/sale/flow/PurchaseFlowByWdly.java → hx-purchase/src/main/java/com/fjhx/purchase/flow/PurchaseFlowByWdly.java

@@ -1,4 +1,4 @@
-package com.fjhx.sale.flow;
+package com.fjhx.purchase.flow;
 
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson2.JSONWriter;
@@ -16,20 +16,16 @@ import com.fjhx.flow.core.FlowDelegate;
 import com.fjhx.flow.core.FlowThreadLocalUtil;
 import com.fjhx.flow.enums.FlowStatusEnum;
 import com.fjhx.purchase.entity.purchase.dto.PurchaseDto;
-import com.fjhx.purchase.entity.purchase.enums.PurchaseDataResourceEnum;
 import com.fjhx.purchase.entity.purchase.enums.PurchaseDetailStatusEnum;
 import com.fjhx.purchase.entity.purchase.enums.PurchaseStatusEnum;
 import com.fjhx.purchase.entity.purchase.po.Purchase;
 import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
-import com.fjhx.purchase.entity.subscribe.enums.SubscribeDetailStatusEnum;
 import com.fjhx.purchase.entity.subscribe.po.Subscribe;
 import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
 import com.fjhx.purchase.service.purchase.PurchaseDetailService;
 import com.fjhx.purchase.service.purchase.PurchaseService;
 import com.fjhx.purchase.service.subscribe.SubscribeDetailService;
 import com.fjhx.purchase.service.subscribe.SubscribeService;
-import com.fjhx.sale.entity.contract.po.ContractProduct;
-import com.fjhx.sale.service.contract.ContractProductService;
 import com.ruoyi.common.core.domain.BasePo;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.utils.SecurityUtils;
@@ -38,10 +34,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.math.BigDecimal;
-import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * 采购流程
@@ -62,8 +56,6 @@ public class PurchaseFlowByWdly extends FlowDelegate {
     @Autowired
     private SubscribeDetailService subscribeDetailService;
     @Autowired
-    private ContractProductService contractProductService;
-    @Autowired
     private CodingRuleService codingRuleService;
 
     @Override
@@ -113,8 +105,10 @@ public class PurchaseFlowByWdly extends FlowDelegate {
                         throw new ServiceException("采购数量不能小于或等于0");
                     }
                     //计算采购数量是否大于申购数量
-                    List<PurchaseDetail> purchaseDetailList1 = purchaseDetailService.list(q -> q.eq(PurchaseDetail::getSubscribeDetailId,
-                            s.getSubscribeDetailId()));
+                    List<PurchaseDetail> purchaseDetailList1 = purchaseDetailService.list(q -> q
+                            .eq(PurchaseDetail::getSubscribeDetailId, s.getSubscribeDetailId())
+                            .in(PurchaseDetail::getStatus, 10, 30, 99)
+                    );
                     //求和
                     BigDecimal purchaseCount = purchaseDetailList1.stream()
                             .map(PurchaseDetail::getCount)
@@ -170,30 +164,30 @@ public class PurchaseFlowByWdly extends FlowDelegate {
     public void end(Long flowId, Long businessId, JSONObject submitData) {
         //修改申购明细状态
         List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
-        updateSubscribeStatus(businessId);
+        purchaseService.updateSubscribeStatus(businessId);
 
         //通过业务ID查询采购数据
         Purchase purchase = purchaseService.getById(businessId);
         if (ObjectUtils.isEmpty(purchase)) {
             throw new ServiceException("采购单不存在");
         }
-        //查询采购产品
-        List<ContractProduct> upContractProduct = new ArrayList<>();
-        for (PurchaseDetail p : purchaseDetailList) {
-            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
-                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
-                ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
-                BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
-                if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
-                    throw new ServiceException("采购数量不得大于外销合同数量");
-                }
-                contractProduct.setExpendQuantity(expendQuantity);
-                upContractProduct.add(contractProduct);
-            }
-        }
-        if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
-            contractProductService.updateBatchById(upContractProduct);
-        }
+//        //查询采购产品
+//        List<ContractProduct> upContractProduct = new ArrayList<>();
+//        for (PurchaseDetail p : purchaseDetailList) {
+//            if (ObjectUtils.isNotEmpty(p.getDataResourceId()) &&
+//                    p.getDataResource() == PurchaseDataResourceEnum.DATA_RESOURCE_1.getKey()) {//如果采购的是外销合同
+//                ContractProduct contractProduct = contractProductService.getById(p.getDataResourceId());
+//                BigDecimal expendQuantity = contractProduct.getExpendQuantity().subtract(p.getCount());
+//                if (expendQuantity.compareTo(BigDecimal.ZERO) < 1) {//小于0不让继续执行
+//                    throw new ServiceException("采购数量不得大于外销合同数量");
+//                }
+//                contractProduct.setExpendQuantity(expendQuantity);
+//                upContractProduct.add(contractProduct);
+//            }
+//        }
+//        if (CollectionUtils.isNotEmpty(upContractProduct)) {//扣减销售合同数量
+//            contractProductService.updateBatchById(upContractProduct);
+//        }
         //修改采购状态为审批通过
         purchase.setPurchaseStatus(PurchaseStatusEnum.PASS.getKey());
         purchase.setApprovedDate(new Date());
@@ -232,7 +226,7 @@ public class PurchaseFlowByWdly extends FlowDelegate {
                 .set(BasePo::getUpdateUser, SecurityUtils.getUserId())
         );
         //修改申购明细状态
-        updateSubscribeStatus(businessId);
+        purchaseService.updateSubscribeStatus(businessId);
     }
 
     /**
@@ -303,30 +297,4 @@ public class PurchaseFlowByWdly extends FlowDelegate {
         }
     }
 
-    /**
-     * 更新申购明细的待采购状态
-     */
-    private void updateSubscribeStatus(Long businessId) {
-        //修改申购明细状态
-        List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
-        List<Long> subscribeDetailIds = purchaseDetailList.stream().map(PurchaseDetail::getSubscribeDetailId).collect(Collectors.toList());
-        List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
-        for (SubscribeDetail subscribeDetail : subscribeDetails) {
-            //获取申购明细下的所有采购记录 计算已采购数
-            List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(q -> q.eq(PurchaseDetail::getSubscribeDetailId,
-                    subscribeDetail.getId()).eq(PurchaseDetail::getBussinessId, subscribeDetail.getBussinessId()));
-            BigDecimal count = purchaseDetails.stream()
-                    .map(PurchaseDetail::getCount)
-                    .reduce(BigDecimal.ZERO, BigDecimal::add);
-            if (count.compareTo(subscribeDetail.getCount()) >= 0) {
-                //修改为已采购
-                subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
-            } else {
-                //修改为部分采购
-                subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
-            }
-        }
-        subscribeDetailService.updateBatchById(subscribeDetails);
-    }
-
 }

+ 3 - 0
hx-purchase/src/main/java/com/fjhx/purchase/service/purchase/PurchaseService.java

@@ -29,6 +29,7 @@ public interface PurchaseService extends BaseService<Purchase> {
      * 采购分页
      */
     Page<PurchaseVo> getPage(PurchaseSelectDto dto);
+    List<PurchaseVo> getList(IWrapper<Purchase> wrapper);
 
     /**
      * 采购分页 维多利亚
@@ -112,4 +113,6 @@ public interface PurchaseService extends BaseService<Purchase> {
      * 作废
      */
     void cancellation(Long id);
+
+    void updateSubscribeStatus(Long businessId);
 }

+ 43 - 0
hx-purchase/src/main/java/com/fjhx/purchase/service/purchase/impl/PurchaseServiceImpl.java

@@ -48,6 +48,7 @@ import com.fjhx.purchase.entity.purchase.vo.PurchaseDocumentaryVo;
 import com.fjhx.purchase.entity.purchase.vo.PurchasePayRecordDetailVo;
 import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
 import com.fjhx.purchase.entity.quality.po.QualityDetail;
+import com.fjhx.purchase.entity.subscribe.enums.SubscribeDetailStatusEnum;
 import com.fjhx.purchase.entity.subscribe.po.Subscribe;
 import com.fjhx.purchase.entity.subscribe.po.SubscribeDetail;
 import com.fjhx.purchase.mapper.purchase.PurchaseMapper;
@@ -191,6 +192,11 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
         return page;
     }
 
+    @Override
+    public List<PurchaseVo> getList(IWrapper<Purchase> wrapper) {
+        return baseMapper.getList(wrapper);
+    }
+
     private IWrapper<Purchase> getWdlyPageWrapper(PurchaseSelectDto dto) {
         IWrapper<Purchase> wrapper = getWrapper();
 
@@ -985,5 +991,42 @@ public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase>
                 .set(BasePo::getUpdateTime, new Date())
         );
         DynamicDataSourceContextHolder.poll();
+
+        //更新待采购状态
+        updateSubscribeStatus(id);
+    }
+
+    /**
+     * 更新申购明细的待采购状态
+     */
+    @Override
+    public void updateSubscribeStatus(Long businessId) {
+        //修改申购明细状态
+        List<PurchaseDetail> purchaseDetailList = purchaseDetailService.list(Wrappers.<PurchaseDetail>query().lambda().eq(PurchaseDetail::getPurchaseId, businessId));
+        List<Long> subscribeDetailIds = purchaseDetailList.stream().map(PurchaseDetail::getSubscribeDetailId).collect(Collectors.toList());
+        List<SubscribeDetail> subscribeDetails = subscribeDetailService.listByIds(subscribeDetailIds);
+        for (SubscribeDetail subscribeDetail : subscribeDetails) {
+            //获取申购明细下的所有采购记录 计算已采购数
+            List<PurchaseDetail> purchaseDetails = purchaseDetailService.list(q -> q
+                    .eq(PurchaseDetail::getSubscribeDetailId,
+                            subscribeDetail.getId()).eq(PurchaseDetail::getBussinessId, subscribeDetail.getBussinessId())
+                    .in(PurchaseDetail::getStatus, 10, 30, 99)
+            );
+            BigDecimal count = purchaseDetails.stream()
+                    .map(PurchaseDetail::getCount)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            if (count.compareTo(subscribeDetail.getCount()) >= 0) {
+                //修改为已采购
+                subscribeDetail.setStatus(SubscribeDetailStatusEnum.PURCHASED.getKey());
+            } else {
+                //修改为部分采购
+                subscribeDetail.setStatus(SubscribeDetailStatusEnum.LITT_PAID_AMOUNT.getKey());
+            }
+            if (count.compareTo(BigDecimal.ZERO) <= 0) {
+                //待采购
+                subscribeDetail.setStatus(SubscribeDetailStatusEnum.PAID_AMOUNT.getKey());
+            }
+        }
+        subscribeDetailService.updateBatchById(subscribeDetails);
     }
 }

+ 7 - 7
hx-purchase/src/main/java/com/fjhx/purchase/service/subscribe/impl/SubscribeDetailServiceImpl.java

@@ -20,6 +20,7 @@ import com.fjhx.item.util.excel.util.ExcelUtil;
 import com.fjhx.purchase.entity.purchase.po.Purchase;
 import com.fjhx.purchase.entity.purchase.po.PurchaseDetail;
 import com.fjhx.purchase.entity.purchase.vo.PurchaseDetailVo;
+import com.fjhx.purchase.entity.purchase.vo.PurchaseVo;
 import com.fjhx.purchase.entity.subscribe.SubscribeDetailExcelBo;
 import com.fjhx.purchase.entity.subscribe.dto.SubscribeDetailDto;
 import com.fjhx.purchase.entity.subscribe.dto.SubscribeDetailSelectDto;
@@ -392,13 +393,12 @@ public class SubscribeDetailServiceImpl extends ServiceImpl<SubscribeDetailMappe
         List<Long> pIds = purchaseDetailService.listObject(PurchaseDetail::getPurchaseId, q -> q.eq(PurchaseDetail::getSubscribeDetailId, id));
         if (ObjectUtils.isNotEmpty(pIds)) {
             //如果存在 非作废的采购订单
-            List<String> pCode = purchaseService.listObject(Purchase::getCode, q -> q
-                    .ne(Purchase::getPurchaseStatus, 88)
-                    .in(Purchase::getId, pIds)
-            );
-            if (ObjectUtils.isNotEmpty(pCode)) {
-                String collect = pCode.stream().collect(Collectors.joining(","));
-                throw new com.obs.services.internal.ServiceException("该申购单下存在【非作废】的采购订单,单号如下:" + collect + " 禁止作废!");
+            List<PurchaseVo> pList = purchaseService.getList(IWrapper.<Purchase>getWrapper()
+                    .ne("p",Purchase::getPurchaseStatus, 88)
+                    .in("p",Purchase::getId, pIds));
+            if (ObjectUtils.isNotEmpty(pList)) {
+                String pCode = pList.stream().map(PurchaseVo::getContractCode).collect(Collectors.joining(","));
+                throw new com.obs.services.internal.ServiceException("该申购单下存在【非作废】的采购订单,单号如下:" + pCode + " 禁止作废!");
             }
         }
 

+ 2 - 1
hx-purchase/src/main/resources/mapper/purchase/PurchaseMapper.xml

@@ -33,7 +33,8 @@
                p.data_resource,
                p.data_resource_id,
                IF(sum( dg.`status` ) != count( dg.`status` ), 1, 0) isTransit,
-               de.dept_name
+               de.dept_name,
+               p.contractCode
         FROM purchase p
                  LEFT JOIN bytesailing_base.sys_dept de ON p.team_id = de.dept_id
                  LEFT JOIN bytesailing_victoriatourist.deliver_goods dg ON dg.purchase_id = p.id

+ 0 - 7
pom.xml

@@ -19,7 +19,6 @@
         <module>hx-wms</module>
         <module>hx-common</module>
         <module>hx-purchase</module>
-        <module>hx-sale</module>
         <module>hx-account</module>
         <module>hx-victoriatourist</module>
     </modules>
@@ -90,12 +89,6 @@
 
             <dependency>
                 <groupId>com.fjhx</groupId>
-                <artifactId>hx-sale</artifactId>
-                <version>${hx.version}</version>
-            </dependency>
-
-            <dependency>
-                <groupId>com.fjhx</groupId>
                 <artifactId>hx-account</artifactId>
                 <version>${hx.version}</version>
             </dependency>