Commit fa8792cc authored by lisong's avatar lisong

添加困人救援超时统计

parent f7f1aabd
package com.yeejoin.amos.boot.module.elevator.api.dto;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author system_generator
* @date 2023-11-10
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="AlertDispatchStatisticsDto", description="")
public class AlertDispatchStatisticsDto extends BaseDto {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "监管单位ID")
private String supervisoryUnitId;
@ApiModelProperty(value = "监管单位名称")
private String supervisoryUnitName;
@ApiModelProperty(value = "监管单位编码")
private String supervisoryUnitOrgCode;
@ApiModelProperty(value = "统计月份")
private String statisticsDate;
@ApiModelProperty(value = "开始日期")
private String startDate;
@ApiModelProperty(value = "维保单位")
private String maintenanceUnit;
@ApiModelProperty(value = "派遣时间")
private String dispatchTime;
@ApiModelProperty(value = "救援地址")
private String address;
@ApiModelProperty(value = "救援到达时间")
private String arriveTime;
}
package com.yeejoin.amos.boot.module.elevator.api.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
*
*
* @author system_generator
* @date 2023-11-10
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("tzs_alert_dispatch_statistics")
public class AlertDispatchStatistics extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 监管单位ID
*/
@TableField("supervisory_unit_id")
private String supervisoryUnitId;
/**
* 监管单位名称
*/
@TableField("supervisory_unit_name")
private String supervisoryUnitName;
/**
* 监管单位编码
*/
@TableField("supervisory_unit_org_code")
private String supervisoryUnitOrgCode;
/**
* 统计月份
*/
@TableField("statistics_date")
private String statisticsDate;
/**
* 开始日期
*/
@TableField("start_date")
private String startDate;
/**
* 维保单位
*/
@TableField("maintenance_unit")
private String maintenanceUnit;
/**
* 派遣时间
*/
@TableField("dispatch_time")
private String dispatchTime;
/**
* 救援地址
*/
@TableField("address")
private String address;
/**
* 救援到达时间
*/
@TableField("arrive_time")
private String arriveTime;
@TableField("end_date")
private String endDate;
}
package com.yeejoin.amos.boot.module.elevator.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertDispatchStatistics;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* Mapper 接口
*
* @author system_generator
* @date 2023-11-10
*/
public interface AlertDispatchStatisticsMapper extends BaseMapper<AlertDispatchStatistics> {
List<Map<String, String>> getMessage(@Param("startDate") String startDate, @Param("endDate") String endDate);
}
package com.yeejoin.amos.boot.module.elevator.api.service;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertDispatchStatistics;
import java.util.List;
/**
* 接口类
*
* @author system_generator
* @date 2023-11-10
*/
public interface IAlertDispatchStatisticsService {
void statisticalGeneration();
List<AlertDispatchStatistics> getList(String date);
}
package com.yeejoin.amos.boot.module.elevator.api.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.Data;
@Data
public class AlertDispatchStatisticsExportVo {
@ColumnWidth(10)
@ExcelProperty(value = "序号", index = 0)
private Integer number;
@ColumnWidth(30)
@ExcelProperty(value = "区域", index = 1)
private String supervisoryUnitName;
@ColumnWidth(30)
@ExcelProperty(value = "维保单位", index = 2)
private String maintenanceUnit;
@ColumnWidth(30)
@ExcelProperty(value = "接派时间", index = 3)
private String dispatchTime;
@ExcelProperty(value = "救援地址", index = 4)
private String address;
@ExcelProperty(value = "救援到达时间", index = 5)
private String arriveTime;
}
<?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.amos.boot.module.elevator.api.mapper.AlertDispatchStatisticsMapper">
<select id="getMessage" resultType="java.util.Map">
SELECT *
from (
SELECT concat(ROUND(date_part('second', arrive_time - dispatch_time) / 60, 2), '分钟') as arriveTime,
(
SELECT ME_UNIT_NAME
from idx_biz_jg_maintenance_record_info
WHERE SEQUENCE_NBR = response_org_id limit 1
) as maintenanceUnit,
DATE_FORMAT(arrive_time, '%Y年%m月%d日%H时%i分%s秒') as dispatchTime,
(SELECT ORG_BRANCH_CODE
from idx_biz_jg_supervision_info
where RECORD = (SELECT equipment_id from tz_alert_called where sequence_nbr = alert_id)) as orgCode,
(SELECT address from tz_alert_called where sequence_nbr = alert_id) as address from tz_dispatch_task
where org_type_code = 'levelOneUnit'
and arrive_time is not null
and dispatch_time between #{startDate}
and #{endDate}
and alert_id in (SELECT sequence_nbr from tz_alert_called where alarm_type_code = '960' and call_time between #{startDate} and #{endDate})
)
WHERE orgCode is not null
</select>
</mapper>
...@@ -49,6 +49,9 @@ public class StatisticsController extends BaseController { ...@@ -49,6 +49,9 @@ public class StatisticsController extends BaseController {
@Autowired @Autowired
private IAlertMaintenanceUnitStatisticsService alertMaintenanceUnitStatisticsService; private IAlertMaintenanceUnitStatisticsService alertMaintenanceUnitStatisticsService;
@Autowired
private IAlertDispatchStatisticsService alertDispatchStatisticsService;
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/statisticalGeneration") @GetMapping(value = "/statisticalGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据") @ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
...@@ -295,4 +298,52 @@ public class StatisticsController extends BaseController { ...@@ -295,4 +298,52 @@ public class StatisticsController extends BaseController {
} }
ExcelUtil.createTemplate(response, "月度故障高发维保单位统计", "月度故障高发维保单位统计", exportVos, AlertMaintenanceUnitStatisticsExportVo.class, null, false); ExcelUtil.createTemplate(response, "月度故障高发维保单位统计", "月度故障高发维保单位统计", exportVos, AlertMaintenanceUnitStatisticsExportVo.class, null, false);
} }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/statisticalDispatchGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
public ResponseModel<Object> statisticalDispatchGeneration() {
alertDispatchStatisticsService.statisticalGeneration();
return ResponseHelper.buildResponse("success");
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/dispatchList")
@ApiOperation(httpMethod = "GET", value = "查询列表", notes = "查询列表")
public ResponseModel<Object> dispatchList(@RequestParam(value = "date", required = false) String date) {
if (ObjectUtils.isEmpty(date)) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
Date nowDate = cal.getTime();
date = format.format(nowDate);
}
Page<AlertDispatchStatistics> alertRescueStatisticsPage = new Page<>();
alertRescueStatisticsPage.setRecords(alertDispatchStatisticsService.getList(date));
return ResponseHelper.buildResponse(alertRescueStatisticsPage);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/exportDispatchData")
@ApiOperation(httpMethod = "GET", value = "月度故障高发维保单位统计导出", notes = "月度故障高发维保单位统计导出")
public void exportDispatchData(HttpServletResponse response, @RequestParam(value = "date", required = false) String date) throws ParseException {
if (ObjectUtils.isEmpty(date)) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
Date nowDate = cal.getTime();
date = format.format(nowDate);
}
ArrayList<AlertDispatchStatisticsExportVo> exportVos = new ArrayList<>();
List<AlertDispatchStatistics> list = alertDispatchStatisticsService.getList(date);
int number = 1;
for (AlertDispatchStatistics item : list) {
AlertDispatchStatisticsExportVo vo = new AlertDispatchStatisticsExportVo();
BeanUtil.copyProperties(item, vo);
vo.setNumber(number);
number = number + 1;
exportVos.add(vo);
}
ExcelUtil.createTemplate(response, "困人救援超时情况统计", "困人救援超时情况统计", exportVos, AlertDispatchStatisticsExportVo.class, null, false);
}
} }
package com.yeejoin.amos.boot.module.elevator.biz.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertDispatchStatisticsDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertDispatchStatistics;
import com.yeejoin.amos.boot.module.elevator.api.mapper.AlertDispatchStatisticsMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertDispatchStatisticsService;
import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
* 服务实现类
*
* @author system_generator
* @date 2023-11-10
*/
@Service
public class AlertDispatchStatisticsServiceImpl extends BaseService<AlertDispatchStatisticsDto, AlertDispatchStatistics, AlertDispatchStatisticsMapper> implements IAlertDispatchStatisticsService {
@Autowired
private AlertStatisticsServiceImpl alertStatisticsService;
@Override
@Scheduled(cron = "0 0 0 1 * ?")
@SchedulerLock(name = "AlertDispatchStatisticsServiceImpl", lockAtMostFor = "PT10M", lockAtLeastFor = "PT10M")
public void statisticalGeneration() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.MONTH, -1);
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
Date firstDayOfMonth = cal.getTime();
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Date lastDayOfMonth = cal.getTime();
List<LinkedHashMap> supervisionList = alertStatisticsService.getSupervisionList();
List<Map<String, String>> message = this.baseMapper.getMessage(format.format(firstDayOfMonth) + " 00:00:00", format.format(lastDayOfMonth) + " 23:59:59");
ArrayList<AlertDispatchStatistics> list = new ArrayList<>();
if (!ObjectUtils.isEmpty(supervisionList)) {
supervisionList.forEach(item -> {
List<Map<String, String>> collect = message.stream().filter(detail -> detail.get("orgCode").startsWith(String.valueOf(item.get("orgCode")))).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(collect)) {
collect.forEach(data -> {
AlertDispatchStatistics alertDispatchStatistics = new AlertDispatchStatistics();
BeanUtil.copyProperties(data, alertDispatchStatistics);
alertDispatchStatistics.setSupervisoryUnitName(String.valueOf(item.get("companyName")));
alertDispatchStatistics.setSupervisoryUnitOrgCode(String.valueOf(item.get("orgCode")));
alertDispatchStatistics.setSupervisoryUnitId(String.valueOf(item.get("sequenceNbr")));
alertDispatchStatistics.setStartDate(format.format(firstDayOfMonth));
alertDispatchStatistics.setEndDate(format.format(lastDayOfMonth));
alertDispatchStatistics.setStatisticsDate(format.format(lastDayOfMonth).substring(0, 7));
list.add(alertDispatchStatistics);
});
}
});
if (!ObjectUtils.isEmpty(list)) {
this.saveBatch(list);
}
}
}
@Override
public List<AlertDispatchStatistics> getList(String date) {
LambdaQueryWrapper<AlertDispatchStatistics> lambda = new QueryWrapper<AlertDispatchStatistics>().lambda();
lambda.eq(AlertDispatchStatistics::getStatisticsDate, date);
return this.baseMapper.selectList(lambda);
}
}
\ No newline at end of file
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