zouxuan 3 năm trước cách đây
mục cha
commit
d83f742819

+ 9 - 0
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/dal/dao/SysRoleDao.java

@@ -28,4 +28,13 @@ public interface SysRoleDao extends BaseDAO<Integer, SysRole> {
      * @return
      */
     SysRole findByRoleName(@Param("roleName") String roleName, @Param("tenantId") Integer tenantId);
+
+    /**
+    * @description: 获取机构管理员角色
+     * @param tenantId
+    * @return java.lang.Integer
+    * @author zx
+    * @date 2022/1/10 14:35
+    */
+    Integer getMinRoleId(@Param("tenantId") Integer tenantId);
 }

+ 12 - 6
mec-auth/mec-auth-server/src/main/java/com/ym/mec/auth/service/impl/SysRoleServiceImpl.java

@@ -1,13 +1,9 @@
 package com.ym.mec.auth.service.impl;
 
-import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysRole;
-import com.ym.mec.auth.api.entity.SysUser;
-import com.ym.mec.auth.api.entity.TenantInfo;
 import com.ym.mec.auth.dal.dao.SysRoleDao;
 import com.ym.mec.auth.dal.dao.SysRoleMenuDao;
 import com.ym.mec.auth.service.SysRoleService;
-import com.ym.mec.auth.service.TenantInfoService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
@@ -45,7 +41,7 @@ public class SysRoleServiceImpl extends BaseServiceImpl<Integer, SysRole>  imple
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void addRole(SysRole sysRole) {
-		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName(), sysRole.getTenantId());
+		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName(),sysRole.getTenantId());
 		if(findByName != null){
 			throw new BizException("操作失败:角色 {} 已存在",sysRole.getRoleName());
 		}
@@ -53,10 +49,19 @@ public class SysRoleServiceImpl extends BaseServiceImpl<Integer, SysRole>  imple
 		batchSave(sysRole);
 	}
 
+	public void checkManageRole(Integer id){
+		Integer tenantId = TenantContextHolder.getTenantId();
+		Integer roleId = sysRoleDao.getMinRoleId(tenantId);
+		if(roleId.equals(id)){
+			throw new BizException("操作失败:机构管理员角色不允许调整");
+		}
+	}
+
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void updateRole(SysRole sysRole) {
-		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName(), sysRole.getTenantId());
+		this.checkManageRole(sysRole.getId());
+		SysRole findByName = sysRoleDao.findByRoleName(sysRole.getRoleName(),sysRole.getTenantId());
 		if(findByName != null && !findByName.getId().equals(sysRole.getId())){
 			throw new BizException("操作失败:角色 {} 已存在",sysRole.getRoleName());
 		}
@@ -69,6 +74,7 @@ public class SysRoleServiceImpl extends BaseServiceImpl<Integer, SysRole>  imple
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void delRole(Integer id) {
+		this.checkManageRole(id);
 		sysRoleDao.delete(id);
 		sysRoleMenuDao.deleteAllMenu(id);
 	}

+ 3 - 0
mec-auth/mec-auth-server/src/main/resources/config/mybatis/SysRoleMapper.xml

@@ -87,4 +87,7 @@
     <select id="findByRoleName" resultMap="SysRole">
         SELECT * FROM sys_role WHERE role_name_ = #{roleName} AND del_flag_ = 0 and tenant_id_ = #{tenantId} LIMIT 1
     </select>
+    <select id="getMinRoleId" resultType="java.lang.Integer">
+        SELECT sr.id_ FROM sys_role WHERE del_flag_ = 0 AND tenant_id_ = #{tenantId} LIMIT 1
+    </select>
 </mapper>

+ 1 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/OrganizationDao.java

@@ -29,10 +29,9 @@ public interface OrganizationDao extends BaseDAO<Integer, Organization> {
 
     /**
      *
-     * @param userId
      * @return
      */
-    List<Organization> queryEmployeeOrgan(@Param("userId") Integer userId, @Param("organId") String organId);
+    List<Organization> queryEmployeeOrgan(@Param("organId") String organId);
 
     /**
      * 根据分部编号获取分部名称map

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/OrganizationService.java

@@ -12,10 +12,10 @@ public interface OrganizationService extends BaseService<Integer, Organization>
     Set<Integer>  EXCLUDE_ORGAN_IDS = new HashSet<>(Arrays.asList(36,38,39,41,42,43,44,45,46,47,48,49,50,52,54,55,56,2,27,22,24));
 
     /**
-     * 获取员工在分部列表
+     * 获取员工在分部列表
      * @return
      */
-    List<Organization> queryEmployeeOrgan(Integer userId,String organId) throws Exception;
+    List<Organization> queryEmployeeOrgan() throws Exception;
 
     /**
      * 获取员工坐在分部列表

+ 8 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/OrganizationServiceImpl.java

@@ -55,21 +55,18 @@ public class OrganizationServiceImpl extends BaseServiceImpl<Integer, Organizati
 	}
 
 	@Override
-	public List<Organization> queryEmployeeOrgan(Integer userId,String organId){
-		return organizationDao.queryEmployeeOrgan(userId,organId);
-	}
-
-	@Override
-	public List<Organization> queryEmployeeOrganByUser(){
+	public List<Organization> queryEmployeeOrgan(){
 		SysUser sysUser = sysUserFeignService.queryUserInfo();
 		if(sysUser == null){
 			throw new BizException("获取用户信息失败");
 		}
-		Integer userId = sysUser.getId();
-		if(sysUser.getIsSuperAdmin()){
-			userId = null;
-		}
-		return organizationDao.queryEmployeeOrgan(userId,null);
+		String organIds = this.getEmployeeOrgan(sysUser.getId(), "", sysUser.getIsSuperAdmin());
+		return organizationDao.queryEmployeeOrgan(organIds);
+	}
+
+	@Override
+	public List<Organization> queryEmployeeOrganByUser(){
+		return this.queryEmployeeOrgan();
 	}
 
 	@Override

+ 0 - 1
mec-biz/src/main/resources/config/mybatis/OrganizationMapper.xml

@@ -139,7 +139,6 @@
         SELECT * FROM organization o
         <where>
             o.del_flag_ = 0
-                AND FIND_IN_SET(o.id_,(SELECT GROUP_CONCAT(organ_id_list_) FROM employee e WHERE e.user_id_ = #{userId}))
             <if test="organId != null and organId != ''">
                 AND FIND_IN_SET(o.id_,#{organId})
             </if>

+ 1 - 6
mec-web/src/main/java/com/ym/mec/web/controller/OrganizationController.java

@@ -48,12 +48,7 @@ public class OrganizationController extends BaseController {
     @GetMapping("/queryEmployeeOrgan")
     @PreAuthorize("@pcs.hasPermissions('organization/queryEmployeeOrgan')")
     public Object queryEmployeeOrgan() throws Exception {
-		SysUser sysUser = sysUserFeignService.queryUserInfo();
-		if(sysUser == null){
-			throw new BizException("获取用户信息失败");
-		}
-		Integer userId = sysUser.getId();
-        return succeed(organizationService.queryEmployeeOrgan(userId,null));
+        return succeed(organizationService.queryEmployeeOrgan());
     }
 
     @ApiOperation(value = "获取员工所在分部列表(管理员查看所有的分部)")

+ 2 - 6
mec-web/src/main/java/com/ym/mec/web/controller/StudentManageController.java

@@ -373,15 +373,11 @@ public class StudentManageController extends BaseController {
     @GetMapping("/getCloudStudyStudentOverView")
     @PreAuthorize("@pcs.hasPermissions('studentManage/getCloudStudyStudentOverView')")
     public HttpResponseResult<CloudStudyStudentDataDto> getCloudStudyStudentOverView(String organIds) throws Exception {
-        SysUser sysUser = sysUserFeignService.queryUserInfo();
-        if (sysUser == null) {
-            return failed("用户信息获取失败");
-        }
-        List<Integer> organIdsList = new ArrayList<>();
+        List<Integer> organIdsList;
         if(StringUtils.isNotBlank(organIds)){
             organIdsList = Arrays.stream(organIds.split(",")).map(id->Integer.valueOf(id)).collect(Collectors.toList());
         }else{
-            List<Organization> organizations = organizationService.queryEmployeeOrgan(sysUser.getId(),null);
+            List<Organization> organizations = organizationService.queryEmployeeOrgan();
             if(CollectionUtils.isEmpty(organizations)){
                 return succeed();
             }

+ 1 - 3
mec-web/src/main/java/com/ym/mec/web/controller/education/ActivityController.java

@@ -13,10 +13,8 @@ import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.util.date.DateUtil;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
@@ -244,7 +242,7 @@ public class ActivityController extends BaseController {
     @ApiOperation(value = "云教练活动统计")
     @GetMapping("/countCloudTeacherActive")
     public Object countCloudTeacherActive(CloudTeacherActiveQueryInfo queryInfo) throws Exception {
-        List<Organization> organizations = organizationService.queryEmployeeOrgan(null,null);
+        List<Organization> organizations = organizationService.queryEmployeeOrgan();
         List<Integer> organIds = new ArrayList<>();
         if(StringUtils.isNotBlank(queryInfo.getOrganIds())){
             organIds = Arrays.stream(queryInfo.getOrganIds().split(",")).map(id->Integer.valueOf(id)).collect(Collectors.toList());

+ 9 - 21
mec-web/src/main/java/com/ym/mec/web/controller/education/EduOrganizationController.java

@@ -1,23 +1,18 @@
 package com.ym.mec.web.controller.education;
 
+import com.ym.mec.biz.dal.entity.CooperationOrgan;
+import com.ym.mec.biz.service.CooperationOrganService;
+import com.ym.mec.biz.service.OrganizationService;
+import com.ym.mec.common.controller.BaseController;
+import com.ym.mec.common.entity.HttpResponseResult;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-
-import java.util.List;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import com.ym.mec.auth.api.client.SysUserFeignService;
-import com.ym.mec.auth.api.entity.SysUser;
-import com.ym.mec.biz.dal.entity.CooperationOrgan;
-import com.ym.mec.biz.service.CooperationOrganService;
-import com.ym.mec.biz.service.OrganizationService;
-import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.entity.HttpResponseResult;
-import com.ym.mec.common.exception.BizException;
+import java.util.List;
 
 @RequestMapping("eduOrganization")
 @Api(tags = "分部服务")
@@ -28,24 +23,17 @@ public class EduOrganizationController extends BaseController {
     private OrganizationService organizationService;
     @Autowired
     private CooperationOrganService cooperationOrganService;
-	@Autowired
-	private SysUserFeignService sysUserFeignService;
 
     @ApiOperation(value = "获取员工所在分部列表")
     @GetMapping("/queryAllOrgan")
-    public Object queryAllOrgan(String organId) throws Exception {
-        return succeed(organizationService.queryEmployeeOrgan(null,organId));
+    public Object queryAllOrgan() throws Exception {
+        return succeed(organizationService.queryEmployeeOrgan());
     }
 
     @ApiOperation(value = "获取员工所在分部列表")
     @GetMapping("/queryEmployeeOrgan")
     public Object queryEmployeeOrgan() throws Exception {
-		SysUser sysUser = sysUserFeignService.queryUserInfo();
-		if(sysUser == null){
-			throw new BizException("获取用户信息失败");
-		}
-		Integer userId = sysUser.getId();
-        return succeed(organizationService.queryEmployeeOrgan(userId,null));
+        return succeed(organizationService.queryEmployeeOrgan());
     }
 
     @ApiOperation(value = "根据分部id获取合作单位(学校)列表")

+ 1 - 13
mec-web/src/main/java/com/ym/mec/web/controller/education/EduStudentController.java

@@ -1,7 +1,5 @@
 package com.ym.mec.web.controller.education;
 
-import com.ym.mec.auth.api.client.SysUserFeignService;
-import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.EduOrganStudentDataDto;
 import com.ym.mec.biz.dal.dto.StatDto;
 import com.ym.mec.biz.dal.entity.Organization;
@@ -10,11 +8,8 @@ import com.ym.mec.biz.service.OrganizationService;
 import com.ym.mec.biz.service.StudentService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
-import com.ym.mec.common.exception.BizException;
-
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
-
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.CollectionUtils;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -38,8 +33,6 @@ public class EduStudentController extends BaseController {
     private StudentService studentService;
     @Autowired
     private OrganizationService organizationService;
-	@Autowired
-	private SysUserFeignService sysUserFeignService;
 
     @ApiOperation(value = "云教练学员数据")
     @GetMapping("/organStudentData")
@@ -50,12 +43,7 @@ public class EduStudentController extends BaseController {
     @ApiOperation(value = "分部云教练学员数据预览")
     @GetMapping("/organStudentOverView")
     public HttpResponseResult<List<EduOrganStudentDataDto>> organStudentOverView() throws Exception {
-		SysUser sysUser = sysUserFeignService.queryUserInfo();
-		if(sysUser == null){
-			throw new BizException("获取用户信息失败");
-		}
-		Integer userId = sysUser.getId();
-        List<Organization> organizations = organizationService.queryEmployeeOrgan(userId,null);
+        List<Organization> organizations = organizationService.queryEmployeeOrgan();
         if(CollectionUtils.isEmpty(organizations)){
             return succeed(Collections.emptyList());
         }