forked from luyan/epmet-cloud-lingshan
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.
770 lines
29 KiB
770 lines
29 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.group.dao.ResiGroupDao">
|
|
|
|
<resultMap id="MyGroupResultDTOMap" type="com.epmet.resi.group.dto.group.result.MyGroupResultDTO">
|
|
<result property="groupId" column="id"/>
|
|
<result property="groupHeadPhoto" column="GROUP_HEAD_PHOTO"/>
|
|
<result property="groupName" column="GROUP_NAME"/>
|
|
<result property="totalMember" column="TOTAL_MEMBERS"/>
|
|
<result property="totalPartyMember" column="TOTAL_PARTY_MEMBERS"/>
|
|
<result property="groupState" column="STATE"/>
|
|
<result property="groupLeaderFlag" column="GROUP_LEADER_FLAG"/>
|
|
<association property="latestTopic" select="com.epmet.modules.group.dao.ResiGroupDao.selectLatestTopic" column="id">
|
|
</association>
|
|
</resultMap>
|
|
<!-- 我的小组查询(包含我创建的小组+我加入的小组),以各组的最新话题时间有近到远排序) -->
|
|
<select id="selectListMyGroup" parameterType="com.epmet.resi.group.dto.group.form.MyGroupFormDTO"
|
|
resultMap="MyGroupResultDTOMap">
|
|
SELECT
|
|
rg.id,
|
|
rg.GROUP_HEAD_PHOTO,
|
|
rg.GROUP_NAME ,
|
|
rgs.TOTAL_MEMBERS ,
|
|
rgs.TOTAL_PARTY_MEMBERS ,
|
|
rg.STATE ,
|
|
rgm.GROUP_LEADER_FLAG,
|
|
rg.GROUP_TYPE
|
|
FROM
|
|
resi_group_member rgm
|
|
LEFT JOIN resi_group rg ON ( rgm.RESI_GROUP_ID = rg.ID )
|
|
LEFT JOIN resi_group_statistical rgs ON ( rg.id = rgs.RESI_GROUP_ID )
|
|
WHERE
|
|
rg.DEL_FLAG = '0'
|
|
AND rgm.DEL_FLAG = '0'
|
|
AND rgs.DEL_FLAG = '0'
|
|
AND rg.CUSTOMER_ID = #{customerId}
|
|
AND rg.GRID_ID =#{gridId}
|
|
AND rgm.CUSTOMER_USER_ID = #{userId}
|
|
AND rgm.STATUS IN ( 'approved', 'silent' )
|
|
AND rg.STATE in('approved','hidden','closed')
|
|
order by rg.LATEST_TOPIC_PUBLISH_DATE desc
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<!-- 查询当前组最新话题 -->
|
|
<select id="selectLatestTopic" resultType="com.epmet.resi.group.dto.group.result.LatestTopicDTO">
|
|
SELECT
|
|
rt.id as topicId,
|
|
rt.TOPIC_CONTENT as topicContent
|
|
FROM
|
|
resi_topic rt
|
|
WHERE
|
|
rt.DEL_FLAG = '0'
|
|
and rt.GROUP_ID=#{groupId}
|
|
AND rt.STATUS = 'discussing'
|
|
order by rt.CREATED_TIME desc
|
|
limit 1
|
|
</select>
|
|
|
|
<!-- 推荐小组列表查询 -->
|
|
<select id="selectListRecommendGroup" parameterType="com.epmet.resi.group.dto.group.form.RecommendGroupFormDTO"
|
|
resultType="com.epmet.resi.group.dto.group.result.RecommendGroupResultDTO">
|
|
SELECT
|
|
rg.id AS groupId,
|
|
rg.GROUP_HEAD_PHOTO AS groupHeadPhoto,
|
|
rg.GROUP_NAME AS groupName,
|
|
rg.GROUP_TYPE AS groupType,
|
|
rgs.TOTAL_MEMBERS AS totalMember,
|
|
rgs.TOTAL_PARTY_MEMBERS AS totalPartyMember
|
|
FROM
|
|
resi_group rg
|
|
LEFT JOIN resi_group_statistical rgs ON ( rg.id = rgs.RESI_GROUP_ID )
|
|
WHERE
|
|
rg.DEL_FLAG = '0'
|
|
AND rgs.DEL_FLAG = '0'
|
|
and rg.id not in (
|
|
SELECT
|
|
rgm.RESI_GROUP_ID
|
|
FROM
|
|
resi_group_member rgm
|
|
WHERE
|
|
rgm.DEL_FLAG = '0'
|
|
AND rgm.`STATUS` !='removed'
|
|
AND rgm.CUSTOMER_USER_ID = #{userId}
|
|
)
|
|
and rg.CUSTOMER_ID=#{customerId}
|
|
and rg.GRID_ID=#{gridId}
|
|
and rg.STATE ='approved'
|
|
and rg.GROUP_TYPE != 'branch'
|
|
order by totalMember desc,rg.LATEST_TOPIC_PUBLISH_DATE desc
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<!-- 我创建的小组查询 -->
|
|
<select id="selectListMyCreated" parameterType="com.epmet.resi.group.dto.group.form.CreatedFormDTO"
|
|
resultType="com.epmet.resi.group.dto.group.result.CreatedResultDTO">
|
|
SELECT
|
|
rg.id AS groupId,
|
|
rg.GROUP_HEAD_PHOTO AS groupHeadPhoto,
|
|
rg.GROUP_NAME AS groupName,
|
|
rgs.TOTAL_MEMBERS AS totalMember,
|
|
rgs.TOTAL_PARTY_MEMBERS AS totalPartyMember,
|
|
rg.STATE AS groupState
|
|
FROM
|
|
resi_group_member rgm
|
|
LEFT JOIN resi_group rg ON ( rgm.RESI_GROUP_ID = rg.ID )
|
|
LEFT JOIN resi_group_statistical rgs ON ( rg.id = rgs.RESI_GROUP_ID )
|
|
WHERE
|
|
rg.DEL_FLAG = '0'
|
|
AND rgm.DEL_FLAG = '0'
|
|
AND rgs.DEL_FLAG = '0'
|
|
AND rg.CUSTOMER_ID = #{customerId}
|
|
AND rg.GRID_ID =#{gridId}
|
|
AND rgm.CUSTOMER_USER_ID = #{userId}
|
|
AND rgm.GROUP_LEADER_FLAG = 'leader'
|
|
ORDER BY
|
|
rg.CREATED_TIME DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<!-- 修改组信息 -->
|
|
<update id="modifyGroupInfo" parameterType="com.epmet.resi.group.dto.group.form.ModifyGroupFormDTO">
|
|
UPDATE resi_group rg
|
|
SET rg.GROUP_NAME = #{groupName},
|
|
rg.GROUP_HEAD_PHOTO = #{groupHeadPhoto},
|
|
rg.GROUP_INTRODUCTION =#{groupIntroduction},
|
|
rg.UPDATED_BY=#{userId},
|
|
rg.UPDATED_BY=NOW()
|
|
WHERE
|
|
rg.id = #{groupId}
|
|
AND rg.DEL_FLAG = '0'
|
|
</update>
|
|
|
|
<!-- 查看小组管理界面信息 -->
|
|
<select id="selectGroupSummarize" parameterType="com.epmet.resi.group.dto.group.form.GroupSummarizeFormDTO"
|
|
resultType="com.epmet.resi.group.dto.group.result.GroupSummarizeResultDTO">
|
|
SELECT
|
|
rg.id AS groupId,
|
|
rg.GROUP_HEAD_PHOTO AS groupHeadPhoto,
|
|
rg.GROUP_NAME AS groupName,
|
|
rg.GROUP_INTRODUCTION AS groupIntroduction,
|
|
rgs.TOTAL_MEMBERS AS totalMember,
|
|
rgs.TOTAL_PARTY_MEMBERS AS totalPartyMember,
|
|
rgm.GROUP_LEADER_FLAG AS leaderFlag,
|
|
(
|
|
SELECT
|
|
count(1)
|
|
FROM
|
|
group_memeber_operation gmo
|
|
WHERE
|
|
gmo.DEL_FLAG = '0'
|
|
AND gmo.GROUP_ID = rg.id
|
|
AND gmo.OPERATE_STATUS = 'under_auditting'
|
|
) AS totalApplyingMember,
|
|
rgs.TOTAL_TOPICS,
|
|
rg.AUDIT_SWITCH
|
|
FROM
|
|
resi_group rg
|
|
LEFT JOIN resi_group_statistical rgs ON ( rg.id = rgs.RESI_GROUP_ID )
|
|
LEFT JOIN resi_group_member rgm
|
|
ON ( rg.id = rgm.RESI_GROUP_ID
|
|
AND rgm.DEL_FLAG='0'
|
|
AND rgm.CUSTOMER_USER_ID =#{userId})
|
|
WHERE
|
|
rg.DEL_FLAG = '0'
|
|
AND rgs.DEL_FLAG = '0'
|
|
and rg.id=#{groupId}
|
|
</select>
|
|
|
|
<!-- 根据组信息查询组张信息 -->
|
|
<select id="selectGroupLeader" parameterType="java.lang.String" resultType="com.epmet.resi.group.dto.member.ResiGroupMemberDTO">
|
|
SELECT
|
|
rgm.ID,
|
|
rgm.CUSTOMER_USER_ID,
|
|
rgm.RESI_GROUP_ID,
|
|
rgm.GROUP_LEADER_FLAG,
|
|
rgm.ENTER_GROUP_TYPE,
|
|
rgm.GROUP_INVITATION_ID,
|
|
rgm.GROUP_LEADER_FLAG,
|
|
rgm.STATUS
|
|
FROM
|
|
resi_group_member rgm
|
|
WHERE
|
|
rgm.DEL_FLAG = '0'
|
|
AND rgm.GROUP_LEADER_FLAG = 'leader'
|
|
AND rgm.RESI_GROUP_ID = #{groupId}
|
|
</select>
|
|
|
|
<!-- 校验群名称是否存在 -->
|
|
<select id="checkResiGroupName" parameterType="com.epmet.resi.group.dto.group.form.ApplyCreateGroupFormDTO"
|
|
resultType="com.epmet.modules.group.entity.ResiGroupEntity">
|
|
SELECT
|
|
rg.*
|
|
FROM
|
|
resi_group rg
|
|
LEFT JOIN resi_group_member rgm ON ( rg.id = rgm.RESI_GROUP_ID AND rgm.DEL_FLAG = '0')
|
|
WHERE
|
|
rg.DEL_FLAG = '0'
|
|
AND rgm.GROUP_LEADER_FLAG = 'leader'
|
|
AND rgm.CUSTOMER_USER_ID = #{userId}
|
|
AND rg.GROUP_NAME = #{groupName}
|
|
AND rg.CUSTOMER_ID = #{customerId}
|
|
AND rg.GRID_ID = #{gridId}
|
|
AND rg.STATE in('approved','under_auditting')
|
|
</select>
|
|
|
|
<!-- 小组审核历史 -->
|
|
<select id="selectAuditedGroupList" parameterType="com.epmet.resi.group.dto.group.form.GroupAuditedFromDTO"
|
|
resultType="com.epmet.resi.group.dto.group.result.GroupAuditedResultDTO">
|
|
SELECT
|
|
rg.ID AS "groupId",
|
|
rg.GROUP_HEAD_PHOTO AS "groupHeadPhoto",
|
|
rg.GROUP_NAME AS "groupName",
|
|
rg.GROUP_INTRODUCTION AS "groupIntroduction",
|
|
rgo.STATE AS "status",
|
|
rgo.MESSAGE_TEXT AS "messageText",
|
|
rgo.UPDATED_TIME AS "auditedTime"
|
|
FROM
|
|
resi_group rg
|
|
INNER JOIN resi_group_operation rgo ON rg.ID = rgo.RESI_GROUP_ID
|
|
WHERE rg.CUSTOMER_ID = #{customerId}
|
|
AND rg.GRID_ID = #{gridId}
|
|
AND (rgo.STATE = 'approved' OR rgo.STATE = 'rejected')
|
|
AND rg.DEL_FLAG = '0'
|
|
AND rgo.DEL_FLAG = '0'
|
|
ORDER BY
|
|
rgo.UPDATED_TIME DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
<select id="selectGroupsByGridId" resultType="com.epmet.modules.group.entity.ResiGroupEntity">
|
|
SELECT
|
|
*
|
|
FROM
|
|
resi_group
|
|
WHERE CUSTOMER_ID = #{customerId}
|
|
AND GRID_ID = #{gridId}
|
|
AND DEL_FLAG = '0'
|
|
ORDER BY
|
|
LATEST_TOPIC_PUBLISH_DATE DESC
|
|
LIMIT #{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<!-- 查询审核中的组信息列表(分页),一条组数据可能对应多条组操作记录,所以要限制组数据和组操作数据当前都在'待审核'状态来锁定唯一的映射关系 -->
|
|
<select id="getApplyingGroupsByCustIdAndGridId" parameterType="com.epmet.resi.group.dto.group.form.ApplyingGroupsFormDTO" resultType="com.epmet.resi.group.dto.group.result.ApplyingGroupResultDTO">
|
|
SELECT
|
|
gro.ID AS groupId,
|
|
gro.GROUP_TYPE AS groupType,
|
|
gro.GROUP_NAME AS groupName,
|
|
gro.GROUP_HEAD_PHOTO AS groupHeadPhoto,
|
|
oper.READ_FLAG AS readFlag,
|
|
oper.MESSAGE_TEXT AS messageText,
|
|
CASE
|
|
WHEN TO_DAYS(oper.CREATED_TIME) = TO_DAYS(NOW()) THEN DATE_FORMAT(oper.CREATED_TIME,'%k:%i')
|
|
ELSE DATE_FORMAT(oper.CREATED_TIME,'%Y-%m-%d %k:%i')
|
|
END
|
|
AS createdTime
|
|
FROM
|
|
RESI_GROUP gro
|
|
LEFT JOIN RESI_GROUP_OPERATION oper ON ( gro.ID = oper.RESI_GROUP_ID AND oper.DEL_FLAG = '0' )
|
|
WHERE
|
|
gro.DEL_FLAG = '0'
|
|
AND gro.CUSTOMER_ID = #{customerId}
|
|
AND gro.GRID_ID = #{gridId}
|
|
AND gro.STATE = 'under_auditting'
|
|
AND oper.STATE = 'under_auditting'
|
|
ORDER BY gro.CREATED_TIME DESC
|
|
LIMIT #{pageNo},#{pageSize}
|
|
</select>
|
|
|
|
<!-- 获取组审核信息详情,已审核/未审核通用,一条组数据可能对应多条组操作记录,所以要限制组操作数据当前在'待审核'、'通过'、'拒绝通过'这三种状态之中的某个状态来锁定唯一的映射关系,因为每条组数据所对应的组操作记录的上述三种状态只能存在一种 -->
|
|
<select id="getApplyingGroupDetailByGroupId" parameterType="java.lang.String" resultType="com.epmet.resi.group.dto.group.result.ApplyingGroupDetailResultDTO">
|
|
SELECT
|
|
gro.ID AS groupId,
|
|
gro.GROUP_NAME AS groupName,
|
|
gro.GROUP_HEAD_PHOTO AS groupHeadPhoto,
|
|
gro.GROUP_INTRODUCTION AS groupIntroduction,
|
|
oper.READ_FLAG AS readFlag,
|
|
oper.MESSAGE_TEXT AS messageText,
|
|
oper.CREATED_TIME AS createdTime,
|
|
oper.STATE AS status,
|
|
oper.OPERATE_REASON rejectReason,
|
|
gro.CREATED_BY AS leaderId,
|
|
oper.READ_FLAG AS readFlag,
|
|
oper.ID AS operationId
|
|
FROM
|
|
RESI_GROUP gro
|
|
LEFT JOIN RESI_GROUP_OPERATION oper ON ( gro.ID = oper.RESI_GROUP_ID AND oper.DEL_FLAG = '0' )
|
|
WHERE
|
|
gro.DEL_FLAG = '0'
|
|
AND gro.ID = #{groupId}
|
|
AND oper.STATE IN ('under_auditting','approved','rejected')
|
|
</select>
|
|
|
|
<!-- 校验用户是否加入小组 -->
|
|
<select id="checkjointeam" parameterType="com.epmet.resi.group.dto.group.form.GridIdFormDTO" resultType="integer">
|
|
SELECT
|
|
COUNT(*) AS joinTeamCounts
|
|
FROM
|
|
resi_group_member rgm
|
|
WHERE
|
|
EXISTS (
|
|
SELECT
|
|
rg.id
|
|
FROM
|
|
resi_group rg
|
|
WHERE
|
|
rg.del_flag = 0
|
|
AND rgm.resi_group_id = rg.id
|
|
AND rg.grid_id = #{gridId}
|
|
)
|
|
AND rgm.CUSTOMER_USER_ID = #{userId}
|
|
AND rgm.del_flag = 0
|
|
</select>
|
|
|
|
<!-- 查询一个网格下面所有组Id -->
|
|
<select id="getGroupIdByGridId" resultType="java.lang.String">
|
|
SELECT
|
|
DISTINCT
|
|
ID
|
|
FROM RESI_GROUP
|
|
WHERE
|
|
DEL_FLAG = '0'
|
|
AND
|
|
GRID_ID = #{gridId}
|
|
</select>
|
|
|
|
<!-- 获取应表决数 -->
|
|
<select id="shouldVoteCount" parameterType="com.epmet.resi.group.dto.group.form.ShouldVoteCountFormDTO" resultType="com.epmet.resi.group.dto.group.result.ShouldVoteCountResultDTO">
|
|
SELECT
|
|
COUNT(DISTINCT CUSTOMER_USER_ID) AS shouldVoteCount
|
|
FROM
|
|
resi_group_member rgm
|
|
LEFT JOIN resi_group rg ON rgm.resi_group_id = rg.id
|
|
WHERE
|
|
rgm.del_flag = 0
|
|
AND rg.del_flag = 0
|
|
AND rg.grid_id = #{gridId}
|
|
</select>
|
|
|
|
<!-- 获取议题创建之前,被踢出小组的人数 -->
|
|
<select id="getOutGroupCount" parameterType="com.epmet.resi.group.dto.group.form.ShouldVoteCountFormDTO" resultType="integer">
|
|
SELECT
|
|
COUNT(*) AS shouldVoteCount
|
|
FROM
|
|
resi_group_member rgm
|
|
LEFT JOIN resi_group rg ON rgm.resi_group_id = rg.id
|
|
WHERE
|
|
rgm.del_flag = 0
|
|
AND rg.del_flag = 0
|
|
AND rgm.STATUS = 'removed'
|
|
AND UNIX_TIMESTAMP( rgm.updated_time ) < #{issueCreatedTime}
|
|
AND rg.grid_id = #{gridId}
|
|
</select>
|
|
|
|
<select id="selectListRecommendList" resultType="com.epmet.resi.group.dto.group.result.RecommendedListResultDTO"
|
|
parameterType="com.epmet.resi.group.dto.group.form.RecommendedListFormDTO">
|
|
SELECT
|
|
rg.id AS groupId,
|
|
rg.GROUP_HEAD_PHOTO AS groupHeadPhoto,
|
|
rg.GROUP_NAME AS groupName,
|
|
rgs.TOTAL_MEMBERS AS totalMember,
|
|
rgs.TOTAL_PARTY_MEMBERS AS totalPartyMember
|
|
FROM
|
|
resi_group rg
|
|
LEFT JOIN resi_group_statistical rgs ON ( rg.id = rgs.RESI_GROUP_ID )
|
|
WHERE
|
|
NOT EXISTS (
|
|
SELECT
|
|
rgm.RESI_GROUP_ID
|
|
FROM
|
|
resi_group_member rgm
|
|
WHERE
|
|
rgm.DEL_FLAG = '0'
|
|
AND rgm.`STATUS` != 'removed'
|
|
AND rgm.CUSTOMER_USER_ID = #{userId}
|
|
AND rgm.RESI_GROUP_ID = rg.ID
|
|
)
|
|
AND NOT EXISTS (
|
|
SELECT
|
|
rmo.GROUP_ID
|
|
FROM
|
|
group_memeber_operation rmo
|
|
WHERE
|
|
rmo.DEL_FLAG = '0'
|
|
AND rmo.CUSTOMER_USER_ID = #{userId}
|
|
AND rmo.OPERATE_STATUS = 'under_auditting'
|
|
AND rmo.GROUP_ID = rg.ID
|
|
)
|
|
AND rg.DEL_FLAG = '0'
|
|
AND rgs.DEL_FLAG = '0'
|
|
AND rg.CUSTOMER_ID = #{customerId}
|
|
AND rg.GRID_ID = #{gridId}
|
|
AND rg.STATE = 'approved'
|
|
ORDER BY
|
|
totalMember DESC,
|
|
rgs.TOTAL_TOPICS DESC
|
|
LIMIT #{pageSize}
|
|
</select>
|
|
|
|
<!-- 根据网格IdList查询小组信息 -->
|
|
<select id="selectGroupListByGridIds" resultType="com.epmet.resi.group.dto.group.ResiGroupDTO">
|
|
SELECT
|
|
ID,
|
|
GRID_ID
|
|
FROM
|
|
RESI_GROUP
|
|
WHERE
|
|
DEL_FLAG = '0'
|
|
<foreach collection="gridIds" item="gridId" open="AND (" separator=" or " close=")" index="index">
|
|
GRID_ID = #{gridId}
|
|
</foreach>
|
|
</select>
|
|
|
|
<select id="countExistsGroupNameBeforeEdit" resultType="java.lang.Integer">
|
|
select sum(t.c) num
|
|
from (
|
|
select count(1) c
|
|
from resi_group g
|
|
where g.GROUP_NAME = #{groupName}
|
|
and g.DEL_FLAG = 0
|
|
and g.GRID_ID = #{gridId}
|
|
and g.ID != #{groupId}
|
|
and g.STATE in ('approved', 'under_auditting')
|
|
union all
|
|
select count(1) c
|
|
from group_edit_submit_record esr
|
|
where esr.GROUP_ID != #{groupId}
|
|
and esr.GRID_ID = #{gridId}
|
|
and esr.GROUP_NAME = #{groupName}
|
|
and esr.AUDIT_STATUS = 'under_auditting'
|
|
and esr.DEL_FLAG = 0
|
|
) t
|
|
</select>
|
|
|
|
<!-- 查询话题所属小组名 -->
|
|
<select id="selectGroupInfo" resultType="com.epmet.resi.group.dto.group.result.GroupInfoResultDTO">
|
|
SELECT
|
|
rt.ID AS topicId,
|
|
rg.GROUP_NAME AS topicGroupName
|
|
FROM resi_topic rt
|
|
LEFT JOIN resi_group rg ON rg.ID = rt.GROUP_ID
|
|
WHERE rt.DEL_FLAG = '0'
|
|
AND rg.DEL_FLAG = '0'
|
|
AND
|
|
<foreach collection="topicIds" item="topicId" separator=" OR ">
|
|
rt.id = #{topicId}
|
|
</foreach>
|
|
|
|
</select>
|
|
|
|
<!-- 查询话题信息 -->
|
|
<resultMap id="selectTopicInfoMap" type="com.epmet.resi.group.dto.group.result.TopicInfoResultDTO">
|
|
<result property="publishedTime" column="publishedTime"/>
|
|
<result property="topicContent" column="topicContent"/>
|
|
<result property="topicId" column="topicId"/>
|
|
<result property="topicUserId" column="topicUserId"/>
|
|
<collection property="topicImgs" ofType="java.lang.String">
|
|
<result column="imgUrl"/>
|
|
<result column="id"/>
|
|
</collection>
|
|
</resultMap>
|
|
<select id="selectTopicInfo" resultMap="selectTopicInfoMap">
|
|
SELECT
|
|
rt.ID AS topicId,
|
|
rt.CREATED_BY AS topicUserId,
|
|
UNIX_TIMESTAMP(rt.CREATED_TIME) AS publishedTime,
|
|
rt.TOPIC_CONTENT as topicContent,
|
|
ta.ATTACHMENT_URL AS imgUrl
|
|
FROM resi_topic rt
|
|
LEFT JOIN resi_topic_attachment ta ON ta.TOPIC_ID = rt.ID
|
|
WHERE rt.DEL_FLAG = '0'
|
|
AND rt.ID = #{topicId}
|
|
</select>
|
|
|
|
<select id="selectListByIds" resultType="com.epmet.resi.group.dto.group.ResiGroupDTO" parameterType="map">
|
|
select rg.* from resi_group rg
|
|
where rg.DEL_FLAG='0'
|
|
<if test="groupIds!=null and groupIds.size()!=0">
|
|
and
|
|
<foreach collection="groupIds" item="groupId" open="(" close=")" separator=" OR ">
|
|
RG.ID = #{groupId}
|
|
</foreach>
|
|
</if>
|
|
</select>
|
|
|
|
<!-- 根据网格id查询,返回每个网格的待审核小组总数+变更小组信息申请数 -->
|
|
<select id="queryGroupProcessingCount" parameterType="map" resultType="com.epmet.resi.group.dto.group.GroupProcessingCountResultDTO">
|
|
SELECT
|
|
temp.gridId,
|
|
sum( total ) AS count
|
|
FROM
|
|
(
|
|
SELECT
|
|
rg.GRID_ID AS gridId,
|
|
count(*) AS total
|
|
FROM
|
|
resi_group rg
|
|
WHERE
|
|
rg.DEL_FLAG = '0'
|
|
AND rg.STATE = 'under_auditting'
|
|
<if test="gridIdList!=null and gridIdList.size()!=0">
|
|
AND rg.GRID_ID IN
|
|
<foreach collection="gridIdList" item="gridId" open="(" close=")" separator=",">
|
|
#{gridId}
|
|
</foreach>
|
|
</if>
|
|
GROUP BY
|
|
rg.GRID_ID
|
|
UNION ALL
|
|
SELECT
|
|
m.GRID_ID AS gridId,
|
|
count( 1 ) AS total
|
|
FROM
|
|
group_edit_submit_record m
|
|
WHERE
|
|
m.DEL_FLAG = '0'
|
|
AND m.AUDIT_STATUS = 'under_auditing'
|
|
<if test="gridIdList!=null and gridIdList.size()!=0">
|
|
AND m.GRID_ID IN
|
|
<foreach collection="gridIdList" item="gridId" open="(" close=")" separator=",">
|
|
#{gridId}
|
|
</foreach>
|
|
</if>
|
|
group by m.GRID_ID
|
|
) temp
|
|
GROUP BY
|
|
temp.gridId
|
|
</select>
|
|
|
|
<select id="selectAllGroupList" resultType="com.epmet.resi.group.dto.group.result.AllGroupListResultDTO">
|
|
SELECT
|
|
rg.id AS groupId,
|
|
rg.group_head_photo AS groupHeadPhoto,
|
|
rg.group_name AS groupName,
|
|
rg.group_type AS groupType,
|
|
rgs.total_members AS totalMember,
|
|
rgs.total_party_members AS totalPartyMember
|
|
FROM
|
|
resi_group rg
|
|
LEFT JOIN resi_group_statistical rgs ON (rg.id = rgs.resi_group_id)
|
|
WHERE
|
|
rg.del_flag = '0'
|
|
AND rgs.del_flag = '0'
|
|
AND rg.grid_id = #{gridId}
|
|
AND rg.state = 'approved'
|
|
ORDER BY
|
|
totalMember DESC
|
|
LIMIT
|
|
#{pageNo}, #{pageSize}
|
|
</select>
|
|
|
|
<!-- 查询 话题、通知、活动最近10条数据 -->
|
|
<select id="selectLatestTen" resultType="com.epmet.resi.group.dto.topic.result.LatestTenResultDTO">
|
|
SELECT id,userId,releaseTime,content,status,issueId,contentType,firstPhoto FROM
|
|
((SELECT
|
|
t.ID,
|
|
t.CREATED_BY AS userId,
|
|
DATE_FORMAT(t.CREATED_TIME,'%Y-%m-%d %H:%m:%s') AS releaseTime,
|
|
t.TOPIC_CONTENT AS content,
|
|
t.`STATUS` AS status,
|
|
IFNULL(t.ISSUE_ID,'') AS issueId,
|
|
'topic' AS contentType,
|
|
IFNULL(ta.ATTACHMENT_URL,'') AS firstPhoto
|
|
FROM resi_topic t
|
|
LEFT JOIN resi_topic_attachment ta ON ta.TOPIC_ID = t.ID AND ta.ATTACHMENT_TYPE = 'image' AND ta.SORT = 0
|
|
WHERE t.DEL_FLAG = '0'
|
|
AND t.`STATUS` != 'hidden'
|
|
AND t.GROUP_ID = #{groupId}
|
|
ORDER BY t.CREATED_TIME DESC
|
|
LIMIT 10)
|
|
UNION ALL
|
|
(SELECT
|
|
ai.ID,
|
|
ai.CREATED_BY AS userId,
|
|
DATE_FORMAT(ai.CREATED_TIME,'%Y-%m-%d %H:%m:%s') AS releaseTime,
|
|
IFNULL(ac.CONTENT,'') AS content,
|
|
ai.`STATUS` AS status,
|
|
'' AS issueId,
|
|
'act' AS contentType,
|
|
IFNULL(ac2.CONTENT,'') AS firstPhoto
|
|
FROM group_act_info ai
|
|
LEFT JOIN group_act_content ac ON ac.GROUP_ACT_ID = ai.ID AND ac.CONTENT_TYPE = 'text'
|
|
LEFT JOIN group_act_content ac2 ON ac2.GROUP_ACT_ID = ai.ID AND ac2.CONTENT_TYPE = 'img' AND ac2.SORT = 1
|
|
WHERE ai.DEL_FLAG = '0'
|
|
AND ai.GROUP_ID = #{groupId}
|
|
ORDER BY ai.CREATED_TIME DESC
|
|
LIMIT 10)
|
|
UNION ALL
|
|
(SELECT
|
|
n.ID,
|
|
n.CREATED_BY AS userId,
|
|
DATE_FORMAT(n.CREATED_TIME,'%Y-%m-%d %H:%m:%s') AS releaseTime,
|
|
n.CONTENT AS content,
|
|
'' AS status,
|
|
'' AS issueId,
|
|
'notice' AS contentType,
|
|
IFNULL(na.ATTACHMENT_URL,'') AS firstPhoto
|
|
FROM notice n
|
|
LEFT JOIN notice_attachment na ON na.NOTICE_ID = n.ID AND na.DEL_FLAG = '0' AND na.ATTACHMENT_TYPE = 'image' AND na.SORT = 0
|
|
WHERE n.DEL_FLAG = '0'
|
|
AND n.GROUP_ID = #{groupId}
|
|
ORDER BY n.CREATED_TIME DESC
|
|
LIMIT 10)
|
|
)temp
|
|
ORDER BY releaseTime DESC
|
|
LIMIT 10
|
|
</select>
|
|
|
|
<!-- 查询此人在小组内未读数量 -->
|
|
<select id="selectUserUnRead" resultType="java.lang.Integer">
|
|
SELECT IFNULL(SUM(unRead),0) FROM
|
|
((SELECT
|
|
COUNT( 1 ) AS unRead
|
|
FROM act_read_record
|
|
WHERE DEL_FLAG = 0
|
|
AND `READ_FLAG` = 'un_read'
|
|
AND USER_ID = #{userId}
|
|
AND GROUP_ID = #{groupId})
|
|
UNION ALL
|
|
(SELECT
|
|
COUNT( 1 ) AS unRead
|
|
FROM notice_read_record
|
|
WHERE DEL_FLAG = 0
|
|
AND READ_FLAG = 'un_read'
|
|
AND USER_ID = #{userId}
|
|
AND GROUP_ID = #{groupId})) temp
|
|
</select>
|
|
|
|
<!-- 查询阅读状态 -->
|
|
<select id="selectUserReadFlag" resultType="com.epmet.resi.group.dto.group.result.UserReadFlagResultDTO">
|
|
(SELECT
|
|
READ_FLAG,
|
|
USER_ID,
|
|
GROUP_ACT_ID AS id
|
|
FROM act_read_record
|
|
WHERE
|
|
DEL_FLAG = 0
|
|
AND (
|
|
<foreach collection="userIds" item="userId" separator=" OR ">
|
|
USER_ID = #{userId}
|
|
</foreach>
|
|
)
|
|
AND (
|
|
<foreach collection="ids" item="id" separator=" OR ">
|
|
GROUP_ACT_ID = #{id}
|
|
</foreach>
|
|
)
|
|
AND GROUP_ID = #{groupId}
|
|
)
|
|
UNION ALL
|
|
(SELECT
|
|
READ_FLAG,
|
|
USER_ID,
|
|
NOTICE_ID AS id
|
|
FROM notice_read_record
|
|
WHERE
|
|
DEL_FLAG = 0
|
|
AND (
|
|
<foreach collection="userIds" item="userId" separator=" OR ">
|
|
USER_ID = #{userId}
|
|
</foreach>
|
|
)
|
|
AND (
|
|
<foreach collection="ids" item="id" separator=" OR ">
|
|
NOTICE_ID = #{id}
|
|
</foreach>
|
|
)
|
|
AND GROUP_ID = #{groupId}
|
|
)
|
|
</select>
|
|
|
|
<!-- 根据 活动或通知查询 未读人数 -->
|
|
<select id="selectUserUnReadById" resultType="com.epmet.resi.group.dto.group.result.UserUnReadResultDTO">
|
|
(SELECT
|
|
GROUP_ACT_ID AS id,
|
|
COUNT( 1 ) AS unRead
|
|
FROM act_read_record
|
|
WHERE DEL_FLAG = 0
|
|
AND (
|
|
<foreach collection="ids" item="id" separator=" OR ">
|
|
GROUP_ACT_ID = #{id}
|
|
</foreach>
|
|
)
|
|
AND `READ_FLAG` = 'un_read'
|
|
AND GROUP_ID = #{groupId}
|
|
GROUP BY GROUP_ACT_ID
|
|
)
|
|
UNION ALL
|
|
(SELECT
|
|
NOTICE_ID AS id,
|
|
COUNT( 1 ) AS unRead
|
|
FROM notice_read_record
|
|
WHERE DEL_FLAG = 0
|
|
AND (
|
|
<foreach collection="ids" item="id" separator=" OR ">
|
|
NOTICE_ID = #{id}
|
|
</foreach>
|
|
)
|
|
AND `READ_FLAG` = 'un_read'
|
|
AND GROUP_ID = #{groupId}
|
|
GROUP BY NOTICE_ID
|
|
)
|
|
</select>
|
|
|
|
<!-- 根据用户ID查询小组下未读的 通知、活动 -->
|
|
<select id="selectUnReadByUserId" resultType="com.epmet.resi.group.dto.group.result.UserReadFlagResultDTO">
|
|
(SELECT
|
|
USER_ID,
|
|
GROUP_ACT_ID AS id
|
|
FROM act_read_record
|
|
WHERE DEL_FLAG = 0
|
|
AND READ_FLAG = 'un_read'
|
|
AND USER_ID = #{userId}
|
|
AND GROUP_ID = #{groupId}
|
|
)
|
|
UNION ALL
|
|
(SELECT
|
|
USER_ID,
|
|
NOTICE_ID AS id
|
|
FROM notice_read_record
|
|
WHERE DEL_FLAG = 0
|
|
AND READ_FLAG = 'un_read'
|
|
AND USER_ID = #{userId}
|
|
AND GROUP_ID = #{groupId}
|
|
)
|
|
</select>
|
|
|
|
<!-- 查询未读的通知和活动信息 -->
|
|
<select id="selectUnReadInfos" resultType="com.epmet.resi.group.dto.notice.result.UnReadListResultDTO">
|
|
SELECT id,userId,releaseTime,content,contentType,firstPhoto FROM
|
|
(
|
|
(SELECT
|
|
ai.ID,
|
|
ai.CREATED_BY AS userId,
|
|
DATE_FORMAT(ai.CREATED_TIME,'%Y-%m-%d %H:%m:%s') AS releaseTime,
|
|
IFNULL(ac.CONTENT,'') AS content,
|
|
'act' AS contentType,
|
|
IFNULL(ac2.CONTENT,'') AS firstPhoto
|
|
FROM group_act_info ai
|
|
LEFT JOIN group_act_content ac ON ac.GROUP_ACT_ID = ai.ID AND ac.CONTENT_TYPE = 'text'
|
|
LEFT JOIN group_act_content ac2 ON ac2.GROUP_ACT_ID = ai.ID AND ac2.CONTENT_TYPE = 'img' AND ac2.SORT = 1
|
|
WHERE ai.DEL_FLAG = '0'
|
|
AND (
|
|
<foreach collection="ids" item="id" separator=" OR ">
|
|
ai.id = #{id}
|
|
</foreach>
|
|
)
|
|
)
|
|
UNION ALL
|
|
(SELECT
|
|
n.ID,
|
|
n.CREATED_BY AS userId,
|
|
DATE_FORMAT(n.CREATED_TIME,'%Y-%m-%d %H:%m:%s') AS releaseTime,
|
|
n.CONTENT AS content,
|
|
'notice' AS contentType,
|
|
IFNULL(na.ATTACHMENT_URL,'') AS firstPhoto
|
|
FROM notice n
|
|
LEFT JOIN notice_attachment na ON na.NOTICE_ID = n.ID AND na.DEL_FLAG = '0' AND na.ATTACHMENT_TYPE = 'image' AND na.SORT = 0
|
|
WHERE n.DEL_FLAG = '0'
|
|
AND (
|
|
<foreach collection="ids" item="id" separator=" OR ">
|
|
n.id = #{id}
|
|
</foreach>
|
|
)
|
|
)
|
|
)temp
|
|
</select>
|
|
|
|
</mapper>
|
|
|