维修工接单/维修班组长重新指派

This commit is contained in:
xiaofajia 2024-10-14 17:24:34 +08:00
parent 316e7cae5a
commit 21e12b339c
8 changed files with 275 additions and 32 deletions

View File

@ -90,5 +90,28 @@ public class RepairWorkerController {
return success(workerService.queryListPage(pageReqVO,page));
}
/**
* 通过工单ID查到工单ID中所选择的员工信息
*
* @author 小李
* @date 15:53 2024/10/14
* @param ticketId 工单ID
**/
@GetMapping("/listByTicketId")
@Operation(summary = "通过工单ID查到工单ID中所选择的员工信息")
public CommonResult<?> listByTicketId(@RequestParam("ticketId") String ticketId) {
return success(workerService.listByTicketId(ticketId));
}
/**
* 通过班组长的id查该班组的员工
*
* @author 小李
* @date 16:55 2024/10/14
**/
@GetMapping("/listByLeadsId")
@Operation(summary = "通过班组长的id查该班组的员工")
public CommonResult<?> listByLeads() {
return success(workerService.listByLeads());
}
}

View File

@ -60,4 +60,20 @@ public interface RepairWorkerService extends IService<RepairWorker> {
**/
IPage<RepairWorkerRespVO> queryListPage(RepairWorkerPageReqVO pageReqVO, Page<RepairWorkerRespVO> page);
/**
* 通过工单ID查到工单ID中所选择的员工信息
*
* @author 小李
* @date 15:53 2024/10/14
* @param ticketId 工单ID
**/
List<RepairWorker> listByTicketId(String ticketId);
/**
* 通过班组长的id查该班组的员工
*
* @author 小李
* @date 16:55 2024/10/14
**/
List<RepairWorker> listByLeads();
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.base.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.base.entity.RepairWorker;
import cn.iocoder.yudao.module.base.mapper.RepairWorkerMapper;
import cn.iocoder.yudao.module.base.service.RepairWorkerService;
@ -9,15 +10,19 @@ import cn.iocoder.yudao.module.base.vo.RepairWorkerPageReqVO;
import cn.iocoder.yudao.module.base.vo.RepairWorkerRespVO;
import cn.iocoder.yudao.module.base.vo.RepairWorkerSaveReqVO;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem;
import cn.iocoder.yudao.module.tickets.service.DlRepairTitemService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* 维修工人 Service 实现类
@ -31,6 +36,10 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
@Resource
private RepairWorkerMapper workerMapper;
@Resource
@Lazy
private DlRepairTitemService dlRepairTitemService;
/**
* 批量创建维修工人
@ -92,4 +101,40 @@ public class RepairWorkerServiceImpl extends ServiceImpl<RepairWorkerMapper, Rep
return workerMapper.queryListPage(pageReqVO,page);
}
/**
* 通过工单ID查到工单ID中所选择的员工信息
*
* @author 小李
* @date 15:53 2024/10/14
* @param ticketId 工单ID
**/
@Override
public List<RepairWorker> listByTicketId(String ticketId){
// 查工单的项目信息
List<DlRepairTitem> titems = dlRepairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>()
.and(item -> {
item.eq(DlRepairTitem::getTicketId, ticketId)
.eq(DlRepairTitem::getItemType, "01");
}));
// 取所有的员工ID
Set<String> ids = titems.stream().flatMap(item -> Arrays.stream(item.getRepairIds().split(","))).collect(Collectors.toSet());
return baseMapper.selectList(new LambdaQueryWrapper<RepairWorker>().in(RepairWorker::getUserId, ids));
}
/**
* 通过班组长的id查该班组的员工
*
* @author 小李
* @date 16:55 2024/10/14
**/
@Override
public List<RepairWorker> listByLeads(){
// 取班组长的记录
RepairWorker worker = baseMapper.selectOne(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getUserId, SecurityFrameworkUtils.getLoginUserId()));
// 根据班组长的工种查所有该工程的工人
List<RepairWorker> workerList = baseMapper.selectList(new LambdaQueryWrapper<RepairWorker>().eq(RepairWorker::getWorkType, worker.getWorkType()));
// 去掉班组长自己
return workerList.stream().filter(item -> !Objects.equals(item.getUserId(), worker.getUserId())).collect(Collectors.toList());
}
}

View File

@ -173,5 +173,45 @@ public class DlRepairTicketsController {
Page<DlRepairTickets> page = new Page<>(pageNo, pageSize);
return success(dlRepairTicketsService.getPageType(repairTicketsReqVO, page));
}
/**
* 判断登录用户的角色针对维修工单中的四个角色
*
* @author 小李
* @date 9:28 2024/10/14
**/
@GetMapping("/userRole")
@Operation(summary = "判断登录用户的角色,针对维修工单中的四个角色")
public CommonResult<?> getUserRole(){
return success(dlRepairTicketsService.getUserRole());
}
/**
* 接单
*
* @author 小李
* @date 11:48 2024/10/14
* @param id 工单ID
**/
@GetMapping("/take")
@Operation(summary = "接单")
public CommonResult<?> updateTake(@RequestParam("id") String id){
dlRepairTicketsService.updateTake(id);
return CommonResult.ok();
}
/**
* 指派员工通知施工
*
* @author 小李
* @date 15:34 2024/10/14
* @param reqVO 请求对象
**/
@PostMapping("/notify")
@Operation(summary = "指派员工,通知施工")
public CommonResult<?> updateRepair(@RequestBody DlRepairTicketsReqVO reqVO){
dlRepairTicketsService.updateRepair(reqVO);
return CommonResult.ok();
}
}

View File

@ -178,4 +178,10 @@ public class DlRepairTickets extends TenantBaseDO {
/** 工单完成情况0:未完成1:已完成) */
private String isFinish;
/** 工单当前施工人id */
private Long nowRepairId;
/** 工单当前施工人name */
private String nowRepairName;
}

View File

@ -90,4 +90,30 @@ public interface DlRepairTicketsService extends IService<DlRepairTickets> {
* @param repairTicketsReqVO 查询对象
**/
IPage<DlRepairTickets> getPageType(DlRepairTicketsReqVO repairTicketsReqVO, Page<DlRepairTickets> page);
/**
* 判断登录用户的角色针对维修工单中的四个角色
*
* @author 小李
* @date 9:28 2024/10/14
**/
Integer getUserRole();
/**
* 接单
*
* @author 小李
* @date 11:48 2024/10/14
* @param id 工单ID
**/
void updateTake(String id);
/**
* 指派员工通知施工
*
* @author 小李
* @date 15:34 2024/10/14
* @param reqVO 请求对象
**/
void updateRepair(DlRepairTicketsReqVO reqVO);
}

View File

@ -45,6 +45,7 @@ import cn.iocoder.yudao.module.tickets.vo.DlRepairTicketsRespVO;
import cn.iocoder.yudao.module.tickets.vo.DlRepairTitemReqVO;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@ -69,6 +70,7 @@ import java.util.stream.Collectors;
import static cn.iocoder.yudao.common.BaseConstants.ORDER_TENANT_NAME;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception0;
/**
* 针对表dl_repair_tickets(维修工单表)的数据库操作Service实现
@ -168,8 +170,8 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
List<DlRepairTitem> itemList = ticketsRespVO.getItemList();
List<DlRepairTitem> collect = itemList.stream().filter(item -> item.getItemType().equals("02")).collect(Collectors.toList());
ticketsRespVO.setPartStatus(CollectionUtil.isEmpty(collect) ? "01" : "02");
// 工单进行状态 默认是未派工
ticketsRespVO.setTicketsWorkStatus("04");
// 工单进行状态 默认是等待接单
ticketsRespVO.setTicketsWorkStatus("01");
// 新增主表
baseMapper.insert(ticketsRespVO);
@ -391,6 +393,40 @@ 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:
// 查自己是什么班组的组长
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:
repairTicketsReqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId()));
break;
case -1:
default:
return null;
}
return baseMapper.getPageType(repairTicketsReqVO, page);
}
/**
* 判断登录用户的角色针对维修工单中的四个角色
*
* @author 小李
* @date 9:28 2024/10/14
**/
@Override
public Integer getUserRole(){
// 查看当前登录用户是什么角色
// 当前登录用户的角色信息
List<Long> byUserId = permissionApi.getRoleIdsByUserId(SecurityFrameworkUtils.getLoginUserId());
@ -400,27 +436,68 @@ 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());
// 总检
if (names.contains(RepairConstants.GENERAL_INSPECTION)){
return 1;
}
// 服务顾问
if (names.contains(RepairConstants.SERVICE_ADVISOR)){
// 服务顾问的ID
repairTicketsReqVO.setAdviserId(String.valueOf(SecurityFrameworkUtils.getLoginUserId()));
}else if (names.contains(RepairConstants.TEAM_LEADER)){
// 班组长
// 查自己是什么班组的组长
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());
// 可能指定的时候指定的有班组长所以还要加班组长的id也加进去
userIds.add(one.getUserId());
repairTicketsReqVO.setUserIds(userIds);
}else if (names.contains(RepairConstants.REPAIR_STAFF)){
// 维修工的ID
repairTicketsReqVO.setUserIds(Collections.singletonList(SecurityFrameworkUtils.getLoginUserId()));
}else if (names.contains(RepairConstants.GENERAL_INSPECTION)){
// 维修总检不操作
}else return null;
return baseMapper.getPageType(repairTicketsReqVO, page);
return 2;
}
// 班组长
if (names.contains(RepairConstants.TEAM_LEADER)){
return 3;
}
// 维修工
if (names.contains(RepairConstants.REPAIR_STAFF)){
return 4;
}
// 啥也不是
return -1;
}
/**
* 接单
*
* @author 小李
* @date 11:48 2024/10/14
* @param id 工单ID
**/
@Override
public void updateTake(String id){
// 改变时看看是否已经被接了
int update = baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
.set(DlRepairTickets::getTicketsWorkStatus, "02")
.and(item -> {
item.eq(DlRepairTickets::getId, id)
.eq(DlRepairTickets::getTicketsWorkStatus, "01");
}));
if (update != 1){
throw exception0(500, "工单已被其他人接单了");
}
}
/**
* 指派员工通知施工
*
* @author 小李
* @date 15:34 2024/10/14
* @param reqVO 请求对象
**/
@Override
public void updateRepair(DlRepairTicketsReqVO reqVO){
// 指派的时候看下是不是已经有人接单了
int update = baseMapper.update(new LambdaUpdateWrapper<DlRepairTickets>()
.set(DlRepairTickets::getNowRepairId, reqVO.getNowRepairId())
.set(DlRepairTickets::getNowRepairName, reqVO.getNowRepairName())
.and(item -> {
item.eq(DlRepairTickets::getId, reqVO.getId())
.eq(DlRepairTickets::getTicketsWorkStatus, "01");
})
);
if (update != 1){
throw exception0(500, "工单已开始");
}
}
}

View File

@ -43,6 +43,8 @@
<result property="partStatus" column="part_status" />
<result property="ticketsWorkStatus" column="tickets_work_status" />
<result property="isFinish" column="is_finish" />
<result property="nowRepairId" column="now_repair_id" />
<result property="nowRepairName" column="now_repair_name" />
</resultMap>
<sql id="Base_SQL">
@ -83,7 +85,9 @@
profit,
part_status,
tickets_work_status,
is_finish
is_finish,
now_repair_id,
now_repair_name
from dl_repair_tickets drt
where drt.deleted = '0'
</sql>
@ -128,7 +132,7 @@
</select>
<select id="getPageType" resultMap="BaseResultMap">
select drt.id as id,
select distinct drt.id as id,
ticket_no,
repair_type,
user_id,
@ -165,7 +169,9 @@
profit,
part_status,
tickets_work_status,
is_finish
is_finish,
now_repair_id,
now_repair_name
from dl_repair_tickets drt
left join dl_repair_titem drti
on drt.id = drti.ticket_id
@ -195,13 +201,17 @@
<if test="map.userIds != null and map.userIds.size > 0">
and (
<foreach item="item" collection="map.userIds" index="index" open="" separator="or" close="">
instr(drti.repair_ids, concat(',', #{item}, ',')) > 0
find_in_set(#{item}, drti.repair_ids) > 0
</foreach>
)
</if>
<if test="map.isFinish != null and map.isFinish != '' and map.isFinish == 0 and map.userIds != null and map.userIds.size > 0">
and (drt.now_repair_id in
<foreach collection="map.userIds" item="item" index="index" open="(" separator="," close=")">
#{item}
</foreach>
)
</if>
order by drt.create_time desc
</select>
<sql id="IDS_TO_SQL">
</sql>
</mapper>