wucl преди 1 година
родител
ревизия
37518d9141

+ 2 - 0
dao/src/main/java/com/dayou/mapper/OrderFundMapper.java

@@ -19,4 +19,6 @@ public interface OrderFundMapper extends CustomBaseMapper<OrderFund> {
     void updateRealAmount(@Param("id") Long id, @Param("thisTimeAmount") BigDecimal thisTimeAmount);
 
     void updateRealAmountByOrderId(@Param("orderId") String orderId, @Param("thisTimeAmount") BigDecimal thisTimeAmount);
+
+    BigDecimal residueNotAllotAmount(@Param("orderFundId") Long orderFundId);
 }

+ 2 - 4
dao/src/main/resources/mapper/FinanceRealFundMapper.xml

@@ -73,12 +73,10 @@
     </select>
 
     <select id="getNotClaimAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
-        SELECT
-
-            ( frf.amount - ifnull(t.ca,0) ) AS notClaimAmount
+        SELECT ( frf.amount -( SELECT ifnull( sum( claim_amount ), 0 ) AS ca FROM finance_claim WHERE deleted = 0 AND real_fund_id = #{realFundId} )
+                   ) AS notClaimAmount
         FROM
             finance_real_fund frf
-                INNER JOIN ( SELECT real_fund_id,ifnull(sum(claim_amount),0) as ca  FROM finance_claim WHERE deleted = 0 and real_fund_id = #{realFundId} ) t ON t.real_fund_id = frf.id
         WHERE
             frf.deleted = 0
     </select>

+ 9 - 0
dao/src/main/resources/mapper/OrderFundMapper.xml

@@ -31,4 +31,13 @@
     <update id="updateRealAmountByOrderId">
         update order_fund set real_amount = (ifnull(real_amount,0) + #{thisTimeAmount}) where order_id = #{orderId} and deleted = 0
     </update>
+
+    <select id="residueNotAllotAmount" parameterType="java.lang.Long" resultType="java.math.BigDecimal">
+        SELECT ( of.real_amount-( SELECT ifnull( sum( real_amount ), 0 ) AS ca FROM production_fund WHERE deleted = 0 AND order_fund_id = #{orderFundId} )
+                   ) AS notClaimAmount
+        FROM
+            order_fund of
+        WHERE
+            of.deleted = 0
+    </select>
 </mapper>

+ 2 - 1
dao/src/main/resources/mapper/ProductionFundMapper.xml

@@ -41,7 +41,8 @@
             mp.evaluate_amount,
             sum(pf.real_amount) as claimedAmount,
             pf.standard_amount,
-            mp.report_no as businessSubId
+            mp.report_no as businessSubId,
+            pf.id as productionFundId
         FROM
             ( SELECT id, business_id FROM order_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 AND id = #{orderFundId} ) orf
                 INNER JOIN ( SELECT id, major_id, report_no, production, evaluate_amount FROM major_production WHERE  deleted = 0 and name is not null ) mp ON orf.business_id = mp.major_id

+ 3 - 0
domain/src/main/java/com/dayou/dto/ReportDTO.java

@@ -40,9 +40,12 @@ public class ReportDTO {
 
     private List<ProductionDTO> productions;
 
+
     /**
      * 已分配金额
      */
     private BigDecimal claimedAmount;
 
+    private BigDecimal thisTimeAmount;
+
 }

+ 7 - 0
service/src/main/java/com/dayou/service/IOrderFundService.java

@@ -5,6 +5,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
+
+import java.math.BigDecimal;
+
 /**
  * <p>
  * 订单应收款 服务类
@@ -25,4 +28,8 @@ public interface IOrderFundService extends IService<OrderFund> {
 
         Boolean delete(Long id);
 
+        BigDecimal residueNotAllotAmount(Long orderFundId);
+
+
+
 }

+ 23 - 10
service/src/main/java/com/dayou/service/impl/MajorProductionServiceImpl.java

@@ -382,6 +382,9 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
 
             for (OrderReportDTO orderReportDTO : claimOrders){
                 BigDecimal thisTimeAmount = orderReportDTO.getThisTimeAmount();
+                if (thisTimeAmount==null || thisTimeAmount.compareTo(BigDecimal.ZERO)==0){
+                    continue;
+                }
                 Long productionFundId = orderReportDTO.getProductionFundId();
                 if (productionFundId==null){
                     MajorProduction production = majorProductionMapper.selectOne(new LambdaQueryWrapper<MajorProduction>().eq(BaseEntity::getId,orderReportDTO.getId()).eq(BaseEntity::getDeleted, Boolean.FALSE)
@@ -425,7 +428,10 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
     public synchronized Boolean allotRealAmountToOrder(List<OrderReportDTO> claimOrders) {
         return majorProductionService.doAllotRealAmountToOrder(claimOrders);
     }
+
+
     @Override
+    @Transactional
     public Boolean doAllotRealAmountToOrder(List<OrderReportDTO> claimOrders) {
         if (CollectionUtil.isNotEmpty(claimOrders)){
             //先校验各订单此次认领金额之和是否大于这笔实收款的剩余金额
@@ -439,6 +445,9 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
 
             for (OrderReportDTO orderReportDTO : claimOrders){
                 BigDecimal thisTimeAmount = orderReportDTO.getThisTimeAmount();
+                if (thisTimeAmount==null || thisTimeAmount.compareTo(BigDecimal.ZERO)==0){
+                    continue;
+                }
                 //更新订单实收款
                 Long orderFundId = orderReportDTO.getOrderFundId();
                 orderFundMapper.updateRealAmount(orderFundId, thisTimeAmount);
@@ -514,30 +523,34 @@ public class MajorProductionServiceImpl extends ServiceImpl<MajorProductionMappe
     public synchronized Boolean allotRealAmountToProduction(OrderReportDTO orderReportDTO) {
         List<ReportDTO> reports = orderReportDTO.getReports();
         Long orderFundId = orderReportDTO.getOrderFundId();
-        BigDecimal totalAmount = reports.stream().filter(x->x.getRealAmount()!=null).map(ReportDTO::getRealAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+        BigDecimal residueAmount = orderFundMapper.residueNotAllotAmount(orderFundId);
+        BigDecimal totalAmount = reports.stream().filter(x->x.getThisTimeAmount()!=null).map(ReportDTO::getThisTimeAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
         if (orderReportDTO.getRealAmount()==null){
             ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"该订单还未认领实收款,请先认领实收款后再分配。");
         }
-        if (totalAmount.compareTo(orderReportDTO.getRealAmount())>0){
-            ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"产品分配金额不能大于订单已认领金额,请检查后再试。");
+        if (totalAmount.compareTo(residueAmount)>0){
+            ErrorCode.throwBusinessException(ErrorCode.CUSTOM_ERROR,"产品分配金额不能大于订单未分配金额,请检查后再试。");
         }
         if (CollectionUtil.isNotEmpty(reports)){
             for (ReportDTO reportDTO :reports){
-                if (reportDTO.getProductionFundId()==null){
+                Long productionFundId = reportDTO.getProductionFundId();
+                if (reportDTO.getThisTimeAmount()==null || reportDTO.getThisTimeAmount().compareTo(BigDecimal.ZERO)==0){
+                    continue;
+                }
+                if (productionFundId==null){
                     MajorProduction production = majorProductionMapper.selectOne(new LambdaQueryWrapper<MajorProduction>().eq(BaseEntity::getId,reportDTO.getId()).eq(BaseEntity::getDeleted, Boolean.FALSE)
                             .select(MajorProduction::getReportNo, MajorProduction::getMajorId, MajorProduction::getProduction, MajorProduction::getEvaluateAmount));
                     ProductionFund productionFund = new ProductionFund();
                     productionFund.setProductionType(production.getProduction());
                     productionFund.setBusinessType(MainBusinessEnum.MAJOR_BUSINESS.name());
-                    productionFund.setOrderFundId(orderFundId);
+                    productionFund.setOrderFundId(orderReportDTO.getOrderFundId());
                     productionFund.setBusinessId(production.getMajorId());
                     productionFund.setProductionNo(production.getReportNo());
-                    productionFund.setRealAmount(reportDTO.getRealAmount());
-                    productionFund.setEvaluateAmount(reportDTO.getEvaluateAmount());
+                    productionFund.setRealAmount(reportDTO.getThisTimeAmount());
+                    productionFund.setEvaluateAmount(production.getEvaluateAmount());
                     productionFundService.add(productionFund);
-                }
-                else {
-                    productionFundService.update(new LambdaUpdateWrapper<ProductionFund>().set(ProductionFund::getRealAmount,reportDTO.getRealAmount()).eq(BaseEntity::getId,reportDTO.getProductionFundId()));
+                }else {
+                    productionFundMapper.updateRealAmount(productionFundId,reportDTO.getThisTimeAmount());
                 }
             }
             return Boolean.TRUE;

+ 11 - 0
service/src/main/java/com/dayou/service/impl/OrderFundServiceImpl.java

@@ -4,6 +4,7 @@ import com.dayou.entity.OrderFund;
 import com.dayou.mapper.OrderFundMapper;
 import com.dayou.service.IOrderFundService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -19,6 +20,8 @@ import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.web.multipart.MultipartFile;
+
+import java.math.BigDecimal;
 import java.util.List;
 import java.util.ArrayList;
 import org.springframework.transaction.annotation.Transactional;
@@ -35,6 +38,8 @@ import com.dayou.enums.BatchTaskTypeEnum;
 @Service
 public class OrderFundServiceImpl extends ServiceImpl<OrderFundMapper, OrderFund> implements IOrderFundService {
 
+    @Autowired
+    private OrderFundMapper orderFundMapper;
 
     @Override
     @SuppressWarnings("unchecked")
@@ -63,4 +68,10 @@ public class OrderFundServiceImpl extends ServiceImpl<OrderFundMapper, OrderFund
         //逻辑删除
         return this.removeById(id);
     }
+
+    @Override
+    public synchronized BigDecimal residueNotAllotAmount(Long orderFundId) {
+        BigDecimal residue = orderFundMapper.residueNotAllotAmount(orderFundId);
+        return residue;
+    }
 }