Commit 21811404 authored by lisong's avatar lisong

添加月度电梯困人故障高发区域统计相关接口

parent 1eda1ed3
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-08
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="AlertPlaceStatisticsDto", description="")
public class AlertPlaceStatisticsDto extends BaseDto {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "监管单位ID")
private String supervisoryUnitId;
@ApiModelProperty(value = "监管单位名称")
private String supervisoryUnitName;
@ApiModelProperty(value = "supervisory_unit_org_code")
private String supervisoryUnitOrgCode;
@ApiModelProperty(value = "统计月份")
private String statisticsDate;
@ApiModelProperty(value = "开始时间")
private String startDate;
@ApiModelProperty(value = "结束时间")
private String endDate;
@ApiModelProperty(value = "困人救援")
private Integer trappedNum;
@ApiModelProperty(value = "故障救援")
private Integer faultNum;
@ApiModelProperty(value = "困人比率")
private String trappedRate;
@ApiModelProperty(value = "故障比率")
private String faultRate;
@ApiModelProperty(value = "使用场所")
private String placeName;
}
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-08
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("tzs_alert_place_statistics")
public class AlertPlaceStatistics extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 监管单位ID
*/
@TableField("supervisory_unit_id")
private String supervisoryUnitId;
/**
* 监管单位名称
*/
@TableField("supervisory_unit_name")
private String supervisoryUnitName;
/**
* supervisory_unit_org_code
*/
@TableField("supervisory_unit_org_code")
private String supervisoryUnitOrgCode;
/**
* 统计月份
*/
@TableField("statistics_date")
private String statisticsDate;
/**
* 开始时间
*/
@TableField("start_date")
private String startDate;
/**
* 结束时间
*/
@TableField("end_date")
private String endDate;
/**
* 困人救援
*/
@TableField("trapped_num")
private Integer trappedNum;
/**
* 故障救援
*/
@TableField("fault_num")
private Integer faultNum;
/**
* 困人比率
*/
@TableField("trapped_rate")
private String trappedRate;
/**
* 故障比率
*/
@TableField("fault_rate")
private String faultRate;
/**
* 使用场所
*/
@TableField("place_name")
private String placeName;
}
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.AlertPlaceStatistics;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
* Mapper 接口
*
* @author system_generator
* @date 2023-11-08
*/
public interface AlertPlaceStatisticsMapper extends BaseMapper<AlertPlaceStatistics> {
List<Map<String, String>> getAllPlace();
Map<String, Integer> getTotal(@Param("startDate")String startDate, @Param("endDate")String endDate);
AlertPlaceStatistics getStatisticsMessage(@Param("placeCode")String placeCode, @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.AlertPlaceStatistics;
import java.util.List;
/**
* 接口类
*
* @author system_generator
* @date 2023-11-08
*/
public interface IAlertPlaceStatisticsService {
void statisticalGeneration();
List<AlertPlaceStatistics> placeList(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 AlertPlaceStatisticsExportVo {
@ColumnWidth(10)
@ExcelProperty(value = "序号", index = 0)
private Integer number;
/**
* 困人救援
*/
@ExcelProperty(value = "困人(起)", index = 2)
private Integer trappedNum;
/**
* 故障救援
*/
@ExcelProperty(value = "困人(起)", index = 4)
private Integer faultNum;
/**
* 困人比率
*/
@ExcelProperty(value = "比 率", index = 3)
private String trappedRate;
/**
* 故障比率
*/
@ExcelProperty(value = "比 率", index = 5)
private String faultRate;
/**
* 使用场所
*/
@ExcelProperty(value = "使用单位性质", index = 1)
private String placeName;
}
<?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.AlertPlaceStatisticsMapper">
<select id="getAllPlace" resultType="java.util.Map">
select code, name from cb_data_dictionary where type = 'ADDRESS'
</select>
<select id="getTotal" resultType="java.util.Map">
select
(select count(1) from tz_alert_called where alarm_type_code = '961' and call_time between #{startDate} and #{endDate}) as faultNum,
(select count(1) from tz_alert_called where alarm_type_code = '960' and call_time between #{startDate} and #{endDate} ) as trappedNum
</select>
<select id="getStatisticsMessage"
resultType="com.yeejoin.amos.boot.module.elevator.api.entity.AlertPlaceStatistics">
SELECT
(SELECT count(1) FROM
tz_alert_called t1
LEFT JOIN idx_biz_jg_use_info t2 ON t1.equipment_id = t2.RECORD WHERE t2.USE_PLACE = #{placeCode} and t1.alarm_type_code = '960' and t1.call_time between #{startDate} and #{endDate}) as trappedNum,
(SELECT count(1) FROM
tz_alert_called t1
LEFT JOIN idx_biz_jg_use_info t2 ON t1.equipment_id = t2.RECORD WHERE t2.USE_PLACE = #{placeCode} and t1.alarm_type_code = '961' and t1.call_time between #{startDate} and #{endDate}) as faultNum
</select>
</mapper>
......@@ -6,25 +6,25 @@
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})
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 alarm_type_code = '960')
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})
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 alarm_type_code = '960')
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})
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 alarm_type_code = '960')
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})
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 alarm_type_code = '960')
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})
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 alarm_type_code = '960')
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 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 alarm_type_code = '960') and org_type_code = 'levelOneUnit')) as avgNum
</select>
</mapper>
......@@ -4,10 +4,13 @@ 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.AlertPlaceStatistics;
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.IAlertPlaceStatisticsService;
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.AlertPlaceStatisticsExportVo;
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;
......@@ -43,6 +46,10 @@ public class StatisticsController extends BaseController {
@Autowired
private IAlertRescueStatisticsService alertRescueStatisticsService;
@Autowired
private IAlertPlaceStatisticsService alertPlaceStatisticsService;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/statisticalGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
......@@ -142,4 +149,54 @@ public class StatisticsController extends BaseController {
ExcelUtil.createTemplate(response, "各地监控中心困人救援月度情况汇总表", "各地监控中心困人救援月度情况汇总表", exportVos, AlertRescueStatisticsExportVo.class, null, false);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/statisticalPlaceGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
public ResponseModel<Object> statisticalPlaceGeneration() {
alertPlaceStatisticsService.statisticalGeneration();
return ResponseHelper.buildResponse("success");
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/placeList")
@ApiOperation(httpMethod = "GET", value = "查询列表", notes = "查询列表")
public ResponseModel<Object> placeList(@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<AlertPlaceStatistics> alertRescueStatisticsPage = new Page<>();
alertRescueStatisticsPage.setRecords(alertPlaceStatisticsService.placeList(date));
return ResponseHelper.buildResponse(alertRescueStatisticsPage);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/exportPlaceData")
@ApiOperation(httpMethod = "GET", value = "月度电梯困人故障高发区域统计导出", notes = "月度电梯困人故障高发区域统计导出")
public void exportPlaceData(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<AlertPlaceStatisticsExportVo> exportVos = new ArrayList<>();
List<AlertPlaceStatistics> list = alertPlaceStatisticsService.placeList(date);
int number = 1;
for (AlertPlaceStatistics item : list) {
AlertPlaceStatisticsExportVo vo = new AlertPlaceStatisticsExportVo();
BeanUtil.copyProperties(item, vo);
vo.setNumber(number);
number = number + 1;
exportVos.add(vo);
}
ExcelUtil.createTemplate(response, "月度电梯困人故障高发区域统计", "月度电梯困人故障高发区域统计", exportVos, AlertPlaceStatisticsExportVo.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.yeejoin.amos.boot.module.elevator.api.dto.AlertPlaceStatisticsDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertPlaceStatistics;
import com.yeejoin.amos.boot.module.elevator.api.mapper.AlertPlaceStatisticsMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertPlaceStatisticsService;
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-08
*/
@Service
public class AlertPlaceStatisticsServiceImpl extends BaseService<AlertPlaceStatisticsDto, AlertPlaceStatistics, AlertPlaceStatisticsMapper> implements IAlertPlaceStatisticsService {
@Override
public void statisticalGeneration() {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
DecimalFormat decimalFormat = new DecimalFormat("0.00");
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<AlertPlaceStatistics> list = new ArrayList<>();
Map<String, Integer> totalMessage = this.baseMapper.getTotal(format.format(firstDayOfMonth) + " 00:00:00", format.format(lastDayOfMonth) + " 23:59:59");
int trappedTotal = ObjectUtils.isEmpty(totalMessage.get("trappedNum")) ? 0 : Integer.parseInt(String.valueOf(totalMessage.get("trappedNum")));
int faultTotal = ObjectUtils.isEmpty(totalMessage.get("faultNum")) ? 0 : Integer.parseInt(String.valueOf(totalMessage.get("faultNum")));
List<Map<String, String>> allPlace = this.baseMapper.getAllPlace();
AlertPlaceStatistics other = new AlertPlaceStatistics();
other.setPlaceName("其他");
other.setStartDate(format.format(firstDayOfMonth));
other.setEndDate(format.format(lastDayOfMonth));
other.setStatisticsDate(format.format(lastDayOfMonth).substring(0, 7));
if (!ObjectUtils.isEmpty(allPlace)) {
allPlace.forEach(item -> {
if (!ObjectUtils.isEmpty(item.get("code")) && !ObjectUtils.isEmpty(item.get("name"))) {
AlertPlaceStatistics placeStatistics = this.baseMapper.getStatisticsMessage(item.get("code"), format.format(firstDayOfMonth) + " 00:00:00", format.format(lastDayOfMonth) + " 23:59:59");
placeStatistics.setPlaceName(item.get("name"));
placeStatistics.setStartDate(format.format(firstDayOfMonth));
placeStatistics.setEndDate(format.format(lastDayOfMonth));
placeStatistics.setStatisticsDate(format.format(lastDayOfMonth).substring(0, 7));
if (trappedTotal != 0 && !ObjectUtils.isEmpty(placeStatistics.getTrappedNum()) && placeStatistics.getTrappedNum() != 0) {
BigDecimal bigDecimal = new BigDecimal(placeStatistics.getTrappedNum());
BigDecimal bigDecimal1 = new BigDecimal(trappedTotal);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
placeStatistics.setTrappedRate(decimalFormat.format(divide) + "%");
} else {
placeStatistics.setTrappedRate("0%");
}
if (faultTotal != 0 && !ObjectUtils.isEmpty(placeStatistics.getFaultNum()) && placeStatistics.getFaultNum() != 0) {
BigDecimal bigDecimal = new BigDecimal(placeStatistics.getFaultNum());
BigDecimal bigDecimal1 = new BigDecimal(faultTotal);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
placeStatistics.setFaultRate(decimalFormat.format(divide) + "%");
} else {
placeStatistics.setFaultRate("0%");
}
other.setTrappedNum(ObjectUtils.isEmpty(other.getTrappedNum()) ? placeStatistics.getTrappedNum() : other.getTrappedNum() + placeStatistics.getTrappedNum());
other.setFaultNum(ObjectUtils.isEmpty(other.getFaultNum()) ? placeStatistics.getFaultNum() : other.getFaultNum() + placeStatistics.getFaultNum());
list.add(placeStatistics);
}
});
}
if (!ObjectUtils.isEmpty(other.getTrappedNum())) {
other.setTrappedNum(trappedTotal - other.getTrappedNum());
}
if (!ObjectUtils.isEmpty(other.getFaultNum())) {
other.setFaultNum(faultTotal - other.getFaultNum());
}
if (trappedTotal != 0 && !ObjectUtils.isEmpty(other.getTrappedNum()) && other.getTrappedNum() != 0) {
BigDecimal bigDecimal = new BigDecimal(other.getTrappedNum());
BigDecimal bigDecimal1 = new BigDecimal(trappedTotal);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
other.setTrappedRate(decimalFormat.format(divide) + "%");
} else {
other.setTrappedRate("0%");
}
if (faultTotal != 0 && !ObjectUtils.isEmpty(other.getFaultNum()) && other.getFaultNum() != 0) {
BigDecimal bigDecimal = new BigDecimal(other.getFaultNum());
BigDecimal bigDecimal1 = new BigDecimal(faultTotal);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 4, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
other.setFaultRate(decimalFormat.format(divide) + "%");
} else {
other.setFaultRate("0%");
}
list.add(other);
if (!ObjectUtils.isEmpty(list)) {
this.saveBatch(list);
}
}
@Override
public List<AlertPlaceStatistics> placeList(String date) {
LambdaQueryWrapper<AlertPlaceStatistics> lambda = new QueryWrapper<AlertPlaceStatistics>().lambda();
lambda.eq(AlertPlaceStatistics::getStatisticsDate, date);
List<AlertPlaceStatistics> alertPlaceStatistics = this.baseMapper.selectList(lambda);
AlertPlaceStatistics placeStatistics = new AlertPlaceStatistics();
placeStatistics.setPlaceName("总 计");
if (!ObjectUtils.isEmpty(alertPlaceStatistics)){
alertPlaceStatistics.forEach(item ->{
placeStatistics.setTrappedNum(ObjectUtils.isEmpty(placeStatistics.getTrappedNum()) ? item.getTrappedNum(): placeStatistics.getTrappedNum() + item.getTrappedNum());
placeStatistics.setFaultNum(ObjectUtils.isEmpty(placeStatistics.getFaultNum()) ? item.getFaultNum(): placeStatistics.getFaultNum() + item.getFaultNum());
});
alertPlaceStatistics.add(placeStatistics);
}
return alertPlaceStatistics;
}
}
\ 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