Commit 70b9db5f authored by lisong's avatar lisong

添加物联报表-周分析报表接口

parent 8d224df6
...@@ -14,7 +14,10 @@ public enum WordTemplateTypeEum { ...@@ -14,7 +14,10 @@ public enum WordTemplateTypeEum {
firePatrolReport("消防巡查报表","FirePatrolReport.ftl"), firePatrolReport("消防巡查报表","FirePatrolReport.ftl"),
fireAutoSysManageReport("消防自动化综合管理报表","fireAutoSysManageReport.ftl"), fireAutoSysManageReport("消防自动化综合管理报表","fireAutoSysManageReport.ftl"),
iotMonthReport("物联报表-月分析报表","iotMonthReport.ftl"); iotMonthReport("物联报表-月分析报表","iotMonthReport.ftl"),
iotWeekReport("物联报表-周分析报表","iotWeekReport.ftl");
......
...@@ -133,7 +133,7 @@ public class ChartsUtils { ...@@ -133,7 +133,7 @@ public class ChartsUtils {
} }
} }
public static String manyLineChart(List<Map<String, Object>> value) { public static String manyLineChart(List<Map<String, Object>> value, String title, String xtitle, String ytitle) {
// 绘图数据集 // 绘图数据集
DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
...@@ -142,7 +142,7 @@ public class ChartsUtils { ...@@ -142,7 +142,7 @@ public class ChartsUtils {
} }
JFreeChart chart = createManyLineChart(dataSet); JFreeChart chart = createManyLineChart(dataSet, title, xtitle, ytitle);
BufferedImage image = chart.createBufferedImage(1000, 800); BufferedImage image = chart.createBufferedImage(1000, 800);
byte[] bytes = null; byte[] bytes = null;
...@@ -161,16 +161,16 @@ public class ChartsUtils { ...@@ -161,16 +161,16 @@ public class ChartsUtils {
* *
* @return * @return
*/ */
public static JFreeChart createManyLineChart(DefaultCategoryDataset dataSet) { public static JFreeChart createManyLineChart(DefaultCategoryDataset dataSet, String title, String xtitle, String ytitle) {
//如果把createLineChart改为createLineChart3D就变为了3D效果的折线图 //如果把createLineChart改为createLineChart3D就变为了3D效果的折线图
JFreeChart chart = ChartFactory.createLineChart("月报警信息", "日期", "告警数量", dataSet, JFreeChart chart = ChartFactory.createLineChart(title, xtitle, ytitle, dataSet,
PlotOrientation.VERTICAL, // 绘制方向 PlotOrientation.VERTICAL, // 绘制方向
true, // 显示图例 true, // 显示图例
true, // 采用标准生成器 true, // 采用标准生成器
false // 是否生成超链接 false // 是否生成超链接
); );
//如 果不使用Font,中文将显示不出来 //如 果不使用Font,中文将显示不出来
Font font = new Font("新宋体", Font.BOLD, 10); Font font = new Font("新宋体", Font.BOLD, 18);
chart.getTitle().setFont(font); // 设置标题字体 chart.getTitle().setFont(font); // 设置标题字体
chart.getLegend().setItemFont(font);// 设置图例类别字体 chart.getLegend().setItemFont(font);// 设置图例类别字体
......
...@@ -480,5 +480,28 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE ...@@ -480,5 +480,28 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE
List<Map<String, Object>> selectMonthPolyline(@Param("systemCode") String sysCode, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("indicator") List<String> indicator); List<Map<String, Object>> selectMonthPolyline(@Param("systemCode") String sysCode, @Param("startDate") String startDate, @Param("endDate") String endDate, @Param("indicator") List<String> indicator);
List<Map<String, Object>> selectWeekReportList(@Param("systemId") String systemId,@Param("startDate") String startDate, @Param("endDate") String endDate, @Param("indicator") List<String> indicator);
Integer selectAlarms(@Param("systemId") String systemId,
@Param("indexType") String indexType,
@Param("equipmentCode") String equipmentCode,
@Param("startDate") String startDate,
@Param("endDate") String endDate,
@Param("indicator") List<String> indicator);
Map<String, Object> selectWeekSummarize(@Param("systemId") String systemId,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
List<Map<String, Object>> selectWeekEquipEchart(@Param("systemCode") String systemCode,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
List<Map<String, Object>> selectWeekEchart(@Param("systemCode") String systemCode,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
List<Map<String, Object>> selectWeekLinesEchart(@Param("systemCode") String systemCode,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
} }
...@@ -276,4 +276,7 @@ public interface IFireFightingSystemService extends IService<FireFightingSystemE ...@@ -276,4 +276,7 @@ public interface IFireFightingSystemService extends IService<FireFightingSystemE
String iotMonthReport(String bizOrgCode, String startDate, String endDate); String iotMonthReport(String bizOrgCode, String startDate, String endDate);
String iotWeekReport(String bizOrgCode, String startDate, String endDate);
} }
...@@ -1469,8 +1469,14 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste ...@@ -1469,8 +1469,14 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
// 系统循环数据填充 // 系统循环数据填充
ArrayList<Map<String, Object>> systemList = new ArrayList<>(); ArrayList<Map<String, Object>> systemList = new ArrayList<>();
if (!CollectionUtils.isEmpty(system)) { if (!CollectionUtils.isEmpty(system)) {
map.put("station", "锦屏"); // 换流站信息
map.put("time", "2022-07"); if (!ObjectUtils.isEmpty(system.get(0).get("stationName"))){
map.put("station", system.get(0).get("stationName"));
}else {
map.put("station", "");
}
map.put("time", startDate+"-"+endDate);
// 单个系统数据 // 单个系统数据
for (Map<String, Object> sys : system) { for (Map<String, Object> sys : system) {
HashMap<String, Object> systemData = new HashMap<>(); HashMap<String, Object> systemData = new HashMap<>();
...@@ -1563,7 +1569,7 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste ...@@ -1563,7 +1569,7 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
if (!CollectionUtils.isEmpty(selectMonthPolyline)) { if (!CollectionUtils.isEmpty(selectMonthPolyline)) {
String pieChart2 = ChartsUtils.manyLineChart(selectMonthPolyline); String pieChart2 = ChartsUtils.manyLineChart(selectMonthPolyline, "月告警信息", "日期", "告警数量");
systemData.put("bing3", pieChart2); systemData.put("bing3", pieChart2);
} else { } else {
systemData.put("bing3", ""); systemData.put("bing3", "");
...@@ -1622,4 +1628,148 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste ...@@ -1622,4 +1628,148 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
return pdfUrlString; return pdfUrlString;
} }
private Map<String, Object> getWeekData(String bizOrgCode, String startDate, String endDate) {
Map<String, Object> map = new HashMap<>();
// 查询该站信息以及所有系统
List<Map<String, Object>> systemList = fireFightingSystemMapper.selectSystemByBizOrgCode(bizOrgCode);
String json = null;
try {
json = IOUtils.toString(systemIndex.getInputStream(), java.lang.String.valueOf(StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
// 系统对应指标配置
List<Map> indicatorConfiguration = JSONObject.parseArray(json, Map.class);
// 一周内所有系统情况
if (!CollectionUtils.isEmpty(systemList)) {
// 换流站信息
if (!ObjectUtils.isEmpty(systemList.get(0).get("stationName"))) {
map.put("station", systemList.get(0).get("stationName"));
} else {
map.put("station", "");
}
map.put("time", startDate + "-" + endDate);
// 系统循环数据填充
ArrayList<Map<String, Object>> dataList = new ArrayList<>();
for (Map<String, Object> system : systemList) {
HashMap<String, Object> systemData = new HashMap<>();
List<Map> collect = indicatorConfiguration.stream().
filter(item -> item.get("code").equals(String.valueOf(system.get("typeCode")))).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(collect)) {
// 系统名称
systemData.put("systemName", ObjectUtils.isEmpty(system.get("name")) ? "" : String.valueOf(system.get("name")));
// 系统对应指标
String indicator = String.valueOf(collect.get(0).get("index"));
String[] split = indicator.split(",");
List<String> indicatorList = Arrays.asList(split);
List<Map<String, Object>> weekReportList = fireFightingSystemMapper.selectWeekReportList(String.valueOf(system.get("id")), startDate, endDate, indicatorList);
ArrayList<Map<String, Object>> list = new ArrayList<>();
if (!CollectionUtils.isEmpty(weekReportList)) {
for (Map<String, Object> weekItem : weekReportList) {
HashMap<String, Object> listItem = new HashMap<>();
// 设备类型
listItem.put("name", ObjectUtils.isEmpty(weekItem.get("name")) ? "" : String.valueOf(weekItem.get("name")));
// 设备总数
listItem.put("num", ObjectUtils.isEmpty(weekItem.get("num")) ? "" : String.valueOf(weekItem.get("num")));
// 无异常设备总数
listItem.put("normalNum", ObjectUtils.isEmpty(weekItem.get("normalNum")) ? "" : String.valueOf(weekItem.get("normalNum")));
// 物联指标
listItem.put("type_name", ObjectUtils.isEmpty(weekItem.get("type_name")) ? "" : String.valueOf(weekItem.get("type_name")));
// 监测数据
listItem.put("monitoringData", ObjectUtils.isEmpty(weekItem.get("monitoringData")) ? "" : String.valueOf(weekItem.get("monitoringData")));
// 获取方式
listItem.put("acquisition", ObjectUtils.isEmpty(weekItem.get("acquisition")) ? "" : String.valueOf(weekItem.get("acquisition")));
// 正常标准
listItem.put("normal", ObjectUtils.isEmpty(weekItem.get("normal")) ? "" : String.valueOf(weekItem.get("normal")));
// 7日告警设备数
listItem.put("alarmEquipNum", ObjectUtils.isEmpty(weekItem.get("alarmEquipNum")) ? "" : String.valueOf(weekItem.get("alarmEquipNum")));
// 7日告警条数
if (!ObjectUtils.isEmpty(weekItem.get("type_code")) && !ObjectUtils.isEmpty(weekItem.get("code"))) {
Integer integer = fireFightingSystemMapper.selectAlarms(valueOf(system.get("id")), valueOf(weekItem.get("type_code")), valueOf(weekItem.get("code")), startDate, endDate, indicatorList);
listItem.put("trueNum", String.valueOf(integer));
} else {
listItem.put("trueNum", String.valueOf(0));
}
list.add(listItem);
}
} else {
HashMap<String, Object> listItem = new HashMap<>();
listItem.put("name", "");
listItem.put("num", "");
listItem.put("normalNum", "");
listItem.put("type_name", "");
listItem.put("monitoringData", "");
listItem.put("acquisition", "");
listItem.put("normal", "");
listItem.put("alarmEquipNum", "");
listItem.put("trueNum", "");
list.add(listItem);
}
// 总结
Map<String, Object> summarize = fireFightingSystemMapper.selectWeekSummarize(valueOf(system.get("id")), startDate, endDate);
if (!ObjectUtils.isEmpty(summarize.get("contant"))) {
systemData.put("summarize", String.valueOf(summarize.get("contant")));
} else {
systemData.put("summarize", "");
}
// echarts 图表
List<Map<String, Object>> mapList = fireFightingSystemMapper.selectWeekEquipEchart(valueOf(system.get("code")), startDate, endDate);
String pieChart1 = ChartsUtils.pieChart(mapList, "告警类别统计");
systemData.put("pictureLeft", pieChart1);
List<Map<String, Object>> weekEchart = fireFightingSystemMapper.selectWeekEchart(valueOf(system.get("code")), startDate, endDate);
String pieChart2 = ChartsUtils.pieChart(weekEchart, "设备告警统计");
systemData.put("pictureCenter", pieChart2);
List<Map<String, Object>> linesEchart = fireFightingSystemMapper.selectWeekLinesEchart(valueOf(system.get("code")), startDate, endDate);
String lines = ChartsUtils.manyLineChart(linesEchart, "周告警信息", "日期", "告警数量");
systemData.put("lines", lines);
systemData.put("sysData", list);
dataList.add(systemData);
map.put("data", dataList);
}
}
}
return map;
}
@Override
public String iotWeekReport(String bizOrgCode, String startDate, String endDate) {
Map<String, Object> dataMap = getWeekData(bizOrgCode, startDate, endDate);
WordTemplateUtils instance = WordTemplateUtils.getInstance();
String pdfUrlString = "";
File filepdf = null;
try {
filepdf = instance.getWordFileItem(dataMap, null, WordTemplateTypeEum.iotWeekReport.getTemplateFile());
filepdf.getAbsolutePath();
MultipartFile multipartFile = new MyByteArrayMultipartFile("file", "file.pdf", "application/pdf", file2byte(filepdf));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) {
Iterator<String> it = result.getResult().keySet().iterator();
while (it.hasNext()) {
pdfUrlString = it.next();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (filepdf != null) {
filepdf.delete();
}
}
return pdfUrlString;
}
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -3713,4 +3713,378 @@ ...@@ -3713,4 +3713,378 @@
) B on B.reportDate = A.date ) C ) B on B.reportDate = A.date ) C
ORDER BY title,x ORDER BY title,x
</select> </select>
<select id="selectWeekReportList" resultType="java.util.Map">
SELECT temp.name,temp.num,temp.normalNum, temp1.type_name , temp1.monitoringData,temp1.acquisition,temp1.normal,
IFNULL(temp1.alarmEquipNum,0) AS alarmEquipNum, temp1.type_code,temp.code
FROM
(
select
a1.*,
(a1.num - a1.exepctionNum) as normalNum
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)
<foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
report.index_type like concat ('%', #{index})
</foreach>
and report.index_true_num > 0 and report.report_date >= '2022-08-01' and report.report_date &lt;= '2022-08-31' ) as exepctionNum
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 is not null
GROUP BY code,s.id, name ORDER BY system_id, code ) a) as a1
) temp
LEFT JOIN
(
SELECT temp.*,
CASE
WHEN wei.is_trend = 0 then "遥信"
WHEN wei.is_trend = 1 then "遥测"
ELSE "/"
END AS monitoringData
FROM
(
SELECT
spec_index.equipment_index_id,
s.id as systemId,
spec.equipment_code as code,
spec_index.equipment_index_name AS type_name,
spec_index.equipment_index_key AS type_code,
'自动获取' AS acquisition,
CASE
WHEN spec_index.equipment_index_key LIKE CONCAT('%', 'fault') THEN
'无故障'
WHEN spec_index.equipment_index_key LIKE CONCAT('%', 'SHIELD') THEN
'无屏蔽'
ELSE
'/'
END AS normal,
IFNULL(
(
SELECT
sum(e.report_equip_num)
FROM
wl_equipment_alarm_equip_day e
WHERE
e.system_id is not null
and e.system_id = s.id
AND e.equipment_code = spec.equipment_code
AND e.index_key = spec_index.equipment_index_key
AND e.report_date >= DATE_FORMAT('2022-08-01','%y-%m-%d')
AND e.report_date &lt;= DATE_FORMAT('2022-08-31','%y-%m-%d')
),
0
) AS alarmEquipNum
FROM
wl_equipment_specific_index spec_index
JOIN wl_equipment_specific spec ON spec_index.equipment_specific_id = spec.id
join f_fire_fighting_system s on FIND_IN_SET(s.id,spec.system_id)
WHERE
spec.system_id is not null
GROUP BY systemId,code,type_code
)temp LEFT JOIN wl_equipment_index wei on temp.equipment_index_id = wei.id
)temp1 on temp.system_id = temp1.systemId and temp.code = temp1.code
where temp.system_id = #{systemId}
</select>
<select id="selectAlarms" resultType="java.lang.Integer">
SELECT
COUNT(1)
FROM
wl_equipment_alarm_report_day report
LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids )
LEFT JOIN wl_equipment_specific spec on report.equipment_specific_id = spec.id
where report.system_ids is not null and report.index_true_num > 0
<foreach collection="indicator" item="index" open="AND(" separator="or" close=")">
report.index_type like concat ('%', #{index})
</foreach>
and report.report_date BETWEEN '2022-08-01' and '2022-08-10'
and system_id = #{systemId}
and index_type = #{indexType}
and report.equipment_code = #{equipmentCode}
</select>
<select id="selectWeekSummarize" resultType="java.util.Map">
SELECT
CONCAT_WS( '',fs.name, '设备总数', b.equipNum, '台,正常设备', b.normalNum, '台,正常率', b.normalRate,'%,故障设备' ,b.faultNum, '台,故障率为', b.faultRate,'%',CHAR(10),
'7日告警设备为',b.exepctionNum,'台,同比上周', b.status1,exepctionWOW,'%。' ,CHAR(10),
'7日告警总数为',b.alarmNum,'条,同比上周', b.status2,alarmWOW,'%。' ,CHAR(10)
) AS contant,
fs.id as system_id
FROM
f_fire_fighting_system fs left join
(
select
SUM(a1.num) AS equipNum,
SUM( (a1.num - a1.exepctionNum))as normalNum,
SUM(a1.faultNum) as faultNum,
a1.systemName,
a1.system_id,
SUM(a1.exepctionNum) as exepctionNum,
SUM(a1.lastExepctionNum) as lastExepctionNum,
SUM(a1.alarmNum) as alarmNum,
SUM(a1.lastAlarmNum) as lastAlarmNum,
if (SUM(a1.lastExepctionNum)>0,IFNULL( convert( ABS(SUM(a1.exepctionNum)-SUM(a1.lastExepctionNum))/SUM(a1.lastExepctionNum),decimal(15,2)),'-'),ABS(SUM(a1.exepctionNum)-SUM(a1.lastExepctionNum)))*100 as exepctionWOW,
if (SUM(a1.lastAlarmNum)>0,IFNULL( convert( ABS(SUM(a1.alarmNum)-SUM(a1.lastAlarmNum))/SUM(a1.lastAlarmNum),decimal(15,2)),'-'),ABS(SUM(a1.alarmNum)-SUM(a1.lastAlarmNum)))*100 as alarmWOW,
(CASE WHEN (SUM(a1.exepctionNum)-SUM(a1.lastExepctionNum)) &lt;0 THEN '减少' else '增加' end ) as status1,
(CASE WHEN (SUM(a1.alarmNum)-SUM(a1.lastAlarmNum)) &lt;0 THEN '减少' else '增加' end ) as status2,
if(SUM(a1.num)>0, convert(SUM(a1.num - a1.exepctionNum)/SUM(a1.num),decimal(15,2)), SUM(a1.num - a1.exepctionNum))*100 as normalRate,
if(SUM(a1.num)>0,convert(SUM(a1.faultNum)/SUM(a1.num),decimal(15,2)),SUM(a1.faultNum)) *100 as faultRate,
a1.create_date
from
(SELECT
system_id,
num,
name,
code,
create_date,
(SELECT IFNULL(count(distinct equipment_specific_id) ,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_true_num >0
and( report.index_type LIKE CONCAT('%','Fault','%')
or report.index_type LIKE CONCAT('%','FireAlarm','%')
or report.index_type LIKE CONCAT('%','Shield','%') )
and report.report_date between #{startDate} and #{endDate} ) as exepctionNum,
(SELECT IFNULL(count(distinct equipment_specific_id) ,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_true_num >0
and( report.index_type LIKE CONCAT('%','Fault','%')
or report.index_type LIKE CONCAT('%','FireAlarm','%')
or report.index_type LIKE CONCAT('%','Shield','%') )
and report.report_date >= DATE_SUB(#{startDate},INTERVAL 7 DAY)
and report.report_date &lt;= DATE_SUB(#{endDate},INTERVAL 7 DAY) ) as lastExepctionNum,
(SELECT IFNULL(SUM(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','%')
or report.index_type LIKE CONCAT('%','FireAlarm','%')
or report.index_type LIKE CONCAT('%','Shield','%') )
and report.report_date between #{startDate} and #{endDate} ) as alarmNum,
(SELECT IFNULL(count(distinct equipment_specific_id) ,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_true_num >0
and( report.index_type LIKE CONCAT('%','Fault','%'))
and report.report_date between #{startDate} and #{endDate} ) as faultNum,
(SELECT IFNULL(SUM(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','%')
or report.index_type LIKE CONCAT('%','FireAlarm','%')
or report.index_type LIKE CONCAT('%','Shield','%') )
and report.report_date >= DATE_SUB(#{startDate},INTERVAL 7 DAY)
and report.report_date &lt;= DATE_SUB(#{endDate},INTERVAL 7 DAY) ) as lastAlarmNum,
systemName
FROM(
SELECT
s.id as system_id,
equipment.code,
equipment.name,
count(1) AS num,
s.name as systemName,
spec.create_date
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 is not null and spec.create_date &lt; #{endDate}
GROUP BY code,s.id, name ORDER BY system_id, code ) a) as a1
GROUP BY a1.system_id
) as b
on fs.id = b.system_id
WHERE fs.id = #{systemId}
</select>
<select id="selectWeekEquipEchart" resultType="java.util.Map">
SELECT
(
select
SUM(a1.num-a1.exepctionNum) AS num
from
(SELECT
system_id,
system_code,
num,
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('%','FireAlarm')
or report.index_type LIKE CONCAT('%','Fault')
or report.index_type LIKE CONCAT('%','Shield'))
and report.index_true_num>0
and report.report_date BETWEEN #{startDate}
and #{endDate} ) as exepctionNum,
create_date
FROM(
SELECT
s.id as system_id,
s.code as system_code,
equipment.code,
count(1) AS num,
spec.create_date
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 is not null and spec.create_date &lt; #{endDate}
GROUP BY code,s.id ORDER BY system_id, code ) a) as a1
WHERE system_code = #{systemCode}
GROUP BY a1.system_id
) as value,
'正常设备' as type
union
SELECT
(
select
SUM(a1.exepctionNum)as exepctionNum
from
(SELECT
system_id,
system_code,
num,
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('%','FireAlarm')
or report.index_type LIKE CONCAT('%','Fault')
or report.index_type LIKE CONCAT('%','Shield') )
and report.index_true_num>0
and report.report_date between #{startDate}
and #{endDate} ) as exepctionNum
FROM(
SELECT
s.id as system_id,
s.code as system_code,
equipment.code,
count(1) AS num,
spec.create_date
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 is not null and spec.create_date &lt; #{endDate}
GROUP BY code,s.id ORDER BY system_id, code ) a) as a1
WHERE system_code = #{systemCode}
GROUP BY a1.system_id
) as value,
'异常设备' as type
</select>
<select id="selectWeekEchart" resultType="java.util.Map">
SELECT
count( report.equipment_specific_id ) AS `value`,
equipment.NAME AS `type`
FROM
wl_equipment_alarm_report_day report
LEFT JOIN wl_equipment equipment ON equipment.CODE = report.equipment_code
LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids )
WHERE
report.system_ids is not null
and report.index_type LIKE CONCAT('%','Fault')
and report.index_true_num >0
AND s.code = #{systemCode}
and report.report_date between #{startDate} and #{endDate}
GROUP BY
report.equipment_code,
s.id
</select>
<select id="selectWeekLinesEchart" resultType="java.util.Map">
SELECT * FROM (
SELECT A.name as title, A.date as x, IFNULL(B.num,0) AS y from
(
select * from (SELECT
@s := @s + 1 AS `index`,
DATE( DATE_SUB( #{endDate}, INTERVAL @s-1 DAY ) ) AS date,
'告警条数' as name
FROM
mysql.help_topic,
( SELECT @s := 0 ) temp ) s
WHERE
s.`index` &lt; 7
) A
LEFT JOIN (
SELECT
SUM( report.index_true_num ) AS num,
report.report_date AS reportDate
FROM
wl_equipment_alarm_report_day report
LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids)
WHERE report.system_ids is not null
and( report.index_type LIKE CONCAT('%','FireAlarm')
or report.index_type LIKE CONCAT('%','Fault')
or report.index_type LIKE CONCAT('%','Shield'))
and s.code = #{systemCode}
GROUP BY
report.report_date,
s.id
) B on B.reportDate = A.date
UNION all
SELECT A.name, A.date , IFNULL(B.num,0) AS num from
(
select * from (SELECT
@s1 := @s1 + 1 AS `index`,
DATE( DATE_SUB( #{endDate}, INTERVAL @s1-1 DAY ) ) AS date,
'告警设备' as name
FROM
mysql.help_topic,
( SELECT @s1 := 0 ) temp ) s
WHERE
s.`index` &lt; 7
) A
LEFT JOIN (
SELECT
COUNT(DISTINCT(report.equipment_specific_id) ) AS num,
report.report_date AS reportDate
FROM
wl_equipment_alarm_report_day report
LEFT JOIN f_fire_fighting_system s ON FIND_IN_SET( s.id, report.system_ids)
WHERE report.system_ids is not null
and( report.index_type LIKE CONCAT('%','FireAlarm')
or report.index_type LIKE CONCAT('%','Fault')
or report.index_type LIKE CONCAT('%','Shield'))
and report.index_true_num >0
and s.code = #{systemCode}
GROUP BY
report.report_date,
s.id
) B on B.reportDate = A.date ) C
ORDER BY x
</select>
</mapper> </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