123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- package com.ruoyi.project.system.dept.service;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import com.ruoyi.common.constant.UserConstants;
- import com.ruoyi.common.utils.StringUtils;
- import com.ruoyi.common.utils.security.ShiroUtils;
- import com.ruoyi.project.system.dept.domain.Dept;
- import com.ruoyi.project.system.dept.mapper.DeptMapper;
- /**
- * 部门管理 服务实现
- *
- * @author ruoyi
- */
- @Service
- public class DeptServiceImpl implements IDeptService
- {
- @Autowired
- private DeptMapper deptMapper;
- /**
- * 查询部门管理数据
- *
- * @return 部门信息集合
- */
- @Override
- public List<Dept> selectDeptList(Dept dept)
- {
- return deptMapper.selectDeptList(dept);
- }
- /**
- * 查询部门所有数据
- *
- * @return 部门信息集合
- */
- @Override
- public List<Dept> selectDeptAll()
- {
- return deptMapper.selectDeptAll();
- }
- /**
- * 查询部门管理树
- *
- * @return 所有部门信息
- */
- @Override
- public List<Map<String, Object>> selectDeptTree()
- {
- List<Map<String, Object>> trees = new ArrayList<Map<String, Object>>();
- List<Dept> deptList = deptMapper.selectDeptAll();
- for (Dept dept : deptList)
- {
- if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()))
- {
- Map<String, Object> deptMap = new HashMap<String, Object>();
- deptMap.put("id", dept.getDeptId());
- deptMap.put("pId", dept.getParentId());
- deptMap.put("name", dept.getDeptName());
- deptMap.put("title", dept.getDeptName());
- trees.add(deptMap);
- }
- }
- return trees;
- }
- /**
- * 查询部门人数
- *
- * @param parentId 部门ID
- * @return 结果
- */
- @Override
- public int selectDeptCount(Long parentId)
- {
- Dept dept = new Dept();
- dept.setParentId(parentId);
- return deptMapper.selectDeptCount(dept);
- }
- /**
- * 查询部门是否存在用户
- *
- * @param deptId 部门ID
- * @return 结果 true 存在 false 不存在
- */
- @Override
- public boolean checkDeptExistUser(Long deptId)
- {
- int result = deptMapper.checkDeptExistUser(deptId);
- return result > 0 ? true : false;
- }
- /**
- * 删除部门管理信息
- *
- * @param deptId 部门ID
- * @return 结果
- */
- @Override
- public int deleteDeptById(Long deptId)
- {
- return deptMapper.deleteDeptById(deptId);
- }
- /**
- * 新增保存部门信息
- *
- * @param dept 部门信息
- * @return 结果
- */
- @Override
- public int insertDept(Dept dept)
- {
- Dept info = deptMapper.selectDeptById(dept.getParentId());
- dept.setCreateBy(ShiroUtils.getLoginName());
- dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
- return deptMapper.insertDept(dept);
- }
- /**
- * 修改保存部门信息
- *
- * @param dept 部门信息
- * @return 结果
- */
- @Override
- public int updateDept(Dept dept)
- {
- Dept info = deptMapper.selectDeptById(dept.getParentId());
- dept.setUpdateBy(ShiroUtils.getLoginName());
- dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
- return deptMapper.updateDept(dept);
- }
- /**
- * 根据部门ID查询信息
- *
- * @param deptId 部门ID
- * @return 部门信息
- */
- @Override
- public Dept selectDeptById(Long deptId)
- {
- return deptMapper.selectDeptById(deptId);
- }
- /**
- * 校验部门名称是否唯一
- *
- * @param dept 部门信息
- * @return 结果
- */
- @Override
- public String checkDeptNameUnique(Dept dept)
- {
- Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId();
- Dept info = deptMapper.checkDeptNameUnique(dept.getDeptName());
- if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue())
- {
- return UserConstants.DEPT_NAME_NOT_UNIQUE;
- }
- return UserConstants.DEPT_NAME_UNIQUE;
- }
- }
|