部门管理

master
shijie 4 years ago
parent 43a53991a0
commit a04eaba7ad
  1. 24
      dq-financial-api/src/main/java/com/daqing/financial/hrms/DeptControllerApi.java
  2. 41
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/DeptController.java
  3. 2
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/DeptDao.java
  4. 4
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/DeptService.java
  5. 38
      dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/DeptServiceImpl.java
  6. 4
      dq-financial-hrms/src/main/resources/mapper/hrms/DeptDao.xml
  7. 14
      dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDeptDao.xml
  8. 14
      dq-financial-hrms/src/main/resources/mapper/hrms/EmployeePositionDao.xml
  9. 14
      dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeRoleDao.xml
  10. 14
      dq-financial-hrms/src/main/resources/mapper/hrms/RolePermissionDao.xml
  11. 36
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/DeptUpdateSortRequest.java
  12. 3
      dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/DeptCode.java

@ -1,12 +1,11 @@
package com.daqing.financial.hrms; package com.daqing.financial.hrms;
import com.daqing.framework.domain.hrms.DeptEntity;
import com.daqing.framework.domain.hrms.request.DeptAddRequest; import com.daqing.framework.domain.hrms.request.DeptAddRequest;
import com.daqing.framework.model.response.ResponseResult; import com.daqing.framework.model.response.ResponseResult;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import java.util.List;
/** /**
* @Author: gongsj. * @Author: gongsj.
* @Description: 部门管理controllerApi定义 * @Description: 部门管理controllerApi定义
@ -29,7 +28,26 @@ public interface DeptControllerApi {
ResponseResult tree(); ResponseResult tree();
/** /**
* 批量修改部门信息 * 拖拉拽重新排序批量修改部门信息
*/ */
@ApiOperation(value = "拖拉拽重新排序,批量修改部门信息", notes = "拖拉拽重新排序,批量修改部门信息")
ResponseResult updateSort(DeptEntity[] depts);
/**
* 根据id查询部门详细信息
*/
@ApiOperation(value = "根据id查询部门详细信息", notes = "根据id查询部门详细信息")
ResponseResult info(Long id);
/**
* 根据id修改部门信息
*/
@ApiOperation(value = "根据id修改部门信息", notes = "根据id修改部门信息")
ResponseResult update(DeptEntity dept);
/**
* 根据id数组批量删除部门信息
*/
@ApiOperation(value = "根据id数组批量删除部门信息", notes = "根据id数组批量删除部门信息")
ResponseResult delete(Long[] ids);
} }

@ -1,7 +1,6 @@
package com.daqing.financial.hrms.controller; package com.daqing.financial.hrms.controller;
import com.daqing.financial.hrms.DeptControllerApi; import com.daqing.financial.hrms.DeptControllerApi;
import com.daqing.financial.hrms.feign.CrmsFeignService;
import com.daqing.financial.hrms.service.DeptService; import com.daqing.financial.hrms.service.DeptService;
import com.daqing.framework.domain.hrms.DeptEntity; import com.daqing.framework.domain.hrms.DeptEntity;
import com.daqing.framework.domain.hrms.request.DeptAddRequest; import com.daqing.framework.domain.hrms.request.DeptAddRequest;
@ -10,7 +9,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.List; import java.util.List;
/** /**
@ -27,9 +25,6 @@ public class DeptController implements DeptControllerApi {
@Autowired @Autowired
private DeptService deptService; private DeptService deptService;
@Autowired
private CrmsFeignService crmsFeignService;
/** /**
* 保存一条部门信息 * 保存一条部门信息
* *
@ -38,28 +33,37 @@ public class DeptController implements DeptControllerApi {
*/ */
@Override @Override
@PostMapping("/save") @PostMapping("/save")
//@RequiresPermissions("hrms:dept:save")
public ResponseResult save(@RequestBody DeptAddRequest deptAddRequest) { public ResponseResult save(@RequestBody DeptAddRequest deptAddRequest) {
boolean result = deptService.saveDept(deptAddRequest); boolean result = deptService.saveDept(deptAddRequest);
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
} }
/**
* 树形结构展示所有部门信息
*
* @return 统一响应对象
*/
@Override @Override
@GetMapping("/tree") @GetMapping("/tree")
//@RequiresPermissions("hrms:dept:tree")
public ResponseResult tree() { public ResponseResult tree() {
List<DeptEntity> list = deptService.listWithTree(); List<DeptEntity> list = deptService.listWithTree();
return new ResponseResult<List<DeptEntity>>().SUCCESS(list); return new ResponseResult<List<DeptEntity>>().SUCCESS(list);
} }
/** /**
* 测试远程调用 * 拖拉拽重新排序批量修改部门信息
*
* @param depts 部门实体类数组
* @return 统一响应对象
*/ */
@GetMapping("/crms_list") @Override
//@RequiresPermissions("hrms:dept:list") @PutMapping("/update/sort")
public ResponseResult crmsList(){ //@RequiresPermissions("hrms:dept:update_sort")
return crmsFeignService.list(new HashMap<>()); public ResponseResult updateSort(@RequestBody DeptEntity[] depts) {
return deptService.updateBatchById(Arrays.asList(depts)) ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
} }
/** /**
@ -69,8 +73,7 @@ public class DeptController implements DeptControllerApi {
//@RequiresPermissions("hrms:dept:info") //@RequiresPermissions("hrms:dept:info")
public ResponseResult info(@PathVariable("id") Long id){ public ResponseResult info(@PathVariable("id") Long id){
DeptEntity dept = deptService.getById(id); DeptEntity dept = deptService.getById(id);
return new ResponseResult<DeptEntity>().SUCCESS(dept);
return ResponseResult.SUCCESS();
} }
/** /**
@ -79,9 +82,8 @@ public class DeptController implements DeptControllerApi {
@PutMapping("/update") @PutMapping("/update")
//@RequiresPermissions("hrms:dept:update") //@RequiresPermissions("hrms:dept:update")
public ResponseResult update(@RequestBody DeptEntity dept){ public ResponseResult update(@RequestBody DeptEntity dept){
deptService.updateById(dept); boolean result = deptService.updateDept(dept);
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
return ResponseResult.SUCCESS();
} }
/** /**
@ -90,8 +92,7 @@ public class DeptController implements DeptControllerApi {
@DeleteMapping("/delete") @DeleteMapping("/delete")
//@RequiresPermissions("hrms:dept:delete") //@RequiresPermissions("hrms:dept:delete")
public ResponseResult delete(@RequestBody Long[] ids){ public ResponseResult delete(@RequestBody Long[] ids){
deptService.removeByIds(Arrays.asList(ids)); boolean result = deptService.deleteByIds(ids);
return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL();
return ResponseResult.SUCCESS();
} }
} }

@ -15,4 +15,6 @@ import org.apache.ibatis.annotations.Param;
@Mapper @Mapper
public interface DeptDao extends BaseMapper<DeptEntity> { public interface DeptDao extends BaseMapper<DeptEntity> {
Integer getMaxSort(@Param("parentId") Long parentId); Integer getMaxSort(@Param("parentId") Long parentId);
Integer getEmpDeptCount(@Param("deptId") Long deptId);
} }

@ -18,5 +18,9 @@ public interface DeptService extends IService<DeptEntity> {
boolean saveDept(DeptAddRequest deptAddRequest); boolean saveDept(DeptAddRequest deptAddRequest);
List<DeptEntity> listWithTree(); List<DeptEntity> listWithTree();
boolean updateDept(DeptEntity dept);
boolean deleteByIds(Long[] ids);
} }

@ -1,7 +1,6 @@
package com.daqing.financial.hrms.service.impl; package com.daqing.financial.hrms.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daqing.financial.hrms.dao.DeptDao; import com.daqing.financial.hrms.dao.DeptDao;
import com.daqing.financial.hrms.service.DeptService; import com.daqing.financial.hrms.service.DeptService;
@ -9,17 +8,15 @@ import com.daqing.framework.domain.hrms.DeptEntity;
import com.daqing.framework.domain.hrms.request.DeptAddRequest; import com.daqing.framework.domain.hrms.request.DeptAddRequest;
import com.daqing.framework.domain.hrms.response.DeptCode; import com.daqing.framework.domain.hrms.response.DeptCode;
import com.daqing.framework.exception.ExceptionCast; import com.daqing.framework.exception.ExceptionCast;
import com.daqing.framework.utils.PageUtils;
import com.daqing.framework.utils.Query;
import com.daqing.framework.utils.SnowflakeIdUtils; import com.daqing.framework.utils.SnowflakeIdUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -107,4 +104,37 @@ public class DeptServiceImpl extends ServiceImpl<DeptDao, DeptEntity> implements
.sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) .sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort())))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
@Override
public boolean updateDept(DeptEntity dept) {
String deptName = dept.getName();
if (StringUtils.isEmpty(deptName)) {
ExceptionCast.cast(DeptCode.DEPT_NAME_ILLEGAL);
}
int count = this.count(new QueryWrapper<DeptEntity>()
.eq("name", deptName)
.notIn("id", dept.getId()));
if (count > 0) {
ExceptionCast.cast(DeptCode.DEPT_NAME_ILLEGAL);
}
return this.updateById(dept);
}
@Override
public boolean deleteByIds(Long[] ids) {
//判断该部门下没有员工,才可删除
// List<Long> collect = Arrays.stream(ids)
// .filter(id -> this.getBaseMapper().getEmpDeptCount(id) > 0)
// .collect(Collectors.toList());
List<Long> list = Arrays.asList(ids);
list.forEach(id -> {
if (this.getBaseMapper().getEmpDeptCount(id) > 0) {
ExceptionCast.cast(DeptCode.DEPT_EMP_EXSIT);
}
});
return this.removeByIds(list);
}
} }

@ -17,4 +17,8 @@
SELECT MAX(sort) FROM hrms_dept WHERE parent_id = #{parentId} SELECT MAX(sort) FROM hrms_dept WHERE parent_id = #{parentId}
</select> </select>
<select id="getEmpDeptCount" parameterType="java.lang.Long" resultType="java.lang.Integer">
SELECT count(1) FROM hrms_employee_dept WHERE dept_id = #{deptId}
</select>
</mapper> </mapper>

@ -1,14 +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.daqing.financial.hrms.dao.EmployeeDeptDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.daqing.framework.domain.hrms.EmployeeDeptEntity" id="employeeDeptMap">
<result property="id" column="id"/>
<result property="employeeId" column="employee_id"/>
<result property="deptId" column="dept_id"/>
</resultMap>
</mapper>

@ -1,14 +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.daqing.financial.hrms.dao.EmployeePositionDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.daqing.framework.domain.hrms.EmployeePositionEntity" id="employeePositionMap">
<result property="id" column="id"/>
<result property="empId" column="emp_id"/>
<result property="positionId" column="position_id"/>
</resultMap>
</mapper>

@ -1,14 +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.daqing.financial.hrms.dao.EmployeeRoleDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.daqing.framework.domain.hrms.EmployeeRoleEntity" id="employeeRoleMap">
<result property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="roleId" column="role_id"/>
</resultMap>
</mapper>

@ -1,14 +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.daqing.financial.hrms.dao.RolePermissionDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.daqing.framework.domain.hrms.RolePermissionEntity" id="rolePermissionMap">
<result property="id" column="id"/>
<result property="roleId" column="role_id"/>
<result property="permissionId" column="permission_id"/>
</resultMap>
</mapper>

@ -0,0 +1,36 @@
package com.daqing.framework.domain.hrms.request;
import lombok.Data;
import java.io.Serializable;
/**
* 新增部门请求体对象
*
* @author gongsj
* @email gongsj@gmail.com
* @date 2020-09-07 17:12:14
*/
@Data
public class DeptUpdateSortRequest implements Serializable {
/**
* 主键
*/
private Long id;
/**
* 部门名称
*/
private String name;
/**
* 上级部门id
*/
private Long parentId;
/**
* 层级
*/
private Integer level;
/**
* 排序
*/
private Integer sort;
}

@ -17,7 +17,8 @@ public enum DeptCode implements ResultCode {
DEPT_NAME_ILLEGAL(false, 22001, "部门名称为空或已存在!"), DEPT_NAME_ILLEGAL(false, 22001, "部门名称为空或已存在!"),
DEPT_ID_NOT_EXSIT(false, 22002, "部门id不存在!"), DEPT_ID_NOT_EXSIT(false, 22002, "部门id不存在!"),
DEPT_LEVEL_ILLEGAL(false, 22003, "部门层级不可超出5级!"); DEPT_LEVEL_ILLEGAL(false, 22003, "部门层级不可超出5级!"),
DEPT_EMP_EXSIT(false, 22004, "请将部门下所有员工移除后再执行删除操作!");
/** /**
* 操作是否成功 * 操作是否成功

Loading…
Cancel
Save