超时自动总检
This commit is contained in:
parent
60bb0a296a
commit
dc6a6e1bc4
@ -126,5 +126,7 @@ public class BaseConstants {
|
||||
/** 施工中 */
|
||||
public static final String REPAIR_RECORD_TYPE_SGZ = "sgz";
|
||||
|
||||
/** 字典:超时自动总检配置 */
|
||||
public static final String AUTO_INSPECTION = "auto_inspection";
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.job;
|
||||
|
||||
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
||||
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
|
||||
import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 超时自动总检的定时任务
|
||||
*
|
||||
* @author 小李
|
||||
* @date 16:32 2024/10/26
|
||||
**/
|
||||
@Component
|
||||
@TenantJob
|
||||
@Slf4j
|
||||
public class AutoInspectionJob implements JobHandler {
|
||||
|
||||
@Resource
|
||||
private DlRepairTicketsService repairTicketsService;
|
||||
|
||||
@Override
|
||||
public String execute(String param) throws Exception {
|
||||
repairTicketsService.autoInspection();
|
||||
return null;
|
||||
}
|
||||
}
|
@ -209,4 +209,12 @@ public interface DlRepairTicketsService extends IService<DlRepairTickets> {
|
||||
* @param id 维修工单ID
|
||||
**/
|
||||
boolean syncTicketWaresToTicket(String id);
|
||||
|
||||
/**
|
||||
* 超时自动总检
|
||||
*
|
||||
* @author 小李
|
||||
* @date 16:35 2024/10/26
|
||||
**/
|
||||
void autoInspection();
|
||||
}
|
||||
|
@ -66,6 +66,9 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -1047,6 +1050,89 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
||||
throw exception0(500, "系统错误");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 超时自动总检
|
||||
*
|
||||
* @author 小李
|
||||
* @date 16:35 2024/10/26
|
||||
**/
|
||||
@Override
|
||||
@DSTransactional
|
||||
public void autoInspection(){
|
||||
// 查所有需要总检但还没总检的工单
|
||||
List<DlRepairTickets> tickets = baseMapper.selectList(new LambdaQueryWrapper<DlRepairTickets>().eq(DlRepairTickets::getTicketsWorkStatus, "05"));
|
||||
// 如果没有,直接退出
|
||||
if (CollectionUtil.isEmpty(tickets)){
|
||||
return;
|
||||
}
|
||||
// 获取超时自动总检配置的时间
|
||||
List<DictDataRespDTO> dataList = dictDataApi.getDictDataList(BaseConstants.AUTO_INSPECTION);
|
||||
// 理论上是只有一个的,但防止被删了或者别的什么原因,直接报错
|
||||
DictDataRespDTO dictDataRespDTO = dataList.stream().findFirst().orElse(null);
|
||||
if (ObjectUtil.isEmpty(dictDataRespDTO)){
|
||||
log.error("超时自动总检时间没有配置");
|
||||
return;
|
||||
}
|
||||
// 计算超时的工单
|
||||
// 超时时间
|
||||
int time = Integer.parseInt(dictDataRespDTO.getValue());
|
||||
|
||||
List<DlRepairTickets> list = tickets.stream().filter(item -> {
|
||||
// 当前时间---放到里面是因为如果数据量多,动态获取当前时间更能满足需求
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return ChronoUnit.MINUTES.between(item.getUpdateTime(), now) > time;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// 同步工单的配件申请表到工单,如果都没超时,退出
|
||||
if (CollectionUtil.isEmpty(list)){
|
||||
return;
|
||||
}
|
||||
// 先取总检们
|
||||
// 取这个角色的角色信息
|
||||
RoleReqDTO roleInfo = roleApi.getRoleInfo(RepairRoleEnum.INSPECTION.getCode());
|
||||
// 通过角色信息查有这个角色的人
|
||||
List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId());
|
||||
// 如果没有总检,直接报错退出
|
||||
if (CollectionUtil.isEmpty(ids)){
|
||||
log.error("系统中没有总检");
|
||||
return;
|
||||
}
|
||||
// 在过滤一次,主要是过滤掉没法同步申请表到工单的数据
|
||||
List<DlRepairTickets> result = list.stream().filter(item -> {
|
||||
boolean flag = syncTicketWaresToTicket(item.getId());
|
||||
// 如果出现更新不到的情况
|
||||
if (!flag) {
|
||||
// 通知总检,让其手动操作
|
||||
ids.forEach(id -> {
|
||||
repairWorkerService.sentMessage(id, "待总检工单:" + item.getTicketNo() + "已经超时,但无法自动总检,请手动处理");
|
||||
});
|
||||
}
|
||||
return flag;
|
||||
}).collect(Collectors.toList());
|
||||
// 如果没有记录同步成功,报错并退出
|
||||
if (CollectionUtil.isEmpty(result)){
|
||||
log.error("自动总检失败,原因可能是无法同步申请表到工单");
|
||||
}
|
||||
// 移交服务顾问
|
||||
List<DlRepairTickets> updateTickets = result.stream().map(item -> {
|
||||
DlRepairTickets ticket = new DlRepairTickets();
|
||||
ticket.setId(item.getId());
|
||||
ticket.setNowRepairId(Long.valueOf(item.getAdviserId()));
|
||||
ticket.setNowRepairName(item.getAdviserName());
|
||||
return ticket;
|
||||
}).collect(Collectors.toList());
|
||||
baseMapper.updateById(updateTickets);
|
||||
// 通知总检和服务顾问
|
||||
result.forEach(item -> {
|
||||
repairWorkerService.sentMessage(Long.valueOf(item.getAdviserId()), "您有新的工单可以出厂检验");
|
||||
ids.forEach(id -> {
|
||||
repairWorkerService.sentMessage(id, "工单:" + item.getTicketNo() + "已由系统自动总检并移交服务顾问");
|
||||
});
|
||||
// 记录日志
|
||||
repairRecordsService.saveRepairRecord(item.getId(), null, RecordTypeEnum.ZJ.getCode(), "该工单由系统自动总检完成", null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user