Commit b81b8506 authored by tianyiming's avatar tianyiming

9885 监盘概览/接口开发2

parent 9996b380
package com.yeejoin.equipmanage.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.equipmanage.common.utils.CommonPageable;
import com.yeejoin.equipmanage.common.utils.CommonResponseUtil;
import com.yeejoin.equipmanage.common.utils.StringUtil;
import com.yeejoin.equipmanage.common.utils.*;
import com.yeejoin.equipmanage.config.PersonIdentify;
import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.mapper.FireFightingSystemMapper;
import com.yeejoin.equipmanage.service.IEquipmentSpecificAlarmService;
import com.yeejoin.equipmanage.service.IFireFightingSystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -15,17 +17,17 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.HashMap;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@Api(tags = "监盘总览组态需求 -- API")
......@@ -38,6 +40,12 @@ public class SupervisionConfigureController extends AbstractBaseController {
@Autowired
private IFireFightingSystemService iFireFightingSystemService;
@Autowired
private IEquipmentSpecificAlarmService equipmentSpecificAlarmService;
@Autowired
private IotFeign iotFeign;
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "监盘概览水源信息")
......@@ -175,4 +183,182 @@ public class SupervisionConfigureController extends AbstractBaseController {
return CommonResponseUtil.success(iFireFightingSystemService.getSystemStatusBySuper(hashMap));
}
@PersonIdentify
@RequestMapping(value = "/fireAlarmLogPage", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "列表分页查询", produces = "application/json;charset=UTF-8", notes = "列表分页查询")
public ResponseModel pageQuery(@RequestParam(required = false) String system, @RequestParam(required = false) String specificIndexKey, CommonPageable commonPageable) {
if (commonPageable.getPageNumber() == 0) {
commonPageable.setPageNumber(1);
}
ReginParams reginParams = getSelectedOrgInfo();
List<CommonRequest> queryRequests = new ArrayList<>();
CommonRequest request7 = new CommonRequest();
request7.setName("system");
request7.setValue(StringUtil.isNotEmpty(system) ? StringUtils.trimToNull(system) : null);
queryRequests.add(request7);
CommonRequest request8 = new CommonRequest();
request8.setName("specificIndexKey");
request8.setValue(StringUtil.isNotEmpty(specificIndexKey) ? StringUtils.trimToNull(specificIndexKey) : null);
queryRequests.add(request8);
if (!ValidationUtil.isEmpty(reginParams.getPersonIdentity())) {
CommonRequest request13 = new CommonRequest();
request13.setName("bizOrgCode");
request13.setValue(StringUtil.isNotEmpty(reginParams.getPersonIdentity().getBizOrgCode()) ? reginParams.getPersonIdentity().getBizOrgCode() : null);
queryRequests.add(request13);
}
CommonPageInfoParam param = CommonPageParamUtil.fillCommonPageInfoParam(queryRequests, commonPageable);
return CommonResponseUtil.success(equipmentSpecificAlarmService.fireAlarmLogPage(param));
}
@PersonIdentify
@RequestMapping(value = "/alarmTrend", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "报警类型趋势", produces = "application/json;charset=UTF-8", notes = "报警类型趋势")
public ResponseModel alarmTrend(@RequestParam(required = false) String bizOrgCode) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
if (StringUtils.isBlank(bizOrgCode)) {
bizOrgCode = personIdentity.getBizOrgCode();
}
}
return CommonResponseUtil.success(equipmentSpecificAlarmService.alarmTrend(bizOrgCode));
}
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(value = "概览稳压泵信息")
@GetMapping("/getPressurePumpInfo")
public ResponseModel getPressurePumpInfo(CommonPageable commonPageable) {
if (commonPageable.getPageNumber() == 0) {
commonPageable.setPageNumber(1);
}
ReginParams reginParams = getSelectedOrgInfo();
String bizOrgCode = !ValidationUtil.isEmpty(reginParams.getPersonIdentity()) && StringUtil.isNotEmpty(reginParams.getPersonIdentity().getBizOrgCode()) ? reginParams.getPersonIdentity().getBizOrgCode() : null;
Page page = new Page<>(commonPageable.getPageNumber(), commonPageable.getPageSize());
if (StringUtils.isEmpty(bizOrgCode)) {
return CommonResponseUtil.success(null);
}
Page<Map<String, Object>> pressurePumpInfo = fireFightingSystemMapper.getPressurePumpInfo(page, bizOrgCode, null);
List<Long> ids = new ArrayList();
pressurePumpInfo.getRecords().stream().map(item -> {
item.put("monthStartNum", 0);
item.put("halfHourStartNum", 0);
item.put("twoHourStartNum", 0);
item.put("fourHourStartNum", 0);
item.put("update_time", "--");
item.put("equipment_index_name", "--");
String prefix = null;
String suffix = null;
String iotCode = item.get("iot_code").toString();
if (iotCode.length() > 8) {
prefix = iotCode.substring(0, 8);
suffix = iotCode.substring(8);
} else {
throw new BadRequest("装备物联编码错误,请确认!");
}
String nowStrLong = DateUtils.getNowStrLong();
Date mounthDate = DateUtils.dateAddMonths(null, -1);
Date halfHour = DateUtils.dateAddMinutes(null, -30);
Date twoHour = DateUtils.dateAddHours(null, -2);
Date fourHour = DateUtils.dateAddHours(null, -3);
String startDateStr = DateUtils.convertDateToString(mounthDate, DateUtils.DATE_TIME_PATTERN);
String half = DateUtils.convertDateToString(halfHour, DateUtils.DATE_TIME_PATTERN);
String two = DateUtils.convertDateToString(twoHour, DateUtils.DATE_TIME_PATTERN);
String four = DateUtils.convertDateToString(fourHour, DateUtils.DATE_TIME_PATTERN);
ResponseModel mounthEntity = null;
ResponseModel halfHourEntity = null;
ResponseModel twoHourEntity = null;
ResponseModel fourHourEntity = null;
try {
mounthEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startDateStr, nowStrLong, prefix, suffix, "FHS_PressurePump_Start");
halfHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), half, nowStrLong, prefix, suffix, "FHS_PressurePump_Start");
twoHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), two, nowStrLong, prefix, suffix, "FHS_PressurePump_Start");
fourHourEntity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), four, nowStrLong, prefix, suffix, "FHS_PressurePump_Start");
} catch (Exception e) {
e.printStackTrace();
}
if (200 == mounthEntity.getStatus()) {
String json1 = JSON.toJSONString(mounthEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("FHS_PressurePump_Start") && t.get("FHS_PressurePump_Start").equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("monthStartNum", num);
} else if (200 == halfHourEntity.getStatus()) {
String json1 = JSON.toJSONString(halfHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("FHS_PressurePump_Start") && t.get("FHS_PressurePump_Start").equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("halfHourStartNum", num);
}else if (200 == twoHourEntity.getStatus()) {
String json1 = JSON.toJSONString(twoHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("FHS_PressurePump_Start") && t.get("FHS_PressurePump_Start").equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("twoHourStartNum", num);
} else if (200 == fourHourEntity.getStatus()) {
String json1 = JSON.toJSONString(fourHourEntity.getResult());
List<Map<String, String>> listObject1 = (List<Map<String, String>>) JSONArray.parse(json1);
List<Map<String, String>> collect = listObject1.stream().filter(t -> (t.containsKey("FHS_PressurePump_Start") && t.get("FHS_PressurePump_Start").equals("true"))).collect(Collectors.toList());
int num = collect.size();
item.put("fourHourStartNum", num);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long nowDateTime = new Date().getTime();//当前时间戳
Map<String, String> stateMap = fireFightingSystemMapper.queryPressureNowStateBySpecificId((Long) item.get("id"));
ids.add((Long) item.get("id"));
boolean time = false;
if (!ObjectUtils.isEmpty(stateMap) && stateMap.containsKey("update_date") && stateMap.containsKey("equipment_index_name")) {
item.put("update_time", String.valueOf(stateMap.get("update_date")).replaceAll("T", " "));
item.put("equipment_index_name", stateMap.get("equipment_index_name"));
if ("启动".equals(stateMap.get("equipment_index_name"))) {
long update_time = 0L;
try {
update_time = sdf.parse(String.valueOf(stateMap.get("update_date")).replaceAll("T", " ")).getTime();
} catch (ParseException e) {
throw new RuntimeException(e);
}
long res = nowDateTime - update_time;
long diffMinute = res / 1000 / 60;
if (diffMinute <= 5) {
time = true;
}
}
}
item.put("stateDesc", Integer.parseInt(String.valueOf(item.get("isAlarm"))) == 0 && time ? "正常" : "异常");
return item;
}).collect(Collectors.toList());
List<Map<String, Object>> stateMap = fireFightingSystemMapper.queryStartAndStopBySpecificId(ids);
long diffMinute = 0L;
if(!ObjectUtils.isEmpty(stateMap)){
List<Map<String, Object>> map = fireFightingSystemMapper.queryStateBySpecificId((long) stateMap.get(0).get("equipment_specific_id"));
String startTime = map.get(0).get("update_date").toString();
String endTime = map.get(1).get("update_date").toString();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long start =0L;
long end =0L;
try {
start = sdf.parse(startTime.replaceAll("T", " ")).getTime();
end = sdf.parse(endTime.replaceAll("T", " ")).getTime();
} catch (ParseException e) {
throw new RuntimeException(e);
}
long res = start - end;
diffMinute= res / 1000 / 60;
}
long finalDiffMinute = diffMinute;
pressurePumpInfo.getRecords().stream(
).map(item -> {
item.put("startAndStopInterval", finalDiffMinute);
return item;
}).collect(Collectors.toList());
return CommonResponseUtil.success(pressurePumpInfo);
}
}
......@@ -219,4 +219,8 @@ public interface EquipmentSpecificAlarmMapper extends BaseMapper<EquipmentSpecif
Map<String, Object> inspectionMessage(@Param("orgCode") String orgCode
, @Param("startTime") String startTime
, @Param("endTime") String endTime);
Page<Map<String, Object>> fireAlarmLogPage(Page page, @Param("param") CommonPageInfoParam param);
List<Map<String, Object>> alarmTrend(String bizOrgCode);
}
......@@ -584,4 +584,9 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE
List<Map<String, Object>> selectDayEchart(@Param("systemId") String systemId,
@Param("date") String date,
@Param("indicator") List<String> indicator);
List<Map<String, Object>> queryStartAndStopBySpecificId(@Param("ids")List<Long> ids);
List<Map<String, Object>> queryStateBySpecificId(@Param("id")long id);
}
......@@ -91,4 +91,8 @@ public interface IEquipmentSpecificAlarmService extends IService<EquipmentSpecif
List<Map<String, Object>> fireFacilitiesList(String bizOrgCode, String startTime, String endTime);
Map<String, Object> dailyMaintenance(String bizOrgCode,String orgCode, String startTime, String endTime);
Map<String, Object> inspectionMessage(String orgCode, String startTime, String endTime);
Page<Map<String, Object>> fireAlarmLogPage(CommonPageInfoParam param);
List<Map<String, Object>> alarmTrend(String bizOrgCode);
}
......@@ -728,4 +728,15 @@ public class EquipmentSpecificAlarmServiceImpl extends ServiceImpl<EquipmentSpec
public Map<String, Object> inspectionMessage(String orgCode, String startTime, String endTime) {
return equipmentSpecificAlarmMapper.inspectionMessage(orgCode, startTime, endTime);
}
@Override
public Page<Map<String, Object>> fireAlarmLogPage(CommonPageInfoParam param) {
Page result = new Page<>(param.getPageNumber(), param.getPageSize());
return this.baseMapper.fireAlarmLogPage(result, param);
}
@Override
public List<Map<String, Object>> alarmTrend(String bizOrgCode) {
return this.baseMapper.alarmTrend(bizOrgCode);
}
}
......@@ -1326,4 +1326,161 @@
LEFT JOIN p_point_classify ppc on pci.point_classify_id = ppc.id
)AS missedCheck
</select>
<select id="fireAlarmLogPage" resultType="java.util.HashMap">
SELECT
equipment_specific_index_name,
equipment_specific_name,
DATE_FORMAT(`wlesal`.`create_date`,'%m-%d %H:%i:%s') alarm_time,
location,
emergency_level_color,
IF
( `wlesal`.`clean_time` IS NOT NULL, '已消除', '未消除' ) AS `cleanStatus`
FROM
`wl_equipment_specific_alarm_log` `wlesal`
LEFT JOIN `wl_equipment_specific` `wles` ON `wlesal`.`equipment_specific_id` = `wles`.`id`
<where>
<if test="param.system != null and param.system != ''">
find_in_set( #{param.system}, `wlesal`.`system_codes` )
</if>
<if test="param.fireEquipmentSpecificIndexKey != null and param.fireEquipmentSpecificIndexKey != ''">
AND wles.equipment_specific_index_key like concat (#{param.fireEquipmentSpecificIndexKey},'%')
</if>
<if test="param.bizOrgCode != null and param.bizOrgCode != ''">
AND wles.biz_org_code like concat (#{param.bizOrgCode},'%')
</if>
</where>
ORDER BY
`wlesal`.`create_date` DESC
</select>
<select id="alarmTrend" resultType="java.util.Map">
SELECT
`result`.`click_date` AS `click_date`,
`a`.`fireAlarmNum` AS `fireAlarmNum`,
`b`.`breakdownNum` AS `breakdownNum`,
`c`.`shieldNum` AS `shieldNum`,
`d`.`otherNum` AS `otherNum`
FROM
((((
`v_monitor_event_utils_week` `result`
LEFT JOIN (
SELECT
`weekUtil`.`click_date` AS `click_date`,
ifnull( count( `fireAlarm`.`id` ), 0 ) AS `fireAlarmNum`
FROM
(
`v_monitor_event_utils_week` `weekUtil`
LEFT JOIN (
SELECT
log.*
FROM
`wl_equipment_specific_alarm_log` `log`
LEFT JOIN wl_equipment_specific wes ON `log`.equipment_specific_id = wes.id
<where>
<if test="bizOrgCode != null and bizOrgCode != ''">
wes.biz_org_code like concat (#{bizOrgCode},'%')
</if>
</where>
) fireAlarm ON (((
date_format( `fireAlarm`.`create_date`, '%Y-%m-%d' ) = `weekUtil`.`click_date`
)
AND ( `fireAlarm`.`equipment_specific_index_name` = '火警' )
)))
GROUP BY
`weekUtil`.`click_date`
ORDER BY
`weekUtil`.`click_date`
) `a` ON ((
`a`.`click_date` = `result`.`click_date`
)))
LEFT JOIN (
SELECT
`weekUtil`.`click_date` AS `click_date`,
ifnull( count( `breakdown`.`id` ), 0 ) AS `breakdownNum`
FROM
(
`v_monitor_event_utils_week` `weekUtil`
LEFT JOIN (
SELECT
log.*
FROM
`wl_equipment_specific_alarm_log` `log`
LEFT JOIN wl_equipment_specific wes ON `log`.equipment_specific_id = wes.id
<where>
<if test="bizOrgCode != null and bizOrgCode != ''">
wes.biz_org_code like concat (#{bizOrgCode},'%')
</if>
</where>
) `breakdown` ON (((
`weekUtil`.`click_date` = date_format( `breakdown`.`create_date`, '%Y-%m-%d' ))
AND ( `breakdown`.`equipment_specific_index_name` = '故障' ))))
GROUP BY
`weekUtil`.`click_date`
ORDER BY
`weekUtil`.`click_date`
) `b` ON ((
`b`.`click_date` = `result`.`click_date`
)))
LEFT JOIN (
SELECT
`weekUtil`.`click_date` AS `click_date`,
ifnull( count( `shield`.`id` ), 0 ) AS `shieldNum`
FROM
(
`v_monitor_event_utils_week` `weekUtil`
LEFT JOIN (
SELECT
log.*
FROM
`wl_equipment_specific_alarm_log` `log`
LEFT JOIN wl_equipment_specific wes ON `log`.equipment_specific_id = wes.id
<where>
<if test="bizOrgCode != null and bizOrgCode != ''">
wes.biz_org_code like concat (#{bizOrgCode},'%')
</if>
</where>
) `shield` ON (((
date_format( `shield`.`create_date`, '%Y-%m-%d' ) = `weekUtil`.`click_date`
)
AND ( `shield`.`equipment_specific_index_name` = '屏蔽' ))))
GROUP BY
`weekUtil`.`click_date`
ORDER BY
`weekUtil`.`click_date`
) `c` ON ((
`c`.`click_date` = `result`.`click_date`
)))
LEFT JOIN (
SELECT
`weekUtil`.`click_date` AS `click_date`,
ifnull( count( `other`.`id` ), 0 ) AS `otherNum`
FROM
(
`v_monitor_event_utils_week` `weekUtil`
LEFT JOIN (
SELECT
log.*
FROM
`wl_equipment_specific_alarm_log` `log`
LEFT JOIN wl_equipment_specific wes ON `log`.equipment_specific_id = wes.id
<where>
<if test="bizOrgCode != null and bizOrgCode != ''">
wes.biz_org_code like concat (#{bizOrgCode},'%')
</if>
</where>
) `other` ON (((
date_format( `other`.`create_date`, '%Y-%m-%d' ) = `weekUtil`.`click_date`
)
AND (
`other`.`equipment_specific_index_name` NOT IN ( '火警', '故障', '屏蔽' )))))
GROUP BY
`weekUtil`.`click_date`
ORDER BY
`weekUtil`.`click_date`
) `d` ON ((
`d`.`click_date` = `result`.`click_date`
)))
ORDER BY
`result`.`click_date` DESC
</select>
</mapper>
\ No newline at end of file
......@@ -4711,4 +4711,34 @@
WHERE FIND_IN_SET( #{id}, system_id ) > 0
AND biz_org_code LIKE concat(#{bizOrgCode}, '%') )
</select>
<select id="queryStartAndStopBySpecificId" resultType="java.util.Map">
SELECT
i.equipment_specific_id,
i.update_date,
i.equipment_index_name
FROM
wl_equipment_specific_index i
WHERE
<if test="ids != null and ids.size > 0">
i.equipment_specific_id IN
<foreach collection="ids" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
AND i.equipment_index_key in ('FHS_PressurePump_Start', 'FHS_PressurePump_Stop')
ORDER BY
i.update_date DESC
</select>
<select id="queryStateBySpecificId" resultType="java.util.Map">
SELECT
i.update_date,
i.equipment_index_name
FROM
wl_equipment_specific_index i
WHERE
i.equipment_specific_id = #{id,jdbcType=VARCHAR}
AND i.equipment_index_key in ('FHS_PressurePump_Start', 'FHS_PressurePump_Stop')
ORDER BY
i.update_date DESC
</select>
</mapper>
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