From f4d6bc491727f8f94589db8ff3fb2e0c68151e8b Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Sat, 21 Sep 2024 16:21:25 +0800 Subject: [PATCH] =?UTF-8?q?add:=20=E5=B7=A5=E4=BD=9C=E7=A5=A8=E6=A0=B9?= =?UTF-8?q?=E6=8D=AE=E5=8F=B0=E8=B4=A6=E4=BF=A1=E6=81=AF=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=A4=A7=E6=A8=A1=E5=9E=8B=E5=88=86=E6=9E=90=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91=20add:=20=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA=E5=B7=A1=E6=A3=80=E5=BC=80=E5=A7=8B=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E5=8A=9F=E8=83=BD=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scheduled/DeviceLedgerScheduledTask.java | 24 ++++---- .../impl/ControlAnswerResolveServiceImpl.java | 6 ++ .../gglm/bigmodel/interactive/vo/AnswerVO.java | 7 ++- .../inspect/plan/controller/PlanController.java | 48 ++++++++++++++++ .../hzinfo/inspect/plan/service/IPlanService.java | 11 ++++ .../inspect/plan/service/impl/PlanServiceImpl.java | 64 ++++++++++++++++++++++ .../controller/WorkTicketInfoController.java | 7 +++ .../ticket/workTicket/feign/TicketInfoClient.java | 4 +- .../workTicket/service/IWorkTicketInfoService.java | 3 + .../service/impl/WorkTicketInfoServiceImpl.java | 17 ++++++ 10 files changed, 176 insertions(+), 15 deletions(-) diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java index 6ed8ea2..7b827cb 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java @@ -54,18 +54,20 @@ public class DeviceLedgerScheduledTask { R searchResult = weaviateClient.queryList(query); if(searchResult.isSuccess() && Func.isNotEmpty(searchResult.getData())) { // 取出数据ID 删除数据 - JSONObject queryJson = JSONObject.parseObject(searchResult.getData().toString()); + JSONObject queryJson = JSONObject.parseObject(JSON.toJSONString(searchResult.getData())); JSONArray data = Optional.ofNullable(queryJson).map(json -> json.getJSONObject("Get")) - .map(json -> json.getJSONArray(ScheduledConstant.DEVICE_LEDGER_CLASS_NAME)).get(); - List ids = data.stream().map(item -> { - JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(item)); - return Optional.ofNullable(jsonObject) - .map(json -> json.getJSONObject("_additional")) - .map(json -> json.getString("id")) - .orElse(""); - }).filter(Func::isNotEmpty).collect(Collectors.toList()); - if(Func.isNotEmpty(ids)) { - weaviateClient.deleteByIds(ids.toString(),ScheduledConstant.DEVICE_LEDGER_CLASS_NAME); + .map(json -> json.getJSONArray(ScheduledConstant.DEVICE_LEDGER_CLASS_NAME)).orElse(null); + if(Func.isNotEmpty(data)) { + List ids = data.stream().map(item -> { + JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(item)); + return Optional.ofNullable(jsonObject) + .map(json -> json.getJSONObject("_additional")) + .map(json -> json.getString("id")) + .orElse(""); + }).filter(Func::isNotEmpty).collect(Collectors.toList()); + if(Func.isNotEmpty(ids)) { + weaviateClient.deleteByIds(ids.stream().collect(Collectors.joining(",")), ScheduledConstant.DEVICE_LEDGER_CLASS_NAME); + } } } // 批量插入数据 diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java index 8b2eb80..fb33e07 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java @@ -50,6 +50,12 @@ public class ControlAnswerResolveServiceImpl implements IAnswerResolveService { ExtraVO result = originExtra.toJavaObject(ExtraVO.class); result.setType(FunctionConstants.TypeEnum.IMAGE_TEXT.getType()); return result; + } else if("jqrxj".equals(params.getString("itemId"))) { + HashMap param = new HashMap<>(1); + param.put("itemName", params.getString("itemName")); + log.info("机器人巡检传参为:{}", JSON.toJSONString(param)); + String body = HttpRequest.post("http://192.168.60.29:8080/api/hzinfo-inspect/plan/initiateRobotPlan").body(JSON.toJSONString(param)).execute().body(); + log.info("结果为:{}",body); } } ExtraVO result = originExtra.toJavaObject(ExtraVO.class); diff --git a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/vo/AnswerVO.java b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/vo/AnswerVO.java index 7c857bd..7f0232b 100644 --- a/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/vo/AnswerVO.java +++ b/hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/vo/AnswerVO.java @@ -34,6 +34,9 @@ public class AnswerVO implements Serializable { @ApiModelProperty("1代表代表正在进行问答,0代表已完成") private Integer running; + @JSONField(name = "q_id") + private String queryId; + /** * 正常发起一次问答,status会经历0、1、2、3、9、0的过程,如果问答需要执行多次指令,则可能会是0、1、2、3、2、3、9、0。 * 9为大模型回复中,answer中会不断填充内容 @@ -62,10 +65,10 @@ public class AnswerVO implements Serializable { private String[] voiceAnswer; public static AnswerVO error(String sessionId,String userId,String query) { - return new AnswerVO(sessionId,userId,0,-2,null,query, InfoMessageConstant.ERROR_MESSAGE, null,null,new String[]{InfoMessageConstant.ERROR_MESSAGE}); + return new AnswerVO(sessionId,userId,0,null,-2,null,query, InfoMessageConstant.ERROR_MESSAGE, null,null,new String[]{InfoMessageConstant.ERROR_MESSAGE}); } public static AnswerVO progress(String sessionId,String userId,String query,String message,Integer status) { - return new AnswerVO(sessionId,userId,1,status,null,query, message, null,null,new String[]{message}); + return new AnswerVO(sessionId,userId,1,null,status,null,query, message, null,null,new String[]{message}); } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java index 1e47b77..6106a16 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java @@ -2,12 +2,18 @@ package com.hnac.hzinfo.inspect.plan.controller; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzinfo.exception.HzServiceException; import com.hnac.hzinfo.inspect.Constants; +import com.hnac.hzinfo.inspect.ai.entity.RobotEntity; +import com.hnac.hzinfo.inspect.ai.service.IRobotService; import com.hnac.hzinfo.inspect.obj.utils.CodeUtils; import com.hnac.hzinfo.inspect.plan.entity.PlanEntity; +import com.hnac.hzinfo.inspect.plan.entity.RouteEntity; import com.hnac.hzinfo.inspect.plan.service.IPlanObjectTemplateService; import com.hnac.hzinfo.inspect.plan.service.IPlanService; +import com.hnac.hzinfo.inspect.plan.service.IRouteService; import com.hnac.hzinfo.inspect.plan.vo.PlanListQueryVO; import com.hnac.hzinfo.inspect.plan.vo.PlanVO; import com.hnac.hzinfo.inspect.utils.Condition; @@ -23,13 +29,17 @@ import org.springblade.core.mp.support.Query; import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.constant.BladeConstant; +import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.system.user.cache.UserCache; +import org.springblade.system.user.entity.User; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.time.LocalDate; import java.util.List; +import java.util.Map; /** @@ -47,6 +57,8 @@ public class PlanController extends BladeController { private final IPlanService planService; private final IPlanObjectTemplateService planObjectTemplateService; + private final IRobotService robotService; + private final IRouteService routeService; /** * 详情 @@ -189,4 +201,40 @@ public class PlanController extends BladeController { } return R.status(planService.submitForHld(plan)); } + + @PostMapping("/initiateRobotPlan") + @ApiOperationSupport(order = 10) + @ApiOperation(value = "机器人计划", notes = "传入userId,routeId,routeName") + public R initiateRobotPlan(@RequestBody Map request) { + String itemName = request.get("itemName"); + // 拆解语义 剔除掉空格前内容以及以开始巡检结尾的字符串 + String robotName = this.processString(itemName).trim(); + List robotEntityList = robotService.list(Wrappers.lambdaQuery().eq(RobotEntity::getName, robotName)); + if(CollectionUtil.isEmpty(robotEntityList)) { + throw new HzServiceException("未获取到机器人配置!"); + } + RobotEntity robotEntity = robotEntityList.get(0); + if(Func.isEmpty(robotEntity.getUserId())) { + throw new HzServiceException("未获取到机器人配置!"); + } + // 获取机器人巡检路线 + List routeEntityList = routeService.list(Wrappers.lambdaQuery().eq(RouteEntity::getCreateDept, UserCache.getUser(robotEntity.getUserId()).getDeptId())); + if(CollectionUtil.isEmpty(routeEntityList)) { + throw new HzServiceException("获取机器人巡检路线失败!"); + } + RouteEntity routeEntity = routeEntityList.get(0); + return R.status(planService.initiateRobotPlan(robotEntity.getUserId(), robotEntity.getUserId(), routeEntity.getId(), routeEntity.getRouteName())); + } + + private String processString(String input) { + String result = input; + int spaceIndex = input.indexOf(" "); + if(spaceIndex != -1) { + result = input.substring(spaceIndex); + } + if (result.endsWith("开始巡检")) { + result = result.substring(0, result.length() - "开始巡检".length()); + } + return result; + } } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/IPlanService.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/IPlanService.java index 38d8e2c..cf89cd5 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/IPlanService.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/IPlanService.java @@ -62,4 +62,15 @@ public interface IPlanService extends IService { List getPlans(List planIds); Boolean revoke(Long planId); + + /** + * 发起一次机器人巡检计划 + * @param userId 机器人用户id + * @param routeId 巡检路径id + * @param robotUserId 机器人用户id + * @return 发起结果 + */ + Boolean initiateRobotPlan(Long userId, Long robotUserId, Long routeId, String routeName); + + } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java index 64de9a2..a3c21ce 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java @@ -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 impleme private ITaskService taskService; @Autowired private IDutyClassClient dutyClassClient; + @Autowired + private IRouteService routeService; /** * 任务提醒缓存名字 cacheName @@ -123,6 +133,60 @@ public class PlanServiceImpl extends ServiceImpl 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 routeObject = JSON.parseArray(robotPlan.getRouteData(), JSONObject.class); + List 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; + } + /** * 保存巡检计划 */ diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/controller/WorkTicketInfoController.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/controller/WorkTicketInfoController.java index 376bbcb..0c09209 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/controller/WorkTicketInfoController.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/controller/WorkTicketInfoController.java @@ -278,5 +278,12 @@ public class WorkTicketInfoController { return R.status(workTicketInfoService.cancel(entity)); } + @GetMapping("/getDeviceSummary") + @ApiOperationSupport(order = 60) + @ApiOperation(value = "获取工作票总结") + public R getDeviceSummary(@RequestParam("stationCode") String stationCode, @RequestParam("emCode") String emCode, @RequestParam("content") String content) { + return R.data(workTicketInfoService.getDeviceSummary(stationCode, emCode, content)); + } + } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java index 977fe88..d742272 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java @@ -294,7 +294,7 @@ public class TicketInfoClient implements ITicketInfoClient { } @Override - @GetMapping(GET_WORK_TICKET_OVERVIEW) + @GetMapping("/getWorkTicketOverview") public R> getWorkTicketOverview(@RequestParam("date") String date, @RequestParam("emCode") String emCode) { LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery() .eq(WorkTicketInfoEntity::getEmCode, emCode).like(WorkTicketInfoEntity::getPlanStartTime, date); @@ -307,7 +307,7 @@ public class TicketInfoClient implements ITicketInfoClient { }).collect(Collectors.toList()); return R.data(overviewList); } - return null; + return R.data(null); } } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java index d3509ce..4a91019 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java @@ -20,6 +20,7 @@ import org.springblade.core.mp.support.BladePage; import org.springblade.core.mp.support.Query; import org.springblade.core.tool.api.R; import org.springblade.flow.core.entity.BladeFlow; +import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletResponse; import java.util.List; @@ -188,4 +189,6 @@ public interface IWorkTicketInfoService extends IService { List exportWorkTicket(WorkTicketInfoDto req); Boolean cancel(WorkTicketInfoEntity entity); + + String getDeviceSummary(String stationCode, String emCode, String content); } diff --git a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java index 4a727bf..2538182 100644 --- a/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java +++ b/hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java @@ -1,6 +1,7 @@ package com.hnac.hzims.ticket.workTicket.service.impl; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; +import cn.hutool.http.HttpRequest; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -8,6 +9,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; @@ -1339,4 +1341,19 @@ public class WorkTicketInfoServiceImpl extends ServiceImpl params = new HashMap(); + params.put("station_id",stationCode); + params.put("device_id",emCode); + params.put("desc",content); + params.put("chat_id",chatId); + params.put("q_id",queryId); + params.put("user_id",AuthUtil.getUserId().toString()); + HttpRequest.post("http://192.168.60.16:9997/custom/device_ledger_summary").body(JSON.toJSONString(params)).execute(); + return chatId; + } }