| | |
| | | package com.whyc.service; |
| | | |
| | | import com.whyc.dto.PowerDevDataAC; |
| | | import com.whyc.dto.PowerDevDataACDC; |
| | | import com.whyc.dto.PowerDevDataDC; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.paramter.PwrdevReportParam; |
| | | import com.whyc.mapper.PwrdevDataHistoryMapper; |
| | | import com.whyc.pojo.PwrdevDataHistory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class PwrdevDataHistoryService { |
| | | @Resource |
| | | private PwrdevDataHistoryMapper mapper; |
| | | |
| | | @Autowired |
| | | private SubTablePageInfoService subService; |
| | | |
| | | public Response searchByCondition(PwrdevReportParam pwrdevReportParam){ |
| | | //获取设备id |
| | |
| | | }else{ |
| | | sqlend = calendar_start.get(Calendar.YEAR)+"%"; |
| | | } |
| | | List<String> tableNameList = mapper.getTableNameList(deviceId+"_"+sqlend); |
| | | List<String> tableNameList = mapper.getTableNameList("tb_pwrdev_historydata_"+deviceId+"_"+sqlend); |
| | | //如果未查询到表名,则没有数据 |
| | | if (tableNameList.size()==0){ |
| | | return new Response().set(1, false, "数据表不存在"); |
| | |
| | | int endMonth = calendar_end.get(Calendar.MONTH)+1; |
| | | //当表名和开始时间的月份相同时,获取开始时间后的数据 |
| | | if (Integer.valueOf(tableName.substring(tableName.length()-2))==startMonth){ |
| | | List<PwrdevDataHistory> listMonth = mapper.getGtStartTime(tableName,startTime); |
| | | //List<PwrdevDataHistory> listMonth = mapper.getGtStartTime(tableName,startTime); |
| | | List<PwrdevDataHistory> listMonth = subService.getGtStartTime(tableName,startTime); |
| | | result.addAll(listMonth); |
| | | } |
| | | //当结束时间与表名的月份相同时,获取结束时间前的数据 |
| | | if (Integer.valueOf(tableName.substring(tableName.length()-2))==endMonth){ |
| | | List<PwrdevDataHistory> listMonth = mapper.getLtEndTime(tableName,endTime); |
| | | //List<PwrdevDataHistory> listMonth = mapper.getLtEndTime(tableName,endTime); |
| | | List<PwrdevDataHistory> listMonth = subService.getLtEndTime(tableName,endTime); |
| | | result.addAll(listMonth); |
| | | } |
| | | } |
| | | //当是年或者月的时候,直接获取整表数据 |
| | | }else if("year".equals(type) || "month".equals(type)){ |
| | | for (String tableName: tableNameList ) { |
| | | List<PwrdevDataHistory> listMonth = mapper.getData(tableName); |
| | | //List<PwrdevDataHistory> listMonth = mapper.getData(tableName); |
| | | List<PwrdevDataHistory> listMonth = subService.getData(tableName); |
| | | result.addAll(listMonth); |
| | | } |
| | | //当是天或者周为同月时,直接在当月表中获取开始时间到结束时间的数据 |
| | |
| | | for (String tableName: tableNameList ) { |
| | | int month = calendar_start.get(Calendar.MONTH)+1; |
| | | if (Integer.valueOf(tableName.substring(tableName.length()-2))==month){ |
| | | List<PwrdevDataHistory> listMonth = mapper.getWeekOrDayData(tableName,startTime,endTime); |
| | | //List<PwrdevDataHistory> listMonth = mapper.getWeekOrDayData(tableName,startTime,endTime); |
| | | List<PwrdevDataHistory> listMonth = subService.getWeekOrDayData(tableName,startTime,endTime); |
| | | result.addAll(listMonth); |
| | | } |
| | | } |
| | | } |
| | | return new Response().set(1,result,"查询成功"); |
| | | |
| | | //追加 ac,acdc,dc分开返回 |
| | | String dataType = pwrdevReportParam.getDataType(); |
| | | Object dataResult; |
| | | if(dataType.equals("ac")){ |
| | | dataResult = result.stream().map(data -> { |
| | | PowerDevDataAC ac = new PowerDevDataAC(); |
| | | ac.setRecordTime(data.getRecordTime()); |
| | | ac.setAcAcIn1VolA(data.getAcAcIn1VolA()); |
| | | ac.setAcAcIn1VolB(data.getAcAcIn1VolB()); |
| | | ac.setAcAcIn1VolC(data.getAcAcIn1VolC()); |
| | | ac.setAcAcIn1CurrA(data.getAcAcIn1CurrA()); |
| | | ac.setAcAcIn1CurrB(data.getAcAcIn1CurrB()); |
| | | ac.setAcAcIn1CurrC(data.getAcAcIn1CurrC()); |
| | | ac.setAcAcIn2VolA(data.getAcAcIn2VolA()); |
| | | ac.setAcAcIn2VolB(data.getAcAcIn2VolB()); |
| | | ac.setAcAcIn2VolC(data.getAcAcIn2VolC()); |
| | | ac.setAcAcIn2CurrA(data.getAcAcIn2CurrA()); |
| | | ac.setAcAcIn2CurrB(data.getAcAcIn2CurrB()); |
| | | ac.setAcAcIn2CurrC(data.getAcAcIn2CurrC()); |
| | | ac.setAcTemprature(data.getAcTemprature()); |
| | | ac.setAcAcVolHLimit(data.getAcAcVolHLimit()); |
| | | ac.setAcAcVolLLimit(data.getAcAcVolLLimit()); |
| | | return ac; |
| | | }).collect(Collectors.toList()); |
| | | }else if(dataType.equals("acdc")){ |
| | | dataResult = result.stream().map(data -> { |
| | | PowerDevDataACDC acdc = new PowerDevDataACDC(); |
| | | acdc.setRecordTime(data.getRecordTime()); |
| | | acdc.setAcdcAcdcmTemp(data.getAcdcAcdcmTemp()); |
| | | acdc.setAcdcAcIn1VolA(data.getAcdcAcIn1VolA()); |
| | | acdc.setAcdcAcIn1VolB(data.getAcdcAcIn1VolB()); |
| | | acdc.setAcdcAcIn1VolC(data.getAcdcAcIn1VolC()); |
| | | acdc.setAcdcAcIn2VolA(data.getAcdcAcIn2VolA()); |
| | | acdc.setAcdcAcIn2VolB(data.getAcdcAcIn2VolB()); |
| | | acdc.setAcdcAcIn2VolC(data.getAcdcAcIn2VolC()); |
| | | acdc.setAcdcAcOutCurrA(data.getAcdcAcOutCurrA()); |
| | | acdc.setAcdcAcOutCurrB(data.getAcdcAcOutCurrB()); |
| | | acdc.setAcdcAcOutCurrC(data.getAcdcAcOutCurrC()); |
| | | acdc.setAcdcAcOutVolA(data.getAcdcAcOutVolA()); |
| | | acdc.setAcdcAcOutVolB(data.getAcdcAcOutVolB()); |
| | | acdc.setAcdcAcOutVolC(data.getAcdcAcOutVolC()); |
| | | acdc.setAcdcAcVolHLimit(data.getAcdcAcVolHLimit()); |
| | | acdc.setAcdcAcVolLLimit(data.getAcdcAcVolLLimit()); |
| | | acdc.setAcdcBattgroup1Curr(data.getAcdcBattgroup1Curr()); |
| | | acdc.setAcdcBattgroup1Vol(data.getAcdcBattgroup1Vol()); |
| | | acdc.setAcdcBattgroup2Curr(data.getAcdcBattgroup2Curr()); |
| | | acdc.setAcdcBattgroup2Vol(data.getAcdcBattgroup2Vol()); |
| | | acdc.setAcdcChargLimitCurr(data.getAcdcChargLimitCurr()); |
| | | acdc.setAcdcDcOutVol(data.getAcdcDcOutVol()); |
| | | acdc.setAcdcDcOutVolHLimit(data.getAcdcDcOutVolHLimit()); |
| | | acdc.setAcdcDcOutVolLLimit(data.getAcdcDcOutVolLLimit()); |
| | | acdc.setAcdcFloatChargeVol(data.getAcdcFloatChargeVol()); |
| | | acdc.setAcdcJunChargeVol(data.getAcdcJunChargeVol()); |
| | | acdc.setAcdcLoaderCurr(data.getAcdcLoaderCurr()); |
| | | acdc.setAcdcM10OutCurr(data.getAcdcM10OutCurr()); |
| | | acdc.setAcdcM11OutCurr(data.getAcdcM11OutCurr()); |
| | | acdc.setAcdcM12OutCurr(data.getAcdcM12OutCurr()); |
| | | acdc.setAcdcM13OutCurr(data.getAcdcM13OutCurr()); |
| | | acdc.setAcdcM14OutCurr(data.getAcdcM14OutCurr()); |
| | | acdc.setAcdcM15OutCurr(data.getAcdcM15OutCurr()); |
| | | acdc.setAcdcM16OutCurr(data.getAcdcM16OutCurr()); |
| | | acdc.setAcdcM1OutCurr(data.getAcdcM1OutCurr()); |
| | | acdc.setAcdcM2OutCurr(data.getAcdcM2OutCurr()); |
| | | acdc.setAcdcM3OutCurr(data.getAcdcM3OutCurr()); |
| | | acdc.setAcdcM4OutCurr(data.getAcdcM4OutCurr()); |
| | | acdc.setAcdcM5OutCurr(data.getAcdcM5OutCurr()); |
| | | acdc.setAcdcM6OutCurr(data.getAcdcM6OutCurr()); |
| | | acdc.setAcdcM7OutCurr(data.getAcdcM7OutCurr()); |
| | | acdc.setAcdcM8OutCurr(data.getAcdcM8OutCurr()); |
| | | acdc.setAcdcM9OutCurr(data.getAcdcM9OutCurr()); |
| | | |
| | | return acdc; |
| | | }).collect(Collectors.toList()); |
| | | }else if(dataType.equals("dc")){ |
| | | dataResult = result.stream().map(data -> { |
| | | PowerDevDataDC dc = new PowerDevDataDC(); |
| | | dc.setRecordTime(data.getRecordTime()); |
| | | dc.setDcDcIn1Vol(data.getDcDcIn1Vol()); |
| | | dc.setDcDcIn2Vol(data.getDcDcIn2Vol()); |
| | | dc.setDcDcOut1Curr(data.getDcDcOut1Curr()); |
| | | dc.setDcDcOut1Vol(data.getDcDcOut1Vol()); |
| | | dc.setDcDcOut2Curr(data.getDcDcOut2Curr()); |
| | | dc.setDcDcOut2Vol(data.getDcDcOut2Vol()); |
| | | dc.setDcDcVolHLimit(data.getDcDcVolHLimit()); |
| | | dc.setDcDcVolLLimit(data.getDcDcVolLLimit()); |
| | | dc.setDcTemprature(data.getDcTemprature()); |
| | | |
| | | return dc; |
| | | }).collect(Collectors.toList()); |
| | | }else{ |
| | | return new Response().set(1,false,"传参dataType不匹配,查询失败"); |
| | | } |
| | | //return new Response().set(1,result,"查询成功"); |
| | | return new Response().set(1,dataResult,"查询成功"); |
| | | } |
| | | |
| | | } |