123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720 |
- package com.slibra.business.service.impl;
- import com.alibaba.fastjson2.JSON;
- import com.alibaba.fastjson2.JSONObject;
- import com.slibra.business.domain.*;
- import com.slibra.business.mapper.*;
- import com.slibra.business.req.ChatReq;
- import com.slibra.business.req.WorkOrderReq;
- import com.slibra.business.res.WorkOrderRes;
- import com.slibra.business.res.XinyiDailyFeeSimple;
- import com.slibra.business.res.XinyiIndustrySimple;
- import com.slibra.business.service.IFrontService;
- import com.slibra.common.DecimalUtils;
- import com.slibra.common.core.domain.TXinyiDaily;
- import com.slibra.common.core.redis.RedisCache;
- 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 lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.connection.stream.RecordId;
- import org.springframework.stereotype.Service;
- import org.springframework.util.CollectionUtils;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.time.LocalDate;
- import java.time.LocalDateTime;
- import java.time.format.DateTimeFormatter;
- import java.util.*;
- import static com.slibra.common.constant.MyConstants.*;
- import static com.slibra.common.enums.BusinessEnum.BigModelBizEnum.DECISION_REPORT;
- import static com.slibra.common.utils.DateUtils.getAllDatesBetween;
- @Service
- @Slf4j
- public class FrontServiceImpl implements IFrontService {
- @Autowired
- private TXinyiIndustryMapper xinyiIndustryMapper;
- @Autowired
- private TXinyiDailyMapper xinyiDailyMapper;
- @Autowired
- private TXinyiRobotMapper xinyiRobotMapper;
- @Autowired
- private TXinyiNormConfigMapper tXinyiNormConfigMapper;
- @Autowired
- private TXinyiWarningRecordMapper xinyiWarningRecordMapper;
- @Autowired
- private TXinyiRecommendQaMapper xinyiRecommendQaMapper;
- @Autowired
- private TXinyiChatRecordMapper xinyiChatRecordMapper;
- @Autowired
- private RedisCache redisCache;
- @Override
- public XinyiIndustrySimple countInfo() {
- //查询基本的工业库数据
- XinyiIndustrySimple xinyiIndustrySimple = new XinyiIndustrySimple();
- LocalDateTime nowTime = LocalDateTime.now();
- //调用接口查询指标
- String[] queryTags = {"信义污水厂JS_COD_Value", "信义污水厂升级出水COD", "信义污水厂JS_AD_Value", "信义污水厂升级出水氨氮", "信义污水厂JS_ZA_Value", "信义污水厂升级出水TN", "信义污水厂JS_ZL_Value", "信义污水厂升级出水TP", "信义污水厂JS_SS_Value", "信义污水厂升级出水SS", "信义污水厂JS_PH_Value", "信义污水厂升级出水PH", "信义污水厂FT101_Value", "信义污水厂出水瞬时流量"};
- xinyiIndustrySimple = this.getRealTimeData(queryTags, nowTime);
- //处理日报数据
- this.addDailyData(xinyiIndustrySimple, nowTime);
- //处理配置信息
- this.addConfigData(xinyiIndustrySimple);
- //计算
- this.calculateData(xinyiIndustrySimple, nowTime);
- //当前的小事数
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYYMMDDHH_CHINESE);
- xinyiIndustrySimple.setTestHour(formatter.format(nowTime) + ":00");//只要小时 但是要后面的:00
- return xinyiIndustrySimple;
- }
- @Override
- public List<String> warningCount() {
- ArrayList<String> result = new ArrayList<>();
- //获取告警的统计数量
- int count = this.xinyiWarningRecordMapper.getWarningCountByType(1);
- if(count > 0)//2024年5月26日19:01:39 有告警记录再返回
- result.add(WARNING_TEMPLATE.replace("#", String.valueOf(count)));
- //获取报警警的统计数量
- count = this.xinyiWarningRecordMapper.getWarningCountByType(2);
- if(count > 0)//2024年5月26日19:01:39 有告警记录再返回
- result.add(FORECAST_WARNING_TEMPLATE.replace("#", String.valueOf(count)));
- return result;
- }
- @Override
- public List<TXinyiWarningRecord> homeWarningList() {
- return this.xinyiWarningRecordMapper.homeWarningList();
- }
- @Override
- public List<TXinyiRecommendQa> recommendQAList(Integer type) {
- return this.xinyiRecommendQaMapper.selectTXinyiRecommendQaList(TXinyiRecommendQa.builder().type(type).build());
- }
- /**
- * 2024年6月23日17:30:07 因为只展示一条数据,所以判断是不是最后一条数据是report类型的,如果是就返回; 如果不是,获取是定时任务生成的最近的一条数据
- * 2024年6月23日20:13:34 因为决策和预测走的同一个接口,所以把type去掉,否则type为1获取不到预测数据
- * @param warningId
- * @return
- */
- @Override
- public TXinyiChatRecord qaDetailByWarningId(String warningId) {
- //2024年5月28日19:10:21 只获取决策的 因为决策和仿真预测是一个接口,所以通过类型区分
- List<TXinyiChatRecord> tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).type(1).build());
- if(CollectionUtils.isEmpty(tXinyiChatRecords))
- return null;
- TXinyiChatRecord tXinyiChatRecord = tXinyiChatRecords.get(0);
- //todo 表增肌一个字段,记录类型,否则查询速度会慢
- if(tXinyiChatRecord.getAnswer().contains(DECISION_REPORT.getCode()))
- return tXinyiChatRecord;
- else{
- tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).type(1).userId(WARNING_DEFAULT_CREATE).build());
- return CollectionUtils.isEmpty(tXinyiChatRecords) ? null : tXinyiChatRecords.get(0);
- }
- }
- @Override
- public String isSatisfiedAnswer(ChatReq chatReq) {
- Long id = chatReq.getId();
- Integer isSatisfied = chatReq.getIsSatisfied();
- if(Objects.isNull(id) || Objects.isNull(isSatisfied))
- throw new ServiceException("请输入正确的参数");
- TXinyiChatRecord tXinyiChatRecord = this.xinyiChatRecordMapper.selectTXinyiChatRecordById(id);
- if(!Objects.isNull(tXinyiChatRecord)){
- tXinyiChatRecord.setIsSatisfied(isSatisfied);
- tXinyiChatRecord.setUpdateBy(SecurityUtils.getUsername());
- tXinyiChatRecord.setUpdateTime(DateUtils.getNowDate());
- this.xinyiChatRecordMapper.updateTXinyiChatRecord(tXinyiChatRecord);
- }
- return "操作成功";
- }
- @Override
- public String handleWarningByMan(TXinyiWarningRecord warningRecordReq) {
- Long id = warningRecordReq.getId();
- if(Objects.isNull(id))
- throw new ServiceException("请输入告警记录id");
- TXinyiWarningRecord tXinyiWarningRecord = this.xinyiWarningRecordMapper.selectTXinyiWarningRecordById(id);
- if(Objects.isNull(tXinyiWarningRecord))
- throw new ServiceException("请输入正确的告警记录id");
- warningRecordReq.setUpdateBy(SecurityUtils.getUsername());
- warningRecordReq.setUpdateTime(DateUtils.getNowDate());
- xinyiWarningRecordMapper.updateTXinyiWarningRecord(warningRecordReq);
- return "操作成功";
- }
- @Override
- public TXinyiChatRecord getLeastShortReport() {
- List<TXinyiChatRecord> tXinyiChatRecords = this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().module(4).build());
- return CollectionUtils.isEmpty(tXinyiChatRecords) ? null : tXinyiChatRecords.get(0);
- }
- @Override
- public List<TXinyiChatRecord> forecastList(String warningId) {
- return this.xinyiChatRecordMapper.selectTXinyiChatRecordList(TXinyiChatRecord.builder().warningId(warningId).type(3).build());
- }
- @Override
- public XinyiDailyFeeSimple recentlyOneFeeInfo() {
- //获取最新的一条日报
- TXinyiDaily tXinyiDaily = this.xinyiDailyMapper.selectNewestData();
- XinyiDailyFeeSimple xinyiDailyFeeSimple = new XinyiDailyFeeSimple();
- if(!Objects.isNull(tXinyiDaily))
- BeanUtils.copyProperties(tXinyiDaily, xinyiDailyFeeSimple);
- return xinyiDailyFeeSimple;
- }
- /**
- * 自定义工单接口 获取数据接口
- * @param workOrderReq
- * @return
- *
- * 2024年6月23日17:12:12 小数处理,所有的小数均保留两位小数处理
- */
- @Override
- public List<WorkOrderRes> customWorkOrder(WorkOrderReq workOrderReq) {
- checkCustomWorkOrder(workOrderReq);
- //两个日期之间所有的时间-天
- List<String> allDatesBetween = getAllDatesBetween(LocalDate.parse(workOrderReq.getTimeBegin()), LocalDate.parse(workOrderReq.getTimeEnd()));
- //返回结果
- List<WorkOrderRes> result = new ArrayList<>(allDatesBetween.size());
- for (String date : allDatesBetween) {
- //查询机器人数据
- WorkOrderRes workOrderRes = new WorkOrderRes();
- workOrderRes.setTime(date);
- TXinyiRobot xinyiRobot = this.xinyiRobotMapper.selectRebotAvgByDate(date);
- if(!Objects.isNull(xinyiRobot))
- this.buildRobotData(xinyiRobot, workOrderRes, workOrderReq);
- //判断数据来源(进出水情况)
- if(workOrderReq.getWhichWay() == 0){// 0:日报 1:工业库(在线仪表)
- List<TXinyiDaily> tXinyiDailies = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(date).build());
- if(!CollectionUtils.isEmpty(tXinyiDailies)){
- TXinyiDaily tXinyiDaily = tXinyiDailies.get(0);
- this.buildDailyData(tXinyiDaily, workOrderRes, workOrderReq);
- }
- }else {
- TXinyiIndustry industry = this.xinyiIndustryMapper.selectIndustryAvgByDate(date);
- if(!Objects.isNull(industry))
- this.buildIndustryData(industry, workOrderRes, workOrderReq);
- }
- result.add(workOrderRes);
- }
- return result;
- }
- @Override
- public JSONObject customWorkOrderHandle(WorkOrderReq workOrderReq) {
- List<WorkOrderRes> workOrderRes = this.customWorkOrder(workOrderReq);
- JSONObject jsonObject = new JSONObject();
- List<JSONObject> jsGroup = new ArrayList<>();
- List<JSONObject> csGroup = new ArrayList<>();
- List<JSONObject> hyGroup = new ArrayList<>();
- //处理成前端响应的结构
- if(!CollectionUtils.isEmpty(workOrderRes)){
- for (WorkOrderRes workOrderRe : workOrderRes) {
- //处理进水
- if(workOrderReq.getJsSlq() || workOrderReq.getJsCod() || workOrderReq.getJsTn()
- || workOrderReq.getJsTp() || workOrderReq.getJsNh3() || workOrderReq.getJsSs()){
- JSONObject jsonObjectJS = new JSONObject();
- jsonObjectJS.put("time", workOrderRe.getTime());
- if(workOrderReq.getJsSlq())
- jsonObjectJS.put("jsSlq", workOrderRe.getJsSlq());
- if(workOrderReq.getJsCod())
- jsonObjectJS.put("jsCod", workOrderRe.getJsCod());
- if(workOrderReq.getJsTn())
- jsonObjectJS.put("jsTn", workOrderRe.getJsTn());
- if(workOrderReq.getJsTp())
- jsonObjectJS.put("jsTp", workOrderRe.getJsTp());
- if(workOrderReq.getJsNh3())
- jsonObjectJS.put("jsNh3", workOrderRe.getJsNh3());
- if(workOrderReq.getJsSs())
- jsonObjectJS.put("jsSs", workOrderRe.getJsSs());
- jsGroup.add(jsonObjectJS);
- }
- //处理出水
- if(workOrderReq.getCsSlqc() || workOrderReq.getCsCod() || workOrderReq.getCsTn()
- || workOrderReq.getCsTp() || workOrderReq.getCsNh3() || workOrderReq.getCsSs()){
- JSONObject jsonObjectCS = new JSONObject();
- jsonObjectCS.put("time", workOrderRe.getTime());
- if(workOrderReq.getCsSlqc())
- jsonObjectCS.put("csSlqc", workOrderRe.getCsSlqc());
- if(workOrderReq.getCsCod())
- jsonObjectCS.put("csCod", workOrderRe.getCsCod());
- if(workOrderReq.getCsTn())
- jsonObjectCS.put("csTn", workOrderRe.getCsTn());
- if(workOrderReq.getCsTp())
- jsonObjectCS.put("csTp", workOrderRe.getCsTp());
- if(workOrderReq.getCsNh3())
- jsonObjectCS.put("csNh3", workOrderRe.getCsNh3());
- if(workOrderReq.getCsSs())
- jsonObjectCS.put("csSs", workOrderRe.getCsSs());
- csGroup.add(jsonObjectCS);
- }
- //处理化验
- if(workOrderReq.getNo3Hlj1Jqr() || workOrderReq.getNo3Hlj2Jqr() || workOrderReq.getNh31Jqr()
- || workOrderReq.getNh32Jqr() || workOrderReq.getNo3Qyc1Jqr() || workOrderReq.getNo3Qyc2Jqr() || workOrderReq.getTpRccJqr()){
- JSONObject jsonObjectHY = new JSONObject();
- jsonObjectHY.put("time", workOrderRe.getTime());
- if(workOrderReq.getNo3Hlj1Jqr())
- jsonObjectHY.put("no3Hlj1Jqr", workOrderRe.getNo3Hlj1Jqr());
- if(workOrderReq.getNo3Hlj2Jqr())
- jsonObjectHY.put("no3Hlj2Jqr", workOrderRe.getNo3Hlj2Jqr());
- if(workOrderReq.getNh31Jqr())
- jsonObjectHY.put("nh31Jqr", workOrderRe.getNh31Jqr());
- if(workOrderReq.getNh32Jqr())
- jsonObjectHY.put("nh32Jqr", workOrderRe.getNh32Jqr());
- if(workOrderReq.getNo3Qyc1Jqr())
- jsonObjectHY.put("no3Qyc1Jqr", workOrderRe.getNo3Qyc1Jqr());
- if(workOrderReq.getNo3Qyc2Jqr())
- jsonObjectHY.put("no3Qyc2Jqr", workOrderRe.getNo3Qyc2Jqr());
- if(workOrderReq.getTpRccJqr())
- jsonObjectHY.put("tpRccJqr", workOrderRe.getTpRccJqr());
- hyGroup.add(jsonObjectHY);
- }
- }
- }
- jsonObject.put("jsGroup", jsGroup);
- jsonObject.put("csGroup", csGroup);
- jsonObject.put("hyGroup", hyGroup);
- return jsonObject;
- }
- @Override
- public JSONObject customWorkOrderHandleByData(WorkOrderReq workOrderReq, List<WorkOrderRes> workOrderRes) {
- JSONObject jsonObject = new JSONObject();
- List<JSONObject> jsGroup = new ArrayList<>();
- List<JSONObject> csGroup = new ArrayList<>();
- List<JSONObject> hyGroup = new ArrayList<>();
- //处理成前端响应的结构
- if(!CollectionUtils.isEmpty(workOrderRes)){
- for (WorkOrderRes workOrderRe : workOrderRes) {
- //处理进水
- if(workOrderReq.getJsSlq() || workOrderReq.getJsCod() || workOrderReq.getJsTn()
- || workOrderReq.getJsTp() || workOrderReq.getJsNh3() || workOrderReq.getJsSs()){
- JSONObject jsonObjectJS = new JSONObject();
- jsonObjectJS.put("time", workOrderRe.getTime());
- if(workOrderReq.getJsSlq())
- jsonObjectJS.put("jsSlq", workOrderRe.getJsSlq());
- if(workOrderReq.getJsCod())
- jsonObjectJS.put("jsCod", workOrderRe.getJsCod());
- if(workOrderReq.getJsTn())
- jsonObjectJS.put("jsTn", workOrderRe.getJsTn());
- if(workOrderReq.getJsTp())
- jsonObjectJS.put("jsTp", workOrderRe.getJsTp());
- if(workOrderReq.getJsNh3())
- jsonObjectJS.put("jsNh3", workOrderRe.getJsNh3());
- if(workOrderReq.getJsSs())
- jsonObjectJS.put("jsSs", workOrderRe.getJsSs());
- jsGroup.add(jsonObjectJS);
- }
- //处理出水
- if(workOrderReq.getCsSlqc() || workOrderReq.getCsCod() || workOrderReq.getCsTn()
- || workOrderReq.getCsTp() || workOrderReq.getCsNh3() || workOrderReq.getCsSs()){
- JSONObject jsonObjectCS = new JSONObject();
- jsonObjectCS.put("time", workOrderRe.getTime());
- if(workOrderReq.getCsSlqc())
- jsonObjectCS.put("csSlqc", workOrderRe.getCsSlqc());
- if(workOrderReq.getCsCod())
- jsonObjectCS.put("csCod", workOrderRe.getCsCod());
- if(workOrderReq.getCsTn())
- jsonObjectCS.put("csTn", workOrderRe.getCsTn());
- if(workOrderReq.getCsTp())
- jsonObjectCS.put("csTp", workOrderRe.getCsTp());
- if(workOrderReq.getCsNh3())
- jsonObjectCS.put("csNh3", workOrderRe.getCsNh3());
- if(workOrderReq.getCsSs())
- jsonObjectCS.put("csSs", workOrderRe.getCsSs());
- csGroup.add(jsonObjectCS);
- }
- //处理化验
- if(workOrderReq.getNo3Hlj1Jqr() || workOrderReq.getNo3Hlj2Jqr() || workOrderReq.getNh31Jqr()
- || workOrderReq.getNh32Jqr() || workOrderReq.getNo3Qyc1Jqr() || workOrderReq.getNo3Qyc2Jqr() || workOrderReq.getTpRccJqr()){
- JSONObject jsonObjectHY = new JSONObject();
- jsonObjectHY.put("time", workOrderRe.getTime());
- if(workOrderReq.getNo3Hlj1Jqr())
- jsonObjectHY.put("no3Hlj1Jqr", workOrderRe.getNo3Hlj1Jqr());
- if(workOrderReq.getNo3Hlj2Jqr())
- jsonObjectHY.put("no3Hlj2Jqr", workOrderRe.getNo3Hlj2Jqr());
- if(workOrderReq.getNh31Jqr())
- jsonObjectHY.put("nh31Jqr", workOrderRe.getNh31Jqr());
- if(workOrderReq.getNh32Jqr())
- jsonObjectHY.put("nh32Jqr", workOrderRe.getNh32Jqr());
- if(workOrderReq.getNo3Qyc1Jqr())
- jsonObjectHY.put("no3Qyc1Jqr", workOrderRe.getNo3Qyc1Jqr());
- if(workOrderReq.getNo3Qyc2Jqr())
- jsonObjectHY.put("no3Qyc2Jqr", workOrderRe.getNo3Qyc2Jqr());
- if(workOrderReq.getTpRccJqr())
- jsonObjectHY.put("tpRccJqr", workOrderRe.getTpRccJqr());
- hyGroup.add(jsonObjectHY);
- }
- }
- }
- jsonObject.put("jsGroup", jsGroup);
- jsonObject.put("csGroup", csGroup);
- jsonObject.put("hyGroup", hyGroup);
- //2024年6月25日13:45:48 新增逻辑 区分是在线仪表的还是日报的,方便前端展示单位
- jsonObject.put("whichWay", workOrderReq.getWhichWay());
- return jsonObject;
- }
- @Override
- public String stopChat(String sessionId) {
- HashMap<String, Object> map = new HashMap<>();
- map.put(SESSION_ID, sessionId);
- RecordId stopGenStream = redisCache.streamXadd(STOP_GEN_STREAM, map);
- log.info("返回结果是{}", JSON.toJSONString(stopGenStream));
- return "操作成功";
- }
- private void buildIndustryData(TXinyiIndustry industry, WorkOrderRes workOrderRes, WorkOrderReq workOrderReq) {
- if(workOrderReq.getJsSlq())
- workOrderRes.setJsSlq(DecimalUtils.getAbsAndScale(industry.getJsSlq(), 2));
- if(workOrderReq.getJsCod())
- workOrderRes.setJsCod(DecimalUtils.getAbsAndScale(industry.getJsCod(), 2));
- if(workOrderReq.getJsTn())
- workOrderRes.setJsTn(DecimalUtils.getAbsAndScale(industry.getJsTn(), 2));
- if(workOrderReq.getJsTp())
- workOrderRes.setJsTp(DecimalUtils.getAbsAndScale(industry.getJsTp(), 2));
- if(workOrderReq.getJsNh3())
- workOrderRes.setJsNh3(DecimalUtils.getAbsAndScale(industry.getJsNh3(), 2));
- if(workOrderReq.getJsSs())
- workOrderRes.setJsSs(DecimalUtils.getAbsAndScale(industry.getJsSs(), 2));
- if(workOrderReq.getCsSlqc())
- workOrderRes.setCsSlqc(DecimalUtils.getAbsAndScale(industry.getCsSlqc(), 2));
- if(workOrderReq.getCsCod())
- workOrderRes.setCsCod(DecimalUtils.getAbsAndScale(industry.getCsCod(), 2));
- if(workOrderReq.getCsTn())
- workOrderRes.setCsTn(DecimalUtils.getAbsAndScale(industry.getCsTn(), 2));
- if(workOrderReq.getCsTp())
- workOrderRes.setCsTp(DecimalUtils.getAbsAndScale(industry.getCsTp(), 2));
- if(workOrderReq.getCsNh3())
- workOrderRes.setCsNh3(DecimalUtils.getAbsAndScale(industry.getCsNh3(), 2));
- if(workOrderReq.getCsSs())
- workOrderRes.setCsSs(DecimalUtils.getAbsAndScale(industry.getCsSs(), 2));
- }
- private void buildDailyData(TXinyiDaily tXinyiDaily, WorkOrderRes workOrderRes, WorkOrderReq workOrderReq) {
- if(workOrderReq.getJsSlq())
- workOrderRes.setJsSlq(DecimalUtils.getAbsAndScale(tXinyiDaily.getJSL(), 2));
- if(workOrderReq.getJsCod())
- workOrderRes.setJsCod(DecimalUtils.getAbsAndScale(tXinyiDaily.getJsCod(), 2));
- if(workOrderReq.getJsTn())
- workOrderRes.setJsTn(DecimalUtils.getAbsAndScale(tXinyiDaily.getJsTn(), 2));
- if(workOrderReq.getJsTp())
- workOrderRes.setJsTp(DecimalUtils.getAbsAndScale(tXinyiDaily.getJsTp(), 2));
- if(workOrderReq.getJsNh3())
- workOrderRes.setJsNh3(DecimalUtils.getAbsAndScale(tXinyiDaily.getJsNh3(), 2));
- if(workOrderReq.getJsSs())
- workOrderRes.setJsSs(DecimalUtils.getAbsAndScale(tXinyiDaily.getJsSs(), 2));
- if(workOrderReq.getCsSlqc())
- workOrderRes.setCsSlqc(DecimalUtils.getAbsAndScale(tXinyiDaily.getCSL(), 2));
- if(workOrderReq.getCsCod())
- workOrderRes.setCsCod(DecimalUtils.getAbsAndScale(tXinyiDaily.getCsCod(), 2));
- if(workOrderReq.getCsTn())
- workOrderRes.setCsTn(DecimalUtils.getAbsAndScale(tXinyiDaily.getCsTn(), 2));
- if(workOrderReq.getCsTp())
- workOrderRes.setCsTp(DecimalUtils.getAbsAndScale(tXinyiDaily.getCsTp(), 2));
- if(workOrderReq.getCsNh3())
- workOrderRes.setCsNh3(DecimalUtils.getAbsAndScale(tXinyiDaily.getCsNh3(), 2));
- if(workOrderReq.getCsSs())
- workOrderRes.setCsSs(DecimalUtils.getAbsAndScale(tXinyiDaily.getCsSs(), 2));
- }
- private void buildRobotData(TXinyiRobot xinyiRobot, WorkOrderRes workOrderRes, WorkOrderReq workOrderReq) {
- if(workOrderReq.getNo3Hlj1Jqr())
- workOrderRes.setNo3Hlj1Jqr(DecimalUtils.getAbsAndScale(xinyiRobot.getNo3Hlj1Jqr(), 2));
- if(workOrderReq.getNo3Hlj2Jqr())
- workOrderRes.setNo3Hlj2Jqr(DecimalUtils.getAbsAndScale(xinyiRobot.getNo3Hlj2Jqr(), 2));
- if(workOrderReq.getNh31Jqr())
- workOrderRes.setNh31Jqr(DecimalUtils.getAbsAndScale(xinyiRobot.getNh31Jqr(), 2));
- if(workOrderReq.getNh32Jqr())
- workOrderRes.setNh32Jqr(DecimalUtils.getAbsAndScale(xinyiRobot.getNh32Jqr(), 2));
- if(workOrderReq.getNo3Qyc1Jqr())
- workOrderRes.setNo3Qyc1Jqr(DecimalUtils.getAbsAndScale(xinyiRobot.getNo3Qyc1Jqr(), 2));
- if(workOrderReq.getNo3Qyc2Jqr())
- workOrderRes.setNo3Qyc2Jqr(DecimalUtils.getAbsAndScale(xinyiRobot.getNo3Qyc2Jqr(), 2));
- if(workOrderReq.getTpRccJqr())
- workOrderRes.setTpRccJqr(DecimalUtils.getAbsAndScale(xinyiRobot.getTpRccJqr(), 2));
- }
- private void checkCustomWorkOrder(WorkOrderReq workOrderReq) {
- if(StringUtils.isBlank(workOrderReq.getTimeBegin()) || StringUtils.isBlank(workOrderReq.getTimeEnd()))
- throw new ServiceException("输入的参数不合法");
- }
- /***
- * 将工业库数据计算出结果
- * @param xinyiIndustrySimple
- * @param nowTime
- * @return
- */
- private XinyiIndustrySimple calculateData(XinyiIndustrySimple xinyiIndustrySimple, LocalDateTime nowTime) {
- LocalDateTime yesterdaySameTime = nowTime.plusDays(-1);
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYYMMDDHH_TS);
- String testTime = formatter.format(yesterdaySameTime);
- //处理昨日同时期的进水 获取环比
- List<TXinyiIndustry> tXinyiIndustries = this.xinyiIndustryMapper.selectTXinyiIndustryList(TXinyiIndustry.builder().testTime(testTime).build());
- if(!CollectionUtils.isEmpty(tXinyiIndustries)){
- TXinyiIndustry industry = tXinyiIndustries.get(0);
- BigDecimal jsSlqYesterday = industry.getJsSlq();
- BigDecimal csSlqcYesterday = industry.getCsSlqc();
- BigDecimal jsSlqToday = xinyiIndustrySimple.getJsSlq();
- BigDecimal csSlqcToday = xinyiIndustrySimple.getCsSlqc();
- if(!Objects.isNull(jsSlqYesterday) && !Objects.isNull(jsSlqToday))
- xinyiIndustrySimple.setSsJsHb((jsSlqToday.subtract(jsSlqYesterday)).divide(jsSlqYesterday, 4, RoundingMode.HALF_UP));
- if(!Objects.isNull(csSlqcYesterday) && !Objects.isNull(csSlqcToday))
- xinyiIndustrySimple.setSsJsHb((csSlqcToday.subtract(csSlqcYesterday)).divide(csSlqcYesterday, 4, RoundingMode.HALF_UP));
- }
- //通过sql查询上周的平均值和环比情况
- DateTimeFormatter formatterDate = DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS);
- //获取上周的统计进出水品均值
- String begin = formatterDate.format(nowTime.plusDays(-7));
- String end = formatterDate.format(nowTime.plusDays(-1));
- HashMap<String, BigDecimal> lastWeek = this.xinyiDailyMapper.selectAvgWater(begin, end);
- if(!Objects.isNull(lastWeek)){
- BigDecimal lastJSL = lastWeek.get("JSL");
- BigDecimal lastCSL = lastWeek.get("CSL");
- //获取上上周的统计进出水品均值
- begin = formatterDate.format(nowTime.plusDays(-14));
- end = formatterDate.format(nowTime.plusDays(-8));
- HashMap<String, BigDecimal> beforeLastWeek = this.xinyiDailyMapper.selectAvgWater(begin, end);
- if(!Objects.isNull(beforeLastWeek)){
- BigDecimal beforeLastJSL = beforeLastWeek.get("JSL");
- BigDecimal beforeLastCSL = beforeLastWeek.get("CSL");
- if(!Objects.isNull(lastJSL)){
- xinyiIndustrySimple.setSzZJSAvg(lastJSL);
- if(!Objects.isNull(beforeLastJSL))
- xinyiIndustrySimple.setSzZJSHb((lastJSL.subtract(beforeLastJSL)).divide(beforeLastJSL, 4, RoundingMode.HALF_UP));
- }
- if(!Objects.isNull(lastCSL)){
- xinyiIndustrySimple.setSzZCSAvg(lastCSL);
- if(!Objects.isNull(beforeLastCSL))
- xinyiIndustrySimple.setSzZCSHb((lastCSL.subtract(beforeLastCSL)).divide(beforeLastCSL, 4, RoundingMode.HALF_UP));
- }
- }
- }
- return xinyiIndustrySimple;
- }
- private XinyiIndustrySimple addConfigData(XinyiIndustrySimple xinyiIndustrySimple) {
- //获取配置表
- List<TXinyiNormConfig> tXinyiNormConfigs = this.tXinyiNormConfigMapper.selectTXinyiNormConfigList(null);
- if(!CollectionUtils.isEmpty(tXinyiNormConfigs)){
- TXinyiNormConfig normConfig = tXinyiNormConfigs.get(0);
- BeanUtils.copyProperties(normConfig, xinyiIndustrySimple);
- }
- return xinyiIndustrySimple;
- }
- private XinyiIndustrySimple addDailyData(XinyiIndustrySimple xinyiIndustrySimple, LocalDateTime nowDate) {
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYYMMDD_TS);
- String nowDateStr = nowDate.format(formatter);
- String yesterdayStr = nowDate.plusDays(-1).format(formatter);//昨天
- String beforeYesterdayStr = nowDate.plusDays(-2).format(formatter);//前天
- List<TXinyiDaily> tXinyiDailies = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(nowDateStr).build());
- if(!CollectionUtils.isEmpty(tXinyiDailies)){
- TXinyiDaily tXinyiDaily = tXinyiDailies.get(0);
- BeanUtils.copyProperties(tXinyiDaily, xinyiIndustrySimple);
- }
- //昨日数据
- List<TXinyiDaily> tXinyiDailiesYesterday = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(yesterdayStr).build());
- if(!CollectionUtils.isEmpty(tXinyiDailiesYesterday)){
- TXinyiDaily tXinyiDailyYesterday = tXinyiDailiesYesterday.get(0);
- BigDecimal zrJsl = tXinyiDailyYesterday.getJSL();
- xinyiIndustrySimple.setZrZJSL(zrJsl);
- BigDecimal zrCsl = tXinyiDailyYesterday.getCSL();
- xinyiIndustrySimple.setZrZCSL(zrCsl);
- //有可能今日获取不到日报数据,相关信息从昨天获取
- if(CollectionUtils.isEmpty(tXinyiDailies))
- BeanUtils.copyProperties(tXinyiDailyYesterday, xinyiIndustrySimple);
- //获取前日数据 并计算环比
- List<TXinyiDaily> tXinyiDailiesBeforeYesterday = this.xinyiDailyMapper.selectTXinyiDailyList(TXinyiDaily.builder().testDate(beforeYesterdayStr).build());
- if(!CollectionUtils.isEmpty(tXinyiDailiesBeforeYesterday)){
- TXinyiDaily tXinyiDailyBeforeYesterday = tXinyiDailiesBeforeYesterday.get(0);
- BigDecimal qrZJSL = tXinyiDailyBeforeYesterday.getJSL();
- if(!Objects.isNull(qrZJSL) && !Objects.isNull(zrJsl))
- xinyiIndustrySimple.setZrZJsHb((zrJsl.subtract(qrZJSL)).divide(qrZJSL, 4, RoundingMode.HALF_UP));
- BigDecimal qrZCSL = tXinyiDailyBeforeYesterday.getCSL();
- if(!Objects.isNull(qrZCSL) && !Objects.isNull(zrCsl))
- xinyiIndustrySimple.setZrZCsHb((zrCsl.subtract(qrZCSL)).divide(qrZCSL, 4, RoundingMode.HALF_UP));
- }
- }
- return xinyiIndustrySimple;
- }
- private XinyiIndustrySimple getRealTimeData(String[] queryTags, LocalDateTime nowTime) {
- /*AtomicReference<XinyiIndustrySimple> result = new AtomicReference<>();
- *//*String time = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH, DateUtils.getNowDate());
- time = time + ":00:00";*//*
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD_HH_MM_SS);
- //获取当前的时间
- LocalDateTime beginTime = nowTime.plusMinutes(-1);
- //调用工业库接口
- String url = "http://10.0.0.27:4568/api/v1/khquerydata";
- HashMap<String, Object> req = new HashMap<>();
- req.put("tagNames", queryTags);
- req.put("startTime", formatter.format(beginTime));
- req.put("endTime", formatter.format(nowTime));
- req.put("recordNumbers", 100000);
- String body = HttpRequest.post(url).header("Authorization", "c2E6c2E=").header("clientName", "hongshan").body(JSON.toJSONString(req)).execute().body();
- // System.out.println("body = " + body);
- log.info("实时数据返回的结果是{}", body);
- //2024年5月31日13:43:24 新增解析内容,判断是否正常返回
- String errorCode = (String) JSON.parseObject(body).get("errorCode");
- if("-1".equals(errorCode)){
- log.info("工业库数据返回错误");
- return new XinyiIndustrySimple();
- }
- List<HashMap<String, String>> list = new ArrayList<>();
- //行转列数据处理
- for (String queryTag : queryTags) {
- JSONArray array = JSON.parseObject(body).getJSONArray(queryTag);
- //特殊数据处理一
- if(Objects.isNull(array) || array.isEmpty()){
- System.out.println(queryTag + "查询到了空的数据,跳过本次循环");
- continue;
- }
- int size = array.size();
- //特殊数据处理二
- if("0".equals(array.get(1) + "")){
- System.out.println(queryTag + "查询到了数据,但是数据集合只有一条,且都是0");
- continue;
- }
- //存放的数据集
- //利用map去重
- HashMap<String, String> map = new LinkedHashMap<>();
- for (int i = 2; i < size; i++) {
- // System.out.println(i + "" + array.get(i));
- JSONArray oneRecord = JSON.parseArray(JSON.toJSONString(array.get(i)));
- //处理为空或者为0的数据
- Object timeStampValue = oneRecord.get(2);
- if(Objects.isNull(timeStampValue) || "0".equals(timeStampValue + ""))
- continue;
- BigDecimal value = Objects.isNull(oneRecord.get(0)) ? null : new BigDecimal(oneRecord.get(0) + "");
- long timestamp = (long) timeStampValue;
- String format = DateUtil.format(new Date(timestamp), DateUtils.YYYYMMDDHH_TS);
- map.put(format, queryTag + "-" + value);
- }
- list.add(map);
- }
- Set<String> recordTimeSet = new HashSet<>();
- Map<String, XinyiIndustrySimple> recordMap = new HashMap<>();
- for (int i = 0; i < list.size(); i++) {
- HashMap<String, String> map = list.get(i);
- int finalJ = i;
- map.forEach((k, v) ->{
- XinyiIndustrySimple xinyiIndustrySimple = null;
- if(!recordTimeSet.contains(k)){//第一次
- xinyiIndustrySimple = new XinyiIndustrySimple();
- recordTimeSet.add(k);
- recordMap.put(k, xinyiIndustrySimple);
- }else{
- xinyiIndustrySimple = recordMap.get(k);
- }
- xinyiIndustrySimple.setTestTime(k);
- //解析值
- String[] split = v.split("-");
- String type = split[0];
- BigDecimal value = new BigDecimal(split[1]);
- if ("信义污水厂JS_COD_Value".equals(type)) {
- xinyiIndustrySimple.setJsCod(value);
- } else if ("信义污水厂JS_PH_Value".equals(type)) {
- xinyiIndustrySimple.setJsPh(value);
- } else if ("信义污水厂JS_SS_Value".equals(type)) {
- xinyiIndustrySimple.setJsSs(value);
- } else if ("信义污水厂JS_ZL_Value".equals(type)) {
- xinyiIndustrySimple.setJsTp(value);
- } else if ("信义污水厂JS_ZA_Value".equals(type)) {
- xinyiIndustrySimple.setJsTn(value);
- } else if ("信义污水厂JS_AD_Value".equals(type)) {
- xinyiIndustrySimple.setJsNh3(value);
- } else if ("信义污水厂出水瞬时流量".equals(type)) {
- xinyiIndustrySimple.setCsSlqc(value);
- } else if ("信义污水厂升级出水COD".equals(type)) {
- xinyiIndustrySimple.setCsCod(value);
- } else if ("信义污水厂升级出水PH".equals(type)) {
- xinyiIndustrySimple.setCsPh(value);
- } else if ("信义污水厂升级出水SS".equals(type)) {
- xinyiIndustrySimple.setCsSs(value);
- } else if ("信义污水厂升级出水TN".equals(type)) {
- xinyiIndustrySimple.setCsTn(value);
- } else if ("信义污水厂升级出水TP".equals(type)) {
- xinyiIndustrySimple.setCsTp(value);
- } else if ("信义污水厂升级出水氨氮".equals(type)) {
- xinyiIndustrySimple.setCsNh3(value);
- } else if ("信义污水厂FT101_Value".equals(type)) {
- xinyiIndustrySimple.setJsSlq(value);
- }
- //只有最后一次才执行数据库添加
- if(finalJ == list.size()-1){
- //赋值完毕返回数据
- result.set(xinyiIndustrySimple);
- }
- });
- }
- XinyiIndustrySimple xinyiIndustrySimple = result.get();
- return Objects.isNull(xinyiIndustrySimple) ? new XinyiIndustrySimple() : xinyiIndustrySimple;*/
- //2024年6月11日16:16:17 逻辑调整,获取最新的那条工业库的数据
- TXinyiIndustry tXinyiIndustry = this.xinyiIndustryMapper.selectTXinyiIndustryNewest();
- XinyiIndustrySimple xinyiIndustrySimple = new XinyiIndustrySimple();
- if(!Objects.isNull(tXinyiIndustry))
- BeanUtils.copyProperties(tXinyiIndustry, xinyiIndustrySimple);
- //获取化验室的最新的一条数据
- TXinyiRobot tXinyiRobot = this.xinyiRobotMapper.selectNewest();
- if(!Objects.isNull(tXinyiRobot))
- BeanUtils.copyProperties(tXinyiRobot, xinyiIndustrySimple);
- return xinyiIndustrySimple;
- }
- public static void main(String[] args) {
- String s = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH, DateUtils.getNowDate());
- s = s + ":00:00";
- System.out.println("s = " + s);
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- LocalDateTime endTime = LocalDateTime.now();
- LocalDateTime begin = endTime.plusMinutes(-1);
- System.out.println(formatter.format(endTime));
- System.out.println(formatter.format(begin));
- LocalDate parse = LocalDate.parse("2024-02-26");
- System.out.println("parse = " + parse);
- }
- }
|