Commit 68bebef9 authored by chenyuxi's avatar chenyuxi

feat: 部门相关接口

parent 7c44e233
......@@ -51,4 +51,11 @@ public class UserDTO extends SysUser {
*/
private String newpassword1;
/**
* 姓名或者手机号搜索
* chenyuxi
* @since 1.9.7
*/
private String nameOrPhone;
}
......@@ -35,7 +35,7 @@ public class SysUserDeptPermission extends Model<SysUserDeptPermission> {
private static final long serialVersionUID = 1L;
@TableId(value = "user_id", type = IdType.ASSIGN_ID)
@TableId(value = "id", type = IdType.ASSIGN_ID)
@Schema(description = "主键id")
private String id;
......
package com.yifu.cloud.plus.v1.yifu.admin.api.vo;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;
/**
* 客户服务平台——部门树
*
* @author chenyuxi
* @since 1.9.7
*/
@Data
public class DeptTreeSelectVO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 部门ID
*/
private Long deptId;
/**
* 父部门ID
*/
private Long parentId;
/**
* 祖级列表
*/
private String ancestors;
/**
* 部门名称
*/
private String name;
/**
* 父部门名称
*/
private String parentName;
/**
* 部门总人数
*/
private String peopleNum;
private List<DeptTreeSelectVO> children;
public DeptTreeSelectVO(SysDeptVo dept) {
this.deptId = dept.getDeptId();
this.parentId = dept.getParentId();
this.ancestors = dept.getAncestors();
this.name = dept.getName();
this.parentName = dept.getParentName();
this.peopleNum =dept.getPeopleNum();
if(dept.getChildren() != null){
this.children = dept.getChildren().stream().map(DeptTreeSelectVO::new).collect(Collectors.toList());
}
}
}
package com.yifu.cloud.plus.v1.yifu.admin.api.vo;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 客户服务平台——部门包装类
*
* @author chenyuxi
* @since 1.9.7
*/
@Data
public class SysDeptVo extends SysDept {
/** 子部门 */
private List<SysDeptVo> children;
/**
* 父部门名称
*/
private String parentName;
/**
* 部门人数
*/
private String peopleNum;
}
......@@ -18,7 +18,10 @@ package com.yifu.cloud.plus.v1.yifu.admin.controller;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.DeptTreeSelectVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
......@@ -154,4 +157,95 @@ public class DeptController {
public R innerUpdateDeptByLdap() {
return R.ok(sysDeptService.updateDeptByLdap());
}
/**
* 客户服务平台——获取部门树(用于下拉选择)
* @return 树形菜单
*/
@GetMapping(value = "/csp/list")
public R<List<DeptTreeSelectVO>> cspList(SysDeptVo dept) {
if(Common.isEmpty(dept.getProjectNo())){
R.failed("项目编码不能为空");
}
return R.ok(sysDeptService.cspDeptTreeSelect(dept));
}
/**
* 客户服务平台——获取部门树(带部门下人数)
* @return 树形菜单
*/
@GetMapping(value = "/csp/tree")
public R<List<DeptTreeSelectVO>> cspTree(SysDeptVo dept) {
if(Common.isEmpty(dept.getProjectNo())){
R.failed("项目编码不能为空");
}
return R.ok(sysDeptService.cspDeptTree(dept));
}
/**
* 客户服务平台——添加部门
* @param sysDept 实体
* @return success/false
*/
@SysLog("客户服务平台——添加部门")
@PostMapping("/csp")
public R<String> saveCspDept(@RequestBody SysDept sysDept) {
if(Common.isEmpty(sysDept.getProjectNo())){
R.failed("项目编码不能为空");
}
// todo 名字长度
if(Common.isEmpty(sysDept.getName())){
R.failed("部门名称不能为空");
}
// 父级不传,默认增顶级部门
if (Common.isEmpty(sysDept.getParentId())){
sysDept.setParentId(0L);
}
return sysDeptService.saveCspDept(sysDept);
}
/**
* 客户服务平台——编辑部门
* @param sysDept 实体
* @return success/false
*/
@SysLog("客户服务平台——编辑部门")
@PutMapping("/csp")
public R<String> updateCspDept(@RequestBody SysDept sysDept) {
if(Common.isEmpty(sysDept.getDeptId())){
R.failed("ID不能为空");
}
if(Common.isEmpty(sysDept.getName())){
R.failed("部门名称不能为空");
}
return sysDeptService.updateCspDept(sysDept);
}
/**
* 删除
* @param id ID
* @return success/false
*/
@SysLog("客户服务平台——删除部门")
@DeleteMapping("/csp/{id:\\d+}")
public R<String> removeCspDeptById(@PathVariable Long id) {
if(Common.isEmpty(id)){
R.failed("项目Id不能为空");
}
return sysDeptService.removeCspDeptById(id);
}
/**
* 客户服务平台——获取项目下部门总数
* @return R<Integer> 部门总数
*/
@GetMapping(value = "/csp/getDeptCount/{projectNo}")
public R<Integer> cspDeptCount(@PathVariable String projectNo) {
if(Common.isEmpty(projectNo)){
R.failed("项目编码不能为空");
}
return R.ok(sysDeptService.cspDeptCount(projectNo));
}
}
......@@ -597,7 +597,7 @@ public class UserController {
* @param userByApprovalRole
* @author chenyuxi
* @date 2025-01-10 17:47:32
* @since 1.7.5
* @since 1.9.5
**/
@Inner
@PostMapping("/inner/getUser/getUserByRoleIdForCrm")
......@@ -623,4 +623,19 @@ public class UserController {
public Boolean selectExitDeptCompany(@RequestBody String deptId) {
return userService.selectExitDeptCompany(deptId);
}
/**
* 分页查询系统里所有用户
*
* @param page 参数集
* @param userDTO 查询参数列表
* @return 用户集合
*
* @author chenyuxi
* @since 1.9.7
*/
@GetMapping("/allUserPage")
public R<IPage<SysUser>> getAllUserPage(Page page, UserDTO userDTO) {
return R.ok(userService.getAllUserPage(page, userDTO));
}
}
/*
* Copyright (c) 2020 yifu4cloud Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.yifu.cloud.plus.v1.yifu.admin.controller;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUserDeptPermission;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.DeptTreeSelectVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptService;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysUserDeptPermissionService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.annotation.Inner;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;
/**
* 项目下用户部门及权限
*
* @author chenyuxi
* @since 1.9.7
*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/userDeptPermission")
@Tag(name = "项目下用户部门及权限")
public class UserDeptPermissionController {
private final SysUserDeptPermissionService sysUserDeptPermissionService;
/**
* 客户服务平台——用户权限控制
* @param sysUserDeptPermission 实体
* @return success/false
*/
@SysLog("客户服务平台——用户权限控制")
@PostMapping("/permission")
public R<String> saveUserPermission(@RequestBody SysUserDeptPermission sysUserDeptPermission) {
if(Common.isEmpty(sysUserDeptPermission.getProjectNo())){
R.failed("项目编码不能为空");
}
if(Common.isEmpty(sysUserDeptPermission.getUserId())){
R.failed("用户ID不能为空");
}
if (Common.isEmpty(sysUserDeptPermission.getPermissionsType())){
R.failed("数据权限不能为空");
}
if (CommonConstants.THREE_STRING.equals(sysUserDeptPermission.getPermissionsType())
&& Common.isEmpty(sysUserDeptPermission.getAppointDeptScope())
){
R.failed("指定部门时,部门范围不能为空");
}
return sysUserDeptPermissionService.saveUserPermission(sysUserDeptPermission);
}
/**
* 客户服务平台——绑定项目
* @param sysUserDeptPermission 实体
* @return success/false
*/
@SysLog("客户服务平台——绑定项目")
@PostMapping("/relation")
public R<String> relationUser(@RequestBody SysUserDeptPermission sysUserDeptPermission) {
if(Common.isEmpty(sysUserDeptPermission.getProjectNo())){
R.failed("项目编码不能为空");
}
if(Common.isEmpty(sysUserDeptPermission.getUserId())){
R.failed("用户ID不能为空");
}
if (Common.isEmpty(sysUserDeptPermission.getDeptId())){
R.failed("部门ID不能为空");
}
return sysUserDeptPermissionService.relationUser(sysUserDeptPermission);
}
}
......@@ -18,6 +18,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
......@@ -47,4 +48,43 @@ public interface SysDeptMapper extends BaseMapper<SysDept> {
SysDept selectDeptDn(@Param("deptDn")String deptDn);
List<SysDept> getDeptListByDeptId(@Param("deptIdSplit") String deptIdSplit, @Param("deptId") Long deptId);
/**
* 客户服务平台——查询部门管理数据
*
* @param dept 部门信息
*/
List<SysDeptVo> cspDeptList(@Param("dept") SysDeptVo dept);
/**
* 客户服务平台——查询部门管理数据(带部门下人数)
*
*/
List<SysDeptVo> cspDeptUserList(@Param("dept") SysDeptVo dept);
/**
* 客户服务平台——查询同项目下同级部门
*
*/
SysDept checkDeptNameUnique(@Param("projectNo") String projectNo, @Param("deptName") String deptName, @Param("parentId") Long parentId);
/**
* 客户服务平台——是否存在子节点
*
* @param deptId 部门ID
* @return 结果
*/
int hasChildByDeptId(@Param("deptId") Long deptId);
/**
* 客户服务平台——查询部门是否存在用户
*
* @param deptId 部门ID
* @return 结果
*/
int checkDeptExistUser(@Param("deptId") Long deptId);
int cspDeptCount(@Param("projectNo") String projectNo);
}
......@@ -83,4 +83,20 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
List<SysUser> getUserManagerByUpDepartIdUp(@Param("departId") Integer departId, @Param("roleId")String roleId);
String selectExitDeptCompany(@Param("deptId") String deptId);
/**
* 分页查询系统里所有用户
* @param page 分页
* @param userDTO 查询参数
* @return list
*/
IPage<SysUser> getAllUserPage(Page page, @Param("query") UserDTO userDTO);
/**
* 分页查询系统里所有用户(带或查询的条件)
* @param page 分页
* @param userDTO 查询参数
* @return list
*/
IPage<SysUser> getAllUserPageWhere(Page page, @Param("query") UserDTO userDTO);
}
......@@ -19,6 +19,8 @@ package com.yifu.cloud.plus.v1.yifu.admin.service;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.DeptTreeSelectVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import java.util.List;
......@@ -79,4 +81,53 @@ public interface SysDeptService extends IService<SysDept> {
* @return R
*/
R updateDeptByLdap();
/**
* 客户服务平台——获取部门树(用于下拉选择)
*
* @param dept 部门信息
* @return 下拉树结构列表
*/
List<DeptTreeSelectVO> cspDeptTreeSelect(SysDeptVo dept);
/**
* 客户服务平台——获取部门树(带部门下人数)
*
* @param dept 部门信息
* @return 部门树列表
*/
List<DeptTreeSelectVO> cspDeptTree(SysDeptVo dept);
/**
* 客户服务平台——添加部门
*
* @param dept 部门信息
* @return 结果
*/
R<String> saveCspDept(SysDept dept);
/**
* 客户服务平台——编辑部门
*
* @param dept 部门信息
* @return 结果
*/
R<String> updateCspDept(SysDept dept);
/**
* 客户服务平台——删除部门
*
* @param id 部门id
* @return 结果
*/
R<String> removeCspDeptById(Long id);
/**
* 客户服务平台——获取项目下部门总数
*
* @param projectNo 项目编码
* @return R<Integer> 部门总数
*/
Integer cspDeptCount(String projectNo);
}
......@@ -19,6 +19,7 @@ package com.yifu.cloud.plus.v1.yifu.admin.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUserDeptPermission;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserPermissionVo;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import java.util.Map;
......@@ -47,4 +48,18 @@ public interface SysUserDeptPermissionService extends IService<SysUserDeptPermis
*/
Map<String, UserPermissionVo> getUserPermissionFlush(String userId);
/**
* 客户服务平台——用户权限控制
* @param sysUserDeptPermission 实体
* @return success/false
*/
R<String> saveUserPermission(SysUserDeptPermission sysUserDeptPermission);
/**
* 客户服务平台——绑定项目
* @param sysUserDeptPermission 实体
* @return success/false
*/
R<String> relationUser(SysUserDeptPermission sysUserDeptPermission);
}
......@@ -192,4 +192,17 @@ public interface SysUserService extends IService<SysUser> {
Boolean selectExitDeptCompany(String deptId);
/**
* 分页查询系统里所有用户
*
* @param page 参数集
* @param userDTO 查询参数列表
* @return 用户集合
*
* @author chenyuxi
* @since 1.9.7
*/
IPage<SysUser> getAllUserPage(Page page, UserDTO userDTO);
}
......@@ -20,26 +20,34 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.unboundid.ldap.sdk.SearchResultEntry;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDeptRelation;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.DeptTreeSelectVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDeptMapper;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysUserMapper;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptRelationService;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysDeptService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.ldap.util.LdapUtil;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -269,4 +277,236 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
}
return R.ok();
}
/**
* 客户服务平台——获取部门树(用于下拉选择)
*
* @param dept 部门信息
* @return 下拉树结构列表
*/
@Override
public List<DeptTreeSelectVO> cspDeptTreeSelect(SysDeptVo dept) {
List<DeptTreeSelectVO> cspDeptTree = new ArrayList<>();
// 获取部门列表
List<SysDeptVo> sysDeptList = baseMapper.cspDeptList(dept);
if(Common.isNotNull(sysDeptList)){
// 组装部门树
List<SysDeptVo> deptTrees = buildDeptTree(sysDeptList);
if(Common.isNotNull(deptTrees)){
// 数据库查到的对象到视图对象的映射
cspDeptTree = deptTrees.stream().map(DeptTreeSelectVO::new).collect(Collectors.toList());
}
}
return cspDeptTree;
}
/**
* 客户服务平台——获取部门树(带部门下人数)
*
* @return 部门树列表
*/
@Override
public List<DeptTreeSelectVO> cspDeptTree(SysDeptVo dept) {
List<DeptTreeSelectVO> cspDeptTree = new ArrayList<>();
// 获取部门列表带用户数量
List<SysDeptVo> sysDeptList = baseMapper.cspDeptUserList(dept);
if(Common.isNotNull(sysDeptList)){
// 组装部门树
List<SysDeptVo> deptTrees = buildDeptTree(sysDeptList);
if(Common.isNotNull(sysDeptList)){
// 数据库查到的对象到视图对象的映射
cspDeptTree = deptTrees.stream().map(DeptTreeSelectVO::new).collect(Collectors.toList());
}
}
return cspDeptTree;
}
/**
* 客户服务平台——组装部门树
*
* @param sysDeptList 部门列表
* @return 下拉树结构列表
*/
private List<SysDeptVo> buildDeptTree(List<SysDeptVo> sysDeptList) {
List<SysDeptVo> returnList = new ArrayList<>();
List<Long> tempDeptIdList = new ArrayList<>();
for (SysDeptVo dept : sysDeptList) {
tempDeptIdList.add(dept.getDeptId());
}
for (Iterator<SysDeptVo> iterator = sysDeptList.iterator(); iterator.hasNext();) {
SysDeptVo dept = (SysDeptVo) iterator.next();
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempDeptIdList.contains(dept.getParentId())) {
// 遍历该父节点的所有子节点
recursionFn(sysDeptList, dept);
returnList.add(dept);
}
}
if (Common.isEmpty(returnList)) {
returnList = sysDeptList;
}
return returnList;
}
/**
* 递归列表
*/
private void recursionFn(List<SysDeptVo> list, SysDeptVo t) {
// 得到子节点列表
List<SysDeptVo> childList = getChildList(list, t);
t.setChildren(childList);
for (SysDeptVo tChild : childList) {
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
}
int i = 0;
int i1= 0;
if(Common.isNotNull(tChild.getPeopleNum())){
i =Integer.parseInt(tChild.getPeopleNum());
}
if(Common.isNotNull(t.getPeopleNum())){
i1=Integer.parseInt(t.getPeopleNum());
}
int i2=i+i1;
String i3=String.valueOf(i2);
t.setPeopleNum(i3);
}
}
/**
* 得到子节点列表
*/
private List<SysDeptVo> getChildList(List<SysDeptVo> list, SysDeptVo t)
{
List<SysDeptVo> tlist = new ArrayList<>();
Iterator<SysDeptVo> it = list.iterator();
while (it.hasNext())
{
SysDeptVo n = (SysDeptVo) it.next();
if (Common.isNotNull(n.getParentId()) && n.getParentId().longValue() == t.getDeptId().longValue())
{
tlist.add(n);
}
}
return tlist;
}
/**
* 判断是否有子节点
*/
private boolean hasChild(List<SysDeptVo> list, SysDeptVo t)
{
return getChildList(list, t).size() > 0 ? true : false;
}
/**
* 客户服务平台——添加部门
*
* @param dept 部门信息
* @return 结果
*/
@Override
public R<String> saveCspDept(SysDept dept) {
if (Common.isEmpty(dept.getParentId())){
dept.setParentId(0L);
}
SysDept nameInfo = baseMapper.checkDeptNameUnique(dept.getProjectNo(),dept.getName(), dept.getParentId());
if (Common.isNotNull(nameInfo)) {
return R.failed("已存在同级同名部门");
}
if(0L == dept.getParentId()){
LambdaQueryWrapper<SysDept> deptQuery = Wrappers.<SysDept>lambdaQuery()
.eq(SysDept::getParentId, 0L)
.eq(SysDept::getProjectNo, dept.getProjectNo())
.eq(SysDept::getDelFlag, CommonConstants.ZERO_STRING)
.last(" limit 1 ");
SysDept firstInfo = baseMapper.selectOne(deptQuery);
if (Common.isNotNull(firstInfo)) {
return R.failed("一个项目下只能有一个顶级部门");
}
}
// 新增部门
if(0L == dept.getParentId()){
dept.setAncestors(CommonConstants.ZERO_STRING);
} else {
if(Common.isNotNull(dept.getParentId())){
SysDept info = baseMapper.selectById(dept.getParentId());
if (Common.isEmpty(info)) {
return R.failed("父级部门未找到");
}
if (Common.isNotNull(info.getAncestors())){
String[] split = info.getAncestors().split(",");
if (split.length >= 6){
return R.failed("添加部门的层级超出限制,最多支持5级");
}
}
dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
}
}
dept.setClient(CommonConstants.ONE_STRING);
this.save(dept);
return R.ok("创建成功");
}
/**
* 客户服务平台——编辑部门
*
* @param dept 部门信息
* @return 结果
*/
@Override
public R<String> updateCspDept(SysDept dept) {
SysDept findInfo = baseMapper.selectById(dept.getDeptId());
if (Common.isEmpty(findInfo)) {
return R.failed("部门未找到");
}
SysDept nameInfo = baseMapper.checkDeptNameUnique(findInfo.getProjectNo(),dept.getName(), findInfo.getParentId());
if (Common.isNotNull(nameInfo) && nameInfo.getDeptId().longValue() != dept.getDeptId().longValue()) {
return R.failed("已存在同级同名部门");
}
LambdaUpdateWrapper<SysDept> updateInfoWrapper = new LambdaUpdateWrapper<>();
updateInfoWrapper.eq(SysDept::getDeptId, dept.getDeptId())
.set(SysDept::getName, dept.getName())
.set(SysDept::getUpdateTime, LocalDateTime.now());
this.update(null, updateInfoWrapper);
return R.ok("更新成功");
}
/**
* 客户服务平台——删除部门
*
* @param deptId 部门id
* @return 结果
*/
@Override
public R<String> removeCspDeptById(Long deptId) {
int hasChild = baseMapper.hasChildByDeptId(deptId);
if (hasChild > 0) {
return R.failed("存在下级部门,不允许删除");
}
int existUser = baseMapper.checkDeptExistUser(deptId);
if (existUser > 0) {
return R.failed("部门下仍然有员工,请调出所有员工后,删除部门");
}
this.removeById(deptId);
return R.ok("删除成功");
}
/**
* 客户服务平台——获取项目下部门总数
*
* @param projectNo 项目编码
* @return R<Integer> 部门总数
*/
@Override
public Integer cspDeptCount(String projectNo) {
return baseMapper.cspDeptCount(projectNo);
}
}
......@@ -16,16 +16,21 @@
package com.yifu.cloud.plus.v1.yifu.admin.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysDept;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUserDeptPermission;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.UserPermissionVo;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysDeptMapper;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysUserDeptPermissionMapper;
import com.yifu.cloud.plus.v1.yifu.admin.mapper.SysUserMapper;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysUserDeptPermissionService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CacheConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.core.util.RedisUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
......@@ -49,6 +54,8 @@ public class SysUserDeptPermissionServiceImpl extends ServiceImpl<SysUserDeptPer
private final SysDeptMapper sysDeptMapper;
private final SysUserMapper sysUserMapper;
@Override
public UserPermissionVo getUserPermissionVo(String projectNo, String userId) {
UserPermissionVo authority = new UserPermissionVo();
......@@ -181,4 +188,91 @@ public class SysUserDeptPermissionServiceImpl extends ServiceImpl<SysUserDeptPer
return tPermissionMapByProject;
}
/**
* 客户服务平台——用户权限控制
*
* @param sysUserDeptPermission 实体
* @return success/false
*/
@Override
public R<String> saveUserPermission(SysUserDeptPermission sysUserDeptPermission) {
LambdaQueryWrapper<SysUser> userQuery = Wrappers.<SysUser>lambdaQuery()
.eq(SysUser::getUserId, sysUserDeptPermission.getUserId())
.eq(SysUser::getDelFlag, CommonConstants.ZERO_STRING)
.last(" limit 1 ");
SysUser userInfo = sysUserMapper.selectOne(userQuery);
if (Common.isEmpty(userInfo)) {
return R.failed("未找到对应用户信息");
}
LambdaQueryWrapper<SysUserDeptPermission> permissionQuery = Wrappers.<SysUserDeptPermission>lambdaQuery()
.eq(SysUserDeptPermission::getUserId, sysUserDeptPermission.getUserId())
.eq(SysUserDeptPermission::getProjectNo, sysUserDeptPermission.getProjectNo())
.last(" limit 1 ");
SysUserDeptPermission permissionInfo = baseMapper.selectOne(permissionQuery);
if (Common.isEmpty(permissionInfo)) {
return R.failed("未找到对应用户部门信息");
}
LambdaQueryWrapper<SysDept> deptQuery = Wrappers.<SysDept>lambdaQuery()
.eq(SysDept::getDeptId, permissionInfo.getDeptId())
.eq(SysDept::getDelFlag, CommonConstants.ZERO_STRING)
.last(" limit 1 ");
SysDept deptInfo = sysDeptMapper.selectOne(deptQuery);
if (Common.isEmpty(deptInfo)) {
return R.failed("异常数据,对应用户部门不存在");
}
String ancestors = deptInfo.getAncestors();
if (Common.isEmpty(ancestors)) {
return R.failed("异常数据,该用户所属部门关系为空");
}
String[] ancestorsSplit = ancestors.split(CommonConstants.COMMA_STRING);
if (ancestorsSplit.length < 2 && CommonConstants.ONE_STRING.equals(sysUserDeptPermission.getPermissionsType())) {
return R.failed("当前用户所在部门为顶级部门,不能使用该权限");
}
// 更新用户数据权限
permissionInfo.setPermissionsType(sysUserDeptPermission.getPermissionsType());
permissionInfo.setAppointDeptScope(sysUserDeptPermission.getAppointDeptScope());
baseMapper.updateById(permissionInfo);
redisUtil.remove(CacheConstants.USER_DETAILS +"::"+ userInfo.getUsername());
return R.ok("更新成功");
}
/**
* 客户服务平台——绑定项目
*
* @param sysUserDeptPermission 实体
* @return success/false
*/
@Override
public R<String> relationUser(SysUserDeptPermission sysUserDeptPermission) {
LambdaQueryWrapper<SysUser> userQuery = Wrappers.<SysUser>lambdaQuery()
.eq(SysUser::getUserId, sysUserDeptPermission.getUserId())
.eq(SysUser::getDelFlag, CommonConstants.ZERO_STRING)
.last(" limit 1 ");
SysUser userInfo = sysUserMapper.selectOne(userQuery);
if (Common.isEmpty(userInfo)) {
return R.failed("未找到对应用户信息");
}
LambdaQueryWrapper<SysUserDeptPermission> permissionQuery = Wrappers.<SysUserDeptPermission>lambdaQuery()
.eq(SysUserDeptPermission::getUserId, sysUserDeptPermission.getUserId())
.eq(SysUserDeptPermission::getProjectNo, sysUserDeptPermission.getProjectNo())
.last(" limit 1 ");
SysUserDeptPermission permissionInfo = baseMapper.selectOne(permissionQuery);
if (Common.isNotNull(permissionInfo)) {
return R.failed("该用户已绑定到项目下了,请勿重复绑定");
}
// 更新用户数据权限
sysUserDeptPermission.setClient(CommonConstants.ONE_STRING);
sysUserDeptPermission.setUserType(CommonConstants.ONE_STRING);
sysUserDeptPermission.setPermissionsType(CommonConstants.TWO_STRING);
baseMapper.insert(sysUserDeptPermission);
redisUtil.remove(CacheConstants.USER_DETAILS +"::"+ userInfo.getUsername());
return R.ok("用户绑定项目成功");
}
}
......@@ -962,4 +962,22 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return deptList.stream().anyMatch(dn::contains);
}
/**
* 分页查询系统里所有用户
*
* @param page 参数集
* @param userDTO 查询参数列表
* @return 用户集合
*
* @author chenyuxi
* @since 1.9.7
*/
@Override
public IPage<SysUser> getAllUserPage(Page page, UserDTO userDTO) {
if(Common.isEmpty(userDTO.getNameOrPhone())){
return baseMapper.getAllUserPage(page, userDTO);
}
return baseMapper.getAllUserPageWhere(page, userDTO);
}
}
......@@ -63,6 +63,53 @@
and (dept_id = #{deptId} or ancestors like concat(#{deptIdSplit}, '%'))
</select>
<select id="cspDeptList" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo">
select d.dept_id, d.name, d.parent_id,d.ancestors
from sys_dept d
where d.del_flag = '0'
<if test="dept.projectNo != null and dept.projectNo != ''">
AND d.project_no = #{dept.projectNo}
</if>
<if test="dept.deptId != null and dept.deptId != 0">
AND d.dept_id = #{dept.deptId}
</if>
<if test="dept.parentId != null and dept.parentId != 0">
AND d.parent_id = #{dept.parentId}
</if>
<if test="dept.name != null and dept.name != ''">
AND d.name like concat('%', #{dept.name}, '%')
</if>
order by d.create_time asc
</select>
<select id="cspDeptUserList" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.vo.SysDeptVo">
select d.dept_id, d.name, d.parent_id,d.ancestors,
(select count(*) from sys_user_dept_permission where dept_id = d.dept_id) as peoplenum
from sys_dept d
where d.del_flag = '0'
<if test="dept.projectNo != null and dept.projectNo != ''">
AND d.project_no = #{dept.projectNo}
</if>
order by d.create_time asc
</select>
<select id="checkDeptNameUnique" resultMap="BaseResultMap">
select dept_id,name from sys_dept
where project_no = #{projectNo} and name=#{deptName} and parent_id = #{parentId} and del_flag = '0' limit 1
</select>
<select id="checkDeptExistUser" resultType="int">
select count(1) from sys_user_dept_permission where dept_id = #{deptId}
</select>
<select id="hasChildByDeptId" resultType="int">
select count(1) from sys_dept where del_flag = '0' and parent_id = #{deptId}
</select>
<select id="cspDeptCount" resultType="int">
select count(1) from sys_dept where del_flag = '0' and project_no = #{projectNo}
</select>
<update id="updateDeptById">
update sys_dept
<trim prefix="set" suffixOverrides=",">
......
......@@ -386,4 +386,29 @@
from
sys_dept where dept_id = #{deptId} limit 1
</select>
<select id="getAllUserPage" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser">
SELECT user_id,nickname,phone,create_time,username FROM sys_user
where del_flag = '0' and lock_flag = '0'
ORDER BY create_time DESC
</select>
<select id="getAllUserPageWhere" resultType="com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysUser">
select u.* from
(SELECT user_id,nickname,phone,create_time,username FROM sys_user
where del_flag = '0' and lock_flag = '0'
<if test="query.nameOrPhone != null and query.nameOrPhone != ''">
<bind name="usernameLike" value="'%' + query.nameOrPhone + '%'"/>
and nickname LIKE #{usernameLike}
</if>
union
SELECT user_id,nickname,phone,create_time,username FROM sys_user
where del_flag = '0' and lock_flag = '0'
<if test="query.nameOrPhone != null and query.nameOrPhone != ''">
and phone = #{query.nameOrPhone}
</if>
) u
ORDER BY u.create_time DESC
</select>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment