FAISP/src/main/resources/mybatisMapper/AffairStatisticsMapper.xml

619 lines
19 KiB
XML
Raw Normal View History

2023-04-06 07:08:48 +00:00
<?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.fpiMgt.statistics.mapper.AffairStatisticsMapper">
<sql id="searchStatistics">
<if test='userNm != null and userNm != ""'>
and wrt_user_nm like '%'||#{userNm}||'%'
</if>
<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 test='rating != null and rating != "" or sangbo != null and sangbo != ""'>
and ab.affair_key in (
select affair_key
from affair_rating ar2
inner join organ_config oc2
on ar2.rating_organ = oc2.organ_cd
<where>
<if test='rating != null and rating != ""'>
and ar2.affair_rate in
<foreach collection="rating" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='sangbo != null and sangbo != ""'>
and ar2.organ_up = 'T'
and oc2.organ_type in
<foreach collection="sangbo" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</where>
)
</if>
</sql>
<sql id="statisticsCategory1">
<choose>
<when test='category1 != null and category1 != ""'>
and item_cd in
<foreach collection="category1" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd = 'DC01')
</otherwise>
</choose>
</sql>
<sql id="statisticsCategory2">
<choose>
<when test='category2 != null and category2 != ""'>
and item_cd in
<foreach collection="category2" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd = 'DC02')
</otherwise>
</choose>
</sql>
<sql id="statisticsCategory3">
<choose>
<when test='category3 != null and category3 != ""'>
and item_cd in
<foreach collection="category3" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd = 'DC03')
</otherwise>
</choose>
</sql>
<sql id="statisticsCategory4">
<choose>
<when test='category4 != null and category4 != ""'>
and item_cd in
<foreach collection="category4" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd = 'DC04')
</otherwise>
</choose>
</sql>
<select id="selectStatusTotal" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as wrt_organ,
item_value,
coalesce(cnt,0) as cnt
from(
select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<choose>
<when test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd = 'OG' and use_chk = 'T')
</otherwise>
</choose>
order by item_cd asc) a left outer join
(select wrt_organ,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<if test='userNm != null and userNm != ""'>
and wrt_user_nm like '%'||#{userNm}||'%'
</if>
<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 test='rating != null and rating != "" or sangbo != null and sangbo != ""'>
and ab.affair_key in (
select affair_key
from affair_rating ar2
inner join organ_config oc2
on ar2.rating_organ = oc2.organ_cd
<where>
<if test='rating != null and rating != ""'>
and ar2.affair_rate in
<foreach collection="rating" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='sangbo != null and sangbo != ""'>
and ar2.organ_up = 'T'
and oc2.organ_type in
<foreach collection="sangbo" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</where>
)
</if>
<if test='category1 != null and category1 != ""'>
and affair_type1 in
<foreach collection="category1" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category2 != null and category2 != ""'>
and affair_type2 in
<foreach collection="category2" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category3 != null and category3 != ""'>
and affair_type3 in
<foreach collection="category3" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category4 != null and category4 != ""'>
and affair_type4 in
<foreach collection="category4" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
group by wrt_organ)b on
a.item_cd = b.wrt_organ
order by wrt_organ asc
</select>
<select id="selectType1ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC01'
<include refid="statisticsCategory1"></include>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type1 as affair_type,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="searchStatistics"></include>
group by wrt_organ,affair_type1) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<select id="selectType2ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC02'
<include refid="statisticsCategory2"></include>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type2 as affair_type,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="searchStatistics"></include>
group by wrt_organ,affair_type2) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<select id="selectType3ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC03'
<include refid="statisticsCategory3"></include>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type3 as affair_type,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="searchStatistics"></include>
group by wrt_organ,affair_type3) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<select id="selectType4ListCnt" resultType="TypeStatistics" parameterType="TypeStatistics">
select b.item_cd as wrt_organ ,
b.item_value,
a.item_cd as affair_type,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'DC04'
<include refid="statisticsCategory4"></include>
)a left join
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<if test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
order by item_cd asc) b on 1=1
left outer join
(select wrt_organ,
affair_type4 as affair_type,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="searchStatistics"></include>
group by wrt_organ,affair_type4) c
on a.item_cd = c.affair_type and b.item_cd = c.wrt_organ
order by wrt_organ,affair_type asc
</select>
<sql id="raitingSearch">
<if test='userNm != null and userNm != ""'>
and wrt_user_nm like '%'||#{userNm}||'%'
</if>
<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 test='rating != null and rating != "" or sangbo != null and sangbo != ""'>
and ab.affair_key in (
select affair_key
from affair_rating ar2
inner join organ_config oc2
on ar2.rating_organ = oc2.organ_cd
<where>
<if test='rating != null and rating != ""'>
and ar2.affair_rate in
<foreach collection="rating" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='sangbo != null and sangbo != ""'>
and ar2.organ_up = 'T'
and oc2.organ_type in
<foreach collection="sangbo" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</where>
)
</if>
<if test='category1 != null and category1 != ""'>
and affair_type1 in
<foreach collection="category1" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category2 != null and category2 != ""'>
and affair_type2 in
<foreach collection="category2" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category3 != null and category3 != ""'>
and affair_type3 in
<foreach collection="category3" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category4 != null and category4 != ""'>
and affair_type4 in
<foreach collection="category4" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</sql>
<select id="selectRatingStatusTotal" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as wrt_organ,
item_value,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T'
<choose>
<when test='organList != null and organList != ""'>
and item_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd = 'OG' and use_chk = 'T')
</otherwise>
</choose>
) a
left outer join
(select ab.wrt_organ,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="raitingSearch"></include>
group by ab.wrt_organ) c
on a.item_cd = c.wrt_organ
order by item_cd asc
</select>
<select id="selectSangboTotal" resultType="TypeStatistics" parameterType="TypeStatistics">
select item_cd as wrt_organ,
item_value,
b.organ_type as affairType,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T') a left join
(select organ_type
from organ_config
<where>
<choose>
<when test='sangbo != null and sangbo != ""'>
organ_type in
<foreach collection="sangbo" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
organ_type not in (select organ_type from organ_config)
</otherwise>
</choose>
</where>
group by organ_type) b on 1=1
left outer join
(select ab.wrt_organ,
oc.organ_type,
count(*) as cnt
from affair_board ab,
affair_rating ar,
organ_config oc
where ab.affair_key = ar.affair_key
and ar.rating_organ = oc.organ_cd
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="raitingSearch"></include>
group by ab.wrt_organ,oc.organ_type) c
on a.item_cd = c.wrt_organ and b.organ_type = c.organ_type
order by item_cd, affairType asc
</select>
<select id="selectArrCntList" resultType="TypeStatistics" parameterType="TypeStatistics">
select a.item_cd as wrt_organ,
b.item_cd as affairType,
coalesce(cnt,0) as cnt
from
(select item_cd,
item_value
from code_mgt
where category_cd = 'OG'
and use_chk = 'T') a left join
(select item_cd
from code_mgt
where category_cd='AAR'
<choose>
<when test='rating != null and rating != ""'>
and item_cd in
<foreach collection="rating" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</when>
<otherwise>
and item_cd not in (select item_cd from code_mgt where category_cd='AAR')
</otherwise>
</choose>
) b on 1=1
left outer join
(select ab.wrt_organ,
ar.affair_rate,
count(*) as cnt
from affair_board ab,
affair_rating ar
where ab.affair_key = ar.affair_key
and (ar.organ_up != 'T' or ar.organ_up is null)
<include refid="raitingSearch"></include>
group by ab.wrt_organ,ar.affair_rate) c
on c.wrt_organ = a.item_cd and c.affair_rate = b.item_cd
order by wrt_organ,affairType asc
</select>
<sql id="selectPersonalStatisticsWhere">
<where>
<choose>
<when test='userStatus != null and userStatus != ""'>
and user_status = #{userStatus}
</when>
<otherwise>
and user_status in ('USC003', 'USC007')
</otherwise>
</choose>
<if test='userNm != null and userNm != ""'>
and user_nm like '%'||#{userNm}||'%'
</if>
<if test='organList != null'>
and og_cd in
<foreach collection="organList" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
</where>
</sql>
<sql id="selectPersonalStatisticsSubWhere">
<where>
<if test='startDate != null and startDate != ""'>
and aa.wrt_dt >= #{startDate}::date
</if>
<if test='endDate != null and endDate != ""'>
and aa.wrt_dt &lt;= #{endDate}::date+1
</if>
<if test='rating != null'>
and ab.affair_rate in
<foreach collection="rating" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category1 != null'>
and aa.affair_type1 in
<foreach collection="category1" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category2 != null'>
and aa.affair_type2 in
<foreach collection="category2" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category3 != null'>
and aa.affair_type3 in
<foreach collection="category3" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='category4 != null'>
and aa.affair_type4 in
<foreach collection="category4" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<if test='sangbo != null'>
and aa.affair_key in (
select aaa.affair_key
from affair_rating aaa
inner join organ_config aab
on aaa.rating_organ = aab.organ_cd
where aaa.organ_up = 'T'
and aab.organ_type in
<foreach collection="sangbo" item="item" index="index" separator="," open="(" close=")">
#{item}
</foreach>
)
</if>
</where>
</sql>
<select id="selectPersonalStatistics" resultType="PersonalAffairStatistics" parameterType="PersonalAffairStatistics">
select user_status,
og_cd,
ofc_cd,
title_cd,
dic_code,
user_nm,
b.title,
b.affair_type4,
b.doc_no,
2023-09-19 05:52:15 +00:00
b.report_dt,
b.affair_rate
2023-04-06 07:08:48 +00:00
from user_info a
inner join
(
select aa.wrt_user_seq ,
aa.title,
aa.affair_type4,
aa.doc_no,
2023-09-19 05:52:15 +00:00
aa.report_dt,
ab.affair_rate
from affair_board aa
2023-04-06 07:08:48 +00:00
inner join affair_rating ab
on aa.affair_key = ab.affair_key and ab.affair_rate is not null and ab.organ_up = 'F'
<include refid="selectPersonalStatisticsSubWhere"></include>
2023-04-06 07:08:48 +00:00
) b on a.user_seq = b.wrt_user_seq
<include refid="selectPersonalStatisticsWhere"></include>
order by og_cd, ofc_cd, title_cd, user_nm
2023-04-06 07:08:48 +00:00
</select>
</mapper>