|
@@ -8,6 +8,7 @@ import com.google.common.base.CaseFormat;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.persagy.common.enums.ResponseCode;
|
|
|
import com.persagy.common.exception.BusinessException;
|
|
|
+import com.persagy.fm.common.constant.DefaultValueConstants;
|
|
|
import com.persagy.fm.common.constant.enums.ValidEnum;
|
|
|
import com.persagy.fm.common.context.DefaultAppContext;
|
|
|
import com.persagy.fm.common.model.dto.Sort;
|
|
@@ -23,8 +24,9 @@ import com.persagy.fm.department.model.dto.UpdateDepartmentDTO;
|
|
|
import com.persagy.fm.department.service.IDepartmentService;
|
|
|
import com.persagy.fm.depproject.model.dto.AddDepProjectDTO;
|
|
|
import com.persagy.fm.depproject.service.IDepProjectService;
|
|
|
-import com.persagy.fm.translate.model.Trans;
|
|
|
-import com.persagy.fm.translate.model.TransType;
|
|
|
+import com.persagy.fm.person.model.dto.PageQueryPersonDTO;
|
|
|
+import com.persagy.fm.person.model.vo.ResponsePersonListItemVO;
|
|
|
+import com.persagy.fm.person.service.IPersonService;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -45,21 +47,23 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
implements IDepartmentService {
|
|
|
@Autowired
|
|
|
private IDepProjectService depProjectService;
|
|
|
+ @Autowired
|
|
|
+ private IPersonService personService;
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public Long createDepartment(AddDepartmentDTO addDepartmentDTO) {
|
|
|
+ public String createDepartment(AddDepartmentDTO addDepartmentDTO) {
|
|
|
Department department = saveDepartment(addDepartmentDTO);
|
|
|
|
|
|
// 保存部门和项目的关系
|
|
|
List<String> projectIds = addDepartmentDTO.getProjectIds();
|
|
|
- Long depId = department.getId();
|
|
|
+ String depId = department.getId();
|
|
|
saveDepProject(projectIds, depId);
|
|
|
|
|
|
return depId;
|
|
|
}
|
|
|
|
|
|
- private void saveDepProject(List<String> projectIds, Long depId) {
|
|
|
+ private void saveDepProject(List<String> projectIds, String depId) {
|
|
|
if (CollectionUtils.isEmpty(projectIds)) {
|
|
|
return;
|
|
|
}
|
|
@@ -94,8 +98,8 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
setDefaultValue(department);
|
|
|
|
|
|
// 获取部门的上级部门,拼装部门的全路径
|
|
|
- Long parentId = department.getParentId();
|
|
|
- if (parentId == 0L) {
|
|
|
+ String parentId = department.getParentId();
|
|
|
+ if (DefaultValueConstants.NO_PARENT_ID.equals(parentId)) {
|
|
|
department.setFullPath(department.getName());
|
|
|
} else {
|
|
|
Department parentDep = queryDepartmentDetail(parentId);
|
|
@@ -139,7 +143,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
}
|
|
|
|
|
|
if (department.getParentId() == null) {
|
|
|
- department.setParentId(0L);
|
|
|
+ department.setParentId(DefaultValueConstants.NO_PARENT_ID);
|
|
|
}
|
|
|
|
|
|
department.setCreator(DefaultAppContext.getContext().getAccountId());
|
|
@@ -167,7 +171,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Department queryDepartmentDetail(Long id) {
|
|
|
+ public Department queryDepartmentDetail(String id) {
|
|
|
Department department = getById(id);
|
|
|
if (department == null) {
|
|
|
throw new IllegalArgumentException("查看Department详情时发生异常,找不到要查看的记录,id=" + id);
|
|
@@ -188,7 +192,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
}
|
|
|
department.setModifier(DefaultAppContext.getContext().getAccountId());
|
|
|
updateById(department);
|
|
|
- Long depId = department.getId();
|
|
|
+ String depId = department.getId();
|
|
|
List<String> projectIds = updateDepartmentDTO.getProjectIds();
|
|
|
updateDepProject(projectIds, depId);
|
|
|
}
|
|
@@ -197,11 +201,11 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
* 更新部门关联的项目
|
|
|
*
|
|
|
* @param projectIds 更新后部门关联的项目
|
|
|
- * @param depId 部门id
|
|
|
+ * @param depId 部门id
|
|
|
* @author lixing
|
|
|
* @version V1.0 2021/3/24 10:51 上午
|
|
|
*/
|
|
|
- private void updateDepProject(List<String> projectIds, Long depId) {
|
|
|
+ private void updateDepProject(List<String> projectIds, String depId) {
|
|
|
// 删除之前部门关联的项目
|
|
|
depProjectService.deleteByDepId(depId);
|
|
|
// 插入新的部门关联的项目
|
|
@@ -242,15 +246,8 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
updateBatchById(sonDeps);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 校验部门是否可删除
|
|
|
- *
|
|
|
- * @param id 部门主键
|
|
|
- * @return 部门do类
|
|
|
- * @author lixing
|
|
|
- * @version V1.0 2021/3/12 11:02 上午
|
|
|
- */
|
|
|
- public Department checkDeletable(Long id) {
|
|
|
+ @Override
|
|
|
+ public Department checkDeletable(String id) {
|
|
|
if (id == null) {
|
|
|
throw new IllegalArgumentException("删除Department时发生异常,主键为空!");
|
|
|
}
|
|
@@ -274,17 +271,20 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
throw new IllegalArgumentException("当前部门包含子部门,不可删除");
|
|
|
}
|
|
|
|
|
|
- // TODO: 2021/3/9 部门包含员工时,不可删除
|
|
|
-
|
|
|
+ PageQueryPersonDTO pageQueryPersonDTO = new PageQueryPersonDTO();
|
|
|
+ pageQueryPersonDTO.setDepId(id);
|
|
|
+ IPage<ResponsePersonListItemVO> responsePersonListItemVOIPage = personService.pageQueryPerson(pageQueryPersonDTO);
|
|
|
+ if (responsePersonListItemVOIPage.getTotal() > 0) {
|
|
|
+ throw new IllegalArgumentException("当前部门包含员工,不可删除");
|
|
|
+ }
|
|
|
return department;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void deleteDepartment(Long id) {
|
|
|
+ public void deleteDepartment(String id) {
|
|
|
// 校验部门是否可删除
|
|
|
Department department = checkDeletable(id);
|
|
|
-
|
|
|
department.setValid(ValidEnum.FALSE.getType());
|
|
|
updateById(department);
|
|
|
}
|
|
@@ -363,14 +363,14 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
if (CollectionUtils.isEmpty(parentDeptList)) {
|
|
|
return Lists.newArrayList();
|
|
|
} else {
|
|
|
- List<Long> parentIds = parentDeptList.stream().map(Department::getId).collect(Collectors.toList());
|
|
|
+ List<String> parentIds = parentDeptList.stream().map(Department::getId).collect(Collectors.toList());
|
|
|
List<Department> sonDeps = queryDepListByParentIds(parentIds);
|
|
|
return sonDeps == null ? Lists.newArrayList() : sonDeps;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Department> queryDepListByParentIds(List<Long> parentIds) {
|
|
|
+ public List<Department> queryDepListByParentIds(List<String> parentIds) {
|
|
|
// 拼装查询条件
|
|
|
QueryWrapper<Department> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq(Department.PROP_VALID, ValidEnum.TRUE.getType());
|