榆山
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.

502 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.elink.esua.epdc.modules.smile.group.dao.GroupDao">
<select id="selectListOfGroups" resultType="com.elink.esua.epdc.smile.dto.group.GroupManagementDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.CREATED_TIME,
gp.SECTION_CODE,
gp.CATEGORY_CODE,
ugp.NICKNAME,
gp.STATE
FROM
epdc_group gp
LEFT JOIN epdc_user_group ugp ON ugp.GROUP_ID = gp.ID
AND ugp.DEL_FLAG = '0'
AND ugp.LORD_FLAG = '1'
WHERE
gp.DEL_FLAG = '0'
AND gp.SECTION_CODE = 'theme_group'
AND gp.CATEGORY_CODE = 'property_group'
AND gp.TYPE_KEY = 'grid_party'
<if test="state != null and state != ''">
AND gp.STATE = #{state}
</if>
<if test="gridId != null and gridId != ''">
AND (gp.DEPT_ID = #{gridId}
OR find_in_set(#{gridId},gp.ALL_DEPT_IDS))
</if>
<if test="streetId != null and streetId != ''">
AND (find_in_set(#{streetId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{streetId},gp.ALL_DEPT_IDS))
</if>
<if test="communityId != null and communityId != ''">
AND (find_in_set(#{communityId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{communityId},gp.ALL_DEPT_IDS))
</if>
ORDER BY
gp.CATEGORY_CODE, gp.CREATED_TIME DESC
</select>
<select id="selectPoliceListOfGroups" resultType="com.elink.esua.epdc.smile.dto.group.GroupManagementDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.CREATED_TIME,
gp.SECTION_CODE,
gp.CATEGORY_CODE,
ugp.NICKNAME,
gp.STATE
FROM
epdc_group gp
LEFT JOIN epdc_user_group ugp ON ugp.GROUP_ID = gp.ID
AND ugp.DEL_FLAG = '0'
AND ugp.LORD_FLAG = '1'
WHERE
gp.DEL_FLAG = '0'
AND gp.SECTION_CODE = 'theme_group'
AND gp.CATEGORY_CODE = 'police_group'
AND gp.TYPE_KEY = 'community_party'
<if test="state != null and state != ''">
AND gp.STATE = #{state}
</if>
<if test="deptId != null and deptId != ''">
AND (gp.DEPT_ID = #{deptId}
OR find_in_set(#{deptId},gp.ALL_DEPT_IDS))
</if>
<if test="gridId != null and gridId != ''">
AND (gp.DEPT_ID = #{gridId}
OR find_in_set(#{gridId},gp.ALL_DEPT_IDS))
</if>
<if test="streetId != null and streetId != ''">
AND (find_in_set(#{streetId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{streetId},gp.ALL_DEPT_IDS))
</if>
<if test="communityId != null and communityId != ''">
AND (find_in_set(#{communityId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{communityId},gp.ALL_DEPT_IDS))
</if>
ORDER BY
gp.CATEGORY_CODE, gp.CREATED_TIME DESC
</select>
<select id="selectInterestListOfGroups" resultType="com.elink.esua.epdc.smile.dto.group.GroupManagementDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.CREATED_TIME,
gp.SECTION_CODE,
gp.CATEGORY_CODE,
gp.ALL_DEPT_NAMES,
ugp.NICKNAME,
gp.STATE
FROM
epdc_group gp
LEFT JOIN epdc_user_group ugp ON ugp.GROUP_ID = gp.ID
AND ugp.DEL_FLAG = '0'
AND ugp.LORD_FLAG = '1'
WHERE
gp.DEL_FLAG = '0'
AND gp.SECTION_CODE = 'interest_group'
<if test="categoryCode != null and categoryCode != ''">
AND gp.CATEGORY_CODE = 'interest_group'
</if>
<if test="state != null and state != ''">
AND gp.STATE = #{state}
</if>
<if test="deptId != null and deptId != ''">
AND (gp.DEPT_ID = #{deptId}
OR find_in_set(#{deptId},gp.ALL_DEPT_IDS))
</if>
<if test="gridId != null and gridId != ''">
AND (gp.DEPT_ID = #{gridId}
OR find_in_set(#{gridId},gp.ALL_DEPT_IDS))
</if>
<if test="streetId != null and streetId != ''">
AND (find_in_set(#{streetId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{streetId},gp.ALL_DEPT_IDS))
</if>
<if test="communityId != null and communityId != ''">
AND (find_in_set(#{communityId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{communityId},gp.ALL_DEPT_IDS))
</if>
ORDER BY
gp.CATEGORY_CODE, gp.CREATED_TIME DESC
</select>
<select id="selectInterestGroupByDept" resultType="com.elink.esua.epdc.smile.dto.group.GroupManagementDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.CREATED_TIME,
gp.STATE
FROM
epdc_group gp
WHERE
gp.DEL_FLAG = '0'
AND gp.STATE IN ( 10, 15 )
AND gp.SECTION_CODE = 'interest_group'
<if test="categoryCode != null and categoryCode != ''">
AND gp.CATEGORY_CODE = #{categoryCode}
</if>
<if test="deptId != null and deptId != ''">
AND gp.DEPT_ID = #{deptId}
</if>
</select>
<select id="selectListOfRepeatGroupName" resultType="long">
SELECT COUNT(ID) amount FROM epdc_group WHERE DEL_FLAG = '0' AND DEPT_ID = #{gridId} AND GROUP_NAME = #{groupName}
</select>
<select id="selectOneOfGroupDetail" resultType="com.elink.esua.epdc.smile.dto.group.GroupDetailDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.GROUP_INTRODUCTION,
gp.CREATED_TIME,
ugp.NICKNAME
FROM
epdc_group gp
LEFT JOIN epdc_user_group ugp ON gp.ID = ugp.GROUP_ID
AND ugp.DEL_FLAG = '0'
AND ugp.LORD_FLAG = '1'
WHERE
gp.DEL_FLAG = '0'
AND gp.ID = #{id}
</select>
<select id="selectListGroupsOfMine" resultType="com.elink.esua.epdc.smile.dto.group.result.GroupsOfMineResultDTO">
SELECT
t.ID,
t.GROUP_NAME,
t.GROUP_AVATAR,
t.GROUP_CATEGORY,
t.STATE,
t.totalNum,
t.partyMemberNum,
COUNT( DISTINCT ugpr.ID ) AS unreadTopicNum,
MAX( tp.CREATED_TIME ) AS latestTopicTime,
CASE
WHEN t.STATE = 0 THEN
'网格长会尽快审核您创建的社群,请耐心等待'
WHEN t.STATE = 5 THEN
t.PROCESSING_OPINIONS
WHEN (
t.STATE = 10
AND t.totalNum <![CDATA[ <= ]]> 1
AND t.GROUP_CATEGORY = '1'
AND COUNT( DISTINCT tp.ID ) = 0
) THEN
'您的社群审核已通过,快加好友进来吧' ELSE ''
END AS description
FROM
(
SELECT
gp.ID,
gp.GROUP_NAME,
gp.GROUP_AVATAR,
gp.GROUP_CATEGORY,
gp.STATE,
gp.PROCESSING_OPINIONS,
SUM( ugp.STATE = 10 ) AS totalNum,
SUM( ugp.PARTY_MEMBER = '1' ) AS partyMemberNum
FROM
epdc_group gp
LEFT JOIN epdc_user_group ugp ON ugp.GROUP_ID = gp.ID
AND ugp.DEL_FLAG = '0'
AND ugp.STATE = 10
WHERE
gp.ID IN (
SELECT
gp.ID
FROM
epdc_group gp
RIGHT JOIN epdc_user_group ugp ON gp.ID = ugp.GROUP_ID
AND ugp.DEL_FLAG = '0'
AND ugp.STATE = 10
AND ugp.USER_ID = #{userId}
WHERE
gp.DEL_FLAG = '0'
AND gp.STATE <![CDATA[ AND gp.STATE <> ]]> 20
AND gp.DEPT_ID = #{gridId}
)
GROUP BY
gp.ID
) t
LEFT JOIN epdc_group_topic_user_read ugpr ON t.ID = ugpr.GROUP_ID
AND ugpr.DEL_FLAG = '0'
AND ugpr.USER_ID = #{userId}
AND ugpr.READ_FLAG = '0'
LEFT JOIN epdc_topic tp ON t.ID = tp.GROUP_ID
AND tp.DEL_FLAG = '0'
GROUP BY
t.ID
ORDER BY
latestTopicTime DESC
</select>
<select id="selectListGroupsOfRecommend"
resultType="com.elink.esua.epdc.smile.dto.group.result.GroupsOfRecommendResultDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.GROUP_AVATAR,
(SELECT COUNT(ugp1.ID) FROM epdc_user_group ugp1 WHERE gp.ID = ugp1.GROUP_ID AND ugp1.DEL_FLAG = '0' AND ugp1.STATE = 10) AS totalNum,
(SELECT COUNT(ugp2.ID) FROM epdc_user_group ugp2 WHERE gp.ID = ugp2.GROUP_ID AND ugp2.DEL_FLAG = '0' AND ugp2.STATE = 10 AND ugp2.PARTY_MEMBER = '1') AS partyMemberNum
FROM
epdc_group gp
LEFT JOIN epdc_topic tp ON gp.ID = tp.GROUP_ID
AND tp.DEL_FLAG = '0'
WHERE
gp.DEL_FLAG = '0'
AND gp.STATE IN ( 10, 15 )
AND gp.DEPT_ID = #{gridId}
AND gp.GROUP_CATEGORY = '1'
AND gp.ID NOT IN ( SELECT ugp.GROUP_ID FROM epdc_user_group ugp WHERE ugp.USER_ID = #{userId} AND ugp.DEL_FLAG = '0' AND ugp.STATE = 10 )
GROUP BY
gp.ID
ORDER BY
MAX( tp.CREATED_TIME ) DESC
</select>
<select id="selectOneOfGroupDetailForMobileEnd"
resultType="com.elink.esua.epdc.smile.dto.group.result.GroupDetailForMobileEndResultDTO">
SELECT
gp.ID,
gp.GROUP_NAME,
gp.GROUP_AVATAR,
gp.GROUP_CATEGORY,
gp.GROUP_INTRODUCTION,
COUNT( DISTINCT ugp.ID ) AS totalNum,
ugp1.NICKNAME,
ugp2.LORD_FLAG,
COUNT( DISTINCT tp.ID ) AS topicNum,
COUNT( DISTINCT tp1.ID ) AS changeToIssueNum
FROM
epdc_group gp
LEFT JOIN epdc_user_group ugp ON gp.ID = ugp.GROUP_ID
AND ugp.DEL_FLAG = '0'
AND ugp.STATE = 10
LEFT JOIN epdc_user_group ugp1 ON gp.ID = ugp1.GROUP_ID
AND ugp1.DEL_FLAG = '0'
AND ugp1.STATE = 10
AND ugp1.LORD_FLAG = '1'
LEFT JOIN epdc_user_group ugp2 ON gp.ID = ugp2.GROUP_ID
AND ugp2.DEL_FLAG = '0'
AND ugp2.STATE = 10
AND ugp2.USER_ID = #{userId}
LEFT JOIN epdc_topic tp ON gp.ID = tp.GROUP_ID
AND tp.DEL_FLAG = '0'
LEFT JOIN epdc_topic tp1 ON gp.ID = tp1.GROUP_ID
AND tp1.DEL_FLAG = '0'
AND (tp1.STATE = 10 OR tp1.STATE = 15)
WHERE
gp.DEL_FLAG = '0'
AND gp.ID = #{id}
</select>
<select id="selectListOfGroupByGridId" resultType="com.elink.esua.epdc.smile.dto.group.GroupListDTO">
SELECT
ID AS groupId,
GROUP_NAME AS groupName
FROM
epdc_group
WHERE
DEL_FLAG = '0'
AND SECTION_CODE = 'theme_group'
AND CATEGORY_CODE = 'police_group'
AND TYPE_KEY = 'community_party'
AND STATE IN ( 10, 15, 20 )
AND DEPT_ID = #{deptId}
</select>
<select id="selectListOfGroupByDeptId" resultType="com.elink.esua.epdc.dto.DeptLevelAndLeaderDTO">
SELECT
DEPT_ID AS deptId,
DEPT_NAME AS deptName
FROM
epdc_group
WHERE
DEL_FLAG = '0'
AND SECTION_CODE = 'theme_group'
AND CATEGORY_CODE = 'police_group'
AND TYPE_KEY = 'community_party'
AND STATE IN ( 10, 15 )
AND PARENT_DEPT_IDS LIKE CONCAT( '%', #{deptId} )
</select>
<select id="selectListOfGroupOrderByActivity" resultType="com.elink.esua.epdc.smile.dto.group.GroupActivityDTO">
SELECT
gp.GROUP_NAME,
gp.ALL_DEPT_NAMES
FROM
epdc_group gp
LEFT JOIN (
SELECT
tc.GROUP_ID,
( tc.COMMENT_NUM + tc.BROWSE_NUM + SUM( tcm.LIKE_COUNT ) + SUM( tcm.UN_LIKE_COUNT ) ) AS attitudeNum
FROM
epdc_topic tc
LEFT JOIN epdc_topic_comment tcm ON tc.ID = tcm.TOPIC_ID
AND tcm.DEL_FLAG = '0'
WHERE
tc.DEL_FLAG = '0'
group by
tc.ID
) tmp ON gp.ID = tmp.GROUP_ID
WHERE
gp.DEL_FLAG = '0'
AND gp.STATE IN ( 10, 15 )
<if test="gridId != null and gridId != ''">
AND (gp.DEPT_ID = #{gridId}
OR find_in_set(#{gridId},gp.ALL_DEPT_IDS))
</if>
<if test="streetId != null and streetId != ''">
AND (find_in_set(#{streetId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{streetId},gp.ALL_DEPT_IDS))
</if>
<if test="communityId != null and communityId != ''">
AND (find_in_set(#{communityId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{communityId},gp.ALL_DEPT_IDS))
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND DATE_FORMAT( gp.CREATED_TIME, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
</if>
GROUP BY
gp.ID
ORDER BY
SUM( tmp.attitudeNum ) DESC,
gp.CREATED_TIME DESC
</select>
<select id="selectListOfGroupOrderByMember" resultType="com.elink.esua.epdc.smile.dto.group.GroupMemberDTO">
SELECT
gp.GROUP_NAME,
CASE
WHEN COUNT( up.ID ) IS NULL THEN
0 ELSE COUNT( up.ID ) END AS memberNum,
gp.ALL_DEPT_NAMES
FROM
epdc_group gp
LEFT JOIN epdc_user_group up ON gp.ID = up.GROUP_ID
AND up.DEL_FLAG = '0'
AND up.STATE = 10
WHERE
gp.DEL_FLAG = '0'
AND gp.STATE IN ( 10, 15 )
<if test="gridId != null and gridId != ''">
AND (gp.DEPT_ID = #{gridId}
OR find_in_set(#{gridId},gp.ALL_DEPT_IDS))
</if>
<if test="streetId != null and streetId != ''">
AND (find_in_set(#{streetId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{streetId},gp.ALL_DEPT_IDS))
</if>
<if test="communityId != null and communityId != ''">
AND (find_in_set(#{communityId},gp.PARENT_DEPT_IDS)
OR find_in_set(#{communityId},gp.ALL_DEPT_IDS))
</if>
<if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
AND DATE_FORMAT( gp.CREATED_TIME, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
</if>
GROUP BY
gp.ID
ORDER BY
memberNum DESC,
gp.CREATED_TIME DESC
</select>
<select id="selectOnePartyGroupInfoByGridId" resultType="com.elink.esua.epdc.smile.dto.group.GroupDTO">
SELECT * FROM epdc_group WHERE DEL_FLAG = '0' AND GROUP_CATEGORY = '0' AND DEPT_ID = #{gridId}
</select>
<!-- 查询已经建立党员群的网格id -->
<select id="listPartyMemberGridId" resultType="java.lang.String">
select distinct eg.DEPT_ID
from epdc_group eg
where eg.DEL_FLAG='0'
and eg.GROUP_CATEGORY='0'
</select>
<!--根据社群id,查询群主手机号-->
<select id="queryGroupUserMOBILE" resultType="java.lang.String">
select MOBILE from
epdc_user_group
where GROUP_ID = #{groupId}
and LORD_FLAG = 1
and DEL_FLAG = 0
</select>
<select id="selectListOfOrganizationInfo" resultType="com.elink.esua.epdc.smile.dto.group.GroupDTO">
SELECT
ID,
PARENT_DEPT_IDS,
PARENT_DEPT_NAMES,
ALL_DEPT_IDS,
ALL_DEPT_NAMES
FROM
epdc_group
WHERE
FIND_IN_SET( #{deptId}, ALL_DEPT_IDS )
</select>
<update id="updateGridByDeptId">
UPDATE epdc_group SET DEPT_NAME = #{newDeptName}, UPDATED_TIME = NOW() WHERE DEPT_ID = #{deptId}
</update>
<select id="selectListOfPartyGroups" resultType="com.elink.esua.epdc.smile.dto.group.GroupDTO">
SELECT
ID,
ALL_DEPT_NAMES
FROM
epdc_group
WHERE
FIND_IN_SET( #{deptId}, ALL_DEPT_IDS )
AND GROUP_CATEGORY = '0'
</select>
<update id="deleteGroupByProjectIds">
UPDATE epdc_group SET DEL_FLAG = '1', UPDATED_TIME = NOW() WHERE
REFERENCE_BUSINESS_ID in
<foreach item="projectIds" collection="projectIds" open="(" separator="," close=")">
#{projectIds}
</foreach>
</update>
<select id="selectGroupByDeptId" resultType="com.elink.esua.epdc.modules.smile.group.entity.GroupEntity">
SELECT
gp.ID
FROM
epdc_group gp
WHERE
gp.DEL_FLAG = '0'
<if test="projectIds != null and projectIds != ''">
AND gp.REFERENCE_BUSINESS_ID = #{projectIds}
</if>
</select>
<select id="selectBySection" resultType="com.elink.esua.epdc.smile.dto.group.result.GroupBySectionResultDTO">
SELECT
gp.id,
gp.GROUP_NAME,
gp.GROUP_AVATAR,
gp.STATE AS GROUP_STATE
FROM
epdc_group gp
WHERE
gp.DEL_FLAG = '0'
AND gp.STATE IN ( 10, 15 )
<if test="sectionCode != null and sectionCode != ''">
AND gp.SECTION_CODE = #{sectionCode}
</if>
AND gp.DEPT_ID IN
<foreach item="dept" collection="deptList" open="(" separator="," close=")">
#{dept}
</foreach>
</select>
</mapper>