FrontController.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. package com.slibra.web.controller.business;
  2. import com.alibaba.fastjson2.JSON;
  3. import com.alibaba.fastjson2.JSONWriter;
  4. import com.slibra.business.domain.TXinyiChatRecord;
  5. import com.slibra.business.domain.TXinyiWarningRecord;
  6. import com.slibra.business.mapper.*;
  7. import com.slibra.business.req.ChatReq;
  8. import com.slibra.business.req.WorkOrderReq;
  9. import com.slibra.business.service.IFrontService;
  10. import com.slibra.common.DecimalUtils;
  11. import com.slibra.common.constant.MyConstants;
  12. import com.slibra.common.core.controller.BaseController;
  13. import com.slibra.common.core.domain.AjaxResult;
  14. import com.slibra.common.core.page.TableDataInfo;
  15. import com.slibra.common.enums.BusinessEnum;
  16. import com.slibra.common.exception.ServiceException;
  17. import com.slibra.common.utils.DateUtils;
  18. import com.slibra.common.utils.SecurityUtils;
  19. import com.slibra.common.utils.StringUtils;
  20. import com.slibra.common.utils.uuid.IdUtils;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.util.CollectionUtils;
  24. import org.springframework.web.bind.annotation.*;
  25. import java.math.BigDecimal;
  26. import java.util.Date;
  27. import java.util.List;
  28. import java.util.Objects;
  29. import static com.slibra.common.constant.MyConstants.*;
  30. /**
  31. * 前端用户相关接口
  32. */
  33. @RestController
  34. @RequestMapping("/front")
  35. @Slf4j
  36. public class FrontController extends BaseController {
  37. @Autowired
  38. private IFrontService frontService;
  39. @Autowired
  40. private TXinyiChatRecordMapper xinyiChatRecordMapper;
  41. @Autowired
  42. private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
  43. @Autowired
  44. private TXinyiAgentAssistantMapper xinyiAgentAssistantMapper;
  45. @Autowired
  46. private TXinyiIndustryMapper xinyiIndustryMapper;
  47. /**
  48. * 获取大屏的实时数据 + 统计数据
  49. * @return
  50. */
  51. @GetMapping(value = "/realTimeData")
  52. public AjaxResult realTimeData()
  53. {
  54. log.info("进入了 获取大屏的实时数据 + 统计数据 接口");
  55. return AjaxResult.success(frontService.countInfo());
  56. }
  57. /**
  58. * 分页获取大模型的问答记录
  59. * @param tXinyiChatRecord
  60. * @return
  61. */
  62. @GetMapping("/bigModel/qa/pageList")
  63. public TableDataInfo qaPageList(TXinyiChatRecord tXinyiChatRecord)
  64. {
  65. log.info("进入了 分页获取大模型的问答记录 接口");
  66. //获取登录用户信息
  67. Long userId = SecurityUtils.getUserId();
  68. tXinyiChatRecord.setUserId(String.valueOf(userId));
  69. startPage();
  70. return getDataTable(xinyiChatRecordMapper.selectTXinyiChatRecordFirstList(tXinyiChatRecord));
  71. }
  72. /**
  73. * 不分页获取大模型的问答记录
  74. * @param tXinyiChatRecord
  75. * @return
  76. */
  77. @GetMapping("/bigModel/qa/noPageList")
  78. public AjaxResult noPageList(TXinyiChatRecord tXinyiChatRecord)
  79. {
  80. log.info("进入了 不分页获取大模型的问答记录 接口");
  81. //获取登录用户信息
  82. Long userId = SecurityUtils.getUserId();
  83. tXinyiChatRecord.setUserId(String.valueOf(userId));
  84. return AjaxResult.success(xinyiChatRecordMapper.selectTXinyiChatRecordFirstList(tXinyiChatRecord));
  85. }
  86. /**
  87. * 通过sessionId获取某个用户的问答列表
  88. * @param tXinyiChatRecord
  89. * @return
  90. */
  91. @GetMapping("/bigModel/qa/qaListBySessionId")
  92. public AjaxResult qaListBySessionId(TXinyiChatRecord tXinyiChatRecord)
  93. {
  94. log.info("进入了 通过sessionId获取某个用户的问答列表 接口");
  95. String sessionId = tXinyiChatRecord.getSessionId();
  96. if(StringUtils.isBlank(sessionId))
  97. throw new ServiceException("必须传入sessionId");
  98. //获取登录用户信息
  99. Long userId = SecurityUtils.getUserId();
  100. tXinyiChatRecord.setUserId(String.valueOf(userId));
  101. return AjaxResult.success(xinyiChatRecordMapper.selectTXinyiChatRecordList(tXinyiChatRecord));
  102. }
  103. /**
  104. *
  105. * 获取报警统计信息接口
  106. * @return
  107. */
  108. @GetMapping("/bigModel/warningCount")
  109. public AjaxResult warningCount()
  110. {
  111. log.info("进入了获取报警统计信息接口");
  112. return AjaxResult.success(frontService.warningCount());
  113. }
  114. /**
  115. * 首页报警记录(按时间倒叙 取十条)
  116. * @return
  117. */
  118. @GetMapping("/bigModel/home/warningList")
  119. public AjaxResult homeWarningList()
  120. {
  121. log.info("进入了 首页报警记录(按时间倒叙 取十条) 接口");
  122. return AjaxResult.success(frontService.homeWarningList());
  123. }
  124. /**
  125. * 获取 信义推荐问答列表
  126. * type: 0专家问答 1水质报警 2生化报警 3预测预警
  127. * @return
  128. */
  129. @GetMapping("/bigModel/home/recommendQAList/{type}")
  130. public AjaxResult recommendQAList(@PathVariable Integer type)
  131. {
  132. log.info("进入了 获取 信义推荐问答列表 接口");
  133. return AjaxResult.success(frontService.recommendQAList(type));
  134. }
  135. //报警+预警记录列表分页 【水质报警 1生化报警 2预测报警】
  136. /**
  137. * 报警+预警记录列表分页
  138. * @param tXinyiWarningRecord
  139. * @return
  140. */
  141. @GetMapping("/bigModel/warning/pageList")
  142. public TableDataInfo warningPageList(TXinyiWarningRecord tXinyiWarningRecord)
  143. {
  144. log.info("进入了 报警+预警记录列表分页 接口");
  145. startPage();
  146. List<TXinyiWarningRecord> tXinyiWarningRecords = xinyiWarningRecordMapper.selectTXinyiWarningRecordList(tXinyiWarningRecord);
  147. this.addWarningRecordExtra(tXinyiWarningRecords);
  148. return getDataTable(tXinyiWarningRecords);
  149. }
  150. //报警+预警记录列表不分页 【水质报警 1生化报警 2预测报警】
  151. /**
  152. * 报警+预警记录列表不分页
  153. * @param tXinyiWarningRecord
  154. * @return
  155. */
  156. @GetMapping("/bigModel/warning/noPageList")
  157. public AjaxResult noPageList(TXinyiWarningRecord tXinyiWarningRecord)
  158. {
  159. log.info("进入了 报警+预警记录列表不分页 接口");
  160. List<TXinyiWarningRecord> tXinyiWarningRecords = xinyiWarningRecordMapper.selectTXinyiWarningRecordList(tXinyiWarningRecord);
  161. this.addWarningRecordExtra(tXinyiWarningRecords);
  162. return AjaxResult.success(tXinyiWarningRecords);
  163. }
  164. private void addWarningRecordExtra(List<TXinyiWarningRecord> tXinyiWarningRecords) {
  165. if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){
  166. for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) {
  167. Date endDate = null;
  168. //判断类型 如果结束了 截止时间就是告警截止时间; 如果正在报警 截止时间就是当前时间
  169. if(0 == tXinyiWarningRecord.getStatus() || 3 == tXinyiWarningRecord.getStatus())
  170. endDate = DateUtils.getNowDate();
  171. else
  172. endDate = tXinyiWarningRecord.getOffTime();
  173. //防止 之前程序处理错误 理论上不再报警了,一定有截止时间的
  174. if(Objects.isNull(endDate)){
  175. log.error("xxxxxxxxx:之前处理告警结束的逻辑异常,没有更新截止时间");
  176. endDate = DateUtils.getNowDate();
  177. }
  178. tXinyiWarningRecord.setCounts(Math.min(DateUtils.differentHoursByMillisecond(tXinyiWarningRecord.getCreateTime(), endDate) + 1, MAX_COUNT));
  179. //2024年7月11日13:36:41 新增处理,返回带单位的报警值(目前只处理生化报警的)
  180. if(1 == tXinyiWarningRecord.getType())
  181. tXinyiWarningRecord.setWarningValStr(this.getWarningValStr(tXinyiWarningRecord.getWarningVal(), tXinyiWarningRecord.getCategory()));
  182. //2024年7月13日17:41:06 小数点保留两位小数
  183. this.handleDecimalPoint(tXinyiWarningRecord);
  184. }
  185. }
  186. }
  187. private void handleDecimalPoint(TXinyiWarningRecord xinyiWarningRecord) {
  188. BigDecimal warningVal = xinyiWarningRecord.getWarningVal();
  189. BigDecimal designVal = xinyiWarningRecord.getDesignVal();
  190. BigDecimal controlVal = xinyiWarningRecord.getControlVal();
  191. BigDecimal forecastVal = xinyiWarningRecord.getForecastVal();
  192. if(!Objects.isNull(warningVal))
  193. xinyiWarningRecord.setWarningVal(DecimalUtils.getAbsAndScale(warningVal, INT_2));
  194. if(!Objects.isNull(designVal))
  195. xinyiWarningRecord.setDesignVal(DecimalUtils.getAbsAndScale(designVal, INT_2));
  196. if(!Objects.isNull(controlVal))
  197. xinyiWarningRecord.setControlVal(DecimalUtils.getAbsAndScale(controlVal, INT_2));
  198. if(!Objects.isNull(forecastVal))
  199. xinyiWarningRecord.setForecastVal(DecimalUtils.getAbsAndScale(forecastVal, INT_2));
  200. }
  201. private String getWarningValStr(BigDecimal warningVal, String category) {
  202. BigDecimal absAndScale = DecimalUtils.getAbsAndScale(warningVal, MyConstants.INT_2);
  203. if(BusinessEnum.WarningCategoryEnum.NHLB.getCode().equals(category))
  204. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.PERCENT.getCode();
  205. if(BusinessEnum.WarningCategoryEnum.WHLB.getCode().equals(category))
  206. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.PERCENT.getCode();
  207. if(BusinessEnum.WarningCategoryEnum.WNND_MLSS_1.getCode().equals(category))
  208. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
  209. if(BusinessEnum.WarningCategoryEnum.WNND_MLSS_2.getCode().equals(category))
  210. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
  211. if(BusinessEnum.WarningCategoryEnum.WNFH.getCode().equals(category))
  212. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.KGBOD_KGMLSS_D.getCode();
  213. if(BusinessEnum.WarningCategoryEnum.HFXWNNDZB.getCode().equals(category))
  214. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
  215. if(BusinessEnum.WarningCategoryEnum.TDB.getCode().equals(category))
  216. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
  217. if(BusinessEnum.WarningCategoryEnum.TLB.getCode().equals(category))
  218. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
  219. if(BusinessEnum.WarningCategoryEnum.BODCODB.getCode().equals(category))
  220. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
  221. if(BusinessEnum.WarningCategoryEnum.HYQDO_ONE.getCode().equals(category))
  222. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
  223. if(BusinessEnum.WarningCategoryEnum.HYQDO_TWO.getCode().equals(category))
  224. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
  225. if(BusinessEnum.WarningCategoryEnum.QSB.getCode().equals(category))
  226. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.M3_M3.getCode();
  227. if(BusinessEnum.WarningCategoryEnum.ECC_BMFH.getCode().equals(category))
  228. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.M3_M2_H.getCode();
  229. if(BusinessEnum.WarningCategoryEnum.ECC_GTFH.getCode().equals(category))
  230. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.KG_M2_D.getCode();
  231. if(BusinessEnum.WarningCategoryEnum.FCXSL.getCode().equals(category))
  232. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.PERCENT.getCode();
  233. return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
  234. }
  235. /**
  236. * 获取 后台配置的智能助手列表
  237. * @return
  238. */
  239. @GetMapping("/bigModel/agentAssistant/list")
  240. public AjaxResult agentAssistantList()
  241. {
  242. log.info("进入了 获取 后台配置的智能助手列表 接口");
  243. return AjaxResult.success(xinyiAgentAssistantMapper.selectTXinyiAgentAssistantList(null));
  244. }
  245. /**
  246. * 获取 告警id获取决策列表的最后一条数据
  247. * 2024年6月23日17:30:07 因为只展示一条数据,所以判断是不是最后一条数据是report类型的,如果是就返回; 如果不是,获取是定时任务生成的最近的一条数据
  248. * @return
  249. */
  250. @GetMapping("/bigModel/warning/qaDetailByWarningId/{warningId}")
  251. public AjaxResult qaDetailByWarningId(@PathVariable String warningId)
  252. {
  253. log.info("进入了 获取 告警id获取决策列表的最后一条数据 接口");
  254. return AjaxResult.success(frontService.qaDetailByWarningId(warningId));
  255. }
  256. /**
  257. * 删除问答记录(单条)
  258. * @return
  259. */
  260. @DeleteMapping("/bigModel/chat/deleteOneChtById/{id}")
  261. public AjaxResult deleteOneChtById(@PathVariable Long id)
  262. {
  263. log.info("进入了 删除问答记录(单条) 接口");
  264. return AjaxResult.success(xinyiChatRecordMapper.deleteTXinyiChatRecordById(id));
  265. }
  266. /**
  267. * 生成sessionId给聊天接口使用
  268. * @return
  269. */
  270. @GetMapping("/bigModel/chat/generateSessionId")
  271. public AjaxResult generateSessionId()
  272. {
  273. log.info("进入了 生成sessionId给聊天接口使用 接口");
  274. return AjaxResult.success(SUCCESS, IdUtils.simpleUUID());
  275. }
  276. /**
  277. * 标记问题是否满意
  278. * @return
  279. */
  280. @PutMapping("/bigModel/chat/isSatisfiedAnswer")
  281. public AjaxResult isSatisfiedAnswer(@RequestBody ChatReq chatReq)
  282. {
  283. log.info("进入了 标记问题是否满意 接口");
  284. return AjaxResult.success(frontService.isSatisfiedAnswer(chatReq));
  285. }
  286. /**
  287. * 人工处理告警接口(是否采用大模型问答 是否转应急 归档/上传地址)
  288. * @return
  289. */
  290. @PutMapping("/bigModel/warning/handleWarningByMan")
  291. public AjaxResult handleWarningByMan(@RequestBody TXinyiWarningRecord warningRecord)
  292. {
  293. log.info("进入了 人工处理告警接口 接口");
  294. return AjaxResult.success(frontService.handleWarningByMan(warningRecord));
  295. }
  296. /**
  297. * 获取 首页简报的问答数据
  298. * @return
  299. */
  300. @GetMapping("/bigModel/home/getLeastShortReport")
  301. public AjaxResult getLeastShortReport()
  302. {
  303. log.info("进入了 首页简报的问答数据获取 接口");
  304. return AjaxResult.success(frontService.getLeastShortReport());
  305. }
  306. /**
  307. * 获取 告警id获取所有的仿真预测列表
  308. * @return
  309. */
  310. @GetMapping("/bigModel/warning/forecastList/{warningId}")
  311. public AjaxResult forecastList(@PathVariable String warningId)
  312. {
  313. log.info("进入了 获取 告警id获取所有的仿真预测列表 接口");
  314. return AjaxResult.success(frontService.forecastList(warningId));
  315. }
  316. /**
  317. * 获取 最新的一条日报相关的费用信息
  318. * @return
  319. */
  320. @GetMapping("/bigModel/daily/recentlyOneFeeInfo")
  321. public String recentlyOneFeeInfo()
  322. {
  323. log.info("进入了 获取 最新的一条日报相关的费用信息 接口");
  324. return JSON.toJSONString(success(frontService.recentlyOneFeeInfo()), JSONWriter.Feature.WriteNulls);
  325. }
  326. /**
  327. * 自定义工单接口 获取数据接口
  328. * @return
  329. * 2024年6月19日14:45:51 返回结构再处理下,方便前端解析
  330. */
  331. @PostMapping("/bigModel/custom/workOrder")
  332. public AjaxResult customWorkOrder(@RequestBody WorkOrderReq workOrderReq)
  333. {
  334. log.info("进入了 自定义工单接口 获取数据接口 接口");
  335. return AjaxResult.success(frontService.customWorkOrderHandle(workOrderReq));
  336. }
  337. /**
  338. *
  339. * 大模型停止生成
  340. * @param sessionId
  341. * @return
  342. */
  343. @GetMapping("/bigModel/warning/stopChat/{sessionId}")
  344. public AjaxResult stopChat(@PathVariable String sessionId)
  345. {
  346. log.info("进入了 大模型停止生成 接口");
  347. return AjaxResult.success(frontService.stopChat(sessionId));
  348. }
  349. /**
  350. *
  351. * 智能投药系统获取实时需要数据接口
  352. * @return
  353. */
  354. @GetMapping("/bigModel/smartAdd/dataInfo")
  355. public AjaxResult smartAddDataInfo()
  356. {
  357. log.info("进入了 智能投药系统获取实时需要数据 接口");
  358. return AjaxResult.success(frontService.smartAddDataInfo());
  359. }
  360. /**
  361. * type说明:
  362. * 0:进水流量
  363. * 1:#1好氧池硝酸盐
  364. * 2:#2好氧池硝酸盐
  365. * 3:#1缺氧池氨氮
  366. * 4:#2缺氧池氨氮
  367. * 5:进水COD
  368. * 6:进水总氮
  369. * 7:碳源投加量
  370. * 入股新增,则类型继续递增 已经优化,放入枚举
  371. *
  372. * @param type
  373. * @return
  374. */
  375. @GetMapping("/bigModel/smartAdd/charList/{type}")
  376. public AjaxResult smartAddCharList(@PathVariable int type)
  377. {
  378. log.info("进入了 智能投药系统获取对应指标最近3天的数据情况 接口");
  379. return AjaxResult.success(frontService.smartAddCharList(type));
  380. }
  381. //--------------------下面是测试的方法--------------------
  382. /*@GetMapping("/test/data")
  383. public void testData(){
  384. List<DecisionReq> decisionReqs = this.xinyiIndustryMapper.selectLast10RecordsForDecisionOnlyIndustry();
  385. System.out.println(JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls));
  386. }*/
  387. }