Commit e248b2bb authored by lisong's avatar lisong

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

parent 2581c4b5
......@@ -16,7 +16,10 @@ public enum WordTemplateTypeEum {
iotMonthReport("物联报表-月分析报表","iotMonthReport.ftl"),
iotWeekReport("物联报表-周分析报表","iotWeekReport.ftl");
iotWeekReport("物联报表-周分析报表","iotWeekReport.ftl"),
iotDayReport("物联报表-日分析报表","iotDayReport.ftl");
......
......@@ -16,6 +16,7 @@ import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.springframework.util.ObjectUtils;
import java.awt.*;
import java.awt.image.BufferedImage;
......@@ -48,7 +49,7 @@ public class ChartsUtils {
// map.put(name.get(i), value.get(i));
// }
for (Map<String, Object> item : data) {
map.put(String.valueOf(item.get("type")),Double.parseDouble(String.valueOf(item.get("value"))));
map.put(String.valueOf(item.get("type")),Double.parseDouble(ObjectUtils.isEmpty(item.get("value"))?"0":String.valueOf(item.get("value"))));
}
......
......@@ -677,4 +677,26 @@ public class ConfigureController extends AbstractBaseController {
return CommonResponseUtil.success(iFireFightingSystemService.iotWeekReport(bizOrgCode, startDate, endDate));
}
@PersonIdentify
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/iotDayReport")
@ApiOperation(httpMethod = "GET", value = "物联报表-日", notes = "物联报表-日")
public ResponseModel iotDayReport(@RequestParam(value = "bizOrgCode", required = false) String bizOrgCode,
@RequestParam(value = "startDate") String startDate,
@RequestParam(value = "endDate") String endDate) {
if (ObjectUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
if (!ValidationUtil.isEmpty(personIdentity)) {
bizOrgCode = personIdentity.getBizOrgCode();
}
}
if (ObjectUtils.isEmpty(bizOrgCode)){
return CommonResponseUtil.success(null);
}
return CommonResponseUtil.success(iFireFightingSystemService.iotDayReport(bizOrgCode, startDate, endDate));
}
}
......@@ -504,4 +504,15 @@ public interface FireFightingSystemMapper extends BaseMapper<FireFightingSystemE
@Param("startDate") String startDate,
@Param("endDate") String endDate);
Map<String, Object> selectDaySummarize(@Param("systemId") String systemId,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
List<Map<String, Object>> selectDayEquipEchart(@Param("systemCode") String systemCode,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
List<Map<String, Object>> selectDayEchart(@Param("systemCode") String systemCode,
@Param("startDate") String startDate,
@Param("endDate") String endDate);
}
......@@ -278,5 +278,7 @@ public interface IFireFightingSystemService extends IService<FireFightingSystemE
String iotWeekReport(String bizOrgCode, String startDate, String endDate);
String iotDayReport(String bizOrgCode, String startDate, String endDate);
}
......@@ -1772,4 +1772,142 @@ public class FireFightingSystemServiceImpl extends ServiceImpl<FireFightingSyste
}
return pdfUrlString;
}
private Map<String, Object> getDayData(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")));
// 日告警设备数
listItem.put("alarmEquipNum", ObjectUtils.isEmpty(weekItem.get("alarmEquipNum")) ? "" : String.valueOf(weekItem.get("alarmEquipNum")));
// 日告警条数
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.selectDaySummarize(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.selectDayEquipEchart(valueOf(system.get("code")), startDate, endDate);
String pieChart1 = ChartsUtils.pieChart(mapList, "设备类别类别统计");
systemData.put("pictureLeft", pieChart1);
List<Map<String, Object>> weekEchart = fireFightingSystemMapper.selectDayEchart(valueOf(system.get("code")), startDate, endDate);
String pieChart2 = ChartsUtils.pieChart(weekEchart, "设备告警统计");
systemData.put("pictureRight", pieChart2);
systemData.put("sysData", list);
dataList.add(systemData);
map.put("data", dataList);
}
}
}
return map;
}
@Override
public String iotDayReport(String bizOrgCode, String startDate, String endDate) {
Map<String, Object> dataMap = getDayData(bizOrgCode, startDate, endDate);
WordTemplateUtils instance = WordTemplateUtils.getInstance();
String pdfUrlString = "";
File filepdf = null;
try {
filepdf = instance.getWordFileItem(dataMap, null, WordTemplateTypeEum.iotDayReport.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.
......@@ -3734,9 +3734,9 @@
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})
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
and report.index_true_num > 0 and report.report_date >= #{startDate} and report.report_date &lt;= #{endDate} ) as exepctionNum
FROM(
SELECT
s.id as system_id,
......@@ -3792,8 +3792,8 @@
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')
AND e.report_date >= DATE_FORMAT(#{startDate},'%y-%m-%d')
AND e.report_date &lt;= DATE_FORMAT(#{endDate},'%y-%m-%d')
),
0
) AS alarmEquipNum
......@@ -3822,7 +3822,7 @@
<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 report.report_date BETWEEN #{startDate} and #{endDate}
and system_id = #{systemId}
and index_type = #{indexType}
and report.equipment_code = #{equipmentCode}
......@@ -4087,4 +4087,168 @@
) B on B.reportDate = A.date ) C
ORDER BY x
</select>
<select id="selectDaySummarize" resultType="java.util.Map">
SELECT
CONCAT_WS('', fs.name, '设备总数', b.equipNum, '台,今日告警设备为', b.equipNum - b.normalNum, '台,告警总数为', b.alarmNum, '条,正常设备', b.normalNum, '台,正常率', b.normalRate, '%' ) 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,
a1.systemName,
a1.system_id,
a1.alarmNum,
ROUND(if( SUM(a1.num)>0,SUM(a1.num - a1.exepctionNum)/SUM(a1.num),SUM(a1.num - a1.exepctionNum))*100,2) as normalRate,
a1.create_date
from
(SELECT
system_id,
num,
name,
code,
create_date,
(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('%','FireAlarm')
or report.index_type LIKE CONCAT('%','Fault')
or report.index_type LIKE CONCAT('%','Shield') )
and report.report_date >= #{startDate} and report.report_date &lt;= #{endDate} ) as exepctionNum,
(SELECT SUM(index_true_num)
FROM wl_equipment_alarm_report_day report
where 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.report_date >= #{startDate}
and report.report_date &lt;= #{endDate}
) as alarmNum,
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
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="selectDayEquipEchart" resultType="java.util.Map">
SELECT
num as `value`,
name as `type`
FROM(
SELECT
s.id as system_id,
s.code as system_code,
equipment.code,
equipment.name,
count(1) AS num,
s.name as systemName
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 WHERE system_code = #{systemCode}
</select>
<select id="selectDayEchart" 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 >= #{startDate}
and report.report_date &lt;= #{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
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 >= #{startDate}
and report.report_date &lt;= #{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
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>
</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