| | |
| | | package com.ruoyi.system.service.impl.sys; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | import com.ruoyi.common.core.exception.ServiceException; |
| | | import com.ruoyi.common.core.text.Convert; |
| | |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.datascope.annotation.DataScope; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.domain.SysDept; |
| | | import com.ruoyi.system.api.domain.SysRole; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysDept; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysRole; |
| | | import com.ruoyi.system.api.domain.poji.sys.SysUser; |
| | | import com.ruoyi.system.domain.pojo.sys.SysDeptMenu; |
| | | import com.ruoyi.system.domain.vo.TreeSelect; |
| | | import com.ruoyi.system.mapper.sys.SysDeptMapper; |
| | | import com.ruoyi.system.mapper.sys.SysDeptMenuMapper; |
| | | import com.ruoyi.system.mapper.sys.SysRoleMapper; |
| | | import com.ruoyi.system.service.staff.SysWxCpService; |
| | | import com.ruoyi.system.service.sys.ISysDeptService; |
| | | import me.chanjar.weixin.common.error.WxErrorException; |
| | | import me.chanjar.weixin.cp.api.WxCpDepartmentService; |
| | | import me.chanjar.weixin.cp.api.WxCpService; |
| | | import me.chanjar.weixin.cp.bean.WxCpDepart; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.ArrayList; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 部门管理 服务实现 |
| | | * |
| | | * @author ruoyi |
| | | * @author jqs |
| | | */ |
| | | @Service |
| | | public class SysDeptServiceImpl implements ISysDeptService |
| | | { |
| | | @Autowired |
| | | @Resource |
| | | private SysDeptMapper deptMapper; |
| | | |
| | | @Autowired |
| | | @Resource |
| | | private SysRoleMapper roleMapper; |
| | | |
| | | @Resource |
| | | private SysDeptMenuMapper deptMenuMapper; |
| | | |
| | | @Resource |
| | | private SysWxCpService sysWxCpService; |
| | | |
| | | @Resource |
| | | @Qualifier("wxService") |
| | | private WxCpService wxCpService; |
| | | |
| | | |
| | | /** |
| | | * 查询部门管理数据 |
| | |
| | | throw new ServiceException("部门停用,不允许新增"); |
| | | } |
| | | dept.setAncestors(info.getAncestors() + "," + dept.getParentId()); |
| | | return deptMapper.insertDept(dept); |
| | | Long wxDeptId = sysWxCpService.addWxCpDept(1L,dept.getDeptName()); |
| | | dept.setWxDeptId(wxDeptId); |
| | | //新增部门 |
| | | int i = deptMapper.insertDept(dept); |
| | | if(dept.getMenuIds()!=null||dept.getStaffMenuIds()!=null){ |
| | | return insertDeptMenu(dept); |
| | | }else{ |
| | | return i; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 新增角色菜单信息 |
| | | * |
| | | * @param dept 部门对象 |
| | | */ |
| | | public int insertDeptMenu(SysDept dept) |
| | | { |
| | | int rows = 1; |
| | | // 新增用户与角色管理 |
| | | List<SysDeptMenu> list = new ArrayList<SysDeptMenu>(); |
| | | for (Long menuId : dept.getMenuIds()) |
| | | { |
| | | SysDeptMenu rm = new SysDeptMenu(); |
| | | rm.setDeptId(dept.getDeptId()); |
| | | rm.setMenuId(menuId); |
| | | rm.setMenuFrom(1); |
| | | list.add(rm); |
| | | } |
| | | for(Long menuId : dept.getStaffMenuIds()){ |
| | | SysDeptMenu rm = new SysDeptMenu(); |
| | | rm.setDeptId(dept.getDeptId()); |
| | | rm.setMenuId(menuId); |
| | | rm.setMenuFrom(2); |
| | | list.add(rm); |
| | | } |
| | | if (list.size() > 0) |
| | | { |
| | | rows = deptMenuMapper.batchDeptMenu(list); |
| | | } |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | |
| | | dept.setAncestors(newAncestors); |
| | | updateDeptChildren(dept.getDeptId(), newAncestors, oldAncestors); |
| | | } |
| | | if(oldDept.getWxDeptId()!=null&&!oldDept.getDeptName().equals(dept.getDeptName())){ |
| | | sysWxCpService.updateWxCpDept(oldDept.getWxDeptId(),dept.getDeptName()); |
| | | } |
| | | int result = deptMapper.updateDept(dept); |
| | | if (UserConstants.DEPT_NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors()) |
| | | && !StringUtils.equals("0", dept.getAncestors())) |
| | |
| | | // 如果该部门是启用状态,则启用该部门的所有上级部门 |
| | | updateParentDeptStatusNormal(dept); |
| | | } |
| | | // 删除角色与菜单关联 |
| | | deptMenuMapper.deleteDeptMenuByDeptId(dept.getDeptId()); |
| | | insertDeptMenu(dept); |
| | | return result; |
| | | } |
| | | |
| | |
| | | { |
| | | return getChildList(list, t).size() > 0 ? true : false; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @description 通过微信部门id获取部门 |
| | | * @author jqs |
| | | * @date 2023/8/17 16:21 |
| | | * @param wxDeptId |
| | | * @return SysDept |
| | | */ |
| | | @Override |
| | | public SysDept getByWxDeptId(Long wxDeptId){ |
| | | return deptMapper.getByWxDeptId(wxDeptId); |
| | | } |
| | | |
| | | /** |
| | | * @description 同步部门 |
| | | * @author jqs |
| | | * @date 2023/8/17 15:42 |
| | | * @param |
| | | * @return void |
| | | */ |
| | | @Override |
| | | public void syncDepartment(){ |
| | | WxCpDepartmentService wxCpDepartmentService = wxCpService.getDepartmentService(); |
| | | try { |
| | | //从企业微信拉去部门名单 |
| | | List<WxCpDepart> wxCpDepartList = wxCpDepartmentService.list(null); |
| | | if(wxCpDepartList!=null&&wxCpDepartList.size()>0){ |
| | | for(WxCpDepart wxCpDepart : wxCpDepartList){ |
| | | if(wxCpDepart.getParentId().compareTo(24L)<0){ |
| | | //获取系统内对应部门 |
| | | SysDept sysDept = this.getByWxDeptId(wxCpDepart.getId()); |
| | | //判断是否有该部门,没有则新建 |
| | | if(sysDept!=null){ |
| | | //判断是否有变化 |
| | | if(!sysDept.getDeptName().equals(wxCpDepart.getName())||sysDept.getOrderNum()!=wxCpDepart.getOrder().intValue()){ |
| | | sysDept.setDeptName(wxCpDepart.getName()); |
| | | sysDept.setOrderNum(wxCpDepart.getOrder().intValue()); |
| | | sysDept.setUpdateBy("企业微信同步"); |
| | | this.updateDept(sysDept); |
| | | } |
| | | }else{ |
| | | sysDept = new SysDept(); |
| | | sysDept.setDelFlag("0"); |
| | | sysDept.setStatus("0"); |
| | | sysDept.setParentId(100L); |
| | | sysDept.setOrderNum(wxCpDepart.getOrder().intValue()); |
| | | sysDept.setCreateBy("企业微信同步"); |
| | | sysDept.setDeptName(wxCpDepart.getName()); |
| | | sysDept.setWxDeptId(wxCpDepart.getId()); |
| | | this.insertDept(sysDept); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (WxErrorException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | } |