diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/dto/RoleDto.java b/admin/admin-api/src/main/java/cn/fateverse/admin/dto/RoleDto.java
index a380c1c..193f7b8 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/dto/RoleDto.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/dto/RoleDto.java
@@ -1,6 +1,6 @@
package cn.fateverse.admin.dto;
-import cn.fateverse.admin.entity.Role;
+import cn.fateverse.common.core.entity.Role;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/dto/UserDto.java b/admin/admin-api/src/main/java/cn/fateverse/admin/dto/UserDto.java
index 14cd0f3..d007825 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/dto/UserDto.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/dto/UserDto.java
@@ -1,6 +1,6 @@
package cn.fateverse.admin.dto;
-import cn.fateverse.admin.entity.UserBase;
+import cn.fateverse.common.core.entity.UserBase;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/dubbo/DubboUserService.java b/admin/admin-api/src/main/java/cn/fateverse/admin/dubbo/DubboUserService.java
index 375a372..5a554f9 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/dubbo/DubboUserService.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/dubbo/DubboUserService.java
@@ -1,6 +1,6 @@
package cn.fateverse.admin.dubbo;
-import cn.fateverse.admin.entity.User;
+import cn.fateverse.common.core.entity.User;
import cn.fateverse.admin.vo.UserVo;
import java.util.List;
diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/DeptVo.java b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/DeptVo.java
index d9ff1ba..37608e1 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/DeptVo.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/DeptVo.java
@@ -6,7 +6,7 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
-import java.util.Date;
+import java.time.LocalDateTime;
import java.util.List;
/**
@@ -66,7 +66,7 @@ public class DeptVo implements Serializable {
/**
* 创建时间
*/
- private Date createTime;
+ private LocalDateTime createTime;
/**
* 子节点
diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/IpBackVo.java b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/IpBackVo.java
index d63c9b5..2b9140c 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/IpBackVo.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/IpBackVo.java
@@ -9,7 +9,7 @@ import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
-import java.util.Date;
+import java.time.LocalDateTime;
/**
* @author Clay
@@ -47,7 +47,7 @@ public class IpBackVo {
@ApiModelProperty("创建时间")
@Excel("创建时间")
- private Date createTime;
+ private LocalDateTime createTime;
public static IpBackVo toIpBackVo(IpBack ipBack) {
return IpBackVo.builder()
diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/RoleVo.java b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/RoleVo.java
index f480cd9..3eb8c24 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/RoleVo.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/RoleVo.java
@@ -1,6 +1,6 @@
package cn.fateverse.admin.vo;
-import cn.fateverse.admin.entity.Role;
+import cn.fateverse.common.core.entity.Role;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
diff --git a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/UserVo.java b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/UserVo.java
index 877dae8..330d34c 100644
--- a/admin/admin-api/src/main/java/cn/fateverse/admin/vo/UserVo.java
+++ b/admin/admin-api/src/main/java/cn/fateverse/admin/vo/UserVo.java
@@ -1,13 +1,11 @@
package cn.fateverse.admin.vo;
-import cn.hutool.core.util.StrUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
-import java.util.regex.Pattern;
/**
* @author Clay
@@ -71,12 +69,4 @@ public class UserVo implements Serializable {
@ApiModelProperty("创建时间")
private Date createTime;
- public boolean checkEmail(){
- if (StrUtil.isEmpty(email)){
- return false;
- }
- Pattern pattern =Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
- + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
- return pattern.matcher(email).matches();
- }
}
diff --git a/admin/admin-biz/pom.xml b/admin/admin-biz/pom.xml
index 79f46e4..0d4aa5e 100644
--- a/admin/admin-biz/pom.xml
+++ b/admin/admin-biz/pom.xml
@@ -24,7 +24,7 @@
cn.fateverse
- common-mybatis
+ common-mybatis-puls
cn.fateverse
@@ -52,6 +52,10 @@
cn.fateverse
common-decrypt
+
+ cn.fateverse
+ admin-api
+
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/ConfigController.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/ConfigController.java
index e96082d..7340a7a 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/ConfigController.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/ConfigController.java
@@ -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;
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/DeptController.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/DeptController.java
index 559e0f0..548afa9 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/DeptController.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/DeptController.java
@@ -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(
@ApiParam(name="deptName",value="部门名称") String deptName,
@ApiParam(name="state",value="状态(1: 正常 0 : 停用)") Integer state){
- List deptVoList = deptService.searchTree(deptName, state);
+ List deptVoList = deptFacade.searchTree(deptName, state);
return Result.ok(deptVoList);
}
@@ -51,23 +46,21 @@ public class DeptController {
public Result 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> option(){
- List optionTreeList = deptService.searchTreeOption();
+ List optionTreeList = deptFacade.searchTreeOption();
return Result.ok(optionTreeList);
}
@ApiOperation("获取修改时的部门列表")
@GetMapping("/option/exclude/{deptId}")
public Result> exclude(@PathVariable Long deptId){
- checkDeptId(deptId);
- List deptVoList = deptService.searchExcludeTree(deptId);
+ List 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 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 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 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不能为空!");
- }
- }
-
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/RoleController.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/RoleController.java
index 1a1799d..fd1f4d0 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/RoleController.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/controller/RoleController.java
@@ -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;
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/convert/DeptConvert.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/convert/DeptConvert.java
new file mode 100644
index 0000000..37581a7
--- /dev/null
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/convert/DeptConvert.java
@@ -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 {
+ DeptConvert INSTANCE = Mappers.getMapper(DeptConvert.class);
+}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/dubbo/DubboDeptServiceImpl.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/dubbo/DubboDeptServiceImpl.java
index 42df996..62f46ee 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/dubbo/DubboDeptServiceImpl.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/dubbo/DubboDeptServiceImpl.java
@@ -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 searchDeptByDeptId(List deptIds) {
- return deptService.searchByIds(deptIds);
+ return deptFacade.searchByIds(deptIds);
}
}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/facade/DeptFacade.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/facade/DeptFacade.java
new file mode 100644
index 0000000..116545c
--- /dev/null
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/facade/DeptFacade.java
@@ -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 searchTree(String deptName, Integer state) {
+ List 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 searchTreeOption() {
+ List 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 searchExcludeTree(Long deptId) {
+ Dept dept = deptService.getById(deptId);
+ if (BaseConstant.ZERO.equals(dept.getParentId())) {
+ return List.of();
+ }
+ List 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 children = deptService.selectChildrenById(deptId);
+ List 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 searchByIds(List deptIds) {
+ List deptList = deptService.searchByIds(deptIds);
+ return DeptConvert.INSTANCE.entityToVOList(deptList);
+ }
+}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/DeptMapper.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/DeptMapper.java
index 705fbb7..ffba47d 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/DeptMapper.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/DeptMapper.java
@@ -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 {
- /**
- * 查询部门列表
- *
- * @param deptName 部门名称
- * @param state 部门状态
- * @return 部门集合
- */
- List selectList(@Param("deptName") String deptName, @Param("state") Integer state);
-
- /**
- * 通过id查询部门信息
- *
- * @param deptId 部门id
- * @return 返回对象
- */
- Dept selectById(Long deptId);
-
- /**
- * 获取排除自身的部门列表
- *
- * @param deptId 部门id
- * @return 部门集合
- */
- List selectExclude(Long deptId);
-
- /**
- * 查询所有的子节点
- *
- * @param deptId 部门id
- * @return 部门集合
- */
- List 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 selectListByDeptParentId(Long parentId);
- /**
- * 通过parentId查询子列表
- *
- * @param parentId 父级id
- * @return 部门名称集合
- */
- Set 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 selectByIds(List 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 depts);
-
- /**
- * 删除部门
- *
- * @param deptId 部门id
- * @return 运行结构
- */
- int delete(Long deptId);
}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/UserMapper.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/UserMapper.java
index d3f52f9..d82b912 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/UserMapper.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/mapper/UserMapper.java
@@ -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 {
/**
* 通过用户名查询用户
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/DeptService.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/DeptService.java
index d3cc9ad..85da6d3 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/DeptService.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/DeptService.java
@@ -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 {
/**
* 查询部门树形结构数据
*
* @param deptName 部门名称
- * @param state 部门状态
+ * @param state 部门状态
* @return 部门集合
*/
- List searchTree(String deptName, Integer state);
-
- /**
- * 部门id查询部门信息
- *
- * @param deptId 部门id
- * @return 返回对象
- */
- DeptVo searchById(Long deptId);
+ List list(String deptName, Integer state);
/**
* 获取排除自身的部门树形结构
@@ -35,14 +26,7 @@ public interface DeptService {
* @param deptId 部门id
* @return 部门树形选择对象
*/
- List searchExcludeTree(Long deptId);
-
- /**
- * 获取部门选择的树形结构
- *
- * @return 部门树形选择对象
- */
- List searchTreeOption();
+ List searchExcludeTree(Long deptId);
/**
* 通过ids获取到部门数据
@@ -50,15 +34,14 @@ public interface DeptService {
* @param deptIds 部门id列表
* @return 部门集合对象
*/
- List searchByIds(List deptIds);
+ List searchByIds(List 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 selectChildrenById(Long deptId);
+
}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/UserService.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/UserService.java
index 8534274..b6f2db2 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/UserService.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/UserService.java
@@ -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 {
/**
* 通过用户名查询用户信息
@@ -263,4 +264,12 @@ public interface UserService {
* @return
*/
List searchAllUserIds();
+
+ /**
+ * 检查现有用户
+ *
+ * @param deptId 部门id
+ * @return boolean
+ */
+ boolean checkExistUser(Long deptId);
}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/DeptServiceImpl.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/DeptServiceImpl.java
index d321844..d5d8f2b 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/DeptServiceImpl.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/DeptServiceImpl.java
@@ -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
+ implements DeptService {
- private final DeptMapper deptMapper;
-
- public DeptServiceImpl(DeptMapper deptMapper) {
- this.deptMapper = deptMapper;
+ @Override
+ public List 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 searchTree(String deptName, Integer state) {
- List deptList = deptMapper.selectList(deptName, state);
- return TreeUtil.build(deptList, DeptVo.class, (config) -> {
- config.setIdField("deptId");
- config.setExclude("phone");
- });
+ public List searchExcludeTree(Long deptId) {
+ return this.lambdaQuery()
+ .ne(Dept::getDeptId, deptId)
+ .ne(Dept::getParentId, deptId)
+ .list();
+ }
+
+
+ @Override
+ public List searchByIds(List 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 searchExcludeTree(Long deptId) {
- Dept dept = deptMapper.selectById(deptId);
- if (0L == dept.getParentId()) {
- return new ArrayList<>();
- }
- List deptList = deptMapper.selectExclude(deptId);
- return TreeUtil.build(deptList, OptionTree.class, (config) -> {
- config.setIdField("deptId");
- config.setOption("deptId", "deptName");
- });
- }
-
- @Override
- public List searchTreeOption() {
- List deptList = deptMapper.selectList(null, null);
- return TreeUtil.build(deptList, OptionTree.class, (config) -> {
- config.setIdField("deptId");
- config.setOption("deptId", "deptName");
- });
- }
-
- @Override
- public List searchByIds(List deptIds) {
- List 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 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 children = deptMapper.selectChildrenById(deptId);
- List newChildren = children.stream().peek(child -> {
- child.setAncestors(child.getAncestors().replace(odlAncestors, newAncestors));
- }).collect(Collectors.toList());
- if (newChildren.size() > 0) {
- deptMapper.updateChildren(newChildren);
- }
+ public List selectChildrenById(Long deptId) {
+ return this.lambdaQuery()
+ .eq(Dept::getParentId, deptId)
+ .list();
}
}
diff --git a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/MenuServiceImpl.java b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/MenuServiceImpl.java
index bc399da..1264d0b 100644
--- a/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/MenuServiceImpl.java
+++ b/admin/admin-biz/src/main/java/cn/fateverse/admin/service/impl/MenuServiceImpl.java
@@ -78,11 +78,11 @@ public class MenuServiceImpl implements MenuService {
@Override
public List searchTree(String menuName, String state) {
List