Commit 36e3a04e authored by lisong's avatar lisong

添加监控中心统计查询、导出接口

parent 2358b46b
package com.yeejoin.amos.boot.module.elevator.api.entity;
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;
......@@ -32,6 +34,8 @@ public class AlertStatistics extends BaseEntity {
* 监管单位名称
*/
@TableField("supervisory_unit_name")
@ColumnWidth(30)
@ExcelProperty(value = "区 域", index = 0)
private String supervisoryUnitName;
/**
......@@ -44,6 +48,7 @@ public class AlertStatistics extends BaseEntity {
* 电梯总数
*/
@TableField("elevator_num")
@ExcelProperty(value = "电梯总数(台)", index = 1)
private Integer elevatorNum;
/**
......@@ -68,18 +73,21 @@ public class AlertStatistics extends BaseEntity {
* 解救人员
*/
@TableField("rescue_personnel")
@ExcelProperty(value = "解救被困人员(起)", index = 5)
private Integer rescuePersonnel;
/**
* 投诉建议
*/
@TableField("complaint")
@ExcelProperty(value = "投诉建议(条)", index = 6)
private Integer complaint;
/**
* 故障率
*/
@TableField("failure_rate")
@ExcelProperty(value = "电梯故障率", index = 7)
private String failureRate;
/**
......@@ -100,4 +108,15 @@ public class AlertStatistics extends BaseEntity {
@TableField("end_date")
private String endDate;
@ExcelProperty(value = "电梯应急总事件(起)", index = 2)
@TableField(exist = false)
private String avgDaysEmergencyEvents;
@ExcelProperty(value = "困 人(起)", index = 3)
@TableField(exist = false)
private String avgDaysTrappedPeople;
@ExcelProperty(value = "故 障(起)", index = 4)
@TableField(exist = false)
private String avgDaysBreakdownRescue;
}
package com.yeejoin.amos.boot.module.elevator.api.service;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertStatistics;
import java.text.ParseException;
import java.util.List;
public interface IAlertStatisticsService {
void statisticalGeneration();
List<AlertStatistics> getList(String date) throws ParseException;
}
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 {
@ExcelProperty(value = "序号", index = 0)
private Integer number;
/**
* 监管单位名称
*/
@ColumnWidth(30)
@ExcelProperty(value = "区 域", index = 1)
private String supervisoryUnitName;
/**
* 电梯总数
*/
@TableField("elevator_num")
@ExcelProperty(value = "电梯总数(台)", index = 2)
private Integer elevatorNum;
@ExcelProperty(value = "电梯应急总事件(起)", index = 3)
private String avgDaysEmergencyEvents;
@ExcelProperty(value = "困 人(起)", index = 4)
private String avgDaysTrappedPeople;
@ExcelProperty(value = "故 障(起)", index = 5)
private String avgDaysBreakdownRescue;
/**
* 解救人员
*/
@ExcelProperty(value = "解救被困人员(起)", index = 6)
private Integer rescuePersonnel;
/**
* 投诉建议
*/
@ExcelProperty(value = "投诉建议(条)", index = 7)
private Integer complaint;
/**
* 故障率
*/
@ExcelProperty(value = "电梯故障率", index = 8)
private String failureRate;
}
package com.yeejoin.amos.boot.module.elevator.biz.controller;
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.module.elevator.api.dto.TemplateDto;
import com.yeejoin.amos.boot.biz.common.excel.ExcelUtil;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertStatistics;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertStatisticsService;
import com.yeejoin.amos.boot.module.elevator.api.vo.AlertStatisticsExportVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@RestController
@Api(tags = "统计Api")
......@@ -31,4 +44,46 @@ public class StatisticsController extends BaseController {
alertStatisticsService.statisticalGeneration();
return ResponseHelper.buildResponse("success");
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getList")
@ApiOperation(httpMethod = "GET", value = "查询统计信息", notes = "查询统计信息")
public ResponseModel<Object> getList(@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);
}
Page<AlertStatistics> alertStatisticsPage = new Page<>();
alertStatisticsPage.setRecords(alertStatisticsService.getList(date));
return ResponseHelper.buildResponse(alertStatisticsPage);
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/exportData")
@ApiOperation(httpMethod = "GET", value = "监管单位统计信息导出", notes = "监管单位统计信息导出")
public void exportData(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<AlertStatisticsExportVo> exportVos = new ArrayList<>();
List<AlertStatistics> list = alertStatisticsService.getList(date);
int number = 1;
for (AlertStatistics item : list) {
AlertStatisticsExportVo vo = new AlertStatisticsExportVo();
BeanUtil.copyProperties(item, vo);
vo.setNumber(number);
number = number + 1;
exportVos.add(vo);
}
ExcelUtil.createTemplate(response, "各地监控中心电梯月度情况综述", "各地监控中心电梯月度情况综述", exportVos, AlertStatisticsExportVo.class, null, false);
}
}
package com.yeejoin.amos.boot.module.elevator.biz.service.impl;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.elevator.api.common.BizCommonConstant;
import com.yeejoin.amos.boot.module.elevator.api.dto.AlertStatisticsDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.AlertStatistics;
import com.yeejoin.amos.boot.module.elevator.api.mapper.AlertStatisticsMapper;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertStatisticsService;
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.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
......@@ -27,6 +33,8 @@ public class AlertStatisticsServiceImpl extends BaseService<AlertStatisticsDto,
@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();
......@@ -63,4 +71,73 @@ public class AlertStatisticsServiceImpl extends BaseService<AlertStatisticsDto,
}
return data;
}
@Override
public List<AlertStatistics> getList(String date) throws ParseException {
LambdaQueryWrapper<AlertStatistics> lambda = new QueryWrapper<AlertStatistics>().lambda();
lambda.eq(AlertStatistics::getStatisticsDate, date);
List<AlertStatistics> alertStatistics = this.getBaseMapper().selectList(lambda);
AlertStatistics statistics = new AlertStatistics();
String startDate = null;
String endDate = null;
for (AlertStatistics item : alertStatistics) {
if (ObjectUtils.isEmpty(startDate)) {
startDate = item.getStartDate();
}
if (ObjectUtils.isEmpty(endDate)) {
endDate = item.getEndDate();
}
item.setAvgDaysEmergencyEvents(String.valueOf(item.getEmergencyEvents()));
item.setAvgDaysBreakdownRescue(String.valueOf(item.getBreakdownRescue()));
item.setAvgDaysTrappedPeople(String.valueOf(item.getTrappedPeople()));
statistics.setElevatorNum(ObjectUtils.isEmpty(statistics.getElevatorNum()) ? item.getElevatorNum() : item.getElevatorNum() + statistics.getElevatorNum());
statistics.setEmergencyEvents(ObjectUtils.isEmpty(statistics.getEmergencyEvents()) ? item.getEmergencyEvents() : item.getEmergencyEvents() + statistics.getEmergencyEvents());
statistics.setTrappedPeople(ObjectUtils.isEmpty(statistics.getTrappedPeople()) ? item.getTrappedPeople() : item.getTrappedPeople() + statistics.getTrappedPeople());
statistics.setBreakdownRescue(ObjectUtils.isEmpty(statistics.getBreakdownRescue()) ? item.getBreakdownRescue() : item.getBreakdownRescue() + statistics.getBreakdownRescue());
statistics.setRescuePersonnel(ObjectUtils.isEmpty(statistics.getRescuePersonnel()) ? item.getRescuePersonnel() : item.getRescuePersonnel() + statistics.getRescuePersonnel());
statistics.setComplaint(ObjectUtils.isEmpty(statistics.getComplaint()) ? item.getComplaint() : item.getComplaint() + statistics.getComplaint());
statistics.setAvgDaysEmergencyEvents(ObjectUtils.isEmpty(statistics.getEmergencyEvents()) ? String.valueOf(item.getEmergencyEvents()) : String.valueOf(item.getEmergencyEvents() + statistics.getEmergencyEvents()));
statistics.setAvgDaysTrappedPeople(ObjectUtils.isEmpty(statistics.getTrappedPeople()) ? String.valueOf(item.getTrappedPeople()) : String.valueOf(item.getTrappedPeople() + statistics.getTrappedPeople()));
statistics.setAvgDaysBreakdownRescue(ObjectUtils.isEmpty(statistics.getBreakdownRescue()) ? String.valueOf(item.getBreakdownRescue()) : String.valueOf(item.getBreakdownRescue() + statistics.getBreakdownRescue()));
}
statistics.setSupervisoryUnitName("合计");
DecimalFormat decimalFormat = new DecimalFormat("0.000");
DecimalFormat decimalFormatAvg = new DecimalFormat("0.0");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
if (ObjectUtils.isEmpty(statistics.getEmergencyEvents()) || ObjectUtils.isEmpty(statistics.getElevatorNum()) || statistics.getEmergencyEvents() == 0 || statistics.getElevatorNum() == 0) {
statistics.setFailureRate("0%");
} else {
BigDecimal bigDecimal = new BigDecimal(statistics.getEmergencyEvents().toString());
BigDecimal bigDecimal1 = new BigDecimal(statistics.getElevatorNum().toString());
BigDecimal divide = bigDecimal.divide(bigDecimal1, 6, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal("100"));
statistics.setFailureRate(decimalFormat.format(divide) + "%");
}
alertStatistics.add(statistics);
AlertStatistics avg = new AlertStatistics();
avg.setSupervisoryUnitName("平均每天");
long days = DateUtil.betweenDay(simpleDateFormat.parse(startDate), simpleDateFormat.parse(endDate), true);
int avgNum = Integer.parseInt(String.valueOf(days));
if (!ObjectUtils.isEmpty(statistics.getEmergencyEvents()) && statistics.getEmergencyEvents() != 0 && avgNum != 0) {
BigDecimal bigDecimal = new BigDecimal(statistics.getEmergencyEvents().toString());
BigDecimal bigDecimal1 = new BigDecimal(avgNum);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 6, BigDecimal.ROUND_HALF_UP);
avg.setAvgDaysEmergencyEvents(decimalFormatAvg.format(divide));
}
if (!ObjectUtils.isEmpty(statistics.getTrappedPeople()) && statistics.getTrappedPeople() != 0 && avgNum != 0) {
BigDecimal bigDecimal = new BigDecimal(statistics.getTrappedPeople().toString());
BigDecimal bigDecimal1 = new BigDecimal(avgNum);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 6, BigDecimal.ROUND_HALF_UP);
avg.setAvgDaysTrappedPeople(decimalFormatAvg.format(divide));
}
if (!ObjectUtils.isEmpty(statistics.getBreakdownRescue()) && statistics.getBreakdownRescue() != 0 && avgNum != 0) {
BigDecimal bigDecimal = new BigDecimal(statistics.getBreakdownRescue().toString());
BigDecimal bigDecimal1 = new BigDecimal(avgNum);
BigDecimal divide = bigDecimal.divide(bigDecimal1, 6, BigDecimal.ROUND_HALF_UP);
avg.setAvgDaysBreakdownRescue(decimalFormatAvg.format(divide));
}
alertStatistics.add(avg);
return alertStatistics;
}
}
\ 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