Browse Source

add: 工作票根据台账信息获取大模型分析结果接口开发

add: 机器人巡检开始指令功能开发
zhongwei
haungxing 2 months ago
parent
commit
f4d6bc4917
  1. 8
      hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java
  2. 6
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/service/impl/ControlAnswerResolveServiceImpl.java
  3. 7
      hzims-service/gglm-big-model/src/main/java/com/hnac/gglm/bigmodel/interactive/vo/AnswerVO.java
  4. 48
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/controller/PlanController.java
  5. 11
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/IPlanService.java
  6. 64
      hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/impl/PlanServiceImpl.java
  7. 7
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/controller/WorkTicketInfoController.java
  8. 4
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java
  9. 3
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/IWorkTicketInfoService.java
  10. 17
      hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/service/impl/WorkTicketInfoServiceImpl.java

8
hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/scheduled/DeviceLedgerScheduledTask.java

@ -54,9 +54,10 @@ public class DeviceLedgerScheduledTask {
R<Object> searchResult = weaviateClient.queryList(query); R<Object> searchResult = weaviateClient.queryList(query);
if(searchResult.isSuccess() && Func.isNotEmpty(searchResult.getData())) { if(searchResult.isSuccess() && Func.isNotEmpty(searchResult.getData())) {
// 取出数据ID 删除数据 // 取出数据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")) JSONArray data = Optional.ofNullable(queryJson).map(json -> json.getJSONObject("Get"))
.map(json -> json.getJSONArray(ScheduledConstant.DEVICE_LEDGER_CLASS_NAME)).get(); .map(json -> json.getJSONArray(ScheduledConstant.DEVICE_LEDGER_CLASS_NAME)).orElse(null);
if(Func.isNotEmpty(data)) {
List<String> ids = data.stream().map(item -> { List<String> ids = data.stream().map(item -> {
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(item)); JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(item));
return Optional.ofNullable(jsonObject) return Optional.ofNullable(jsonObject)
@ -65,7 +66,8 @@ public class DeviceLedgerScheduledTask {
.orElse(""); .orElse("");
}).filter(Func::isNotEmpty).collect(Collectors.toList()); }).filter(Func::isNotEmpty).collect(Collectors.toList());
if(Func.isNotEmpty(ids)) { if(Func.isNotEmpty(ids)) {
weaviateClient.deleteByIds(ids.toString(),ScheduledConstant.DEVICE_LEDGER_CLASS_NAME); weaviateClient.deleteByIds(ids.stream().collect(Collectors.joining(",")), ScheduledConstant.DEVICE_LEDGER_CLASS_NAME);
}
} }
} }
// 批量插入数据 // 批量插入数据

6
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); ExtraVO result = originExtra.toJavaObject(ExtraVO.class);
result.setType(FunctionConstants.TypeEnum.IMAGE_TEXT.getType()); result.setType(FunctionConstants.TypeEnum.IMAGE_TEXT.getType());
return result; return result;
} else if("jqrxj".equals(params.getString("itemId"))) {
HashMap<String, String> 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); ExtraVO result = originExtra.toJavaObject(ExtraVO.class);

7
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代表已完成") @ApiModelProperty("1代表代表正在进行问答,0代表已完成")
private Integer running; private Integer running;
@JSONField(name = "q_id")
private String queryId;
/** /**
* 正常发起一次问答status会经历012390的过程如果问答需要执行多次指令则可能会是01232390 * 正常发起一次问答status会经历012390的过程如果问答需要执行多次指令则可能会是01232390
* 9为大模型回复中answer中会不断填充内容 * 9为大模型回复中answer中会不断填充内容
@ -62,10 +65,10 @@ public class AnswerVO implements Serializable {
private String[] voiceAnswer; private String[] voiceAnswer;
public static AnswerVO error(String sessionId,String userId,String query) { 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) { 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});
} }
} }

48
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.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzinfo.exception.HzServiceException;
import com.hnac.hzinfo.inspect.Constants; 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.obj.utils.CodeUtils;
import com.hnac.hzinfo.inspect.plan.entity.PlanEntity; 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.IPlanObjectTemplateService;
import com.hnac.hzinfo.inspect.plan.service.IPlanService; 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.PlanListQueryVO;
import com.hnac.hzinfo.inspect.plan.vo.PlanVO; import com.hnac.hzinfo.inspect.plan.vo.PlanVO;
import com.hnac.hzinfo.inspect.utils.Condition; 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.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant; import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func; 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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
@ -47,6 +57,8 @@ public class PlanController extends BladeController {
private final IPlanService planService; private final IPlanService planService;
private final IPlanObjectTemplateService planObjectTemplateService; 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)); return R.status(planService.submitForHld(plan));
} }
@PostMapping("/initiateRobotPlan")
@ApiOperationSupport(order = 10)
@ApiOperation(value = "机器人计划", notes = "传入userId,routeId,routeName")
public R<Boolean> initiateRobotPlan(@RequestBody Map<String,String> request) {
String itemName = request.get("itemName");
// 拆解语义 剔除掉空格前内容以及以开始巡检结尾的字符串
String robotName = this.processString(itemName).trim();
List<RobotEntity> robotEntityList = robotService.list(Wrappers.<RobotEntity>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<RouteEntity> routeEntityList = routeService.list(Wrappers.<RouteEntity>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;
}
} }

11
hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/plan/service/IPlanService.java

@ -62,4 +62,15 @@ public interface IPlanService extends IService<PlanEntity> {
List<PlanOfflineVO> getPlans(List<Long> planIds); List<PlanOfflineVO> getPlans(List<Long> planIds);
Boolean revoke(Long planId); Boolean revoke(Long planId);
/**
* 发起一次机器人巡检计划
* @param userId 机器人用户id
* @param routeId 巡检路径id
* @param robotUserId 机器人用户id
* @return 发起结果
*/
Boolean initiateRobotPlan(Long userId, Long robotUserId, Long routeId, String routeName);
} }

64
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; 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 com.hnac.hzinfo.inspect.plan.vo.PlanOfflineVO;
import org.springblade.system.feign.ISysClient; import org.springblade.system.feign.ISysClient;
import com.alibaba.fastjson.JSON; 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.cache.UserCache;
import org.springblade.system.user.entity.User; import org.springblade.system.user.entity.User;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.core.Local;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -72,6 +80,8 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
private ITaskService taskService; private ITaskService taskService;
@Autowired @Autowired
private IDutyClassClient dutyClassClient; private IDutyClassClient dutyClassClient;
@Autowired
private IRouteService routeService;
/** /**
* 任务提醒缓存名字 cacheName * 任务提醒缓存名字 cacheName
@ -123,6 +133,60 @@ public class PlanServiceImpl extends ServiceImpl<PlanMapper, PlanEntity> impleme
return re; 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;
}
/** /**
* 保存巡检计划 * 保存巡检计划
*/ */

7
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)); 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));
}
} }

4
hzims-service/ticket/src/main/java/com/hnac/hzims/ticket/workTicket/feign/TicketInfoClient.java

@ -294,7 +294,7 @@ public class TicketInfoClient implements ITicketInfoClient {
} }
@Override @Override
@GetMapping(GET_WORK_TICKET_OVERVIEW) @GetMapping("/getWorkTicketOverview")
public R<List<String>> getWorkTicketOverview(@RequestParam("date") String date, @RequestParam("emCode") String emCode) { public R<List<String>> getWorkTicketOverview(@RequestParam("date") String date, @RequestParam("emCode") String emCode) {
LambdaQueryWrapper<WorkTicketInfoEntity> queryWrapper = Wrappers.<WorkTicketInfoEntity>lambdaQuery() LambdaQueryWrapper<WorkTicketInfoEntity> queryWrapper = Wrappers.<WorkTicketInfoEntity>lambdaQuery()
.eq(WorkTicketInfoEntity::getEmCode, emCode).like(WorkTicketInfoEntity::getPlanStartTime, date); .eq(WorkTicketInfoEntity::getEmCode, emCode).like(WorkTicketInfoEntity::getPlanStartTime, date);
@ -307,7 +307,7 @@ public class TicketInfoClient implements ITicketInfoClient {
}).collect(Collectors.toList()); }).collect(Collectors.toList());
return R.data(overviewList); return R.data(overviewList);
} }
return null; return R.data(null);
} }
} }

3
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.mp.support.Query;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.flow.core.entity.BladeFlow; import org.springblade.flow.core.entity.BladeFlow;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.List; import java.util.List;
@ -188,4 +189,6 @@ public interface IWorkTicketInfoService extends IService<WorkTicketInfoEntity> {
List<WorkTicketExportVO> exportWorkTicket(WorkTicketInfoDto req); List<WorkTicketExportVO> exportWorkTicket(WorkTicketInfoDto req);
Boolean cancel(WorkTicketInfoEntity entity); Boolean cancel(WorkTicketInfoEntity entity);
String getDeviceSummary(String stationCode, String emCode, String content);
} }

17
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; package com.hnac.hzims.ticket.workTicket.service.impl;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; 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.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@ -1339,4 +1341,19 @@ public class WorkTicketInfoServiceImpl extends ServiceImpl<WorkTicketInfoMapper,
entity.setFlowTaskName("线下作废"); entity.setFlowTaskName("线下作废");
return this.updateById(entity); return this.updateById(entity);
} }
@Override
public String getDeviceSummary(String stationCode, String emCode, String content) {
String chatId = IdWorker.get32UUID();
String queryId = IdWorker.get32UUID();
Map<String,String> 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;
}
} }

Loading…
Cancel
Save