Browse Source

用户管理 权限

zhangc 8 months ago
parent
commit
614ed512db

+ 1 - 1
src/main/java/com/sunxung/factoring/component/aspect/OperationLogAspect.java

@@ -108,7 +108,7 @@ public class OperationLogAspect {
                     // 从获取RequestAttributes中获取HttpServletRequest的信息
                     HttpServletRequest request = (HttpServletRequest) requestAttributes.resolveReference(RequestAttributes.REFERENCE_REQUEST);
                     //获取ip
-                    String clientIP = ServletUtil.getClientIP(request);
+                    String clientIP =  request.getRemoteAddr();
                     sysOperationLog.setClientIp(clientIP);
                     //获取目标方法执行时间
                     long usageTime = endTime - beginTime;

+ 5 - 0
src/main/java/com/sunxung/factoring/component/util/ConstantConversionUtil.java

@@ -610,6 +610,11 @@ public class ConstantConversionUtil {
      */
     public static final String VIEW_ALL_SIGN_CONFIRMATION = "viewAllSignConfirmation";
 
+    /**
+     * 查看所有 c端用户
+     */
+    public static final String VIEW_ALL_CLIENT_USER = "viewAllClientUser";
+
     /**
      * 垫款业务编号后缀-AD
      **/

+ 14 - 1
src/main/java/com/sunxung/factoring/entity/sys/request/ClientUserQueryRequest.java

@@ -5,6 +5,8 @@ import lombok.Data;
 import lombok.Getter;
 import lombok.Setter;
 
+import java.util.List;
+
 @Getter
 @Setter
 public class ClientUserQueryRequest extends BaseSearch {
@@ -14,7 +16,6 @@ public class ClientUserQueryRequest extends BaseSearch {
    */
   private Long  mark;
 
-
   /**
    *
    */
@@ -26,5 +27,17 @@ public class ClientUserQueryRequest extends BaseSearch {
   private String  managerName;
 
 
+  private String roleType;
+
+
+  private Long  currentUserId;
+
+
+  private List<Long> orgIds;
+
+
+  private List<Long>  userIds;
+
+
 
 }

+ 2 - 0
src/main/java/com/sunxung/factoring/service/sys/OrgService.java

@@ -183,6 +183,8 @@ public interface OrgService {
      */
     List<Org> findByNameList(List<String> orgNameList);
 
+    Org findByName(String name);
+
     /**
      * 查询用户所属部门是否为长安银科
      * @param userId

+ 64 - 10
src/main/java/com/sunxung/factoring/service/sys/impl/ClientUserServiceImpl.java

@@ -6,18 +6,18 @@ import com.github.pagehelper.Page;
 import com.github.pagehelper.PageHelper;
 import com.sunxung.factoring.component.exception.ServiceException;
 import com.sunxung.factoring.component.exception.ValidatorException;
-import com.sunxung.factoring.component.util.BeanUtilsProxy;
-import com.sunxung.factoring.component.util.ThreadLocalUtil;
+import com.sunxung.factoring.component.util.*;
 import com.sunxung.factoring.entity.CommonVO;
 import com.sunxung.factoring.entity.GridPage;
-import com.sunxung.factoring.entity.sys.ClientUserDO;
-import com.sunxung.factoring.entity.sys.User;
+import com.sunxung.factoring.entity.sys.*;
 import com.sunxung.factoring.entity.sys.request.ClientUserQueryRequest;
 import com.sunxung.factoring.entity.sys.request.DistributePMRequest;
 import com.sunxung.factoring.entity.sys.request.DistributeRMRequest;
 import com.sunxung.factoring.entity.sys.vo.ClientUserVO;
 import com.sunxung.factoring.mapper.sys.ClientUserMapper;
 import com.sunxung.factoring.service.sys.ClientUserService;
+import com.sunxung.factoring.service.sys.OrgService;
+import com.sunxung.factoring.service.sys.PermissionService;
 import com.sunxung.factoring.service.sys.UserService;
 import org.apache.commons.compress.utils.Lists;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -31,6 +31,7 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 
 @Service
@@ -41,9 +42,59 @@ public class ClientUserServiceImpl extends ServiceImpl<ClientUserMapper, ClientU
   @Autowired
   private UserService userService;
 
+  @Autowired
+  private OrgService orgService;
+
+  @Autowired
+  private PermissionService permissionService;
+
   @Override
   public GridPage<ClientUserVO> pageList(ClientUserQueryRequest clientUserQueryRequest) {
 
+    List<Role> roles = ThreadLocalUtil.getUser().getRoles();
+    Long userId = ThreadLocalUtil.getUserId();
+    clientUserQueryRequest.setCurrentUserId(userId);
+    String roleType = null;
+    List<Long> orgIds = Lists.newArrayList();
+    List<Long> userIds= Lists.newArrayList();
+    orgIds.add(-1L);
+    userIds.add(-1L);
+
+    Permission per = permissionService.getByEname(ConstantConversionUtil.VIEW_ALL_CLIENT_USER);
+    List<Long> pers = permissionService.getPermissionIdByUserId(ThreadLocalUtil.getUserId());
+    boolean showAllData = false;
+    if (pers.contains(per.getId())
+        || ThreadLocalUtil.getUser().getLoginName().equals(ConstantConversionUtil.ADMINISTORIES)) {
+      showAllData = true;
+    }
+    if(!showAllData){
+        //如果不是查看全员 则需要判断用户的角色
+        List<UserOrgRel> userOrgRelList = userService.findOrgRelByUserId(userId);
+        for (UserOrgRel userOrgRel : userOrgRelList) {
+          if (userOrgRel.isUserIdentity()) {
+            roleType = "projectCapital";
+            orgIds.add(userOrgRel.getOrgId());
+            // 如果是部门负责人,获取部门下所有人员Id
+            List<Long> userIdList = userService.findUserIdByOrgId(userOrgRel.getOrgId());
+            userIds.addAll(userIdList);
+          }
+        }
+        if(StringUtil.isEmpty(roleType)){
+          for(Role role:roles){
+            if(role.getName().equals("业务经理")){
+              roleType = "projectManager";
+              break;
+            }
+            if(role.getName().equals("风控经理")){
+              roleType = "riskManager";
+              break;
+            }
+          }
+        }
+      clientUserQueryRequest.setRoleType(roleType);
+      clientUserQueryRequest.setUserIds(userIds);
+      clientUserQueryRequest.setOrgIds(orgIds);
+    }
     Page<Object> objects = PageHelper.startPage(clientUserQueryRequest.getPage(),
         clientUserQueryRequest.getRows());
     List<ClientUserVO> clientUserVOS = this.baseMapper.pageList(clientUserQueryRequest);
@@ -139,7 +190,7 @@ public class ClientUserServiceImpl extends ServiceImpl<ClientUserMapper, ClientU
   @Override
   public List<CommonVO> getPMs(Long clientUserId) {
     if(clientUserId==null){
-      List<User> userByRoleId = userService.findUserByRoleId(17L);
+      List<User> userByRoleId = userService.findUserByRoleName("业务经理");
       List<CommonVO> commonVOs = BeanUtilsProxy.copyPropertiesList(userByRoleId, CommonVO.class);
       return commonVOs;
     }
@@ -153,7 +204,7 @@ public class ClientUserServiceImpl extends ServiceImpl<ClientUserMapper, ClientU
     if(orgId!=null){
        userIdByOrgId = userService.findUserIdByOrgId(orgId);
     }
-    List<User> userByRoleId = userService.findUserByRoleId(17L);
+    List<User> userByRoleId = userService.findUserByRoleName("业务经理");
     if(!CollectionUtils.isEmpty(userIdByOrgId)){
         for(User u:userByRoleId){
           if(userIdByOrgId.indexOf(u.getId())<0){
@@ -187,10 +238,13 @@ public class ClientUserServiceImpl extends ServiceImpl<ClientUserMapper, ClientU
     List<Long> list1 = com.google.common.collect.Lists.newArrayList(896L,914L,144L,1037L,1279L,1402L,1175L);
     List<Long> list2 = com.google.common.collect.Lists.newArrayList(2066L,2285L,2425L,2850L,2747L,1787L,1916L);
 
-    Long xayyzx = 2L;  //西安运营中心
-    Long zcglzx = 8L;     //资产管理中心
-    Long shyyzx = 3L;     //上海运营中心
-    Long szyyzx = 14L;  //深圳运营中心
+
+
+
+    Long xayyzx =  orgService.findByName("西安运营中心").getId();    //西安运营中心
+    Long zcglzx =  orgService.findByName("资产管理中心").getId();    //资产管理中心
+    Long shyyzx =  orgService.findByName("上海运营中心").getId();    //上海运营中心
+    Long szyyzx =  orgService.findByName("深圳运营中心").getId();;   //深圳运营中心
 
     List<ClientUserDO> userList = new ArrayList<>();
     List<ClientUserDO> userList1 = new ArrayList<>();

+ 6 - 0
src/main/java/com/sunxung/factoring/service/sys/impl/OrgServiceImpl.java

@@ -581,6 +581,12 @@ public class OrgServiceImpl implements OrgService {
         return orgList;
     }
 
+    @Override
+    public Org findByName(String orgName) {
+        Org org = orgMapper.findByName(orgName);
+        return org;
+    }
+
     @Override
     public Org findRootByUseId(Long userId) {
         return orgMapper.findRootByUseId(userId);

+ 17 - 0
src/main/resources/mapper/sys/ClientUserMapper.xml

@@ -31,6 +31,23 @@
       <if test=" managerName !=null and managerName !=''  ">
         and (b.name like CONCAT('%',#{managerName},'%') or  c.name like CONCAT('%',#{managerName},'%'))
 			</if>
+      <if test="roleType =='projectManager' ">
+         and ( a.project_manager = #{currentUserId} or a.project_manager is null  )
+			</if>
+			<if test="roleType =='riskManager' ">
+				and  a.risk_manager = #{currentUserId}
+			</if>
+			<if test="roleType =='projectCapital' ">
+				and ( a.org_id in (
+									<foreach collection="orgIds" item="orgId" separator=",">#{orgId}
+									</foreach>
+				      )  or
+				        a.project_manager in (
+									<foreach collection="userIds" item="userId" separator=",">#{userId}
+									</foreach>
+			       	)
+				    )
+			</if>
 		</where>
 	</select>