package com.xlht.xlhtproject.service.impl; import com.xlht.xlhtproject.domain.*; import com.xlht.xlhtproject.enums.BusinessEnum; import com.xlht.xlhtproject.mapper.*; import com.xlht.xlhtproject.service.IFrontService; import com.xlht.xlhtproject.utils.DateUtils; import com.xlht.xlhtproject.utils.StringUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.math.RoundingMode; import java.util.*; import java.util.stream.Collectors; import static com.xlht.xlhtproject.enums.MyConstants.*; @Service @Slf4j public class FrontServiceImpl implements IFrontService { @Autowired private TShuju1Mapper shuju1Mapper; @Autowired private TTbXieMapper xieMapper; @Autowired private ZAssayMapper zAssayMapper; @Autowired private TXlhtAddRecordMapper xlhtAddRecordMapper; @Autowired private ZAssayResultMapper zAssayResultMapper; @Override public SmartAdd smartAddDataInfo() { return this.shuju1Mapper.getNewestData(); } @Override public Map> smartAddCharList(int type, String timeBegin, String timeEnd) { // return Collections.emptyMap(); //日期兜底处理 Date nowDate = DateUtils.getNowDate(); Date dayBefore7 = DateUtils.plusDate(-1, nowDate); //2024年09月13日17:02:59 支持前段自定义起止时间 //先用日期获取当天和前一天的数据,如果获取不到,则提示错误信息 String nowDateStr = StringUtils.isBlank(timeEnd) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, nowDate) : timeEnd; String dayBefore1Str = StringUtils.isBlank(timeBegin) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dayBefore7) : timeBegin; //返回的对象 Map> result = new HashMap<>(); //获取筛选日期内的所有的数据 List tShuju1List = this.shuju1Mapper.selectTShuju1List(TShuju1.builder().timeBegin(dayBefore1Str).timeEnd(nowDateStr).build()); List list = new ArrayList<>(); //先判断类型,然后根据不同类型,查询不同的数据 if(BusinessEnum.SmartAddMedicineReqEnum.JSLL.getCode() == type){ //查询仪表即可 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), Objects.isNull(o.getScJsZll()) ? null : o.getScJsZll().divide(BigDecimal_2, NUMBER_SCALE_4, RoundingMode.HALF_UP))) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.HY_1_XSY.getCode() == type){ //查询化验室 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr1HyXiaodan())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list); //查询预测 锡林浩特没有预测数据 // result.put(BusinessEnum.DataSourceEnum.YC.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.HY_2_XSY.getCode() == type){ //查询化验室 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr2HyXiaodan())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list); //查询预测 锡林浩特没有预测数据 // list = // result.put(BusinessEnum.DataSourceEnum.YC.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.QY_1_AD.getCode() == type){ //查询化验室 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr1QyAndan())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.QY_2_AD.getCode() == type){ //查询化验室 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr2QyAndan())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.JSCOD.getCode() == type){ //查询仪表即可 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getScJsCod())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list); //查询化验室 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqrSwcCod())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.HY.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.JSTN.getCode() == type){ //查询仪表即可 list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getScJsZongdan())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list); }else if(BusinessEnum.SmartAddMedicineReqEnum.TYTJL.getCode() == type){ //查询仪表即可 锡林浩特的没有 /*list = tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.get())) .collect(Collectors.toList()); result.put(BusinessEnum.DataSourceEnum.YB.getCode(), list);*/ }else{ log.info("暂不支持的类型~~~"); } return result; } /** * * 0 进水流量 * 1 #1好氧池硝酸盐 * 2 #2好氧池硝酸盐 * 3 #1缺氧池氨氮 * 4 #2缺氧池氨氮 * 5 进水COD--连续检测 * 6 进水COD--在线仪表 * 7 进水总氮 * 8 碳源投加量-#1-计算投药量 * 9 碳源投加量-#2-计算投药量 * 10 碳源投加量-#1-组态反馈 * 11 碳源投加量-#2-组态反馈 * @param timeBegin * @param timeEnd * @return */ @Override public Map> smartAddCharListAll(String timeBegin, String timeEnd) { //返回结果 Map> result = new HashMap<>(); //日期兜底处理 Date nowDate = DateUtils.getNowDate(); Date dayBefore7 = DateUtils.plusDate(-1, nowDate); //2024年09月13日17:02:59 支持前段自定义起止时间 //先用日期获取当天和前一天的数据,如果获取不到,则提示错误信息 String nowDateStr = StringUtils.isBlank(timeEnd) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, nowDate) : timeEnd; String dayBefore1Str = StringUtils.isBlank(timeBegin) ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, dayBefore7) : timeBegin; //获取筛选日期内的所有的数据 List tShuju1List = this.shuju1Mapper.selectTShuju1List(TShuju1.builder().timeBegin(dayBefore1Str).timeEnd(nowDateStr).build()); //返回的对象具体内容 //进水流量 result.put("0", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), Objects.isNull(o.getScJsZll()) ? null : o.getScJsZll().divide(BigDecimal_2, NUMBER_SCALE_4, RoundingMode.HALF_UP))) .collect(Collectors.toList())); //#1好氧池硝酸盐 result.put("1", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr1HyXiaodan())) .collect(Collectors.toList())); //#2好氧池硝酸盐 result.put("2", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr2HyXiaodan())) .collect(Collectors.toList())); //#1缺氧池氨氮 result.put("3", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr1QyAndan())) .collect(Collectors.toList())); //#2缺氧池氨氮 result.put("4", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqr2QyAndan())) .collect(Collectors.toList())); //进水COD--连续检测 result.put("5", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getJqrSwcCod())) .collect(Collectors.toList())); //进水COD--在线仪表 result.put("6", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getScJsCod())) .collect(Collectors.toList())); //进水总氮 result.put("7", tShuju1List.stream() .map(o -> new ChartBasic(o.getTIME(), o.getScJsZongdan())) .collect(Collectors.toList())); //处理投加信息 List tXlhtAddRecords = xlhtAddRecordMapper.selectTXlhtAddRecordList(TXlhtAddRecord.builder().timeBegin(timeBegin).timeEnd(timeEnd).build()); result.put("8", tXlhtAddRecords.stream() .map(o -> new ChartBasic(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, o.getCreateTime()), o.getOneAmount())) .collect(Collectors.toList())); result.put("9", tXlhtAddRecords.stream() .map(o -> new ChartBasic(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, o.getCreateTime()), o.getTwoAmount())) .collect(Collectors.toList())); result.put("10", tXlhtAddRecords.stream() .map(o -> new ChartBasic(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, o.getCreateTime()), o.getRealOneAmount())) .collect(Collectors.toList())); result.put("11", tXlhtAddRecords.stream() .map(o -> new ChartBasic(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, o.getCreateTime()), o.getRealTwoAmount())) .collect(Collectors.toList())); return result; } @Override public HomeCountInfo homeCountInfo() { HomeCountInfo build = HomeCountInfo.builder().build(); //获取化验状态 TTbXie tTbXie = this.xieMapper.selectTTbXieByID(LONG_1); if(!Objects.isNull(tTbXie)) build.setStatus(tTbXie.getJqrZhuantai()); //获取累计运行天数 定义:只要某天有化验,那么就算累计加一天 //2024年10月13日13:56:33 查询逻辑调整:不再查询化验记录,查询上报的数据 (T_SHUJU_1)表的数据 build.setDays(this.zAssayMapper.selectDistinctDays()); /*//获取累计化验轮次 build.setCounts(this.zAssayMapper.selectCount()); //获取累计化验次数 build.setTotals(this.zAssayResultMapper.selectCount());*/ //2024年10月13日13:56:14 化验次数和化验轮次 int count = this.shuju1Mapper.selectCountDistinctAssayNo(); build.setCounts(count); build.setTotals(count * INT_7); return build; } }