浏览代码

合同头部统计

caozj 1 年之前
父节点
当前提交
0a0a754467

+ 2 - 2
hx-sale/src/main/java/com/fjhx/sale/controller/contract/ContractController.java

@@ -259,8 +259,8 @@ public class ContractController {
      * 头部统计客户金额
      */
     @GetMapping("/getHeadCustomerStatistics")
-    public Map<String,Object> getHeadCustomerStatistics() {
-        return contractService.getHeadCustomerStatistics();
+    public Map<String,Object> getHeadCustomerStatistics(@RequestBody ContractSelectDto dto) {
+        return contractService.getHeadCustomerStatistics(dto);
     }
 
     /**

+ 2 - 1
hx-sale/src/main/java/com/fjhx/sale/mapper/contract/ContractMapper.java

@@ -102,5 +102,6 @@ public interface ContractMapper extends BaseMapper<Contract> {
     List<AccountRunningWaterVo> getAccountRunningWaterByContractId(@Param("contractId") Long contractId);
 
     void updateContract(Contract contract);
-    List<ContractVo> getCustomerMoney(@Param("authIds")List<Long> authIds);
+
+    List<ContractVo> getCustomerMoney( @Param("ew") IWrapper<Contract> wrapper);
 }

+ 1 - 1
hx-sale/src/main/java/com/fjhx/sale/service/contract/ContractService.java

@@ -192,7 +192,7 @@ public interface ContractService extends BaseService<Contract> {
      * 统计头部客户金额
      * @return
      */
-    Map<String,Object> getHeadCustomerStatistics();
+    Map<String,Object> getHeadCustomerStatistics(ContractSelectDto dto);
 
     void updateContract(Contract contract);
 }

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

@@ -1671,19 +1671,42 @@ public class ContractServiceImpl extends ServiceImpl<ContractMapper, Contract>
      * @return
      */
     @Override
-    public Map<String, Object> getHeadCustomerStatistics() {
+    public Map<String, Object> getHeadCustomerStatistics(ContractSelectDto dto) {
         Map<String,Object> map = new HashMap<>();
         map.put("sumAmount",BigDecimal.ZERO);
         map.put("sumArrivalAmount",BigDecimal.ZERO);
         map.put("sumQuantity",BigDecimal.ZERO);
         map.put("list",new ArrayList<>());
+
         List<Long> authIdList = customerService.getAuthIdList();
-        List<ContractVo> list;
-        if(CollectionUtils.isNotEmpty(authIdList)){
-            list = baseMapper.getCustomerMoney(authIdList);
-        }else{
-            list = baseMapper.getCustomerMoney(null);
+        if (authIdList.size() == 0) {
+            return new HashMap<>();
+        }
+        IWrapper<Contract> wrapper = getWrapper();
+        wrapper.in("t1", Contract::getBuyCorporationId, authIdList);
+        wrapper.eq("t1", Contract::getIsChange, "0");//列表只展示未变更得数据
+        wrapper.ne("t1",Contract::getIsShow,1);
+        wrapper.between("t1", Contract::getStatus, FlowStatusEnum1.DRAFT.getKey(), FlowStatusEnum1.CANCELLATION.getKey() - 1);
+        if (StringUtils.isNotEmpty(dto.getStatus())) {
+            wrapper.eq("t1", Contract::getStatus, dto.getStatus());
+        }
+        if (StringUtils.isNotEmpty(dto.getSellCorporationId())) {
+            wrapper.eq("t1", Contract::getSellCorporationId, dto.getSellCorporationId());
+        }
+        if (StringUtils.isNotEmpty(dto.getRefundStatusNew())) {
+            wrapper.in("t1.refundStatusNew", Arrays.asList(dto.getRefundStatusNew().split(",")));
+        }
+        if (StringUtils.isNotEmpty(dto.getKeyword())) {
+            wrapper.keyword(dto.getKeyword(), new SqlField("t1", Contract::getCode));
         }
+        //根据客户id关联
+        wrapper.eq(ContractVo::getBuyCorporationId, dto.getCustomerId());
+        //过滤合同类型
+        wrapper.eq("t1.contract_type", dto.getContractType());
+        wrapper.groupBy("t1.sell_corporation_id");
+        List<ContractVo> list;
+        list = baseMapper.getCustomerMoney(wrapper);
+
         if(CollectionUtils.isNotEmpty(list)){
             BigDecimal sumAmount = list.stream().map(ContractVo::getSumAmount).reduce(BigDecimal.ZERO,BigDecimal::add);
             BigDecimal sumQuantity = list.stream().map(ContractVo::getSumQuantity).reduce(BigDecimal.ZERO,BigDecimal::add);

+ 37 - 19
hx-sale/src/main/resources/mapper/contract/ContractMapper.xml

@@ -244,28 +244,46 @@
         SELECT
             t1.sell_corporation_id AS sellCorporationId,
             IFNULL( SUM( t1.amount * t1.rate ), 0 ) AS sumAmount,
-            IFNULL( count(1) ,0 ) AS sumQuantity,
+            IFNULL( count( 1 ), 0 ) AS sumQuantity,
             (
-                SELECT
-                    IFNULL( SUM( IFNULL( cc.money, 0 ) * IFNULL( cc.rate, 1 )), 0 )
-                FROM
-                    claim_contract cc
-                WHERE
-                    FIND_IN_SET( cc.contract_id, GROUP_CONCAT( t1.id ) )
+            SELECT
+            IFNULL( SUM( IFNULL( cc.money, 0 ) * IFNULL( cc.rate, 1 )), 0 )
+            FROM
+            claim_contract cc
+            WHERE
+            FIND_IN_SET( cc.contract_id, GROUP_CONCAT( t1.id ) )
             ) AS sumClaimMoney
         FROM
-            contract t1
-        WHERE
-            t1.is_show != 1
-            AND t1.is_change = 0
-            AND t1.`status` >= 30
-            AND t1.`status` &lt; 88
-            <if test="authIds neq null and authIds.size() > 0">
-                <foreach collection="authIds" item="authId" open="AND t1.buy_corporation_id IN (" separator="," close=")">
-                    #{authId}
-                </foreach>
-            </if>
-        GROUP BY sell_corporation_id
+                (
+                SELECT
+                    t1.*,
+                    IFNULL( t1.amount, 0 ) * IFNULL( t1.rate, 0 ) AS amountCNY,
+                    CASE
+
+                    WHEN ( IFNULL( t1.amount, 0 ) * IFNULL( t1.rate, 0 ) - t1.sumClaimMoney ) &lt;= 0 THEN
+                    20
+                    WHEN t1.sumClaimMoney = 0 THEN
+                    0 ELSE 10
+                    END AS refundStatusNew
+                FROM
+                        (
+                        SELECT
+                        t1.*,
+                        (
+                        SELECT
+                        IFNULL( SUM( 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
+                FROM
+                    contract t1
+                    ) t1
+                ) t1
+        ${ew.customSqlSegment}
     </select>
     <update id="updateContract" parameterType="com.fjhx.sale.entity.contract.po.Contract">
         update contract

+ 4 - 2
hx-sale/src/main/resources/mapper/contract/ContractProductMapper.xml

@@ -52,10 +52,12 @@
             ${ew.customSqlSegment}
             ) t1
         <where>
-            <if test="isArrival neq null" >
+            <if test="isArrival neq null and isArrival==1 ">
                 t1.ad &lt; t1.advanceRatio
             </if>
-
+            <if test="isArrival neq null and isArrival==2 ">
+                t1.ad > t1.advanceRatio
+            </if>
         </where>
     </select>