修改部门和项目、分包关联
This commit is contained in:
@ -1,21 +0,0 @@
|
||||
package org.dromara.contractor.config;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.dromara.contractor.interceptor.ContractorInterceptor;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Resource
|
||||
private ContractorInterceptor contractorInterceptor;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(contractorInterceptor)
|
||||
.addPathPatterns("/contractor/**") // 拦截所有 /contractor 开头
|
||||
.excludePathPatterns("/contractor/contractor/**"); // 排除具体路径
|
||||
}
|
||||
}
|
@ -47,16 +47,6 @@ public class SubContractorController extends BaseController {
|
||||
return contractorService.queryPageList(req, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询没有绑定部门的分包单位列表
|
||||
*/
|
||||
@SaCheckPermission("contractor:contractor:listNoDept")
|
||||
@GetMapping("/listNoDept/{projectId}")
|
||||
public List<SubContractorVo> listNoDept(@NotNull(message = "项目主键不能为空")
|
||||
@PathVariable Long projectId) {
|
||||
return contractorService.queryListNoDept(projectId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据项目id查询分包方管理人员信息列表
|
||||
*/
|
||||
|
@ -1,84 +0,0 @@
|
||||
package org.dromara.contractor.interceptor;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.dromara.common.core.exception.ServiceException;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.web.filter.RepeatedlyRequestWrapper;
|
||||
import org.dromara.system.domain.enums.SysDeptTypeEnum;
|
||||
import org.dromara.system.domain.vo.SysDeptVo;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author lilemy
|
||||
* @date 2025/7/21 15:57
|
||||
*/
|
||||
@Component
|
||||
public class ContractorInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Resource
|
||||
private ISysDeptService deptService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
Long deptId = LoginHelper.getDeptId();
|
||||
if (ObjectUtil.isNotNull(deptId)) {
|
||||
SysDeptVo deptVo = deptService.selectDeptById(deptId);
|
||||
if (deptVo.getDeptType().equals(SysDeptTypeEnum.CONTRACT.getCode())) {
|
||||
// 在请求前处理逻辑
|
||||
System.out.println("拦截到了 /contractor/** 请求:" + request.getRequestURI());
|
||||
Long contractorId = deptVo.getContractorId();
|
||||
if (isJsonRequest(request)) {
|
||||
String jsonParam = "";
|
||||
if (request instanceof RepeatedlyRequestWrapper) {
|
||||
BufferedReader reader = request.getReader();
|
||||
jsonParam = IoUtil.read(reader);
|
||||
}
|
||||
JSONObject jsonObject = JSONUtil.parseObj(jsonParam);
|
||||
contractorId = jsonObject.getLong("contractorId");
|
||||
} else {
|
||||
Map<String, String[]> parameterMap = request.getParameterMap();
|
||||
if (MapUtil.isNotEmpty(parameterMap)) {
|
||||
String[] contractorIds = parameterMap.get("contractorId");
|
||||
if (contractorIds != null && contractorIds.length != 0 && StringUtils.isNotBlank(contractorIds[0])) {
|
||||
contractorId = Long.valueOf(Arrays.asList(contractorIds).getFirst());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ObjectUtil.isNull(contractorId) || !contractorId.equals(deptVo.getContractorId())) {
|
||||
throw new ServiceException("无访问权限");
|
||||
}
|
||||
}
|
||||
}
|
||||
return true; // 返回 true 放行,false 拦截
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断本次请求的数据类型是否为json
|
||||
*
|
||||
* @param request request
|
||||
* @return boolean
|
||||
*/
|
||||
private boolean isJsonRequest(HttpServletRequest request) {
|
||||
String contentType = request.getContentType();
|
||||
if (contentType != null) {
|
||||
return StringUtils.startsWithIgnoreCase(contentType, MediaType.APPLICATION_JSON_VALUE);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -48,14 +48,6 @@ public interface ISubContractorService extends IService<SubContractor> {
|
||||
*/
|
||||
List<SubContractorVo> queryList(SubContractorQueryReq req);
|
||||
|
||||
/**
|
||||
* 查询未绑定部门的分包单位列表
|
||||
*
|
||||
* @param projectId 项目id
|
||||
* @return 分包单位列表
|
||||
*/
|
||||
List<SubContractorVo> queryListNoDept(Long projectId);
|
||||
|
||||
/**
|
||||
* 新增分包单位
|
||||
*
|
||||
|
@ -29,8 +29,6 @@ import org.dromara.contractor.service.ISubContractorService;
|
||||
import org.dromara.project.domain.BusProject;
|
||||
import org.dromara.project.domain.enums.SubConstructionUserRoleEnum;
|
||||
import org.dromara.project.service.IBusProjectService;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.enums.SysDeptTypeEnum;
|
||||
import org.dromara.system.mapper.SysDeptMapper;
|
||||
import org.dromara.tender.domain.TenderSupplierInput;
|
||||
import org.dromara.tender.service.ITenderSupplierInputService;
|
||||
@ -40,7 +38,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -91,13 +88,6 @@ public class SubContractorServiceImpl extends ServiceImpl<SubContractorMapper, S
|
||||
@Override
|
||||
public TableDataInfo<SubContractorVo> queryPageList(SubContractorQueryReq req, PageQuery pageQuery) {
|
||||
LambdaQueryWrapper<SubContractor> lqw = this.buildQueryWrapper(req);
|
||||
Long deptId = LoginHelper.getDeptId();
|
||||
if (deptId != null) {
|
||||
SysDept dept = deptMapper.selectById(deptId);
|
||||
if (dept.getDeptType().equals(SysDeptTypeEnum.CONTRACT.getCode())) {
|
||||
lqw.eq(SubContractor::getId, dept.getContractorId());
|
||||
}
|
||||
}
|
||||
// 查询数据库
|
||||
Page<SubContractor> result = this.page(pageQuery.build(), lqw);
|
||||
return TableDataInfo.build(this.getVoPage(result));
|
||||
@ -116,31 +106,6 @@ public class SubContractorServiceImpl extends ServiceImpl<SubContractorMapper, S
|
||||
return list.stream().map(this::getVo).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未绑定部门的分包单位列表
|
||||
*
|
||||
* @param projectId 项目id
|
||||
* @return 分包单位列表
|
||||
*/
|
||||
@Override
|
||||
public List<SubContractorVo> queryListNoDept(Long projectId) {
|
||||
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(SysDept::getDeptType, SysDeptTypeEnum.CONTRACT.getCode());
|
||||
lqw.isNotNull(SysDept::getContractorId);
|
||||
List<SysDept> depts = deptMapper.selectList(lqw);
|
||||
List<Long> idList = depts.stream().map(SysDept::getContractorId).toList();
|
||||
List<SubContractor> contractorList = this.lambdaQuery()
|
||||
.eq(SubContractor::getProjectId, projectId)
|
||||
.notIn(CollUtil.isNotEmpty(idList), SubContractor::getId, idList)
|
||||
.list();
|
||||
return contractorList.stream().map(contractor -> {
|
||||
// 对象转封装类
|
||||
SubContractorVo contractorVo = new SubContractorVo();
|
||||
BeanUtils.copyProperties(contractor, contractorVo);
|
||||
return contractorVo;
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增分包单位
|
||||
*
|
||||
@ -252,26 +217,6 @@ public class SubContractorServiceImpl extends ServiceImpl<SubContractorMapper, S
|
||||
if (constructionUserService.count(queryWrapper) > 0) {
|
||||
throw new ServiceException("删除分包单位失败,删除分包单位下存在施工人员", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
// 判断当前分包公司是否绑定了部门
|
||||
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.in(SysDept::getContractorId, ids);
|
||||
List<SysDept> deptList = deptMapper.selectList(lqw);
|
||||
if (CollUtil.isNotEmpty(deptList)) {
|
||||
Map<Long, SubContractor> contractorMap = contractorList.stream()
|
||||
.collect(Collectors.toMap(SubContractor::getId, Function.identity()));
|
||||
Set<String> contractorNames = new HashSet<>();
|
||||
for (SysDept dept : deptList) {
|
||||
Long contractorId = dept.getContractorId();
|
||||
SubContractor contractor = contractorMap.get(contractorId);
|
||||
if (contractor != null) {
|
||||
contractorNames.add(contractor.getName());
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(contractorNames)) {
|
||||
String joinedNames = String.join(",", contractorNames);
|
||||
throw new ServiceException("删除分包单位失败,以下单位已绑定部门:" + joinedNames, HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 判断对应数据是否都存在
|
||||
if (contractorList.size() != ids.size()) {
|
||||
|
@ -59,15 +59,6 @@ public class BusProjectController extends BaseController {
|
||||
return projectService.queryPageList(req, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目列表
|
||||
*/
|
||||
@SaCheckPermission("project:project:listNoDept")
|
||||
@GetMapping("/listNoDept")
|
||||
public R<List<BusProjectVo>> listNoDept() {
|
||||
return R.ok(projectService.queryListNoDept());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目下的子项目列表
|
||||
*/
|
||||
|
@ -45,11 +45,6 @@ public class BusProject extends BaseEntity {
|
||||
*/
|
||||
private Long pId;
|
||||
|
||||
/**
|
||||
* 部门id
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 状态(0正常 1停用)
|
||||
*/
|
||||
@ -155,11 +150,6 @@ public class BusProject extends BaseEntity {
|
||||
*/
|
||||
private String showHidden;
|
||||
|
||||
/**
|
||||
* go项目id
|
||||
*/
|
||||
private Long goId;
|
||||
|
||||
/**
|
||||
* 是否删除(0正常 1删除)
|
||||
*/
|
||||
|
@ -46,13 +46,6 @@ public interface IBusProjectService extends IService<BusProject> {
|
||||
*/
|
||||
List<BusProjectVo> queryList(BusProjectQueryReq req);
|
||||
|
||||
/**
|
||||
* 查询未绑定部门的项目列表(不查询子项目)
|
||||
*
|
||||
* @return 项目列表
|
||||
*/
|
||||
List<BusProjectVo> queryListNoDept();
|
||||
|
||||
/**
|
||||
* 查询项目下的子项目列表
|
||||
*
|
||||
|
@ -58,9 +58,6 @@ import org.dromara.project.service.IBusProjectService;
|
||||
import org.dromara.project.service.IBusUserProjectRelevancyService;
|
||||
import org.dromara.quality.service.IQltKnowledgeDocumentService;
|
||||
import org.dromara.safety.service.IHseKnowledgeDocumentService;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.enums.SysDeptTypeEnum;
|
||||
import org.dromara.system.mapper.SysDeptMapper;
|
||||
import org.dromara.workflow.service.IFlwDefinitionService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@ -126,10 +123,6 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
|
||||
@Resource
|
||||
private IFlwDefinitionService flwDefinitionService;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private SysDeptMapper deptMapper;
|
||||
|
||||
@Lazy
|
||||
@Resource
|
||||
private IBusProjectService self;
|
||||
@ -203,25 +196,6 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
|
||||
return this.list(lqw).stream().map(this::getVo).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询未绑定部门的项目列表(不查询子项目)
|
||||
*
|
||||
* @return 项目列表
|
||||
*/
|
||||
@Override
|
||||
public List<BusProjectVo> queryListNoDept() {
|
||||
LambdaQueryWrapper<SysDept> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(SysDept::getDeptType, SysDeptTypeEnum.PROJECT.getCode());
|
||||
lqw.isNotNull(SysDept::getProjectId);
|
||||
List<SysDept> depts = deptMapper.selectList(lqw);
|
||||
List<Long> idList = depts.stream().map(SysDept::getProjectId).toList();
|
||||
List<BusProject> projectList = this.lambdaQuery()
|
||||
.notIn(CollUtil.isNotEmpty(idList), BusProject::getId, idList)
|
||||
.eq(BusProject::getPId, BusProjectConstant.PARENT_ID)
|
||||
.list();
|
||||
return projectList.stream().map(this::getVo).toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询项目下的子项目列表
|
||||
*
|
||||
|
@ -308,7 +308,7 @@ public class BusUserProjectRelevancyServiceImpl extends ServiceImpl<BusUserProje
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Map<Long, List<BusProject>> projectMap = projectService.lambdaQuery()
|
||||
.select(BusProject::getId, BusProject::getPId, BusProject::getProjectName, BusProject::getShortName, BusProject::getGoId)
|
||||
.select(BusProject::getId, BusProject::getPId, BusProject::getProjectName, BusProject::getShortName)
|
||||
.in(BusProject::getId, projectIdList)
|
||||
.eq(BusProject::getPId, BusProjectConstant.PARENT_ID)
|
||||
.list()
|
||||
@ -328,7 +328,6 @@ public class BusUserProjectRelevancyServiceImpl extends ServiceImpl<BusUserProje
|
||||
loginUserProjectRelevancy.setProjectId(projectId);
|
||||
loginUserProjectRelevancy.setProjectName(project.getProjectName());
|
||||
loginUserProjectRelevancy.setShortName(project.getShortName());
|
||||
loginUserProjectRelevancy.setGoId(project.getGoId());
|
||||
return loginUserProjectRelevancy;
|
||||
}
|
||||
return null;
|
||||
|
@ -1,21 +1,14 @@
|
||||
package org.dromara.system.controller.system;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.lang.tree.Tree;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.dromara.common.core.constant.HttpStatus;
|
||||
import org.dromara.common.core.constant.SystemConstants;
|
||||
import org.dromara.common.core.domain.R;
|
||||
import org.dromara.common.core.utils.StringUtils;
|
||||
import org.dromara.common.log.annotation.Log;
|
||||
import org.dromara.common.log.enums.BusinessType;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.project.domain.BusProject;
|
||||
import org.dromara.project.domain.vo.project.BusProjectVo;
|
||||
import org.dromara.project.service.IBusProjectService;
|
||||
import org.dromara.system.domain.bo.SysDeptBo;
|
||||
import org.dromara.system.domain.vo.SysDeptVo;
|
||||
import org.dromara.system.service.ISysDeptService;
|
||||
@ -38,7 +31,6 @@ public class SysDeptController extends BaseController {
|
||||
|
||||
private final ISysDeptService deptService;
|
||||
private final ISysPostService postService;
|
||||
private final IBusProjectService projectService;
|
||||
|
||||
/**
|
||||
* 获取部门列表
|
||||
@ -64,16 +56,6 @@ public class SysDeptController extends BaseController {
|
||||
return R.ok(depts);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据项目id获取部门树以及岗位列表
|
||||
*/
|
||||
@SaCheckPermission("system:dept:treeByProjectId")
|
||||
@GetMapping("/list/treeByProjectId/{projectId}")
|
||||
public R<List<Tree<Long>>> listTreeByProjectId(@PathVariable Long projectId) {
|
||||
List<Tree<Long>> tree = deptService.buildDeptTreeByProjectId(projectId);
|
||||
return R.ok(tree);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门编号获取详细信息
|
||||
*
|
||||
@ -86,31 +68,6 @@ public class SysDeptController extends BaseController {
|
||||
return R.ok(deptService.selectDeptById(deptId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门ID查询所属项目ID列表
|
||||
*/
|
||||
@SaCheckPermission("system:dept:projectIdList")
|
||||
@GetMapping("/projectIdList/{deptId}")
|
||||
public R<List<BusProjectVo>> listProjectIdByDeptId(@NotNull(message = "部门主键不能为空")
|
||||
@PathVariable Long deptId) {
|
||||
SysDeptVo deptVo = deptService.selectDeptById(deptId);
|
||||
if (deptVo == null) {
|
||||
return R.fail(HttpStatus.NOT_FOUND, "部门不存在");
|
||||
}
|
||||
List<Long> projectIds = deptService.selectProjectIdById(deptId, deptVo.getDeptType());
|
||||
if (CollUtil.isEmpty(projectIds)) {
|
||||
return R.ok(List.of());
|
||||
}
|
||||
List<BusProject> projectList = projectService.listByIds(projectIds);
|
||||
return R.ok(projectList.stream().map(project -> {
|
||||
BusProjectVo vo = new BusProjectVo();
|
||||
vo.setId(project.getId());
|
||||
vo.setProjectName(project.getProjectName());
|
||||
vo.setShortName(project.getShortName());
|
||||
return vo;
|
||||
}).toList());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据部门编号获取详细信息
|
||||
// *
|
||||
|
@ -50,17 +50,6 @@ public class SysMenuController extends BaseController {
|
||||
return R.ok(menuService.buildMenus(menus));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部项目路由信息
|
||||
*
|
||||
* @return 路由信息
|
||||
*/
|
||||
@GetMapping("/getAllRouters")
|
||||
public R<List<RouterVo>> getAllRouters() {
|
||||
List<SysMenu> menus = menuService.selectMenuTreeByUserId(LoginHelper.getUserId(), null);
|
||||
return R.ok(menuService.buildMenus(menus));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单列表
|
||||
*/
|
||||
|
@ -23,13 +23,11 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.common.tenant.helper.TenantHelper;
|
||||
import org.dromara.common.web.core.BaseController;
|
||||
import org.dromara.contractor.service.ISubContractorService;
|
||||
import org.dromara.system.domain.bo.SysDeptBo;
|
||||
import org.dromara.system.domain.bo.SysPostBo;
|
||||
import org.dromara.system.domain.bo.SysRoleBo;
|
||||
import org.dromara.system.domain.bo.SysUserBo;
|
||||
import org.dromara.system.domain.dto.role.SysRoleProjectDto;
|
||||
import org.dromara.system.domain.enums.SysDeptTypeEnum;
|
||||
import org.dromara.system.domain.vo.*;
|
||||
import org.dromara.system.listener.SysUserImportListener;
|
||||
import org.dromara.system.service.*;
|
||||
@ -57,7 +55,6 @@ public class SysUserController extends BaseController {
|
||||
private final ISysPostService postService;
|
||||
private final ISysDeptService deptService;
|
||||
private final ISysTenantService tenantService;
|
||||
private final ISubContractorService contractorService;
|
||||
|
||||
/**
|
||||
* 获取用户列表
|
||||
@ -121,14 +118,6 @@ public class SysUserController extends BaseController {
|
||||
userInfoVo.setUser(user);
|
||||
userInfoVo.setPermissions(loginUser.getMenuPermission());
|
||||
userInfoVo.setRoles(loginUser.getRolePermission());
|
||||
Long deptId = user.getDeptId();
|
||||
if (ObjectUtil.isNotNull(deptId)) {
|
||||
SysDeptVo deptVo = deptService.selectDeptById(deptId);
|
||||
Long contractorId = deptVo.getContractorId();
|
||||
if (deptVo.getDeptType().equals(SysDeptTypeEnum.CONTRACT.getCode()) && ObjectUtil.isNotNull(contractorId)) {
|
||||
userInfoVo.setContractorId(contractorId);
|
||||
}
|
||||
}
|
||||
return R.ok(userInfoVo);
|
||||
}
|
||||
|
||||
|
@ -33,16 +33,6 @@ public class SysDept extends TenantEntity {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 项目ID
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 分包公司ID
|
||||
*/
|
||||
private Long contractorId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
|
@ -33,21 +33,6 @@ public class SysDeptBo extends BaseEntity {
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 项目部门项目id
|
||||
*/
|
||||
private Long rowProjectId;
|
||||
|
||||
/**
|
||||
* 分包公司ID
|
||||
*/
|
||||
private Long contractorId;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@ -102,61 +87,4 @@ public class SysDeptBo extends BaseEntity {
|
||||
@NotBlank(message = "部门类型不能为空")
|
||||
private String deptType;
|
||||
|
||||
|
||||
// /**
|
||||
// * ======================
|
||||
// * 如果子集为0,则需要新增角色
|
||||
// * ======================
|
||||
// */
|
||||
//
|
||||
// /**
|
||||
// * 角色ID
|
||||
// */
|
||||
// private Long roleId;
|
||||
//
|
||||
// /**
|
||||
// * 角色权限字符串
|
||||
// */
|
||||
// private String roleKey;
|
||||
//
|
||||
// /**
|
||||
// * 显示顺序
|
||||
// */
|
||||
// private Integer roleSort;
|
||||
//
|
||||
// /**
|
||||
// * 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
// */
|
||||
// private String dataScope;
|
||||
//
|
||||
// /**
|
||||
// * 菜单树选择项是否关联显示
|
||||
// */
|
||||
// private Boolean menuCheckStrictly;
|
||||
//
|
||||
// /**
|
||||
// * 部门树选择项是否关联显示
|
||||
// */
|
||||
// private Boolean deptCheckStrictly;
|
||||
//
|
||||
// /**
|
||||
// * 角色状态(0正常 1停用)
|
||||
// */
|
||||
// private String roleStatus;
|
||||
//
|
||||
// /**
|
||||
// * 备注
|
||||
// */
|
||||
// private String remark;
|
||||
//
|
||||
// /**
|
||||
// * 菜单组
|
||||
// */
|
||||
// private Long[] menuIds;
|
||||
//
|
||||
// /**
|
||||
// * 部门组(数据权限)
|
||||
// */
|
||||
// private Long[] deptIds;
|
||||
|
||||
}
|
||||
|
@ -6,14 +6,11 @@ import io.github.linpeilie.annotations.AutoMapper;
|
||||
import lombok.Data;
|
||||
import org.dromara.common.excel.annotation.ExcelDictFormat;
|
||||
import org.dromara.common.excel.convert.ExcelDictConvert;
|
||||
import org.dromara.contractor.domain.vo.contractor.SubContractorVo;
|
||||
import org.dromara.project.domain.vo.project.BusProjectVo;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门视图对象 sys_dept
|
||||
@ -49,26 +46,6 @@ public class SysDeptVo implements Serializable {
|
||||
*/
|
||||
private SysDeptVo parent;
|
||||
|
||||
/**
|
||||
* 项目id
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 分包公司ID
|
||||
*/
|
||||
private Long contractorId;
|
||||
|
||||
/**
|
||||
* 未绑定项目信息
|
||||
*/
|
||||
private List<BusProjectVo> projectList;
|
||||
|
||||
/**
|
||||
* 未绑定分包信息
|
||||
*/
|
||||
private List<SubContractorVo> contractorList;
|
||||
|
||||
/**
|
||||
* 祖级列表
|
||||
*/
|
||||
|
@ -36,14 +36,6 @@ public interface ISysDeptService {
|
||||
*/
|
||||
List<Tree<Long>> buildDeptTreeSelect(List<SysDeptVo> depts);
|
||||
|
||||
/**
|
||||
* 构建前端所需要下拉树结构
|
||||
*
|
||||
* @param projectId 项目id
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
List<Tree<Long>> buildDeptTreeByProjectId(Long projectId);
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
*
|
||||
|
@ -20,22 +20,12 @@ import org.dromara.common.core.utils.*;
|
||||
import org.dromara.common.mybatis.helper.DataBaseHelper;
|
||||
import org.dromara.common.redis.utils.CacheUtils;
|
||||
import org.dromara.common.satoken.utils.LoginHelper;
|
||||
import org.dromara.contractor.domain.SubContractor;
|
||||
import org.dromara.contractor.domain.vo.contractor.SubContractorVo;
|
||||
import org.dromara.contractor.service.ISubContractorService;
|
||||
import org.dromara.project.domain.BusProject;
|
||||
import org.dromara.project.domain.vo.project.BusProjectVo;
|
||||
import org.dromara.project.service.IBusProjectService;
|
||||
import org.dromara.project.service.IBusUserProjectRelevancyService;
|
||||
import org.dromara.system.domain.SysDept;
|
||||
import org.dromara.system.domain.SysPost;
|
||||
import org.dromara.system.domain.SysRole;
|
||||
import org.dromara.system.domain.SysUser;
|
||||
import org.dromara.system.domain.bo.SysDeptBo;
|
||||
import org.dromara.system.domain.enums.SysContractorRoleEnum;
|
||||
import org.dromara.system.domain.enums.SysDeptTypeEnum;
|
||||
import org.dromara.system.domain.vo.SysDeptVo;
|
||||
import org.dromara.system.domain.vo.SysPostVo;
|
||||
import org.dromara.system.mapper.SysDeptMapper;
|
||||
import org.dromara.system.mapper.SysPostMapper;
|
||||
import org.dromara.system.mapper.SysRoleMapper;
|
||||
@ -48,8 +38,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 部门管理 服务实现
|
||||
@ -65,8 +53,6 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
private final SysRoleMapper roleMapper;
|
||||
private final SysUserMapper userMapper;
|
||||
private final SysPostMapper postMapper;
|
||||
private final IBusProjectService projectService;
|
||||
private final ISubContractorService contractorService;
|
||||
|
||||
/**
|
||||
* 查询部门管理数据
|
||||
@ -149,7 +135,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
*
|
||||
* @param projectId 项目id
|
||||
* @return 下拉树结构列表
|
||||
*/
|
||||
*//*
|
||||
@Override
|
||||
public List<Tree<Long>> buildDeptTreeByProjectId(Long projectId) {
|
||||
SysDept dept = baseMapper.selectOne(
|
||||
@ -196,7 +182,7 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
}
|
||||
}
|
||||
return treeList;
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 根据角色ID查询部门树信息
|
||||
@ -227,22 +213,6 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
.select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
||||
dept.setParentName(ObjectUtils.notNullGetter(parentDept, SysDeptVo::getDeptName));
|
||||
dept.setParent(parentDept);
|
||||
String deptType = dept.getDeptType();
|
||||
// 获取未绑定项目信息
|
||||
List<BusProjectVo> projectVos = new ArrayList<>(projectService.queryListNoDept());
|
||||
// 获取项目部门绑定的项目信息
|
||||
if (deptType.equals(SysDeptTypeEnum.PROJECT.getCode()) && dept.getProjectId() != null) {
|
||||
BusProjectVo vo = projectService.getVo(projectService.getById(dept.getProjectId()));
|
||||
projectVos.add(vo);
|
||||
}
|
||||
dept.setProjectList(projectVos);
|
||||
// 如果为分包部门,获取分包部门信息
|
||||
if (deptType.equals(SysDeptTypeEnum.CONTRACT.getCode())) {
|
||||
List<SubContractorVo> contractorVos = new ArrayList<>(contractorService.queryListNoDept(dept.getProjectId()));
|
||||
SubContractorVo vo = contractorService.getVo(contractorService.getById(dept.getContractorId()));
|
||||
contractorVos.add(vo);
|
||||
dept.setContractorList(contractorVos);
|
||||
}
|
||||
return dept;
|
||||
}
|
||||
|
||||
@ -271,32 +241,6 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
return baseMapper.getProjectIdsByDept(deptId);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 根据部门ID查询信息
|
||||
// *
|
||||
// * @return 部门信息
|
||||
// */
|
||||
// @Cacheable(cacheNames = CacheNames.SYS_DEPT, key = "#deptId")
|
||||
// @Override
|
||||
// public SysDeptBo selectDeptByIdBo(SysDeptBo bo) {
|
||||
// SysDeptBo sysDeptBo = new SysDeptBo();
|
||||
// SysDeptVo dept = baseMapper.selectVoById(bo.getDeptId());
|
||||
// if (ObjectUtil.isNull(dept)) {
|
||||
// return null;
|
||||
// }
|
||||
// SysDeptVo parentDept = baseMapper.selectVoOne(new LambdaQueryWrapper<SysDept>()
|
||||
// .select(SysDept::getDeptName).eq(SysDept::getDeptId, dept.getParentId()));
|
||||
// dept.setParentName(ObjectUtils.notNullGetter(parentDept, SysDeptVo::getDeptName));
|
||||
//
|
||||
// //cory 获取角色信息
|
||||
// roleService.checkRoleDataScope(bo.getRoleId());
|
||||
// SysRoleVo sysRoleVo = roleService.selectRoleById(bo.getRoleId());
|
||||
// BeanUtils.copyProperties(dept,sysDeptBo);
|
||||
// BeanUtils.copyProperties(sysRoleVo,sysDeptBo);
|
||||
// sysDeptBo.setRoleSort(sysRoleVo.getRoleSort());
|
||||
// return sysDeptBo;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 通过部门名称查询部门ID
|
||||
*
|
||||
@ -472,104 +416,15 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
if (!SystemConstants.NORMAL.equals(info.getStatus())) {
|
||||
throw new ServiceException("部门停用,不允许新增");
|
||||
}
|
||||
/* String pDeptType = info.getDeptType();
|
||||
String deptType = bo.getDeptType();
|
||||
if (SysDeptTypeEnum.SPECIAL.getCode().equals(pDeptType) || SysDeptTypeEnum.CONTRACT.getCode().equals(pDeptType)) {
|
||||
// 父部门为特殊部门或者项目部门,不允许新增子部门
|
||||
throw new ServiceException("当前部门不允许有子部门");
|
||||
} else if (SysDeptTypeEnum.PROJECT.getCode().equals(pDeptType) && !SysDeptTypeEnum.CONTRACT.getCode().equals(deptType)) {
|
||||
// 父部门为项目部门,只能新增分包部门
|
||||
throw new ServiceException("项目部门只能新增分包部门");
|
||||
}*/
|
||||
SysDept dept = MapstructUtils.convert(bo, SysDept.class);
|
||||
if (dept == null) {
|
||||
throw new ServiceException("新增部门参数异常", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
dept.setAncestors(info.getAncestors() + StringUtils.SEPARATOR + dept.getParentId());
|
||||
/*if (SysDeptTypeEnum.PROJECT.getCode().equals(deptType)) {
|
||||
// 项目部门
|
||||
Long projectId = bo.getProjectId();
|
||||
BusProject project = projectService.getById(projectId);
|
||||
if (project == null) {
|
||||
throw new ServiceException("项目不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 判断该项目是否被绑定
|
||||
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysDept::getProjectId, projectId);
|
||||
Long l = baseMapper.selectCount(queryWrapper);
|
||||
if (l > 0) {
|
||||
throw new ServiceException("该项目已被其他部门绑定", HttpStatus.CONFLICT);
|
||||
}
|
||||
dept.setProjectId(projectId);
|
||||
// 判断是否有需要新增项目关联的用户
|
||||
List<Long> deptIds = this.getParentAndSiblingDeptIds(dept);
|
||||
deptIds.remove(dept.getDeptId());
|
||||
LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.select(SysUser::getUserId);
|
||||
lqw.in(SysUser::getDeptId, deptIds);
|
||||
List<Long> userIds = userMapper.selectList(lqw).stream()
|
||||
.map(SysUser::getUserId)
|
||||
.filter(userId -> !LoginHelper.isSuperAdmin(userId))
|
||||
.toList();
|
||||
if (CollUtil.isNotEmpty(userIds)) {
|
||||
userProjectRelevancyService.saveBatchByUserList(projectId, userIds, "2");
|
||||
}
|
||||
} else if (SysDeptTypeEnum.CONTRACT.getCode().equals(deptType)) {
|
||||
// 分包部门
|
||||
Long projectId = bo.getRowProjectId();
|
||||
BusProject project = projectService.getById(projectId);
|
||||
if (project == null) {
|
||||
throw new ServiceException("项目不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
Long contractorId = bo.getContractorId();
|
||||
SubContractor contractor = contractorService.getById(contractorId);
|
||||
if (contractor == null) {
|
||||
throw new ServiceException("分包方不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
if (!contractor.getProjectId().equals(projectId)) {
|
||||
throw new ServiceException("分包方不属于当前项目,请重新选择", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
// 判断该项目是否被绑定
|
||||
Long projectCount = baseMapper.selectCount(
|
||||
new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getProjectId, projectId)
|
||||
);
|
||||
if (projectCount <= 0) {
|
||||
throw new ServiceException("所选项目未绑定部门,请先将项目绑定部门", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
// 判断该分包方是否被绑定
|
||||
Long contractorCount = baseMapper.selectCount(
|
||||
new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getContractorId, contractorId)
|
||||
);
|
||||
if (contractorCount > 0) {
|
||||
throw new ServiceException("该分包方已被其他部门绑定", HttpStatus.CONFLICT);
|
||||
}
|
||||
dept.setProjectId(projectId);
|
||||
dept.setContractorId(contractorId);
|
||||
}*/
|
||||
int insert = baseMapper.insert(dept);
|
||||
if (insert < 1) {
|
||||
throw new ServiceException("添加部门失败", HttpStatus.ERROR);
|
||||
}
|
||||
/* if (SysDeptTypeEnum.CONTRACT.getCode().equals(deptType)) {
|
||||
// 分包部门,自动创建下面的角色
|
||||
Long deptId = dept.getDeptId();
|
||||
List<SysContractorRoleEnum> roleNameList = List.of(SysContractorRoleEnum.values());
|
||||
List<SysRole> roles = roleNameList.stream().map(item -> {
|
||||
SysRole role = new SysRole();
|
||||
role.setDeptId(deptId);
|
||||
role.setRoleName(item.getName());
|
||||
role.setRoleKey(dept.getContractorId() + "_" + item.getCode());
|
||||
role.setStatus("0");
|
||||
role.setRoleSort(item.getSort());
|
||||
return role;
|
||||
}).toList();
|
||||
boolean b = roleMapper.insertBatch(roles);
|
||||
if (!b) {
|
||||
throw new ServiceException("添加部门角色失败");
|
||||
}
|
||||
}*/
|
||||
return insert;
|
||||
}
|
||||
|
||||
@ -604,74 +459,6 @@ public class SysDeptServiceImpl implements ISysDeptService, DeptService {
|
||||
} else {
|
||||
dept.setAncestors(oldDept.getAncestors());
|
||||
}
|
||||
/*String deptType = dept.getDeptType();
|
||||
if (SysDeptTypeEnum.PROJECT.getCode().equals(deptType)) {
|
||||
// 判断是否需要更新用户与项目的关联
|
||||
Long oldProjectId = oldDept.getProjectId();
|
||||
Long newProjectId = dept.getProjectId();
|
||||
if (newProjectId != null && !Objects.equals(oldProjectId, newProjectId)) {
|
||||
// 检查新项目是否存在
|
||||
BusProject project = projectService.getById(newProjectId);
|
||||
if (project == null) {
|
||||
throw new ServiceException("关联项目不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 判断新项目是否被绑定
|
||||
LambdaQueryWrapper<SysDept> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysDept::getProjectId, newProjectId);
|
||||
Long l = baseMapper.selectCount(queryWrapper);
|
||||
if (l > 0) {
|
||||
throw new ServiceException("该项目已被其他部门绑定", HttpStatus.CONFLICT);
|
||||
}
|
||||
// 获取当前部门及其上级部门 ID 列表
|
||||
List<Long> deptIds = this.getParentAndSiblingDeptIds(dept);
|
||||
deptIds.remove(dept.getDeptId());
|
||||
// 获取部门用户 ID
|
||||
LambdaQueryWrapper<SysUser> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.select(SysUser::getUserId);
|
||||
lqw.in(SysUser::getDeptId, deptIds);
|
||||
List<Long> userIds = userMapper.selectList(lqw).stream()
|
||||
.map(SysUser::getUserId)
|
||||
.filter(userId -> !LoginHelper.isSuperAdmin(userId))
|
||||
.toList();
|
||||
if (CollUtil.isNotEmpty(userIds)) {
|
||||
// 情况 1:原本有项目,且项目 ID 改变 → 删除旧的,添加新的
|
||||
if (oldProjectId != null) {
|
||||
userProjectRelevancyService.deleteByProjectAndUserIds(oldProjectId, userIds);
|
||||
userProjectRelevancyService.saveBatchByUserList(newProjectId, userIds, "2");
|
||||
} else {
|
||||
// 情况 2:原本没有项目,现在新增了 → 直接添加
|
||||
userProjectRelevancyService.saveBatchByUserList(newProjectId, userIds, "2");
|
||||
}
|
||||
}
|
||||
dept.setProjectId(newProjectId);
|
||||
}
|
||||
} else if (SysDeptTypeEnum.CONTRACT.getCode().equals(deptType)) {
|
||||
Long oldContractorId = oldDept.getContractorId();
|
||||
Long newContractorId = dept.getContractorId();
|
||||
if (!oldDept.getProjectId().equals(dept.getProjectId())) {
|
||||
throw new ServiceException("分包方不属于当前项目,请重新选择", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
if (newContractorId != null && !Objects.equals(oldContractorId, newContractorId)) {
|
||||
SubContractor contractor = contractorService.getById(newContractorId);
|
||||
// 检查分包方是否存在
|
||||
if (contractor == null) {
|
||||
throw new ServiceException("关联分包方不存在", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
// 检查分包方所属项目是否与当前部门所属项目一致
|
||||
if (!contractor.getProjectId().equals(dept.getProjectId())) {
|
||||
throw new ServiceException("分包方不属于当前项目,请重新选择", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
// 判断新选择分包方是否被绑定
|
||||
Long contractorCount = baseMapper.selectCount(
|
||||
new LambdaQueryWrapper<SysDept>()
|
||||
.eq(SysDept::getContractorId, newContractorId)
|
||||
);
|
||||
if (contractorCount > 0) {
|
||||
throw new ServiceException("该分包方已被其他部门绑定", HttpStatus.CONFLICT);
|
||||
}
|
||||
dept.setContractorId(newContractorId);
|
||||
}
|
||||
}*/
|
||||
int result = baseMapper.updateById(dept);
|
||||
if (SystemConstants.NORMAL.equals(dept.getStatus()) && StringUtils.isNotEmpty(dept.getAncestors())
|
||||
&& !StringUtils.equals(SystemConstants.NORMAL, dept.getAncestors())) {
|
||||
|
Reference in New Issue
Block a user