feat : 部门重构完成
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-mybatis</artifactId>
|
||||
<artifactId>common-mybatis-puls</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
@@ -52,6 +52,10 @@
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-decrypt</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>admin-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -10,6 +10,7 @@ import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.excel.utils.ExcelUtil;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
package cn.fateverse.admin.controller;
|
||||
|
||||
import cn.fateverse.admin.dto.DeptDto;
|
||||
import cn.fateverse.admin.facade.DeptFacade;
|
||||
import cn.fateverse.admin.vo.DeptVo;
|
||||
import cn.fateverse.admin.service.DeptService;
|
||||
import cn.fateverse.common.core.constant.UserConstants;
|
||||
import cn.fateverse.admin.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.OptionTree;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
import cn.fateverse.common.log.enums.BusinessType;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -25,14 +24,10 @@ import java.util.List;
|
||||
@Api(tags = "部门接口")
|
||||
@RestController
|
||||
@RequestMapping("/dept")
|
||||
@RequiredArgsConstructor
|
||||
public class DeptController {
|
||||
|
||||
private final DeptService deptService;
|
||||
|
||||
|
||||
public DeptController(DeptService deptService) {
|
||||
this.deptService = deptService;
|
||||
}
|
||||
private final DeptFacade deptFacade;
|
||||
|
||||
|
||||
@ApiOperation("获取列表信息")
|
||||
@@ -41,7 +36,7 @@ public class DeptController {
|
||||
public Result<List<DeptVo>> list(
|
||||
@ApiParam(name="deptName",value="部门名称") String deptName,
|
||||
@ApiParam(name="state",value="状态(1: 正常 0 : 停用)") Integer state){
|
||||
List<DeptVo> deptVoList = deptService.searchTree(deptName, state);
|
||||
List<DeptVo> deptVoList = deptFacade.searchTree(deptName, state);
|
||||
return Result.ok(deptVoList);
|
||||
}
|
||||
|
||||
@@ -51,23 +46,21 @@ public class DeptController {
|
||||
public Result<DeptVo> info(
|
||||
@ApiParam(name="deptId",value="部门id")
|
||||
@PathVariable Long deptId){
|
||||
checkDeptId(deptId);
|
||||
DeptVo deptVo = deptService.searchById(deptId);
|
||||
DeptVo deptVo = deptFacade.searchById(deptId);
|
||||
return Result.ok(deptVo);
|
||||
}
|
||||
|
||||
@ApiOperation("获取树形接口的option")
|
||||
@GetMapping("/option")
|
||||
public Result<List<OptionTree>> option(){
|
||||
List<OptionTree> optionTreeList = deptService.searchTreeOption();
|
||||
List<OptionTree> optionTreeList = deptFacade.searchTreeOption();
|
||||
return Result.ok(optionTreeList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取修改时的部门列表")
|
||||
@GetMapping("/option/exclude/{deptId}")
|
||||
public Result<List<OptionTree>> exclude(@PathVariable Long deptId){
|
||||
checkDeptId(deptId);
|
||||
List<OptionTree> deptVoList = deptService.searchExcludeTree(deptId);
|
||||
List<OptionTree> deptVoList = deptFacade.searchExcludeTree(deptId);
|
||||
return Result.ok(deptVoList);
|
||||
}
|
||||
|
||||
@@ -76,12 +69,7 @@ public class DeptController {
|
||||
@PreAuthorize("@ss.hasPermission('admin:dept:add')")
|
||||
@Log(title = "新增部门",businessType = BusinessType.INSERT)
|
||||
public Result<Void> add(@RequestBody @Validated DeptDto deptDto){
|
||||
Dept dept = new Dept();
|
||||
BeanUtils.copyProperties(deptDto,dept);
|
||||
if (UserConstants.DEPT_DISABLE.equals(deptService.checkNameUnique(dept))){
|
||||
return Result.error("新增部门: "+ dept.getDeptName() +"'失败,部门名称以存在!");
|
||||
}
|
||||
deptService.save(dept);
|
||||
deptFacade.save(deptDto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -90,15 +78,7 @@ public class DeptController {
|
||||
@PreAuthorize("@ss.hasPermission('admin:dept:edit')")
|
||||
@Log(title = "修改部门",businessType = BusinessType.UPDATE)
|
||||
public Result<Void> edit(@RequestBody @Validated DeptDto deptDto){
|
||||
Dept dept = new Dept();
|
||||
BeanUtils.copyProperties(deptDto,dept);
|
||||
if (UserConstants.DEPT_DISABLE.equals(deptService.checkNameUnique(dept))){
|
||||
return Result.error("修改部门: "+ dept.getDeptName() +"'失败,部门名称以存在!");
|
||||
}else if (dept.getDeptId().equals(dept.getParentId())){
|
||||
return Result.error("修改部门: "+ dept.getDeptName() +"'失败,上级部门不能为自己!");
|
||||
}
|
||||
checkDeptId(dept.getDeptId());
|
||||
deptService.edit(dept);
|
||||
deptFacade.edit(deptDto);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
@@ -108,26 +88,11 @@ public class DeptController {
|
||||
@PreAuthorize("@ss.hasPermission('admin:dept:del')")
|
||||
@Log(title = "删除部门",businessType = BusinessType.DELETE)
|
||||
public Result<Void> delete(@PathVariable Long deptId){
|
||||
checkDeptId(deptId);
|
||||
if (deptService.hasChildById(deptId)){
|
||||
return Result.error("存在下级部门,不允许删除");
|
||||
}else if (deptService.checkExistUser(deptId)){
|
||||
return Result.error("该部门下存在用户,不允许删除");
|
||||
}
|
||||
deptService.remove(deptId);
|
||||
deptFacade.remove(deptId);
|
||||
return Result.ok();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查部门id是都为空
|
||||
*/
|
||||
private void checkDeptId(Long deptId){
|
||||
if (null == deptId){
|
||||
throw new CustomException("部门id不能为空!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import cn.fateverse.common.core.result.Result;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.security.entity.LoginUser;
|
||||
import cn.fateverse.common.core.entity.LoginUser;
|
||||
import cn.fateverse.common.security.service.TokenService;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import cn.fateverse.common.log.annotation.Log;
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.fateverse.admin.convert;
|
||||
|
||||
import cn.fateverse.admin.dto.DeptDto;
|
||||
import cn.fateverse.admin.vo.DeptVo;
|
||||
import cn.fateverse.common.core.convert.BaseConvertDefine;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface DeptConvert extends BaseConvertDefine<DeptDto, Dept, DeptVo> {
|
||||
DeptConvert INSTANCE = Mappers.getMapper(DeptConvert.class);
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
package cn.fateverse.admin.dubbo;
|
||||
|
||||
import cn.fateverse.admin.service.DeptService;
|
||||
import cn.fateverse.admin.facade.DeptFacade;
|
||||
import cn.fateverse.admin.vo.DeptVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import java.util.List;
|
||||
@@ -11,18 +12,15 @@ import java.util.List;
|
||||
* @date 2023-02-20
|
||||
*/
|
||||
@DubboService
|
||||
@RequiredArgsConstructor
|
||||
public class DubboDeptServiceImpl implements DubboDeptService {
|
||||
|
||||
|
||||
private final DeptService deptService;
|
||||
|
||||
public DubboDeptServiceImpl(DeptService deptService) {
|
||||
this.deptService = deptService;
|
||||
}
|
||||
private final DeptFacade deptFacade;
|
||||
|
||||
|
||||
@Override
|
||||
public List<DeptVo> searchDeptByDeptId(List<Long> deptIds) {
|
||||
return deptService.searchByIds(deptIds);
|
||||
return deptFacade.searchByIds(deptIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
package cn.fateverse.admin.facade;
|
||||
|
||||
import cn.fateverse.admin.convert.DeptConvert;
|
||||
import cn.fateverse.admin.dto.DeptDto;
|
||||
import cn.fateverse.admin.service.DeptService;
|
||||
import cn.fateverse.admin.service.UserService;
|
||||
import cn.fateverse.admin.vo.DeptVo;
|
||||
import cn.fateverse.common.core.constant.BaseConstant;
|
||||
import cn.fateverse.common.core.constant.UserConstants;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.OptionTree;
|
||||
import cn.fateverse.common.core.utils.AssertUtil;
|
||||
import cn.fateverse.common.core.utils.convert.TreeUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DeptFacade {
|
||||
|
||||
private final DeptService deptService;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
/**
|
||||
* 查询树形结构信息
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @param state 状态
|
||||
* @return {@link List }<{@link DeptVo }>
|
||||
*/
|
||||
public List<DeptVo> searchTree(String deptName, Integer state) {
|
||||
List<Dept> deptList = deptService.list(deptName, state);
|
||||
return TreeUtil.build(deptList, DeptVo.class, (config) -> {
|
||||
config.setIdField("deptId");
|
||||
config.setExclude("phone");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 按id查询
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return {@link DeptVo }
|
||||
*/
|
||||
public DeptVo searchById(Long deptId) {
|
||||
Dept dept = deptService.getById(deptId);
|
||||
return DeptConvert.INSTANCE.entityToVo(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门选择的树形结构
|
||||
*
|
||||
* @return {@link List }<{@link OptionTree }> 部门树形选择对象
|
||||
*/
|
||||
public List<OptionTree> searchTreeOption() {
|
||||
List<Dept> deptList = deptService.list(null, null);
|
||||
return TreeUtil.build(deptList, OptionTree.class, (config) -> {
|
||||
config.setIdField("deptId");
|
||||
config.setOption("deptId", "deptName");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索排除树
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return {@link List }<{@link OptionTree }>
|
||||
*/
|
||||
public List<OptionTree> searchExcludeTree(Long deptId) {
|
||||
Dept dept = deptService.getById(deptId);
|
||||
if (BaseConstant.ZERO.equals(dept.getParentId())) {
|
||||
return List.of();
|
||||
}
|
||||
List<Dept> deptList = deptService.searchExcludeTree(deptId);
|
||||
return TreeUtil.build(deptList, OptionTree.class, (config) -> {
|
||||
config.setIdField("deptId");
|
||||
config.setOption("deptId", "deptName");
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param deptDto 部门dto
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(DeptDto deptDto) {
|
||||
Dept dept = DeptConvert.INSTANCE.dtoToEntity(deptDto);
|
||||
deptService.checkNameUnique(dept);
|
||||
deptService.save(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param deptDto 部门dto
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void edit(DeptDto deptDto) {
|
||||
Dept dept = DeptConvert.INSTANCE.dtoToEntity(deptDto);
|
||||
deptService.checkNameUnique(dept);
|
||||
AssertUtil.isTrue(!dept.getDeptId().equals(dept.getParentId()), "修改部门: {} '失败,上级部门不能为自己!", dept.getDeptName());
|
||||
|
||||
Dept newParentDept = deptService.getById(dept.getParentId());
|
||||
Dept oldDept = deptService.getById(dept.getDeptId());
|
||||
if (null != newParentDept && null != oldDept) {
|
||||
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
||||
String oldAncestors = oldDept.getAncestors();
|
||||
dept.setAncestors(newAncestors);
|
||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||
}
|
||||
if (null != newParentDept && UserConstants.DEPT_DISABLE.equals(newParentDept.getState())) {
|
||||
updateParentDept(dept);
|
||||
}
|
||||
deptService.save(dept);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新字元素的ancestors
|
||||
*
|
||||
* @param deptId
|
||||
* @param newAncestors
|
||||
* @param odlAncestors
|
||||
*/
|
||||
public void updateDeptChildren(Long deptId, String newAncestors, String odlAncestors) {
|
||||
List<Dept> children = deptService.selectChildrenById(deptId);
|
||||
List<Dept> newChildren = children.stream().peek(child -> {
|
||||
child.setAncestors(child.getAncestors().replace(odlAncestors, newAncestors));
|
||||
}).collect(Collectors.toList());
|
||||
if (CollUtil.isNotEmpty(newChildren)) {
|
||||
deptService.updateBatchById(newChildren);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新父级部门的状态
|
||||
*
|
||||
* @param dept
|
||||
*/
|
||||
public void updateParentDept(Dept dept) {
|
||||
Dept parent = deptService.getById(dept.getParentId());
|
||||
parent.setState(dept.getState());
|
||||
deptService.updateById(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*
|
||||
* @param deptId 部门id
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void remove(Long deptId) {
|
||||
AssertUtil.isTrue(!deptService.hasChildById(deptId), "存在下级部门,不允许删除");
|
||||
AssertUtil.isTrue(!userService.checkExistUser(deptId), "该部门下存在用户,不允许删除");
|
||||
deptService.removeById(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按id搜索
|
||||
*
|
||||
* @param deptIds 部门id
|
||||
* @return {@link List }<{@link DeptVo }>
|
||||
*/
|
||||
public List<DeptVo> searchByIds(List<Long> deptIds) {
|
||||
List<Dept> deptList = deptService.searchByIds(deptIds);
|
||||
return DeptConvert.INSTANCE.entityToVOList(deptList);
|
||||
}
|
||||
}
|
||||
@@ -1,137 +1,25 @@
|
||||
package cn.fateverse.admin.mapper;
|
||||
|
||||
import cn.fateverse.admin.entity.Dept;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/2
|
||||
*/
|
||||
public interface DeptMapper {
|
||||
public interface DeptMapper extends BaseMapper<Dept> {
|
||||
|
||||
|
||||
/**
|
||||
* 查询部门列表
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @param state 部门状态
|
||||
* @return 部门集合
|
||||
*/
|
||||
List<Dept> selectList(@Param("deptName") String deptName, @Param("state") Integer state);
|
||||
|
||||
/**
|
||||
* 通过id查询部门信息
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 返回对象
|
||||
*/
|
||||
Dept selectById(Long deptId);
|
||||
|
||||
/**
|
||||
* 获取排除自身的部门列表
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 部门集合
|
||||
*/
|
||||
List<Dept> selectExclude(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询所有的子节点
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 部门集合
|
||||
*/
|
||||
List<Dept> selectChildrenById(Long deptId);
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @param parentId 父部门ID
|
||||
* @return 结果
|
||||
*/
|
||||
Dept selectByDeptNameAndParentId(@Param("deptName") String deptName, @Param("parentId") Long parentId);
|
||||
|
||||
/**
|
||||
* 根据父id查询部门信息
|
||||
*
|
||||
* @param parentId 父级部门id
|
||||
* @return 部门集合
|
||||
*/
|
||||
List<Dept> selectListByDeptParentId(Long parentId);
|
||||
|
||||
|
||||
/**
|
||||
* 通过parentId查询子列表
|
||||
*
|
||||
* @param parentId 父级id
|
||||
* @return 部门名称集合
|
||||
*/
|
||||
Set<String> selectDeptNameListByParentId(Long parentId);
|
||||
|
||||
/**
|
||||
* 查找是否存在子节点
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 数量
|
||||
*/
|
||||
int selectChildCountByDeptId(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 数量
|
||||
*/
|
||||
int selectExistUserCount(Long deptId);
|
||||
|
||||
/**
|
||||
* 根据ids获取到部门
|
||||
*
|
||||
* @param deptIds 部门id列表
|
||||
* @return 部门集合对象
|
||||
*/
|
||||
List<Dept> selectByIds(List<Long> deptIds);
|
||||
|
||||
/**
|
||||
* 新增部门
|
||||
*
|
||||
* @param dept 部门对象
|
||||
* @return 影响条数
|
||||
*/
|
||||
int insert(Dept dept);
|
||||
|
||||
/**
|
||||
* 更新部门信息
|
||||
*
|
||||
* @param dept 部门对象
|
||||
* @return 影响条数
|
||||
*/
|
||||
int update(Dept dept);
|
||||
|
||||
/**
|
||||
* 修改部门的状态;
|
||||
*
|
||||
* @param dept 部门对象
|
||||
* @return 影响条数
|
||||
*/
|
||||
int updateState(Dept dept);
|
||||
|
||||
/**
|
||||
* 批量修改子元素之前的关系
|
||||
*
|
||||
* @param depts 子元素
|
||||
* @return 结果
|
||||
*/
|
||||
int updateChildren(@Param("depts") List<Dept> depts);
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 运行结构
|
||||
*/
|
||||
int delete(Long deptId);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package cn.fateverse.admin.mapper;
|
||||
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import cn.fateverse.admin.entity.UserBase;
|
||||
import cn.fateverse.admin.query.UserQuery;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.UserBase;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,7 +12,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/10/30
|
||||
*/
|
||||
public interface UserMapper {
|
||||
public interface UserMapper extends BaseMapper<UserBase> {
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package cn.fateverse.admin.service;
|
||||
|
||||
import cn.fateverse.admin.vo.DeptVo;
|
||||
import cn.fateverse.admin.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.OptionTree;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -10,24 +9,16 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/11/2
|
||||
*/
|
||||
public interface DeptService {
|
||||
public interface DeptService extends IService<Dept> {
|
||||
|
||||
/**
|
||||
* 查询部门树形结构数据
|
||||
*
|
||||
* @param deptName 部门名称
|
||||
* @param state 部门状态
|
||||
* @param state 部门状态
|
||||
* @return 部门集合
|
||||
*/
|
||||
List<DeptVo> searchTree(String deptName, Integer state);
|
||||
|
||||
/**
|
||||
* 部门id查询部门信息
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 返回对象
|
||||
*/
|
||||
DeptVo searchById(Long deptId);
|
||||
List<Dept> list(String deptName, Integer state);
|
||||
|
||||
/**
|
||||
* 获取排除自身的部门树形结构
|
||||
@@ -35,14 +26,7 @@ public interface DeptService {
|
||||
* @param deptId 部门id
|
||||
* @return 部门树形选择对象
|
||||
*/
|
||||
List<OptionTree> searchExcludeTree(Long deptId);
|
||||
|
||||
/**
|
||||
* 获取部门选择的树形结构
|
||||
*
|
||||
* @return 部门树形选择对象
|
||||
*/
|
||||
List<OptionTree> searchTreeOption();
|
||||
List<Dept> searchExcludeTree(Long deptId);
|
||||
|
||||
/**
|
||||
* 通过ids获取到部门数据
|
||||
@@ -50,15 +34,14 @@ public interface DeptService {
|
||||
* @param deptIds 部门id列表
|
||||
* @return 部门集合对象
|
||||
*/
|
||||
List<DeptVo> searchByIds(List<Long> deptIds);
|
||||
List<Dept> searchByIds(List<Long> deptIds);
|
||||
|
||||
/**
|
||||
* 校验部门名称是否唯一
|
||||
*
|
||||
* @param dept 部门对象
|
||||
* @return 结果
|
||||
*/
|
||||
String checkNameUnique(Dept dept);
|
||||
void checkNameUnique(Dept dept);
|
||||
|
||||
/**
|
||||
* 是否存在部门子节点
|
||||
@@ -69,34 +52,11 @@ public interface DeptService {
|
||||
boolean hasChildById(Long deptId);
|
||||
|
||||
/**
|
||||
* 查询部门是否存在用户
|
||||
*
|
||||
* @param deptId 部门ID
|
||||
* @return 结果 true 存在 false 不存在
|
||||
*/
|
||||
boolean checkExistUser(Long deptId);
|
||||
|
||||
/**
|
||||
* 新增部门
|
||||
*
|
||||
* @param dept 部门对象
|
||||
* @return 影响条数
|
||||
*/
|
||||
int save(Dept dept);
|
||||
|
||||
/**
|
||||
* 更新部门信息
|
||||
*
|
||||
* @param dept 部门对象
|
||||
* @return 影响条数
|
||||
*/
|
||||
int edit(Dept dept);
|
||||
|
||||
/**
|
||||
* 删除部门
|
||||
* 按id选择子代
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return 影响条数
|
||||
* @return {@link List }<{@link Dept }>
|
||||
*/
|
||||
int remove(Long deptId);
|
||||
List<Dept> selectChildrenById(Long deptId);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package cn.fateverse.admin.service;
|
||||
|
||||
import cn.fateverse.admin.dto.UserDto;
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import cn.fateverse.admin.query.UserQuery;
|
||||
import cn.fateverse.admin.vo.UserChooseVo;
|
||||
import cn.fateverse.admin.vo.UserDetailVo;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,7 +15,7 @@ import java.util.List;
|
||||
* @author Clay
|
||||
* @date 2022/10/30
|
||||
*/
|
||||
public interface UserService {
|
||||
public interface UserService extends IService<User> {
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户信息
|
||||
@@ -263,4 +264,12 @@ public interface UserService {
|
||||
* @return
|
||||
*/
|
||||
List<Long> searchAllUserIds();
|
||||
|
||||
/**
|
||||
* 检查现有用户
|
||||
*
|
||||
* @param deptId 部门id
|
||||
* @return boolean
|
||||
*/
|
||||
boolean checkExistUser(Long deptId);
|
||||
}
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.vo.DeptVo;
|
||||
import cn.fateverse.admin.mapper.DeptMapper;
|
||||
import cn.fateverse.admin.service.DeptService;
|
||||
import cn.fateverse.common.core.constant.UserConstants;
|
||||
import cn.fateverse.admin.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.OptionTree;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.utils.AssertUtil;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.core.utils.convert.TreeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
@@ -25,157 +19,58 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DeptServiceImpl implements DeptService {
|
||||
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept>
|
||||
implements DeptService {
|
||||
|
||||
|
||||
private final DeptMapper deptMapper;
|
||||
|
||||
public DeptServiceImpl(DeptMapper deptMapper) {
|
||||
this.deptMapper = deptMapper;
|
||||
@Override
|
||||
public List<Dept> list(String deptName, Integer state) {
|
||||
return this.lambdaQuery()
|
||||
.like(StrUtil.isNotBlank(deptName), Dept::getDeptName, deptName)
|
||||
.like(ObjectUtil.isNotNull(state), Dept::getState, state)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptVo> searchTree(String deptName, Integer state) {
|
||||
List<Dept> deptList = deptMapper.selectList(deptName, state);
|
||||
return TreeUtil.build(deptList, DeptVo.class, (config) -> {
|
||||
config.setIdField("deptId");
|
||||
config.setExclude("phone");
|
||||
});
|
||||
public List<Dept> searchExcludeTree(Long deptId) {
|
||||
return this.lambdaQuery()
|
||||
.ne(Dept::getDeptId, deptId)
|
||||
.ne(Dept::getParentId, deptId)
|
||||
.list();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Dept> searchByIds(List<Long> deptIds) {
|
||||
return this.lambdaQuery()
|
||||
.in(Dept::getDeptId, deptIds)
|
||||
.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeptVo searchById(Long deptId) {
|
||||
Dept dept = deptMapper.selectById(deptId);
|
||||
DeptVo deptVo = new DeptVo();
|
||||
BeanUtils.copyProperties(dept, deptVo);
|
||||
return deptVo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OptionTree> searchExcludeTree(Long deptId) {
|
||||
Dept dept = deptMapper.selectById(deptId);
|
||||
if (0L == dept.getParentId()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<Dept> deptList = deptMapper.selectExclude(deptId);
|
||||
return TreeUtil.build(deptList, OptionTree.class, (config) -> {
|
||||
config.setIdField("deptId");
|
||||
config.setOption("deptId", "deptName");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OptionTree> searchTreeOption() {
|
||||
List<Dept> deptList = deptMapper.selectList(null, null);
|
||||
return TreeUtil.build(deptList, OptionTree.class, (config) -> {
|
||||
config.setIdField("deptId");
|
||||
config.setOption("deptId", "deptName");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeptVo> searchByIds(List<Long> deptIds) {
|
||||
List<Dept> deptList = deptMapper.selectByIds(deptIds);
|
||||
return deptList.stream().map(dept ->
|
||||
DeptVo.builder()
|
||||
.deptId(dept.getDeptId())
|
||||
.parentId(dept.getParentId())
|
||||
.deptName(dept.getDeptName())
|
||||
.email(dept.getEmail())
|
||||
.orderNum(dept.getOrderNum())
|
||||
.leader(dept.getLeader())
|
||||
.leaderId(dept.getLeaderId())
|
||||
.phone(dept.getPhone())
|
||||
.state(dept.getState())
|
||||
.createTime(dept.getCreateTime())
|
||||
.build()
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String checkNameUnique(Dept dept) {
|
||||
public void checkNameUnique(Dept dept) {
|
||||
Long deptId = LongUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
|
||||
Dept info = deptMapper.selectByDeptNameAndParentId(dept.getDeptName(), deptId);
|
||||
if (!ObjectUtils.isEmpty(info) && !info.getDeptId().equals(deptId)) {
|
||||
return UserConstants.NOT_UNIQUE;
|
||||
}
|
||||
return UserConstants.UNIQUE;
|
||||
Dept info = this.lambdaQuery()
|
||||
.eq(Dept::getDeptName, dept.getDeptName())
|
||||
.eq(Dept::getParentId, deptId)
|
||||
.last("limit 1")
|
||||
.one();
|
||||
AssertUtil.isTrue(ObjectUtil.isNotNull(info) && !dept.getDeptId().equals(info.getDeptId()), "新增部门: {}'失败,部门名称以存在!", dept.getDeptName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildById(Long deptId) {
|
||||
return deptMapper.selectChildCountByDeptId(deptId) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkExistUser(Long deptId) {
|
||||
return deptMapper.selectExistUserCount(deptId) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int save(Dept dept) {
|
||||
Set<String> deptNameSet = deptMapper.selectDeptNameListByParentId(dept.getParentId());
|
||||
Dept info = deptMapper.selectById(dept.getParentId());
|
||||
if (deptNameSet.contains(dept.getDeptName())) {
|
||||
throw new CustomException(info.getDeptName() + "下已经存在" + dept.getDeptName() + "部门");
|
||||
}
|
||||
if (UserConstants.DEPT_DISABLE.equals(info.getState())) {
|
||||
throw new CustomException("上级部门停用,不允许添加");
|
||||
}
|
||||
dept.setAncestors(info.getAncestors() + "," + info.getDeptId());
|
||||
return deptMapper.insert(dept);
|
||||
return this.lambdaQuery()
|
||||
.eq(Dept::getParentId, deptId)
|
||||
.eq(Dept::getDelFlag, 0)
|
||||
.exists();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int edit(Dept dept) {
|
||||
Dept newParentDept = deptMapper.selectById(dept.getParentId());
|
||||
Dept oldDept = deptMapper.selectById(dept.getDeptId());
|
||||
if (null != newParentDept && null != oldDept) {
|
||||
String newAncestors = newParentDept.getAncestors() + "," + newParentDept.getDeptId();
|
||||
String oldAncestors = oldDept.getAncestors();
|
||||
dept.setAncestors(newAncestors);
|
||||
updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors);
|
||||
}
|
||||
if (null != newParentDept && UserConstants.DEPT_DISABLE.equals(newParentDept.getState())) {
|
||||
updateParentDept(dept);
|
||||
}
|
||||
return deptMapper.update(dept);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int remove(Long deptId) {
|
||||
return deptMapper.delete(deptId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新父级部门的状态
|
||||
*
|
||||
* @param dept
|
||||
*/
|
||||
public void updateParentDept(Dept dept) {
|
||||
dept = deptMapper.selectById(dept.getDeptId());
|
||||
deptMapper.updateState(dept);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新字元素的ancestors
|
||||
*
|
||||
* @param deptId
|
||||
* @param newAncestors
|
||||
* @param odlAncestors
|
||||
*/
|
||||
public void updateDeptChildren(Long deptId, String newAncestors, String odlAncestors) {
|
||||
List<Dept> children = deptMapper.selectChildrenById(deptId);
|
||||
List<Dept> newChildren = children.stream().peek(child -> {
|
||||
child.setAncestors(child.getAncestors().replace(odlAncestors, newAncestors));
|
||||
}).collect(Collectors.toList());
|
||||
if (newChildren.size() > 0) {
|
||||
deptMapper.updateChildren(newChildren);
|
||||
}
|
||||
public List<Dept> selectChildrenById(Long deptId) {
|
||||
return this.lambdaQuery()
|
||||
.eq(Dept::getParentId, deptId)
|
||||
.list();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,11 +78,11 @@ public class MenuServiceImpl implements MenuService {
|
||||
@Override
|
||||
public List<MenuSimpVo> searchTree(String menuName, String state) {
|
||||
List<Menu> menuList = null;
|
||||
User user = Objects.requireNonNull(SecurityUtils.getLoginUser()).getUser();
|
||||
if (User.isAdmin(user.getUserId())) {
|
||||
Long userId = Objects.requireNonNull(SecurityUtils.getUserId());
|
||||
if (User.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectList(menuName, state, null, false);
|
||||
} else {
|
||||
menuList = menuMapper.selectListByUserId(user.getUserId(), menuName, state, null, false);
|
||||
menuList = menuMapper.selectListByUserId(userId, menuName, state, null, false);
|
||||
}
|
||||
return TreeUtil.build(menuList, MenuSimpVo.class, (config) -> {
|
||||
config.setIdField("menuId");
|
||||
@@ -101,12 +101,12 @@ public class MenuServiceImpl implements MenuService {
|
||||
|
||||
@Override
|
||||
public List<OptionTree> searchTreeOption(Long excludeId) {
|
||||
User user = Objects.requireNonNull(SecurityUtils.getLoginUser()).getUser();
|
||||
Long userId = Objects.requireNonNull(SecurityUtils.getUserId());
|
||||
List<Menu> menuList = null;
|
||||
if (User.isAdmin(user.getUserId())) {
|
||||
if (User.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectList(null, null, excludeId, true);
|
||||
} else {
|
||||
menuList = menuMapper.selectListByUserId(user.getUserId(), null, null, excludeId, true);
|
||||
menuList = menuMapper.selectListByUserId(userId, null, null, excludeId, true);
|
||||
}
|
||||
return TreeUtil.build(menuList, OptionTree.class, (config) -> {
|
||||
config.setIdField("menuId");
|
||||
@@ -121,12 +121,12 @@ public class MenuServiceImpl implements MenuService {
|
||||
if (null == roleId || roleId.equals(0L)) {
|
||||
checkedSet = menuMapper.selectCheckedMenuIdByRoleId(roleId);
|
||||
}
|
||||
User user = Objects.requireNonNull(SecurityUtils.getLoginUser()).getUser();
|
||||
Long userId = Objects.requireNonNull(SecurityUtils.getUserId());
|
||||
List<Menu> menuList = null;
|
||||
if (User.isAdmin(user.getUserId())) {
|
||||
if (User.isAdmin(userId)) {
|
||||
menuList = menuMapper.selectList(null, null, null, true);
|
||||
} else {
|
||||
menuList = menuMapper.selectListByUserId(user.getUserId(), null, null, null, true);
|
||||
menuList = menuMapper.selectListByUserId(userId, null, null, null, true);
|
||||
}
|
||||
return OptionMenuVo.builder()
|
||||
.checked(checkedSet)
|
||||
|
||||
@@ -8,7 +8,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.admin.entity.OnlineUser;
|
||||
import cn.fateverse.admin.service.OnlineUserService;
|
||||
import cn.fateverse.common.core.constant.CacheConstants;
|
||||
import cn.fateverse.common.security.entity.LoginUser;
|
||||
import cn.fateverse.common.core.entity.LoginUser;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
package cn.fateverse.admin.service.impl;
|
||||
|
||||
import cn.fateverse.admin.dto.UserDto;
|
||||
import cn.fateverse.admin.entity.*;
|
||||
import cn.fateverse.admin.entity.UserPost;
|
||||
import cn.fateverse.admin.entity.UserRole;
|
||||
import cn.fateverse.admin.mapper.*;
|
||||
import cn.fateverse.admin.query.RoleQuery;
|
||||
import cn.fateverse.admin.query.UserQuery;
|
||||
import cn.fateverse.admin.service.UserService;
|
||||
import cn.fateverse.admin.vo.UserChooseVo;
|
||||
import cn.fateverse.admin.vo.UserDetailVo;
|
||||
import cn.fateverse.admin.vo.UserVo;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import cn.fateverse.admin.service.UserService;
|
||||
import cn.fateverse.common.core.entity.Dept;
|
||||
import cn.fateverse.common.core.entity.User;
|
||||
import cn.fateverse.common.core.entity.UserBase;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.LongUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.mybatis.utils.PageUtils;
|
||||
import cn.fateverse.common.mybatisplus.utils.PageUtils;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -33,7 +37,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserBase>
|
||||
implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@@ -162,7 +167,6 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void bindRole(List<Long> userIds, Long roleId) {
|
||||
@@ -322,14 +326,17 @@ public class UserServiceImpl implements UserService {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> searchAllUserIds() {
|
||||
return userMapper.selectAllUserIds();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean checkExistUser(Long deptId) {
|
||||
return this.lambdaQuery()
|
||||
.eq(UserBase::getDeptId, deptId)
|
||||
.exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量处理用户与角色之间的对应关系
|
||||
|
||||
@@ -23,161 +23,10 @@
|
||||
from sys_dept
|
||||
</sql>
|
||||
|
||||
<select id="selectList" resultType="cn.fateverse.admin.entity.Dept">
|
||||
<include refid="selectSql"/>
|
||||
<where>
|
||||
<if test="deptName != null and deptName != ''"> and dept_name like concat('%',#{deptName},'%')</if>
|
||||
<if test="state != null"> and `state` = #{state}</if>
|
||||
</where>
|
||||
order by parent_id, order_num
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultType="cn.fateverse.admin.entity.Dept">
|
||||
select d.dept_id,
|
||||
d.parent_id,
|
||||
d.ancestors,
|
||||
d.dept_name,
|
||||
d.order_num,
|
||||
d.leader,
|
||||
d.leader_id,
|
||||
d.phone,
|
||||
d.email,
|
||||
d.state,
|
||||
d.del_flag,
|
||||
d.create_by,
|
||||
d.create_time,
|
||||
d.update_by,
|
||||
d.update_time
|
||||
from sys_dept d
|
||||
left join sys_dept p on p.dept_id = d.parent_id
|
||||
where d.dept_id = #{deptId}
|
||||
</select>
|
||||
|
||||
<select id="selectExclude" resultType="cn.fateverse.admin.entity.Dept">
|
||||
<include refid="selectSql"/>
|
||||
where dept_id != #{deptId} and parent_id != #{deptId}
|
||||
</select>
|
||||
|
||||
<select id="selectChildrenById" parameterType="Long" resultType="cn.fateverse.admin.entity.Dept">
|
||||
<include refid="selectSql"/>
|
||||
where find_in_set(#{deptId}, ancestors)
|
||||
</select>
|
||||
|
||||
<select id="selectByDeptNameAndParentId" resultType="cn.fateverse.admin.entity.Dept">
|
||||
<include refid="selectSql"/>
|
||||
where dept_name = #{deptName} and parent_id = #{parentId} limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectListByDeptParentId" resultType="cn.fateverse.admin.entity.Dept">
|
||||
<select id="selectListByDeptParentId" resultType="cn.fateverse.common.core.entity.Dept">
|
||||
<include refid="selectSql"/>
|
||||
where parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="selectChildCountByDeptId" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from sys_dept
|
||||
where parent_id = #{deptId}
|
||||
and del_flag = '0'
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectExistUserCount" resultType="java.lang.Integer">
|
||||
select count(1)
|
||||
from sys_user
|
||||
where dept_id = #{deptId}
|
||||
and del_flag = '0'
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectDeptNameListByParentId" resultType="java.lang.String">
|
||||
select dept_name from sys_dept where parent_id = #{parentId}
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultType="cn.fateverse.admin.entity.Dept">
|
||||
<include refid="selectSql"/>
|
||||
where dept_id in
|
||||
<foreach collection="list" item="deptId" open="(" separator="," close=")">
|
||||
#{deptId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="insert">
|
||||
insert into sys_dept
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null and deptId != 0">dept_id,</if>
|
||||
<if test="parentId != null and parentId != 0">parent_id,</if>
|
||||
<if test="deptName != null and deptName != ''">dept_name,</if>
|
||||
<if test="ancestors != null and ancestors != ''">ancestors,</if>
|
||||
<if test="orderNum != null and orderNum != ''">order_num,</if>
|
||||
<if test="leader != null and leader != ''">leader,</if>
|
||||
<if test="leaderId != null ">leader_id,</if>
|
||||
<if test="phone != null and phone != ''">phone,</if>
|
||||
<if test="email != null and email != ''">email,</if>
|
||||
<if test="state != null">state,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="deptId != null and deptId != 0">#{deptId},</if>
|
||||
<if test="parentId != null and parentId != 0">#{parentId},</if>
|
||||
<if test="deptName != null and deptName != ''">#{deptName},</if>
|
||||
<if test="ancestors != null and ancestors != ''">#{ancestors},</if>
|
||||
<if test="orderNum != null and orderNum != ''">#{orderNum},</if>
|
||||
<if test="leader != null and leader != ''">#{leader},</if>
|
||||
<if test="leaderId != null ">#{leaderId},</if>
|
||||
<if test="phone != null and phone != ''">#{phone},</if>
|
||||
<if test="email != null and email != ''">#{email},</if>
|
||||
<if test="state != null">#{state},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
update sys_dept
|
||||
<set>
|
||||
<if test="parentId != null and parentId != 0">parent_id = #{parentId},</if>
|
||||
<if test="deptName != null and deptName != ''">dept_name = #{deptName},</if>
|
||||
<if test="ancestors != null">ancestors = #{ancestors},</if>
|
||||
<if test="orderNum != null">order_num = #{orderNum},</if>
|
||||
<if test="leader != null">leader = #{leader},</if>
|
||||
<if test="leaderId != null">leader_id = #{leaderId},</if>
|
||||
<if test="phone != null">phone = #{phone},</if>
|
||||
<if test="email != null">email = #{email},</if>
|
||||
<if test="state != null">state = #{state},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where dept_id = #{deptId}
|
||||
</update>
|
||||
|
||||
<update id="updateChildren" parameterType="java.util.List">
|
||||
update sys_dept set ancestors =
|
||||
<foreach collection="depts" item="item" index="index"
|
||||
separator=" " open="case dept_id" close="end">
|
||||
when #{item.deptId} then #{item.ancestors}
|
||||
</foreach>
|
||||
where dept_id in
|
||||
<foreach collection="depts" item="item" index="index"
|
||||
separator="," open="(" close=")">
|
||||
#{item.deptId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updateState">
|
||||
update sys_dept
|
||||
<set>
|
||||
<if test="state != null and state != ''">state = #{state},</if>
|
||||
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
where dept_id in (${ancestors})
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
delete
|
||||
from sys_dept
|
||||
where dept_id = #{deptId}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
from sys_role
|
||||
</sql>
|
||||
|
||||
<select id="selectList" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="selectList" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
<where>
|
||||
<if test="roleName != null and roleName != ''"> and role_name like concat('%',#{roleName} ,'%')</if>
|
||||
@@ -35,7 +35,7 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectById" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="selectById" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
where role_id = #{roleId}
|
||||
</select>
|
||||
@@ -46,16 +46,16 @@
|
||||
where r.role_id = #{roleId}
|
||||
limit 1
|
||||
</select>
|
||||
<select id="selectByRoleName" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="selectByRoleName" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
where role_name = #{roleName} limit 0,1
|
||||
</select>
|
||||
<select id="selectByRoleKey" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="selectByRoleKey" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
where role_key = #{roleKey} limit 0,1
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="selectByIds" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
where role_id in
|
||||
<foreach collection="list" open="(" separator="," close=")" item="roleId">
|
||||
@@ -63,7 +63,7 @@
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="selectListByMenuId" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="selectListByMenuId" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
<where>
|
||||
<if test="roleName != null and roleName != ''">and role_name like concat('%',#{roleName} ,'%')</if>
|
||||
@@ -72,7 +72,7 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="searchListExcludeMenuId" resultType="cn.fateverse.admin.entity.Role">
|
||||
<select id="searchListExcludeMenuId" resultType="cn.fateverse.common.core.entity.Role">
|
||||
<include refid="selectSql"/>
|
||||
<where>
|
||||
<if test="roleName != null and roleName != ''">and role_name like concat('%',#{roleName} ,'%')</if>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="cn.fateverse.admin.mapper.UserMapper">
|
||||
|
||||
<resultMap type="cn.fateverse.admin.entity.User" id="UserResult">
|
||||
<resultMap type="cn.fateverse.common.core.entity.User" id="UserResult">
|
||||
<id property="userId" column="user_id"/>
|
||||
<result property="deptId" column="dept_id"/>
|
||||
<result property="userName" column="user_name"/>
|
||||
@@ -26,11 +26,11 @@
|
||||
<result property="userType" column="user_type"/>
|
||||
<result property="openId" column="open_id"/>
|
||||
<result property="unionId" column="union_id"/>
|
||||
<association property="dept" column="dept_id" javaType="cn.fateverse.admin.entity.Dept" resultMap="deptResult"/>
|
||||
<association property="dept" column="dept_id" javaType="cn.fateverse.common.core.entity.Dept" resultMap="deptResult"/>
|
||||
<collection property="roles" javaType="java.util.List" resultMap="RoleResult"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="deptResult" type="cn.fateverse.admin.entity.Dept">
|
||||
<resultMap id="deptResult" type="cn.fateverse.common.core.entity.Dept">
|
||||
<id property="deptId" column="dept_id"/>
|
||||
<result property="parentId" column="parent_id"/>
|
||||
<result property="deptName" column="dept_name"/>
|
||||
@@ -41,7 +41,7 @@
|
||||
<result property="state" column="dept_state"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="RoleResult" type="cn.fateverse.admin.entity.Role">
|
||||
<resultMap id="RoleResult" type="cn.fateverse.common.core.entity.Role">
|
||||
<id property="roleId" column="role_id"/>
|
||||
<result property="roleName" column="role_name"/>
|
||||
<result property="roleKey" column="role_key"/>
|
||||
@@ -218,17 +218,17 @@
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectUserInfoByUserName" resultType="cn.fateverse.admin.entity.User">
|
||||
<select id="selectUserInfoByUserName" resultType="cn.fateverse.common.core.entity.User">
|
||||
<include refid="selectUser"/>
|
||||
where user_name = #{userName}
|
||||
</select>
|
||||
|
||||
<select id="selectByPhoneNum" resultType="cn.fateverse.admin.entity.User">
|
||||
<select id="selectByPhoneNum" resultType="cn.fateverse.common.core.entity.User">
|
||||
<include refid="selectUser"/>
|
||||
where phone_number = #{phoneNumber}
|
||||
</select>
|
||||
|
||||
<select id="selectByEmail" resultType="cn.fateverse.admin.entity.User">
|
||||
<select id="selectByEmail" resultType="cn.fateverse.common.core.entity.User">
|
||||
<include refid="selectUser"/>
|
||||
where email = #{email} limit 0,1
|
||||
</select>
|
||||
@@ -260,7 +260,7 @@
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insert" parameterType="cn.fateverse.admin.entity.UserBase" useGeneratedKeys="true" keyProperty="userId"
|
||||
<insert id="insert" parameterType="cn.fateverse.common.core.entity.UserBase" useGeneratedKeys="true" keyProperty="userId"
|
||||
keyColumn="user_id">
|
||||
insert into sys_user
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
|
||||
Reference in New Issue
Block a user