diff --git a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcomp/controller/AnnualCompController.java b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcomp/controller/AnnualCompController.java index 25e92d21..a2748084 100644 --- a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcomp/controller/AnnualCompController.java +++ b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcomp/controller/AnnualCompController.java @@ -21,6 +21,8 @@ import org.jeecg.modules.demo.annualcomp.service.IAnnualCompService; import org.jeecg.modules.demo.annualcomp.vo.AnnualCompVo; import org.jeecg.modules.demo.comp.entity.Comp; import org.jeecg.modules.demo.comp.service.ICompService; +import org.jeecg.modules.system.entity.SysRole; +import org.jeecg.modules.system.service.ISysUserRoleService; import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -30,9 +32,7 @@ import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.Arrays; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.stream.Collectors; /** @@ -53,6 +53,9 @@ public class AnnualCompController extends JeecgController roleList = iSysUserRoleService.getUserRoleByUserId(loginUser.getId()); + Map roleMap = Optional.ofNullable(roleList).orElse(new LinkedList<>()).stream().collect(Collectors.toMap(SysRole::getRoleCode, SysRole::getRoleCode)); + //角色名称 管理员&组委会可以看到所有,其它用户可见到所属自己数据 + Map efficientRoleMap = new LinkedHashMap<>(); + efficientRoleMap.put("admin", "admin"); + efficientRoleMap.put("committee", "committee"); + efficientRoleMap.put("superAdmin", "superAdmin"); String compname = annualComp.getCompname(); -// String compId = null; LambdaQueryWrapper queryWrapper1 = new LambdaQueryWrapper<>(); if (StringUtils.isNotBlank(compname)) { queryWrapper1.eq(Comp::getCompName, compname); } - if (StringUtils.equals("管理员", realname) || StringUtils.equals("教务处", realname)) { + if (efficientRoleMap.containsValue(roleMap.get("admin")) + ||efficientRoleMap.containsValue(roleMap.get("committee")) + ||efficientRoleMap.containsValue(roleMap.get("superAdmin"))) { } else { queryWrapper1.eq(Comp::getCompAdmin, loginUser.getUsername()); } diff --git a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcompaward/controller/AnnualCompAwardController.java b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcompaward/controller/AnnualCompAwardController.java index 0259f767..92120d2e 100644 --- a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcompaward/controller/AnnualCompAwardController.java +++ b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/annualcompaward/controller/AnnualCompAwardController.java @@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.subject.Subject; @@ -24,6 +23,8 @@ import org.jeecg.modules.demo.annualcompaward.entity.AnnualCompAward; import org.jeecg.modules.demo.annualcompaward.service.IAnnualCompAwardService; import org.jeecg.modules.demo.comp.entity.Comp; import org.jeecg.modules.demo.comp.service.ICompService; +import org.jeecg.modules.system.entity.SysRole; +import org.jeecg.modules.system.service.ISysUserRoleService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; @@ -57,6 +58,9 @@ public class AnnualCompAwardController extends JeecgController annualCompPointIds = new TreeSet<>(); + List roleList = iSysUserRoleService.getUserRoleByUserId(loginUser.getId()); + Map roleMap = Optional.ofNullable(roleList).orElse(new LinkedList<>()).stream().collect(Collectors.toMap(SysRole::getRoleCode, SysRole::getRoleCode)); + //角色编码 管理员&组委会&教务处 可以看到所有,其它用户可见到所属自己数据 + Map efficientRoleMap = new LinkedHashMap<>(); + efficientRoleMap.put("admin", "admin"); + efficientRoleMap.put("committee", "committee"); + efficientRoleMap.put("superAdmin", "superAdmin"); -// QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(annualCompAward, req.getParameterMap()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (StringUtils.equals("管理员", realname) || StringUtils.equals("教务处", realname)) { - } else { + Page page = new Page(pageNo, pageSize); + // 查询所属当前登录用户数据 + if (!efficientRoleMap.containsValue(roleMap.get("admin")) + && !efficientRoleMap.containsValue(roleMap.get("committee")) + && !efficientRoleMap.containsValue(roleMap.get("superAdmin"))) { List compList = iCompService.list(new LambdaQueryWrapper().eq(Comp::getCompAdmin, loginUser.getUsername())); - if (!ObjectUtils.isEmpty(compList)) { - Set compIds = compList.stream().map(c -> c.getId()).collect(Collectors.toSet()); - List annualCompList = annualCompService.list(new LambdaQueryWrapper().in(AnnualComp::getCompid, compIds)); - if (!ObjectUtils.isEmpty(annualCompList)) { - Set annualCompIds = annualCompList.stream().map(d -> d.getId()).collect(Collectors.toSet()); - List annualCompPointList = annualCompPointService.list(new LambdaQueryWrapper().in(AnnualCompPoint::getAnnualCompId, annualCompIds)); - if (!ObjectUtils.isEmpty(annualCompPointList)) { - annualCompPointIds = annualCompPointList.stream().map(e -> e.getId()).collect(Collectors.toSet()); - } + if (ObjectUtils.isEmpty(compList)) { + return Result.OK(page); + } + Set compIds = compList.stream().map(c -> c.getId()).collect(Collectors.toSet()); + List annualCompList = annualCompService.list(new LambdaQueryWrapper().in(AnnualComp::getCompid, compIds)); + if (!ObjectUtils.isEmpty(annualCompList)) { + Set annualCompIds = annualCompList.stream().map(d -> d.getId()).collect(Collectors.toSet()); + List annualCompPointList = annualCompPointService.list(new LambdaQueryWrapper().in(AnnualCompPoint::getAnnualCompId, annualCompIds)); + if (!ObjectUtils.isEmpty(annualCompPointList)) { + Set annualCompPointIds = annualCompPointList.stream().map(e -> e.getId()).collect(Collectors.toSet()); + queryWrapper.in(AnnualCompAward::getAnnucompid, annualCompPointIds); } } - queryWrapper.in(AnnualCompAward::getAnnucompid, annualCompPointIds); } - Page page = new Page(pageNo, pageSize); annualCompAwardService.page(page, queryWrapper); // Page page1 = new Page<>(); @@ -143,6 +153,7 @@ public class AnnualCompAwardController extends JeecgController { @Autowired private IAnnualCompService annualCompService; + @Autowired + private ISysUserRoleService iSysUserRoleService; + /** * 分页列表查询 * @@ -83,8 +85,16 @@ public class CompController extends JeecgController { // 获取当前登录用户 LoginUser loginUser = (LoginUser) subject.getPrincipal(); //角色名称 管理员&教务处可以查看所有 - String realname = loginUser.getRealname(); - if (StringUtils.equals("管理员", realname) || StringUtils.equals("教务处", realname)) { + List roleList = iSysUserRoleService.getUserRoleByUserId(loginUser.getId()); + Map roleMap = Optional.ofNullable(roleList).orElse(new LinkedList<>()).stream().collect(Collectors.toMap(SysRole::getRoleCode, SysRole::getRoleCode)); + //角色编码 管理员&组委会&教务处 可以看到所有,其它用户可见到所属自己数据 + Map efficientRoleMap = new LinkedHashMap<>(); + efficientRoleMap.put("admin", "admin"); + efficientRoleMap.put("committee", "committee"); + efficientRoleMap.put("superAdmin", "superAdmin"); + if (efficientRoleMap.containsValue(roleMap.get("admin")) + ||efficientRoleMap.containsValue(roleMap.get("committee")) + ||efficientRoleMap.containsValue(roleMap.get("superAdmin"))) { } else { comp.setCompAdmin(loginUser.getUsername()); } @@ -116,12 +126,12 @@ public class CompController extends JeecgController { * @return */ //@AutoLog(value = "比赛专家-分页列表查询") - @ApiOperation(value="比赛专家-分页列表查询", notes="比赛专家-分页列表查询") + @ApiOperation(value = "比赛专家-分页列表查询", notes = "比赛专家-分页列表查询") @GetMapping(value = "/listSTU") public Result> listSTU(Comp compExp, - @RequestParam(name="pageNo", defaultValue="1") Integer pageNo, - @RequestParam(name="pageSize", defaultValue="10") Integer pageSize, - HttpServletRequest req) { + @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, + @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, + HttpServletRequest req) { QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(compExp, req.getParameterMap()); Page page = new Page(pageNo, pageSize); IPage pageList = compService.page(page, queryWrapper); @@ -180,7 +190,7 @@ public class CompController extends JeecgController { comp.setCompAdmin(join);*/ //现业务只有一个有效负责人,值为 sys_user表username modify by zhc 11.21 - if(!ObjectUtils.isEmpty(list)){ + if (!ObjectUtils.isEmpty(list)) { comp.setCompAdmin(list.get(0)); } diff --git a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/compskill/controller/CompskillController.java b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/compskill/controller/CompskillController.java index 462aeb16..c9258dac 100644 --- a/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/compskill/controller/CompskillController.java +++ b/jeecg-boot-master/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/compskill/controller/CompskillController.java @@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang.StringUtils; import org.apache.shiro.SecurityUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.subject.Subject; @@ -27,6 +26,8 @@ import org.jeecg.modules.demo.comp.service.ICompService; import org.jeecg.modules.demo.compskill.entity.Compskill; import org.jeecg.modules.demo.compskill.entity.Compskillvo; import org.jeecg.modules.demo.compskill.service.ICompskillService; +import org.jeecg.modules.system.entity.SysRole; +import org.jeecg.modules.system.service.ISysUserRoleService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.ObjectUtils; @@ -35,10 +36,7 @@ import org.springframework.web.servlet.ModelAndView; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import java.util.stream.Collectors; /** @@ -66,6 +64,9 @@ public class CompskillController extends JeecgController roleList = iSysUserRoleService.getUserRoleByUserId(loginUser.getId()); + Map roleMap = Optional.ofNullable(roleList).orElse(new LinkedList<>()).stream().collect(Collectors.toMap(SysRole::getRoleCode, SysRole::getRoleCode)); + //角色编码 管理员&组委会&教务处 可以看到所有,其它用户可见到所属自己数据 + Map efficientRoleMap = new LinkedHashMap<>(); + efficientRoleMap.put("admin", "admin"); + efficientRoleMap.put("committee", "committee"); + efficientRoleMap.put("superAdmin", "superAdmin"); - Set annualCompPointIds = new TreeSet<>(); -// QueryWrapper queryWrapper = QueryGenerator.initQueryWrapper(compskill, req.getParameterMap()); LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); - if (StringUtils.equals("管理员", realname) || StringUtils.equals("教务处", realname)) { - } else { + // 查询所属当前登录用户数据 + if (!efficientRoleMap.containsValue(roleMap.get("admin")) + && !efficientRoleMap.containsValue(roleMap.get("committee")) + && !efficientRoleMap.containsValue(roleMap.get("superAdmin"))) { List compList = iCompService.list(new LambdaQueryWrapper().eq(Comp::getCompAdmin, loginUser.getUsername())); if (!ObjectUtils.isEmpty(compList)) { Set compIds = compList.stream().map(c -> c.getId()).collect(Collectors.toSet()); @@ -103,11 +109,11 @@ public class CompskillController extends JeecgController annualCompIds = annualCompList.stream().map(d -> d.getId()).collect(Collectors.toSet()); List annualCompPointList = annualCompPointService.list(new LambdaQueryWrapper().in(AnnualCompPoint::getAnnualCompId, annualCompIds)); if (!ObjectUtils.isEmpty(annualCompPointList)) { - annualCompPointIds = annualCompPointList.stream().map(e -> e.getId()).collect(Collectors.toSet()); + Set annualCompPointIds = annualCompPointList.stream().map(e -> e.getId()).collect(Collectors.toSet()); + queryWrapper.in(Compskill::getAnnucompid, annualCompPointIds); } } } - queryWrapper.in(Compskill::getAnnucompid, annualCompPointIds); } diff --git a/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysUserRoleService.java b/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysUserRoleService.java index e031449c..ab23dde9 100644 --- a/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysUserRoleService.java +++ b/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/ISysUserRoleService.java @@ -1,7 +1,11 @@ package org.jeecg.modules.system.service; +import java.util.ArrayList; +import java.util.List; import java.util.Map; +import org.jeecg.modules.system.entity.SysRole; +import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUserRole; import com.baomidou.mybatisplus.extension.service.IService; @@ -15,4 +19,6 @@ import com.baomidou.mybatisplus.extension.service.IService; * @since 2018-12-21 */ public interface ISysUserRoleService extends IService { + + List getUserRoleByUserId(String userId); } diff --git a/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserRoleServiceImpl.java b/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserRoleServiceImpl.java index 9af6f772..5dfc90d1 100644 --- a/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserRoleServiceImpl.java +++ b/jeecg-boot-master/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysUserRoleServiceImpl.java @@ -1,20 +1,18 @@ package org.jeecg.modules.system.service.impl; -import java.util.IdentityHashMap; -import java.util.List; -import java.util.Map; - +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.jeecg.modules.system.entity.SysRole; -import org.jeecg.modules.system.entity.SysUser; import org.jeecg.modules.system.entity.SysUserRole; import org.jeecg.modules.system.mapper.SysUserRoleMapper; import org.jeecg.modules.system.service.ISysRoleService; import org.jeecg.modules.system.service.ISysUserRoleService; -import org.jeecg.modules.system.service.ISysUserService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.ObjectUtils; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import java.util.LinkedList; +import java.util.List; /** *

@@ -27,4 +25,26 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @Service public class SysUserRoleServiceImpl extends ServiceImpl implements ISysUserRoleService { + @Autowired + private ISysRoleService sysRoleService; + + /** + * @description: 根据用户id, 获取用户角色 + * @param: [userId] + * @return: java.util.List + * @author: z.h.c + * @date: 23/12/19 15:36 + */ + @Override + public List getUserRoleByUserId(String userId) { + List sysRoleList = new LinkedList<>(); + List userRoleList = this.list(new LambdaQueryWrapper().eq(SysUserRole::getUserId, userId)); + for (SysUserRole sysUserRole : userRoleList) { + SysRole sysRole = sysRoleService.getById(sysUserRole.getRoleId()); + if (!ObjectUtils.isEmpty(sysRole)) { + sysRoleList.add(sysRole); + } + } + return sysRoleList; + } } diff --git a/jeecgboot-vue3-master/src/views/annualcompetitionprojectregistration/student/AnnualCompetitionProjectRegistrationList.vue b/jeecgboot-vue3-master/src/views/annualcompetitionprojectregistration/student/AnnualCompetitionProjectRegistrationList.vue index a232948d..9a7eb784 100644 --- a/jeecgboot-vue3-master/src/views/annualcompetitionprojectregistration/student/AnnualCompetitionProjectRegistrationList.vue +++ b/jeecgboot-vue3-master/src/views/annualcompetitionprojectregistration/student/AnnualCompetitionProjectRegistrationList.vue @@ -6,9 +6,9 @@