Przeglądaj źródła

销售合同 分页优化

yzc 1 rok temu
rodzic
commit
70545d0f24

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

@@ -388,9 +388,9 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             Map<String, String> contractTypeStatusDic = dictTenantDataVoList.stream().collect(Collectors.toMap(DictTenantDataVo::getDictKey, DictTenantDataVo::getDictValue));
             DynamicDataSourceContextHolder.poll();
 
-            List<Long> customerIds = list.stream().map(Contract::getBuyCorporationId).collect(Collectors.toList());
-            List<Customer> customerList = customerService.list(Wrappers.<Customer>query().lambda().in(Customer::getId, customerIds));
-            Map<Long, List<Customer>> cusMap = customerList.stream().distinct().collect(Collectors.groupingBy(Customer::getId));
+//            List<Long> customerIds = list.stream().map(Contract::getBuyCorporationId).collect(Collectors.toList());
+//            List<Customer> customerList = customerService.list(Wrappers.<Customer>query().lambda().in(Customer::getId, customerIds));
+//            Map<Long, List<Customer>> cusMap = customerList.stream().distinct().collect(Collectors.groupingBy(Customer::getId));
 
             List<Long> ids = list.stream().map(ContractVo::getId).collect(Collectors.toList());
             // 获取交接单附件
@@ -399,16 +399,16 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
             // 获取包装附件
             Map<Long, List<FileInfoVo>> packageFileMap = ObsFileUtil.getFileMap(ids, 2);
             for (ContractVo p : list) {
-
-                // 客户
-                if (MapUtils.isNotEmpty(cusMap)) {
-                    List<Customer> customers = cusMap.getOrDefault(p.getBuyCorporationId(), null);
-                    p.setBuyCorporationName(customers == null ? null : customers.get(0).getName());
-                    // 赋值客户标签
-                    p.setTag(customers == null ? null : customers.get(0).getTag());
-                    //赋值业务员
-                    p.setUserName(p.getSalesmanName());
-                }
+//
+//                // 客户
+//                if (MapUtils.isNotEmpty(cusMap)) {
+//                    List<Customer> customers = cusMap.getOrDefault(p.getBuyCorporationId(), null);
+//                    p.setBuyCorporationName(customers == null ? null : customers.get(0).getName());
+//                    // 赋值客户标签
+//                    p.setTag(customers == null ? null : customers.get(0).getTag());
+//                    //赋值业务员
+//                    p.setUserName(p.getSalesmanName());
+//                }
 
                 // 赋值交接单附件
                 if (MapUtils.isNotEmpty(fileMap)) {

+ 33 - 29
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -2,42 +2,46 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.fjhx.sale.mapper.contract.ContractMapper">
     <select id="getPage" resultType="com.fjhx.sale.entity.contract.vo.ContractVo">
-        SELECT *
+        SELECT null as data_json, t1.*
         FROM (SELECT t1.*,
+                     c.name                                       customerName,
+                     us.nick_name                                 salesmanName,
+                     us.nick_name                              as userName,
+                     us.user_id                                   salesmanId,
+                     IFNULL(cl.sumClaimMoney, 0)               AS sumClaimMoney,
+                     IF(pa.contractId is null, 0, 1)           AS notPack,
                      IFNULL(t1.amount, 0) * IFNULL(t1.rate, 0) AS amountCNY,
+                     c.name                                    as buyCorporationName,
+                     c.tag                                     as tag,
                      CASE
-                         WHEN (IFNULL(t1.amount, 0) * IFNULL(t1.rate, 0) - t1.sumClaimMoney) &lt;= 0 THEN
+                         WHEN (IFNULL(t1.amount, 0) * IFNULL(t1.rate, 0) - IFNULL(cl.sumClaimMoney, 0)) &lt;= 0 THEN
                              20
-                         WHEN t1.sumClaimMoney = 0 THEN
+                         WHEN IFNULL(cl.sumClaimMoney, 0) = 0 THEN
                              0
                          ELSE 10
                          END                                   AS refundStatusNew
-              FROM (SELECT t1.*,
-                           c.name                            customerName,
-                           us.nick_name                      salesmanName,
-                           us.user_id                        salesmanId,
-                           (SELECT IFNULL(SUM(IFNULL(cc.money_cny, IFNULL(cc.money, 0) * IFNULL(arw.rate, 1))), 0)
-                            FROM claim_contract cc
-                                     left join claim c on cc.claim_id = c.id
-                                     LEFT JOIN bytesailing_account.account_running_water arw on c.business_id = arw.id
-                            WHERE cc.contract_id = t1.id) AS sumClaimMoney,
-                           pa.notPack
-                    FROM contract t1
-                             left join bytesailing_customer.customer c on t1.buy_corporation_id = c.id
-                             left join bytesailing_base.sys_user us on c.user_id = us.user_id
-                             left join (SELECT pack.*,
-                                               (sumPackQuantity &lt; cpQuantity) notPack
-                                        FROM (SELECT t1.id                                   AS contractId,
-                                                     t2.quantity                             AS cpQuantity,
-                                                     (SELECT IFNULL(SUM(pd.pack_quantity * pdd.quantity), 0)
-                                                      FROM pack_detail_product pdd
-                                                               LEFT JOIN pack_detail pd ON pdd.pack_detail_id = pd.id
-                                                      WHERE pdd.contract_product_id = t2.id) AS sumPackQuantity
-                                              FROM contract t1
-                                                       LEFT JOIN contract_product t2 ON t1.id = t2.contract_id
-                                              WHERE t1.`status` = 30
-                                              GROUP BY t1.id) pack) pa on pa.contractId = t1.id) t1
-              GROUP BY t1.id) t1
+              FROM contract t1
+                       left join bytesailing_customer.customer c on t1.buy_corporation_id = c.id
+                       left join bytesailing_base.sys_user us on c.user_id = us.user_id
+                       left join (SELECT t2.id,
+                                         t1.id                                           AS contractId,
+                                         t2.quantity                                     AS cpQuantity,
+                                         IFNULL(SUM(pd.pack_quantity * pdd.quantity), 0) AS sumPackQuantity
+                                  FROM contract t1
+                                           JOIN contract_product t2 ON t2.contract_id = t1.id
+                                           LEFT JOIN pack_detail_product pdd ON pdd.contract_product_id = t2.id
+                                           LEFT JOIN pack_detail pd ON pdd.pack_detail_id = pd.id
+                                  WHERE t1.`status` = 30
+                                  GROUP BY t2.id
+                                  HAVING sumPackQuantity &lt; cpQuantity) pa on pa.contractId = t1.id
+                       LEFT JOIN (SELECT cc.contract_id,
+                                         IFNULL(sum(IFNULL(cc.money_cny, IFNULL(cc.money, 0) * IFNULL(arw.rate, 1))),
+                                                0) AS sumClaimMoney
+                                  FROM claim_contract cc
+                                           LEFT JOIN claim c ON cc.claim_id = c.id
+                                           LEFT JOIN bytesailing_account.account_running_water arw ON c.business_id = arw.id
+                                  GROUP BY cc.contract_id) cl ON cl.contract_id = t1.id
+              group by t1.id) t1
             ${ew.customSqlSegment}
     </select>