From 7935724516cb699835da888d59cd5b7bec5c6049 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 12 九月 2024 12:07:29 +0800
Subject: [PATCH] 完成业主功能的优化

---
 service-user/src/main/java/com/java110/user/cmd/owner/EditOwnerCmd.java |  287 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 147 insertions(+), 140 deletions(-)

diff --git a/service-user/src/main/java/com/java110/user/cmd/owner/EditOwnerCmd.java b/service-user/src/main/java/com/java110/user/cmd/owner/EditOwnerCmd.java
index 312b737..d9e8642 100644
--- a/service-user/src/main/java/com/java110/user/cmd/owner/EditOwnerCmd.java
+++ b/service-user/src/main/java/com/java110/user/cmd/owner/EditOwnerCmd.java
@@ -5,40 +5,82 @@
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
 import com.java110.core.context.ICmdDataFlowContext;
-import com.java110.core.event.cmd.AbstractServiceCmdListener;
+import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.factory.GenerateCodeFactory;
+import com.java110.doc.annotation.*;
+import com.java110.dto.account.AccountDto;
 import com.java110.dto.file.FileDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.owner.OwnerAppUserDto;
 import com.java110.dto.owner.OwnerDto;
+import com.java110.intf.acct.IAccountInnerServiceSMO;
 import com.java110.intf.common.IFileInnerServiceSMO;
 import com.java110.intf.common.IFileRelInnerServiceSMO;
-import com.java110.intf.community.IOwnerV1InnerServiceSMO;
-import com.java110.intf.user.IOwnerAppUserInnerServiceSMO;
-import com.java110.intf.user.IOwnerAppUserV1InnerServiceSMO;
-import com.java110.intf.user.IOwnerAttrInnerServiceSMO;
-import com.java110.intf.user.IOwnerInnerServiceSMO;
+import com.java110.intf.user.*;
+import com.java110.po.account.AccountPo;
 import com.java110.po.file.FileRelPo;
 import com.java110.po.owner.OwnerAppUserPo;
 import com.java110.po.owner.OwnerAttrPo;
 import com.java110.po.owner.OwnerPo;
+import com.java110.po.user.UserPo;
 import com.java110.utils.cache.MappingCache;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.ListUtil;
 import com.java110.utils.util.StringUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.util.List;
 
+@Java110CmdDoc(title = "淇敼涓氫富",
+        description = "绗笁鏂圭郴缁燂紝姣斿鎷涘晢绯荤粺鍚屾涓氫富淇℃伅",
+        httpMethod = "post",
+        url = "http://{ip}:{port}/app/owner.editOwner",
+        resource = "userDoc",
+        author = "鍚村鏂�",
+        serviceCode = "owner.editOwner",
+        seq = 10)
+
+@Java110ParamsDoc(params = {
+        @Java110ParamDoc(name = "communityId", length = 30, remark = "灏忓尯ID"),
+        @Java110ParamDoc(name = "name", length = 64, remark = "涓氫富鍚嶇О"),
+        @Java110ParamDoc(name = "link", length = 11, remark = "涓氫富鎵嬫満鍙�"),
+        @Java110ParamDoc(name = "idCard", length = 30, remark = "涓氫富韬唤璇佸彿"),
+        @Java110ParamDoc(name = "address", length = 512, remark = "鍦板潃"),
+        @Java110ParamDoc(name = "sex", length = 12, remark = "鎬у埆 鐢� 1 濂� 0"),
+        @Java110ParamDoc(name = "ownerTypeCd", length = 12, remark = "涓氫富绫诲瀷 1001 涓氫富 2002 瀹跺涵鎴愬憳 瀹跺涵鎴愬憳 闇�瑕佷紶涓氫富鐨刼wnerId"),
+        @Java110ParamDoc(name = "remark", length = 512, remark = "澶囨敞"),
+        @Java110ParamDoc(name = "memberId", length = 30, remark = "涓氫富ID"),
+        @Java110ParamDoc(name = "ownerPhoto", length = -1, remark = "涓氫富浜鸿劯 鐢ㄤ簬鍚屾闂ㄧ 浜鸿劯寮�闂�"),
+})
+
+@Java110ResponseDoc(
+        params = {
+                @Java110ParamDoc(name = "code", type = "int", length = 11, defaultValue = "0", remark = "杩斿洖缂栧彿锛�0 鎴愬姛 鍏朵粬澶辫触"),
+                @Java110ParamDoc(name = "msg", type = "String", length = 250, defaultValue = "鎴愬姛", remark = "鎻忚堪"),
+        })
+
+@Java110ExampleDoc(
+        reqBody = "{\n" +
+                "\t\"name\": \"鐜嬬帇\",\n" +
+                "\t\"age\": \"\",\n" +
+                "\t\"link\": \"18909718888\",\n" +
+                "\t\"address\": \"寮犱笁\",\n" +
+                "\t\"sex\": \"0\",\n" +
+                "\t\"ownerTypeCd\": \"1001\",\n" +
+                "\t\"remark\": \"\",\n" +
+                "\t\"memberId\": 123123123,\n" +
+                "\t\"ownerPhoto\": \"\",\n" +
+                "\t\"idCard\": \"\",\n" +
+                "\t\"communityId\": \"2022121921870161\"\n" +
+                "}",
+        resBody = "{\"code\":0,\"msg\":\"鎴愬姛\"}"
+)
 @Java110Cmd(serviceCode = "owner.editOwner")
-public class EditOwnerCmd extends AbstractServiceCmdListener {
-
-
-    @Autowired
-    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
+public class EditOwnerCmd extends Cmd {
 
     @Autowired
     private IOwnerInnerServiceSMO ownerInnerServiceSMOImpl;
@@ -51,81 +93,72 @@
 
     @Autowired
     private IOwnerAppUserInnerServiceSMO ownerAppUserInnerServiceSMOImpl;
+
     @Autowired
     private IOwnerAppUserV1InnerServiceSMO ownerAppUserV1InnerServiceSMOImpl;
 
     @Autowired
     private IFileRelInnerServiceSMO fileRelInnerServiceSMOImpl;
 
+    @Autowired
+    private IFileInnerServiceSMO fileInnerServiceSMOImpl;
+
+    @Autowired
+    private IAccountInnerServiceSMO accountInnerServiceSMOImpl;
+
+    @Autowired
+    private IUserV1InnerServiceSMO userV1InnerServiceSMOImpl;
 
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
         Assert.jsonObjectHaveKey(reqJson, "memberId", "璇锋眰鎶ユ枃涓湭鍖呭惈ownerId");
         Assert.jsonObjectHaveKey(reqJson, "name", "璇锋眰鎶ユ枃涓湭鍖呭惈name");
-        Assert.jsonObjectHaveKey(reqJson, "age", "璇锋眰鎶ユ枃涓湭鍖呭惈age");
         Assert.jsonObjectHaveKey(reqJson, "link", "璇锋眰鎶ユ枃涓湭鍖呭惈link");
-        Assert.jsonObjectHaveKey(reqJson, "sex", "璇锋眰鎶ユ枃涓湭鍖呭惈sex");
-        Assert.jsonObjectHaveKey(reqJson, "ownerTypeCd", "璇锋眰鎶ユ枃涓湭鍖呭惈ownerTypeCd");
         Assert.jsonObjectHaveKey(reqJson, "communityId", "璇锋眰鎶ユ枃涓湭鍖呭惈communityId");
-        // Assert.jsonObjectHaveKey(paramIn, "idCard", "璇锋眰鎶ユ枃涓湭鍖呭惈韬唤璇佸彿");
         Assert.judgeAttrValue(reqJson);
-
         //鑾峰彇鎵嬫満鍙�(鍒ゆ柇鎵嬫満鍙锋槸鍚﹂噸澶�)
         String link = reqJson.getString("link");
         if (!StringUtil.isEmpty(link) && link.contains("*")) {
-            OwnerDto ownerDto = new OwnerDto();
-            ownerDto.setOwnerId(reqJson.getString("ownerId"));
-            //涓氫富
-            ownerDto.setOwnerTypeCd("1001");
-            List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwners(ownerDto);
-            Assert.listOnlyOne(ownerDtos, "鏌ヨ涓氫富淇℃伅閿欒锛�");
-            link = ownerDtos.get(0).getLink();
-            reqJson.put("link", link);
+            reqJson.put("link", "");
         }
         //鑾峰彇韬唤璇佸彿(鍒ゆ柇韬唤璇佸彿鏄惁閲嶅)
         String idCard = reqJson.getString("idCard");
         if (!StringUtil.isEmpty(idCard) && idCard.contains("*")) {
-            OwnerDto owner = new OwnerDto();
-            owner.setOwnerId(reqJson.getString("ownerId"));
-            //涓氫富
-            owner.setOwnerTypeCd("1001");
-            List<OwnerDto> owners = ownerInnerServiceSMOImpl.queryOwners(owner);
-            Assert.listOnlyOne(owners, "鏌ヨ涓氫富淇℃伅閿欒锛�");
-            idCard = owners.get(0).getIdCard();
-            reqJson.put("idCard", idCard);
+            reqJson.put("idCard", "");
         }
+
+        if (reqJson.containsKey("ownerPhotoUrl")) {
+            String ownerPhotoUrl = reqJson.getString("ownerPhotoUrl");
+            if (!StringUtil.isEmpty(ownerPhotoUrl) && ownerPhotoUrl.length() > 500) {
+                throw new CmdException("鍥剧墖鍦板潃澶暱");
+            }
+            if (!StringUtil.isEmpty(ownerPhotoUrl)) {
+                reqJson.put("faceUrl", ownerPhotoUrl);
+            }
+        }
+
 
         String userValidate = MappingCache.getValue("USER_VALIDATE");
-
-        if(!"ON".equals(userValidate)){
-            return ;
+        if (!"ON".equals(userValidate)) {
+            return;
         }
 
+        OwnerDto curOwner = new OwnerDto();
+        curOwner.setMemberId(reqJson.getString("memberId"));
+
+        List<OwnerDto> curOwners = ownerInnerServiceSMOImpl.queryOwners(curOwner);
+        Assert.listOnlyOne(curOwners, "鏈煡璇㈠埌涓氫富淇℃伅鎴栨煡璇㈠埌澶氭潯");
+
         OwnerDto ownerDto = new OwnerDto();
-        ownerDto.setLink(link);
+        ownerDto.setLink(curOwners.get(0).getLink());
         ownerDto.setCommunityId(reqJson.getString("communityId"));
         List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryAllOwners(ownerDto);
         if (ownerDtos != null && ownerDtos.size() > 1) {
             throw new IllegalArgumentException("鎵嬫満鍙烽噸澶嶏紝璇烽噸鏂拌緭鍏�");
         } else if (ownerDtos != null && ownerDtos.size() == 1) {
             for (OwnerDto owner : ownerDtos) {
-                if ((!StringUtil.isEmpty(reqJson.getString("ownerId")) && !owner.getOwnerId().equals(reqJson.getString("ownerId"))) || (!StringUtil.isEmpty(reqJson.getString("memberId")) && !owner.getMemberId().equals(reqJson.getString("memberId")))) {
+                if (!reqJson.getString("memberId").equals(owner.getMemberId())) {
                     throw new IllegalArgumentException("鎵嬫満鍙烽噸澶嶏紝璇烽噸鏂拌緭鍏�");
-                }
-            }
-        }
-        if (!StringUtil.isEmpty(idCard)) {
-            OwnerDto owner = new OwnerDto();
-            owner.setIdCard(idCard);
-            owner.setCommunityId(reqJson.getString("communityId"));
-            List<OwnerDto> owners = ownerInnerServiceSMOImpl.queryAllOwners(owner);
-            if (owners != null && owners.size() > 1) {
-                throw new IllegalArgumentException("韬唤璇佸彿閲嶅锛岃閲嶆柊杈撳叆");
-            } else if (owners != null && owners.size() == 1) {
-                for (OwnerDto ownerDto1 : owners) {
-                    if ((!StringUtil.isEmpty(reqJson.getString("ownerId")) && !ownerDto1.getOwnerId().equals(reqJson.getString("ownerId"))) || (!StringUtil.isEmpty(reqJson.getString("memberId")) && !ownerDto1.getMemberId().equals(reqJson.getString("memberId")))) {
-                        throw new IllegalArgumentException("韬唤璇佸彿閲嶅锛岃閲嶆柊杈撳叆");
-                    }
                 }
             }
         }
@@ -134,38 +167,28 @@
     @Override
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
-        if (!reqJson.containsKey("ownerId") || OwnerDto.OWNER_TYPE_CD_OWNER.equals(reqJson.getString("ownerTypeCd"))) {
-            reqJson.put("ownerId", reqJson.getString("memberId"));
+
+
+        //todo 淇敼 涓氫富淇℃伅
+        OwnerPo ownerPo = BeanConvertUtil.covertBean(reqJson, OwnerPo.class);
+        int flag = ownerV1InnerServiceSMOImpl.updateOwner(ownerPo);
+        if (flag < 1) {
+            throw new CmdException("淇敼涓氫富澶辫触");
         }
 
-        //杩欓噷娉ㄩ噴 鍥犱负 鏈夊浗澶栫殑鎵嬫満鍙� 涓嶆槸11浣�
-//        if (link.length() != 11) {
-//            throw new IllegalArgumentException("鎵嬫満鍙疯緭鍏ヤ笉姝g‘锛�");
-//        }
-        if (reqJson.containsKey("ownerPhoto") && !StringUtils.isEmpty(reqJson.getString("ownerPhoto"))) {
-            FileDto fileDto = new FileDto();
-            fileDto.setFileId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_file_id));
-            fileDto.setFileName(fileDto.getFileId());
-            fileDto.setContext(reqJson.getString("ownerPhoto"));
-            fileDto.setSuffix("jpeg");
-            fileDto.setCommunityId(reqJson.getString("communityId"));
-            String fileName = fileInnerServiceSMOImpl.saveFile(fileDto);
-            reqJson.put("ownerPhotoId", fileDto.getFileId());
-            reqJson.put("fileSaveName", fileName);
-            editOwnerPhoto(reqJson);
-        }
-        editOwner(reqJson);
+        //todo 淇敼璐︽埛
+        updateAccount(reqJson);
+
         JSONArray attrs = reqJson.getJSONArray("attrs");
-        if (attrs.size() < 1) {
+        if (ListUtil.isNull(attrs)) {
             return;
         }
         JSONObject attr = null;
-        int flag = 0;
         for (int attrIndex = 0; attrIndex < attrs.size(); attrIndex++) {
             attr = attrs.getJSONObject(attrIndex);
             attr.put("memberId", reqJson.getString("memberId"));
             attr.put("communityId", reqJson.getString("communityId"));
-            if (!attr.containsKey("attrId") || attr.getString("attrId").startsWith("-") || StringUtil.isEmpty(attr.getString("attrId"))) {
+            if (!attr.containsKey("attrId") || StringUtil.isEmpty(attr.getString("attrId")) || attr.getString("attrId").startsWith("-")) {
                 attr.put("attrId", GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_attrId));
                 OwnerAttrPo ownerAttrPo = BeanConvertUtil.covertBean(attr, OwnerAttrPo.class);
                 flag = ownerAttrInnerServiceSMOImpl.saveOwnerAttr(ownerAttrPo);
@@ -180,78 +203,62 @@
                 throw new CmdException("淇敼涓氫富灞炴�уけ璐�");
             }
         }
+        //todo 濡傛灉 涓氫富鍋氫簡缁戝畾鍒欎慨鏀圭粦瀹氱殑鎵嬫満鍙�
+        updateOwnerAppUser(reqJson);
     }
 
-    public void editOwner(JSONObject paramInJson) {
+    public void updateAccount(JSONObject paramInJson) {
 
-        OwnerDto ownerDto = new OwnerDto();
-        ownerDto.setMemberId(paramInJson.getString("memberId"));
-        List<OwnerDto> ownerDtos = ownerInnerServiceSMOImpl.queryOwnerMembers(ownerDto);
-
-        Assert.listOnlyOne(ownerDtos, "鏈煡璇㈠埌涓氫富淇℃伅鎴栨煡璇㈠埌澶氭潯");
-
-        JSONObject businessOwner = new JSONObject();
-        businessOwner.putAll(BeanConvertUtil.beanCovertMap(ownerDtos.get(0)));
-        businessOwner.putAll(paramInJson);
-
-        if (paramInJson.containsKey("wxPhoto")) {
-            businessOwner.put("link", paramInJson.getString("wxPhoto"));
-        }
-        businessOwner.put("state", ownerDtos.get(0).getState());
-        OwnerPo ownerPo = BeanConvertUtil.covertBean(businessOwner, OwnerPo.class);
-        int flag = ownerV1InnerServiceSMOImpl.updateOwner(ownerPo);
-        if (flag < 1) {
-            throw new CmdException("淇敼涓氫富澶辫触");
-        }
-        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
-        ownerAppUserDto.setMemberId(paramInJson.getString("ownerId"));
-
-        //鏌ヨapp鐢ㄦ埛琛�
-        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
-        if (ownerAppUserDtos != null && ownerAppUserDtos.size() > 0) {
-            for (OwnerAppUserDto ownerAppUser : ownerAppUserDtos) {
-                OwnerAppUserPo ownerAppUserPo = BeanConvertUtil.covertBean(ownerAppUser, OwnerAppUserPo.class);
-                ownerAppUserPo.setLink(paramInJson.getString("link"));
-                ownerAppUserPo.setIdCard(paramInJson.getString("idCard"));
-                flag = ownerAppUserV1InnerServiceSMOImpl.updateOwnerAppUser(ownerAppUserPo);
-                if (flag < 1) {
-                    throw new CmdException("淇敼涓氫富澶辫触");
-                }
-            }
-        }
-    }
-
-    public void editOwnerPhoto(JSONObject paramInJson) {
-
-        FileRelDto fileRelDto = new FileRelDto();
-        fileRelDto.setRelTypeCd("10000");
-        fileRelDto.setObjId(paramInJson.getString("memberId"));
-        int flag = 0;
-        List<FileRelDto> fileRelDtos = fileRelInnerServiceSMOImpl.queryFileRels(fileRelDto);
-        if (fileRelDtos == null || fileRelDtos.size() == 0) {
-            JSONObject businessUnit = new JSONObject();
-            businessUnit.put("fileRelId", "-1");
-            businessUnit.put("relTypeCd", "10000");
-            businessUnit.put("saveWay", "table");
-            businessUnit.put("objId", paramInJson.getString("memberId"));
-            businessUnit.put("fileRealName", paramInJson.getString("ownerPhotoId"));
-            businessUnit.put("fileSaveName", paramInJson.getString("ownerPhotoId"));
-            FileRelPo fileRelPo = BeanConvertUtil.covertBean(businessUnit, FileRelPo.class);
-            flag = fileRelInnerServiceSMOImpl.saveFileRel(fileRelPo);
-            if (flag < 1) {
-                throw new CmdException("淇濆瓨鏂囦欢澶辫触");
-            }
+        //todo 鍒ゆ柇涓氫富鎵嬫満鍙峰拰璐︽埛鎵嬫満鍙锋槸鍚︾浉鍚岋紝涓嶇浉鍚屼慨鏀硅处鎴锋墜鏈哄彿
+        AccountDto accountDto = new AccountDto();
+        accountDto.setObjId(paramInJson.getString("memberId"));
+        accountDto.setPartId(paramInJson.getString("communityId"));
+        List<AccountDto> accountDtos = accountInnerServiceSMOImpl.queryAccounts(accountDto);
+        if (ListUtil.isNull(accountDtos)) {
             return;
         }
+        //鏌ヨ鏇存柊鍚庣殑涓氫富淇℃伅
+        OwnerDto owner = new OwnerDto();
+        owner.setMemberId(paramInJson.getString("memberId"));
+        List<OwnerDto> owners = ownerInnerServiceSMOImpl.queryOwnerMembers(owner);
+        Assert.listOnlyOne(owners, "鏈煡璇㈠埌涓氫富淇℃伅鎴栨煡璇㈠埌澶氭潯");
+        if (!accountDtos.get(0).getLink().equals(owners.get(0).getLink()) || !accountDtos.get(0).getAcctName().equals(owners.get(0).getName())) {
+            AccountPo accountPo = new AccountPo();
+            accountPo.setAcctName(owners.get(0).getName());
+            accountPo.setoLink(owners.get(0).getLink());
+            accountPo.setAcctId(accountDtos.get(0).getAcctId());
+            accountInnerServiceSMOImpl.updateAccount(accountPo);
+        }
+    }
 
-        JSONObject businessUnit = new JSONObject();
-        businessUnit.putAll(BeanConvertUtil.beanCovertMap(fileRelDtos.get(0)));
-        businessUnit.put("fileRealName", paramInJson.getString("ownerPhotoId"));
-        businessUnit.put("fileSaveName", paramInJson.getString("fileSaveName"));
-        FileRelPo fileRelPo = BeanConvertUtil.covertBean(businessUnit, FileRelPo.class);
-        flag = fileRelInnerServiceSMOImpl.updateFileRel(fileRelPo);
-        if (flag < 1) {
-            throw new CmdException("淇濆瓨鏂囦欢澶辫触");
+    /**
+     * 濡傛灉 涓氫富鍋氫簡缁戝畾鍒欎慨鏀圭粦瀹氱殑鎵嬫満鍙�
+     *
+     * @param reqJson
+     */
+    private void updateOwnerAppUser(JSONObject reqJson) {
+        OwnerAppUserDto ownerAppUserDto = new OwnerAppUserDto();
+        ownerAppUserDto.setMemberId(reqJson.getString("memberId"));
+        //todo 鏌ヨapp鐢ㄦ埛琛�
+        List<OwnerAppUserDto> ownerAppUserDtos = ownerAppUserInnerServiceSMOImpl.queryOwnerAppUsers(ownerAppUserDto);
+        if (ownerAppUserDtos == null || ownerAppUserDtos.size() < 1) {
+            return;
+        }
+        for (OwnerAppUserDto ownerAppUser : ownerAppUserDtos) {
+            OwnerAppUserPo ownerAppUserPo = BeanConvertUtil.covertBean(ownerAppUser, OwnerAppUserPo.class);
+            ownerAppUserPo.setLink(reqJson.getString("link"));
+            ownerAppUserV1InnerServiceSMOImpl.updateOwnerAppUser(ownerAppUserPo);
+            if (StringUtil.isEmpty(ownerAppUser.getUserId())) {
+                continue;
+            }
+            if (ownerAppUser.getUserId().startsWith("-")) {
+                continue;
+            }
+            // todo 淇敼鐢ㄦ埛淇℃伅
+            UserPo userPo = new UserPo();
+            userPo.setUserId(ownerAppUserDtos.get(0).getUserId());
+            userPo.setTel(reqJson.getString("link"));
+            userV1InnerServiceSMOImpl.updateUser(userPo);
         }
     }
 }

--
Gitblit v1.8.0