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

70 lines
2.5 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.publicBoard.mapper.PublicBoardMapper">
<sql id="selectContentListWhere">
<where>
<if test='publicType != null and publicType != ""'>
and a.public_type = #{publicType}
</if>
<if test='startDate != null and startDate != ""'>
and a.wrt_dt >= #{startDate}::date
</if>
<if test='endDate != null and endDate != ""'>
and a.wrt_dt &lt;= #{endDate}::date+1
</if>
and a.public_key in (
<if test="downOrganCdList != null">
select public_key from public_board where wrt_organ in
<foreach collection="downOrganCdList" item="organCd" separator="," open="(" close=")">
#{organCd}
</foreach>
</if>
<if test="downOrganCdList != null and upOrganCdList != null">
union all
</if>
<if test="upOrganCdList != null">
select public_key from public_board where organ_chk = 'F' and wrt_organ in
<foreach collection="upOrganCdList" item="organCd" separator="," open="(" close=")">
#{organCd}
</foreach>
</if>
)
</where>
</sql>
<select id="selectContentList" resultType="PublicBoard" parameterType="PublicBoard">
select a.public_key,
a.public_type,
a.title,
a.content,
a.wrt_organ,
a.wrt_part,
a.wrt_user_nm,
a.wrt_user_seq,
a.wrt_dt,
a.organ_chk,
b.fileCnt,
c.commentCnt
from public_board a
left outer join (select public_key,
count(file_seq) as fileCnt
from public_file
group by public_key) b
on a.public_key = b.public_key
left outer join (select public_key,
count(comment_key) as commentCnt
from public_comment
group by public_key) c
on a.public_key = c.public_key
<include refid="selectContentListWhere"></include>
order by public_key desc
limit #{rowCnt} offset #{firstIndex}
</select>
<select id="selectContentListCnt" resultType="int" parameterType="PublicBoard">
select count(*)
from public_board a
<include refid="selectContentListWhere"></include>
</select>
</mapper>