123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468 |
- package com.slibra.web.controller.business;
- import com.alibaba.fastjson2.JSON;
- import com.alibaba.fastjson2.JSONWriter;
- import com.slibra.business.domain.TXinyiChatRecord;
- import com.slibra.business.domain.TXinyiWarningRecord;
- import com.slibra.business.mapper.*;
- import com.slibra.business.req.ChatReq;
- import com.slibra.business.req.WorkOrderReq;
- import com.slibra.business.service.IFrontService;
- import com.slibra.common.DecimalUtils;
- import com.slibra.common.constant.MyConstants;
- import com.slibra.common.core.controller.BaseController;
- import com.slibra.common.core.domain.AjaxResult;
- import com.slibra.common.core.page.TableDataInfo;
- import com.slibra.common.enums.BusinessEnum;
- import com.slibra.common.exception.ServiceException;
- import com.slibra.common.utils.DateUtils;
- import com.slibra.common.utils.SecurityUtils;
- import com.slibra.common.utils.StringUtils;
- import com.slibra.common.utils.uuid.IdUtils;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.bind.annotation.*;
- import java.math.BigDecimal;
- import java.util.Date;
- import java.util.List;
- import java.util.Objects;
- import static com.slibra.common.constant.MyConstants.*;
- /**
- * 前端用户相关接口
- */
- @RestController
- @RequestMapping("/front")
- @Slf4j
- public class FrontController extends BaseController {
- @Autowired
- private IFrontService frontService;
- @Autowired
- private TXinyiChatRecordMapper xinyiChatRecordMapper;
- @Autowired
- private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
- @Autowired
- private TXinyiAgentAssistantMapper xinyiAgentAssistantMapper;
- @Autowired
- private TXinyiIndustryMapper xinyiIndustryMapper;
- /**
- * 获取大屏的实时数据 + 统计数据
- * @return
- */
- @GetMapping(value = "/realTimeData")
- public AjaxResult realTimeData()
- {
- log.info("进入了 获取大屏的实时数据 + 统计数据 接口");
- return AjaxResult.success(frontService.countInfo());
- }
- /**
- * 分页获取大模型的问答记录
- * @param tXinyiChatRecord
- * @return
- */
- @GetMapping("/bigModel/qa/pageList")
- public TableDataInfo qaPageList(TXinyiChatRecord tXinyiChatRecord)
- {
- log.info("进入了 分页获取大模型的问答记录 接口");
- //获取登录用户信息
- Long userId = SecurityUtils.getUserId();
- tXinyiChatRecord.setUserId(String.valueOf(userId));
- startPage();
- return getDataTable(xinyiChatRecordMapper.selectTXinyiChatRecordFirstList(tXinyiChatRecord));
- }
- /**
- * 不分页获取大模型的问答记录
- * @param tXinyiChatRecord
- * @return
- */
- @GetMapping("/bigModel/qa/noPageList")
- public AjaxResult noPageList(TXinyiChatRecord tXinyiChatRecord)
- {
- log.info("进入了 不分页获取大模型的问答记录 接口");
- //获取登录用户信息
- Long userId = SecurityUtils.getUserId();
- tXinyiChatRecord.setUserId(String.valueOf(userId));
- return AjaxResult.success(xinyiChatRecordMapper.selectTXinyiChatRecordFirstList(tXinyiChatRecord));
- }
- /**
- * 通过sessionId获取某个用户的问答列表
- * @param tXinyiChatRecord
- * @return
- */
- @GetMapping("/bigModel/qa/qaListBySessionId")
- public AjaxResult qaListBySessionId(TXinyiChatRecord tXinyiChatRecord)
- {
- log.info("进入了 通过sessionId获取某个用户的问答列表 接口");
- String sessionId = tXinyiChatRecord.getSessionId();
- if(StringUtils.isBlank(sessionId))
- throw new ServiceException("必须传入sessionId");
- //获取登录用户信息
- Long userId = SecurityUtils.getUserId();
- tXinyiChatRecord.setUserId(String.valueOf(userId));
- return AjaxResult.success(xinyiChatRecordMapper.selectTXinyiChatRecordList(tXinyiChatRecord));
- }
- /**
- *
- * 获取报警统计信息接口
- * @return
- */
- @GetMapping("/bigModel/warningCount")
- public AjaxResult warningCount()
- {
- log.info("进入了获取报警统计信息接口");
- return AjaxResult.success(frontService.warningCount());
- }
- /**
- * 首页报警记录(按时间倒叙 取十条)
- * @return
- */
- @GetMapping("/bigModel/home/warningList")
- public AjaxResult homeWarningList()
- {
- log.info("进入了 首页报警记录(按时间倒叙 取十条) 接口");
- return AjaxResult.success(frontService.homeWarningList());
- }
- /**
- * 获取 信义推荐问答列表
- * type: 0专家问答 1水质报警 2生化报警 3预测预警
- * @return
- */
- @GetMapping("/bigModel/home/recommendQAList/{type}")
- public AjaxResult recommendQAList(@PathVariable Integer type)
- {
- log.info("进入了 获取 信义推荐问答列表 接口");
- return AjaxResult.success(frontService.recommendQAList(type));
- }
- //报警+预警记录列表分页 【水质报警 1生化报警 2预测报警】
- /**
- * 报警+预警记录列表分页
- * @param tXinyiWarningRecord
- * @return
- */
- @GetMapping("/bigModel/warning/pageList")
- public TableDataInfo warningPageList(TXinyiWarningRecord tXinyiWarningRecord)
- {
- log.info("进入了 报警+预警记录列表分页 接口");
- startPage();
- List<TXinyiWarningRecord> tXinyiWarningRecords = xinyiWarningRecordMapper.selectTXinyiWarningRecordList(tXinyiWarningRecord);
- this.addWarningRecordExtra(tXinyiWarningRecords);
- return getDataTable(tXinyiWarningRecords);
- }
- //报警+预警记录列表不分页 【水质报警 1生化报警 2预测报警】
- /**
- * 报警+预警记录列表不分页
- * @param tXinyiWarningRecord
- * @return
- */
- @GetMapping("/bigModel/warning/noPageList")
- public AjaxResult noPageList(TXinyiWarningRecord tXinyiWarningRecord)
- {
- log.info("进入了 报警+预警记录列表不分页 接口");
- List<TXinyiWarningRecord> tXinyiWarningRecords = xinyiWarningRecordMapper.selectTXinyiWarningRecordList(tXinyiWarningRecord);
- this.addWarningRecordExtra(tXinyiWarningRecords);
- return AjaxResult.success(tXinyiWarningRecords);
- }
- private void addWarningRecordExtra(List<TXinyiWarningRecord> tXinyiWarningRecords) {
- if(!CollectionUtils.isEmpty(tXinyiWarningRecords)){
- for (TXinyiWarningRecord tXinyiWarningRecord : tXinyiWarningRecords) {
- Date endDate = null;
- //判断类型 如果结束了 截止时间就是告警截止时间; 如果正在报警 截止时间就是当前时间
- if(0 == tXinyiWarningRecord.getStatus() || 3 == tXinyiWarningRecord.getStatus())
- endDate = DateUtils.getNowDate();
- else
- endDate = tXinyiWarningRecord.getOffTime();
- //防止 之前程序处理错误 理论上不再报警了,一定有截止时间的
- if(Objects.isNull(endDate)){
- log.error("xxxxxxxxx:之前处理告警结束的逻辑异常,没有更新截止时间");
- endDate = DateUtils.getNowDate();
- }
- tXinyiWarningRecord.setCounts(Math.min(DateUtils.differentHoursByMillisecond(tXinyiWarningRecord.getCreateTime(), endDate) + 1, MAX_COUNT));
- //2024年7月11日13:36:41 新增处理,返回带单位的报警值(目前只处理生化报警的)
- if(1 == tXinyiWarningRecord.getType())
- tXinyiWarningRecord.setWarningValStr(this.getWarningValStr(tXinyiWarningRecord.getWarningVal(), tXinyiWarningRecord.getCategory()));
- //2024年7月13日17:41:06 小数点保留两位小数
- this.handleDecimalPoint(tXinyiWarningRecord);
- }
- }
- }
- private void handleDecimalPoint(TXinyiWarningRecord xinyiWarningRecord) {
- BigDecimal warningVal = xinyiWarningRecord.getWarningVal();
- BigDecimal designVal = xinyiWarningRecord.getDesignVal();
- BigDecimal controlVal = xinyiWarningRecord.getControlVal();
- BigDecimal forecastVal = xinyiWarningRecord.getForecastVal();
- if(!Objects.isNull(warningVal))
- xinyiWarningRecord.setWarningVal(DecimalUtils.getAbsAndScale(warningVal, INT_2));
- if(!Objects.isNull(designVal))
- xinyiWarningRecord.setDesignVal(DecimalUtils.getAbsAndScale(designVal, INT_2));
- if(!Objects.isNull(controlVal))
- xinyiWarningRecord.setControlVal(DecimalUtils.getAbsAndScale(controlVal, INT_2));
- if(!Objects.isNull(forecastVal))
- xinyiWarningRecord.setForecastVal(DecimalUtils.getAbsAndScale(forecastVal, INT_2));
- }
- private String getWarningValStr(BigDecimal warningVal, String category) {
- BigDecimal absAndScale = DecimalUtils.getAbsAndScale(warningVal, MyConstants.INT_2);
- if(BusinessEnum.WarningCategoryEnum.NHLB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.PERCENT.getCode();
- if(BusinessEnum.WarningCategoryEnum.WHLB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.PERCENT.getCode();
- if(BusinessEnum.WarningCategoryEnum.WNND_MLSS_1.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
- if(BusinessEnum.WarningCategoryEnum.WNND_MLSS_2.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
- if(BusinessEnum.WarningCategoryEnum.WNFH.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.KGBOD_KGMLSS_D.getCode();
- if(BusinessEnum.WarningCategoryEnum.HFXWNNDZB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
- if(BusinessEnum.WarningCategoryEnum.TDB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
- if(BusinessEnum.WarningCategoryEnum.TLB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
- if(BusinessEnum.WarningCategoryEnum.BODCODB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
- if(BusinessEnum.WarningCategoryEnum.HYQDO_ONE.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
- if(BusinessEnum.WarningCategoryEnum.HYQDO_TWO.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.MG_L.getCode();
- if(BusinessEnum.WarningCategoryEnum.QSB.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.M3_M3.getCode();
- if(BusinessEnum.WarningCategoryEnum.ECC_BMFH.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.M3_M2_H.getCode();
- if(BusinessEnum.WarningCategoryEnum.ECC_GTFH.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.KG_M2_D.getCode();
- if(BusinessEnum.WarningCategoryEnum.FCXSL.getCode().equals(category))
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.PERCENT.getCode();
- return absAndScale + SPACE_STR + BusinessEnum.BigModelUnitEnum.NULL.getCode();
- }
- /**
- * 获取 后台配置的智能助手列表
- * @return
- */
- @GetMapping("/bigModel/agentAssistant/list")
- public AjaxResult agentAssistantList()
- {
- log.info("进入了 获取 后台配置的智能助手列表 接口");
- return AjaxResult.success(xinyiAgentAssistantMapper.selectTXinyiAgentAssistantList(null));
- }
- /**
- * 获取 告警id获取决策列表的最后一条数据
- * 2024年6月23日17:30:07 因为只展示一条数据,所以判断是不是最后一条数据是report类型的,如果是就返回; 如果不是,获取是定时任务生成的最近的一条数据
- * @return
- */
- @GetMapping("/bigModel/warning/qaDetailByWarningId/{warningId}")
- public AjaxResult qaDetailByWarningId(@PathVariable String warningId)
- {
- log.info("进入了 获取 告警id获取决策列表的最后一条数据 接口");
- return AjaxResult.success(frontService.qaDetailByWarningId(warningId));
- }
- /**
- * 删除问答记录(单条)
- * @return
- */
- @DeleteMapping("/bigModel/chat/deleteOneChtById/{id}")
- public AjaxResult deleteOneChtById(@PathVariable Long id)
- {
- log.info("进入了 删除问答记录(单条) 接口");
- return AjaxResult.success(xinyiChatRecordMapper.deleteTXinyiChatRecordById(id));
- }
- /**
- * 生成sessionId给聊天接口使用
- * @return
- */
- @GetMapping("/bigModel/chat/generateSessionId")
- public AjaxResult generateSessionId()
- {
- log.info("进入了 生成sessionId给聊天接口使用 接口");
- return AjaxResult.success(SUCCESS, IdUtils.simpleUUID());
- }
- /**
- * 标记问题是否满意
- * @return
- */
- @PutMapping("/bigModel/chat/isSatisfiedAnswer")
- public AjaxResult isSatisfiedAnswer(@RequestBody ChatReq chatReq)
- {
- log.info("进入了 标记问题是否满意 接口");
- return AjaxResult.success(frontService.isSatisfiedAnswer(chatReq));
- }
- /**
- * 人工处理告警接口(是否采用大模型问答 是否转应急 归档/上传地址)
- * @return
- */
- @PutMapping("/bigModel/warning/handleWarningByMan")
- public AjaxResult handleWarningByMan(@RequestBody TXinyiWarningRecord warningRecord)
- {
- log.info("进入了 人工处理告警接口 接口");
- return AjaxResult.success(frontService.handleWarningByMan(warningRecord));
- }
- /**
- * 获取 首页简报的问答数据
- * @return
- */
- @GetMapping("/bigModel/home/getLeastShortReport")
- public AjaxResult getLeastShortReport()
- {
- log.info("进入了 首页简报的问答数据获取 接口");
- return AjaxResult.success(frontService.getLeastShortReport());
- }
- /**
- * 获取 告警id获取所有的仿真预测列表
- * @return
- */
- @GetMapping("/bigModel/warning/forecastList/{warningId}")
- public AjaxResult forecastList(@PathVariable String warningId)
- {
- log.info("进入了 获取 告警id获取所有的仿真预测列表 接口");
- return AjaxResult.success(frontService.forecastList(warningId));
- }
- /**
- * 获取 最新的一条日报相关的费用信息
- * @return
- */
- @GetMapping("/bigModel/daily/recentlyOneFeeInfo")
- public String recentlyOneFeeInfo()
- {
- log.info("进入了 获取 最新的一条日报相关的费用信息 接口");
- return JSON.toJSONString(success(frontService.recentlyOneFeeInfo()), JSONWriter.Feature.WriteNulls);
- }
- /**
- * 自定义工单接口 获取数据接口
- * @return
- * 2024年6月19日14:45:51 返回结构再处理下,方便前端解析
- */
- @PostMapping("/bigModel/custom/workOrder")
- public AjaxResult customWorkOrder(@RequestBody WorkOrderReq workOrderReq)
- {
- log.info("进入了 自定义工单接口 获取数据接口 接口");
- return AjaxResult.success(frontService.customWorkOrderHandle(workOrderReq));
- }
- /**
- *
- * 大模型停止生成
- * @param sessionId
- * @return
- */
- @GetMapping("/bigModel/warning/stopChat/{sessionId}")
- public AjaxResult stopChat(@PathVariable String sessionId)
- {
- log.info("进入了 大模型停止生成 接口");
- return AjaxResult.success(frontService.stopChat(sessionId));
- }
- /**
- *
- * 智能投药系统获取实时需要数据接口
- * @return
- */
- @GetMapping("/bigModel/smartAdd/dataInfo")
- public AjaxResult smartAddDataInfo()
- {
- log.info("进入了 智能投药系统获取实时需要数据 接口");
- return AjaxResult.success(frontService.smartAddDataInfo());
- }
- /**
- * type说明:
- * 0:进水流量
- * 1:#1好氧池硝酸盐
- * 2:#2好氧池硝酸盐
- * 3:#1缺氧池氨氮
- * 4:#2缺氧池氨氮
- * 5:进水COD
- * 6:进水总氮
- * 7:碳源投加量
- * 入股新增,则类型继续递增 已经优化,放入枚举
- *
- * @param type
- * @return
- */
- @GetMapping("/bigModel/smartAdd/charList/{type}")
- public AjaxResult smartAddCharList(@PathVariable int type)
- {
- log.info("进入了 智能投药系统获取对应指标最近3天的数据情况 接口");
- return AjaxResult.success(frontService.smartAddCharList(type));
- }
- //--------------------下面是测试的方法--------------------
- /*@GetMapping("/test/data")
- public void testData(){
- List<DecisionReq> decisionReqs = this.xinyiIndustryMapper.selectLast10RecordsForDecisionOnlyIndustry();
- System.out.println(JSON.toJSONString(decisionReqs, JSONWriter.Feature.WriteNulls));
- }*/
- }
|