diff --git a/dq-financial-api/src/main/java/com/daqing/financial/hrms/DeptControllerApi.java b/dq-financial-api/src/main/java/com/daqing/financial/hrms/DeptControllerApi.java index adf43540..4990e3cf 100644 --- a/dq-financial-api/src/main/java/com/daqing/financial/hrms/DeptControllerApi.java +++ b/dq-financial-api/src/main/java/com/daqing/financial/hrms/DeptControllerApi.java @@ -1,12 +1,11 @@ package com.daqing.financial.hrms; +import com.daqing.framework.domain.hrms.DeptEntity; import com.daqing.framework.domain.hrms.request.DeptAddRequest; import com.daqing.framework.model.response.ResponseResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import java.util.List; - /** * @Author: gongsj. * @Description: 部门管理controllerApi定义 @@ -29,7 +28,26 @@ public interface DeptControllerApi { 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); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/DeptController.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/DeptController.java index 65f031ca..a58f12e2 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/DeptController.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/controller/DeptController.java @@ -1,7 +1,6 @@ package com.daqing.financial.hrms.controller; import com.daqing.financial.hrms.DeptControllerApi; -import com.daqing.financial.hrms.feign.CrmsFeignService; import com.daqing.financial.hrms.service.DeptService; import com.daqing.framework.domain.hrms.DeptEntity; 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 java.util.Arrays; -import java.util.HashMap; import java.util.List; /** @@ -27,9 +25,6 @@ public class DeptController implements DeptControllerApi { @Autowired private DeptService deptService; - @Autowired - private CrmsFeignService crmsFeignService; - /** * 保存一条部门信息 * @@ -38,28 +33,37 @@ public class DeptController implements DeptControllerApi { */ @Override @PostMapping("/save") + //@RequiresPermissions("hrms:dept:save") public ResponseResult save(@RequestBody DeptAddRequest deptAddRequest) { boolean result = deptService.saveDept(deptAddRequest); return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } + /** + * 树形结构展示所有部门信息 + * + * @return 统一响应对象 + */ @Override @GetMapping("/tree") + //@RequiresPermissions("hrms:dept:tree") public ResponseResult tree() { List list = deptService.listWithTree(); return new ResponseResult>().SUCCESS(list); } - - /** - * 测试远程调用 + * 拖拉拽重新排序,批量修改部门信息 + * + * @param depts 部门实体类数组 + * @return 统一响应对象 */ - @GetMapping("/crms_list") - //@RequiresPermissions("hrms:dept:list") - public ResponseResult crmsList(){ - return crmsFeignService.list(new HashMap<>()); + @Override + @PutMapping("/update/sort") + //@RequiresPermissions("hrms:dept:update_sort") + 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") public ResponseResult info(@PathVariable("id") Long id){ DeptEntity dept = deptService.getById(id); - - return ResponseResult.SUCCESS(); + return new ResponseResult().SUCCESS(dept); } /** @@ -79,9 +82,8 @@ public class DeptController implements DeptControllerApi { @PutMapping("/update") //@RequiresPermissions("hrms:dept:update") public ResponseResult update(@RequestBody DeptEntity dept){ - deptService.updateById(dept); - - return ResponseResult.SUCCESS(); + boolean result = deptService.updateDept(dept); + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } /** @@ -90,8 +92,7 @@ public class DeptController implements DeptControllerApi { @DeleteMapping("/delete") //@RequiresPermissions("hrms:dept:delete") public ResponseResult delete(@RequestBody Long[] ids){ - deptService.removeByIds(Arrays.asList(ids)); - - return ResponseResult.SUCCESS(); + boolean result = deptService.deleteByIds(ids); + return result ? ResponseResult.SUCCESS() : ResponseResult.FAIL(); } } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/DeptDao.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/DeptDao.java index 4eb84c7f..a2e8f116 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/DeptDao.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/dao/DeptDao.java @@ -15,4 +15,6 @@ import org.apache.ibatis.annotations.Param; @Mapper public interface DeptDao extends BaseMapper { Integer getMaxSort(@Param("parentId") Long parentId); + + Integer getEmpDeptCount(@Param("deptId") Long deptId); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/DeptService.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/DeptService.java index 23bc6c80..0ae38e3d 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/DeptService.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/DeptService.java @@ -18,5 +18,9 @@ public interface DeptService extends IService { boolean saveDept(DeptAddRequest deptAddRequest); List listWithTree(); + + boolean updateDept(DeptEntity dept); + + boolean deleteByIds(Long[] ids); } diff --git a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/DeptServiceImpl.java b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/DeptServiceImpl.java index c622cc91..bd809a10 100644 --- a/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/DeptServiceImpl.java +++ b/dq-financial-hrms/src/main/java/com/daqing/financial/hrms/service/impl/DeptServiceImpl.java @@ -1,7 +1,6 @@ package com.daqing.financial.hrms.service.impl; 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.daqing.financial.hrms.dao.DeptDao; 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.response.DeptCode; 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 org.apache.commons.lang.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.Comparator; import java.util.Date; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; @@ -107,4 +104,37 @@ public class DeptServiceImpl extends ServiceImpl implements .sorted(Comparator.comparingInt(menu -> (menu.getSort() == null ? 0 : menu.getSort()))) .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() + .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 collect = Arrays.stream(ids) +// .filter(id -> this.getBaseMapper().getEmpDeptCount(id) > 0) +// .collect(Collectors.toList()); + List list = Arrays.asList(ids); + list.forEach(id -> { + if (this.getBaseMapper().getEmpDeptCount(id) > 0) { + ExceptionCast.cast(DeptCode.DEPT_EMP_EXSIT); + } + }); + return this.removeByIds(list); + } } \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/DeptDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/DeptDao.xml index 37ef3832..873a1ac4 100644 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/DeptDao.xml +++ b/dq-financial-hrms/src/main/resources/mapper/hrms/DeptDao.xml @@ -17,4 +17,8 @@ SELECT MAX(sort) FROM hrms_dept WHERE parent_id = #{parentId} + + \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDeptDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDeptDao.xml deleted file mode 100644 index 5cdf5c39..00000000 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeDeptDao.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeePositionDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeePositionDao.xml deleted file mode 100644 index e6cc8987..00000000 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeePositionDao.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeRoleDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeRoleDao.xml deleted file mode 100644 index 7e34662a..00000000 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/EmployeeRoleDao.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-financial-hrms/src/main/resources/mapper/hrms/RolePermissionDao.xml b/dq-financial-hrms/src/main/resources/mapper/hrms/RolePermissionDao.xml deleted file mode 100644 index 0073b5e7..00000000 --- a/dq-financial-hrms/src/main/resources/mapper/hrms/RolePermissionDao.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/DeptUpdateSortRequest.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/DeptUpdateSortRequest.java new file mode 100644 index 00000000..639de2b9 --- /dev/null +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/request/DeptUpdateSortRequest.java @@ -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; +} diff --git a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/DeptCode.java b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/DeptCode.java index 115886a3..8ac89a9b 100644 --- a/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/DeptCode.java +++ b/dq-framework-model/src/main/java/com/daqing/framework/domain/hrms/response/DeptCode.java @@ -17,7 +17,8 @@ public enum DeptCode implements ResultCode { DEPT_NAME_ILLEGAL(false, 22001, "部门名称为空或已存在!"), DEPT_ID_NOT_EXSIT(false, 22002, "部门id不存在!"), - DEPT_LEVEL_ILLEGAL(false, 22003, "部门层级不可超出5级!"); + DEPT_LEVEL_ILLEGAL(false, 22003, "部门层级不可超出5级!"), + DEPT_EMP_EXSIT(false, 22004, "请将部门下所有员工移除后再执行删除操作!"); /** * 操作是否成功