Commit 627b1b50 authored by suhuiguang's avatar suhuiguang

1.大屏-概览-右屏使用登记统计

parent e6f2a499
package com.yeejoin.amos.boot.module.common.api.dto;
import lombok.Data;
import javax.validation.constraints.NotBlank;
/**
* 大屏筛选过滤对象
*
* @author Administrator
*/
@Data
public class DPFilterParamDto {
/**
* 区域
*/
@NotBlank(message = "区域编码不能为空!")
private String cityCode;
/**
* 数据统计的开始日期
*/
private String beginDate;
/**
* 数据统计的结束日期
*/
private String endDate;
}
package com.yeejoin.amos.boot.module.common.api.dto;
import lombok.Builder;
import lombok.Data;
/**
* @author Administrator
*/
@Data
@Builder
public class LegendDataDto {
/**
* 唯一标识code
*/
private String dataKey;
/**
* 图列名称
*/
private String value;
}
package com.yeejoin.amos.boot.module.jg.api.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Administrator
*/
@Data
@ApiModel
public class EquipBizCountDto {
@ApiModelProperty(value = "设备种类code")
private String equList;
@ApiModelProperty(value = "设备类别code")
private String equCategory;
@ApiModelProperty(value = "设备品种code")
private String equipDefine;
@ApiModelProperty(value = "次数")
private Integer num;
@ApiModelProperty(value = "区域信息省#市#区,按照#分割")
private String areaCode;
}
package com.yeejoin.amos.boot.module.jg.api.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.JgEnableDisableDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgEnableDisable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
/**
......@@ -24,4 +27,6 @@ public interface JgEnableDisableMapper extends BaseMapper<JgEnableDisable> {
@Param("userId") String userId);
Map<String, Object> getDetail(@Param("sequenceNbr") Long sequenceNbr);
List<EquipBizCountDto> queryStoppedDeviceStaticListData(DPFilterParamDto dpFilterParamDto);
}
......@@ -2,6 +2,8 @@ package com.yeejoin.amos.boot.module.jg.api.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.JgScrapCancelDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgScrapCancel;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
......@@ -43,4 +45,5 @@ public interface JgScrapCancelMapper extends BaseMapper<JgScrapCancel> {
*/
Map<String, Object> queryEquipInformation(@Param("sequenceNbr") long sequenceNbr);
List<EquipBizCountDto> queryScrappedDeviceStaticListData(DPFilterParamDto dpFilterParamDto);
}
......@@ -3,7 +3,9 @@ package com.yeejoin.amos.boot.module.jg.api.mapper;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jg.api.dto.CompanyEquipCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto;
import com.yeejoin.amos.boot.module.jg.api.dto.JgUseRegistrationDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistration;
import com.yeejoin.amos.boot.module.jg.api.vo.SortVo;
......@@ -75,4 +77,6 @@ public interface JgUseRegistrationMapper extends BaseMapper<JgUseRegistration> {
@Select("select name from tz_equipment_category where code=#{code}")
String getEquCategoryNameByCode(String code);
List<EquipBizCountDto> queryNewDeviceStaticListData(DPFilterParamDto dpFilterParamDto);
}
......@@ -115,4 +115,40 @@
LEFT JOIN idx_biz_jg_use_info use on jede.equ_id = use.RECORD
where jed.sequence_nbr = #{sequenceNbr}
</select>
<select id="queryStoppedDeviceStaticListData"
resultType="com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto">
select
c.equ_list,
c.equ_category,
c.equ_define,
count(1) as num
from
(SELECT
ri.equ_list,
ri.equ_category,
ri.equ_define,
concat(u.PROVINCE,'#', u.CITY,'#', u.COUNTY) as areaCode
FROM
"tzs_jg_enable_disable_eq" ae,
tzs_jg_enable_disable a,
"idx_biz_jg_use_info" u,
idx_biz_jg_register_info ri
where
a.sequence_nbr = ae.enable_disable_apply_id
and ae.equ_id = u."RECORD"
and u."RECORD" = ri."RECORD"
and (a.audit_pass_date between #{beginDate} and #{endDate})
and a.apply_type ='SB_TY'
and a.audit_status='已完成'
and u."PROVINCE" <![CDATA[<>]]> ''
and u."CITY" <![CDATA[<>]]> ''
and u."COUNTY" <![CDATA[<>]]> ''
) c
where
c.areaCode like concat('%',#{cityCode}, '%')
group by
c.equ_list,
c.equ_category,
c.equ_define
</select>
</mapper>
......@@ -253,4 +253,40 @@
WHERE ur.sequence_nbr = #{sequenceNbr}
LIMIT 1
</select>
<select id="queryScrappedDeviceStaticListData"
resultType="com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto">
select
c.equ_list,
c.equ_category,
c.equ_define,
count(1) as num
from
(SELECT
ri.equ_list,
ri.equ_category,
ri.equ_define,
concat(u.PROVINCE,'#', u.CITY,'#', u.COUNTY) as areaCode
FROM
"tzs_jg_scrap_cancel_eq" ae,
tzs_jg_scrap_cancel a,
"idx_biz_jg_use_info" u,
idx_biz_jg_register_info ri
where
a.sequence_nbr = ae.equip_transfer_id
and ae.equ_id = u."RECORD"
and u."RECORD" = ri."RECORD"
and (a.audit_pass_date between #{beginDate} and #{endDate})
and a.cancel_type ='1'
and a.audit_status='已完成'
and u."PROVINCE" <![CDATA[<>]]> ''
and u."CITY" <![CDATA[<>]]> ''
and u."COUNTY" <![CDATA[<>]]> ''
) c
where
c.areaCode like concat('%',#{cityCode}, '%')
group by
c.equ_list,
c.equ_category,
c.equ_define
</select>
</mapper>
......@@ -557,4 +557,39 @@
LEFT JOIN idx_biz_jg_register_info jri ON re.equ_id = jri.RECORD
where ur.sequence_nbr = #{sequenceNbr}
</select>
<select id="queryNewDeviceStaticListData"
resultType="com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto">
select
c.equ_list,
c.equ_category,
c.equ_define,
count(1) as num
from
(SELECT
ri.equ_list,
ri.equ_category,
ri.equ_define,
concat(u.PROVINCE,'#', u.CITY,'#', u.COUNTY) as areaCode
FROM
"tzs_jg_use_registration_eq" ae,
tzs_jg_use_registration a,
"idx_biz_jg_use_info" u,
idx_biz_jg_register_info ri
where
ae.equ_id = u."RECORD"
and a.sequence_nbr = ae.equip_transfer_id
and u."RECORD" = ri."RECORD"
and (a.audit_pass_date between #{beginDate} and #{endDate})
and a.status='已完成'
and u."PROVINCE" <![CDATA[<>]]> ''
and u."CITY" <![CDATA[<>]]> ''
and u."COUNTY" <![CDATA[<>]]> ''
) c
where
c.areaCode like concat('%',#{cityCode}, '%')
group by
c.equ_list,
c.equ_category,
c.equ_define
</select>
</mapper>
package com.yeejoin.amos.boot.module.jg.biz.controller;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jg.biz.service.impl.DPStatisticsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.exception.instance.BadRequest;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List;
import java.util.Map;
/**
* 大屏统计controller
*
* @author Administrator
*/
@RestController
@RequestMapping("/db/statistics")
@Api(tags = "大屏统计")
public class DPStatisticsController {
private DPStatisticsServiceImpl statisticsService;
public DPStatisticsController(DPStatisticsServiceImpl statisticsService) {
this.statisticsService = statisticsService;
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST", value = "大屏总览右侧-使用登记统计", notes = "大屏总览右侧-使用登记统计")
@PostMapping(value = "/useRegister/count/byEquList")
public ResponseModel<Map<String, Object>> useRegisterCountByEquList(@Validated @RequestBody DPFilterParamDto dpFilterParamDto, BindingResult result) {
List<FieldError> fieldErrors = result.getFieldErrors();
if(!fieldErrors.isEmpty()){
throw new BadRequest(fieldErrors.get(0).getDefaultMessage());
}
return ResponseHelper.buildResponse(statisticsService.useRegisterCountByEquList(dpFilterParamDto));
}
}
package com.yeejoin.amos.boot.module.jg.biz.service.impl;
import cn.hutool.core.date.DateUtil;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.common.api.dto.LegendDataDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipBizCountDto;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgEnableDisableMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgScrapCancelMapper;
import com.yeejoin.amos.boot.module.jg.api.mapper.JgUseRegistrationMapper;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.ymt.api.mapper.EquipmentCategoryMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 大屏统计实现类
*
* @author Administrator
*/
@Service
public class DPStatisticsServiceImpl {
/**
* 压力容器设备种类
*/
private final static String EQU_LIST_CYLINDER = "2000";
/**
* 气瓶设备类别
*/
private final static String EQU_CATEGORY_CYLINDER = "2300";
private EquipmentCategoryMapper equipmentCategoryMapper;
private JgUseRegistrationMapper useRegistrationMapper;
private JgEnableDisableMapper enableDisableMapper;
private JgScrapCancelMapper scrapCancelMapper;
public DPStatisticsServiceImpl(EquipmentCategoryMapper equipmentCategoryMapper, JgUseRegistrationMapper useRegistrationMapper, JgEnableDisableMapper enableDisableMapper, JgScrapCancelMapper scrapCancelMapper) {
this.equipmentCategoryMapper = equipmentCategoryMapper;
this.useRegistrationMapper = useRegistrationMapper;
this.enableDisableMapper = enableDisableMapper;
this.scrapCancelMapper = scrapCancelMapper;
}
public Map<String, Object> useRegisterCountByEquList(DPFilterParamDto dpFilterParamDto) {
// 1.查询条件构造未上送时间时,默认查询数据为近一个月数据
this.setDefaultFilter(dpFilterParamDto);
// 2.按照前端约定格式返回数据
Map<String, Object> result = new HashMap<>();
List<LegendDataDto> legendDataDtos = this.buildLegendDataList();
//2.1 图列数据构造
result.put("legendData", legendDataDtos);
// 8大类设备种类
List<EquipmentCategoryDto> equipmentCategoryDtos = equipmentCategoryMapper.selectClassify();
//2.2 x轴数据构造
result.put("xdata", this.getXData(equipmentCategoryDtos));
//2.3 y轴数据构造
this.buildYData(result, legendDataDtos, dpFilterParamDto, equipmentCategoryDtos);
return result;
}
private List<LegendDataDto> buildLegendDataList() {
List<LegendDataDto> legendDataDtos = new ArrayList<>();
legendDataDtos.add(LegendDataDto.builder().dataKey("newDevice").value("新增登记设备 (万)").build());
legendDataDtos.add(LegendDataDto.builder().dataKey("stoppedDevice").value("报停设备 (万)").build());
legendDataDtos.add(LegendDataDto.builder().dataKey("scrappedDevice").value("报废设备 (万)").build());
return legendDataDtos;
}
private void buildYData(Map<String, Object> result, List<LegendDataDto> legendDataDtos, DPFilterParamDto dpFilterParamDto, List<EquipmentCategoryDto> equipmentCategoryDtos) {
// 待统计的数据本来sql可以单独统计,但是要求气瓶单独从压力容器里拎出来,与八大类同级,故java处理
// 1.新增登记统计
result.put("newDevice", this.getNewDeviceCountData(dpFilterParamDto, equipmentCategoryDtos));
// 2.新增报停设备统计
result.put("stoppedDevice", this.getStoppedDeviceCountData(dpFilterParamDto, equipmentCategoryDtos));
// 3.新增报废设备统计
result.put("scrappedDevice", this.getScrappedDeviceCountData(dpFilterParamDto, equipmentCategoryDtos));
}
private List<Integer> getNewDeviceCountData(DPFilterParamDto dpFilterParamDto, List<EquipmentCategoryDto> equipmentCategoryDtos) {
List<EquipBizCountDto> staticsData = useRegistrationMapper.queryNewDeviceStaticListData(dpFilterParamDto);
return countNumByEquList(equipmentCategoryDtos, staticsData);
}
private List<Integer> getStoppedDeviceCountData(DPFilterParamDto dpFilterParamDto, List<EquipmentCategoryDto> equipmentCategoryDtos) {
List<EquipBizCountDto> staticsData = enableDisableMapper.queryStoppedDeviceStaticListData(dpFilterParamDto);
return countNumByEquList(equipmentCategoryDtos, staticsData);
}
private List<Integer> getScrappedDeviceCountData(DPFilterParamDto dpFilterParamDto, List<EquipmentCategoryDto> equipmentCategoryDtos) {
List<EquipBizCountDto> staticsData = scrapCancelMapper.queryScrappedDeviceStaticListData(dpFilterParamDto);
return countNumByEquList(equipmentCategoryDtos, staticsData);
}
private List<Integer> countNumByEquList(List<EquipmentCategoryDto> equipmentCategoryDtos, List<EquipBizCountDto> bizCountDtos) {
List<Integer> lineData = new ArrayList<>();
// 8大类数据统计数量
equipmentCategoryDtos.forEach(equipmentCategoryDto -> {
int num = 0;
// 压力容器要去掉气瓶2300,气瓶单独统计
if (EQU_LIST_CYLINDER.equals(equipmentCategoryDto.getCode())) {
num = bizCountDtos.stream().filter(c -> c.getEquList().equals(equipmentCategoryDto.getCode()) && !EQU_CATEGORY_CYLINDER.equals(c.getEquCategory())).mapToInt(EquipBizCountDto::getNum).sum();
} else {
num = bizCountDtos.stream().filter(c -> c.getEquList().equals(equipmentCategoryDto.getCode())).mapToInt(EquipBizCountDto::getNum).sum();
}
lineData.add(num);
});
// 再增加气瓶(设备类别2300)专项
int num = bizCountDtos.stream().filter(c -> EQU_CATEGORY_CYLINDER.equals(c.getEquCategory())).mapToInt(EquipBizCountDto::getNum).sum();
lineData.add(num);
return lineData;
}
private List<String> getXData(List<EquipmentCategoryDto> equipmentCategoryDtos) {
// 8大类 + 气瓶 注意数据顺序和要和这个x轴一致
List<String> names = equipmentCategoryDtos.stream().map(EquipmentCategoryDto::getName).collect(Collectors.toList());
names.add("气瓶");
return names;
}
private void setDefaultFilter(DPFilterParamDto dpFilterParamDto) {
if (StringUtils.isEmpty(dpFilterParamDto.getBeginDate())) {
dpFilterParamDto.setBeginDate(DateUtil.lastMonth().toDateStr());
}
if (StringUtils.isEmpty(dpFilterParamDto.getEndDate())) {
dpFilterParamDto.setEndDate(DateUtil.today());
}
}
}
package com.yeejoin.amos.boot.module.jyjc.biz.controller;
import com.yeejoin.amos.boot.module.jyjc.api.model.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jyjc.biz.service.DPStatisticsServiceImpl;
import com.yeejoin.amos.boot.module.jyjc.biz.service.impl.DPStatisticsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.BindingResult;
......
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