You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

462 lines
16 KiB

<?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.epmet.modules.topic.dao.ResiTopicDao">
<sql id="sql">
rt.id AS "id",
rt.group_id AS "groupId",
rt.topic_content AS "topicContent",
rt.status AS "status",
rt.province AS "province",
rt.city AS "city",
rt.area AS "area",
rt.address AS "address",
rt.longitude AS "longitude",
rt.dimension AS "dimension",
rt.del_flag AS "delFlag",
rt.revision AS "revision",
rt.created_by AS "createdBy",
rt.created_time AS "createdTime",
rt.updated_by AS "updatedBy",
rt.updated_time AS "updatedTime"
</sql>
<!-- 新增话题 -->
<insert id="insertOne" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.epmet.modules.topic.entity.ResiTopicEntity">
<selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE">
select replace(uuid(),'-','') AS ID
</selectKey>
INSERT INTO resi_topic
<trim prefix="(" suffix=")" suffixOverrides=",">
id,
<if test ='null != groupId'>
group_id,
</if>
<if test ='null != topicContent'>
topic_content,
</if>
<if test ='null != status'>
status,
</if>
<if test ='null != province'>
province,
</if>
<if test ='null != city'>
city,
</if>
<if test ='null != area'>
area,
</if>
<if test ='null != address'>
address,
</if>
<if test ='null != longitude'>
longitude,
</if>
<if test ='null != dimension'>
dimension,
</if>
<if test ='null != createdBy'>
created_by,
</if>
updated_by,
del_flag,
revision,
created_time,
updated_time
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
#{id},
<if test ='null != groupId'>
#{groupId},
</if>
<if test ='null != topicContent'>
#{topicContent},
</if>
<if test ='null != status'>
#{status},
</if>
<if test ='null != province'>
#{province},
</if>
<if test ='null != city'>
#{city},
</if>
<if test ='null != area'>
#{area},
</if>
<if test ='null != address'>
#{address},
</if>
<if test ='null != longitude'>
#{longitude},
</if>
<if test ='null != dimension'>
#{dimension},
</if>
<if test ='null != createdBy'>
#{createdBy},
</if>
'APP_USER',
'0',
0,
now(),
now()
</trim>
</insert>
<!-- 查询最近十条话题 -->
<select id="getLatestTenTopics" parameterType="string" resultType="com.epmet.resi.group.dto.topic.result.ResiTopicIncludeIssueInfoResultDTO">
SELECT
topic.ID AS topicId,
topic.GROUP_ID,
topic.TOPIC_CONTENT,
topic.STATUS,
topic.CREATED_TIME AS releaseTime,
topic.CREATED_BY AS userId,
topic.SHIFT_ISSUE AS shiftIssueFlag,
IFNULL(topic.ISSUE_ID,'') AS issueId,
IFNULL(attachement2.firstPhoto,'') AS firstPhoto,
CASE
WHEN topic.CREATED_BY = #{userId} THEN 'me'
ELSE 'other'
END AS releaseUserFlag
FROM
RESI_TOPIC topic
LEFT JOIN
(
SELECT
attachment.TOPIC_ID AS attachmentTopicId,
attachment.ATTACHMENT_URL as firstPhoto,
MIN(attachment.SORT)
FROM
RESI_TOPIC_ATTACHMENT attachment
WHERE
attachment.DEL_FLAG = '0'
GROUP BY attachment.TOPIC_ID
) attachement2
ON
topic.ID = attachement2.attachmentTopicId
WHERE
topic.DEL_FLAG = '0'
AND <![CDATA[ topic.STATUS <> 'hidden' ]]>
AND topic.GROUP_ID = #{groupId}
ORDER BY
topic.CREATED_TIME DESC
LIMIT 10
</select>
<!-- 查询历史话题,分页,参数查询 -->
<select id="getPastTopics" parameterType="com.epmet.resi.group.dto.topic.form.ResiTopicPageFormDTO" resultType="com.epmet.resi.group.dto.topic.result.ResiTopicInfoResultDTO">
SELECT
topic.ID AS topicId,
topic.GROUP_ID,
topic.TOPIC_CONTENT,
topic.STATUS,
topic.CREATED_TIME AS releaseTime,
topic.CREATED_BY AS userId,
IFNULL(attachement2.firstPhoto,'') AS firstPhoto,
CASE
WHEN topic.CREATED_BY = #{userId} THEN 'me'
ELSE 'other'
END AS releaseUserFlag
FROM
RESI_TOPIC topic
LEFT JOIN
(
SELECT
attachment.TOPIC_ID AS attachmentTopicId,
attachment.ATTACHMENT_URL as firstPhoto,
MIN(attachment.SORT)
FROM
RESI_TOPIC_ATTACHMENT attachment
WHERE
attachment.DEL_FLAG = '0'
GROUP BY attachment.TOPIC_ID
) attachement2
ON
topic.ID = attachement2.attachmentTopicId
<where>
topic.DEL_FLAG = '0'
AND topic.GROUP_ID = #{groupId}
<if test='"hidden" != status'>
AND <![CDATA[ topic.STATUS <> 'hidden' ]]>
</if>
<if test='null != status and "" != status'>
AND topic.STATUS = #{status}
</if>
</where>
ORDER BY
topic.CREATED_TIME DESC
LIMIT #{pageNo},#{pageSize}
</select>
<!-- 查询历史话题,分页,参数查询 ,返回时携带shift_issue、issue_id字段-->
<select id="getTopicsIncludeIssueInfoByConditions" parameterType="com.epmet.resi.group.dto.topic.form.ResiTopicPageFormDTO" resultType="com.epmet.resi.group.dto.topic.result.ResiTopicIncludeIssueInfoResultDTO">
SELECT
topic.ID AS topicId,
topic.GROUP_ID,
topic.TOPIC_CONTENT,
topic.STATUS,
topic.CREATED_TIME AS releaseTime,
topic.CREATED_BY AS userId,
topic.SHIFT_ISSUE AS shiftIssueFlag,
IFNULL(topic.ISSUE_ID,'') AS issueId,
IFNULL(attachement2.firstPhoto,'') AS firstPhoto,
CASE
WHEN topic.CREATED_BY = #{userId} THEN 'me'
ELSE 'other'
END AS releaseUserFlag
FROM
RESI_TOPIC topic
LEFT JOIN
(
SELECT
attachment.TOPIC_ID AS attachmentTopicId,
attachment.ATTACHMENT_URL as firstPhoto,
MIN(attachment.SORT)
FROM
RESI_TOPIC_ATTACHMENT attachment
WHERE
attachment.DEL_FLAG = '0'
GROUP BY attachment.TOPIC_ID
) attachement2
ON
topic.ID = attachement2.attachmentTopicId
<where>
topic.DEL_FLAG = '0'
AND topic.GROUP_ID = #{groupId}
<if test='"hidden" != status'>
AND <![CDATA[ topic.STATUS <> 'hidden' ]]>
</if>
<if test='null != status and "" != status'>
AND topic.STATUS = #{status}
</if>
</where>
ORDER BY
topic.CREATED_TIME DESC
LIMIT #{pageNo},#{pageSize}
</select>
<select id="selectTopicList" resultType="com.epmet.resi.group.dto.topic.ResiTopicDTO">
SELECT
<include refid="sql"></include>
FROM resi_topic rt
WHERE rt.del_flag = '0'
<if test='null != groupId and "" != groupId'>
AND rt.group_id = #{groupId}
</if>
<if test='null != createdBy and "" != createdBy'>
AND rt.created_by = #{createdBy}
</if>
</select>
<!-- 单条更新 全部条件判断 -->
<update id="updateOne" parameterType="com.epmet.modules.topic.entity.ResiTopicEntity">
UPDATE
RESI_TOPIC
<set>
<if test ='null != groupId and "" != groupId'>group_id = #{groupId},</if>
<if test ='null != topicContent and "" != topicContent'>topic_content = #{topicContent},</if>
<if test ='null != status and "" != status'>status = #{status},</if>
<if test ='null != province and "" != province'>province = #{province},</if>
<if test ='null != city and "" != city'>city = #{city},</if>
<if test ='null != area and "" != area'>area = #{area},</if>
<if test ='null != address and "" != address'>address = #{address},</if>
<if test ='null != longitude and "" != longitude'>longitude = #{longitude},</if>
<if test ='null != dimension and "" != dimension'>dimension = #{dimension},</if>
<if test ='null != delFlag and "" != delFlag'>del_flag = #{delFlag},</if>
<if test ='null != revision'>revision = #{revision},</if>
<if test ='null != createdBy and "" != createdBy'>created_by = #{createdBy},</if>
<if test ='null != createdTime'>created_time = #{createdTime},</if>
<if test ='null != updatedBy and "" != updatedBy'>updated_by = #{updatedBy},</if>
<if test ='null != updatedTime'>updated_time = #{updatedTime},</if>
<if test ='null != shiftIssue'>shift_issue = #{shiftIssue},</if>
<if test ='null != issueId and "" != issueId'>issue_id = #{issueId}</if>
</set>
WHERE
ID = #{id}
AND DEL_FLAG = '0'
</update>
<!-- 单条更新 -->
<update id="update" parameterType="com.epmet.modules.topic.entity.ResiTopicEntity">
UPDATE
RESI_TOPIC
<set>
<if test='null != status and "" != status'>
STATUS = #{status} ,
</if>
<if test='null != delFlag and "" != delFlag'>
DEL_FLAG = #{delFlag} ,
</if>
<if test='null != topicContent and "" != topicContent'>
TOPIC_CONTENT = #{topicContent} ,
</if>
UPDATED_BY = #{updatedBy} ,
UPDATED_TIME = NOW()
</set>
WHERE
ID = #{id}
AND DEL_FLAG = '0'
</update>
<!-- 批量取消屏蔽 -->
<update id="cancelHiddenOrCloseBatch">
UPDATE
RESI_TOPIC
SET
STATUS = #{status},
UPDATED_TIME = NOW(),
UPDATED_BY = #{updatedBy}
<where>
ID
<foreach collection="list" item="item" index="index" open="in (" separator="," close=")">
#{item}
</foreach>
AND
DEL_FLAG = '0'
<if test='"discussing" == status'>
AND STATUS = 'hidden'
</if>
</where>
</update>
<!-- 批量更新 -->
<update id="updateBatch" parameterType="list">
update RESI_TOPIC
<trim prefix="set" suffixOverrides=",">
<trim prefix="topic_content= case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.topicContent!=null">
when id=#{i.id} then #{i.topicContent}
</if>
</foreach>
</trim>
<trim prefix=" status =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.status!=null">
when id=#{i.id} then #{i.status}
</if>
</foreach>
</trim>
<trim prefix="updated_by =case" suffix="end," >
<foreach collection="list" item="i" index="index">
<if test="i.updatedBy!=null">
when id=#{i.id} then #{i.updatedBy}
</if>
</foreach>
</trim>
</trim>
updated_time = now()
where
<foreach collection="list" separator="or" item="i" index="index" >
id=#{i.id}
</foreach>
</update>
6 years ago
<!-- 根据topicId查询话题信息 (议题详情——话题信息) -->
<select id="selectDetail" parameterType="com.epmet.resi.group.dto.topic.form.TopicInfoFormDTO" resultType="com.epmet.resi.group.dto.topic.TopicInfoDTO">
SELECT
id AS topicId,
topic_content AS topicContent,
created_by AS publishedUser,
UNIX_TIMESTAMP( created_time ) AS publishedTime
FROM
resi_topic
WHERE
id = #{topicId}
AND del_flag = 0
</select>
<!-- 通过topicId查询话题所在组的网格Id和客户Id -->
<select id="getGroupInfoByTopicId" resultType="com.epmet.resi.group.dto.topic.result.ResiTopicAndGroupResultDTO">
SELECT
groupp.ID AS groupId,
IFNULL(groupp.GRID_ID,'') AS gridId,
IFNULL(groupp.CUSTOMER_ID,'') AS customerId,
topic.CREATED_BY AS topicAuthorId
FROM
RESI_TOPIC topic
INNER JOIN RESI_GROUP groupp ON topic.GROUP_ID = groupp.ID
WHERE
topic.DEL_FLAG = '0'
AND groupp.DEL_FLAG = '0'
AND topic.ID = #{topicId}
</select>
<!-- 查询话题和附件信息resultMap -->
<resultMap id="govTopicIssueInfoResultMap" type="com.epmet.resi.group.dto.topic.result.ResiTopicAttachmentsResultDTO">
<id property="topicId" column="TOPIC_ID"/>
<result property="topicContent" column="TOPIC_CONTENT"/>
<result property="createdBy" column="CREATED_BY" />
<result property="groupId" column="GROUP_ID" />
<result property="createdTime" column="CREATED_TIME" />
<collection property="photoList" ofType="java.lang.String">
<constructor>
<arg column="ATTACHMENT_URL"/>
</constructor>
</collection>
</resultMap>
<!-- 查询话题和附件信息 -->
<select id="selectTopicAndAttachments" resultMap="govTopicIssueInfoResultMap">
SELECT
topic.ID AS TOPIC_ID,
topic.TOPIC_CONTENT ,
topic.CREATED_BY ,
topic.GROUP_ID ,
topic.CREATED_TIME ,
attachment.ATTACHMENT_URL
FROM
resi_topic topic
LEFT JOIN
resi_topic_attachment attachment
ON
topic.ID = attachment.TOPIC_ID
AND
attachment.DEL_FLAG = '0'
WHERE
topic.DEL_FLAG = '0'
AND
topic.ID = #{topicId}
ORDER BY
attachment.SORT ASC
</select>
<!-- 校验本人是不是话题发起人 -->
<select id="checkTopicPublisher" parameterType="com.epmet.resi.group.dto.topic.form.CheckTopicPublisherFormDTO" resultType="com.epmet.resi.group.dto.topic.result.CheckTopicPublisherResultDTO">
SELECT
COUNT(*) AS checkTopicPublisher
FROM
resi_topic
WHERE
del_flag = 0
AND created_by = #{createdBy}
AND id = #{topicId}
</select>
<select id="listMyTopics" resultType="com.epmet.resi.group.dto.topic.result.MyTopicsResultDTO">
select t.id as topicId,
t.topic_content as topicContent,
unix_timestamp(t.created_time) as releaseTime,
g.GROUP_NAME as releaseGroupName
from resi_topic t
inner join resi_group g on (t.GROUP_ID = g.ID and g.CUSTOMER_ID = #{customerId})
where t.CREATED_BY = #{userId}
order by t.CREATED_TIME desc
</select>
</mapper>