Browse Source

添加排序功能

dev
曲树通 6 years ago
parent
commit
a28facd7d6
  1. 390
      esua-epdc/epdc-module/epdc-analysis/epdc-analysis-server/src/main/resources/mapper/user/UserAnalysisDao.xml

390
esua-epdc/epdc-module/epdc-analysis/epdc-analysis-server/src/main/resources/mapper/user/UserAnalysisDao.xml

@ -5,80 +5,106 @@
<select id="selectListUserDataRank" resultType="com.elink.esua.epdc.dto.user.result.UserDataRankResultDTO">
SELECT
t1.*,
t1.userCount - t1.partyMemberCount AS residentCount,
t1.oldCount / t1.userCount oldPercent,
t1.youngCount / t1.userCount youngPercent
t1.*,
t1.userCount - t1.partyMemberCount AS residentCount,
t1.oldCount / t1.userCount oldPercent,
t1.youngCount / t1.userCount youngPercent
FROM
( SELECT
t.streetName, t.streetId,
COUNT( t.userId ) userCount,
count( t.SEX = '1' OR NULL ) maleCount,
count( t.SEX = '0' OR NULL ) femaleCount,
count( t.SEX = '2' OR NULL ) unknownSexCount,
COUNT( t.PARTY_FLAG = '1' OR NULL ) partyMemberCount,
COUNT( t.age > 50 OR NULL ) oldCount,
COUNT( ( t.age &lt;= 50 AND t.age > 0 ) OR NULL ) youngCount
FROM (
SELECT
uu.ID AS userId,
CASE WHEN uu.SEX != '0' AND uu.SEX != '1' THEN '2' ELSE uu.SEX END AS SEX,
uu.STATE, uu.PARTY_FLAG, uu.DEPT_ID,
IFNULL( TIMESTAMPDIFF( YEAR, uu.BIRTHDAY, CURDATE()), 0 ) age,
ad2.`name` streetName, ad2.id streetId
FROM
esua_epdc_user.epdc_user uu
LEFT JOIN esua_epdc_admin.sys_dept ad ON uu.DEPT_ID = ad.ID AND ad.type_key = 'grid_party'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
WHERE uu.DEL_FLAG = '0'
<if test='partyFlag != null and partyFlag = "1"'>AND uu.PARTY_FLAG = '1'</if>
<choose>
<when test="gridId != null and gridId != ''">AND ad2.ID = #{gridId}</when>
<otherwise>
<if test="deptIdList != null and deptIdList.size() > 0">
AND ad2.ID in <foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>
</if>
</otherwise>
</choose>
/*待补充按时间筛选*/
<if test="startTime != null and endTime != null and endTime != ''">
AND uu.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
AND ad.id IS NOT NULL
) t
GROUP BY t.streetId
) t1
/*待补充排序功能 order by t1.oldCount asc */
( SELECT
t.streetName, t.streetId,
COUNT( t.userId ) userCount,
count( t.SEX = '1' OR NULL ) maleCount,
count( t.SEX = '0' OR NULL ) femaleCount,
count( t.SEX = '2' OR NULL ) unknownSexCount,
COUNT( t.PARTY_FLAG = '1' OR NULL ) partyMemberCount,
COUNT( t.age > 50 OR NULL ) oldCount,
COUNT( ( t.age &lt;= 50 AND t.age > 0 ) OR NULL ) youngCount
FROM (
SELECT
uu.ID AS userId,
CASE WHEN uu.SEX != '0' AND uu.SEX != '1' THEN '2' ELSE uu.SEX END AS SEX,
uu.STATE, uu.PARTY_FLAG, uu.DEPT_ID,
IFNULL( TIMESTAMPDIFF( YEAR, uu.BIRTHDAY, CURDATE()), 0 ) age,
ad2.`name` streetName, ad2.id streetId
FROM
esua_epdc_user.epdc_user uu
LEFT JOIN esua_epdc_admin.sys_dept ad ON uu.DEPT_ID = ad.ID AND ad.type_key = 'grid_party'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
WHERE uu.DEL_FLAG = '0'
<if test='partyFlag != null and partyFlag = "1"'>AND uu.PARTY_FLAG = '1'</if>
<choose>
<when test="gridId != null and gridId != ''">AND ad2.ID = #{gridId}</when>
<otherwise>
<if test="deptIdList != null and deptIdList.size() > 0">
AND ad2.ID in
<foreach collection="deptIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>
</if>
</otherwise>
</choose>
/*待补充按时间筛选*/
<if test="startTime != null and endTime != null and endTime != ''">
AND uu.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
AND ad.id IS NOT NULL
) t
<choose>
<when test='category != null and category == "0"'>
where
t.age>=50
GROUP BY t.streetId
order by COUNT( t.age > 50 OR NULL ) desc
</when>
<when test='category != null and category == "1"'>
where
t.age &lt; 50
GROUP BY t.streetId
order by COUNT( ( t.age &lt;= 50 AND t.age > 0 ) OR NULL ) desc
</when>
<when test='category != null and category == "2"'>
where
t.age>=50
GROUP BY t.streetId
order by COUNT( t.age > 50 OR NULL ) asc
</when>
<when test='category != null and category == "3"'>
where
t.age &lt; 50
GROUP BY t.streetId
order by COUNT( t.age > 50 OR NULL ) asc
</when>
<otherwise>
GROUP BY t.streetId
</otherwise>
</choose>
) t1
/*待补充排序功能 order by t1.oldCount asc */
</select>
<select id="selectListPartyAuthFailureCountByStreetId"
resultType="com.elink.esua.epdc.dto.user.result.UserDataRankResultDTO">
SELECT
ad2.id AS streetId,
COUNT( DISTINCT uf.USER_ID ) partyAuthFailureCount
ad2.id AS streetId,
COUNT( DISTINCT uf.USER_ID ) partyAuthFailureCount
FROM
esua_epdc_user.epdc_user uu
LEFT JOIN esua_epdc_user.epdc_party_authentication_failed uf ON uu.id = uf.user_id
LEFT JOIN esua_epdc_admin.sys_dept ad ON uu.DEPT_ID = ad.ID
AND ad.type_key = 'grid_party'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
esua_epdc_user.epdc_user uu
LEFT JOIN esua_epdc_user.epdc_party_authentication_failed uf ON uu.id = uf.user_id
LEFT JOIN esua_epdc_admin.sys_dept ad ON uu.DEPT_ID = ad.ID
AND ad.type_key = 'grid_party'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
WHERE
uu.DEL_FLAG = '0'
AND uu.PARTY_FLAG = '0'
AND ad.id IS NOT NULL
<if test="streetIdList != null and streetIdList.size() > 0">
and ad2.ID in
<foreach collection="streetIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND uu.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
uu.DEL_FLAG = '0'
AND uu.PARTY_FLAG = '0'
AND ad.id IS NOT NULL
<if test="streetIdList != null and streetIdList.size() > 0">
and ad2.ID in
<foreach collection="streetIdList" item="deptId" open="(" separator="," close=")">#{deptId}</foreach>
</if>
GROUP BY
ad2.ID
ad2.ID
</select>
@ -112,18 +138,19 @@
<!--新闻数-->
<select id="selectListNewsCount" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
COUNT(nn.ID) newsCount,nn.DEPT_ID gridId
COUNT(nn.ID) newsCount,nn.DEPT_ID gridId
FROM
esua_epdc_news.epdc_news nn
esua_epdc_news.epdc_news nn
WHERE
nn.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND nn.DEPT_ID in <foreach item="item" collection="gridIdList" open="(" separator="," close=")"> #{item} </foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND nn.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
nn.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND nn.DEPT_ID in
<foreach item="item" collection="gridIdList" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND nn.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
GROUP BY nn.DEPT_ID
</select>
@ -131,18 +158,19 @@
<!--通知数-->
<select id="selectListNoticeCount" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
COUNT(nn.ID) newsCount,nn.DEPT_ID gridId
COUNT(nn.ID) newsCount,nn.DEPT_ID gridId
FROM
esua_epdc_news.epdc_notice nn
esua_epdc_news.epdc_notice nn
WHERE
nn.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND nn.DEPT_ID in <foreach item="item" collection="gridIdList" open="(" separator="," close=")"> #{item} </foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND nn.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
nn.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND nn.DEPT_ID in
<foreach item="item" collection="gridIdList" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND nn.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
GROUP BY nn.DEPT_ID
</select>
@ -150,18 +178,19 @@
<!--议题数-->
<select id="selectListEventCount" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
epen.GRID_ID gridId, COUNT( epen.ID ) eventCount
epen.GRID_ID gridId, COUNT( epen.ID ) eventCount
FROM
esua_epdc_events.epdc_events epen
esua_epdc_events.epdc_events epen
WHERE
epen.DEL_FLAG = '0' AND epen.EVENT_STATE = '4'
<if test="gridIdList != null and gridIdList.size() > 0">
AND epen.GRID_ID in <foreach item="item" collection="gridIdList" open="(" separator="," close=")"> #{item} </foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND epen.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
epen.DEL_FLAG = '0' AND epen.EVENT_STATE = '4'
<if test="gridIdList != null and gridIdList.size() > 0">
AND epen.GRID_ID in
<foreach item="item" collection="gridIdList" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND epen.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
GROUP BY epen.GRID_ID
</select>
@ -169,60 +198,63 @@
<!--项目数-->
<select id="selectListItemCount" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
epen.GRID_ID gridId,
COUNT( epen.ID ) itemCount,
count(epen.ITEM_STATE = '10' or null) itemCloseCount
epen.GRID_ID gridId,
COUNT( epen.ID ) itemCount,
count(epen.ITEM_STATE = '10' or null) itemCloseCount
FROM
esua_epdc_events.epdc_item epen
esua_epdc_events.epdc_item epen
WHERE
epen.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND epen.GRID_ID in <foreach item="item" collection="gridIdList" open="(" separator="," close=")"> #{item} </foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND epen.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
epen.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND epen.GRID_ID in
<foreach item="item" collection="gridIdList" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND epen.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
GROUP BY epen.GRID_ID
</select>
<!--社群数-->
<select id="selectListCommunityCount" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
epgr.GRID_ID gridId,
COUNT( DISTINCT epgr.ID ) communityCount,
COUNT( DISTINCT ug.user_id ) communityMemberCount,
COUNT( DISTINCT ut.ID ) communityTopicCount
epgr.GRID_ID gridId,
COUNT( DISTINCT epgr.ID ) communityCount,
COUNT( DISTINCT ug.user_id ) communityMemberCount,
COUNT( DISTINCT ut.ID ) communityTopicCount
FROM
esua_epdc_group.epdc_group epgr
LEFT JOIN esua_epdc_group.epdc_user_group ug ON epgr.id = ug.group_id AND ug.DEL_FLAG = '0'
LEFT JOIN esua_epdc_group.epdc_topic ut ON epgr.id = ut.group_id AND ut.DEL_FLAG = '0'
esua_epdc_group.epdc_group epgr
LEFT JOIN esua_epdc_group.epdc_user_group ug ON epgr.id = ug.group_id AND ug.DEL_FLAG = '0'
LEFT JOIN esua_epdc_group.epdc_topic ut ON epgr.id = ut.group_id AND ut.DEL_FLAG = '0'
WHERE
epgr.DEL_FLAG = '0' AND ( epgr.STATE = '10' OR epgr.STATE = '15' )
<if test="gridIdList != null and gridIdList.size() > 0">
AND epgr.GRID_ID in <foreach item="item" collection="gridIdList" open="(" separator="," close=")"> #{item} </foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND epgr.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
epgr.DEL_FLAG = '0' AND ( epgr.STATE = '10' OR epgr.STATE = '15' )
<if test="gridIdList != null and gridIdList.size() > 0">
AND epgr.GRID_ID in
<foreach item="item" collection="gridIdList" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND epgr.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
GROUP BY epgr.GRID_ID
</select>
<select id="getUserStatistics" resultType="com.elink.esua.epdc.dto.user.result.UserAnalysisCountDTO" parameterType="com.elink.esua.epdc.dto.user.form.UserCountDTO">
<select id="getUserStatistics" resultType="com.elink.esua.epdc.dto.user.result.UserAnalysisCountDTO"
parameterType="com.elink.esua.epdc.dto.user.form.UserCountDTO">
SELECT
t.userCount,
t.partyMemberCount,
t.residentCount - t.partyMemberCount residentCount
FROM
FROM
(
SELECT
COUNT( u.ID ) userCount,
COUNT( u.STATE != '0' OR NULL ) residentCount,
COUNT( u.party_flag = '1' OR NULL ) partyMemberCount
COUNT( u.ID ) userCount,
COUNT( u.STATE != '0' OR NULL ) residentCount,
COUNT( u.party_flag = '1' OR NULL ) partyMemberCount
FROM
esua_epdc_user.epdc_user u
esua_epdc_user.epdc_user u
LEFT JOIN esua_epdc_admin.sys_dept ad ON u.DEPT_ID = ad.ID
AND ad.type_key = 'grid_party'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
@ -231,7 +263,7 @@
u.DEL_FLAG = '0'
AND ad.id IS NOT NULL
<if test="deptIdList != null and deptIdList.size() > 0">
and ad2.ID in
and ad2.ID in
<foreach item="deptIdItem" collection="deptIdList" open="(" separator="," close=")">
#{deptIdItem}
</foreach>
@ -242,20 +274,21 @@
)t
</select>
<select id="getGridStatistics" resultType="com.elink.esua.epdc.dto.user.result.GriddingCountDTO" parameterType="com.elink.esua.epdc.dto.user.form.UserCountDTO">
<select id="getGridStatistics" resultType="com.elink.esua.epdc.dto.user.result.GriddingCountDTO"
parameterType="com.elink.esua.epdc.dto.user.form.UserCountDTO">
SELECT
COUNT( ad.id) gridTotle,
COUNT( ac.ID) gridCount
COUNT( ad.id) gridTotle,
COUNT( ac.ID) gridCount
FROM
esua_epdc_admin.sys_dept ad
LEFT JOIN esua_epdc_admin.epdc_dept_ma_code ac ON ad.id = ac.GRID_ID
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
esua_epdc_admin.sys_dept ad
LEFT JOIN esua_epdc_admin.epdc_dept_ma_code ac ON ad.id = ac.GRID_ID
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad.pid = ad1.id
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad1.pid = ad2.id
WHERE
ad.type_key = 'grid_party'
ad.type_key = 'grid_party'
<if test="deptIdList != null and deptIdList.size() > 0">
and ad2.ID in
and ad2.ID in
<foreach item="deptIdItem" collection="deptIdList" open="(" separator="," close=")">
#{deptIdItem}
</foreach>
@ -265,7 +298,7 @@
AND ad2.id = #{formDto.deptId}
</if>
ORDER BY
ad.create_date ASC
ad.create_date ASC
</select>
<select id="userRegisterSort"
resultType="com.elink.esua.epdc.dto.user.result.UserSortRankResultDTO">
@ -292,7 +325,7 @@
uu.DEL_FLAG = '0'
AND ad.id IS NOT NULL
<if test="deptIdList != null and deptIdList.size() > 0">
and ad2.ID in
and ad2.ID in
<foreach item="deptIdItem" collection="deptIdList" open="(" separator="," close=")">
#{deptIdItem}
</foreach>
@ -322,50 +355,53 @@
<select id="selectListGridHasMaCode" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
ad.id gridId,
CONCAT( ad2.`name`, '-', ad1.`name`, '-', ad.`name` ) AS allDeptName,
GROUP_CONCAT( DISTINCT u.real_name ) gridLeader
ad.id gridId,
CONCAT( ad2.`name`, '-', ad1.`name`, '-', ad.`name` ) AS allDeptName,
GROUP_CONCAT( DISTINCT u.real_name ) gridLeader
FROM
esua_epdc_admin.sys_dept ad
LEFT JOIN esua_epdc_admin.epdc_dept_ma_code ama ON ad.id = ama.GRID_ID AND ama.DEL_FLAG = '0'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad1.id = ad.pid
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad2.id = ad1.pid
LEFT JOIN esua_epdc_admin.sys_role_data_scope ards ON ards.dept_id = ad.id
LEFT JOIN esua_epdc_admin.sys_role r ON ards.role_id = r.id AND r.DEL_FLAG = 0 and r.type_key = 'gridLeader'
LEFT JOIN esua_epdc_admin.sys_role_user ru ON r.id = ru.role_id
LEFT JOIN esua_epdc_admin.sys_user u ON ru.user_id = u.id AND u.del_flag = 0
esua_epdc_admin.sys_dept ad
LEFT JOIN esua_epdc_admin.epdc_dept_ma_code ama ON ad.id = ama.GRID_ID AND ama.DEL_FLAG = '0'
LEFT JOIN esua_epdc_admin.sys_dept ad1 ON ad1.id = ad.pid
LEFT JOIN esua_epdc_admin.sys_dept ad2 ON ad2.id = ad1.pid
LEFT JOIN esua_epdc_admin.sys_role_data_scope ards ON ards.dept_id = ad.id
LEFT JOIN esua_epdc_admin.sys_role r ON ards.role_id = r.id AND r.DEL_FLAG = 0 and r.type_key = 'gridLeader'
LEFT JOIN esua_epdc_admin.sys_role_user ru ON r.id = ru.role_id
LEFT JOIN esua_epdc_admin.sys_user u ON ru.user_id = u.id AND u.del_flag = 0
WHERE
ad.type_key = 'grid_party'
AND ad.del_flag = 0
AND ama.ID IS NOT NULL
<if test="gridId != null and grid != ''">and (ad1.id = #{gridId} or ad2.id = #{gridId})</if>
ad.type_key = 'grid_party'
AND ad.del_flag = 0
AND ama.ID IS
<if test='category != null and category == "0"'>NOT</if>
NULL
<if test="gridId != null and grid != ''">and (ad1.id = #{gridId} or ad2.id = #{gridId})</if>
GROUP BY
ad.id
ad.id
ORDER BY
ama.CREATED_TIME DESC,
ad.create_date DESC
ama.CREATED_TIME DESC,
ad.create_date DESC
</select>
<select id="selectListReigistData" resultType="com.elink.esua.epdc.dto.user.result.GridOpeningResultDTO">
SELECT
t.DEPT_ID, COUNT( t.ID ) registerCount,
COUNT(t.PARTY_FLAG = '0' OR NULL) residentCount,
COUNT(t.PARTY_FLAG = '1' OR NULL) partyCount
t.DEPT_ID, COUNT( t.ID ) registerCount,
COUNT(t.PARTY_FLAG = '0' OR NULL) residentCount,
COUNT(t.PARTY_FLAG = '1' OR NULL) partyCount
FROM (
SELECT
uu.ID, uu.DEPT_ID, uu.STATE, uu.PARTY_FLAG
FROM
esua_epdc_user.epdc_user uu
WHERE
uu.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND uu.DEPT_ID in <foreach item="item" collection="gridIdList" open="(" separator="," close=")"> #{item} </foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND uu.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
AND uu.DEPT_ID IS NOT NULL
) t
SELECT
uu.ID, uu.DEPT_ID, uu.STATE, uu.PARTY_FLAG
FROM
esua_epdc_user.epdc_user uu
WHERE
uu.DEL_FLAG = '0'
<if test="gridIdList != null and gridIdList.size() > 0">
AND uu.DEPT_ID in
<foreach item="item" collection="gridIdList" open="(" separator="," close=")">#{item}</foreach>
</if>
<if test="startTime != null and endTime != null and endTime != ''">
AND uu.CREATED_TIME BETWEEN #{startTime}
AND #{endTime}
</if>
AND uu.DEPT_ID IS NOT NULL
) t
GROUP BY t.DEPT_ID
</select>
</mapper>

Loading…
Cancel
Save