From 24e84dca4ffd61cc92338263c3825e0944542f2e Mon Sep 17 00:00:00 2001 From: xin <1099200748@qq.com> Date: Fri, 06 Jun 2025 19:28:10 +0800 Subject: [PATCH] 删除用户机构 --- oying-common/src/main/java/com/oying/utils/CacheKey.java | 5 - oying-system/src/main/java/com/oying/modules/system/service/impl/UserServiceImpl.java | 36 ++---- oying-system/src/main/java/com/oying/modules/system/service/DataService.java | 2 oying-system/src/main/java/com/oying/modules/system/service/impl/RoleServiceImpl.java | 8 - oying-system/src/main/java/com/oying/modules/system/rest/UserController.java | 44 +------- oying-system/src/main/java/com/oying/modules/security/service/OnlineUserService.java | 4 oying-system/src/main/java/com/oying/modules/system/domain/Role.java | 4 /dev/null | 70 -------------- oying-system/src/main/java/com/oying/modules/security/service/UserDetailsServiceImpl.java | 2 oying-system/src/main/java/com/oying/modules/security/service/dto/OnlineUserDto.java | 3 oying-system/src/main/java/com/oying/modules/system/domain/User.java | 8 - oying-system/src/main/java/com/oying/modules/system/domain/dto/UserQueryCriteria.java | 8 - oying-system/src/main/resources/mapper/system/RoleDeptMapper.xml | 2 oying-system/src/main/java/com/oying/modules/system/service/impl/DataServiceImpl.java | 27 +--- oying-system/src/main/java/com/oying/modules/system/mapper/RoleMapper.java | 3 oying-system/src/main/resources/mapper/system/RoleMapper.xml | 23 ---- oying-system/src/main/java/com/oying/modules/system/mapper/UserMapper.java | 4 oying-system/src/main/java/com/oying/modules/system/mapper/RoleDeptMapper.java | 3 oying-system/src/main/resources/mapper/system/UserMapper.xml | 33 ------ 19 files changed, 38 insertions(+), 251 deletions(-) diff --git a/oying-common/src/main/java/com/oying/utils/CacheKey.java b/oying-common/src/main/java/com/oying/utils/CacheKey.java index 935c73a..f90a1b1 100644 --- a/oying-common/src/main/java/com/oying/utils/CacheKey.java +++ b/oying-common/src/main/java/com/oying/utils/CacheKey.java @@ -35,11 +35,6 @@ String ROLE_ID = "role::id:"; /** - * 机构 - */ - String DEPT_ID = "dept::id:"; - - /** * 岗位 */ String JOB_ID = "job::id:"; diff --git a/oying-system/src/main/java/com/oying/modules/security/service/OnlineUserService.java b/oying-system/src/main/java/com/oying/modules/security/service/OnlineUserService.java index 0945d3f..cef08a7 100644 --- a/oying-system/src/main/java/com/oying/modules/security/service/OnlineUserService.java +++ b/oying-system/src/main/java/com/oying/modules/security/service/OnlineUserService.java @@ -35,14 +35,13 @@ * @param request / */ public void save(JwtUserDto jwtUserDto, String token, HttpServletRequest request){ - String dept = jwtUserDto.getUser().getDept().getName(); String ip = StringUtils.getIp(request); String id = tokenProvider.getId(token); String browser = StringUtils.getBrowser(request); String address = StringUtils.getCityInfo(ip); OnlineUserDto onlineUserDto = null; try { - onlineUserDto = new OnlineUserDto(id, jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date()); + onlineUserDto = new OnlineUserDto(id, jwtUserDto.getUsername(), jwtUserDto.getUser().getNickName(), browser , ip, address, EncryptUtils.desEncrypt(token), new Date()); } catch (Exception e) { log.error(e.getMessage(),e); } @@ -103,7 +102,6 @@ for (OnlineUserDto user : all) { Map<String,Object> map = new LinkedHashMap<>(); map.put("用户名", user.getUserName()); - map.put("机构", user.getDept()); map.put("登录IP", user.getIp()); map.put("登录地点", user.getAddress()); map.put("浏览器", user.getBrowser()); diff --git a/oying-system/src/main/java/com/oying/modules/security/service/UserDetailsServiceImpl.java b/oying-system/src/main/java/com/oying/modules/security/service/UserDetailsServiceImpl.java index a9da4b2..e90f918 100644 --- a/oying-system/src/main/java/com/oying/modules/security/service/UserDetailsServiceImpl.java +++ b/oying-system/src/main/java/com/oying/modules/security/service/UserDetailsServiceImpl.java @@ -40,7 +40,7 @@ // 获取用户的权限 List<AuthorityDto> authorities = roleService.buildPermissions(user); // 初始化JwtUserDto - jwtUserDto = new JwtUserDto(user, dataService.getDeptIds(user), authorities); + jwtUserDto = new JwtUserDto(user, dataService.getDataIds(user), authorities); // 添加缓存数据 userCacheManager.addUserCache(username, jwtUserDto); } diff --git a/oying-system/src/main/java/com/oying/modules/security/service/dto/OnlineUserDto.java b/oying-system/src/main/java/com/oying/modules/security/service/dto/OnlineUserDto.java index 8a0bdb6..085b0d7 100644 --- a/oying-system/src/main/java/com/oying/modules/security/service/dto/OnlineUserDto.java +++ b/oying-system/src/main/java/com/oying/modules/security/service/dto/OnlineUserDto.java @@ -24,9 +24,6 @@ @ApiModelProperty(value = "昵称") private String nickName; - @ApiModelProperty(value = "岗位") - private String dept; - @ApiModelProperty(value = "浏览器") private String browser; diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/Dept.java b/oying-system/src/main/java/com/oying/modules/system/domain/Dept.java deleted file mode 100644 index 8b3a571..0000000 --- a/oying-system/src/main/java/com/oying/modules/system/domain/Dept.java +++ /dev/null @@ -1,92 +0,0 @@ -package com.oying.modules.system.domain; - -import com.alibaba.fastjson2.annotation.JSONField; -import com.baomidou.mybatisplus.annotation.IdType; -import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; -import com.baomidou.mybatisplus.annotation.TableName; -import io.swagger.annotations.ApiModelProperty; -import lombok.Getter; -import lombok.Setter; -import com.oying.base.BaseEntity; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.List; -import java.util.Objects; -import java.util.Set; - -/** -* @author Z -* @date 2019-03-25 -*/ -@Getter -@Setter -@TableName("sys_dept") -public class Dept extends BaseEntity implements Serializable { - - @NotNull(groups = Update.class) - @TableId(value="dept_id", type = IdType.AUTO) - @ApiModelProperty(value = "ID", hidden = true) - private Long id; - - @TableField(exist = false) - @JSONField(serialize = false) - @ApiModelProperty(value = "角色") - private Set<Role> roles; - - @TableField(exist = false) - @ApiModelProperty(value = "子机构") - private List<Dept> children; - - @ApiModelProperty(value = "排序") - private Integer deptSort; - - @NotBlank - @ApiModelProperty(value = "机构名称") - private String name; - - @NotNull - @ApiModelProperty(value = "是否启用") - private Boolean enabled; - - @ApiModelProperty(value = "上级机构") - private Long pid; - - @ApiModelProperty(value = "子节点数目", hidden = true) - private Integer subCount = 0; - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - Dept dept = (Dept) o; - return Objects.equals(id, dept.id) && - Objects.equals(name, dept.name); - } - - @Override - public int hashCode() { - return Objects.hash(id, name); - } - - @ApiModelProperty(value = "是否有子节点") - public Boolean getHasChildren() { - return subCount > 0; - } - - - @ApiModelProperty(value = "是否为叶子") - public Boolean getLeaf() { - return subCount <= 0; - } - - @ApiModelProperty(value = "标签名称") - public String getLabel() { - return name; - } -} diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/Role.java b/oying-system/src/main/java/com/oying/modules/system/domain/Role.java index 0071841..0bc9996 100644 --- a/oying-system/src/main/java/com/oying/modules/system/domain/Role.java +++ b/oying-system/src/main/java/com/oying/modules/system/domain/Role.java @@ -38,10 +38,6 @@ @ApiModelProperty(value = "菜单", hidden = true) private Set<Menu> menus; - @TableField(exist = false) - @ApiModelProperty(value = "机构", hidden = true) - private Set<Dept> depts; - @NotBlank @ApiModelProperty(value = "名称", hidden = true) private String name; diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/User.java b/oying-system/src/main/java/com/oying/modules/system/domain/User.java index 17f7b64..486110e 100644 --- a/oying-system/src/main/java/com/oying/modules/system/domain/User.java +++ b/oying-system/src/main/java/com/oying/modules/system/domain/User.java @@ -39,14 +39,6 @@ @ApiModelProperty(value = "用户岗位") private Set<Job> jobs; - @TableField(value = "dept_id") - @ApiModelProperty(hidden = true) - private Long deptId; - - @ApiModelProperty(value = "用户机构") - @TableField(exist = false) - private Dept dept; - @NotBlank @ApiModelProperty(value = "用户类型(BUYER、MERCHANT、RIDER、ADMIN、SUPPLIER、AGENT)") private String userType; diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/dto/DeptQueryCriteria.java b/oying-system/src/main/java/com/oying/modules/system/domain/dto/DeptQueryCriteria.java deleted file mode 100644 index 2266571..0000000 --- a/oying-system/src/main/java/com/oying/modules/system/domain/dto/DeptQueryCriteria.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.oying.modules.system.domain.dto; - -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import java.sql.Timestamp; -import java.util.List; - -/** -* @author Z -* @date 2019-03-25 -*/ -@Data -public class DeptQueryCriteria{ - - @ApiModelProperty(value = "机构id集合") - private List<Long> ids; - - @ApiModelProperty(value = "机构名称") - private String name; - - @ApiModelProperty(value = "是否启用") - private Boolean enabled; - - @ApiModelProperty(value = "上级机构") - private Long pid; - - @ApiModelProperty(value = "PID为空查询") - private Boolean pidIsNull; - - @ApiModelProperty(value = "创建时间") - private List<Timestamp> createTime; -} diff --git a/oying-system/src/main/java/com/oying/modules/system/domain/dto/UserQueryCriteria.java b/oying-system/src/main/java/com/oying/modules/system/domain/dto/UserQueryCriteria.java index 81b91f4..b8f13d5 100644 --- a/oying-system/src/main/java/com/oying/modules/system/domain/dto/UserQueryCriteria.java +++ b/oying-system/src/main/java/com/oying/modules/system/domain/dto/UserQueryCriteria.java @@ -4,9 +4,7 @@ import lombok.Data; import java.io.Serializable; import java.sql.Timestamp; -import java.util.HashSet; import java.util.List; -import java.util.Set; /** * @author Z @@ -18,17 +16,11 @@ @ApiModelProperty(value = "ID") private Long id; - @ApiModelProperty(value = "多个ID") - private Set<Long> deptIds = new HashSet<>(); - @ApiModelProperty(value = "模糊查询") private String blurry; @ApiModelProperty(value = "是否启用") private Boolean enabled; - - @ApiModelProperty(value = "机构ID") - private Long deptId; @ApiModelProperty(value = "创建时间") private List<Timestamp> createTime; diff --git a/oying-system/src/main/java/com/oying/modules/system/mapper/DeptMapper.java b/oying-system/src/main/java/com/oying/modules/system/mapper/DeptMapper.java deleted file mode 100644 index fa57430..0000000 --- a/oying-system/src/main/java/com/oying/modules/system/mapper/DeptMapper.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.oying.modules.system.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.oying.modules.system.domain.Dept; -import com.oying.modules.system.domain.dto.DeptQueryCriteria; -import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; -import java.util.List; -import java.util.Set; - -/** -* @author Z -* @date 2023-06-20 -*/ -@Mapper -public interface DeptMapper extends BaseMapper<Dept> { - - List<Dept> findAll(@Param("criteria") DeptQueryCriteria criteria); - - List<Dept> findByPid(@Param("pid") Long pid); - - List<Dept> findByPidIsNull(); - - Set<Dept> findByRoleId(@Param("roleId") Long roleId); - - @Select("select count(*) from sys_dept where pid = #{pid}") - int countByPid(@Param("pid") Long pid); - - @Select("update sys_dept set sub_count = #{count} where dept_id = #{id}") - void updateSubCntById(@Param("count") Integer count, @Param("id") Long id); -} diff --git a/oying-system/src/main/java/com/oying/modules/system/mapper/RoleDeptMapper.java b/oying-system/src/main/java/com/oying/modules/system/mapper/RoleDeptMapper.java index a8200ad..6fb8cfe 100644 --- a/oying-system/src/main/java/com/oying/modules/system/mapper/RoleDeptMapper.java +++ b/oying-system/src/main/java/com/oying/modules/system/mapper/RoleDeptMapper.java @@ -1,6 +1,5 @@ package com.oying.modules.system.mapper; -import com.oying.modules.system.domain.Dept; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.util.Set; @@ -11,7 +10,7 @@ */ @Mapper public interface RoleDeptMapper { - void insertData(@Param("roleId") Long roleId, @Param("depts") Set<Dept> depts); + void insertData(@Param("roleId") Long roleId, @Param("ids") Set<Long> ids); void deleteByRoleId(@Param("roleId") Long roleId); diff --git a/oying-system/src/main/java/com/oying/modules/system/mapper/RoleMapper.java b/oying-system/src/main/java/com/oying/modules/system/mapper/RoleMapper.java index ba5455f..a44beed 100644 --- a/oying-system/src/main/java/com/oying/modules/system/mapper/RoleMapper.java +++ b/oying-system/src/main/java/com/oying/modules/system/mapper/RoleMapper.java @@ -7,7 +7,6 @@ import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.List; -import java.util.Set; /** * @author Z @@ -27,8 +26,6 @@ Role findByName(@Param("name") String name); List<Role> findByUserId(@Param("userId") Long userId); - - int countByDepts(@Param("deptIds") Set<Long> deptIds); @Select("SELECT role.role_id as id FROM sys_role role, sys_roles_menus rm " + "WHERE role.role_id = rm.role_id AND rm.menu_id = #{menuId}") diff --git a/oying-system/src/main/java/com/oying/modules/system/mapper/UserMapper.java b/oying-system/src/main/java/com/oying/modules/system/mapper/UserMapper.java index 4598cee..928ffcc 100644 --- a/oying-system/src/main/java/com/oying/modules/system/mapper/UserMapper.java +++ b/oying-system/src/main/java/com/oying/modules/system/mapper/UserMapper.java @@ -41,13 +41,9 @@ List<User> findByRoleId(@Param("roleId") Long roleId); - List<User> findByRoleDeptId(@Param("deptId") Long deptId); - List<User> findByMenuId(@Param("menuId") Long menuId); int countByJobs(@Param("jobIds") Set<Long> jobIds); - - int countByDepts(@Param("deptIds") Set<Long> deptIds); int countByRoles(@Param("roleIds") Set<Long> roleIds); diff --git a/oying-system/src/main/java/com/oying/modules/system/rest/DeptController.java b/oying-system/src/main/java/com/oying/modules/system/rest/DeptController.java deleted file mode 100644 index 68314fd..0000000 --- a/oying-system/src/main/java/com/oying/modules/system/rest/DeptController.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.oying.modules.system.rest; - -import cn.hutool.core.collection.CollectionUtil; -import com.oying.modules.system.domain.Dept; -import com.oying.modules.system.domain.dto.DeptQueryCriteria; -import com.oying.utils.R; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.RequiredArgsConstructor; -import com.oying.annotation.Log; -import com.oying.exception.BadRequestException; -import com.oying.modules.system.service.DeptService; -import com.oying.utils.PageResult; -import com.oying.utils.PageUtil; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.security.access.prepost.PreAuthorize; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletResponse; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @author Z - * @date 2019-03-25 - */ -@RestController -@RequiredArgsConstructor -@Api(tags = "系统:机构管理") -@RequestMapping("/api/dept") -public class DeptController { - - private final DeptService deptService; - private static final String ENTITY_NAME = "dept"; - - @ApiOperation("导出机构数据") - @GetMapping(value = "/download") - @PreAuthorize("@el.check('dept:list')") - public void exportDept(HttpServletResponse response, DeptQueryCriteria criteria) throws Exception { - deptService.download(deptService.queryAll(criteria, false), response); - } - - @ApiOperation("查询机构") - @GetMapping - @PreAuthorize("@el.check('user:list','dept:list')") - public ResponseEntity<Object> queryDept(DeptQueryCriteria criteria) throws Exception { - List<Dept> depts = deptService.queryAll(criteria, true); - return new ResponseEntity<>(R.success(PageUtil.toPage(depts)), HttpStatus.OK); - } - - @ApiOperation("查询机构:根据ID获取同级与上级数据") - @PostMapping("/superior") - @PreAuthorize("@el.check('user:list','dept:list')") - public ResponseEntity<Object> getDeptSuperior(@RequestBody List<Long> ids, @RequestParam(defaultValue = "false") Boolean exclude) { - Set<Dept> deptSet = new LinkedHashSet<>(); - for (Long id : ids) { - Dept dept = deptService.findById(id); - List<Dept> depts = deptService.getSuperior(dept, new ArrayList<>()); - if (exclude) { - for (Dept data : depts) { - if (data.getId().equals(dept.getPid())) { - data.setSubCount(data.getSubCount() - 1); - } - } - // 编辑机构时不显示自己以及自己下级的数据,避免出现PID数据环形问题 - depts = depts.stream().filter(i -> !ids.contains(i.getId())).collect(Collectors.toList()); - } - deptSet.addAll(depts); - } - return new ResponseEntity<>(R.success(deptService.buildTree(new ArrayList<>(deptSet))), HttpStatus.OK); - } - - @Log("新增机构") - @ApiOperation("新增机构") - @PostMapping - @PreAuthorize("@el.check('dept:add')") - public ResponseEntity<Object> createDept(@Validated @RequestBody Dept resources) { - if (resources.getId() != null) { - throw new BadRequestException("A new " + ENTITY_NAME + " cannot already have an ID"); - } - deptService.create(resources); - return new ResponseEntity<>(R.success(), HttpStatus.CREATED); - } - - @Log("修改机构") - @ApiOperation("修改机构") - @PutMapping - @PreAuthorize("@el.check('dept:edit')") - public ResponseEntity<Object> updateDept(@Validated(Dept.Update.class) @RequestBody Dept resources) { - deptService.update(resources); - return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT); - } - - @Log("删除机构") - @ApiOperation("删除机构") - @DeleteMapping - @PreAuthorize("@el.check('dept:del')") - public ResponseEntity<Object> deleteDept(@RequestBody Set<Long> ids) { - Set<Dept> depts = new HashSet<>(); - for (Long id : ids) { - List<Dept> deptList = deptService.findByPid(id); - depts.add(deptService.findById(id)); - if (CollectionUtil.isNotEmpty(deptList)) { - depts = deptService.getDeleteDepts(deptList, depts); - } - } - // 验证是否被角色或用户关联 - deptService.verification(depts); - deptService.delete(depts); - return new ResponseEntity<>(R.success(),HttpStatus.OK); - } -} diff --git a/oying-system/src/main/java/com/oying/modules/system/rest/UserController.java b/oying-system/src/main/java/com/oying/modules/system/rest/UserController.java index 29c06fe..21c859d 100644 --- a/oying-system/src/main/java/com/oying/modules/system/rest/UserController.java +++ b/oying-system/src/main/java/com/oying/modules/system/rest/UserController.java @@ -1,8 +1,6 @@ package com.oying.modules.system.rest; -import cn.hutool.core.collection.CollectionUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.oying.modules.system.domain.Dept; import com.oying.modules.system.domain.Role; import com.oying.modules.system.domain.User; import com.oying.modules.system.domain.dto.UserPassVo; @@ -12,9 +10,7 @@ import lombok.RequiredArgsConstructor; import com.oying.annotation.Log; import com.oying.config.properties.RsaProperties; -import com.oying.modules.system.service.DataService; import com.oying.exception.BadRequestException; -import com.oying.modules.system.service.DeptService; import com.oying.modules.system.service.RoleService; import com.oying.modules.system.domain.dto.UserQueryCriteria; import com.oying.modules.system.service.VerifyService; @@ -24,8 +20,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.crypto.password.PasswordEncoder; -import org.springframework.util.CollectionUtils; -import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -47,8 +41,6 @@ private final PasswordEncoder passwordEncoder; private final UserService userService; - private final DataService dataService; - private final DeptService deptService; private final RoleService roleService; private final VerifyService verificationCodeService; @@ -64,28 +56,8 @@ @PreAuthorize("@el.check('user:list')") public ResponseEntity<Object> queryUser(UserQueryCriteria criteria) { Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize()); - if (!ObjectUtils.isEmpty(criteria.getDeptId())) { - criteria.getDeptIds().add(criteria.getDeptId()); - // 先查找是否存在子节点 - List<Dept> data = deptService.findByPid(criteria.getDeptId()); - // 然后把子节点的ID都加入到集合中 - criteria.getDeptIds().addAll(deptService.getDeptChildren(data)); - } // 数据权限 - List<Long> dataScopes = dataService.getDeptIds(userService.findByName(SecurityUtils.getCurrentUsername())); - // criteria.getDeptIds() 不为空并且数据权限不为空则取交集 - if (!CollectionUtils.isEmpty(criteria.getDeptIds()) && !CollectionUtils.isEmpty(dataScopes)) { - // 取交集 - criteria.getDeptIds().retainAll(dataScopes); - if (!CollectionUtil.isEmpty(criteria.getDeptIds())) { - return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); - } - } else { - // 否则取并集 - criteria.getDeptIds().addAll(dataScopes); - return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); - } - return new ResponseEntity<>(R.success(), HttpStatus.OK); + return new ResponseEntity<>(R.success(userService.queryAll(criteria, page)), HttpStatus.OK); } @Log("新增用户") @@ -97,7 +69,7 @@ // 默认密码 123456 resources.setPassword(passwordEncoder.encode("123456")); userService.create(resources); - return new ResponseEntity<>(R.success(),HttpStatus.CREATED); + return new ResponseEntity<>(R.success(), HttpStatus.CREATED); } @Log("修改用户") @@ -107,7 +79,7 @@ public ResponseEntity<Object> updateUser(@Validated(User.Update.class) @RequestBody User resources) throws Exception { checkLevel(resources); userService.update(resources); - return new ResponseEntity<>(R.success(),HttpStatus.NO_CONTENT); + return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT); } @Log("修改用户:个人中心") @@ -118,7 +90,7 @@ throw new BadRequestException("不能修改他人资料"); } userService.updateCenter(resources); - return new ResponseEntity<>(R.success(),HttpStatus.NO_CONTENT); + return new ResponseEntity<>(R.success(), HttpStatus.NO_CONTENT); } @Log("删除用户") @@ -134,7 +106,7 @@ } } userService.delete(ids); - return new ResponseEntity<>(R.success(),HttpStatus.OK); + return new ResponseEntity<>(R.success(), HttpStatus.OK); } @ApiOperation("修改密码") @@ -150,7 +122,7 @@ throw new BadRequestException("新密码不能与旧密码相同"); } userService.updatePass(user.getUsername(), passwordEncoder.encode(newPass)); - return new ResponseEntity<>(R.success(),HttpStatus.OK); + return new ResponseEntity<>(R.success(), HttpStatus.OK); } @ApiOperation("重置密码") @@ -158,7 +130,7 @@ public ResponseEntity<Object> resetPwd(@RequestBody Set<Long> ids) { String pwd = passwordEncoder.encode("123456"); userService.resetPwd(ids, pwd); - return new ResponseEntity<>(R.success(),HttpStatus.OK); + return new ResponseEntity<>(R.success(), HttpStatus.OK); } @ApiOperation("修改头像") @@ -178,7 +150,7 @@ } verificationCodeService.validated(CodeEnum.EMAIL_RESET_EMAIL_CODE.getKey() + resources.getEmail(), code); userService.updateEmail(user.getUsername(), resources.getEmail()); - return new ResponseEntity<>(R.success(),HttpStatus.OK); + return new ResponseEntity<>(R.success(), HttpStatus.OK); } /** diff --git a/oying-system/src/main/java/com/oying/modules/system/service/DataService.java b/oying-system/src/main/java/com/oying/modules/system/service/DataService.java index bd538bd..fc7b75d 100644 --- a/oying-system/src/main/java/com/oying/modules/system/service/DataService.java +++ b/oying-system/src/main/java/com/oying/modules/system/service/DataService.java @@ -16,5 +16,5 @@ * @param user / * @return / */ - List<Long> getDeptIds(User user); + List<Long> getDataIds(User user); } diff --git a/oying-system/src/main/java/com/oying/modules/system/service/DeptService.java b/oying-system/src/main/java/com/oying/modules/system/service/DeptService.java deleted file mode 100644 index 10c8c25..0000000 --- a/oying-system/src/main/java/com/oying/modules/system/service/DeptService.java +++ /dev/null @@ -1,110 +0,0 @@ -package com.oying.modules.system.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.oying.modules.system.domain.Dept; -import com.oying.modules.system.domain.dto.DeptQueryCriteria; - -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.List; -import java.util.Set; - -/** -* @author Z -* @date 2019-03-25 -*/ -public interface DeptService extends IService<Dept> { - - /** - * 查询所有数据 - * @param criteria 条件 - * @param isQuery / - * @throws Exception / - * @return / - */ - List<Dept> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception; - - /** - * 根据ID查询 - * @param id / - * @return / - */ - Dept findById(Long id); - - /** - * 创建 - * @param resources / - */ - void create(Dept resources); - - /** - * 编辑 - * @param resources / - */ - void update(Dept resources); - - /** - * 删除 - * @param depts / - * - */ - void delete(Set<Dept> depts); - - /** - * 根据PID查询 - * @param pid / - * @return / - */ - List<Dept> findByPid(long pid); - - /** - * 根据角色ID查询 - * @param id / - * @return / - */ - Set<Dept> findByRoleId(Long id); - - /** - * 导出数据 - * @param depts 待导出的数据 - * @param response / - * @throws IOException / - */ - void download(List<Dept> depts, HttpServletResponse response) throws IOException; - - /** - * 获取待删除的机构 - * @param deptList / - * @param depts / - * @return / - */ - Set<Dept> getDeleteDepts(List<Dept> deptList, Set<Dept> depts); - - /** - * 根据ID获取同级与上级数据 - * @param dept / - * @param depts / - * @return / - */ - List<Dept> getSuperior(Dept dept, List<Dept> depts); - - /** - * 构建树形数据 - * @param depts / - * @return / - */ - Object buildTree(List<Dept> depts); - - /** - * 获取 - * @param deptList 、 - * @return 、 - */ - List<Long> getDeptChildren(List<Dept> deptList); - - /** - * 验证是否被角色或用户关联 - * @param depts / - */ - void verification(Set<Dept> depts); -} diff --git a/oying-system/src/main/java/com/oying/modules/system/service/impl/DataServiceImpl.java b/oying-system/src/main/java/com/oying/modules/system/service/impl/DataServiceImpl.java index 7242f12..97caf87 100644 --- a/oying-system/src/main/java/com/oying/modules/system/service/impl/DataServiceImpl.java +++ b/oying-system/src/main/java/com/oying/modules/system/service/impl/DataServiceImpl.java @@ -1,12 +1,10 @@ package com.oying.modules.system.service.impl; import cn.hutool.core.collection.CollUtil; -import com.oying.modules.system.domain.Dept; import com.oying.modules.system.domain.Role; import com.oying.modules.system.domain.User; import lombok.RequiredArgsConstructor; import com.oying.modules.system.service.DataService; -import com.oying.modules.system.service.DeptService; import com.oying.modules.system.service.RoleService; import com.oying.utils.CacheKey; import com.oying.utils.RedisUtils; @@ -26,7 +24,6 @@ private final RedisUtils redisUtils; private final RoleService roleService; - private final DeptService deptService; /** * 用户角色和用户机构改变时需清理缓存 @@ -34,11 +31,11 @@ * @return / */ @Override - public List<Long> getDeptIds(User user) { + public List<Long> getDataIds(User user) { String key = CacheKey.DATA_USER + user.getId(); List<Long> ids = redisUtils.getList(key, Long.class); if (CollUtil.isEmpty(ids)) { - Set<Long> deptIds = new HashSet<>(); + Set<Long> dataIds = new HashSet<>(); // 查询用户角色 List<Role> roleList = roleService.findByUsersId(user.getId()); // 获取对应的机构ID @@ -46,16 +43,15 @@ DataScopeEnum dataScopeEnum = DataScopeEnum.find(role.getDataScope()); switch (Objects.requireNonNull(dataScopeEnum)) { case THIS_LEVEL: - deptIds.add(user.getDept().getId()); break; case CUSTOMIZE: - deptIds.addAll(getCustomize(deptIds, role)); + dataIds.addAll(getCustomize(dataIds, role)); break; default: return new ArrayList<>(); } } - ids = new ArrayList<>(deptIds); + ids = new ArrayList<>(dataIds); redisUtils.set(key, ids, 1, TimeUnit.DAYS); } return ids; @@ -63,19 +59,12 @@ /** * 获取自定义的数据权限 - * @param deptIds 机构ID + * @param dataIds 机构ID * @param role 角色 * @return 数据权限ID */ - public Set<Long> getCustomize(Set<Long> deptIds, Role role){ - Set<Dept> depts = deptService.findByRoleId(role.getId()); - for (Dept dept : depts) { - deptIds.add(dept.getId()); - List<Dept> deptChildren = deptService.findByPid(dept.getId()); - if (CollUtil.isNotEmpty(deptChildren)) { - deptIds.addAll(deptService.getDeptChildren(deptChildren)); - } - } - return deptIds; + public Set<Long> getCustomize(Set<Long> dataIds, Role role){ + System.out.println(role); + return dataIds; } } diff --git a/oying-system/src/main/java/com/oying/modules/system/service/impl/DeptServiceImpl.java b/oying-system/src/main/java/com/oying/modules/system/service/impl/DeptServiceImpl.java deleted file mode 100644 index 0c3386b..0000000 --- a/oying-system/src/main/java/com/oying/modules/system/service/impl/DeptServiceImpl.java +++ /dev/null @@ -1,265 +0,0 @@ -package com.oying.modules.system.service.impl; - -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.collection.CollectionUtil; -import cn.hutool.core.util.ObjectUtil; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.oying.modules.system.domain.Dept; -import com.oying.modules.system.domain.User; -import com.oying.modules.system.domain.dto.DeptQueryCriteria; -import com.oying.modules.system.mapper.DeptMapper; -import com.oying.modules.system.mapper.RoleMapper; -import com.oying.modules.system.mapper.UserMapper; -import com.oying.modules.system.service.DeptService; -import com.oying.utils.*; -import lombok.RequiredArgsConstructor; -import com.oying.exception.BadRequestException; -import com.oying.utils.enums.DataScopeEnum; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.lang.reflect.Field; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -/** -* @author Z -* @date 2019-03-25 -*/ -@Service -@RequiredArgsConstructor -public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService { - - private final DeptMapper deptMapper; - private final UserMapper userMapper; - private final RedisUtils redisUtils; - private final RoleMapper roleMapper; - - @Override - public List<Dept> queryAll(DeptQueryCriteria criteria, Boolean isQuery) throws Exception { - String dataScopeType = SecurityUtils.getDataScopeType(); - if (isQuery) { - if(dataScopeType.equals(DataScopeEnum.ALL.getValue())){ - criteria.setPidIsNull(true); - } - List<Field> fields = StringUtils.getAllFields(criteria.getClass(), new ArrayList<>()); - List<String> fieldNames = new ArrayList<String>(){{ add("pidIsNull");add("enabled");}}; - for (Field field : fields) { - //设置对象的访问权限,保证对private的属性的访问 - field.setAccessible(true); - Object val = field.get(criteria); - if(fieldNames.contains(field.getName())){ - continue; - } - if (ObjectUtil.isNotNull(val)) { - criteria.setPidIsNull(null); - break; - } - } - } - // 数据权限 - criteria.setIds(SecurityUtils.getCurrentUserDataScope()); - List<Dept> list = deptMapper.findAll(criteria); - // 如果为空,就代表为自定义权限或者本级权限,就需要去重,不理解可以注释掉,看查询结果 - if(StringUtils.isBlank(dataScopeType)){ - return deduplication(list); - } - return list; - } - - @Override - public Dept findById(Long id) { - String key = CacheKey.DEPT_ID + id; - Dept dept = redisUtils.get(key, Dept.class); - if(dept == null){ - dept = deptMapper.selectById(id); - redisUtils.set(key, dept, 1, TimeUnit.DAYS); - } - return dept; - } - - @Override - public List<Dept> findByPid(long pid) { - return deptMapper.findByPid(pid); - } - - @Override - public Set<Dept> findByRoleId(Long id) { - return deptMapper.findByRoleId(id); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void create(Dept resources) { - save(resources); - // 清理缓存 - updateSubCnt(resources.getPid()); - // 清理自定义角色权限的datascope缓存 - delCaches(resources.getPid()); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void update(Dept resources) { - // 旧的机构 - Long oldPid = findById(resources.getId()).getPid(); - Long newPid = resources.getPid(); - if(resources.getPid() != null && resources.getId().equals(resources.getPid())) { - throw new BadRequestException("上级不能为自己"); - } - Dept dept = getById(resources.getId()); - resources.setId(dept.getId()); - saveOrUpdate(resources); - // 更新父节点中子节点数目 - updateSubCnt(oldPid); - updateSubCnt(newPid); - // 清理缓存 - delCaches(resources.getId()); - } - - @Override - @Transactional(rollbackFor = Exception.class) - public void delete(Set<Dept> depts) { - for (Dept dept : depts) { - // 清理缓存 - delCaches(dept.getId()); - deptMapper.deleteById(dept.getId()); - updateSubCnt(dept.getPid()); - } - } - - @Override - public void download(List<Dept> depts, HttpServletResponse response) throws IOException { - List<Map<String, Object>> list = new ArrayList<>(); - for (Dept dept : depts) { - Map<String,Object> map = new LinkedHashMap<>(); - map.put("机构名称", dept.getName()); - map.put("机构状态", dept.getEnabled() ? "启用" : "停用"); - map.put("创建日期", dept.getCreateTime()); - list.add(map); - } - FileUtil.downloadExcel(list, response); - } - - @Override - public Set<Dept> getDeleteDepts(List<Dept> menuList, Set<Dept> deptSet) { - for (Dept dept : menuList) { - deptSet.add(dept); - List<Dept> depts = deptMapper.findByPid(dept.getId()); - if(CollUtil.isNotEmpty(depts)){ - getDeleteDepts(depts, deptSet); - } - } - return deptSet; - } - - @Override - public List<Long> getDeptChildren(List<Dept> deptList) { - List<Long> list = new ArrayList<>(); - deptList.forEach(dept -> { - if (dept!=null && dept.getEnabled()) { - List<Dept> depts = deptMapper.findByPid(dept.getId()); - if (CollUtil.isNotEmpty(depts)) { - list.addAll(getDeptChildren(depts)); - } - list.add(dept.getId()); - } - } - ); - return list; - } - - @Override - public List<Dept> getSuperior(Dept dept, List<Dept> depts) { - if(dept.getPid() == null){ - depts.addAll(deptMapper.findByPidIsNull()); - return depts; - } - depts.addAll(deptMapper.findByPid(dept.getPid())); - return getSuperior(findById(dept.getPid()), depts); - } - - @Override - public Object buildTree(List<Dept> deptList) { - Set<Dept> trees = new LinkedHashSet<>(); - Set<Dept> depts= new LinkedHashSet<>(); - List<String> deptNames = deptList.stream().map(Dept::getName).collect(Collectors.toList()); - boolean isChild; - for (Dept dept : deptList) { - isChild = false; - if (dept.getPid() == null) { - trees.add(dept); - } - for (Dept it : deptList) { - if (it.getPid() != null && dept.getId().equals(it.getPid())) { - isChild = true; - if (dept.getChildren() == null) { - dept.setChildren(new ArrayList<>()); - } - dept.getChildren().add(it); - } - } - if(isChild) { - depts.add(dept); - } else if(dept.getPid() != null && !deptNames.contains(findById(dept.getPid()).getName())) { - depts.add(dept); - } - } - - if (CollectionUtil.isEmpty(trees)) { - trees = depts; - } - Map<String,Object> map = new HashMap<>(2); - map.put("totalElements",depts.size()); - map.put("content",CollectionUtil.isEmpty(trees)? depts :trees); - return map; - } - - @Override - public void verification(Set<Dept> depts) { - Set<Long> deptIds = depts.stream().map(Dept::getId).collect(Collectors.toSet()); - if(userMapper.countByDepts(deptIds) > 0){ - throw new BadRequestException("所选机构存在用户关联,请解除后再试!"); - } - if(roleMapper.countByDepts(deptIds) > 0){ - throw new BadRequestException("所选机构存在角色关联,请解除后再试!"); - } - } - - private void updateSubCnt(Long deptId){ - if(deptId != null){ - int count = deptMapper.countByPid(deptId); - deptMapper.updateSubCntById(count, deptId); - } - } - - private List<Dept> deduplication(List<Dept> list) { - List<Dept> depts = new ArrayList<>(); - for (Dept dept : list) { - boolean flag = true; - for (Dept dept1 : list) { - if (dept1.getId().equals(dept.getPid())) { - flag = false; - break; - } - } - if (flag){ - depts.add(dept); - } - } - return depts; - } - - /** - * 清理缓存 - * @param id / - */ - public void delCaches(Long id){ - List<User> users = userMapper.findByRoleDeptId(id); - // 删除数据权限 - redisUtils.delByKeys(CacheKey.DATA_USER, users.stream().map(User::getId).collect(Collectors.toSet())); - redisUtils.del(CacheKey.DEPT_ID + id); - } -} diff --git a/oying-system/src/main/java/com/oying/modules/system/service/impl/RoleServiceImpl.java b/oying-system/src/main/java/com/oying/modules/system/service/impl/RoleServiceImpl.java index 91b8820..307b89b 100644 --- a/oying-system/src/main/java/com/oying/modules/system/service/impl/RoleServiceImpl.java +++ b/oying-system/src/main/java/com/oying/modules/system/service/impl/RoleServiceImpl.java @@ -79,9 +79,6 @@ } save(resources); // 判断是否有机构数据,若有,则需创建关联 - if (CollectionUtil.isNotEmpty(resources.getDepts())) { - roleDeptMapper.insertData(resources.getId(), resources.getDepts()); - } } @Override @@ -95,16 +92,13 @@ role.setName(resources.getName()); role.setDescription(resources.getDescription()); role.setDataScope(resources.getDataScope()); - role.setDepts(resources.getDepts()); role.setLevel(resources.getLevel()); // 更新 saveOrUpdate(role); // 删除关联机构数据 roleDeptMapper.deleteByRoleId(resources.getId()); // 判断是否有机构数据,若有,则需更新关联 - if (CollectionUtil.isNotEmpty(resources.getDepts())) { - roleDeptMapper.insertData(resources.getId(), resources.getDepts()); - } + // 更新相关缓存 delCaches(role.getId(), null); } diff --git a/oying-system/src/main/java/com/oying/modules/system/service/impl/UserServiceImpl.java b/oying-system/src/main/java/com/oying/modules/system/service/impl/UserServiceImpl.java index 0790373..86fbd18 100644 --- a/oying-system/src/main/java/com/oying/modules/system/service/impl/UserServiceImpl.java +++ b/oying-system/src/main/java/com/oying/modules/system/service/impl/UserServiceImpl.java @@ -72,16 +72,15 @@ @Override @Transactional(rollbackFor = Exception.class) public void create(User resources) { - resources.setDeptId(resources.getDept().getId()); if (userMapper.findByUsername(resources.getUsername()) != null) { throw new EntityExistException(User.class, "username", resources.getUsername()); } - if (userMapper.findByEmail(resources.getEmail()) != null) { - throw new EntityExistException(User.class, "email", resources.getEmail()); - } - if (userMapper.findByPhone(resources.getPhone()) != null) { - throw new EntityExistException(User.class, "phone", resources.getPhone()); - } +// if (userMapper.findByEmail(resources.getEmail()) != null) { +// throw new EntityExistException(User.class, "email", resources.getEmail()); +// } +// if (userMapper.findByPhone(resources.getPhone()) != null) { +// throw new EntityExistException(User.class, "phone", resources.getPhone()); +// } save(resources); // 保存用户岗位 userJobMapper.insertData(resources.getId(), resources.getJobs()); @@ -94,17 +93,17 @@ public void update(User resources) throws Exception { User user = getById(resources.getId()); User user1 = userMapper.findByUsername(resources.getUsername()); - User user2 = userMapper.findByEmail(resources.getEmail()); - User user3 = userMapper.findByPhone(resources.getPhone()); +// User user2 = userMapper.findByEmail(resources.getEmail()); +// User user3 = userMapper.findByPhone(resources.getPhone()); if (user1 != null && !user.getId().equals(user1.getId())) { throw new EntityExistException(User.class, "username", resources.getUsername()); } - if (user2 != null && !user.getId().equals(user2.getId())) { - throw new EntityExistException(User.class, "email", resources.getEmail()); - } - if (user3 != null && !user.getId().equals(user3.getId())) { - throw new EntityExistException(User.class, "phone", resources.getPhone()); - } +// if (user2 != null && !user.getId().equals(user2.getId())) { +// throw new EntityExistException(User.class, "email", resources.getEmail()); +// } +// if (user3 != null && !user.getId().equals(user3.getId())) { +// throw new EntityExistException(User.class, "phone", resources.getPhone()); +// } // 如果用户的角色改变 if (!resources.getRoles().equals(user.getRoles())) { redisUtils.del(CacheKey.DATA_USER + resources.getId()); @@ -112,20 +111,14 @@ redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); redisUtils.del(CacheKey.ROLE_USER + resources.getId()); } - // 修改机构会影响 数据权限 - if (!Objects.equals(resources.getDept(),user.getDept())) { - redisUtils.del(CacheKey.DATA_USER + resources.getId()); - } // 如果用户被禁用,则清除用户登录信息 if(!resources.getEnabled()){ onlineUserService.kickOutForUsername(resources.getUsername()); } - user.setDeptId(resources.getDept().getId()); user.setUsername(resources.getUsername()); user.setEmail(resources.getEmail()); user.setEnabled(resources.getEnabled()); user.setRoles(resources.getRoles()); - user.setDept(resources.getDept()); user.setJobs(resources.getJobs()); user.setPhone(resources.getPhone()); user.setNickName(resources.getNickName()); @@ -251,7 +244,6 @@ Map<String, Object> map = new LinkedHashMap<>(); map.put("用户名", user.getUsername()); map.put("角色", roles); - map.put("机构", user.getDept().getName()); map.put("岗位", user.getJobs().stream().map(Job::getName).collect(Collectors.toList())); map.put("邮箱", user.getEmail()); map.put("状态", user.getEnabled() ? "启用" : "禁用"); diff --git a/oying-system/src/main/resources/mapper/system/DeptMapper.xml b/oying-system/src/main/resources/mapper/system/DeptMapper.xml deleted file mode 100644 index 10be3a2..0000000 --- a/oying-system/src/main/resources/mapper/system/DeptMapper.xml +++ /dev/null @@ -1,70 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > -<mapper namespace="com.oying.modules.system.mapper.DeptMapper"> - <resultMap id="BaseResultMap" type="com.oying.modules.system.domain.Dept"> - <id column="dept_id" property="id"/> - <result column="dept_sort" property="deptSort"/> - <result column="name" property="name"/> - <result column="enabled" property="enabled"/> - <result column="pid" property="pid"/> - <result column="sub_count" property="subCount"/> - <result column="create_by" property="createBy"/> - <result column="update_by" property="updateBy"/> - <result column="create_time" property="createTime"/> - <result column="update_time" property="updateTime"/> - </resultMap> - - <sql id="BaseResultMap"> - dept_id, name, pid, sub_count, create_time, update_time, create_by, update_by, enabled, dept_sort - </sql> - - <select id="findAll" resultMap="BaseResultMap"> - select - <include refid="BaseResultMap"/> - from sys_dept - <where> - <if test="criteria.ids != null and criteria.ids.size() > 0"> - and dept_id in - <foreach collection="criteria.ids" item="id" open="(" separator="," close=")"> - #{id} - </foreach> - </if> - <if test="criteria.name != null and criteria.name != ''"> - and name like concat('%', #{criteria.name}, '%') - </if> - <if test="criteria.enabled != null"> - and enabled = #{criteria.enabled} - </if> - <if test="criteria.pid != null"> - and pid = #{criteria.pid} - </if> - <if test="criteria.pidIsNull != null"> - and pid is null - </if> - <if test="criteria.createTime != null and criteria.createTime.size() != 0"> - and create_time between #{criteria.createTime[0]} and #{criteria.createTime[1]} - </if> - </where> - order by dept_sort - </select> - - <select id="findByPid" resultMap="BaseResultMap"> - select - <include refid="BaseResultMap"/> - from sys_dept - where pid = #{pid} - </select> - - <select id="findByPidIsNull" resultMap="BaseResultMap"> - select - <include refid="BaseResultMap"/> - from sys_dept - where pid is null - </select> - - <select id="findByRoleId" resultType="com.oying.modules.system.domain.Dept"> - select d.dept_id as id, d.name, d.pid, d.sub_count, d.create_time, d.update_time, d.create_by, d.update_by, d.enabled, d.dept_sort - from sys_dept d, sys_roles_depts r - where d.dept_id = r.dept_id and r.role_id = #{roleId} - </select> -</mapper> diff --git a/oying-system/src/main/resources/mapper/system/RoleDeptMapper.xml b/oying-system/src/main/resources/mapper/system/RoleDeptMapper.xml index 664c04d..801e8c8 100644 --- a/oying-system/src/main/resources/mapper/system/RoleDeptMapper.xml +++ b/oying-system/src/main/resources/mapper/system/RoleDeptMapper.xml @@ -5,7 +5,7 @@ <insert id="insertData"> insert into sys_roles_depts (role_id, dept_id) values - <foreach collection="depts" item="item" open="(" separator="),(" close=")"> + <foreach collection="ids" item="item" open="(" separator="),(" close=")"> #{roleId}, #{item.id} </foreach> </insert> diff --git a/oying-system/src/main/resources/mapper/system/RoleMapper.xml b/oying-system/src/main/resources/mapper/system/RoleMapper.xml index 3134824..ff1bf73 100644 --- a/oying-system/src/main/resources/mapper/system/RoleMapper.xml +++ b/oying-system/src/main/resources/mapper/system/RoleMapper.xml @@ -16,10 +16,6 @@ <result column="menu_title" property="title"/> <result column="menu_permission" property="permission"/> </collection> - <collection property="depts" ofType="com.oying.modules.system.domain.Dept"> - <id column="dept_id" property="id"/> - <result column="dept_name" property="name"/> - </collection> </resultMap> <sql id="Base_Column_List"> @@ -30,10 +26,6 @@ <sql id="Menu_Column_List"> menu.menu_id as menu_id, menu.title as menu_title, menu.permission as menu_permission - </sql> - - <sql id="Dept_Column_List"> - dept.dept_id as dept_id, dept.name as dept_name </sql> <sql id="Where_sql"> @@ -57,7 +49,6 @@ <select id="findAll" resultMap="BaseResultMap"> select role.*, - <include refid="Dept_Column_List"/>, <include refid="Menu_Column_List"/> from ( select @@ -72,7 +63,6 @@ left join sys_roles_menus srm on role.role_role_id = srm.role_id left join sys_menu menu on menu.menu_id = srm.menu_id left join sys_roles_depts srd on role.role_role_id = srd.role_id - left join sys_dept dept on dept.dept_id = srd.dept_id order by role.role_level </select> @@ -90,37 +80,24 @@ <select id="findById" resultMap="BaseResultMap"> select <include refid="Base_Column_List"/>, - <include refid="Dept_Column_List"/>, <include refid="Menu_Column_List"/> from sys_role role left join sys_roles_menus srm on role.role_id = srm.role_id left join sys_menu menu on menu.menu_id = srm.menu_id left join sys_roles_depts srd on role.role_id = srd.role_id - left join sys_dept dept on dept.dept_id = srd.dept_id where role.role_id = #{roleId} </select> <select id="findByUserId" resultMap="BaseResultMap"> SELECT <include refid="Base_Column_List"/>, - <include refid="Dept_Column_List"/>, <include refid="Menu_Column_List"/> from sys_role role left join sys_roles_menus srm on role.role_id = srm.role_id left join sys_menu menu on menu.menu_id = srm.menu_id left join sys_roles_depts srd on role.role_id = srd.role_id - left join sys_dept dept on dept.dept_id = srd.dept_id left join sys_users_roles ur on role.role_id = ur.role_id WHERE role.role_id = ur.role_id AND ur.user_id = #{userId} </select> - <select id="countByDepts" resultType="int"> - select count(*) - from sys_role r, sys_roles_depts d - where r.role_id = d.role_id - and d.dept_id in - <foreach collection="deptIds" item="deptId" open="(" separator="," close=")"> - #{deptId} - </foreach> - </select> </mapper> diff --git a/oying-system/src/main/resources/mapper/system/UserMapper.xml b/oying-system/src/main/resources/mapper/system/UserMapper.xml index a4eca68..a71ec72 100644 --- a/oying-system/src/main/resources/mapper/system/UserMapper.xml +++ b/oying-system/src/main/resources/mapper/system/UserMapper.xml @@ -3,7 +3,6 @@ <mapper namespace="com.oying.modules.system.mapper.UserMapper"> <resultMap id="BaseResultMap" type="com.oying.modules.system.domain.User"> <id column="user_user_id" property="id"/> - <result column="user_dept_id" property="deptId"/> <result column="user_username" property="username"/> <result column="user_user_type" property="userType"/> <result column="user_openid" property="openid"/> @@ -21,10 +20,6 @@ <result column="user_update_by" property="updateBy"/> <result column="user_create_time" property="createTime"/> <result column="user_update_time" property="updateTime"/> - <association property="dept" javaType="com.oying.modules.system.domain.Dept"> - <id column="dept_id" property="id"/> - <result column="dept_name" property="name"/> - </association> <collection property="jobs" ofType="com.oying.modules.system.domain.Job"> <id column="job_id" property="id"/> <result column="job_name" property="name"/> @@ -38,13 +33,12 @@ </resultMap> <sql id="Base_Column_List"> - u.user_id as user_user_id, u.dept_id as user_dept_id, u.username as user_username, + u.user_id as user_user_id, u.username as user_username, u.user_type as user_user_type,u.openid as user_openid, u.nick_name as user_nick_name, u.email as user_email, u.phone as user_phone, u.gender as user_gender, u.avatar_name as user_avatar_name, u.avatar_path as user_avatar_path, u.enabled as user_enabled, u.pwd_reset_time as user_pwd_reset_time, u.create_by as user_create_by, - u.update_by as user_update_by, u.create_time as user_create_time, u.update_time as user_update_time, - d.dept_id as dept_id, d.name as dept_name + u.update_by as user_update_by, u.create_time as user_create_time, u.update_time as user_update_time </sql> <sql id="Job_Column_List"> @@ -62,12 +56,6 @@ </if> <if test="criteria.enabled != null"> and u.enabled = #{criteria.enabled} - </if> - <if test="criteria.deptIds != null and criteria.deptIds.size() != 0"> - and u.dept_id in - <foreach collection="criteria.deptIds" item="deptId" open="(" separator="," close=")"> - #{deptId} - </foreach> </if> <if test="criteria.blurry != null and criteria.blurry != ''"> and ( @@ -90,7 +78,6 @@ select <include refid="Base_Column_List"/> from sys_user u - left join sys_dept d on u.dept_id = d.dept_id <include refid="Whrer_Sql"/> order by u.user_id desc <if test="criteria.offset != null"> @@ -115,7 +102,6 @@ u.password user_password, u.is_admin user_is_admin, <include refid="Base_Column_List"/> from sys_user u - left join sys_dept d on u.dept_id = d.dept_id where u.username = #{username} </select> @@ -124,7 +110,6 @@ u.password user_password, u.is_admin user_is_admin, <include refid="Base_Column_List"/> from sys_user u - left join sys_dept d on u.dept_id = d.dept_id where u.openid = #{openid} </select> @@ -144,12 +129,6 @@ group by u.user_id </select> - <select id="findByRoleDeptId" resultType="com.oying.modules.system.domain.User"> - SELECT u.* FROM sys_user u, sys_users_roles r, sys_roles_depts d - WHERE u.user_id = r.user_id AND r.role_id = d.role_id AND d.dept_id = #{deptId} - group by u.user_id - </select> - <select id="findByMenuId" resultType="com.oying.modules.system.domain.User"> SELECT u.user_id as id, u.username FROM sys_user u, sys_users_roles ur, sys_roles_menus rm WHERE u.user_id = ur.user_id AND ur.role_id = rm.role_id AND rm.menu_id = #{menuId} @@ -161,14 +140,6 @@ WHERE u.user_id = j.user_id AND j.job_id IN <foreach collection="jobIds" item="jobId" open="(" separator="," close=")"> #{jobId} - </foreach> - </select> - - <select id="countByDepts" resultType="int"> - SELECT count(*) FROM sys_user u - WHERE u.dept_id IN - <foreach collection="deptIds" item="deptId" open="(" separator="," close=")"> - #{deptId} </foreach> </select> -- Gitblit v1.9.3