Commit ef9cb4df authored by lisong's avatar lisong

添加困人救援月度情况相关接口

parent 51a0f06b
package com.yeejoin.amos.boot.module.elevator.api.dto;
import com.baomidou.mybatisplus.annotation.TableField;
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-07
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="AlertRescueStatisticsDto", description="")
public class AlertRescueStatisticsDto extends BaseDto {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "监管单位ID")
private String supervisoryUnitId;
@ApiModelProperty(value = "监管单位名称")
private String supervisoryUnitName;
@ApiModelProperty(value = "监管单位orgcode")
private String supervisoryUnitOrgCode;
@ApiModelProperty(value = "维保单位数")
private Integer maintenanceUnit;
@ApiModelProperty(value = "大于30分钟")
private Integer greaterNum;
@ApiModelProperty(value = "小于30分钟")
private Integer lessNum;
@ApiModelProperty(value = "平均")
private String avgNum;
@ApiModelProperty(value = "一级救援")
@TableField("levelOne")
private Integer levelOne;
@ApiModelProperty(value = "二级救援")
@TableField("levelTwo")
private Integer levelTwo;
@ApiModelProperty(value = "三级救援")
@TableField("levelThree")
private Integer levelThree;
@ApiModelProperty(value = "统计月份")
private String statisticsDate;
@ApiModelProperty(value = "开始时间")
private String startDate;
@ApiModelProperty(value = "结束时间")
private String endDate;
}
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-07
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("tzs_alert_rescue_statistics")
public class AlertRescueStatistics extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 监管单位ID
*/
@TableField("supervisory_unit_id")
private String supervisoryUnitId;
/**
* 监管单位名称
*/
@TableField("supervisory_unit_name")
private String supervisoryUnitName;
/**
* 监管单位orgcode
*/
@TableField("supervisory_unit_org_code")
private String supervisoryUnitOrgCode;
/**
* 维保单位数
*/
@TableField("maintenance_unit")
private Integer maintenanceUnit;
/**
* 大于30分钟
*/
@TableField("greater_num")
private Integer greaterNum;
/**
* 小于30分钟
*/
@TableField("less_num")
private Integer lessNum;
/**
* 平均
*/
@TableField("avg_num")
private String avgNum;
/**
* 一级救援
*/
@TableField("level_one")
private Integer levelOne;
/**
* 二级救援
*/
@TableField("level_two")
private Integer levelTwo;
/**
* 三级救援
*/
@TableField("level_three")
private Integer levelThree;
/**
* 统计月份
*/
@TableField("statistics_date")
private String statisticsDate;
/**
* 开始时间
*/
@TableField("start_date")
private String startDate;
/**
* 结束时间
*/
@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.AlertRescueStatistics;
import org.apache.ibatis.annotations.Param;
/**
* Mapper 接口
*
* @author system_generator
* @date 2023-11-07
*/
public interface AlertRescueStatisticsMapper extends BaseMapper<AlertRescueStatistics> {
AlertRescueStatistics getStatisticsMessage(@Param("orgCode")String orgCode, @Param("startDate")String startDate , @Param("endDate")String endDate);
}
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 AlertRescueStatisticsExportVo {
@ColumnWidth(10)
@ExcelProperty(value = "序号", index = 0)
private Integer number;
/**
* 监管单位名称
*/
@ColumnWidth(30)
@ExcelProperty(value = "区域", index = 1)
private String supervisoryUnitName;
/**
* 维保单位数
*/
@ExcelProperty(value = "派遣维保公司(家)", index = 2)
private Integer maintenanceUnit;
/**
* 大于30分钟
*/
@ExcelProperty(value = "超过30分钟到达(次)", index = 4)
private Integer greaterNum;
/**
* 小于30分钟
*/
@ExcelProperty(value = "30分钟内到达(次)", index = 3)
private Integer lessNum;
/**
* 平均
*/
@ColumnWidth(25)
@ExcelProperty(value = "平均到达救援现场时间(min)", index = 5)
private String avgNum;
/**
* 一级救援
*/
@ExcelProperty(value = "一级救援次(次)", index = 6)
private Integer levelOne;
/**
* 二级救援
*/
@ExcelProperty(value = "二级救援(次)", index = 7)
private Integer levelTwo;
/**
* 三级救援
*/
@ExcelProperty(value = "三级救援(次)", index = 8)
private Integer levelThree;
}
......@@ -2,18 +2,14 @@ package com.yeejoin.amos.boot.module.elevator.api.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
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;
@Data
public class AlertStatisticsExportVo {
@ColumnWidth(10)
@ExcelProperty(value = "序号", index = 0)
private Integer number;
/**
......@@ -26,7 +22,6 @@ public class AlertStatisticsExportVo {
/**
* 电梯总数
*/
@TableField("elevator_num")
@ExcelProperty(value = "电梯总数(台)", index = 2)
private Integer elevatorNum;
......
<?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.AlertRescueStatisticsMapper">
<select id="getStatisticsMessage"
resultType="com.yeejoin.amos.boot.module.elevator.api.entity.AlertRescueStatistics">
SELECT (select count(1)
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate})
and org_type_code = 'levelOneUnit') as levelOne,
(select count(1)
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate})
and org_type_code = 'levelTwoUnit') as levelTwo,
(select count(1)
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate})
and org_type_code = '953') as levelThree,
(select count(DISTINCT (response_org_id))
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate})
and org_type_code = 'levelOneUnit') as maintenanceUnit,
(select count(1)
from tz_dispatch_task
where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate})
and org_type_code = 'levelOneUnit'
and date_part('minute', arrive_time - rec_date) &lt; 30) as lessNum,
(SELECT sum(times) from (SELECT date_part('second', arrive_time - rec_date)as times from tz_dispatch_task where alert_id in (SELECT sequence_nbr from tz_alert_called where biz_org_code like concat(#{orgCode}, '%') and call_time BETWEEN #{startDate} and #{endDate}) and org_type_code = 'levelOneUnit')) as avgNum
</select>
</mapper>
......@@ -4,8 +4,11 @@ import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertRescueStatistics;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertStatistics;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertRescueStatisticsService;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertStatisticsService;
import com.yeejoin.amos.boot.module.elevator.api.vo.AlertRescueStatisticsExportVo;
import com.yeejoin.amos.boot.module.elevator.api.vo.AlertStatisticsExportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
......@@ -37,6 +40,9 @@ public class StatisticsController extends BaseController {
@Autowired
private IAlertStatisticsService alertStatisticsService;
@Autowired
private IAlertRescueStatisticsService alertRescueStatisticsService;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/statisticalGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
......@@ -86,4 +92,54 @@ public class StatisticsController extends BaseController {
ExcelUtil.createTemplate(response, "各地监控中心电梯月度情况综述", "各地监控中心电梯月度情况综述", exportVos, AlertStatisticsExportVo.class, null, false);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/rescueStatisticalGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
public ResponseModel<Object> rescueStatisticalGeneration() {
alertRescueStatisticsService.statisticalGeneration();
return ResponseHelper.buildResponse("success");
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/rescueList")
@ApiOperation(httpMethod = "GET", value = "查询列表", notes = "查询列表")
public ResponseModel<Object> rescueList(@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<AlertRescueStatistics> alertRescueStatisticsPage = new Page<>();
alertRescueStatisticsPage.setRecords(alertRescueStatisticsService.getList(date));
return ResponseHelper.buildResponse(alertRescueStatisticsPage);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/exportRescueData")
@ApiOperation(httpMethod = "GET", value = "监管单位统计信息导出", notes = "监管单位统计信息导出")
public void exportRescueData(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<AlertRescueStatisticsExportVo> exportVos = new ArrayList<>();
List<AlertRescueStatistics> list = alertRescueStatisticsService.getList(date);
int number = 1;
for (AlertRescueStatistics item : list) {
AlertRescueStatisticsExportVo vo = new AlertRescueStatisticsExportVo();
BeanUtil.copyProperties(item, vo);
vo.setNumber(number);
number = number + 1;
exportVos.add(vo);
}
ExcelUtil.createTemplate(response, "各地监控中心困人救援月度情况汇总表", "各地监控中心困人救援月度情况汇总表", exportVos, AlertRescueStatisticsExportVo.class, null, false);
}
}
package com.yeejoin.amos.boot.module.elevator.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertRescueStatisticsDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertRescueStatistics;
import com.yeejoin.amos.boot.module.elevator.api.mapper.AlertRescueStatisticsMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertRescueStatisticsService;
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.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* 服务实现类
*
* @author system_generator
* @date 2023-11-07
*/
@Service
public class AlertRescueStatisticsServiceImpl extends BaseService<AlertRescueStatisticsDto, AlertRescueStatistics, AlertRescueStatisticsMapper> implements IAlertRescueStatisticsService {
@Autowired
private AlertStatisticsServiceImpl alertStatisticsService;
@Override
@Scheduled(cron = "0 0 0 1 * ?")
@SchedulerLock(name = "statisticalGeneration", 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();
ArrayList<AlertRescueStatistics> list = new ArrayList<>();
List<LinkedHashMap> supervisionList = alertStatisticsService.getSupervisionList();
DecimalFormat decimalFormat = new DecimalFormat("0.000");
if (!ObjectUtils.isEmpty(supervisionList)) {
supervisionList.forEach(item -> {
AlertRescueStatistics statisticsMessage = this.baseMapper.getStatisticsMessage(String.valueOf(item.get("orgCode")), format.format(firstDayOfMonth) + " 00:00:00", format.format(lastDayOfMonth) + " 23:59:59");
statisticsMessage.setSupervisoryUnitName(String.valueOf(item.get("companyName")));
statisticsMessage.setSupervisoryUnitOrgCode(String.valueOf(item.get("orgCode")));
statisticsMessage.setSupervisoryUnitId(String.valueOf(item.get("sequenceNbr")));
statisticsMessage.setGreaterNum(statisticsMessage.getMaintenanceUnit() - statisticsMessage.getLessNum());
if (ObjectUtils.isEmpty(statisticsMessage.getAvgNum()) || ObjectUtils.isEmpty(statisticsMessage.getMaintenanceUnit()) || statisticsMessage.getAvgNum().equals("0") || statisticsMessage.getMaintenanceUnit() == 0) {
statisticsMessage.setAvgNum("0");
} else {
BigDecimal bigDecimal = new BigDecimal(statisticsMessage.getAvgNum()).divide(new BigDecimal("60"), 6, BigDecimal.ROUND_HALF_UP);
BigDecimal bigDecimal1 = new BigDecimal(statisticsMessage.getMaintenanceUnit().toString());
BigDecimal divide = bigDecimal.divide(bigDecimal1, 6, BigDecimal.ROUND_HALF_UP);
statisticsMessage.setAvgNum(decimalFormat.format(divide));
}
statisticsMessage.setStartDate(format.format(firstDayOfMonth));
statisticsMessage.setEndDate(format.format(lastDayOfMonth));
statisticsMessage.setStatisticsDate(format.format(lastDayOfMonth).substring(0, 7));
list.add(statisticsMessage);
});
}
if (!ObjectUtils.isEmpty(list)) {
this.saveBatch(list);
}
}
@Override
public List<AlertRescueStatistics> getList(String date) {
DecimalFormat decimalFormat = new DecimalFormat("0.000");
LambdaQueryWrapper<AlertRescueStatistics> lambda = new QueryWrapper<AlertRescueStatistics>().lambda();
lambda.eq(AlertRescueStatistics::getStatisticsDate, date);
List<AlertRescueStatistics> alertRescueStatistics = this.baseMapper.selectList(lambda);
AlertRescueStatistics total = new AlertRescueStatistics();
total.setSupervisoryUnitName("合计");
if (!ObjectUtils.isEmpty(alertRescueStatistics)) {
alertRescueStatistics.forEach(item -> {
total.setMaintenanceUnit(ObjectUtils.isEmpty(total.getMaintenanceUnit()) ? item.getMaintenanceUnit() : total.getMaintenanceUnit() + item.getMaintenanceUnit());
total.setLessNum(ObjectUtils.isEmpty(total.getLessNum()) ? item.getLessNum() : total.getLessNum() + item.getLessNum());
total.setGreaterNum(ObjectUtils.isEmpty(total.getGreaterNum()) ? item.getGreaterNum() : total.getGreaterNum() + item.getGreaterNum());
total.setLevelOne(ObjectUtils.isEmpty(total.getLevelOne()) ? item.getLevelOne() : total.getLevelOne() + item.getLevelOne());
total.setLevelTwo(ObjectUtils.isEmpty(total.getLevelTwo()) ? item.getLevelTwo() : total.getLevelTwo() + item.getLevelTwo());
total.setLevelThree(ObjectUtils.isEmpty(total.getLevelThree()) ? item.getLevelThree() : total.getLevelThree() + item.getLevelThree());
total.setAvgNum(ObjectUtils.isEmpty(total.getAvgNum()) ? item.getAvgNum() : String.valueOf(Double.parseDouble(total.getAvgNum()) + Double.parseDouble(item.getAvgNum())));
});
if (ObjectUtils.isEmpty(total.getAvgNum()) || total.getAvgNum().equals("0")) {
total.setAvgNum("0");
} else {
BigDecimal bigDecimal = new BigDecimal(total.getAvgNum());
BigDecimal bigDecimal1 = new BigDecimal(alertRescueStatistics.size());
BigDecimal divide = bigDecimal.divide(bigDecimal1, 6, BigDecimal.ROUND_HALF_UP);
total.setAvgNum(decimalFormat.format(divide));
}
alertRescueStatistics.add(total);
}
return alertRescueStatistics;
}
}
\ No newline at end of file
......@@ -64,7 +64,7 @@ public class AlertStatisticsServiceImpl extends BaseService<AlertStatisticsDto,
}
private List<LinkedHashMap> getSupervisionList() {
public List<LinkedHashMap> getSupervisionList() {
List<LinkedHashMap> data = (List<LinkedHashMap>) redisUtils.get(REGULATOR_UNIT_TREE);
if (!ObjectUtils.isEmpty(data)) {
data = (List<LinkedHashMap>) data.get(0).get("children");
......@@ -102,15 +102,7 @@ public class AlertStatisticsServiceImpl extends BaseService<AlertStatisticsDto,
statistics.setAvgDaysBreakdownRescue(ObjectUtils.isEmpty(statistics.getBreakdownRescue()) ? String.valueOf(item.getBreakdownRescue()) : String.valueOf(item.getBreakdownRescue() + statistics.getBreakdownRescue()));
}
}else {
statistics.setElevatorNum(0);
statistics.setEmergencyEvents(0);
statistics.setTrappedPeople(0);
statistics.setBreakdownRescue(0);
statistics.setRescuePersonnel(0);
statistics.setComplaint(0);
statistics.setAvgDaysEmergencyEvents("0");
statistics.setAvgDaysTrappedPeople("0");
statistics.setAvgDaysBreakdownRescue("0");
return alertStatistics;
}
statistics.setSupervisoryUnitName("合计");
statistics.setSequenceNbr(0L);
......
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