|
|
|
@ -3,6 +3,7 @@ package com.hnac.hzims.operational.maintenance.scheduled;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
|
|
|
import com.hnac.hzims.equipment.entity.EmInfoEntity; |
|
|
|
|
import com.hnac.hzims.equipment.feign.IEmInfoClient; |
|
|
|
|
import com.hnac.hzims.operational.constants.FlowKeyConstants; |
|
|
|
|
import com.hnac.hzims.operational.constants.RedisKeyConstants; |
|
|
|
@ -61,6 +62,7 @@ public class MaintenanceTaskSchedule {
|
|
|
|
|
private final IFlowClient flowClient; |
|
|
|
|
private final IImsDutyMainService dutyMainService; |
|
|
|
|
private final RedisTemplate redisTemplate; |
|
|
|
|
private final IEmInfoClient emInfoClient; |
|
|
|
|
|
|
|
|
|
@XxlJob(GENERATE_MAINTENANCE_TASK_SCHEDULE) |
|
|
|
|
public ReturnT<String> execute(String param) throws Exception { |
|
|
|
@ -87,24 +89,24 @@ public class MaintenanceTaskSchedule {
|
|
|
|
|
OperMaintenanceTaskEntity taskEntity = BeanUtil.copy(plan,OperMaintenanceTaskEntity.class); |
|
|
|
|
taskEntity.setPlanId(plan.getId()); |
|
|
|
|
taskEntity.setDisposer(Optional.ofNullable(plan.getDisposer()).map(String::valueOf).orElse(null)); |
|
|
|
|
taskEntity.setDisposerName(Optional.ofNullable(plan.getDisposer()).map(s -> |
|
|
|
|
{ |
|
|
|
|
User user = UserCache.getUser(s); |
|
|
|
|
if (ObjectUtil.isNotEmpty(user)){ |
|
|
|
|
return user.getName(); |
|
|
|
|
}else { |
|
|
|
|
return ""; |
|
|
|
|
} |
|
|
|
|
}).filter(s->StringUtils.isNotBlank(s)).orElse(null)); |
|
|
|
|
String disposerName = Optional.ofNullable(plan.getDisposer()).map(UserCache::getUser).map(User::getName).orElse(null); |
|
|
|
|
taskEntity.setDisposerName(disposerName); |
|
|
|
|
LocalDateTime disposeTime = taskEntity.getDisposeTime().toInstant() |
|
|
|
|
.atZone(ZoneId.systemDefault()).toLocalDateTime(); |
|
|
|
|
taskEntity.setPlanEndTime(disposeTime.plusHours(taskEntity.getHours())); |
|
|
|
|
if(StringUtil.isNotBlank(plan.getEmCode())){ |
|
|
|
|
String[] emCodeList = plan.getEmCode().split(","); |
|
|
|
|
for(String emCode : emCodeList){ |
|
|
|
|
List<String> emCodeList = Func.toStrList(",", plan.getEmCode()); |
|
|
|
|
emCodeList.stream().filter(StringUtil::isNotBlank).forEach(emCode -> { |
|
|
|
|
EmInfoEntity emInfoEntity = emInfoClient.getByCode(emCode); |
|
|
|
|
if(ObjectUtil.isEmpty(emInfoEntity)) { |
|
|
|
|
log.error( "[{}]设备编号未查询到相关设备,生成任务失败!",emCode); |
|
|
|
|
XxlJobLogger.log("[" + emCode + "]设备编号未查询到相关设备,生成任务失败!"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
taskEntity.setEmCode(emCode); |
|
|
|
|
taskEntity.setEmName(emInfoEntity.getName()); |
|
|
|
|
this.createTask(taskEntity,plan); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
this.createTask(taskEntity,plan); |
|
|
|
@ -139,7 +141,7 @@ public class MaintenanceTaskSchedule {
|
|
|
|
|
Instant instant = task.getDisposeTime().toInstant(); |
|
|
|
|
ZoneId zoneId = ZoneId.systemDefault(); |
|
|
|
|
LocalDateTime disposeTime = instant.atZone(zoneId).toLocalDateTime(); |
|
|
|
|
task.setPlanEndTime(disposeTime.plusHours(task.getHours())); |
|
|
|
|
task.setPlanEndTime(disposeTime.plusHours(task.getPeriod())); |
|
|
|
|
// 当模式为班次时
|
|
|
|
|
Integer maintenanceModel = plan.getMaintenanceModel(); |
|
|
|
|
if(Func.isNotEmpty(maintenanceModel) && maintenanceModel == 2 ) { |
|
|
|
@ -149,20 +151,11 @@ public class MaintenanceTaskSchedule {
|
|
|
|
|
ImsDutyMainEntity entity = dutyMainService.getOne(dutyQuery); |
|
|
|
|
if (ObjectUtil.isNotEmpty(entity) && StringUtils.isNotEmpty(entity.getDutyPersonIds())) { |
|
|
|
|
String userId = entity.getDutyPersonIds(); |
|
|
|
|
String[] split = userId.split("\\^"); |
|
|
|
|
task.setDisposer(userId.replaceAll("\\^", ",")); |
|
|
|
|
if (ArrayUtils.isNotEmpty(split)){ |
|
|
|
|
List<String> list = Arrays.asList(split); |
|
|
|
|
String disposerName= list.stream().map(s->{ |
|
|
|
|
User user = UserCache.getUser(Long.valueOf(s)); |
|
|
|
|
if (ObjectUtil.isNotEmpty(user)){ |
|
|
|
|
return user.getName();} |
|
|
|
|
return ""; |
|
|
|
|
}).filter(s->StringUtils.isNotBlank(s)).collect(Collectors.joining(",")); |
|
|
|
|
if (StringUtils.isNotBlank(disposerName)) { |
|
|
|
|
task.setDisposerName(disposerName); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
List<Long> userIdList = Func.toLongList("\\^", userId); |
|
|
|
|
String disposerName = userIdList.stream().map(UserCache::getUser).filter(Func::isNotEmpty) |
|
|
|
|
.map(User::getName).filter(StringUtil::isNotBlank).collect(Collectors.joining(",")); |
|
|
|
|
task.setDisposerName(Optional.ofNullable(disposerName).filter(StringUtil::isNotBlank).orElse(null)); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
XxlJobLogger.log("ID为:"+plan.getId()+"的日常维护计划未获取到值班人员,未生成任务。"); |
|
|
|
@ -205,5 +198,4 @@ public class MaintenanceTaskSchedule {
|
|
|
|
|
R<BladeFlow> flowResult = flowClient.startProcessInstanceContainNameByKey(FlowKeyConstants.MAINTENANCE_TASK_FLOW_KEY, String.valueOf(task.getId()), task.getTitle(), params); |
|
|
|
|
return Optional.ofNullable(flowResult).filter(r -> r.isSuccess()).map(R::getData).map(BladeFlow::getProcessInstanceId).orElse(null); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|