瀏覽代碼

优化代码

wuxw 3 年之前
父節點
當前提交
0be5151718

+ 27 - 10
java110-bean/src/main/java/com/java110/dto/roleCommunity/RoleCommunityDto.java

@@ -1,6 +1,7 @@
 package com.java110.dto.roleCommunity;
 
 import com.java110.dto.PageDto;
+
 import java.io.Serializable;
 import java.util.Date;
 
@@ -15,9 +16,10 @@ import java.util.Date;
 public class RoleCommunityDto extends PageDto implements Serializable {
 
     private String roleId;
-private String rcId;
-private String communityId;
-private String storeId;
+    private String rcId;
+    private String communityId;
+    private  String communityName;
+    private String storeId;
 
 
     private Date createTime;
@@ -28,25 +30,32 @@ private String storeId;
     public String getRoleId() {
         return roleId;
     }
-public void setRoleId(String roleId) {
+
+    public void setRoleId(String roleId) {
         this.roleId = roleId;
     }
-public String getRcId() {
+
+    public String getRcId() {
         return rcId;
     }
-public void setRcId(String rcId) {
+
+    public void setRcId(String rcId) {
         this.rcId = rcId;
     }
-public String getCommunityId() {
+
+    public String getCommunityId() {
         return communityId;
     }
-public void setCommunityId(String communityId) {
+
+    public void setCommunityId(String communityId) {
         this.communityId = communityId;
     }
-public String getStoreId() {
+
+    public String getStoreId() {
         return storeId;
     }
-public void setStoreId(String storeId) {
+
+    public void setStoreId(String storeId) {
         this.storeId = storeId;
     }
 
@@ -66,4 +75,12 @@ public void setStoreId(String storeId) {
     public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
+
+    public String getCommunityName() {
+        return communityName;
+    }
+
+    public void setCommunityName(String communityName) {
+        this.communityName = communityName;
+    }
 }

+ 32 - 14
java110-bean/src/main/java/com/java110/po/roleCommunity/RoleCommunityPo.java

@@ -17,6 +17,7 @@ package com.java110.po.roleCommunity;
 
 import java.io.Serializable;
 import java.util.Date;
+
 /**
  * 类表述: Po 数据模型实体对象 基本保持与数据库模型一直 用于 增加修改删除 等时的数据载体
  * add by 吴学文 at 2022-07-25 17:12:49 mail: 928255095@qq.com
@@ -28,41 +29,58 @@ import java.util.Date;
 public class RoleCommunityPo implements Serializable {
 
     private String roleId;
-private String rcId;
-private String statusCd = "0";
-private String communityId;
-private String storeId;
-public String getRoleId() {
+    private String rcId;
+    private String statusCd = "0";
+    private String communityId;
+    private  String communityName;
+    private String storeId;
+
+    public String getRoleId() {
         return roleId;
     }
-public void setRoleId(String roleId) {
+
+    public void setRoleId(String roleId) {
         this.roleId = roleId;
     }
-public String getRcId() {
+
+    public String getRcId() {
         return rcId;
     }
-public void setRcId(String rcId) {
+
+    public void setRcId(String rcId) {
         this.rcId = rcId;
     }
-public String getStatusCd() {
+
+    public String getStatusCd() {
         return statusCd;
     }
-public void setStatusCd(String statusCd) {
+
+    public void setStatusCd(String statusCd) {
         this.statusCd = statusCd;
     }
-public String getCommunityId() {
+
+    public String getCommunityId() {
         return communityId;
     }
-public void setCommunityId(String communityId) {
+
+    public void setCommunityId(String communityId) {
         this.communityId = communityId;
     }
-public String getStoreId() {
+
+    public String getStoreId() {
         return storeId;
     }
-public void setStoreId(String storeId) {
+
+    public void setStoreId(String storeId) {
         this.storeId = storeId;
     }
 
 
+    public String getCommunityName() {
+        return communityName;
+    }
 
+    public void setCommunityName(String communityName) {
+        this.communityName = communityName;
+    }
 }

+ 6 - 3
java110-db/src/main/resources/mapper/user/RoleCommunityV1ServiceDaoImplMapper.xml

@@ -8,9 +8,9 @@
     <!-- 保存项目授权信息 add by wuxw 2018-07-03 -->
     <insert id="saveRoleCommunityInfo" parameterType="Map">
         insert into u_role_community(
-        role_id,rc_id,community_id,store_id
+        role_id,rc_id,community_id,community_name,store_id
         ) values (
-        #{roleId},#{rcId},#{communityId},#{storeId}
+        #{roleId},#{rcId},#{communityId},#{communityName},#{storeId}
         )
     </insert>
 
@@ -18,7 +18,7 @@
     <!-- 查询项目授权信息 add by wuxw 2018-07-03 -->
     <select id="getRoleCommunityInfo" parameterType="Map" resultType="Map">
         select t.role_id,t.role_id roleId,t.rc_id,t.rc_id rcId,t.status_cd,t.status_cd
-        statusCd,t.community_id,t.community_id communityId,t.store_id,t.store_id storeId
+        statusCd,t.community_id,t.community_id communityId,t.community_name communityName,t.store_id,t.store_id storeId
         from u_role_community t
         where 1 =1
         <if test="roleId !=null and roleId != ''">
@@ -56,6 +56,9 @@
         <if test="communityId !=null and communityId != ''">
             , t.community_id= #{communityId}
         </if>
+        <if test="communityName !=null and communityName != ''">
+            , t.community_name= #{communityName}
+        </if>
         <if test="storeId !=null and storeId != ''">
             , t.store_id= #{storeId}
         </if>

+ 25 - 51
service-api/src/main/java/com/java110/api/listener/org/ListOrgNoCommunitysListener.java

@@ -1,73 +1,57 @@
-package com.java110.api.listener.org;
+package com.java110.user.cmd.org;
 
 import com.alibaba.fastjson.JSONObject;
-import com.java110.api.listener.AbstractServiceApiListener;
-import com.java110.core.annotation.Java110Listener;
-import com.java110.core.context.DataFlowContext;
-import com.java110.intf.community.ICommunityInnerServiceSMO;
-import com.java110.intf.user.IOrgCommunityInnerServiceSMO;
+import com.java110.core.annotation.Java110Cmd;
+import com.java110.core.context.ICmdDataFlowContext;
+import com.java110.core.event.cmd.Cmd;
+import com.java110.core.event.cmd.CmdEvent;
 import com.java110.dto.community.CommunityDto;
 import com.java110.dto.org.OrgCommunityDto;
-import com.java110.core.event.service.api.ServiceDataFlowEvent;
-import com.java110.utils.constant.ServiceCodeOrgConstant;
+import com.java110.dto.roleCommunity.RoleCommunityDto;
+import com.java110.intf.community.ICommunityInnerServiceSMO;
+import com.java110.intf.user.IOrgCommunityInnerServiceSMO;
+import com.java110.intf.user.IRoleCommunityV1InnerServiceSMO;
+import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.BeanConvertUtil;
+import com.java110.utils.util.StringUtil;
 import com.java110.vo.api.community.ApiCommunityDataVo;
 import com.java110.vo.api.community.ApiCommunityVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpMethod;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 
 import java.util.ArrayList;
 import java.util.List;
 
-
-/**
- * 查询小区侦听类
- */
-@Java110Listener("listOrgNoCommunitysListener")
-public class ListOrgNoCommunitysListener extends AbstractServiceApiListener {
+@Java110Cmd(serviceCode = "org.listOrgNoCommunitys")
+public class ListOrgNoCommunitysCmd extends Cmd {
 
     @Autowired
-    private IOrgCommunityInnerServiceSMO orgCommunityInnerServiceSMOImpl;
+    private IRoleCommunityV1InnerServiceSMO roleCommunityV1InnerServiceSMO;
 
     @Autowired
     private ICommunityInnerServiceSMO communityInnerServiceSMOImpl;
 
     @Override
-    public String getServiceCode() {
-        return ServiceCodeOrgConstant.LIST_ORG_NO_COMMUNITYS;
-    }
-
-    @Override
-    public HttpMethod getHttpMethod() {
-        return HttpMethod.GET;
-    }
-
-
-    @Override
-    public int getOrder() {
-        return DEFAULT_ORDER;
-    }
-
-
-
-    @Override
-    protected void validate(ServiceDataFlowEvent event, JSONObject reqJson) {
+    public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         super.validatePageInfo(reqJson);
+        if(!reqJson.containsKey("storeId") || StringUtil.isEmpty(reqJson.getString("storeId"))) {
+            String storeId = context.getReqHeaders().get("store-id");
+            reqJson.put("storeId",storeId);
+        }
         Assert.hasKeyAndValue(reqJson, "storeId", "必填,请填写商户ID");
-        Assert.hasKeyAndValue(reqJson, "orgId", "必填,请填写组织ID");
+
+        Assert.hasKeyAndValue(reqJson, "roleId", "必填,请填写角色");
     }
 
     @Override
-    protected void doSoService(ServiceDataFlowEvent event, DataFlowContext context, JSONObject reqJson) {
-
-        OrgCommunityDto orgCommunityDto = BeanConvertUtil.covertBean(reqJson, OrgCommunityDto.class);
+    public void doCmd(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
+        RoleCommunityDto roleCommunityDto = BeanConvertUtil.covertBean(reqJson, RoleCommunityDto.class);
 
-        List<OrgCommunityDto> orgCommunityDtos = orgCommunityInnerServiceSMOImpl.queryOrgCommunitys(orgCommunityDto);
+        List<RoleCommunityDto> orgCommunityDtos = roleCommunityV1InnerServiceSMO.queryRoleCommunitys(roleCommunityDto);
         List<String> communityIds = new ArrayList<>();
-        for(OrgCommunityDto tmpOrgCommunityDto : orgCommunityDtos){
+        for(RoleCommunityDto tmpOrgCommunityDto : orgCommunityDtos){
             communityIds.add(tmpOrgCommunityDto.getCommunityId());
         }
         CommunityDto communityDto = BeanConvertUtil.covertBean(reqJson, CommunityDto.class);
@@ -95,15 +79,5 @@ public class ListOrgNoCommunitysListener extends AbstractServiceApiListener {
         ResponseEntity<String> responseEntity = new ResponseEntity<String>(JSONObject.toJSONString(apiCommunityVo), HttpStatus.OK);
 
         context.setResponseEntity(responseEntity);
-
-    }
-
-
-    public IOrgCommunityInnerServiceSMO getOrgCommunityInnerServiceSMOImpl() {
-        return orgCommunityInnerServiceSMOImpl;
-    }
-
-    public void setOrgCommunityInnerServiceSMOImpl(IOrgCommunityInnerServiceSMO orgCommunityInnerServiceSMOImpl) {
-        this.orgCommunityInnerServiceSMOImpl = orgCommunityInnerServiceSMOImpl;
     }
 }

+ 18 - 7
service-user/src/main/java/com/java110/user/cmd/roleCommunity/SaveRoleCommunityCmd.java

@@ -15,6 +15,7 @@
  */
 package com.java110.user.cmd.roleCommunity;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.annotation.Java110Transactional;
@@ -55,20 +56,30 @@ public class SaveRoleCommunityCmd extends Cmd {
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) {
         Assert.hasKeyAndValue(reqJson, "roleId", "请求报文中未包含roleId");
-Assert.hasKeyAndValue(reqJson, "communityId", "请求报文中未包含communityId");
-
+        if (!reqJson.containsKey("communitys") || reqJson.getJSONArray("communitys").size() < 1) {
+            throw new IllegalArgumentException("未包含小区信息");
+        }
     }
 
     @Override
     @Java110Transactional
     public void doCmd(CmdEvent event, ICmdDataFlowContext cmdDataFlowContext, JSONObject reqJson) throws CmdException {
+        String storeId = cmdDataFlowContext.getReqHeaders().get("store-id");
 
-       RoleCommunityPo roleCommunityPo = BeanConvertUtil.covertBean(reqJson, RoleCommunityPo.class);
-        roleCommunityPo.setRcId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
-        int flag = roleCommunityV1InnerServiceSMOImpl.saveRoleCommunity(roleCommunityPo);
+        RoleCommunityPo roleCommunityPo = null;
+        JSONArray communitys = reqJson.getJSONArray("communitys");
+        for (int communityIndex = 0; communityIndex < communitys.size(); communityIndex++) {
+            roleCommunityPo = new RoleCommunityPo();
+            roleCommunityPo.setCommunityId(communitys.getJSONObject(communityIndex).getString("communityId"));
+            roleCommunityPo.setCommunityName(communitys.getJSONObject(communityIndex).getString("communityName"));
+            roleCommunityPo.setRoleId(reqJson.getString("roleId"));
+            roleCommunityPo.setStoreId(storeId);
+            roleCommunityPo.setRcId(GenerateCodeFactory.getGeneratorId(CODE_PREFIX_ID));
+            int flag = roleCommunityV1InnerServiceSMOImpl.saveRoleCommunity(roleCommunityPo);
 
-        if (flag < 1) {
-            throw new CmdException("保存数据失败");
+            if (flag < 1) {
+                throw new CmdException("保存数据失败");
+            }
         }
 
         cmdDataFlowContext.setResponseEntity(ResultVo.success());