package com.ruoyi.station.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.stream.Collectors;
|
|
import com.ruoyi.common.constant.UserConstants;
|
import com.ruoyi.common.core.domain.Ztree;
|
import com.ruoyi.common.utils.DateUtils;
|
import com.ruoyi.common.utils.IdUtils;
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.station.domain.MjWorkUser;
|
import com.ruoyi.system.domain.SysDept;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import com.ruoyi.station.mapper.MjDeptMapper;
|
import com.ruoyi.station.domain.MjDept;
|
import com.ruoyi.station.service.IMjDeptService;
|
import com.ruoyi.common.core.text.Convert;
|
|
/**
|
* 部门Service业务层处理
|
*
|
* @author ruoyi
|
* @date 2020-08-07
|
*/
|
@Service
|
public class MjDeptServiceImpl implements IMjDeptService
|
{
|
@Autowired
|
private MjDeptMapper mjDeptMapper;
|
|
/**
|
* 查询部门
|
*
|
* @param id 部门ID
|
* @return 部门
|
*/
|
@Override
|
public MjDept selectMjDeptById(String id)
|
{
|
|
MjDept mjDept = mjDeptMapper.selectMjDeptByIdorName(id,null);
|
if(mjDept.getDelFlag()==1){
|
return null;
|
}else {
|
return mjDept;
|
}
|
}
|
|
/**
|
* 查询部门列表
|
*
|
* @param mjDept 部门
|
* @return 部门
|
*/
|
@Override
|
public List<MjDept> selectMjDeptList(MjDept mjDept)
|
{
|
|
List<MjDept> mjDepts = mjDeptMapper.selectMjDeptList(mjDept);
|
List<MjDept> list = mjDepts.parallelStream()
|
.filter(mjDepts1 -> mjDepts1.getDelFlag() == 0)
|
.collect(Collectors.toList());
|
return list;
|
}
|
|
/**
|
* 新增部门
|
*
|
* @param mjDept 部门
|
* @return 结果
|
*/
|
@Override
|
public int insertMjDept(MjDept mjDept)
|
{
|
mjDept.setCreateTime(DateUtils.getNowDate());
|
mjDept.setUpdateTime(DateUtils.getNowDate());
|
mjDept.setId(IdUtils.getUUIDInOrderId()+"");
|
if(mjDept.getDelFlag()==null){
|
mjDept.setDelFlag(0);
|
}
|
return mjDeptMapper.insertMjDept(mjDept);
|
}
|
|
/**
|
* 修改部门
|
*
|
* @param mjDept 部门
|
* @return 结果
|
*/
|
@Override
|
public int updateMjDept(MjDept mjDept)
|
{
|
mjDept.setUpdateTime(DateUtils.getNowDate());
|
return mjDeptMapper.updateMjDept(mjDept);
|
}
|
|
/**
|
* 删除部门对象
|
*
|
* @param ids 需要删除的数据ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteMjDeptByIds(String ids)
|
{
|
|
int count=0;
|
String[] strings = Convert.toStrArray(ids);
|
for (String string : strings) {
|
MjDept mjDept = mjDeptMapper.selectMjDeptByIdorName(string,null);
|
mjDept.setDelFlag(1);
|
mjDeptMapper.updateMjDept(mjDept);
|
count++;
|
}
|
return count;
|
}
|
|
/**
|
* 删除部门信息
|
*
|
* @param id 部门ID
|
* @return 结果
|
*/
|
@Override
|
public int deleteMjDeptById(String id)
|
{
|
|
MjDept mjDept = mjDeptMapper.selectMjDeptByIdorName(id,null);
|
mjDept.setDelFlag(1);
|
return mjDeptMapper.updateMjDept(mjDept);
|
}
|
|
/**
|
* 校验部门名称是否唯一
|
*
|
* @param dept 部门信息
|
* @return 结果
|
*/
|
@Override
|
public String checkDeptNameUnique(MjDept dept) {
|
String deptId = StringUtils.isNull(dept.getId()) ? "" : dept.getId();
|
MjDept info = mjDeptMapper.checkDeptNameUnique(dept.getDeptName(), dept.getDeptParentId());
|
if (StringUtils.isNotNull(info) && !info.getId().equals(deptId))
|
{
|
return UserConstants.DEPT_NAME_NOT_UNIQUE;
|
}
|
return UserConstants.DEPT_NAME_UNIQUE;
|
}
|
|
@Override
|
public List<Ztree> selectDeptTree(MjDept mjDept) {
|
List<MjDept> mjDepts = mjDeptMapper.selectMjDeptList(mjDept);
|
List<Ztree> ztrees = initZtree(mjDepts);
|
return ztrees;
|
}
|
|
/**
|
* 对象转部门树
|
*
|
* @param deptList 部门列表
|
* @return 树结构列表
|
*/
|
public List<Ztree> initZtree(List<MjDept> deptList)
|
{
|
return initZtree(deptList, null);
|
}
|
|
/**
|
* 对象转部门树
|
*
|
* @param deptList 部门列表
|
* @param roleDeptList 角色已存在菜单列表
|
* @return 树结构列表
|
*/
|
public List<Ztree> initZtree(List<MjDept> deptList, List<String> roleDeptList)
|
{
|
|
List<Ztree> ztrees = new ArrayList<Ztree>();
|
boolean isCheck = StringUtils.isNotNull(roleDeptList);
|
for (MjDept dept : deptList)
|
{
|
if (UserConstants.DEPT_NORMAL.equals(dept.getDelFlag()+""))
|
{
|
Ztree ztree = new Ztree();
|
ztree.setId(Long.parseLong(dept.getId()));
|
ztree.setpId(Long.parseLong(dept.getDeptParentId()));
|
ztree.setName(dept.getDeptName());
|
ztree.setTitle(dept.getDeptName());
|
if (isCheck)
|
{
|
ztree.setChecked(roleDeptList.contains(dept.getId() + dept.getDeptName()));
|
}
|
ztrees.add(ztree);
|
}
|
}
|
return ztrees;
|
}
|
|
}
|