Browse Source

优化 代码

wuxw 3 years ago
parent
commit
cde40b7ebd

+ 14 - 0
java110-db/src/main/resources/mapper/store/OrgStaffRelV1ServiceDaoImplMapper.xml

@@ -37,6 +37,13 @@
         <if test="staffId !=null and staffId != ''">
         <if test="staffId !=null and staffId != ''">
             and t.staff_id= #{staffId}
             and t.staff_id= #{staffId}
         </if>
         </if>
+        <if test="staffIds != null">
+            and t.staff_id in
+            <foreach collection="staffIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+
         <if test="relCd !=null and relCd != ''">
         <if test="relCd !=null and relCd != ''">
             and t.rel_cd= #{relCd}
             and t.rel_cd= #{relCd}
         </if>
         </if>
@@ -93,6 +100,13 @@
         <if test="staffId !=null and staffId != ''">
         <if test="staffId !=null and staffId != ''">
             and t.staff_id= #{staffId}
             and t.staff_id= #{staffId}
         </if>
         </if>
+        <if test="staffIds != null">
+            and t.staff_id in
+            <foreach collection="staffIds" item="item" open="(" close=")" separator=",">
+                #{item}
+            </foreach>
+        </if>
+
         <if test="relCd !=null and relCd != ''">
         <if test="relCd !=null and relCd != ''">
             and t.rel_cd= #{relCd}
             and t.rel_cd= #{relCd}
         </if>
         </if>

+ 3 - 2
java110-db/src/main/resources/mapper/user/UserServiceDaoImplMapper.xml

@@ -500,13 +500,14 @@
     <select id="getStaffs" parameterType="Map" resultType="Map">
     <select id="getStaffs" parameterType="Map" resultType="Map">
         select u.user_id, u.user_id userId,u.name,u.name
         select u.user_id, u.user_id userId,u.name,u.name
         userName,u.email,u.address,u.location_cd,u.location_cd locationCd,
         userName,u.email,u.address,u.location_cd,u.location_cd locationCd,
-        u.age,u.sex,u.tel,u.level_cd levelCd,u.b_id
+        u.age,u.sex,u.tel,u.level_cd levelCd,u.b_id,su.rel_cd relCd,td.name relCdName
         <if test="orgId !=null and orgId != ''">
         <if test="orgId !=null and orgId != ''">
-            ,uo.org_id orgId,uo.org_name,uo.org_name orgName,uosr.store_id storeId,uosr.rel_cd relCd
+            ,uo.org_id orgId,uo.org_name,uo.org_name orgName,uosr.store_id storeId,
         </if>
         </if>
         from
         from
         u_user u
         u_user u
         inner join s_store_user su on su.user_id = u.user_id
         inner join s_store_user su on su.user_id = u.user_id
+        left join t_dict td on su.rel_cd =  td.status_cd and td.table_name='s_store_user'  and td.table_columns='rel_cd'
         <if test="orgId !=null and orgId != ''">
         <if test="orgId !=null and orgId != ''">
             left join u_org_staff_rel uosr on u.user_id = uosr.staff_id and uosr.status_cd = '0'
             left join u_org_staff_rel uosr on u.user_id = uosr.staff_id and uosr.status_cd = '0'
             left join u_org uo on uosr.org_id = uo.org_id and uo.status_cd = '0'
             left join u_org uo on uosr.org_id = uo.org_id and uo.status_cd = '0'

+ 81 - 0
service-user/src/main/java/com/java110/user/cmd/user/QueryStaffInfosCmd.java

@@ -5,7 +5,12 @@ import com.java110.core.annotation.Java110Cmd;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.context.ICmdDataFlowContext;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.Cmd;
 import com.java110.core.event.cmd.CmdEvent;
 import com.java110.core.event.cmd.CmdEvent;
+import com.java110.dto.org.OrgDto;
+import com.java110.dto.org.OrgStaffRelDto;
 import com.java110.dto.user.UserDto;
 import com.java110.dto.user.UserDto;
+import com.java110.intf.store.IOrgStaffRelV1InnerServiceSMO;
+import com.java110.intf.user.IOrgStaffRelInnerServiceSMO;
+import com.java110.intf.user.IOrgV1InnerServiceSMO;
 import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.Assert;
@@ -27,6 +32,12 @@ public class QueryStaffInfosCmd extends Cmd {
     @Autowired
     @Autowired
     private IUserInnerServiceSMO userInnerServiceSMOImpl;
     private IUserInnerServiceSMO userInnerServiceSMOImpl;
 
 
+    @Autowired
+    private IOrgV1InnerServiceSMO orgV1InnerServiceSMOImpl;
+
+    @Autowired
+    private IOrgStaffRelV1InnerServiceSMO orgStaffRelV1InnerServiceSMOImpl;
+
     @Override
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         Assert.hasKeyAndValue(reqJson,"page","请求报文中未包含page节点");
         Assert.hasKeyAndValue(reqJson,"page","请求报文中未包含page节点");
@@ -49,6 +60,7 @@ public class QueryStaffInfosCmd extends Cmd {
         if (count > 0) {
         if (count > 0) {
             staffs = BeanConvertUtil.covertBeanList(userInnerServiceSMOImpl.getStaffs(userDto), ApiStaffDataVo.class);
             staffs = BeanConvertUtil.covertBeanList(userInnerServiceSMOImpl.getStaffs(userDto), ApiStaffDataVo.class);
             refreshInitials(staffs);
             refreshInitials(staffs);
+            refreshOrgs(staffs,reqJson.getString("storeId"));
         } else {
         } else {
             staffs = new ArrayList<>();
             staffs = new ArrayList<>();
         }
         }
@@ -64,6 +76,75 @@ public class QueryStaffInfosCmd extends Cmd {
         context.setResponseEntity(responseEntity);
         context.setResponseEntity(responseEntity);
     }
     }
 
 
+    private void refreshOrgs(List<ApiStaffDataVo> staffs,String storeId) {
+        if(staffs == null ||  staffs.size()<1){
+            return ;
+        }
+
+        List<String>  staffIds  = new ArrayList<>();
+        for(ApiStaffDataVo apiStaffDataVo : staffs){
+            staffIds.add(apiStaffDataVo.getUserId());
+        }
+
+        OrgDto orgDto = new OrgDto();
+        orgDto.setStoreId(storeId);
+        List<OrgDto> orgDtos = orgV1InnerServiceSMOImpl.queryOrgs(orgDto);
+        if (orgDtos == null || orgDtos.size() < 1) {
+            return;
+        }
+        OrgStaffRelDto orgStaffRelDto = new OrgStaffRelDto();
+        orgStaffRelDto.setStaffIds(staffIds.toArray(new String[staffIds.size()]));
+        orgStaffRelDto.setStoreId(storeId);
+        List<OrgStaffRelDto> orgStaffRels = orgStaffRelV1InnerServiceSMOImpl.queryOrgStaffRels(orgStaffRelDto);
+
+        if (orgStaffRels == null || orgStaffRels.size() < 1) {
+            return;
+        }
+
+
+        for(ApiStaffDataVo apiStaffDataVo : staffs){
+            for(OrgStaffRelDto tmpOrgStaffRelDto : orgStaffRels){
+                if(!apiStaffDataVo.getUserId().equals(tmpOrgStaffRelDto.getStaffId())){
+                    continue;
+                }
+                tmpOrgStaffRelDto.setParentOrgId(tmpOrgStaffRelDto.getOrgId());
+                findParents(tmpOrgStaffRelDto, orgDtos, null);
+                apiStaffDataVo.setOrgName(tmpOrgStaffRelDto.getOrgName());
+            }
+        }
+
+    }
+
+
+    private void findParents(OrgStaffRelDto orgStaffRelDto, List<OrgDto> orgDtos, OrgDto curOrgDto) {
+        for (OrgDto orgDto : orgDtos) {
+            if (!orgStaffRelDto.getParentOrgId().equals(orgDto.getOrgId())) { // 他自己跳过
+                continue;
+            }
+            orgStaffRelDto.setParentOrgId(orgDto.getParentOrgId());
+            curOrgDto = orgDto;
+            if (StringUtil.isEmpty(orgStaffRelDto.getOrgName())) {
+                orgStaffRelDto.setOrgName(orgDto.getOrgName() );
+                continue;
+            }
+            orgStaffRelDto.setOrgName(orgDto.getOrgName() + " / " + orgStaffRelDto.getOrgName());
+        }
+
+        if (curOrgDto != null && OrgDto.ORG_LEVEL_STORE.equals(curOrgDto.getOrgLevel())) {
+            return;
+        }
+
+        if (curOrgDto != null && curOrgDto.getParentOrgId().equals(curOrgDto.getOrgId())) {
+            return;
+        }
+
+        if (curOrgDto != null && "-1".equals(curOrgDto.getParentOrgId())) {
+            return;
+        }
+
+        findParents(orgStaffRelDto, orgDtos, curOrgDto);
+    }
+
     /**
     /**
      * 刷入首字母
      * 刷入首字母
      * @param staffs
      * @param staffs

+ 22 - 0
service-user/src/main/java/com/java110/user/cmd/user/UserStaffModifyCmd.java

@@ -11,15 +11,18 @@ import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.dto.file.FileDto;
 import com.java110.dto.file.FileDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.file.FileRelDto;
 import com.java110.dto.org.OrgStaffRelDto;
 import com.java110.dto.org.OrgStaffRelDto;
+import com.java110.dto.store.StoreUserDto;
 import com.java110.dto.user.UserDto;
 import com.java110.dto.user.UserDto;
 import com.java110.intf.common.IFileInnerServiceSMO;
 import com.java110.intf.common.IFileInnerServiceSMO;
 import com.java110.intf.common.IFileRelInnerServiceSMO;
 import com.java110.intf.common.IFileRelInnerServiceSMO;
 import com.java110.intf.store.IOrgStaffRelV1InnerServiceSMO;
 import com.java110.intf.store.IOrgStaffRelV1InnerServiceSMO;
+import com.java110.intf.store.IStoreUserV1InnerServiceSMO;
 import com.java110.intf.user.IOrgStaffRelInnerServiceSMO;
 import com.java110.intf.user.IOrgStaffRelInnerServiceSMO;
 import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.intf.user.IUserInnerServiceSMO;
 import com.java110.intf.user.IUserV1InnerServiceSMO;
 import com.java110.intf.user.IUserV1InnerServiceSMO;
 import com.java110.po.file.FileRelPo;
 import com.java110.po.file.FileRelPo;
 import com.java110.po.org.OrgStaffRelPo;
 import com.java110.po.org.OrgStaffRelPo;
+import com.java110.po.store.StoreUserPo;
 import com.java110.po.user.UserPo;
 import com.java110.po.user.UserPo;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.exception.CmdException;
 import com.java110.utils.util.Assert;
 import com.java110.utils.util.Assert;
@@ -49,6 +52,9 @@ public class UserStaffModifyCmd extends Cmd {
     @Autowired
     @Autowired
     private IOrgStaffRelV1InnerServiceSMO orgStaffRelV1InnerServiceSMOImpl;
     private IOrgStaffRelV1InnerServiceSMO orgStaffRelV1InnerServiceSMOImpl;
 
 
+    @Autowired
+    private IStoreUserV1InnerServiceSMO  storeUserV1InnerServiceSMOImpl;
+
     @Override
     @Override
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
     public void validate(CmdEvent event, ICmdDataFlowContext context, JSONObject reqJson) throws CmdException {
         Assert.jsonObjectHaveKey(reqJson, "staffId", "请求参数中未包含员工 节点,请确认");
         Assert.jsonObjectHaveKey(reqJson, "staffId", "请求参数中未包含员工 节点,请确认");
@@ -137,6 +143,22 @@ public class UserStaffModifyCmd extends Cmd {
         if (flag < 1) {
         if (flag < 1) {
             throw new CmdException("保存员工 失败");
             throw new CmdException("保存员工 失败");
         }
         }
+
+        StoreUserDto storeUserDto = new StoreUserDto();
+        storeUserDto.setUserId(userPo.getUserId());
+        List<StoreUserDto> storeUserDtos = storeUserV1InnerServiceSMOImpl.queryStoreUsers(storeUserDto);
+
+        if (storeUserDtos == null || storeUserDtos.size() < 1) {
+            return;
+        }
+        StoreUserPo storeUserPo = new StoreUserPo();
+        storeUserPo.setRelCd(paramObj.getString("relCd"));
+        storeUserPo.setStoreUserId(storeUserDtos.get(0).getStoreUserId());
+
+        flag = storeUserV1InnerServiceSMOImpl.updateStoreUser(storeUserPo);
+        if (flag < 1) {
+            throw new CmdException("保存员工 失败");
+        }
     }
     }