Browse Source

优化执法分析逻辑

master
vincent 3 weeks ago
parent
commit
a5bf2a7764
  1. 242
      zdxt-modules/zdxt-enforcement-code/src/main/resources/mapper/enforcementcode/report/EnforcementRegistrationReportMapper.xml

242
zdxt-modules/zdxt-enforcement-code/src/main/resources/mapper/enforcementcode/report/EnforcementRegistrationReportMapper.xml

@ -353,31 +353,26 @@
AND er.check_category = #{bo.checkCategory}
</if>
<if test="bo.dateType != null and bo.dateType == 1">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
AND er.enforcement_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
AND er.enforcement_time &lt; DATE_FORMAT(DATE_ADD(LAST_DAY(CURDATE()),INTERVAL 1 DAY),'%Y-%m-01')
</if>
<if test="bo.dateType != null and bo.dateType == 2">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') &gt;= CONCAT(YEAR(CURDATE()), '-',
CASE WHEN QUARTER(CURDATE()) IN (1) THEN '01'
WHEN QUARTER(CURDATE()) IN (2) THEN '04'
WHEN QUARTER(CURDATE()) IN (3) THEN '07'
ELSE '10' END)
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') &lt;= CONCAT(YEAR(CURDATE()), '-',
CASE WHEN QUARTER(CURDATE()) IN (1) THEN '03'
WHEN QUARTER(CURDATE()) IN (2) THEN '06'
WHEN QUARTER(CURDATE()) IN (3) THEN '09'
ELSE '12' END)
AND er.enforcement_time >= MAKEDATE(YEAR(CURDATE()),1) + INTERVAL (QUARTER(CURDATE())-1)*3 MONTH
AND er.enforcement_time &lt; MAKEDATE(YEAR(CURDATE()),1) + INTERVAL QUARTER(CURDATE())*3 MONTH
</if>
<if test="bo.dateType != null and bo.dateType == 3">
AND DATE_FORMAT(er.enforcement_time, '%Y') = DATE_FORMAT(CURDATE(), '%Y')
AND er.enforcement_time >= DATE_FORMAT(CURDATE(), '%Y-01-01')
AND er.enforcement_time &lt; DATE_FORMAT(DATE_ADD(MAKEDATE(YEAR(CURDATE()), 1),INTERVAL 1 YEAR),'%Y-%m-01')
</if>
<if test="bo.dateSearch != null and bo.dateSearch != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') = #{bo.dateSearch}
AND er.enforcement_time >= STR_TO_DATE(CONCAT(#{bo.dateSearch},'-01'),'%Y-%m-%d')
AND er.enforcement_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(#{bo.dateSearch},'-01'),'%Y-%m-%d'),INTERVAL 1 MONTH)
</if>
<if test="bo.beginTime != null and bo.beginTime != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') &gt;= #{bo.beginTime}
AND er.enforcement_time >= #{bo.beginTime}
</if>
<if test="bo.endTime != null and bo.endTime != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') &lt;= #{bo.endTime}
AND er.enforcement_time &lt; DATE_ADD(#{bo.endTime}, INTERVAL 1 DAY)
</if>
<if test="dataFilter != null and dataFilter != ''">
${dataFilter}
@ -505,146 +500,22 @@
<!-- 执法分析V2(按企业聚合,SQL JOIN字典表按dict_sort排序) -->
<select id="selectAnalysisPageV2" resultType="com.zdxt.enforcementcode.domain.vo.report.RegistrationAnalysisVo">
SELECT
t.district,
t.street,
t.enterprise_name AS enterpriseName,
t.enterprise_number AS enterpriseNumber,
t.bureau_dept_name AS bureauDeptName,
CONCAT_WS(',', t.law_enforcer, NULLIF(t.law_enforcer_two, '')) AS lawEnforcer,
t.law_enforcement_item_text AS lawEnforcementItemText,
DATE_FORMAT(t.enforcement_time, '%Y-%m-%d') AS enforcementTime,
t.num AS totalCount
FROM (
SELECT
er.district, er.street, er.enterprise_name, er.enterprise_number,
er.bureau_dept_id, er.bureau_dept_name, er.law_enforcer, er.law_enforcer_two,
er.law_enforcement_item_text,
MAX(er.enforcement_time) AS enforcement_time,
COUNT(er.enterprise_number) AS num
FROM enforcement_registration er
<where>
AND er.is_submit = 1
AND er.is_delete = 0
AND er.bureau_dept_name is not null
AND er.law_enforcement_id is not null
AND er.enterprise_name is not null
AND er.enterprise_number is not null AND er.enterprise_number != ''
AND er.law_enforcer is not null
AND er.law_enforcer_two is not null
AND er.is_complaint is not null
AND er.check_category is not null
AND er.bureau_dept_id is not null
AND (er.status = 0 OR er.status IS NULL)
<if test="bo.bureauDeptName != null and bo.bureauDeptName != ''">
AND er.bureau_dept_name LIKE CONCAT('%', #{bo.bureauDeptName}, '%')
</if>
<if test="bo.lawEnforcer != null and bo.lawEnforcer != ''">
AND (er.law_enforcer LIKE CONCAT('%', #{bo.lawEnforcer}, '%')
OR er.law_enforcer_two LIKE CONCAT('%', #{bo.lawEnforcer}, '%'))
</if>
<if test="bo.enterpriseName != null and bo.enterpriseName != ''">
AND er.enterprise_name LIKE CONCAT('%', #{bo.enterpriseName}, '%')
</if>
<if test="bo.lawEnforcementItemText != null and bo.lawEnforcementItemText != ''">
AND er.law_enforcement_item_text LIKE CONCAT('%', #{bo.lawEnforcementItemText}, '%')
</if>
<if test="bo.district != null and bo.district != ''">
AND (er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '区%')
OR er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '新区%'))
</if>
<if test="bo.street != null and bo.street != ''">
AND (er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '区', #{bo.street}, '%')
OR er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '新区', #{bo.street}, '%'))
</if>
<if test="bo.dateType != null and bo.dateType == 1">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') = DATE_FORMAT(CURDATE(), '%Y-%m')
</if>
<if test="bo.dateType != null and bo.dateType == 2">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') &gt;= CONCAT(YEAR(CURDATE()), '-',
CASE WHEN QUARTER(CURDATE()) IN (1) THEN '01'
WHEN QUARTER(CURDATE()) IN (2) THEN '04'
WHEN QUARTER(CURDATE()) IN (3) THEN '07'
ELSE '10' END)
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') &lt;= CONCAT(YEAR(CURDATE()), '-',
CASE WHEN QUARTER(CURDATE()) IN (1) THEN '03'
WHEN QUARTER(CURDATE()) IN (2) THEN '06'
WHEN QUARTER(CURDATE()) IN (3) THEN '09'
ELSE '12' END)
</if>
<if test="bo.dateType != null and bo.dateType == 3">
AND DATE_FORMAT(er.enforcement_time, '%Y') = DATE_FORMAT(CURDATE(), '%Y')
</if>
<if test="bo.dateSearch != null and bo.dateSearch != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m') = #{bo.dateSearch}
</if>
<if test="bo.beginTime != null and bo.beginTime != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') &gt;= #{bo.beginTime}
</if>
<if test="bo.endTime != null and bo.endTime != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') &lt;= #{bo.endTime}
</if>
<if test="dataFilter != null and dataFilter != ''">
${dataFilter}
</if>
</where>
GROUP BY er.enterprise_number, er.enterprise_name, er.district, er.street,
er.bureau_dept_id, er.bureau_dept_name, er.law_enforcer, er.law_enforcer_two,
er.law_enforcement_item_text
) t
LEFT JOIN sys_dict_data area
ON area.dict_type = 'address_type'
AND area.status = '0'
AND area.dict_label = t.district
LEFT JOIN sys_dict_data str
ON str.dict_type = area.dict_value
AND str.status = '0'
AND str.dict_label = t.street
<where>
<if test="bo.numLeft != null and bo.numLeft != ''">
AND t.num &gt;= #{bo.numLeft}
</if>
<if test="bo.numRight != null and bo.numRight != ''">
AND t.num &lt;= #{bo.numRight}
</if>
<if test="bo.num != null and bo.num != ''">
AND t.num &gt;= #{bo.num}
</if>
</where>
ORDER BY
CASE
WHEN t.district IS NULL OR t.district = '' THEN 2
WHEN area.dict_sort IS NULL THEN 1
ELSE 0
END,
area.dict_sort,
t.district,
CASE
WHEN t.street IS NULL OR t.street = '' THEN 2
WHEN str.dict_sort IS NULL THEN 1
ELSE 0
END,
str.dict_sort,
t.street,
t.enforcement_time ASC
</select>
<!-- 执法分析-导出专用(返回个体记录,不GROUP BY,与旧系统一致) -->
<select id="selectAnalysisExportV2" resultType="com.zdxt.enforcementcode.domain.vo.report.RegistrationAnalysisVo">
er.district,
er.street,
er.enterprise_name AS enterpriseName,
er.enterprise_number AS enterpriseNumber,
er.bureau_dept_name AS bureauDeptName,
CONCAT_WS(',', er.law_enforcer, NULLIF(er.law_enforcer_two, '')) AS lawEnforcer,
er.law_enforcement_item_text AS lawEnforcementItemText,
DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') AS enforcementTime,
stat.totalCount
FROM enforcement_registration er
INNER JOIN (
SELECT
er.district,
er.enterprise_name AS enterpriseName,
er.enterprise_number AS enterpriseNumber,
er.bureau_dept_name AS bureauDeptName,
er.bureau_dept_id AS bureauDeptId,
CONCAT_WS(',', er.law_enforcer, NULLIF(er.law_enforcer_two, '')) AS lawEnforcer,
er.law_enforcement_item_text AS lawEnforcementItemText,
DATE_FORMAT(er.enforcement_time, '%Y-%m-%d %H:%i:%s') AS enforcementTime,
er.remark
enterprise_number,
MAX(CONCAT(enforcement_time, '|', id)) AS max_key,
COUNT(1) AS totalCount
FROM enforcement_registration er
LEFT JOIN sys_dict_data area
ON area.dict_type = 'address_type'
AND area.status = '0'
AND area.dict_label = er.district
<where>
AND er.is_submit = 1
AND er.is_delete = 0
@ -653,7 +524,6 @@
AND er.enterprise_name is not null
AND er.enterprise_number is not null AND er.enterprise_number != ''
AND er.law_enforcer is not null
AND er.law_enforcer_two is not null
AND er.is_complaint is not null
AND er.check_category is not null
AND er.bureau_dept_id is not null
@ -663,7 +533,7 @@
</if>
<if test="bo.lawEnforcer != null and bo.lawEnforcer != ''">
AND (er.law_enforcer LIKE CONCAT('%', #{bo.lawEnforcer}, '%')
OR er.law_enforcer_two LIKE CONCAT('%', #{bo.lawEnforcer}, '%'))
OR er.law_enforcer_two LIKE CONCAT('%', #{bo.lawEnforcer}, '%'))
</if>
<if test="bo.enterpriseName != null and bo.enterpriseName != ''">
AND er.enterprise_name LIKE CONCAT('%', #{bo.enterpriseName}, '%')
@ -673,23 +543,75 @@
</if>
<if test="bo.district != null and bo.district != ''">
AND (er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '区%')
OR er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '新区%'))
OR er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '新区%'))
</if>
<if test="bo.street != null and bo.street != ''">
AND (er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '区', #{bo.street}, '%')
OR er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '新区', #{bo.street}, '%'))
OR er.enterprise_address LIKE CONCAT('深圳市', SUBSTRING_INDEX(#{bo.district}, '区', 1), '新区', #{bo.street}, '%'))
</if>
<if test="bo.dateType != null and bo.dateType == 1">
AND er.enforcement_time >= DATE_FORMAT(CURDATE(), '%Y-%m-01')
AND er.enforcement_time &lt; DATE_FORMAT(DATE_ADD(LAST_DAY(CURDATE()),INTERVAL 1 DAY),'%Y-%m-01')
</if>
<if test="bo.dateType != null and bo.dateType == 2">
AND er.enforcement_time >= MAKEDATE(YEAR(CURDATE()),1) + INTERVAL (QUARTER(CURDATE())-1)*3 MONTH
AND er.enforcement_time &lt; MAKEDATE(YEAR(CURDATE()),1) + INTERVAL QUARTER(CURDATE())*3 MONTH
</if>
<if test="bo.dateType != null and bo.dateType == 3">
AND er.enforcement_time >= DATE_FORMAT(CURDATE(), '%Y-01-01')
AND er.enforcement_time &lt; DATE_FORMAT(DATE_ADD(MAKEDATE(YEAR(CURDATE()), 1),INTERVAL 1 YEAR),'%Y-%m-01')
</if>
<if test="bo.dateSearch != null and bo.dateSearch != ''">
AND er.enforcement_time >= STR_TO_DATE(CONCAT(#{bo.dateSearch},'-01'),'%Y-%m-%d')
AND er.enforcement_time &lt; DATE_ADD(STR_TO_DATE(CONCAT(#{bo.dateSearch},'-01'),'%Y-%m-%d'),INTERVAL 1 MONTH)
</if>
<if test="bo.beginTime != null and bo.beginTime != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') &gt;= #{bo.beginTime}
AND er.enforcement_time >= #{bo.beginTime}
</if>
<if test="bo.endTime != null and bo.endTime != ''">
AND DATE_FORMAT(er.enforcement_time, '%Y-%m-%d') &lt;= #{bo.endTime}
AND er.enforcement_time &lt; DATE_ADD(#{bo.endTime}, INTERVAL 1 DAY)
</if>
<if test="dataFilter != null and dataFilter != ''">
${dataFilter}
</if>
</where>
ORDER BY er.enterprise_name
GROUP BY enterprise_number
) stat ON er.enterprise_number = stat.enterprise_number AND CONCAT(er.enforcement_time,'|',er.id)=stat.max_key
LEFT JOIN sys_dict_data area
ON area.dict_type = 'address_type'
AND area.status = '0'
AND area.dict_label = er.district
LEFT JOIN sys_dict_data str
ON str.dict_type = area.dict_value
AND str.status = '0'
AND str.dict_label = er.street
WHERE er.is_delete=0 AND er.is_submit=1
<if test="bo.numLeft != null and bo.numLeft != ''">
AND stat.totalCount >= #{bo.numLeft}
</if>
<if test="bo.numRight != null and bo.numRight != ''">
AND stat.totalCount &lt;= #{bo.numRight}
</if>
<if test="bo.num != null and bo.num != ''">
AND stat.totalCount >= #{bo.num}
</if>
ORDER BY
CASE
WHEN er.district IS NULL OR er.district = '' THEN 2
WHEN area.dict_sort IS NULL THEN 1
ELSE 0
END,
area.dict_sort,
er.district,
CASE
WHEN er.street IS NULL OR er.street = '' THEN 2
WHEN str.dict_sort IS NULL THEN 1
ELSE 0
END,
str.dict_sort,
er.street,
er.enforcement_time DESC
</select>
<!-- 执法分析-详情(指定企业的执法明细聚合) -->

Loading…
Cancel
Save