From 7958f1dddb8a7f4e70d232b07a7703955ecedae0 Mon Sep 17 00:00:00 2001
From: Your Name <you@example.com>
Date: 星期六, 26 八月 2023 12:45:33 +0800
Subject: [PATCH] 优化diamante

---
 service-acct/src/main/java/com/java110/acct/bmo/account/impl/GetAccountBMOImpl.java |  130 +++++++++++++++++++++++++++++++++++++++---
 1 files changed, 119 insertions(+), 11 deletions(-)

diff --git a/service-acct/src/main/java/com/java110/acct/bmo/account/impl/GetAccountBMOImpl.java b/service-acct/src/main/java/com/java110/acct/bmo/account/impl/GetAccountBMOImpl.java
index 7533ec5..263fd4d 100644
--- a/service-acct/src/main/java/com/java110/acct/bmo/account/impl/GetAccountBMOImpl.java
+++ b/service-acct/src/main/java/com/java110/acct/bmo/account/impl/GetAccountBMOImpl.java
@@ -1,12 +1,18 @@
 package com.java110.acct.bmo.account.impl;
 
 import com.java110.acct.bmo.account.IGetAccountBMO;
+import com.java110.core.factory.CommunitySettingFactory;
+import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.dto.account.AccountDto;
-import com.java110.dto.accountDetail.AccountDetailDto;
+import com.java110.dto.account.AccountDetailDto;
 import com.java110.dto.owner.OwnerDto;
+import com.java110.dto.user.UserDto;
 import com.java110.intf.acct.IAccountDetailInnerServiceSMO;
 import com.java110.intf.acct.IAccountInnerServiceSMO;
 import com.java110.intf.user.IOwnerInnerServiceSMO;
+import com.java110.intf.user.IUserInnerServiceSMO;
+import com.java110.po.account.AccountPo;
+import com.java110.utils.lock.DistributedLock;
 import com.java110.utils.util.StringUtil;
 import com.java110.vo.ResultVo;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,6 +34,15 @@
 
     @Autowired
     private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
+
+    //閿�(绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒�)
+    public static final String MAXIMUM_NUMBER = "MAXIMUM_NUMBER";
+
+    //閿�(绉垎璐︽埛鎶垫墸姣斾緥)
+    public static final String DEDUCTION_PROPORTION = "DEDUCTION_PROPORTION";
+
+    @Autowired
+    private IUserInnerServiceSMO userInnerServiceSMOImpl;
 
     /**
      * @param accountDto
@@ -81,30 +96,123 @@
     public ResponseEntity<String> queryOwnerAccount(AccountDto accountDto, OwnerDto ownerDto) {
 
         List<OwnerDto> ownerDtos = null;
-        if (!StringUtil.isEmpty(ownerDto.getLink()) || !StringUtil.isEmpty(ownerDto.getIdCard())) {
+        List<AccountDto> accountDtos = null;
+        int count = 0;
+        if (!StringUtil.isEmpty(ownerDto.getIdCard())) {
             //鍏堟煡璇笟涓�
             ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
+            if (ownerDtos != null && ownerDtos.size() > 0) {
+                accountDto.setAcctName("");
+                accountDto.setObjId(ownerDtos.get(0).getMemberId());
+            }
         }
 
-        if (ownerDtos != null && ownerDtos.size() > 0) {
-            accountDto.setAcctName("");
-            accountDto.setObjId(ownerDtos.get(0).getMemberId());
-        }
-
-        int count = accountInnerServiceSMOImpl.queryAccountsCount(accountDto);
-
-        List<AccountDto> accountDtos = null;
+        count = accountInnerServiceSMOImpl.queryAccountsCount(accountDto);
         if (count > 0) {
             accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
         } else {
             accountDtos = new ArrayList<>();
         }
 
-        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) accountDto.getRow()), count, accountDtos);
+
+        if (accountDtos == null || accountDtos.size() < 1) {
+            //娣诲姞 璐︽埛
+            accountDtos = addAccountDto(accountDto, ownerDto);
+
+        }
+        //绉垎璐︽埛鏈�澶т娇鐢ㄧН鍒�
+        String maximumNumber = CommunitySettingFactory.getValue(ownerDto.getCommunityId(), MAXIMUM_NUMBER);
+        //绉垎璐︽埛鎶垫墸姣斾緥
+        String deductionProportion = CommunitySettingFactory.getValue(ownerDto.getCommunityId(), DEDUCTION_PROPORTION);
+        List<AccountDto> accountList = new ArrayList<>();
+        for (AccountDto account : accountDtos) {
+            if (!StringUtil.isEmpty(maximumNumber)) {
+                account.setMaximumNumber(maximumNumber);
+            }
+            if (!StringUtil.isEmpty(deductionProportion)) {
+                account.setDeductionProportion(deductionProportion);
+            }
+            accountList.add(account);
+        }
+
+        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) accountDto.getRow()), count, accountList);
 
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);
 
         return responseEntity;
     }
 
+
+    private List<AccountDto> addAccountDto(AccountDto accountDto, OwnerDto ownerDto) {
+        // todo  鏌ヨ璐︽埛鍚嶇О 杩欓噷濡傛灉瀛樺湪涓氫富鍒欎笟涓诲悕绉� 涓嶆槸涓氫富 鍒� 濉啓鐢ㄦ埛鍚嶇О锛屽鏋滅敤鎴烽兘娌℃湁 鍒欒繑鍥炵┖
+        String acctName = getAccountName(ownerDto);
+
+        if (StringUtil.isEmpty(acctName)) {
+            return new ArrayList<>();
+        }
+        //寮�濮嬮攣浠g爜
+        String requestId = DistributedLock.getLockUUID();
+        String key = this.getClass().getSimpleName() + "AddCountDto" + ownerDto.getOwnerId();
+        try {
+            DistributedLock.waitGetDistributedLock(key, requestId);
+
+            AccountPo accountPo = new AccountPo();
+            accountPo.setAmount("0");
+            accountPo.setAcctId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_acctId));
+            accountPo.setObjId(ownerDto.getOwnerId());
+            accountPo.setObjType(AccountDto.OBJ_TYPE_PERSON);
+            accountPo.setAcctType(AccountDto.ACCT_TYPE_CASH);
+            accountPo.setAcctName(acctName);
+            accountPo.setPartId(ownerDto.getCommunityId());
+            accountPo.setLink(ownerDto.getLink());
+            accountInnerServiceSMOImpl.saveAccount(accountPo);
+            List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
+            return accountDtos;
+        } finally {
+            DistributedLock.releaseDistributedLock(requestId, key);
+        }
+    }
+
+    private String getAccountName(OwnerDto ownerDto) {
+
+        // todo  owner
+        if (!StringUtil.isEmpty(ownerDto.getOwnerId())) {
+            OwnerDto tmpOwnerDto = new OwnerDto();
+            tmpOwnerDto.setMemberId(ownerDto.getOwnerId());
+            tmpOwnerDto.setCommunityId(ownerDto.getCommunityId());
+            List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(tmpOwnerDto);
+            if (ownerDtos == null || ownerDtos.size() < 1) {
+                return "";
+            }
+            ownerDto.setCommunityId(ownerDtos.get(0).getCommunityId());
+            ownerDto.setLink(ownerDtos.get(0).getLink());
+            return ownerDtos.get(0).getName();
+        }
+
+        // todo 蹇呴』鍖呭惈 鎵嬫満鍙峰拰灏忓尯
+        if (StringUtil.isEmpty(ownerDto.getLink()) || StringUtil.isEmpty(ownerDto.getCommunityId())) {
+            return "";
+        }
+
+        // todo 涓氫富鐢� 鎵嬫満鍙锋煡璇�
+        OwnerDto tmpOwnerDto = new OwnerDto();
+        tmpOwnerDto.setLink(ownerDto.getLink());
+        tmpOwnerDto.setCommunityId(ownerDto.getCommunityId());
+        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(tmpOwnerDto);
+        if (ownerDtos != null && ownerDtos.size() > 0) {
+            ownerDto.setOwnerId(ownerDtos.get(0).getMemberId());
+            return ownerDtos.get(0).getName();
+        }
+
+        //todo 闈炰笟涓绘槸娓稿
+        UserDto userDto = new UserDto();
+        userDto.setTel(ownerDto.getLink());
+        List<UserDto> userDtos = userInnerServiceSMOImpl.getUsers(userDto);
+        if (userDtos != null && userDtos.size() > 0) {
+            ownerDto.setOwnerId("-1");
+            return userDtos.get(0).getName();
+        }
+        return "";
+    }
+
 }

--
Gitblit v1.8.0