Commit 7943cbaf authored by lisong's avatar lisong

添加96333统计生成接口

parent 5bcdf5f0
package com.yeejoin.amos.boot.module.elevator.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import com.yeejoin.amos.boot.biz.common.dto.BaseDto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
/**
*
*
* @author system_generator
* @date 2023-11-02
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value="AlertStatisticsDto", description="")
public class AlertStatisticsDto 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 elevatorNum;
@ApiModelProperty(value = "应急事件")
private Integer emergencyEvents;
@ApiModelProperty(value = "困人救援")
private Integer trappedPeople;
@ApiModelProperty(value = "故障救援")
private Integer breakdownRescue;
@ApiModelProperty(value = "故障救援")
private Integer rescuePersonnel;
@ApiModelProperty(value = "投诉建议")
private Integer complaint;
@ApiModelProperty(value = "故障率")
private Integer failureRate;
@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;
import java.util.Date;
/**
*
*
* @author system_generator
* @date 2023-11-02
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("tzs_alert_statistics")
public class AlertStatistics 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("elevator_num")
private Integer elevatorNum;
/**
* 应急事件
*/
@TableField("emergency_events")
private Integer emergencyEvents;
/**
* 困人救援
*/
@TableField("trapped_people")
private Integer trappedPeople;
/**
* 故障救援
*/
@TableField("breakdown_rescue")
private Integer breakdownRescue;
/**
* 解救人员
*/
@TableField("rescue_personnel")
private Integer rescuePersonnel;
/**
* 投诉建议
*/
@TableField("complaint")
private Integer complaint;
/**
* 故障率
*/
@TableField("failure_rate")
private String failureRate;
/**
* 统计日期
*/
@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.AlertStatistics;
import org.apache.ibatis.annotations.Param;
/**
* Mapper 接口
*
* @author system_generator
* @date 2023-11-02
*/
public interface AlertStatisticsMapper extends BaseMapper<AlertStatistics> {
AlertStatistics getStatissticsMessage(@Param("orgCode")String orgCode, @Param("startDate")String startDate , @Param("endDate")String endDate);
}
package com.yeejoin.amos.boot.module.elevator.api.service;
public interface IAlertStatisticsService {
void statisticalGeneration();
}
<?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.AlertStatisticsMapper">
<select id="getStatissticsMessage"
resultType="com.yeejoin.amos.boot.module.elevator.api.entity.AlertStatistics">
SELECT temp.*,
CASE
when temp.emergencyEventsAll = 0 then '0%'
when temp.elevatorNum = 0 then '0%'
else concat(round((temp.emergencyEventsAll - temp.complaint) / temp.elevatorNum * 100, 2),
'%') end AS failureRate,
(temp.emergencyEventsAll - temp.complaint) as emergencyEvents
FROM (
SELECT (
SELECT COUNT(1)
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%')) AS elevatorNum,
(SELECT COUNT(1)
FROM tz_alert_called
WHERE equipment_id IN (SELECT RECORD
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%') ) and call_time BETWEEN #{startDate} and #{endDate}) AS emergencyEventsAll,
(SELECT COUNT(1)
FROM tz_alert_called
WHERE alarm_type_code = '960'
AND equipment_id IN (SELECT RECORD
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%')) and call_time BETWEEN #{startDate} and #{endDate}) AS trappedPeople,
(SELECT COUNT(1)
FROM tz_alert_called
WHERE alarm_type_code = '961'
AND equipment_id IN (SELECT RECORD
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%')) and call_time BETWEEN #{startDate} and #{endDate}) AS breakdownRescue,
(SELECT COUNT(1)
FROM tz_alert_called
WHERE alarm_type_code = '962'
AND equipment_id IN (SELECT RECORD
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%')) and call_time BETWEEN #{startDate} and #{endDate}) AS complaint,
(
SELECT (
(
SELECT ifnull(SUM(field_value), 0)
FROM tz_alert_form_value
WHERE alert_called_id IN (
SELECT sequence_nbr
FROM tz_alert_called
WHERE equipment_id IN (
SELECT RECORD
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%')) and call_time BETWEEN #{startDate} and #{endDate})
AND field_code = 'trapped_num'
) - (
SELECT ifnull(SUM(field_value), 0)
FROM tz_alert_form_value
WHERE alert_called_id IN (
SELECT sequence_nbr
FROM tz_alert_called
WHERE equipment_id IN (
SELECT RECORD
FROM idx_biz_jg_supervision_info
WHERE ORG_BRANCH_CODE LIKE concat(#{orgCode}, '%')) and call_time BETWEEN #{startDate} and #{endDate})
AND field_code = 'die_num'
)
)) AS rescuePersonnel
) temp
</select>
</mapper>
package com.yeejoin.amos.boot.module.elevator.biz.controller;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.elevator.api.dto.TemplateDto;
import com.yeejoin.amos.boot.module.elevator.api.service.IAlertStatisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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.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;
@RestController
@Api(tags = "统计Api")
@RequestMapping(value = "/statistics")
public class StatisticsController extends BaseController {
@Autowired
private IAlertStatisticsService alertStatisticsService;
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/statisticalGeneration")
@ApiOperation(httpMethod = "GET", value = "生成统计数据", notes = "生成统计数据")
public ResponseModel<Object> statisticalGeneration() {
alertStatisticsService.statisticalGeneration();
return ResponseHelper.buildResponse("success");
}
}
package com.yeejoin.amos.boot.module.elevator.biz.service.impl;
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 org.springframework.beans.factory.annotation.Autowired;
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.text.SimpleDateFormat;
import java.util.*;
@Service
public class AlertStatisticsServiceImpl extends BaseService<AlertStatisticsDto, AlertStatistics, AlertStatisticsMapper> implements IAlertStatisticsService {
private static final String REGULATOR_UNIT_TREE = "REGULATOR_UNIT_TREE";
@Autowired
RedisUtils redisUtils;
@Override
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<AlertStatistics> list = new ArrayList<>();
List<LinkedHashMap> supervisionList = getSupervisionList();
if (!ObjectUtils.isEmpty(supervisionList)) {
supervisionList.forEach(item -> {
if (!ObjectUtils.isEmpty(item.get("orgCode"))) {
AlertStatistics statissticsMessage = this.getBaseMapper().getStatissticsMessage(String.valueOf(item.get("orgCode")), format.format(firstDayOfMonth) + " 00:00:00", format.format(lastDayOfMonth) + " 23:59:59");
statissticsMessage.setSupervisoryUnitName(String.valueOf(item.get("companyName")));
statissticsMessage.setSupervisoryUnitOrgCode(String.valueOf(item.get("orgCode")));
statissticsMessage.setSupervisoryUnitId(String.valueOf(item.get("sequenceNbr")));
statissticsMessage.setStartDate(format.format(firstDayOfMonth));
statissticsMessage.setEndDate(format.format(lastDayOfMonth));
statissticsMessage.setStatisticsDate(format.format(lastDayOfMonth).substring(0, 7));
list.add(statissticsMessage);
}
});
}
this.saveBatch(list);
}
private 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");
}
return data;
}
}
\ 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