whyclxw
2025-05-28 e16302f9d475c7cc4dd18c5abf1a23cb5502e362
src/main/java/com/whyc/service/PwrdevDataHistoryService.java
@@ -7,6 +7,7 @@
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;
@@ -21,6 +22,9 @@
public class PwrdevDataHistoryService {
    @Resource
    private PwrdevDataHistoryMapper mapper;
    @Autowired
    private SubTablePageInfoService subService;
    public Response searchByCondition(PwrdevReportParam pwrdevReportParam){
        //获取设备id
@@ -49,7 +53,7 @@
        }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, "数据表不存在");
@@ -66,19 +70,22 @@
                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);
            }
            //当是天或者周为同月时,直接在当月表中获取开始时间到结束时间的数据
@@ -86,7 +93,8 @@
            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);
                }
            }