Commit 16c743b9 authored by tianbo's avatar tianbo

feat(statistics): 优化统计查询逻辑并调整SQL结构

- 修改 CommonBaseMapper.xml,增加 company_code 非空条件过滤脏数据 - 在 JGDPStatisticsServiceImpl.java 中引入 ConcurrentHashMap 缓存区域机构代码列表 - 新增 getOrgCodeListByRegionCode 方法用于获取缓存或查询机构代码列表 - 替换原有的 regionCode 查询参数为 orgCode 参数传递方式 - 更新各类统计方法实现,统一使用 orgCode 查询替代 cityCode - 调整 mapper 接口定义,删除按年/月拆分的查询接口,合并为时间段查询接口 - 重写 JGStatisticsMapper.xml 中 SQL 查询逻辑,使用 supervision_info 表关联 - 引入公用 SQL 片段 maintenanceCountSql 提高复用性 - 删除冗余 vehicleEquCount 相关查询方法及实现 - 使用 audit_pass_date 字段代替 rec_date 提高准确性 - 统一时间筛选条件格式并支持动态起止时间范围查询 - 添加 FieldMapping 注解支持 cityCode 到 companyCodes 的字段映射转换
parent 7bf0b204
package com.yeejoin.amos.boot.module.statistics.api.mapper;
import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.dto.CountDto;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
......@@ -11,42 +12,36 @@ import java.util.Map;
public interface JGStatisticsMapper {
List<Map<String, Object>> maintenanceCountTopTen(@Param("dpFilterParamDto") DPFilterParamDto dpFilterParamDto, @Param("regionCodeList") List<Integer> regionCodeList);
List<Map<String, Object>> maintenanceCountTopTen(@Param("orgCodeList") List<String> orgCodeList);
List<Map<String, Object>> maintenanceCount(@Param("dpFilterParamDto") DPFilterParamDto dpFilterParamDto, @Param("regionCodeList") List<Integer> regionCodeList);
List<Map<String, Object>> maintenanceCount(@Param("orgCodeList") List<String> orgCodeList);
List<Map<String, Object>> installEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> installEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> maintenanceEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> maintenanceEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> reformEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> reformEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> transferEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> transferEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> useEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> useEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> changeReformEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> changeReformEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> changeTransferEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> changeTransferEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> changeUnitEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> changeUnitEquCount(@Param("orgCode") String orgCode, @Param("startTime") String startTime);
List<Map<String, Object>> vehicleEquCount(@Param("cityCode") String cityCode, @Param("startTime") String startTime);
List<Map<String, Object>> newRegEquCountByMonth(@Param("orgCode") String orgCode);
List<Map<String, Object>> newRegEquCountByMonth(@Param("cityCode") String cityCode);
List<Map<String, Object>> newVehicleEquCountByMonth(@Param("orgCode") String orgCode);
List<Map<String, Object>> newVehicleEquCountByMonth(@Param("cityCode") String cityCode);
List<Map<String, Object>> newRegEquCountByPeriod(@Param("orgCode") String orgCode, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
List<Map<String, Object>> newRegEquCountByYear(@Param("cityCode") String cityCode);
List<Map<String, Object>> newRegEquCountByLastYear(@Param("cityCode") String cityCode);
List<Map<String, Object>> newVehicleEquCountByPeriod(@Param("orgCode") String orgCode, @Param("startTime") DateTime startTime, @Param("endTime") DateTime endTime);
List<Map<String, Object>> newVehicleEquCountByYear(@Param("cityCode") String cityCode);
List<Map<String, Object>> newVehicleEquCountByLastYear(@Param("cityCode") String cityCode);
String newVehicleCountByYear(@Param("cityCode") String cityCode);
String newVehicleCountByMonth(@Param("cityCode") String cityCode);
String newVehicleCountByPeriod(@Param("dto") DPFilterParamDto dpFilterParamDto, @Param("startTime") DateTime startTime);
long certificateCountByOrgCode(@Param("orgCode") String orgCode);
......@@ -104,5 +99,7 @@ public interface JGStatisticsMapper {
Page<Map<String, Object>> noticeCountTopPageNew(@Param("page") Page<Map<String, Object>> page, @Param("dpFilterParamForDetailDto") DPFilterParamForDetailDto dpFilterParamForDetailDto);
List<String> getOrgCodeListByRegionCode(@Param("regionCode") String regionCode);
List<Map<String, Object>> noticeCountTopPageByUseUnitCode(@Param("unitCodeList") List<String> unitCodeList, @Param("dto") DPFilterParamForDetailDto dto);
}
......@@ -30,6 +30,7 @@
FROM privilege_company
WHERE region_seq = #{regionSeq}
and (level != 'company' and level != 'organization')
and company_code is not null
UNION ALL
SELECT
c.sequence_nbr,
......@@ -41,6 +42,7 @@
INNER JOIN company_tree ct ON c.parent_id = ct.sequence_nbr
WHERE NOT (c.sequence_nbr = ANY(ct.path))
and (c.level != 'company' and c.level != 'organization')
and c.company_code is not null
)
SELECT
company_code companyCode
......
......@@ -2,347 +2,219 @@
<!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.statistics.api.mapper.JGStatisticsMapper">
<sql id="maintenanceCountSql">
WITH orgCode_table AS (
select org_code
FROM UNNEST(ARRAY[
<foreach collection="orgCodeList" item="code" separator=",">
#{code}
</foreach>]) AS org_code
)
SELECT COUNT(1),
pt.org_code,
(select company_name from privilege_company where org_code = pt.org_code) companyName,
(select company_code from privilege_company where org_code = pt.org_code) companyCode
FROM tzs_jg_maintenance_contract mc
INNER JOIN tzs_jg_maintenance_contract_eq eq ON eq.equip_transfer_id = mc.sequence_nbr
INNER JOIN idx_biz_jg_supervision_info si ON si."RECORD" = eq.equ_id
INNER JOIN orgCode_table pt ON si."ORG_BRANCH_CODE" LIKE pt.org_code || '%'
WHERE mc.status = '已完成'
GROUP BY pt.org_code
ORDER BY COUNT DESC
</sql>
<select id="maintenanceCountTopTen" resultType="java.util.Map">
SELECT
COUNT(1),
pc.company_name AS companyName,
pc.company_code AS companyCode
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN ( SELECT DISTINCT record, ME_UNIT_CREDIT_CODE FROM idx_biz_jg_maintenance_record_info ) AS jri ON jri.ME_UNIT_CREDIT_CODE = bi.use_unit_code
WHERE
pc.company_code IN
<foreach collection="regionCodeList" item="item" open="(" separator="," close=")">
#{item} :: VARCHAR
</foreach>
GROUP BY
pc.company_code
ORDER BY
COUNT DESC
LIMIT 10;
<include refid="maintenanceCountSql" />
LIMIT 10;
</select>
<select id="maintenanceCount" resultType="java.util.Map">
SELECT
COUNT(1),
pc.company_name AS companyName,
pc.company_code AS companyCode
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN ( SELECT DISTINCT record, ME_UNIT_CREDIT_CODE FROM idx_biz_jg_maintenance_record_info ) AS jri ON jri.ME_UNIT_CREDIT_CODE = bi.use_unit_code
WHERE
pc.company_code IN
<foreach collection="regionCodeList" item="item" open="(" separator="," close=")">
#{item} :: VARCHAR
</foreach>
GROUP BY
pc.company_code
<include refid="maintenanceCountSql" />
</select>
<select id="installEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_installation_notice T ON T.use_unit_credit_code = bi.use_unit_code
AND T.notice_status = 6616
INNER JOIN tzs_jg_installation_notice_eq te ON te.equip_transfer_id = T.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and T.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_installation_notice T
INNER JOIN tzs_jg_installation_notice_eq te ON te.equip_transfer_id = T.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE T.notice_status = 6616
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and T.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="maintenanceEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_maintain_notice tn ON tn.use_unit_credit_code = bi.use_unit_code
AND tn.notice_status = 6616
INNER JOIN tzs_jg_maintain_notice_eq te ON te.equip_transfer_id = tn.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and tn.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_maintain_notice tn
INNER JOIN tzs_jg_maintain_notice_eq te ON te.equip_transfer_id = tn.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE tn.notice_status = 6616
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and tn.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="reformEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_reform_notice tn ON tn.use_unit_credit_code = bi.use_unit_code
AND tn.notice_status = 6616
INNER JOIN tzs_jg_reform_notice_eq te ON te.equip_transfer_id = tn.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and tn.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_reform_notice tn
INNER JOIN tzs_jg_reform_notice_eq te ON te.equip_transfer_id = tn.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE tn.notice_status = 6616
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and tn.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="transferEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_transfer_notice tn ON tn.use_unit_credit_code = bi.use_unit_code
AND tn.notice_status = 6616
INNER JOIN tzs_jg_transfer_notice_eq te ON te.equip_transfer_id = tn.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and tn.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_transfer_notice tn
INNER JOIN tzs_jg_transfer_notice_eq te ON te.equip_transfer_id = tn.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE tn.notice_status = 6616
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and tn.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="useEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_use_registration ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and ur.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_use_registration ur
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and ur.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="changeReformEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_change_registration_reform ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.audit_status = '已完成'
INNER JOIN tzs_jg_change_registration_reform_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and ur.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_change_registration_reform ur
INNER JOIN tzs_jg_change_registration_reform_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.audit_status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and ur.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="changeTransferEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_change_registration_transfer ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.audit_status = '已完成'
INNER JOIN tzs_jg_change_registration_transfer_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and ur.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_change_registration_transfer ur
INNER JOIN tzs_jg_change_registration_transfer_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.audit_status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and ur.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="changeUnitEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_change_registration_unit ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_change_registration_unit_eq te ON te.unit_change_registration_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and ur.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
</select>
<select id="vehicleEquCount" resultType="java.util.Map">
SELECT COUNT
( 1 ),
jri.equ_list AS equList,
jri.equ_category AS equCategory
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_vehicle_information ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_vehicle_information_eq te ON te.vehicle_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri.record
WHERE
pc.company_code = #{cityCode} and ur.rec_date &gt;= #{startTime}
GROUP BY
jri.equ_category
(1),
jri."EQU_LIST" AS equList,
jri."EQU_CATEGORY" AS equCategory
FROM tzs_jg_change_registration_unit ur
INNER JOIN tzs_jg_change_registration_unit_eq te ON te.unit_change_registration_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_register_info jri ON te.equ_id = jri."RECORD"
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
and ur.rec_date &gt;= #{startTime}
GROUP BY jri."EQU_CATEGORY"
</select>
<select id="newRegEquCountByMonth" resultType="java.util.Map">
SELECT COUNT
( 1 ) ,
DATE_FORMAT(ur.rec_date,'%Y-%m-%d')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_use_registration ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(CURDATE(), '%Y-%m') ,'%')
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m-%d')
ORDER BY
ur.rec_date
(1),
TO_CHAR(ur.audit_pass_date, 'YYYY-MM-DD')
FROM tzs_jg_use_registration ur
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
AND ur.audit_pass_date >= DATE_TRUNC('month', CURRENT_DATE)
GROUP BY TO_CHAR(ur.audit_pass_date, 'YYYY-MM-DD')
ORDER BY ur.audit_pass_date
</select>
<select id="newVehicleEquCountByMonth" resultType="java.util.Map">
SELECT COUNT
( 1 ) ,
DATE_FORMAT(ur.rec_date,'%Y-%m-%d')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_vehicle_information ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_vehicle_information_eq te ON te.vehicle_id = ur.sequence_nbr
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(CURDATE(), '%Y-%m') ,'%')
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m-%d')
ORDER BY
ur.rec_date
</select>
<select id="newRegEquCountByYear" resultType="java.util.Map">
SELECT COUNT
( 1 ) ,
DATE_FORMAT(ur.rec_date,'%Y-%m')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_use_registration ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(CURDATE(), '%Y') ,'%')
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m')
ORDER BY
ur.rec_date
</select>
<select id="newRegEquCountByLastYear" resultType="java.util.Map">
SELECT COUNT
( 1 ) ,
DATE_FORMAT(ur.rec_date,'%Y-%m')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_use_registration ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 YEAR), '%Y') ,'%')
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m')
ORDER BY
ur.rec_date
</select>
<select id="newVehicleEquCountByYear" resultType="java.util.Map">
SELECT COUNT
( 1 ) ,
DATE_FORMAT(ur.rec_date,'%Y-%m')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_vehicle_information ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_vehicle_information_eq te ON te.vehicle_id = ur.sequence_nbr
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(CURDATE(), '%Y') ,'%')
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m')
ORDER BY
ur.rec_date
(1),
TO_CHAR(ur.audit_pass_date, 'YYYY-MM-DD')
FROM tzs_jg_vehicle_information ur
INNER JOIN tzs_jg_vehicle_information_eq te ON te.vehicle_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
AND ur.audit_pass_date >= DATE_TRUNC('month', CURRENT_DATE)
GROUP BY TO_CHAR(ur.audit_pass_date, 'YYYY-MM-DD')
ORDER BY ur.audit_pass_date
</select>
<select id="newVehicleEquCountByLastYear" resultType="java.util.Map">
<select id="newRegEquCountByPeriod" resultType="java.util.Map">
SELECT COUNT
( 1 ) ,
DATE_FORMAT(ur.rec_date,'%Y-%m')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_vehicle_information ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
INNER JOIN tzs_jg_vehicle_information_eq te ON te.vehicle_id = ur.sequence_nbr
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 YEAR), '%Y') ,'%')
(1),
TO_CHAR(ur.audit_pass_date,'YYYY-MM')
FROM tzs_jg_use_registration ur
INNER JOIN tzs_jg_use_registration_eq te ON te.equip_transfer_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE ur.status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
<if test="startTime != null">
AND ur.audit_pass_date >= #{startTime}
</if>
<if test="endTime != null">
AND ur.audit_pass_date <![CDATA[<]]> #{endTime}
</if>
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m')
TO_CHAR(ur.audit_pass_date,'YYYY-MM')
ORDER BY
ur.rec_date
ur.audit_pass_date
</select>
<select id="newVehicleCountByYear" resultType="String">
<select id="newVehicleEquCountByPeriod" resultType="java.util.Map">
SELECT COUNT
( 1 )
( 1 ) ,
TO_CHAR(ur.audit_pass_date,'YYYY-MM')
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_vehicle_information ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
tzs_jg_vehicle_information ur
INNER JOIN tzs_jg_vehicle_information_eq te ON te.vehicle_id = ur.sequence_nbr
INNER JOIN idx_biz_jg_supervision_info si ON te.equ_id = si."RECORD"
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(CURDATE(), '%Y') ,'%')
ur.status = '已完成'
and si."ORG_BRANCH_CODE" like CONCAT(#{orgCode}, '%')
<if test="startTime != null">
AND ur.audit_pass_date >= #{startTime}
</if>
<if test="endTime != null">
AND ur.audit_pass_date <![CDATA[<]]> #{endTime}
</if>
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y')
TO_CHAR(ur.audit_pass_date,'YYYY-MM')
ORDER BY
ur.rec_date
ur.audit_pass_date
</select>
<select id="newVehicleCountByMonth" resultType="String">
SELECT COUNT
( 1 )
FROM
privilege_company pc
INNER JOIN tz_base_enterprise_info bi ON bi.supervise_org_code LIKE CONCAT ( pc.org_code, '%' )
INNER JOIN tzs_jg_vehicle_information ur ON ur.use_unit_credit_code = bi.use_unit_code
AND ur.status = '已完成'
WHERE
pc.company_code = #{cityCode}
AND ur.rec_date like concat('%',DATE_FORMAT(CURDATE(), '%Y-%m') ,'%')
GROUP BY
DATE_FORMAT(ur.rec_date,'%Y-%m')
ORDER BY
ur.rec_date
</select>
<select id="certificateCountByOrgCode" resultType="java.lang.Long">
SELECT
COUNT (1)
......@@ -2999,4 +2871,41 @@
#{item}
</foreach>
</select>
<select id="getOrgCodeListByRegionCode" resultType="java.lang.String">
SELECT org_code
FROM privilege_company
WHERE parent_id = (SELECT sequence_nbr FROM privilege_company WHERE company_code = #{regionCode})
AND level != 'company'
AND is_deleted = 0
AND company_type = '监管机构'
</select>
<select id="newVehicleCountByPeriod" resultType="java.lang.String">
SELECT COUNT
( 1 )
FROM
tzs_jg_vehicle_information ur
WHERE
ur.status = '已完成'
AND ur.audit_pass_date >= #{startTime}
<choose>
<when test='dto.cityCode != null and dto.cityCode == "610000"'>
and 1=1
</when>
<otherwise>
<if test="dto.companyCodes != null and dto.companyCodes.size > 0">
and ur.receive_company_code = ANY(ARRAY[
<foreach collection="dto.companyCodes" item="companyCode" separator=",">
#{companyCode}
</foreach>
])
</if>
</otherwise>
</choose>
GROUP BY
TO_CHAR(ur.audit_pass_date,'YYYY')
ORDER BY
ur.audit_pass_date
</select>
</mapper>
......@@ -89,6 +89,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -283,6 +284,8 @@ public class JGDPStatisticsServiceImpl {
private final ComprehensiveStatisticalAnalysisServiceImpl statisticalAnalysisService;
private static final Map<String, List<String>> regionCodeOrgCodesMap = new ConcurrentHashMap<>();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
public void init() {
......@@ -1270,9 +1273,8 @@ public class JGDPStatisticsServiceImpl {
public List<Map<String, Object>> maintenanceCountTopTen(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Integer> regionCodeList = regionModels.stream().map(m -> m.getRegionCode()).collect(Collectors.toList());
Map<Integer, RegionModel> regionMap = regionModels.stream().collect(Collectors.toMap(RegionModel::getRegionCode, Function.identity()));
List<Map<String, Object>> list = jgStatisticsMapper.maintenanceCountTopTen(dpFilterParamDto, regionCodeList);
List<Map<String, Object>> list = jgStatisticsMapper.maintenanceCountTopTen(getOrgCodeListByRegionCode(dpFilterParamDto.getCityCode()));
List<Map<String, Object>> resultList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
Map<String, Object> result = new HashMap<>();
......@@ -1287,9 +1289,8 @@ public class JGDPStatisticsServiceImpl {
public Map<String, Object> maintenanceCount(DPFilterParamDto dpFilterParamDto) {
List<RegionModel> regionModels = stCommonService.setRegionIfRootParent(dpFilterParamDto);
List<Integer> regionCodeList = regionModels.stream().map(m -> m.getRegionCode()).collect(Collectors.toList());
Map<Integer, RegionModel> regionMap = regionModels.stream().collect(Collectors.toMap(RegionModel::getRegionCode, Function.identity()));
List<Map<String, Object>> list = jgStatisticsMapper.maintenanceCount(dpFilterParamDto, regionCodeList);
List<Map<String, Object>> list = jgStatisticsMapper.maintenanceCount(getOrgCodeListByRegionCode(dpFilterParamDto.getCityCode()));
Map<String, Object> resultMap = new HashMap<>();
List xList = new ArrayList();
List yList = new ArrayList();
......@@ -1407,22 +1408,27 @@ public class JGDPStatisticsServiceImpl {
return resultList;
}
public List<String> getOrgCodeListByRegionCode(String regionCode) {
return regionCodeOrgCodesMap.computeIfAbsent(regionCode, (k) -> jgStatisticsMapper.getOrgCodeListByRegionCode(regionCode));
}
public Map<String, Object> getNoticeEquCount(DPFilterParamDto dpFilterParamDto) {
String orgCodeP = stCommonService.getAndSetOrgCode(dpFilterParamDto);
String startTime = LocalDate.now().minusDays(29).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//安装告知
List<Map<String, Object>> installlist = jgStatisticsMapper.installEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> installlist = jgStatisticsMapper.installEquCount(orgCodeP, startTime);
Map<String, Integer> installCountMap = new HashMap<>();
countNoticEquList(installCountMap, installlist);
//维修告知
List<Map<String, Object>> maintenancelist = jgStatisticsMapper.maintenanceEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> maintenancelist = jgStatisticsMapper.maintenanceEquCount(orgCodeP, startTime);
Map<String, Integer> maintenanceCountMap = new HashMap<>();
countNoticEquList(maintenanceCountMap, maintenancelist);
//改造告知
List<Map<String, Object>> reformlist = jgStatisticsMapper.reformEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> reformlist = jgStatisticsMapper.reformEquCount(orgCodeP, startTime);
Map<String, Integer> reformCountMap = new HashMap<>();
countNoticEquList(reformCountMap, reformlist);
//移装告知
List<Map<String, Object>> transferlist = jgStatisticsMapper.transferEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> transferlist = jgStatisticsMapper.transferEquCount(orgCodeP, startTime);
Map<String, Integer> transferCountMap = new HashMap<>();
countNoticEquList(transferCountMap, transferlist);
......@@ -1532,10 +1538,11 @@ public class JGDPStatisticsServiceImpl {
}
public Map<String, Object> getRegEquCount(DPFilterParamDto dpFilterParamDto) {
String orgCodeP = stCommonService.getAndSetOrgCode(dpFilterParamDto);
Map<String, Object> resultMap = new HashMap<>();
String startTime = LocalDate.now().minusDays(29).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
//使用登记
List<Map<String, Object>> uselist = jgStatisticsMapper.useEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> uselist = jgStatisticsMapper.useEquCount(orgCodeP, startTime);
Map<String, Integer> useCountMap = new HashMap<>();
countNoticEquList(useCountMap, uselist);
//车用气瓶使用登记-
......@@ -1543,15 +1550,15 @@ public class JGDPStatisticsServiceImpl {
// Map<String, Integer> vehicleCountMap = new HashMap<>();
// countNoticEquList(vehicleCountMap, vehicleList);
//改造变更登记
List<Map<String, Object>> changeReformList = jgStatisticsMapper.changeReformEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> changeReformList = jgStatisticsMapper.changeReformEquCount(orgCodeP, startTime);
Map<String, Integer> changeReformCountMap = new HashMap<>();
countNoticEquList(changeReformCountMap, changeReformList);
//移装变更登记
List<Map<String, Object>> changeTransferList = jgStatisticsMapper.changeTransferEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> changeTransferList = jgStatisticsMapper.changeTransferEquCount(orgCodeP, startTime);
Map<String, Integer> changeTransferCountMap = new HashMap<>();
countNoticEquList(changeTransferCountMap, changeTransferList);
//单位变更登记
List<Map<String, Object>> changeUnitList = jgStatisticsMapper.changeUnitEquCount(dpFilterParamDto.getCityCode(), startTime);
List<Map<String, Object>> changeUnitList = jgStatisticsMapper.changeUnitEquCount(orgCodeP, startTime);
Map<String, Integer> changeUnitCountMap = new HashMap<>();
countNoticEquList(changeUnitCountMap, changeUnitList);
......@@ -1707,6 +1714,7 @@ public class JGDPStatisticsServiceImpl {
}
public Map<String, Object> newRegEquCount(DPFilterParamDto dpFilterParamDto) {
String orgCodeP = stCommonService.getAndSetOrgCode(dpFilterParamDto);
Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> map = new HashMap<>();
map.put("dataKey", "newRegisterEq");
......@@ -1719,8 +1727,8 @@ public class JGDPStatisticsServiceImpl {
Map<String, Object> useCountMap = new HashMap<>();
Map<String, Object> vehicleCountMap = new HashMap<>();
if ("month".equals(dpFilterParamDto.getSearchType())) {
List<Map<String, Object>> useCountList = jgStatisticsMapper.newRegEquCountByMonth(dpFilterParamDto.getCityCode());
List<Map<String, Object>> vehicleCountList = jgStatisticsMapper.newVehicleEquCountByMonth(dpFilterParamDto.getCityCode());
List<Map<String, Object>> useCountList = jgStatisticsMapper.newRegEquCountByMonth(orgCodeP);
List<Map<String, Object>> vehicleCountList = jgStatisticsMapper.newVehicleEquCountByMonth(orgCodeP);
for (int i = 0; i < useCountList.size(); i++) {
useCountMap.put(useCountList.get(i).getOrDefault("date_format", "") + "", Integer.valueOf(useCountList.get(i).getOrDefault("count", 0) + ""));
}
......@@ -1734,8 +1742,8 @@ public class JGDPStatisticsServiceImpl {
}
} else if ("year".equals(dpFilterParamDto.getSearchType())) {
List<Map<String, Object>> useCountList = jgStatisticsMapper.newRegEquCountByYear(dpFilterParamDto.getCityCode());
List<Map<String, Object>> vehicleCountList = jgStatisticsMapper.newVehicleEquCountByYear(dpFilterParamDto.getCityCode());
List<Map<String, Object>> useCountList = jgStatisticsMapper.newRegEquCountByPeriod(orgCodeP, DateUtil.beginOfYear(new Date()), DateUtil.endOfYear(new Date()));
List<Map<String, Object>> vehicleCountList = jgStatisticsMapper.newVehicleEquCountByPeriod(orgCodeP, DateUtil.beginOfYear(new Date()), DateUtil.endOfYear(new Date()));
for (int i = 0; i < useCountList.size(); i++) {
useCountMap.put(useCountList.get(i).getOrDefault("date_format", "") + "", Integer.valueOf(useCountList.get(i).getOrDefault("count", 0) + ""));
}
......@@ -1749,8 +1757,8 @@ public class JGDPStatisticsServiceImpl {
}
} else if ("lastYear".equals(dpFilterParamDto.getSearchType())) {
List<Map<String, Object>> useCountList = jgStatisticsMapper.newRegEquCountByLastYear(dpFilterParamDto.getCityCode());
List<Map<String, Object>> vehicleCountList = jgStatisticsMapper.newVehicleEquCountByLastYear(dpFilterParamDto.getCityCode());
List<Map<String, Object>> useCountList = jgStatisticsMapper.newRegEquCountByPeriod(orgCodeP, DateUtil.beginOfYear(DateUtil.offset(new Date(), DateField.YEAR, -1)), DateUtil.endOfYear(DateUtil.offset(new Date(), DateField.YEAR, -1)));
List<Map<String, Object>> vehicleCountList = jgStatisticsMapper.newVehicleEquCountByPeriod(orgCodeP, DateUtil.beginOfYear(DateUtil.offset(new Date(), DateField.YEAR, -1)), DateUtil.endOfYear(DateUtil.offset(new Date(), DateField.YEAR, -1)));
for (int i = 0; i < useCountList.size(); i++) {
useCountMap.put(useCountList.get(i).getOrDefault("date_format", "") + "", Integer.valueOf(useCountList.get(i).getOrDefault("count", 0) + ""));
}
......@@ -1773,20 +1781,24 @@ public class JGDPStatisticsServiceImpl {
return resultMap;
}
@FieldMapping({
@FieldMapping.FieldMap(sourceField = "cityCode", targetField = "companyCodes", serviceClass = StCommonServiceImpl.class, queryMethod = "getCompanyCodesByRegionCode"),
})
public List<Map<String, Object>> newRegCount(DPFilterParamDto dpFilterParamDto) {
String orgCodeP = stCommonService.getAndSetOrgCode(dpFilterParamDto);
List<Map<String, Object>> resultList = new ArrayList<>();
//年使用登记设备
List<Map<String, Object>> useEquCountListYear = jgStatisticsMapper.newRegEquCountByYear(dpFilterParamDto.getCityCode());
List<Map<String, Object>> useEquCountListYear = jgStatisticsMapper.newRegEquCountByPeriod(orgCodeP, DateUtil.beginOfYear(new Date()), DateUtil.endOfYear(new Date()));
//年气瓶使用登记设备
List<Map<String, Object>> vehicleEquCountListYear = jgStatisticsMapper.newVehicleEquCountByYear(dpFilterParamDto.getCityCode());
List<Map<String, Object>> vehicleEquCountListYear = jgStatisticsMapper.newVehicleEquCountByPeriod(orgCodeP, DateUtil.beginOfYear(new Date()), DateUtil.endOfYear(new Date()));
//月使用登记设备
List<Map<String, Object>> useEquCountListMonth = jgStatisticsMapper.newRegEquCountByMonth(dpFilterParamDto.getCityCode());
List<Map<String, Object>> useEquCountListMonth = jgStatisticsMapper.newRegEquCountByMonth(orgCodeP);
//月气瓶使用登记设备
List<Map<String, Object>> vehicleEquCountListMonth = jgStatisticsMapper.newVehicleEquCountByMonth(dpFilterParamDto.getCityCode());
List<Map<String, Object>> vehicleEquCountListMonth = jgStatisticsMapper.newVehicleEquCountByMonth(orgCodeP);
//年气瓶使用登记
String vehicleCountYear = jgStatisticsMapper.newVehicleCountByYear(dpFilterParamDto.getCityCode());
String vehicleCountYear = jgStatisticsMapper.newVehicleCountByPeriod(dpFilterParamDto, DateUtil.beginOfYear(new Date()));
//月气瓶使用登记
String vehicleCountListMonth = jgStatisticsMapper.newVehicleCountByMonth(dpFilterParamDto.getCityCode());
String vehicleCountListMonth = jgStatisticsMapper.newVehicleCountByPeriod(dpFilterParamDto, DateUtil.beginOfMonth(new Date()));
/**
* [ { "name": "本年新增登记", "value": 52 }, { "name": "本年新增设备", "value": 83 },
* { "name": "本月新增登记", "value": 16 }, { "name": "本月新增设备", "value": 50 } ]
......
......@@ -174,6 +174,9 @@ public class StCommonServiceImpl {
}
public List<String> getCompanyCodesByRegionCode(String cityCode) {
if ("610000".equals(cityCode)) {
return null;
}
RegionModel region = regionCodeRegionMap.get(Integer.valueOf(cityCode));
return regionCodeCompanyCodeMap.computeIfAbsent(Integer.valueOf(cityCode), k -> commonMapper.selectCompanyCodeByRegionCode(region.getSequenceNbr()));
}
......
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