FAISP/src/main/resources/mybatisMapper/InternationalCrimeArrestMap...

171 lines
6.8 KiB
XML

<?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.dbnt.faisp.main.faStatistics.internationalCrimeArrest.mapper.InternationalCrimeArrestMapper">
<sql id="selectInternationalCrimeArrestListWhere">
<where>
status &lt;> 'DST008'
<if test='organ != null and organ != ""'>
AND organ = #{organ}
</if>
<if test='department != null and department != ""'>
AND department = #{department}
</if>
<if test='crimeType != null and crimeType != ""'>
AND crime_type = #{crimeType}
</if>
<if test='violationType != null and violationType != ""'>
AND violation_type = #{violationType}
</if>
<if test='caseNum != null and caseNum != ""'>
AND case_num = #{caseNum}
</if>
<if test='crimeName != null and crimeName != ""'>
AND crime_name LIKE CONCAT('%', #{crimeName}, '%')
</if>
<if test='occurTable != null and occurTable != ""'>
AND occur_table LIKE CONCAT('%', #{occurTable}, '%')
</if>
<if test='arrestTable != null and arrestTable != ""'>
AND arrest_table LIKE CONCAT('%', #{arrestTable}, '%')
</if>
<if test='suspectTable != null and suspectTable != ""'>
AND suspect_table LIKE CONCAT('%', #{suspectTable}, '%')
</if>
<if test='crimeAwarenessDt != null'>
And crime_awareness_dt = #{crimeAwarenessDt}::DATE
</if>
<if test='caseSentDt != null'>
AND case_sent_dt = #{caseSentDt}::DATE
</if>
<if test='processResult != null and processResult != ""'>
AND ica_key in (
select ica_key
from ica_suspect_info
where process_result = #{processResult}
)
</if>
<if test='dateSelector == "wrtDt"'>
<if test='startDate != null and startDate != ""'>
And wrt_dt >= #{startDate}::DATE
</if>
<if test='endDate != null and endDate != ""'>
AND wrt_dt &lt;= #{endDate}::DATE+1
</if>
</if>
</where>
</sql>
<select id="selectInternationalCrimeArrestList" resultType="InternationalCrimeArrest" parameterType="InternationalCrimeArrest">
SELECT a.ica_key,
a.organ,
a.department,
a.case_officer,
a.crime_type,
a.violation_type,
a.crime_name,
a.occur_table,
a.arrest_table,
a.suspect_table,
a.crime_awareness_dt,
a.case_sent_dt,
a.case_num,
a.wrt_organ,
a.wrt_part,
a.wrt_user_grd,
a.wrt_user_nm,
a.wrt_dt
FROM international_crime_arrest a
<include refid="selectInternationalCrimeArrestListWhere"></include>
ORDER BY a.ica_key DESC
LIMIT #{rowCnt} OFFSET #{firstIndex}
</select>
<select id="selectInternationalCrimeArrestListCnt" resultType="int" parameterType="InternationalCrimeArrest">
SELECT count(*)
FROM international_crime_arrest a
<include refid="selectInternationalCrimeArrestListWhere"></include>
</select>
<select id="selectSuspectPersonInfoParamList" resultType="com.dbnt.faisp.util.ParamMap" parameterType="int">
SELECT
s.spi_key,
s.ica_key,
s.sex,
s.age,
s.country,
s.stay_qualification,
s.stay_period_expired_dt,
s.entry_visa
FROM suspect_person_info s
INNER JOIN international_crime_arrest i
ON s.ica_key = i.ica_key
WHERE s.ica_key = #{icaKey}
</select>
<select id="selectIcaStatistics" resultType="IcaStatistics" parameterType="IcaStatistics">
select a.item_value as crimeType ,
a.item_cd as crimeTypeCd,
b.item_value as violationType,
b.item_cd as violationTypeCd,
coalesce(c.caseCnt, 0) as caseCnt,
coalesce(c.suspectCnt, 0) as suspectCnt,
coalesce(c.arrestCnt, 0) as arrestCnt,
coalesce(c.arrestSuspectCnt, 0) as arrestSuspectCnt,
coalesce(c.pcr001Cnt, 0) as pcr001Cnt,
coalesce(c.pcr002Cnt, 0) as pcr002Cnt,
coalesce(c.pcr003Cnt, 0) as pcr003Cnt,
coalesce(c.pcr004Cnt, 0) as pcr004Cnt,
coalesce(c.pcr005Cnt, 0) as pcr005Cnt,
coalesce(c.pcr006Cnt, 0) as pcr006Cnt
from code_mgt a
inner join code_mgt b on a.category_cd = 'CTH' and a.item_cd = b.category_cd
left outer join (
select aa.crime_type,
aa.violation_type,
count(distinct aa.ica_key) as caseCnt,
count(*) as suspectCnt,
count(distinct case
when ab.process_result = 'PCR001'
or ab.process_result = 'PCR002'
or ab.process_result = 'PCR003' then aa.ica_key
else null
end) as arrestCnt,
sum(case
when ab.process_result = 'PCR001'
or ab.process_result = 'PCR002'
or ab.process_result = 'PCR003' then 1
else 0
end) as arrestSuspectCnt,
sum(case when ab.process_result = 'PCR001' then 1 else 0 end) as pcr001Cnt,
sum(case when ab.process_result = 'PCR002' then 1 else 0 end) as pcr002Cnt,
sum(case when ab.process_result = 'PCR003' then 1 else 0 end) as pcr003Cnt,
sum(case when ab.process_result = 'PCR004' then 1 else 0 end) as pcr004Cnt,
sum(case when ab.process_result = 'PCR005' then 1 else 0 end) as pcr005Cnt,
sum(case when ab.process_result = 'PCR006' then 1 else 0 end) as pcr006Cnt
from international_crime_arrest aa
inner join ica_suspect_info ab on aa.ica_key = ab.ica_key
where
status &lt;> 'DST008'
<if test='organ != null and organ != ""'>
and department = #{organ}
</if>
<if test='year != null and year != 0'>
and EXTRACT(YEAR FROM case_sent_dt) = ${year}
</if>
<if test='month != null and month != 0'>
and EXTRACT(MONTH FROM case_sent_dt) = ${month}
</if>
group by crime_type, violation_type
) c on a.item_cd = c.crime_type and b.item_cd = c.violation_type
order by a.item_cd, b.item_cd
</select>
<select id="selectYearOptionList" resultType="int">
select distinct EXTRACT(YEAR FROM case_sent_dt)
from international_crime_arrest
where status &lt;> 'DST008'
</select>
</mapper>