Parcourir la source

利润预算结算添加 是否亏损

yzc il y a 1 an
Parent
commit
54c30ae34f

+ 5 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/dto/ContractSelectDto.java

@@ -83,4 +83,9 @@ public class ContractSelectDto extends BaseSelectDto {
      * 是否结清 1是0否
      */
     private Integer isSettled;
+
+    /**
+     * 是否亏损 1是 0否
+     */
+    private Integer isLoss;
 }

+ 11 - 0
hx-sale/src/main/java/com/fjhx/sale/entity/contract/vo/ContractBudgetVo.java

@@ -1,6 +1,7 @@
 package com.fjhx.sale.entity.contract.vo;
 
 import com.fjhx.sale.entity.contract.po.Contract;
+import com.fjhx.sale.entity.purchase.po.EhsdPurchase;
 import com.ruoyi.common.core.domain.BasePo;
 import lombok.Getter;
 import lombok.Setter;
@@ -190,6 +191,16 @@ public class ContractBudgetVo extends Contract {
      */
     private BigDecimal accountPaid;
 
+    /**
+     * 采购列表
+     */
+    private List<EhsdPurchase> purchasesList;
+
+    /**
+     * 是否亏损
+     */
+    private Integer isLoss;
+
     private List<GrossProfitInfo> grossProfitInfoList;
 
     @Getter

+ 45 - 4
hx-sale/src/main/java/com/fjhx/sale/service/contract/impl/ContractServiceImpl.java

@@ -459,11 +459,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
 
         //客户名称
         if (StringUtils.isNotEmpty(dto.getCustomerName())) {
-            wrapper.like("cu.name", dto.getCustomerName());
+            wrapper.like("t1.name", dto.getCustomerName());
         }
         //业务员
         if (StringUtils.isNotEmpty(dto.getUserName())) {
-            wrapper.like("us1.nick_name", dto.getUserName());
+            wrapper.like("t1.nick_name", dto.getUserName());
         }
         //销售合同编号
         if (StringUtils.isNotEmpty(dto.getContractCode())) {
@@ -478,6 +478,17 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
 
         //是否结清过滤
         wrapper.eq("t1", Contract::getIsSettled, dto.getIsSettled());
+
+        //是否亏损过滤
+        Integer isLoss = dto.getIsLoss();
+        if (ObjectUtil.isNotEmpty(isLoss)) {
+            if (Objects.equals(isLoss, 1)) {
+                wrapper.apply("(t1.amount*t1.rate)<t1.sumPurchaseContractMoney");
+            } else {
+                wrapper.apply("(t1.amount*t1.rate)>=t1.sumPurchaseContractMoney");
+            }
+        }
+
         return wrapper;
     }
 
@@ -504,6 +515,21 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         //计数历史毛利率图
         setGrossProfitInfoList(list);
 
+        //添加采购列表
+        List<Long> ids = list.stream().map(ContractBudgetVo::getContractId).collect(Collectors.toList());
+        Map<Long, List<EhsdPurchase>> map = ehsdPurchaseService.mapKGroup(EhsdPurchase::getDataResourceId,
+                q -> q.in(EhsdPurchase::getDataResourceId, ids).in(EhsdPurchase::getStatus, 12, 30, 60));
+        list.forEach(item -> item.setPurchasesList(map.get(item.getContractId())));
+
+        for (ContractBudgetVo contractBudgetVo : list) {
+            //赋值采购列表
+            contractBudgetVo.setPurchasesList(map.get(contractBudgetVo.getContractId()));
+//            //赋值是否亏损
+//            BigDecimal ehsdSumAmount = contractBudgetVo.getEhsdSumAmount();
+//            ehsdSumAmount = ObjectUtil.isEmpty(ehsdSumAmount)?BigDecimal.ZERO:ehsdSumAmount;
+//            contractBudgetVo.setIsLoss(contractBudgetVo.getRmbContractAmount().compareTo(ehsdSumAmount)<0?1:0);
+        }
+
         return page;
     }
 
@@ -531,6 +557,8 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 if (ObjectUtil.isNotEmpty(contract)) {
                     oldContractId = contract.getOldContractId();
                     arr.add(contract);
+                } else {
+                    oldContractId = null;
                 }
             }
 
@@ -867,11 +895,11 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
 
         //客户名称
         if (StringUtils.isNotEmpty(dto.getCustomerName())) {
-            wrapper.like("cu.name", dto.getCustomerName());
+            wrapper.like("t1.name", dto.getCustomerName());
         }
         //业务员
         if (StringUtils.isNotEmpty(dto.getUserName())) {
-            wrapper.like("us1.nick_name", dto.getUserName());
+            wrapper.like("t1.nick_name", dto.getUserName());
         }
         //销售合同编号
         if (StringUtils.isNotEmpty(dto.getContractCode())) {
@@ -887,6 +915,16 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
         //是否结清过滤
         wrapper.eq("t1", Contract::getIsSettled, dto.getIsSettled());
 
+        //是否亏损过滤
+        Integer isLoss = dto.getIsLoss();
+        if (ObjectUtil.isNotEmpty(isLoss)) {
+            if (Objects.equals(isLoss, 1)) {
+                wrapper.apply("(t1.amount*t1.rate)<t1.sumPurchaseContractMoney");
+            } else {
+                wrapper.apply("(t1.amount*t1.rate)>=t1.sumPurchaseContractMoney");
+            }
+        }
+
         Page<ContractBudgetVo> page = this.baseMapper.getProfitClearingPage(dto.getPage(), wrapper);
         List<ContractBudgetVo> list = page.getRecords();
         if (ObjectUtil.isEmpty(list)) {
@@ -965,6 +1003,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
                 }
                 v.setGrossRate(grossRate);
             }
+
+            //赋值采购列表
+            v.setPurchasesList(purchaseMap.get(v.getContractId()));
         }
         return page;
     }

+ 63 - 34
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -58,47 +58,76 @@
     </select>
 
     <select id="getProfitClearingPage" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
-        SELECT t1.id AS      contractId,
-               us1.nick_name userName,
-               t1.*
-        FROM contract t1
-                 LEFT JOIN bytesailing_customer.customer cu on t1.buy_corporation_id = cu.id and cu.del_flag = 0
-                 LEFT JOIN bytesailing_base.sys_user us1 ON cu.user_id = us1.user_id and us1.del_flag = 0
-            ${ew.customSqlSegment}
+        SELECT t1.*,
+               if(t1.amount &lt; t1.sumPurchaseContractMoney, 1, 0) AS isLoss
+        from (SELECT t1.id                            AS contractId,
+                     us1.nick_name                       userName,
+                     t1.*,
+                     (select IFNULL(SUM(amount), 0)
+                      from ehsd_purchase
+                      where data_resource_id = t1.id
+                        and `status` in (10, 30, 60)) as sumPurchaseContractMoney
+              FROM contract t1
+                       LEFT JOIN bytesailing_customer.customer cu
+                                 on t1.buy_corporation_id = cu.id and cu.del_flag = 0
+                       LEFT JOIN bytesailing_base.sys_user us1
+                                 ON cu.user_id = us1.user_id and us1.del_flag = 0) t1 ${ew.customSqlSegment}
     </select>
 
     <select id="getProfitBudgetPage" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
-        SELECT (select GROUP_CONCAT(id) from contract_product WHERE contract_id = t1.id) AS contractProductIds,
-               t1.id                                                                     AS contractId,
-               t1.`code`,
-               t1.buy_corporation_id,
-               us1.nick_name                                                                userName,
-               t1.amount,
-               t1.currency,
-               t1.currency_rate_json,
-               t1.rate                                                                   AS rate,
-               t2.*,
-               IFNULL(t1.budget_money, 0)                                                AS budgetMoney,
-               cu.name                                                                      customerName,
-               t1.is_settled
-        FROM contract t1
-                 LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id
-                 LEFT JOIN bytesailing_customer.customer cu on t1.buy_corporation_id = cu.id and cu.del_flag = 0
-                 LEFT JOIN bytesailing_base.sys_user us1 ON cu.user_id = us1.user_id and us1.del_flag = 0
+        SELECT t1.*,
+               if(t1.amount &lt; t1.sumPurchaseContractMoney, 1, 0) AS isLoss
+        FROM (SELECT (SELECT GROUP_CONCAT(id) FROM contract_product WHERE contract_id = t1.id) AS contractProductIds,
+                     t1.id                                                                     AS contractId,
+                     t1.`code`,
+                     t1.buy_corporation_id,
+                     us1.nick_name                                                                userName,
+                     t1.amount,
+                     t1.currency,
+                     t1.currency_rate_json,
+                     t1.rate                                                                   AS rate,
+                     t2.*,
+                     IFNULL(t1.budget_money, 0)                                                AS budgetMoney,
+                     cu.NAME                                                                      customerName,
+                     t1.is_settled,
+                     t1.is_change,
+                     t1.status,
+                     t1.is_show,
+                     (SELECT IFNULL(SUM(amount), 0)
+                      FROM ehsd_purchase
+                      WHERE data_resource_id = t1.id
+                        AND `status` IN (10, 30, 60))                                          AS sumPurchaseContractMoney
+              FROM contract t1
+                       LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id
+                       LEFT JOIN bytesailing_customer.customer cu ON t1.buy_corporation_id = cu.id
+                  AND cu.del_flag = 0
+                       LEFT JOIN bytesailing_base.sys_user us1 ON cu.user_id = us1.user_id
+                  AND us1.del_flag = 0) t1
             ${ew.customSqlSegment}
     </select>
 
     <select id="getProfitBudgetHeadStatistic" resultType="com.fjhx.sale.entity.contract.vo.ContractBudgetVo">
-        SELECT t1.id   AS contractId,
-               t1.amount,
-               t1.currency,
-               t1.currency_rate_json,
-               t1.rate AS rate,
-               t2.*
-        FROM contract t1
-                 LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id
-                 LEFT JOIN bytesailing_customer.customer cu on t1.buy_corporation_id = cu.id and cu.del_flag = 0
-                 LEFT JOIN bytesailing_base.sys_user us1 ON cu.user_id = us1.user_id and us1.del_flag = 0
+        SELECT t1.*,
+               if(t1.amount &lt; t1.sumPurchaseContractMoney, 1, 0) AS isLoss
+        FROM (SELECT t1.id                                                         AS contractId,
+                     t1.amount,
+                     t1.currency,
+                     t1.currency_rate_json,
+                     t1.rate                                                       AS rate,
+                     t2.*,
+                     t1.is_settled,
+                     t1.is_change,
+                     t1.status,
+                     t1.is_show,
+                     us1.nick_name,
+                     t1.code,
+                     (SELECT IFNULL(SUM(amount), 0)
+                      FROM ehsd_purchase
+                      WHERE data_resource_id = t1.id AND `status` IN (10, 30, 60)) AS sumPurchaseContractMoney
+              FROM contract t1
+                       LEFT JOIN contract_budget t2 ON t1.id = t2.contract_id
+                       LEFT JOIN bytesailing_customer.customer cu on t1.buy_corporation_id = cu.id and cu.del_flag = 0
+                       LEFT JOIN bytesailing_base.sys_user us1 ON cu.user_id = us1.user_id and us1.del_flag = 0) t1
             ${ew.customSqlSegment}
     </select>