Commit 493f20ae authored by suhuiguang's avatar suhuiguang

1.分析报告优化

parent d1b08819
package com.yeejoin.equipmanage.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 设备告警月统计
*
* @author system_generator
* @date 2022-01-16
*/
@Data
@Accessors(chain = true)
@TableName("wl_analysis_report_month")
public class AnalysisReportMonth {
private static final long serialVersionUID = 1L;
/**
* 系统id
*/
@TableField("system_id")
private Long systemId;
/**
* 总数量
*/
@TableField("num")
private Integer num;
/**
* 装备定义编码
*/
@TableField("equipment_code")
private String equipmentCode;
/**
*
*/
@TableField("equipment_name")
private String equipmentName;
/**
* 报告所在年月
*/
@TableField("report_month")
private String reportMonth;
/**
* 故障设备数量
*/
@TableField("fault_equip_num")
private Integer faultEquipNum;
/**
* 故障信息条数
*/
@TableField("fault_info_num")
private Integer faultInfoNum;
/**
* 告警设备数量
*/
@TableField("alarm_equip_num")
private Integer alarmEquipNum;
/**
* 告警信息条数
*/
@TableField("alarm_info_num")
private Integer alarmInfoNum;
/**
* 总信息数量
*/
@TableField("total_info_num")
private Integer totalInfoNum;
/**
* 创建时间
*/
@TableField("create_date")
private Date createDate;
}
package com.yeejoin.equipmanage.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
/**
* 总结报告
*
* @author system_generator
* @date 2022-01-16
*/
@Data
@Accessors(chain = true)
@TableName("wl_analysis_report_summary")
public class AnalysisReportSummary {
private static final long serialVersionUID = 1L;
/**
* 系统id
*/
@TableField("system_id")
private Long systemId;
/**
* 系统名称
*/
@TableField("system_name")
private String systemName;
/**
* 报告类型
*/
@TableField("report_type")
private String reportType;
/**
* 报告日期
*/
@TableField("report_date")
private Date reportDate;
/**
* 总结信息
*/
@TableField("summary_info")
private String summaryInfo;
/**
* 创建时间
*/
@TableField("create_date")
private Date createDate;
}
......@@ -122,4 +122,7 @@ public class FireFightingSystemEntity {
@ApiModelProperty("系统类型编码")
private String systemTypeCode;
@ApiModelProperty(value = "分析报告统计用参数(为空不统计) ")
private String analysisIndexKey;
}
package com.yeejoin.equipmanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.equipmanage.common.entity.AnalysisReportMonth;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 设备告警月统计 Mapper 接口
*
* @author system_generator
* @date 2022-01-16
*/
public interface AnalysisReportMonthMapper extends BaseMapper<AnalysisReportMonth> {
/**
* 插入月分析列表数据
* @param suffix 指标信息
* @param beginDate 开始日期
* @param endDate 结束日期
* @param systemId 系统id
*/
void insertSystemMonthData(@Param("indexKeySuffix") List<String> suffix, @Param("beginDate") String beginDate, @Param("endDate") String endDate, @Param("systemId") Long systemId);
}
package com.yeejoin.equipmanage.mapper;
import com.yeejoin.equipmanage.common.entity.AnalysisReportSummary;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 总结报告 Mapper 接口
*
* @author system_generator
* @date 2022-01-16
*/
public interface AnalysisReportSummaryMapper extends BaseMapper<AnalysisReportSummary> {
/**
* 插入月总结信息
* @param suffix 指标参数
* @param beginDate 开始日期
* @param endDate 结束日期
* @param systemId 系统id
*/
void insertSystemMonthSummaryData(@Param("indexKeySuffix") List<String> suffix, @Param("beginDate") String beginDate, @Param("endDate") String endDate, @Param("systemId") Long systemId);
}
......@@ -50,6 +50,6 @@ public class AnalysisReportSchedulerJob {
Date yestDay = DateUtils.dateAdd(new Date(),-1,false);
Date beginDate = DateUtils.getFirstDayOfMonth(yestDay);
Date endDate = DateUtils.getLastDayOfMonth(yestDay);
iAnalysisReportLogService.generateReport(AnalysisReportEnum.MONTH_REPORT,beginDate,endDate);
iAnalysisReportLogService.generateMonthReport(AnalysisReportEnum.MONTH_REPORT,beginDate,endDate);
}
}
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.yeejoin.equipmanage.common.entity.AnalysisReportLog;
import com.yeejoin.equipmanage.common.enums.AnalysisReportEnum;
import java.text.ParseException;
import java.util.Date;
/**
......@@ -27,4 +28,11 @@ public interface IAnalysisReportLogService extends IService<AnalysisReportLog> {
* @param endDate 结束日期
*/
void generateReport(AnalysisReportEnum reportEnum, Date beginDate, Date endDate);
/** 月报表生成
* @param monthReport 报告类型
* @param beginDate 开始日期
* @param endDate 结束日期
*/
void generateMonthReport(AnalysisReportEnum monthReport, Date beginDate, Date endDate) throws ParseException;
}
......@@ -5,14 +5,21 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.equipmanage.common.entity.AnalysisReportLog;
import com.yeejoin.equipmanage.common.entity.FireFightingSystemEntity;
import com.yeejoin.equipmanage.common.entity.publics.BaseEntity;
import com.yeejoin.equipmanage.common.enums.AnalysisReportEnum;
import com.yeejoin.equipmanage.common.utils.DateUtils;
import com.yeejoin.equipmanage.mapper.AnalysisReportLogMapper;
import com.yeejoin.equipmanage.mapper.AnalysisReportMonthMapper;
import com.yeejoin.equipmanage.mapper.AnalysisReportSummaryMapper;
import com.yeejoin.equipmanage.service.IAnalysisReportLogService;
import com.yeejoin.equipmanage.service.IFireFightingSystemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Calendar;
import java.util.Date;
import java.text.ParseException;
import java.util.*;
/**
* 报告流水表 服务实现类
......@@ -23,6 +30,16 @@ import java.util.Date;
@Service
public class AnalysisReportLogServiceImpl extends ServiceImpl<AnalysisReportLogMapper, AnalysisReportLog> implements IAnalysisReportLogService {
@Autowired
IFireFightingSystemService fireFightingSystemService;
@Autowired
AnalysisReportMonthMapper analysisReportMonthMapper;
@Autowired
AnalysisReportSummaryMapper analysisReportSummaryMapper;
@Override
public IPage<AnalysisReportLog> listPage(Page page, AnalysisReportLog analysisReportLog) {
......@@ -39,12 +56,35 @@ public class AnalysisReportLogServiceImpl extends ServiceImpl<AnalysisReportLogM
@Override
public void generateReport(AnalysisReportEnum reportEnum, Date beginDate, Date endDate) {
this.saveAnalysisReportLog(reportEnum, beginDate, endDate);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void generateMonthReport(AnalysisReportEnum reportEnum, Date beginDate, Date endDate) throws ParseException {
// 0.保存日志
this.saveAnalysisReportLog(reportEnum, beginDate, endDate);
// 创建月分析统计报告数据
// 1、 查询消防系统表,捞出所有系统,新增字段,存放自定义用的告警指标模糊查询指标key,逗号分隔
List<FireFightingSystemEntity> fightingSystemEntityList = fireFightingSystemService.getBaseMapper().selectList(
new LambdaQueryWrapper<FireFightingSystemEntity>()
.isNotNull(FireFightingSystemEntity::getAnalysisIndexKey));
// 2、循环插入 wl_analysis_report_month、wl_analysis_report_summary
String beginDateStr = DateUtils.dateFormat(beginDate,DateUtils.DATE_PATTERN);
String endDateStr = DateUtils.dateFormat(endDate,DateUtils.DATE_PATTERN);
fightingSystemEntityList.forEach(f -> {
analysisReportMonthMapper.insertSystemMonthData(new ArrayList<>(Arrays.asList(f.getAnalysisIndexKey().split(","))), beginDateStr, endDateStr, f.getId());
analysisReportSummaryMapper.insertSystemMonthSummaryData(new ArrayList<>(Arrays.asList(f.getAnalysisIndexKey().split(","))), beginDateStr, endDateStr, f.getId());
});
}
private void saveAnalysisReportLog(AnalysisReportEnum reportEnum, Date beginDate, Date endDate) {
AnalysisReportLog reportLog = new AnalysisReportLog();
reportLog.setName(reportEnum.getName());
reportLog.setReportType(reportEnum.getType());
reportLog.setStartDate(beginDate);
reportLog.setEndDate(endDate);
reportLog.setReportDateDesc(buildReportDateDesc(reportEnum,beginDate,endDate));
reportLog.setReportDateDesc(buildReportDateDesc(reportEnum, beginDate, endDate));
this.save(reportLog);
}
......@@ -52,7 +92,7 @@ public class AnalysisReportLogServiceImpl extends ServiceImpl<AnalysisReportLogM
StringBuilder desc = new StringBuilder();
Calendar calendar = Calendar.getInstance();
calendar.setTime(beginDate);
switch (reportEnum){
switch (reportEnum) {
case DAY_REPORT:
desc.append(calendar.get(Calendar.YEAR));
desc.append("年");
......
......@@ -2071,4 +2071,73 @@
ALTER TABLE wl_equipment ADD COLUMN clean_type varchar(50) DEFAULT NULL COMMENT '警情消除方式(0:收到复位信号自动消除;1:警情处理确认后消除)';
</sql>
</changeSet>
<changeSet author="suhuiguang" id="1642465149617-1">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="wl_analysis_report_month"/>
</not>
</preConditions>
<comment>create table wl_analysis_report_month 分析报告用</comment>
<sql>
CREATE TABLE `wl_analysis_report_month` (
`system_id` bigint DEFAULT NULL COMMENT '系统id',
`num` int DEFAULT NULL COMMENT '总数量',
`equipment_code` varchar(255) DEFAULT NULL COMMENT '装备定义编码',
`equipment_name` varchar(255) DEFAULT NULL,
`report_month` varchar(255) DEFAULT NULL COMMENT '报告所在年月',
`fault_equip_num` int DEFAULT NULL COMMENT '故障设备数量',
`fault_info_num` int DEFAULT NULL COMMENT '故障信息条数',
`alarm_equip_num` int DEFAULT NULL COMMENT '告警设备数量',
`alarm_info_num` int DEFAULT NULL COMMENT '告警信息条数',
`total_info_num` int DEFAULT NULL COMMENT '总信息数量',
`create_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
UNIQUE KEY `uk_system_id_report_month_equipment_code` (`system_id`,`equipment_code`,`report_month`) USING BTREE,
KEY `idx_report_month` (`report_month`) USING BTREE
) ENGINE=InnoDB COMMENT='设备告警月统计';
</sql>
</changeSet>
<changeSet author="suhuiguang" id="1642465149617-2">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="wl_analysis_report_summary"/>
</not>
</preConditions>
<comment>create table wl_analysis_report_summary 分析报告用</comment>
<sql>
CREATE TABLE `wl_analysis_report_summary` (
`system_id` bigint DEFAULT NULL COMMENT '系统id',
`system_name` varchar(255) DEFAULT NULL COMMENT '系统名称',
`report_type` varchar(255) DEFAULT NULL COMMENT '报告类型',
`report_date` date DEFAULT NULL COMMENT '报告日期',
`summary_info` varchar(500) DEFAULT NULL COMMENT '总结信息',
`create_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
UNIQUE KEY `uk_system_id_report_type_report_date` (`system_id`,`report_type`,`report_date`),
KEY `idx_systemid_report_type` (`system_id`,`report_type`) USING BTREE
) ENGINE=InnoDB COMMENT='总结报告';
</sql>
</changeSet>
<changeSet author="suhuiguang" id="1642465149617-3">
<preConditions onFail="MARK_RAN">
<not>
<columnExists tableName="f_fire_fighting_system" columnName="analysis_index_key"/>
</not>
</preConditions>
<comment>f_fire_fighting_system add column analysis_index_key 分析报告用</comment>
<sql>
ALTER TABLE f_fire_fighting_system ADD COLUMN `analysis_index_key` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '分析报告统计用参数(为空不统计)';
</sql>
</changeSet>
<changeSet author="suhuiguang" id="1642465149617-4">
<preConditions onFail="MARK_RAN">
<columnExists tableName="f_fire_fighting_system" columnName="analysis_index_key"/>
</preConditions>
<comment>f_fire_fighting_system 更新 analysis_index_key 分析报告统计用</comment>
<sql>
UPDATE `f_fire_fighting_system` SET `analysis_index_key`='Fault,Open,OilLeak' WHERE (`code`='029026401813010000000030');
UPDATE `f_fire_fighting_system` SET `analysis_index_key`='FireAlarm,Fault,Shield' WHERE (`code`='029026401813010000000016');
UPDATE `f_fire_fighting_system` SET `analysis_index_key`='Fault,Alarm,Abnormal' WHERE (`code`='029026401813010000000023');
UPDATE `f_fire_fighting_system` SET `analysis_index_key`='Fault,Shield,FireAlarm' WHERE (`code`='029026401813010000000047');
UPDATE `f_fire_fighting_system` SET `analysis_index_key`='FireAlarm,Fault,Shield,State' WHERE (`code`='029026401813010000000054');
</sql>
</changeSet>
</databaseChangeLog>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.equipmanage.mapper.AnalysisReportMonthMapper">
<insert id="insertSystemMonthData">
insert into wl_analysis_report_month
(
system_id,
num,
equipment_name,
equipment_code,
fault_equip_num,
fault_info_num,
alarm_equip_num,
alarm_info_num,
total_info_num,
report_month
)
select
a1.*,
DATE_FORMAT(NOW(),'%Y-%m')
from
(SELECT
system_id,
num,
name,
code,
(SELECT
count(distinct equipment_specific_id)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
and report.index_true_num >0
and report.index_type LIKE CONCAT('%','Fault')
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as faultEquipNum,
(SELECT IFNULL(sum(report.index_true_num),0)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
and report.index_type LIKE CONCAT('%','Fault')
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as faultInfoNum,
(SELECT count(distinct equipment_specific_id)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
and report.index_true_num >0
<if test="indexKeySuffix.size() > 0">
and
<foreach collection="indexKeySuffix" item="keySuffix" open="(" close=")" separator="or">
report.index_type LIKE CONCAT('%',#{keySuffix})
</foreach>
</if>
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as alarmEquipNum,
(SELECT IFNULL(sum(report.index_true_num),0)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
<if test="indexKeySuffix.size() > 0">
and
<foreach collection="indexKeySuffix" item="keySuffix" open="(" close=")" separator="or">
report.index_type LIKE CONCAT('%',#{keySuffix})
</foreach>
</if>
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as alarmInfoNum,
(SELECT IFNULL(sum(report.index_true_num),0)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as totalInfoNum
FROM(
SELECT
s.id as system_id,
equipment.code,
equipment.name,
count(1) AS num
FROM
wl_equipment_specific spec
LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
where spec.system_id <![CDATA[<>]]> '' and s.id = #{systemId}
GROUP BY equipment.code,s.id, equipment.name ORDER BY system_id, code
) a) as a1
</insert>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.equipmanage.mapper.AnalysisReportSummaryMapper">
<insert id="insertSystemMonthSummaryData">
insert into
wl_analysis_report_summary (
system_id,
summary_info,
system_name,
report_type,
report_date
)
select
s.id,
CONCAT(s.name,',',#{beginDate},' - ',#{endDate} ,':',CHAR(10),
CONCAT('正常设备',IFNULL(f1.totalNormalEquipNum,0),'台,','正常率:',concat(IFNULL(f1.normalEquipNumPercent,0)*100,'%'),',',
'同比上月',IF(IFNULL(f1.totalNormalEquipNum,0)- IFNULL(f1.lastMonthTotalNormalEquipNum,0) >0 ,'增加','减少'),
if(IFNULL(f1.lastMonthTotalNormalEquipNum,0) = 0 ,'---',CONCAT(round(IFNULL(f1.totalNormalEquipNum,0)/f1.lastMonthTotalNormalEquipNum -1,2)* 100,'%')),',',CHAR(10)),
CONCAT('故障设备',IFNULL(f1.totalFaultEquipNum,0),'台,','故障率:',concat(ROUND(IFNULL(f1.faultEquipPercent,0),2)*100,'%'),',',
'同比上月',IF(IFNULL(f1.totalFaultEquipNum,0)- IFNULL(f1.lastMonthTotalFaultEquipNum,0) >0 ,'增加','减少'),
if(IFNULL(f1.lastMonthTotalFaultEquipNum,0) = 0 ,'---',CONCAT(round(IFNULL(f1.totalFaultEquipNum,0)/f1.lastMonthTotalFaultEquipNum -1,2)* 100,'%')),',',CHAR(10)),
CONCAT('告警设备',IFNULL(f1.totalAlarmEquipNum,0),'台,',
'同比上月',IF(IFNULL(f1.totalAlarmEquipNum,0)- IFNULL(f1.lastMonthTotalAlarmEquipNum,0) >0 ,'增加','减少'),
if(IFNULL(f1.lastMonthTotalAlarmEquipNum,0) = 0 ,'---',CONCAT(round(IFNULL(f1.totalAlarmEquipNum,0)/f1.lastMonthTotalAlarmEquipNum -1,2)* 100,'%')),',',CHAR(10)),
CONCAT('告警总数',IFNULL(f1.totalAlarmInfoNum,0),'条,',
'同比上月',IF(IFNULL(f1.totalAlarmInfoNum,0)- IFNULL(f1.lastMonthTotalAlarmInfoNum,0) >0 ,'增加','减少'),
if(IFNULL(f1.lastMonthTotalAlarmInfoNum,0) = 0 ,'---', CONCAT(round(IFNULL(f1.totalAlarmInfoNum,0)/f1.lastMonthTotalAlarmInfoNum -1,2)* 100,'%'))
,'。')) as content,
s.`name`,
3 as report_type,
#{endDate} as report_date
from
f_fire_fighting_system s
LEFT JOIN
(select
s1.*,
IFNULL(s2.totalAlarmEquipNum,0) as lastMonthTotalAlarmEquipNum,
IFNULL(s2.totalAlarmInfoNum,0) as lastMonthTotalAlarmInfoNum,
IFNULL(s2.totalNormalEquipNum,0) as lastMonthTotalNormalEquipNum,
IFNULL(s2.totalEquipNum,0) as lastMonthTotalEquipNum,
IFNULL(s2.totalFaultEquipNum,0) as lastMonthTotalFaultEquipNum
from
(SELECT
u1.system_id,
IFNULL(sum(num),0) as totalEquipNum,
IFNULL(sum(normalEquipNum),0) as totalNormalEquipNum,
IFNULL(sum(faultEquipNum),0) as totalFaultEquipNum,
IFNULL(sum(alarmEquipNum),0) as totalAlarmEquipNum,
IFNULL(sum(alarmInfoNum),0) as totalAlarmInfoNum,
if(sum(num) > 0,ROUND(sum(normalEquipNum)/sum(num),2), '-') as normalEquipNumPercent,
if(sum(num) > 0,ROUND(sum(faultEquipNum)/sum(num),2), '-') as faultEquipPercent
from
(select
a1.*,
(a1.num - a1.alarmEquipNum) as normalEquipNum
from
(SELECT
system_id,
num,
name,
code,
(SELECT count(distinct equipment_specific_id)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
and report.index_true_num >0
and report.index_type LIKE CONCAT('%','Fault')
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as faultEquipNum,
(SELECT count(distinct equipment_specific_id)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
<if test="indexKeySuffix.size() > 0">
and
<foreach collection="indexKeySuffix" item="keySuffix" open="(" close=")" separator="or">
report.index_type LIKE CONCAT('%',#{keySuffix})
</foreach>
</if>
and report.index_true_num >0
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as alarmEquipNum,
(SELECT IFNULL(sum(report.index_true_num),0)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
<if test="indexKeySuffix.size() > 0">
and
<foreach collection="indexKeySuffix" item="keySuffix" open="(" close=")" separator="or">
report.index_type LIKE CONCAT('%',#{keySuffix})
</foreach>
</if>
and report.report_date >= #{beginDate}
and report.report_date <![CDATA[<=]]> #{endDate}
) as alarmInfoNum
FROM
(
SELECT
s.id as system_id,
equipment.code,
equipment.name,
count(1) AS num
FROM
wl_equipment_specific spec
LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
where spec.system_id <![CDATA[<>]]> ''
GROUP BY equipment.code,s.id, equipment.name ORDER BY system_id, code
) a) as a1) u1
GROUP BY u1.system_id) s1
LEFT JOIN
(SELECT
u1.system_id,
sum(num) as totalEquipNum,
sum(normalEquipNum) as totalNormalEquipNum,
sum(faultEquipNum) as totalFaultEquipNum,
sum(alarmEquipNum) as totalAlarmEquipNum,
sum(alarmInfoNum) as totalAlarmInfoNum
from
(select
a1.*,
(a1.num - a1.alarmEquipNum) as normalEquipNum
from
(SELECT
system_id,
num,
name,
code,
(SELECT count(distinct equipment_specific_id)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
and report.index_type LIKE CONCAT('%','Fault')
and report.index_true_num >0
and report.report_date >= DATE_SUB(#{beginDate},INTERVAL 1 MONTH)
and report.report_date <![CDATA[<=]]> DATE_SUB(#{endDate},INTERVAL 1 MONTH)
) as faultEquipNum,
(SELECT count(distinct equipment_specific_id)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
<if test="indexKeySuffix.size() > 0">
and
<foreach collection="indexKeySuffix" item="keySuffix" open="(" close=")" separator="or">
report.index_type LIKE CONCAT('%',#{keySuffix})
</foreach>
</if>
and report.index_true_num >0
and report.report_date >= DATE_SUB(#{beginDate},INTERVAL 1 MONTH)
and report.report_date <![CDATA[<=]]> DATE_SUB(#{endDate},INTERVAL 1 MONTH)
) as alarmEquipNum,
(SELECT IFNULL(sum(report.index_true_num),0)
FROM wl_equipment_alarm_report_day report
where report.equipment_code = a.code and FIND_IN_SET(a.system_id,report.system_ids)
<if test="indexKeySuffix.size() > 0">
and
<foreach collection="indexKeySuffix" item="keySuffix" open="(" close=")" separator="or">
report.index_type LIKE CONCAT('%',#{keySuffix})
</foreach>
</if>
and report.report_date >= DATE_SUB(#{beginDate},INTERVAL 1 MONTH)
and report.report_date<![CDATA[<=]]> DATE_SUB(#{endDate},INTERVAL 1 MONTH)
) as alarmInfoNum
FROM
(
SELECT
s.id as system_id,
equipment.code,
equipment.name,
count(1) AS num
FROM
wl_equipment_specific spec
LEFT JOIN wl_equipment_detail detail ON spec.equipment_detail_id = detail.id
LEFT JOIN wl_equipment equipment ON equipment.id =detail.equipment_id
left join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
where
spec.system_id <![CDATA[<>]]> ''
GROUP BY equipment.code,s.id, equipment.name ORDER BY system_id, code
) a) as a1) u1
GROUP BY u1.system_id) s2 ON s1.system_id = s2.system_id
) f1 on s.id = f1.system_id
where s.id = #{systemId}
</insert>
</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