diff --git a/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java b/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java new file mode 100644 index 0000000..8a37873 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/common/controller/IOTCommonDataControler.java @@ -0,0 +1,64 @@ +package com.lzbi.common.controller; + +import com.lzbi.common.core.controller.BaseController; +import com.lzbi.common.core.domain.AjaxResult; +import com.lzbi.common.core.domain.entity.SysDept; +import com.lzbi.common.service.IotSysDeptService; +import com.lzbi.common.utils.StringUtils; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.List; + +@RestController +@RequestMapping("/common/iot/dept") +public class IOTCommonDataControler extends BaseController{ + @Resource + IotSysDeptService iotSysDeptService; + /** + * 获取部门列表 + */ + //@PreAuthorize("@ss.hasPermi('system:dept:list')") + @GetMapping("/list") + public AjaxResult list(SysDept dept) + { + List depts = iotSysDeptService.selectDeptList(dept); + return success(depts); + } + + /** + * 查询部门列表(排除节点) + */ + //@PreAuthorize("@ss.hasPermi('system:dept:list')") + @GetMapping("/list/exclude/{deptId}") + public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId) + { + List depts = iotSysDeptService.selectDeptList(new SysDept()); + depts.removeIf(d -> d.getDeptId().intValue() == deptId || ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + "")); + return success(depts); + } + + /** + * 根据部门编号获取详细信息 + */ + //@PreAuthorize("@ss.hasPermi('system:dept:query')") + @GetMapping(value = "/{deptId}") + public AjaxResult getInfo(@PathVariable Long deptId) + { + iotSysDeptService.checkDeptDataScope(deptId); + return success(iotSysDeptService.selectDeptById(deptId)); + } + /** + * 获取部门树列表 + */ + //@PreAuthorize("@ss.hasPermi('system:user:list')") + @GetMapping("/deptTree") + public AjaxResult deptTree(SysDept dept) + { + return success(iotSysDeptService.selectDeptTreeList(dept)); + } +} diff --git a/lzbi-module/src/main/java/com/lzbi/common/mapper/IOTSysDeptMapper.java b/lzbi-module/src/main/java/com/lzbi/common/mapper/IOTSysDeptMapper.java new file mode 100644 index 0000000..a85f1b7 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/common/mapper/IOTSysDeptMapper.java @@ -0,0 +1,131 @@ +package com.lzbi.common.mapper; + +import com.baomidou.mybatisplus.annotation.InterceptorIgnore; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.lzbi.bi.domain.DcBusiDataScreenDto; +import com.lzbi.common.core.domain.entity.SysDept; +import org.apache.ibatis.annotations.Param; + + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * 部门管理 数据层 + * + * @author ruoyi + */@InterceptorIgnore(tenantLine = "true") +public interface IOTSysDeptMapper extends BaseMapper +{ + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + public List selectDeptList(SysDept dept); + + /** + * 根据角色ID查询部门树信息 + * + * @param roleId 角色ID + * @param deptCheckStrictly 部门树选择项是否关联显示 + * @return 选中部门列表 + */ + public List selectDeptListByRoleId(@Param("roleId") Long roleId, @Param("deptCheckStrictly") boolean deptCheckStrictly); + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + public SysDept selectDeptById(Long deptId); + + /** + * 根据ID查询所有子部门 + * + * @param deptId 部门ID + * @return 部门列表 + */ + public List selectChildrenDeptById(Long deptId); + + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + public int selectNormalChildrenDeptById(Long deptId); + + /** + * 是否存在子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + public int hasChildByDeptId(Long deptId); + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 + */ + public int checkDeptExistUser(Long deptId); + + /** + * 校验部门名称是否唯一 + * + * @param deptName 部门名称 + * @param parentId 父部门ID + * @return 结果 + */ + public SysDept checkDeptNameUnique(@Param("deptName") String deptName, @Param("parentId") Long parentId); + + /** + * 新增部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int insertDept(SysDept dept); + + /** + * 修改部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int updateDept(SysDept dept); + + /** + * 修改所在部门正常状态 + * + * @param deptIds 部门ID组 + */ + public void updateDeptStatusNormal(Long[] deptIds); + + /** + * 修改子元素关系 + * + * @param depts 子元素 + * @return 结果 + */ + public int updateDeptChildren(@Param("depts") List depts); + + /** + * 删除部门管理信息 + * + * @param deptId 部门ID + * @return 结果 + */ + public int deleteDeptById(Long deptId); + //add by zhousq 2023-12 根据部门类别筛选部门 + public List selectOrg(Long parentId); + public List selectCompany(Long parentId); + public Map selectDeptMap(); + + List selectDeptListByRoleIds(List ids); +} diff --git a/lzbi-module/src/main/java/com/lzbi/common/service/IotSysDeptService.java b/lzbi-module/src/main/java/com/lzbi/common/service/IotSysDeptService.java new file mode 100644 index 0000000..58ca475 --- /dev/null +++ b/lzbi-module/src/main/java/com/lzbi/common/service/IotSysDeptService.java @@ -0,0 +1,239 @@ +package com.lzbi.common.service; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.extension.service.IService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.lzbi.common.annotation.DataScope; +import com.lzbi.common.constant.UserConstants; +import com.lzbi.common.core.domain.TreeSelect; +import com.lzbi.common.core.domain.entity.SysDept; +import com.lzbi.common.core.domain.entity.SysRole; +import com.lzbi.common.core.domain.entity.SysUser; +import com.lzbi.common.core.text.Convert; +import com.lzbi.common.exception.ServiceException; +import com.lzbi.common.mapper.IOTSysDeptMapper; +import com.lzbi.common.utils.SecurityUtils; +import com.lzbi.common.utils.StringUtils; +import com.lzbi.common.utils.spring.SpringUtils; + +import org.springframework.stereotype.Service; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * 部门管理 服务实现 + * + * @author ruoyi + */ +@DS("workDB") +@Service +public class IotSysDeptService extends ServiceImpl implements IService { + + + /** + * 查询部门管理数据 + * + * @param dept 部门信息 + * @return 部门信息集合 + */ + + @DataScope(deptAlias = "d") + public List selectDeptList(SysDept dept) { + return baseMapper.selectDeptList(dept); + } + + public List selecttList(SysDept dept) { + return baseMapper.selectDeptList(dept); + } + + /** + * 查询部门树结构信息 + * + * @param dept 部门信息 + * @return 部门树信息集合 + */ + + public List selectDeptTreeList(SysDept dept) { + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + return buildDeptTreeSelect(depts); + } + + + public List selectDeptListByRoleIds(List ids) { + return baseMapper.selectDeptListByRoleIds(ids); + } + + /** + * 构建前端所需要树结构 + * + * @param depts 部门列表 + * @return 树结构列表 + */ + + public List buildDeptTree(List depts) { + List returnList = new ArrayList(); + List tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList()); + for (SysDept dept : depts) { + // 如果是顶级节点, 遍历该父节点的所有子节点 + if (!tempList.contains(dept.getParentId())) { + recursionFn(depts, dept); + returnList.add(dept); + } + } + if (returnList.isEmpty()) { + returnList = depts; + } + return returnList; + } + + /** + * 构建前端所需要下拉树结构 + * + * @param depts 部门列表 + * @return 下拉树结构列表 + */ + + public List buildDeptTreeSelect(List depts) { + List deptTrees = buildDeptTree(depts); + return deptTrees.stream().map(TreeSelect::new).collect(Collectors.toList()); + } + + + + /** + * 根据部门ID查询信息 + * + * @param deptId 部门ID + * @return 部门信息 + */ + + public SysDept selectDeptById(Long deptId) { + return baseMapper.selectDeptById(deptId); + } + + /** + * 根据ID查询所有子部门(正常状态) + * + * @param deptId 部门ID + * @return 子部门数 + */ + + public int selectNormalChildrenDeptById(Long deptId) { + return baseMapper.selectNormalChildrenDeptById(deptId); + } + + /** + * 是否存在子节点 + * + * @param deptId 部门ID + * @return 结果 + */ + + public boolean hasChildByDeptId(Long deptId) { + int result = baseMapper.hasChildByDeptId(deptId); + return result > 0; + } + + /** + * 查询部门是否存在用户 + * + * @param deptId 部门ID + * @return 结果 true 存在 false 不存在 + */ + + public boolean checkDeptExistUser(Long deptId) { + int result = baseMapper.checkDeptExistUser(deptId); + return result > 0; + } + + /** + * 校验部门名称是否唯一 + * + * @param dept 部门信息 + * @return 结果 + */ + public boolean checkDeptNameUnique(SysDept dept) { + Long deptId = StringUtils.isNull(dept.getDeptId()) ? -1L : dept.getDeptId(); + SysDept info = baseMapper.checkDeptNameUnique(dept.getDeptName(), dept.getParentId()); + if (StringUtils.isNotNull(info) && info.getDeptId().longValue() != deptId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验部门是否有数据权限 + * + * @param deptId 部门id + */ + public void checkDeptDataScope(Long deptId) { + if (!SysUser.isAdmin(SecurityUtils.getUserId())) { + SysDept dept = new SysDept(); + dept.setDeptId(deptId); + List depts = SpringUtils.getAopProxy(this).selectDeptList(dept); + if (StringUtils.isEmpty(depts)) { + throw new ServiceException("没有权限访问部门数据!"); + } + } + } + + /** + * 新增保存部门信息 + * + * @param dept 部门信息 + * @return 结果 + */ + public int insertDept(SysDept dept) { + SysDept info = baseMapper.selectDeptById(dept.getParentId()); + // 如果父节点不为正常状态,则不允许新增子节点 + if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) { + throw new ServiceException("部门停用,不允许新增"); + } + dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); + return baseMapper.insertDept(dept); + } + + + //获取所有部门的hash映射,便于查询(key :depid,value:deptName) + public Map selectDeptMap(){ + return baseMapper.selectDeptMap(); + } + /** + * 递归列表 + */ + private void recursionFn(List list, SysDept t) { + // 得到子节点列表 + List childList = getChildList(list, t); + t.setChildren(childList); + for (SysDept tChild : childList) { + if (hasChild(list, tChild)) { + recursionFn(list, tChild); + } + } + } + + /** + * 得到子节点列表 + */ + private List getChildList(List list, SysDept t) { + List tlist = new ArrayList(); + Iterator it = list.iterator(); + while (it.hasNext()) { + SysDept n = (SysDept) it.next(); + if (StringUtils.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue()) { + tlist.add(n); + } + } + return tlist; + } + + /** + * 判断是否有子节点 + */ + private boolean hasChild(List list, SysDept t) { + return getChildList(list, t).size() > 0; + } + + +} diff --git a/lzbi-module/src/main/resources/mapper/IOTSysDeptMapper.xml b/lzbi-module/src/main/resources/mapper/IOTSysDeptMapper.xml new file mode 100644 index 0000000..a5eeefa --- /dev/null +++ b/lzbi-module/src/main/resources/mapper/IOTSysDeptMapper.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + select d.dept_id, d.parent_id, d.ancestors, d.dept_name, d.order_num, d.leader, d.phone, d.email, d.status, d.del_flag, d.create_by, d.create_time,d.short_name,d.all_name,d.org_type + from sys_dept d + + + + + + + + + + + + + + + + + + + + + + + + + + insert into sys_dept( + dept_id, + parent_id, + dept_name, + ancestors, + order_num, + leader, + phone, + email, + status, + create_by, + short_name, + all_name, + org_type, + create_time + )values( + #{deptId}, + #{parentId}, + #{deptName}, + #{ancestors}, + #{orderNum}, + #{leader}, + #{phone}, + #{email}, + #{status}, + #{createBy}, + #{shortName}, + #{allName}, + #{orgType}, + sysdate() + ) + + + + update sys_dept + + parent_id = #{parentId}, + dept_name = #{deptName}, + ancestors = #{ancestors}, + order_num = #{orderNum}, + leader = #{leader}, + phone = #{phone}, + email = #{email}, + status = #{status}, + update_by = #{updateBy}, + short_name = #{shortName}, + all_name = #{allName}, + org_type = #{orgType}, + update_time = sysdate() + + where dept_id = #{deptId} + + + + update sys_dept set ancestors = + + when #{item.deptId} then #{item.ancestors} + , + all_name = + + when #{item.deptId} then #{item.allName} + + where dept_id in + + #{item.deptId} + + + + + update sys_dept set status = '0' where dept_id in + + #{deptId} + + + + + update sys_dept set del_flag = '2' where dept_id = #{deptId} + + + \ No newline at end of file