Commit b40e4cf1 authored by lilongyang's avatar lilongyang

1、风电/光伏监测左侧列表查询按照时间周期查询

parent 8dd0ffbf
......@@ -357,7 +357,7 @@ public class IdxBizFanHealthIndexController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "GET", value = "TD 风电场站/设备左侧列表通用接口", notes = "TD 风电场站/设备列表通用接口")
@GetMapping(value = "/stationHealthIndexTable")
public ResponseModel<Page<FanHealthIndexDay>> stationHealthIndexTable(@RequestParam(value = "area", required = false) String area,
public ResponseModel<Page> stationHealthIndexTable(@RequestParam(value = "area", required = false) String area,
@RequestParam(value = "station", required = false) String station,
@RequestParam(value = "analysisObjType", required = false) String analysisObjType,
@RequestParam(value = "analysisType", required = false) String analysisType,
......@@ -368,33 +368,28 @@ public class IdxBizFanHealthIndexController extends BaseController {
@RequestParam(value = "equipmentName", required = false) String equipmentName,
@RequestParam(value = "healthLevel", required = false) String healthLevel,
@RequestParam(value = "type", required = false) String type,
@RequestParam(value = "requiredType", required = false) String requiredType,
@RequestParam(value = "subSystem", required = false) String subSystem,
@RequestParam(value = "current", required = false) Integer current,
@RequestParam(value = "size", required = false) Integer size) {
Page<FanHealthIndexDay> page = new Page<FanHealthIndexDay>();
Page page = new Page<>();
page.setCurrent(current);
page.setSize(size);
if (type.equals("0")) {
Date startDayTime = DateUtils.getCurrentDayStartTime(new Date());
Date date = DateUtils.dateAddHours(startDayTime, -9);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
} else {
Date endDate = DateUtils.dateAddHours(DateUtils.longStr2Date(endTimeTop), -7);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
endTimeTop = formatter.format(endDate);
Date startDate = DateUtils.dateAddHours(DateUtils.longStr2Date(startTimeTop), -9);
startTimeTop = formatter.format(startDate);
}
List<String> gatewayIds = permissionService.getCurrentUserAmosOrgCodes();
String orgCode = "NULL";
if (gatewayIds.size() > 0) {
orgCode = gatewayIds.get(0) + "%";
}
int total = 0;
if (requiredType.equals(WarningPeriodEnum.DAY.getName())) {
Date startDayTime = DateUtils.getCurrentDayStartTime(new Date());
Date date = DateUtils.dateAddHours(startDayTime, -9);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
List<FanHealthIndexDay> fanHealthIndexDays = fanHealthIndexDayMapper.selectData(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, (current - 1) * size, size, orgCode);
int total = fanHealthIndexDayMapper.selectDataTotal(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, orgCode);
total = fanHealthIndexDayMapper.selectDataTotal(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, orgCode);
if (CollectionUtils.isEmpty(fanHealthIndexDays)) {
fanHealthIndexDays = fanHealthIndexDayMapper.selectLatestData(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, null, null, (current - 1) * size, size, orgCode);
if (CollectionUtils.isEmpty(fanHealthIndexDays)) {
......@@ -410,6 +405,51 @@ public class IdxBizFanHealthIndexController extends BaseController {
});
page.setRecords(fanHealthIndexDays);
} else if (requiredType.equals(WarningPeriodEnum.HOUR.getName())) {
Date date = new Date();
date = DateUtil.offsetHour(date, -8);
date = DateUtil.offsetMinute(date, -59);
startTimeTop = DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN);
List<FanHealthIndexHour> fanHealthIndexHour = fanHealthIndexHourMapper.selectData(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, (current - 1) * size, size, orgCode);
total = fanHealthIndexHourMapper.selectDataTotal(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, orgCode);
if (CollectionUtils.isEmpty(fanHealthIndexHour)) {
fanHealthIndexHour = fanHealthIndexHourMapper.selectLatestData(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, null, null, (current - 1) * size, size, orgCode);
if (CollectionUtils.isEmpty(fanHealthIndexHour)) {
logger.warn("根据条件:area:{},station:{},equipmentName:{},subSystem:{},pointName:{},analysisObjType:{}获取最新的数据为空", area, station, equipmentName, subSystem, pointName, analysisObjType);
total = 0;
} else {
total = fanHealthIndexHour.size();
}
}
fanHealthIndexHour.forEach(item -> {
double roundedNumber = Double.parseDouble(df.format(item.getHealthIndex()));
item.setHealthIndex(roundedNumber);
});
page.setRecords(fanHealthIndexHour);
} else {
Date date = DateUtils.dateAddMinutes(null, -9);
date = DateUtils.dateAddHours(date, -8);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
List<FanHealthIndexMoment> fanHealthIndexMoment = fanHealthIndexMomentMapper.selectData(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, (current - 1) * size, size, orgCode);
total = fanHealthIndexMomentMapper.selectDataTotal(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, startTimeTop, endTimeTop, orgCode);
if (CollectionUtils.isEmpty(fanHealthIndexMoment)) {
fanHealthIndexMoment = fanHealthIndexMomentMapper.selectLatestData(healthLevel, area, equipmentName, subSystem, analysisType, analysisObjType, station, pointName, indexAddress, null, null, (current - 1) * size, size, orgCode);
if (CollectionUtils.isEmpty(fanHealthIndexMoment)) {
logger.warn("根据条件:area:{},station:{},equipmentName:{},subSystem:{},pointName:{},analysisObjType:{}获取最新的数据为空", area, station, equipmentName, subSystem, pointName, analysisObjType);
total = 0;
} else {
total = fanHealthIndexMoment.size();
}
}
fanHealthIndexMoment.forEach(item -> {
double roundedNumber = Double.parseDouble(df.format(item.getHealthIndex()));
item.setHealthIndex(roundedNumber);
});
page.setRecords(fanHealthIndexMoment);
}
page.setTotal(total);
return ResponseHelper.buildResponse(page);
}
......@@ -505,7 +545,7 @@ public class IdxBizFanHealthIndexController extends BaseController {
startTimeTop = DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN);
maps = fanHealthIndexHourMapper.selectEquipStatusByStation(area, analysisObjType, station, gatewayIds,startTimeTop);
}else{
Date date = DateUtils.dateAddMinutes(null, -9);
Date date = DateUtils.dateAddMinutes(null, -12);
date = DateUtils.dateAddHours(date, -8);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
......@@ -563,7 +603,7 @@ public class IdxBizFanHealthIndexController extends BaseController {
startTimeTop = DateUtil.format(date, DatePattern.NORM_DATETIME_PATTERN);
maps = fanHealthIndexHourMapper.selectEquipStatusByEquipment("测点", STATION, EQUIPMENTNAME,startTimeTop);
}else{
Date date = DateUtils.dateAddMinutes(null, -9);
Date date = DateUtils.dateAddMinutes(null, -12);
date = DateUtils.dateAddHours(date, -8);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
......@@ -676,7 +716,7 @@ public class IdxBizFanHealthIndexController extends BaseController {
return ResponseHelper.buildResponse(page);
} else {
// if (null != type && type.equals("0")){
Date date = DateUtils.dateAddMinutes(null, -9);
Date date = DateUtils.dateAddMinutes(null, -12);
date = DateUtils.dateAddHours(date, -8);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
......@@ -759,7 +799,7 @@ public class IdxBizFanHealthIndexController extends BaseController {
return ResponseHelper.buildResponse(map);
} else {
// if (null != type && type.equals("0")){
Date date = DateUtils.dateAddMinutes(null, -9);
Date date = DateUtils.dateAddMinutes(null, -12);
date = DateUtils.dateAddHours(date, -8);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startTimeTop = formatter.format(date);
......
......@@ -66,4 +66,62 @@ public interface FanHealthIndexHourMapper extends BaseMapper<FanHealthIndexHour>
"</script>")
List<Map<String, Object>> selectEquipStatusByEquipment( @Param("analysisObjType") String analysisObjType, @Param("station") String station, @Param("equipmentName") String equipmentName,@Param("startTimeTop") String startTimeTop);
@Select("<script>" +
"SELECT count(1) from ( SELECT distinct `health_index` AS healthIndex,anomaly,rec_date as recDate, `health_index` AS `value`, substr(analysis_time,1,10) as analysisTime, station,equipment_name AS equipmentName,point_name as pointName,\n" +
"( CASE HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status FROM analysis_data.fan_health_index_hour WHERE analysis_obj_type = #{analysisObjType} and org_code is not null" +
"<if test='endTimeTop!= null'> and ts &lt;= #{endTimeTop} </if> " +
"<if test='startTimeTop!= null'> and ts &gt;= #{startTimeTop} </if> " +
"<if test='area!= null'> AND area = #{area} </if> " +
"<if test='indexAddress!= null'> AND index_address = #{indexAddress} </if> " +
"<if test='pointName!= null'>AND point_name = #{pointName} </if> " +
"<if test='station!= null'>AND station = #{station} </if>" +
"<if test='healthLevel!= null'>AND health_level = #{healthLevel} </if>" +
"<if test='subSystem!= null'>AND sub_system = #{subSystem} </if> " +
"<if test='equipmentName!= null'>AND equipment_name = #{equipmentName} </if>" +
"<if test='orgCode!= null'>AND org_code like '${orgCode}' </if>)" +
"</script>")
int selectDataTotal(@Param("healthLevel") String healthLevel, @Param("area") String area, @Param("equipmentName") String equipmentName, @Param("subSystem") String subSystem, @Param("analysisType") String analysisType, @Param("analysisObjType") String analysisObjType, @Param("station") String station, @Param("pointName") String pointName, @Param("indexAddress") String indexAddress, @Param("startTimeTop") String startTimeTop, @Param("endTimeTop") String endTimeTop, @Param("orgCode") String orgCode);
@Select("<script>"+
"SELECT distinct d.`health_index` AS healthIndex,d.ts,d.rec_date as recDate, d.`health_index` AS `value`, d.anomaly, substr(d.analysis_time,1,10) as analysisTime,d.station,d.equipment_name AS equipmentName, d.point_name as pointName, ( CASE d.HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status" +
" FROM analysis_data.fan_health_index_hour d" +
" INNER JOIN (SELECT last(ts) as maxTs " +
"<if test='area!= null '> ,area </if> " +
"<if test='station!= null'>, station </if>" +
"<if test='subSystem!= null'>, sub_system </if> " +
"<if test='equipmentName!= null'>, equipment_name </if>" +
"<if test='pointName!= null '>, point_name </if> " +
" FROM analysis_data.fan_health_index_hour WHERE analysis_obj_type = #{analysisObjType} " +
" GROUP BY " +
"<if test='area!= null '> area </if> " +
"<if test='station!= null'>, station </if>" +
"<if test='subSystem!= null'>, sub_system </if> " +
"<if test='equipmentName!= null'>, equipment_name </if>" +
"<if test='pointName!= null '>, point_name </if> " +
" ORDER BY ts ASC ) as c " +
" on d.ts = c.maxTs" +
"<if test='area!= null '> and d.area = c.area </if> " +
"<if test='station!= null'> and d.station = c.station </if>" +
"<if test='subSystem!= null'> and d.sub_system = c.sub_system </if> " +
"<if test='equipmentName!= null'> and d.equipment_name = c.equipment_name </if>" +
"<if test='pointName!= null '> and d.point_name = c.point_name </if> " +
"WHERE d.analysis_obj_type = #{analysisObjType} and d.org_code is not null" +
"<if test='endTimeTop!= null'> and d.ts &lt;= #{endTimeTop} </if> " +
"<if test='startTimeTop!= null'> and d.ts &gt;= #{startTimeTop} </if> " +
"<if test='area!= null '> AND d.area = #{area} </if> " +
"<if test='indexAddress!= null '> AND d.index_address = #{indexAddress} </if> " +
"<if test='pointName!= null '>AND d.point_name = #{pointName} </if> " +
"<if test='station!= null'>AND d.station = #{station} </if>" +
"<if test='healthLevel!= null '>AND d.health_level = #{healthLevel} </if>" +
"<if test='subSystem!= null'>AND sub_system = #{subSystem} </if> " +
"<if test='equipmentName!= null'>AND d.equipment_name = #{equipmentName} </if>" +
"<if test='orgCode!= null'>AND d.org_code like '${orgCode}' </if>" +
"order by d.ts DESC "+
"<if test='current != null and size != null'>limit ${current},${size} </if>" +
"</script>")
List<FanHealthIndexHour> selectLatestData(@Param("healthLevel") String healthLevel, @Param("area") String area, @Param("equipmentName") String equipmentName, @Param("subSystem") String subSystem, @Param("analysisType") String analysisType, @Param("analysisObjType") String analysisObjType, @Param("station") String station, @Param("pointName") String pointName, @Param("indexAddress") String indexAddress, @Param("startTimeTop") String startTimeTop, @Param("endTimeTop") String endTimeTop,
@Param("current") Integer current, @Param("size") Integer size,
@Param("orgCode") String orgCode
);
}
......@@ -65,4 +65,61 @@ public interface FanHealthIndexMomentMapper extends BaseMapper<FanHealthIndexMom
"</script>")
List<Map<String, Object>> selectEquipStatusByEquipment( @Param("analysisObjType") String analysisObjType, @Param("station") String station, @Param("equipmentName") String equipmentName,@Param("startTimeTop") String startTimeTop);
@Select("<script>" +
"SELECT count(1) from ( SELECT distinct `health_index` AS healthIndex,anomaly,rec_date as recDate, `health_index` AS `value`, substr(analysis_time,1,10) as analysisTime, station,equipment_name AS equipmentName,point_name as pointName,\n" +
"( CASE HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status FROM analysis_data.fan_health_index_moment WHERE analysis_obj_type = #{analysisObjType} and org_code is not null" +
"<if test='endTimeTop!= null'> and ts &lt;= #{endTimeTop} </if> " +
"<if test='startTimeTop!= null'> and ts &gt;= #{startTimeTop} </if> " +
"<if test='area!= null'> AND area = #{area} </if> " +
"<if test='indexAddress!= null'> AND index_address = #{indexAddress} </if> " +
"<if test='pointName!= null'>AND point_name = #{pointName} </if> " +
"<if test='station!= null'>AND station = #{station} </if>" +
"<if test='healthLevel!= null'>AND health_level = #{healthLevel} </if>" +
"<if test='subSystem!= null'>AND sub_system = #{subSystem} </if> " +
"<if test='equipmentName!= null'>AND equipment_name = #{equipmentName} </if>" +
"<if test='orgCode!= null'>AND org_code like '${orgCode}' </if>)" +
"</script>")
int selectDataTotal(@Param("healthLevel") String healthLevel, @Param("area") String area, @Param("equipmentName") String equipmentName, @Param("subSystem") String subSystem, @Param("analysisType") String analysisType, @Param("analysisObjType") String analysisObjType, @Param("station") String station, @Param("pointName") String pointName, @Param("indexAddress") String indexAddress, @Param("startTimeTop") String startTimeTop, @Param("endTimeTop") String endTimeTop, @Param("orgCode") String orgCode);
@Select("<script>"+
"SELECT distinct d.`health_index` AS healthIndex,d.ts,d.rec_date as recDate, d.`health_index` AS `value`, d.anomaly, substr(d.analysis_time,1,10) as analysisTime,d.station,d.equipment_name AS equipmentName, d.point_name as pointName, ( CASE d.HEALTH_LEVEL WHEN '危险' THEN 3 WHEN '警告' THEN 2 WHEN '注意' THEN 1 ELSE 0 END ) AS status" +
" FROM analysis_data.fan_health_index_moment d" +
" INNER JOIN (SELECT last(ts) as maxTs " +
"<if test='area!= null '> ,area </if> " +
"<if test='station!= null'>, station </if>" +
"<if test='subSystem!= null'>, sub_system </if> " +
"<if test='equipmentName!= null'>, equipment_name </if>" +
"<if test='pointName!= null '>, point_name </if> " +
" FROM analysis_data.fan_health_index_moment WHERE analysis_obj_type = #{analysisObjType} " +
" GROUP BY " +
"<if test='area!= null '> area </if> " +
"<if test='station!= null'>, station </if>" +
"<if test='subSystem!= null'>, sub_system </if> " +
"<if test='equipmentName!= null'>, equipment_name </if>" +
"<if test='pointName!= null '>, point_name </if> " +
" ORDER BY ts ASC ) as c " +
" on d.ts = c.maxTs" +
"<if test='area!= null '> and d.area = c.area </if> " +
"<if test='station!= null'> and d.station = c.station </if>" +
"<if test='subSystem!= null'> and d.sub_system = c.sub_system </if> " +
"<if test='equipmentName!= null'> and d.equipment_name = c.equipment_name </if>" +
"<if test='pointName!= null '> and d.point_name = c.point_name </if> " +
"WHERE d.analysis_obj_type = #{analysisObjType} and d.org_code is not null" +
"<if test='endTimeTop!= null'> and d.ts &lt;= #{endTimeTop} </if> " +
"<if test='startTimeTop!= null'> and d.ts &gt;= #{startTimeTop} </if> " +
"<if test='area!= null '> AND d.area = #{area} </if> " +
"<if test='indexAddress!= null '> AND d.index_address = #{indexAddress} </if> " +
"<if test='pointName!= null '>AND d.point_name = #{pointName} </if> " +
"<if test='station!= null'>AND d.station = #{station} </if>" +
"<if test='healthLevel!= null '>AND d.health_level = #{healthLevel} </if>" +
"<if test='subSystem!= null'>AND sub_system = #{subSystem} </if> " +
"<if test='equipmentName!= null'>AND d.equipment_name = #{equipmentName} </if>" +
"<if test='orgCode!= null'>AND d.org_code like '${orgCode}' </if>" +
"order by d.ts DESC "+
"<if test='current != null and size != null'>limit ${current},${size} </if>" +
"</script>")
List<FanHealthIndexMoment> selectLatestData(@Param("healthLevel") String healthLevel, @Param("area") String area, @Param("equipmentName") String equipmentName, @Param("subSystem") String subSystem, @Param("analysisType") String analysisType, @Param("analysisObjType") String analysisObjType, @Param("station") String station, @Param("pointName") String pointName, @Param("indexAddress") String indexAddress, @Param("startTimeTop") String startTimeTop, @Param("endTimeTop") String endTimeTop,
@Param("current") Integer current, @Param("size") Integer size,
@Param("orgCode") String orgCode
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment