优化维修判断逻辑
This commit is contained in:
parent
d10a19a252
commit
d3783b1de9
@ -97,7 +97,7 @@ public interface DlRepairTicketsService extends IService<DlRepairTickets> {
|
||||
* @author 小李
|
||||
* @date 9:28 2024/10/14
|
||||
**/
|
||||
Integer getUserRole();
|
||||
String getUserRole();
|
||||
|
||||
/**
|
||||
* 接单
|
||||
|
@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.tickets.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.common.RepairConstants;
|
||||
import cn.iocoder.yudao.common.RepairErrorCodeConstants;
|
||||
import cn.iocoder.yudao.common.RepairRoleEnum;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.base.entity.RepairWorker;
|
||||
import cn.iocoder.yudao.module.base.service.RepairWorkerService;
|
||||
@ -51,21 +51,14 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.deepoove.poi.XWPFTemplate;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.print.Doc;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.iocoder.yudao.common.BaseConstants.ORDER_TENANT_NAME;
|
||||
@ -138,6 +131,8 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
||||
@Resource
|
||||
@Lazy
|
||||
private RepairWorkerService repairWorkerService;
|
||||
@Resource
|
||||
private RepairWorkerService workerService;
|
||||
|
||||
/**
|
||||
* 维修工单表 新增
|
||||
@ -393,28 +388,29 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
||||
**/
|
||||
@Override
|
||||
public IPage<DlRepairTickets> getPageType(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page){
|
||||
Integer userRole = getUserRole();
|
||||
switch (userRole){
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
|
||||
break;
|
||||
case 3:
|
||||
// 查自己是什么班组的组长
|
||||
String userRoleCode = getUserRole();
|
||||
if(userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())|| userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){
|
||||
//维修管理员和总检,看所有数据
|
||||
}else if(userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){
|
||||
//服务顾问看自己的
|
||||
repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
|
||||
}else if(userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())){
|
||||
//维修工,进一步判断是否是班组长
|
||||
boolean ifLeader = workerService.getIfLeader();
|
||||
if(ifLeader){
|
||||
//班组长,看本班组所有数据
|
||||
RepairWorker one = repairWorkerService.getOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()));
|
||||
// 查自己班组的员工信息
|
||||
List<RepairWorker> list = repairWorkerService.list(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getWorkType, one.getWorkType()));
|
||||
// 所有的员工信息
|
||||
List<Long> userIds = list.stream().map(RepairWorker::getUserId).collect(Collectors.toList());
|
||||
repairTicketsReqVO.setUserIds(userIds);
|
||||
break;
|
||||
case 4:
|
||||
}else{
|
||||
//普通维修工
|
||||
repairTicketsReqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId()));
|
||||
break;
|
||||
case -1:
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
return baseMapper.getPageType(repairTicketsReqVO, page);
|
||||
}
|
||||
@ -426,7 +422,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
||||
* @date 9:28 2024/10/14
|
||||
**/
|
||||
@Override
|
||||
public Integer getUserRole(){
|
||||
public String getUserRole(){
|
||||
// 查看当前登录用户是什么角色
|
||||
// 当前登录用户的角色信息
|
||||
List<Long> byUserId = permissionApi.getRoleIdsByUserId(SecurityFrameworkUtils.getLoginUserId());
|
||||
@ -435,29 +431,33 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
||||
// 过滤出登录用户有的角色信息
|
||||
List<RoleReqDTO> collect = roleList.stream().filter(item -> byUserId.contains(item.getId())).collect(Collectors.toList());
|
||||
// 取出角色名称
|
||||
List<String> names = collect.stream().map(RoleReqDTO::getName).collect(Collectors.toList());
|
||||
List<String> codes = collect.stream().map(RoleReqDTO::getCode).collect(Collectors.toList());
|
||||
// 维修业务管理员--可以看所有数据,但不能做操作
|
||||
if (codes.contains(RepairRoleEnum.ADMIN.getCode())){
|
||||
return RepairRoleEnum.ADMIN.getCode();
|
||||
}
|
||||
// 总检
|
||||
if (names.contains(RepairConstants.GENERAL_INSPECTION)){
|
||||
return 1;
|
||||
if (codes.contains(RepairRoleEnum.INSPECTION.getCode())){
|
||||
return RepairRoleEnum.INSPECTION.getCode();
|
||||
}
|
||||
// 服务顾问
|
||||
if (names.contains(RepairConstants.SERVICE_ADVISOR)){
|
||||
return 2;
|
||||
if (codes.contains(RepairRoleEnum.ADVISOR.getName())){
|
||||
return RepairRoleEnum.ADVISOR.getName();
|
||||
}
|
||||
// 班组长
|
||||
if (names.contains(RepairConstants.TEAM_LEADER)){
|
||||
return 3;
|
||||
}
|
||||
// 维修工
|
||||
if (names.contains(RepairConstants.REPAIR_STAFF)){
|
||||
return 4;
|
||||
// 维修工(或班组长)
|
||||
if (codes.contains(RepairRoleEnum.REPAIR_STAFF.getCode())){
|
||||
return RepairRoleEnum.REPAIR_STAFF.getCode();
|
||||
}
|
||||
// 维修仓库管理员
|
||||
if(names.contains(RepairConstants.REPAIR_WAREHOUSE)){
|
||||
return 5;
|
||||
if(codes.contains(RepairRoleEnum.WAREHOUSE.getCode())){
|
||||
return RepairRoleEnum.WAREHOUSE.getCode();
|
||||
}
|
||||
// 维修财务
|
||||
if(codes.contains(RepairRoleEnum.WXCW.getCode())){
|
||||
return RepairRoleEnum.WXCW.getCode();
|
||||
}
|
||||
// 啥也不是
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.tickets.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.iocoder.yudao.common.RepairRoleEnum;
|
||||
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import cn.iocoder.yudao.module.base.entity.RepairWorker;
|
||||
import cn.iocoder.yudao.module.base.service.RepairWorkerService;
|
||||
@ -75,6 +76,8 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
|
||||
@Resource
|
||||
@Lazy
|
||||
private RepairWaresService repairWaresService;
|
||||
@Resource
|
||||
private RepairWorkerService workerService;
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
@ -86,35 +89,33 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
|
||||
@Override
|
||||
public IPage<DlTicketWares> getPage(DlTicketWaresReqVO reqVO, Page<DlTicketWares> page){
|
||||
// 确认查看者身份
|
||||
Integer userRole = repairTicketsService.getUserRole();
|
||||
// 啥也不是
|
||||
if (userRole == -1){
|
||||
return null;
|
||||
}
|
||||
switch (userRole){
|
||||
// 服务顾问
|
||||
case 2:
|
||||
reqVO.setAdviserId(SecurityFrameworkUtils.getLoginUserId());
|
||||
break;
|
||||
// 班组长
|
||||
case 3:
|
||||
// 查自己是什么班组的组长
|
||||
String userRoleCode = repairTicketsService.getUserRole();
|
||||
if(userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())|| userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())){
|
||||
//维修管理员和总检,看所有数据
|
||||
}else if(userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){
|
||||
//服务顾问
|
||||
reqVO.setAdviserId(SecurityFrameworkUtils.getLoginUserId());
|
||||
}else if(userRoleCode.equals(RepairRoleEnum.REPAIR_STAFF.getCode())){
|
||||
//维修工,进一步判断是否是班组长
|
||||
boolean ifLeader = workerService.getIfLeader();
|
||||
if(ifLeader){
|
||||
//班组长,看本班组所有数据
|
||||
RepairWorker one = repairWorkerService.getOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()));
|
||||
// 查自己班组的员工信息
|
||||
List<RepairWorker> list = repairWorkerService.list(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getWorkType, one.getWorkType()));
|
||||
// 所有的员工信息
|
||||
List<Long> userIds = list.stream().map(RepairWorker::getUserId).collect(Collectors.toList());
|
||||
reqVO.setUserIds(userIds);
|
||||
break;
|
||||
// 维修工
|
||||
case 4:
|
||||
}else{
|
||||
//普通维修工
|
||||
reqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId()));
|
||||
break;
|
||||
}
|
||||
}else if(userRoleCode.equals(RepairRoleEnum.WAREHOUSE.getCode())){
|
||||
// 维修仓库管理员
|
||||
case 5:
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setUserRole(5);
|
||||
break;
|
||||
reqVO.setStatus(null);
|
||||
reqVO.setUserRole(5);
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
return baseMapper.getPage(reqVO, page);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user