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.
 
 
 
 
 

601 lines
20 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'
AND attachment.ATTACHMENT_TYPE = 'image'
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'
AND attachment.ATTACHMENT_TYPE = 'image'
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'
AND attachment.ATTACHMENT_TYPE = 'image'
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>
<!-- 根据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'
AND
attachment.ATTACHMENT_TYPE = 'image'
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="listMyCreateTopics" resultType="com.epmet.resi.group.dto.topic.result.MyCreateTopicsResultDTO">
select t.id as topicId,
t.topic_content as topicContent,
unix_timestamp(t.created_time) as releaseTime,
g.GROUP_NAME as releaseGroupName,
g.GRID_ID as releaseGridId,
t.GROUP_ID as groupId
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>
<select id="selectIssueList" resultType="com.epmet.resi.group.dto.topic.result.IssueGridResultDTO">
SELECT
rt.issue_id AS "issueId",
rg.grid_id AS "gridId"
FROM
resi_topic rt
INNER JOIN resi_group rg ON rt.group_id = rg.id
WHERE
rt.del_flag = '0'
AND rt.shift_issue = '1'<!-- 话题转议题标志 -->
<foreach collection="topicList" item="topicId" open="AND( " separator=" OR " index="index" close=")">
rt.id = #{topicId}
</foreach>
</select>
<!-- 查询我参与过的话题 -->
<select id="selectParticipatedTopics" resultType="com.epmet.resi.group.dto.topic.result.ParticipatedTopicUnitResultDTO">
SELECT
topic.id AS topicId,
topic.topic_content,
UNIX_TIMESTAMP(topic.created_time) AS releaseTime,
groupp.group_name AS topicReleaseGroupName,
groupp.grid_id AS topicReleaseGridName,
topic.GROUP_ID
FROM
resi_topic topic LEFT JOIN resi_group groupp ON topic.group_id = groupp.ID AND groupp.del_flag = '0' AND groupp.customer_id = #{customerId}
WHERE
topic.del_flag = '0'
and topic.`STATUS`!='hidden'
AND
topic.id IN (
SELECT DISTINCT topic_id FROM resi_topic_comment WHERE
del_flag = '0' AND created_by = #{userId}
)
AND topic.created_by <![CDATA[ <> ]]> #{userId}
ORDER BY topic.created_time desc
</select>
<!-- 查询我创建的话题 -->
<select id="selectMyCreateTopic" resultType="java.lang.String">
SELECT
id
FROM
resi_topic
WHERE
del_flag = '0'
AND created_by = #{userId}
</select>
<!-- 查询我评论过的话题 -->
<select id="selectMyPartTopic" resultType="java.lang.String">
SELECT
DISTINCT(rt.ID) AS topicIds
FROM resi_topic rt
LEFT JOIN resi_topic_comment rtc ON rtc.TOPIC_ID = rt.ID
WHERE rt.DEL_FLAG = '0'
AND rtc.DEL_FLAG = '0'
AND rt.CREATED_BY != #{userId}
AND rtc.CREATED_BY = #{userId}
</select>
<select id="selectTopicIdsByGroup" resultType="java.lang.String">
select ID
FROM resi_topic
WHERE del_flag = 0
AND GROUP_ID = #{groupId}
AND STATUS != 'hidden'
</select>
<!-- 查询议题所在小组 -->
<select id="selectGroupIdByIssueId" resultType="string">
SELECT
group_id
FROM
resi_topic
WHERE
del_flag = '0'
AND
issue_id = #{issueId}
AND
shift_issue = 1
</select>
<!--查询此人今日发表话题数量 -->
<select id="selectPublishTopicCountByUserId" resultType="java.lang.Integer">
SELECT
COUNT(ID)
FROM resi_topic
WHERE DEL_FLAG = 0
AND DATE_FORMAT(CREATED_TIME,'%Y%m%d') = DATE_FORMAT(NOW(),'%Y%m%d')
AND CREATED_BY = #{userId}
</select>
<!-- 根据topicId查询客户ID -->
<select id="selectCustomerIdByTopicId" resultType="java.lang.String">
SELECT g.CUSTOMER_ID FROM resi_topic t
LEFT JOIN resi_group g ON g.ID = t.GROUP_ID
WHERE t.DEL_FLAG = 0
AND g.DEL_FLAG = 0
AND t.ID = #{topicId}
</select>
<select id="selectByIssueId" parameterType="map" resultType="com.epmet.resi.group.dto.topic.ResiTopicDTO">
select * from resi_topic rt
where rt.DEL_FLAG='0'
and rt.ISSUE_ID=#{issueId}
</select>
<!-- 查询小组内还未成为议题的是当前人员创建的讨论中的话题 -->
<select id="selectIdList" resultType="java.lang.String">
SELECT
id
FROM
resi_topic
WHERE
del_flag = '0'
AND shift_issue = '0'
AND `status` = 'discussing'
AND group_id = #{groupId}
AND created_by = #{userId}
</select>
<update id="upTopicList">
UPDATE resi_topic
SET status = 'hidden',
updated_by = #{userId},
updated_time = NOW()
WHERE
del_flag = '0'
<foreach collection="delIdList" item="id" open="AND (" close=")" separator=" OR ">
id = #{id}
</foreach>
</update>
</mapper>