Browse Source

资金流水问题处理

yzc 1 year ago
parent
commit
14155e4d47

+ 25 - 25
hx-account/src/main/java/com/fjhx/account/service/account/impl/AccountRunningWaterServiceImpl.java

@@ -233,31 +233,31 @@ public class AccountRunningWaterServiceImpl extends ServiceImpl<AccountRunningWa
             dto.setRate(divide);
         }
 
-        // 修改账户余额表的余额
-        AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
-                .eq(AccountRemainder::getAccountManagementId, dto.getAccountManagementId())
-                .eq(AccountRemainder::getCurrency, dto.getCurrency())
-        );
-
-        if (ObjectUtil.isEmpty(accountRemainder)) {
-            throw new ServiceException("该账户不存在此币种,请前往资金账户添加");
-        }
-        BigDecimal amount = dto.getAmount();
-        String status = dto.getStatus();
-        BigDecimal remainder = accountRemainder.getRemainder();
-
-        accountRemainder.setStatus(status);
-        accountRemainder.setChangeRemainder(amount);
-
-        if (status.equals("10")) {
-            accountRemainder.setRemainder(remainder.add(amount));
-        } else if (status.equals("20")) {
-            if (remainder.compareTo(amount) < 0) {
-                throw new ServiceException("账户余额不足");
-            }
-            accountRemainder.setRemainder(remainder.subtract(amount));
-        }
-        accountRemainderService.updateById(accountRemainder);
+//        // 修改账户余额表的余额
+//        AccountRemainder accountRemainder = accountRemainderService.getOne(q -> q
+//                .eq(AccountRemainder::getAccountManagementId, dto.getAccountManagementId())
+//                .eq(AccountRemainder::getCurrency, dto.getCurrency())
+//        );
+//
+//        if (ObjectUtil.isEmpty(accountRemainder)) {
+//            throw new ServiceException("该账户不存在此币种,请前往资金账户添加");
+//        }
+//        BigDecimal amount = dto.getAmount();
+//        String status = dto.getStatus();
+//        BigDecimal remainder = accountRemainder.getRemainder();
+//
+//        accountRemainder.setStatus(status);
+//        accountRemainder.setChangeRemainder(amount);
+//
+//        if (status.equals("10")) {
+//            accountRemainder.setRemainder(remainder.add(amount));
+//        } else if (status.equals("20")) {
+//            if (remainder.compareTo(amount) < 0) {
+//                throw new ServiceException("账户余额不足");
+//            }
+//            accountRemainder.setRemainder(remainder.subtract(amount));
+//        }
+//        accountRemainderService.updateById(accountRemainder);
 
         this.save(dto);
 

+ 46 - 43
hx-account/src/main/resources/mapper/account/AccountRunningWaterMapper.xml

@@ -3,50 +3,53 @@
 <mapper namespace="com.fjhx.account.mapper.account.AccountRunningWaterMapper">
     <!--这段代码正常是不需要跨库查询的。但是一开始封装包的时候分装的不合理,pom里面包是不能互相引用的。account包继承sale包会出现依赖冲突,目前不好改动,只能跨库查询-->
     <select id="getPage" resultType="com.fjhx.account.entity.account.vo.AccountRunningWaterVo">
-        SELECT arw.*
-             , if(arw.type = 40, (select GROUP_CONCAT(c.`code`)
-                                  from tax_refund_details trd
-                                           left join contract c on c.id = trd.contract_id
-                                  where trd.account_running_water_id = arw.id),
-                  (SELECT IF
-                              (t1.type = 20, GROUP_CONCAT(c.`code`), GROUP_CONCAT(t4.`code`)) contractCodes
-                   FROM account_payment t1
-                            LEFT JOIN account_request_funds t2 ON t1.business_id = t2.id
-                            LEFT JOIN account_request_funds_detail t3 ON t2.id = t3.account_request_funds_id
-                            LEFT JOIN contract t4 ON t3.contract_id = t4.id
-                       --采购付款来源
-                            LEFT JOIN pay pa ON t1.business_id = pa.id
-                            LEFT JOIN pay_detail pad
-                      ON pad.pay_id = pa.id
-                      LEFT JOIN purchase p ON pad.purchase_id = p.id
-                      LEFT JOIN contract c ON p.data_resource_id = c.id
-                      WHERE
-                      t1.id = arw.business_id ) )AS contractCodes
-
-             , if(arw.type = 40, (select GROUP_CONCAT(trd.contract_id)
-                                  from tax_refund_details trd
-                                  where trd.account_running_water_id = arw.id), (SELECT IF
-                                                                                            (t1.type = 20,
-                                                                                             GROUP_CONCAT(c.id),
-                                                                                             GROUP_CONCAT(t4.id)) contractIds
-                                                                                 FROM account_payment t1
-                                                                                          LEFT JOIN account_request_funds t2
-                                                                                                    ON t1.business_id = t2.id
-                                                                                          LEFT JOIN account_request_funds_detail t3 ON t2.id = t3.account_request_funds_id
-                                                                                          LEFT JOIN contract t4
-                                                                                                    ON t3.contract_id = t4.id
-                                                                                     --采购付款来源
-                                                                                          LEFT JOIN pay pa ON t1.business_id = pa.id
-                                                                                          LEFT JOIN pay_detail pad ON pad.pay_id = pa.id
-                      LEFT JOIN purchase p ON pad.purchase_id = p.id
-                      LEFT JOIN contract c ON p.data_resource_id = c.id
-                      WHERE
-                      t1.id = arw.business_id )) AS contractIds
-             , am.alias                             accountManagementName
-             , am.corporation_id
+        SELECT arw.*,
+               am.alias accountManagementName,
+               am.corporation_id,
+               t2.contractIds,
+               t2.contractCodes
         FROM account_running_water arw
-                 LEFT JOIN account_management am
-                           ON arw.account_management_id = am.id
+                 LEFT JOIN account_management am ON arw.account_management_id = am.id
+                 LEFT JOIN (SELECT GROUP_CONCAT(t1.contractCode SEPARATOR ',') AS contractCodes,
+                                   GROUP_CONCAT(t1.contractId SEPARATOR ',')   AS contractIds,
+                                   t1.accountRunningWaterId
+                            FROM ((--#到账认领
+                                      SELECT c.`code`       AS contractCode,
+                                             c.id           AS contractId,
+                                             cl.business_id AS accountRunningWaterId
+                                      FROM claim cl
+                                               JOIN claim_contract clc ON clc.claim_id = cl.id
+                                               JOIN contract c ON clc.contract_id = c.id)
+                                  UNION ALL
+                                  (--#退税
+                                      SELECT c.`code`                     AS contractCode,
+                                             c.`id`                       AS contractId,
+                                             trd.account_running_water_id AS accountRunningWaterId
+                                      FROM tax_refund_details trd
+                                               LEFT JOIN contract c ON c.id = trd.contract_id)
+                                  UNION ALL
+                                  (--#采购付款
+                                      SELECT c.`code` AS contractCode,
+                                             c.id     AS contractId,
+                                             arw.id   AS accountRunningWaterId
+                                      FROM account_running_water arw
+                                               JOIN account_payment t1 ON arw.business_id = t1.id
+                                               JOIN pay pa ON t1.business_id = pa.id
+                                               JOIN pay_detail pad
+                                      ON pad.pay_id = pa.id
+                                          JOIN purchase p ON pad.purchase_id = p.id
+                                          JOIN contract c ON p.data_resource_id = c.id)
+                                  UNION ALL
+                                  (--#请款-打款
+                                      SELECT t4.`code` AS contractCode,
+                                             t4.id     AS contractId,
+                                             arw.id    AS accountRunningWaterId
+                                      FROM account_running_water arw
+                                               JOIN account_payment t1 ON arw.business_id = t1.id
+                                               JOIN account_request_funds t2 ON t1.business_id = t2.id
+                                               JOIN account_request_funds_detail t3 ON t2.id = t3.account_request_funds_id
+                                               JOIN contract t4 ON t3.contract_id = t4.id)) t1
+                            GROUP BY t1.accountRunningWaterId) t2 ON t2.accountRunningWaterId = arw.id
             ${ew.customSqlSegment}
     </select>
     <select id="getDetail" resultType="com.fjhx.account.entity.account.vo.AccountRunningWaterVo">