|
@@ -8,6 +8,9 @@ import com.slibra.business.domain.*;
|
|
import com.slibra.business.mapper.*;
|
|
import com.slibra.business.mapper.*;
|
|
import com.slibra.business.req.ChatReq;
|
|
import com.slibra.business.req.ChatReq;
|
|
import com.slibra.business.req.DecisionReq;
|
|
import com.slibra.business.req.DecisionReq;
|
|
|
|
+import com.slibra.business.req.WorkOrderReq;
|
|
|
|
+import com.slibra.business.res.WorkOrderRes;
|
|
|
|
+import com.slibra.business.service.IFrontService;
|
|
import com.slibra.common.core.controller.BaseController;
|
|
import com.slibra.common.core.controller.BaseController;
|
|
import com.slibra.common.enums.BusinessEnum;
|
|
import com.slibra.common.enums.BusinessEnum;
|
|
import com.slibra.common.exception.ServiceException;
|
|
import com.slibra.common.exception.ServiceException;
|
|
@@ -22,6 +25,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.pytorch.serve.grpc.inference.InferenceAPIsServiceGrpc;
|
|
import org.pytorch.serve.grpc.inference.InferenceAPIsServiceGrpc;
|
|
import org.pytorch.serve.grpc.inference.PredictionResponse;
|
|
import org.pytorch.serve.grpc.inference.PredictionResponse;
|
|
import org.pytorch.serve.grpc.inference.PredictionsRequest;
|
|
import org.pytorch.serve.grpc.inference.PredictionsRequest;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -60,6 +64,9 @@ public class GRPCController extends BaseController {
|
|
@Autowired
|
|
@Autowired
|
|
private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
|
|
private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IFrontService frontService;
|
|
|
|
+
|
|
|
|
|
|
/*private InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub getStub(){
|
|
/*private InferenceAPIsServiceGrpc.InferenceAPIsServiceBlockingStub getStub(){
|
|
return InferenceAPIsServiceGrpc.newBlockingStub(ManagedChannelBuilder.forAddress("10.0.0.24", 17070)
|
|
return InferenceAPIsServiceGrpc.newBlockingStub(ManagedChannelBuilder.forAddress("10.0.0.24", 17070)
|
|
@@ -262,6 +269,7 @@ public class GRPCController extends BaseController {
|
|
|
|
|
|
/**
|
|
/**
|
|
* RAG+⼤模型的调⽤参数
|
|
* RAG+⼤模型的调⽤参数
|
|
|
|
+ * 2024年6月17日09:40:38 工单新增 自定义工单处理
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
@PostMapping(value = "/inferStreamRag")
|
|
@PostMapping(value = "/inferStreamRag")
|
|
@@ -277,7 +285,9 @@ public class GRPCController extends BaseController {
|
|
//请求参数
|
|
//请求参数
|
|
Integer module = chatReq.getModule();//来自那个模块
|
|
Integer module = chatReq.getModule();//来自那个模块
|
|
Date reportDate = chatReq.getReportDate();//如果传过值来了 代表的是工单类型的问答
|
|
Date reportDate = chatReq.getReportDate();//如果传过值来了 代表的是工单类型的问答
|
|
- if(Objects.isNull(reportDate) && module == 1){//工单 必须要输入日期
|
|
|
|
|
|
+ String timeBegin = chatReq.getTimeBegin();
|
|
|
|
+ String timeEnd = chatReq.getTimeEnd();
|
|
|
|
+ if((Objects.isNull(reportDate) || StringUtils.isBlank(timeBegin) && StringUtils.isBlank(timeEnd)) && module == 1){//工单 必须要输入日期
|
|
//智能工单需要传入一个时间的参数
|
|
//智能工单需要传入一个时间的参数
|
|
try {
|
|
try {
|
|
outputStream = response.getOutputStream();
|
|
outputStream = response.getOutputStream();
|
|
@@ -293,29 +303,36 @@ public class GRPCController extends BaseController {
|
|
int isStrong = Objects.isNull(chatReq.getIsStrong()) ? 0 : chatReq.getIsStrong();
|
|
int isStrong = Objects.isNull(chatReq.getIsStrong()) ? 0 : chatReq.getIsStrong();
|
|
//如果是工单,需要特殊处理一下showVal和question
|
|
//如果是工单,需要特殊处理一下showVal和question
|
|
if(1 == module){
|
|
if(1 == module){
|
|
- //获取前一天的日期
|
|
|
|
- Date beforeYesterday = DateUtils.plusDate(-1, reportDate);
|
|
|
|
- //先用日期获取当天和前一天的数据,如果获取不到,则提示错误信息
|
|
|
|
- String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, reportDate);
|
|
|
|
- String dateBefore = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, beforeYesterday);
|
|
|
|
- chatReq.setShowVal(GONGDAN_TITLE.replace("#{0}", date));//处理展示的标题
|
|
|
|
- String currentDate = DateUtils.parseDateToStr(DateUtils.YYYYMMDD_TS, reportDate);
|
|
|
|
- String earlyDate = DateUtils.parseDateToStr(DateUtils.YYYYMMDD_TS, beforeYesterday);
|
|
|
|
- List<TXinyiDaily> tXinyiDailiesNow = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(currentDate).build());
|
|
|
|
- List<TXinyiDaily> tXinyiDailiesBefore = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(earlyDate).build());
|
|
|
|
- if(CollectionUtils.isEmpty(tXinyiDailiesNow) || CollectionUtils.isEmpty(tXinyiDailiesBefore)){
|
|
|
|
- //没有查询到数据
|
|
|
|
- try {
|
|
|
|
- outputStream = response.getOutputStream();
|
|
|
|
- outputStream.write(CHAT_GONGDAN_2_ERROR_MSG.getBytes());
|
|
|
|
- outputStream.flush();
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- throw new RuntimeException(e);
|
|
|
|
|
|
+ if(StringUtils.isBlank(timeBegin) && StringUtils.isBlank(timeEnd)){//按天生成工单
|
|
|
|
+ //获取前一天的日期
|
|
|
|
+ Date beforeYesterday = DateUtils.plusDate(-1, reportDate);
|
|
|
|
+ //先用日期获取当天和前一天的数据,如果获取不到,则提示错误信息
|
|
|
|
+ String date = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, reportDate);
|
|
|
|
+ String dateBefore = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, beforeYesterday);
|
|
|
|
+ chatReq.setShowVal(GONGDAN_TITLE.replace("#{0}", date));//处理展示的标题
|
|
|
|
+ String currentDate = DateUtils.parseDateToStr(DateUtils.YYYYMMDD_TS, reportDate);
|
|
|
|
+ String earlyDate = DateUtils.parseDateToStr(DateUtils.YYYYMMDD_TS, beforeYesterday);
|
|
|
|
+ List<TXinyiDaily> tXinyiDailiesNow = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(currentDate).build());
|
|
|
|
+ List<TXinyiDaily> tXinyiDailiesBefore = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(earlyDate).build());
|
|
|
|
+ if(CollectionUtils.isEmpty(tXinyiDailiesNow) || CollectionUtils.isEmpty(tXinyiDailiesBefore)){
|
|
|
|
+ //没有查询到数据
|
|
|
|
+ try {
|
|
|
|
+ outputStream = response.getOutputStream();
|
|
|
|
+ outputStream.write(CHAT_GONGDAN_2_ERROR_MSG.getBytes());
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
+ }
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- return;
|
|
|
|
|
|
+ //如果查询到了 拼装数据
|
|
|
|
+ chatReq.setQuestion(this.buildGDQuestion(date, dateBefore, tXinyiDailiesNow.get(0), tXinyiDailiesBefore.get(0)));
|
|
|
|
+ }else{//自定义工单
|
|
|
|
+ chatReq.setShowVal(GONGDAN_TITLE_CUSTOM.replace("#{0}", timeBegin).replace("#{1}", timeEnd));//处理展示的标题
|
|
|
|
+ WorkOrderReq workOrderReq = new WorkOrderReq();
|
|
|
|
+ BeanUtils.copyProperties(chatReq, workOrderReq);
|
|
|
|
+ chatReq.setQuestion(this.buildGDQuestionCustom(frontService.customWorkOrder(workOrderReq), workOrderReq));
|
|
}
|
|
}
|
|
- //如果查询到了 拼装数据
|
|
|
|
- chatReq.setQuestion(this.buildGDQuestion(date, dateBefore, tXinyiDailiesNow.get(0), tXinyiDailiesBefore.get(0)));
|
|
|
|
isStrong = 1;
|
|
isStrong = 1;
|
|
}
|
|
}
|
|
String ipAddr = IpUtils.getIpAddr();//获取用户的ip地址 传给大模型
|
|
String ipAddr = IpUtils.getIpAddr();//获取用户的ip地址 传给大模型
|
|
@@ -402,6 +419,59 @@ public class GRPCController extends BaseController {
|
|
// return AjaxResult.success("ok");
|
|
// return AjaxResult.success("ok");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private String buildGDQuestionCustom(List<WorkOrderRes> workOrderRes, WorkOrderReq workOrderReq) {
|
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
|
+ sb.append(GONGDAN_PROMPT_CUSTOM_BEGIN.replace("{0}", workOrderReq.getTimeBegin()).replace("{1}", workOrderReq.getTimeEnd()));
|
|
|
|
+ if(workOrderReq.getJsSlq() || workOrderReq.getJsSs() || workOrderReq.getJsTp() || workOrderReq.getJsTn() || workOrderReq.getJsCod() || workOrderReq.getJsNh3()){
|
|
|
|
+ sb.append("进水:\n");
|
|
|
|
+ for (WorkOrderRes workOrderRe : workOrderRes) {
|
|
|
|
+ sb.append(workOrderRe.getTime()).append(":");
|
|
|
|
+ if(workOrderReq.getJsCod())
|
|
|
|
+ sb.append(workOrderRe.getJsCod()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getJsTn())
|
|
|
|
+ sb.append(workOrderRe.getJsTn()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getJsTp())
|
|
|
|
+ sb.append(workOrderRe.getJsTp()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getJsNh3())
|
|
|
|
+ sb.append(workOrderRe.getJsNh3()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getJsSs())
|
|
|
|
+ sb.append(workOrderRe.getJsSs()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getJsSlq())
|
|
|
|
+ sb.append(workOrderRe.getJsSlq()).append("m³/d、");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if(workOrderReq.getCsSlqc() || workOrderReq.getCsSs() || workOrderReq.getCsTp() || workOrderReq.getCsTn() || workOrderReq.getCsCod() || workOrderReq.getCsNh3()){
|
|
|
|
+ sb.append("出水:\n");
|
|
|
|
+ for (WorkOrderRes workOrderRe : workOrderRes) {
|
|
|
|
+ sb.append(workOrderRe.getTime()).append(":");
|
|
|
|
+ if(workOrderReq.getCsCod())
|
|
|
|
+ sb.append(workOrderRe.getCsCod()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getCsTn())
|
|
|
|
+ sb.append(workOrderRe.getCsTn()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getCsTp())
|
|
|
|
+ sb.append(workOrderRe.getCsTp()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getCsNh3())
|
|
|
|
+ sb.append(workOrderRe.getCsNh3()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getCsSs())
|
|
|
|
+ sb.append(workOrderRe.getCsSs()).append("mg/L、");
|
|
|
|
+ if(workOrderReq.getCsSlqc())
|
|
|
|
+ sb.append(workOrderRe.getCsSlqc()).append("m³/d、");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sb.append(GONGDAN_PROMPT_CUSTOM_END_1);
|
|
|
|
+ if(workOrderReq.getJsCod() || workOrderReq.getCsCod())
|
|
|
|
+ sb.append("化学需氧量(COD)、");
|
|
|
|
+ if(workOrderReq.getJsTp() || workOrderReq.getCsTp())
|
|
|
|
+ sb.append("总磷(TP)、");
|
|
|
|
+ if(workOrderReq.getJsTn() || workOrderReq.getCsTn())
|
|
|
|
+ sb.append("总氮(TN)、");
|
|
|
|
+ if(workOrderReq.getJsSs() || workOrderReq.getCsSs())
|
|
|
|
+ sb.append("SS、");
|
|
|
|
+ if(workOrderReq.getJsNh3() || workOrderReq.getCsNh3())
|
|
|
|
+ sb.append("氨氮、");
|
|
|
|
+ sb.append(GONGDAN_PROMPT_CUSTOM_END_2);
|
|
|
|
+ return sb.toString();
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|