|
|
|
@ -1,5 +1,10 @@
|
|
|
|
|
package com.hnac.hzinfo.inspect.plan.service.impl; |
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
|
import com.hnac.hzims.common.constant.CommonConstant; |
|
|
|
|
import com.hnac.hzinfo.exception.HzServiceException; |
|
|
|
|
import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; |
|
|
|
|
import com.hnac.hzinfo.inspect.plan.vo.PlanOfflineVO; |
|
|
|
|
import org.springblade.system.feign.ISysClient; |
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
@ -38,11 +43,14 @@ import org.springblade.core.tool.utils.SpringUtil;
|
|
|
|
|
import org.springblade.system.user.cache.UserCache; |
|
|
|
|
import org.springblade.system.user.entity.User; |
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
import org.springframework.cglib.core.Local; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.LocalTime; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
@ -72,6 +80,8 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
|
|
|
|
|
private ITaskService taskService; |
|
|
|
|
@Autowired |
|
|
|
|
private IDutyClassClient dutyClassClient; |
|
|
|
|
@Autowired |
|
|
|
|
private IRouteService routeService; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 任务提醒缓存名字 cacheName |
|
|
|
@ -123,6 +133,60 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
|
|
|
|
|
return re; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public Boolean initiateRobotPlan(Long userId, Long robotUserId, Long routeId, String routeName) { |
|
|
|
|
PlanEntity robotPlan = new PlanEntity(); |
|
|
|
|
// 获取巡检路线信息
|
|
|
|
|
RouteEntity routeEntity = routeService.getById(routeId); |
|
|
|
|
if(Func.isEmpty(routeEntity.getRouteData())) { |
|
|
|
|
throw new HzServiceException("路径为空,无法生成机器人巡检任务"); |
|
|
|
|
} |
|
|
|
|
robotPlan.setRouteData(routeEntity.getRouteData()); |
|
|
|
|
robotPlan.setAutoVideo(PlanContants.InspectTypeEnum.ROBOT.getVal()); |
|
|
|
|
robotPlan.setCycle(PlanContants.PlanCycleEnum.NEVER_CYCLE.getCycle()); |
|
|
|
|
robotPlan.setStartRemind(1); |
|
|
|
|
robotPlan.setEndRemind(1); |
|
|
|
|
robotPlan.setStartTime(LocalDate.now()); |
|
|
|
|
robotPlan.setEndTime(LocalDate.now()); |
|
|
|
|
robotPlan.setTaskTimesADay(1); |
|
|
|
|
robotPlan.setType(PlanContants.PlanTypeEnum.USER_TYPE.getType()); |
|
|
|
|
LocalTime nowTime = LocalTime.now(); |
|
|
|
|
JSONObject execTime = new JSONObject(); |
|
|
|
|
execTime.put("execStartTime", nowTime.format(DateTimeFormatter.ofPattern("HH:mm:ss"))); |
|
|
|
|
execTime.put("execEndTime", nowTime.plusMinutes(30).format(DateTimeFormatter.ofPattern("HH:mm:ss"))); |
|
|
|
|
robotPlan.setExecTimeJson(JSON.toJSONString(Lists.newArrayList(execTime))); |
|
|
|
|
robotPlan.setPlanType(PlanContants.PlanContentTypeEnum.COMMON.getDesc()); |
|
|
|
|
robotPlan.setRouteId(routeId); |
|
|
|
|
robotPlan.setName("大模型-[" + routeName + "]机器人巡检任务"); |
|
|
|
|
robotPlan.setMessageTemplateId(1646693931483721730L); |
|
|
|
|
robotPlan.setRouteName(routeName); |
|
|
|
|
robotPlan.setMethod(PlanContants.PlanMethodEnum.CONCURRENT.getMethod()); |
|
|
|
|
robotPlan.setCreateUser(userId); |
|
|
|
|
robotPlan.setCreateDept(routeEntity.getCreateDept()); |
|
|
|
|
robotPlan.setUpdateUser(userId); |
|
|
|
|
// 将任务置为已审核状态
|
|
|
|
|
robotPlan.setStatus(Integer.valueOf(PlanContants.PlanStatusEnum.CHECK_STATUS.getStatus())); |
|
|
|
|
robotPlan.setApprover(userId); |
|
|
|
|
robotPlan.setApproveTime(LocalDateTime.now()); |
|
|
|
|
robotPlan.setCode(String.valueOf(System.currentTimeMillis())); |
|
|
|
|
robotPlan.setTenantId(CommonConstant.TENANT_ID); |
|
|
|
|
this.save(robotPlan); |
|
|
|
|
// 保存用户巡检计划关联关系
|
|
|
|
|
PlanUserEntity planUser = PlanUserEntity.builder().planId(robotPlan.getId()).userId(robotUserId).build(); |
|
|
|
|
planUserService.save(planUser); |
|
|
|
|
List<JSONObject> routeObject = JSON.parseArray(robotPlan.getRouteData(), JSONObject.class); |
|
|
|
|
List<PlanObjectTemplateEntity> planObjectTemplates = routeObject.stream().map(json -> { |
|
|
|
|
PlanObjectTemplateEntity pot = new PlanObjectTemplateEntity(); |
|
|
|
|
pot.setObjectId(Long.valueOf(json.get("objectId").toString())); |
|
|
|
|
pot.setTemplateId(Long.valueOf(json.get("templateId").toString())); |
|
|
|
|
pot.setPlanId(robotPlan.getId()); |
|
|
|
|
return pot; |
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
planObjectTemplateService.saveBatch(planObjectTemplates); |
|
|
|
|
genPresentTask(robotPlan.getId()); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 保存巡检计划 |
|
|
|
|
*/ |
|
|
|
|