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.
 
 
 
 
 

642 lines
22 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.dao.IssueDao">
<resultMap type="com.epmet.entity.IssueEntity" id="issueMap">
<result property="id" column="ID"/>
<result property="issueStatus" column="ISSUE_STATUS"/>
<result property="sourceType" column="SOURCE_TYPE"/>
<result property="sourceId" column="SOURCE_ID"/>
<result property="closeReason" column="CLOSE_REASON"/>
<result property="resolveType" column="RESOLVE_TYPE"/>
<result property="issueTitle" column="ISSUE_TITLE"/>
<result property="suggestion" column="SUGGESTION"/>
<result property="customerId" column="CUSTOMER_ID"/>
<result property="gridId" column="GRID_ID"/>
<result property="orgIdPath" column="ORG_ID_PATH"/>
<result property="orgId" column="ORG_ID"/>
<result property="votingDeadline" column="VOTING_DEADLINE"/>
<result property="decidedTime" column="DECIDED_TIME"/>
<result property="shiftedTime" column="SHIFTED_TIME"/>
<result property="closedTime" column="CLOSED_TIME"/>
<result property="delFlag" column="DEL_FLAG"/>
<result property="revision" column="REVISION"/>
<result property="createdBy" column="CREATED_BY"/>
<result property="createdTime" column="CREATED_TIME"/>
<result property="updatedBy" column="UPDATED_BY"/>
<result property="updatedTime" column="UPDATED_TIME"/>
</resultMap>
<!-- 议题详情 -->
<select id="issueDetail" parameterType="com.epmet.dto.form.IssueDetailFormDTO" resultType="com.epmet.dto.result.IssueResultDTO">
SELECT
source_id AS topicId,
issue_title AS issueTitle,
issue_status AS issueStatus,
suggestion AS issueSuggestion,
grid_id AS gridId,
created_by AS userId
FROM
issue
WHERE
id = #{issueId}
AND del_flag = 0
</select>
<select id="selectIssueListByGridId" parameterType="com.epmet.dto.form.ShiftProjectListFromDTO" resultType="com.epmet.entity.IssueEntity">
SELECT
*
FROM
issue
WHERE
DEL_FLAG = '0'
AND GRID_ID = #{gridId}
AND ISSUE_STATUS = 'shift_project'
ORDER BY UPDATED_TIME DESC
LIMIT #{pageNo},
#{pageSize}
</select>
<!-- 新增议题 -->
<insert id="insertOne" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.epmet.dto.IssueDTO">
<selectKey keyProperty="id" resultType="java.lang.String" order="BEFORE">
SELECT replace(uuid(),'-','') AS ID
</selectKey>
INSERT INTO issue
<trim prefix="(" suffix=")" suffixOverrides=",">
id,
<if test ='null != issueStatus'>
issue_status,
</if>
<if test ='null != sourceType'>
source_type,
</if>
<if test ='null != sourceId'>
source_id,
</if>
<if test ='null != closeReason'>
close_reason,
</if>
<if test ='null != resolveType'>
resolve_type,
</if>
<if test ='null != issueTitle'>
issue_title,
</if>
<if test ='null != suggestion'>
suggestion,
</if>
<if test ='null != customerId'>
customer_id,
</if>
<if test ='null != gridId'>
grid_id,
</if>
<if test ='null != orgIdPath'>
org_id_path,
</if>
<if test ='null != orgId'>
org_id,
</if>
<if test ='null != votingDeadline'>
voting_deadline,
</if>
<if test ='null != decidedTime'>
decided_time,
</if>
<if test ='null != shiftedTime'>
shifted_time,
</if>
<if test ='null != closedTime'>
closed_time,
</if>
<if test ='null != createdBy'>
created_by,
</if>
<if test ='null != createdTime'>
created_time,
</if>
<if test ='null != createdBy'>
updated_by,
</if>
<if test ='null != createdTime'>
updated_time,
</if>
del_flag,
revision
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<choose>
<when test='null != issueId and "" != issueId'>
#{issueId},
</when>
<otherwise>
#{id},
</otherwise>
</choose>
<if test ='null != issueStatus'>
#{issueStatus},
</if>
<if test ='null != sourceType'>
#{sourceType},
</if>
<if test ='null != sourceId'>
#{sourceId},
</if>
<if test ='null != closeReason'>
#{closeReason},
</if>
<if test ='null != resolveType'>
#{resolveType},
</if>
<if test ='null != issueTitle'>
#{issueTitle},
</if>
<if test ='null != suggestion'>
#{suggestion},
</if>
<if test ='null != customerId'>
#{customerId},
</if>
<if test ='null != gridId'>
#{gridId},
</if>
<if test ='null != orgIdPath'>
#{orgIdPath},
</if>
<if test ='null != orgId'>
#{orgId},
</if>
<if test ='null != votingDeadline'>
#{votingDeadline},
</if>
<if test ='null != decidedTime'>
#{decidedTime},
</if>
<if test ='null != shiftedTime'>
#{shiftedTime},
</if>
<if test ='null != closedTime'>
#{closedTime},
</if>
<if test ='null != createdBy'>
#{createdBy},
</if>
<if test ='null != createdTime'>
#{createdTime},
</if>
<if test ='null != createdBy'>
#{createdBy},
</if>
<if test ='null != createdTime'>
#{createdTime},
</if>
'0',
0
</trim>
</insert>
<!-- 查询表决中议题列表 -->
<select id="selectVotingList" parameterType="com.epmet.dto.form.CommonIssueListFormDTO" resultType="com.epmet.dto.result.VotingIssueListResultDTO">
SELECT
ID AS issueId,
IFNULL(ISSUE_TITLE,'') AS issueTitle,
IFNULL(SUGGESTION,'')AS suggestion,
UNIX_TIMESTAMP( created_time ) AS issuePublishTime,
SOURCE_ID AS sourceId
FROM
issue
WHERE
DEL_FLAG = '0'
AND GRID_ID = #{gridId}
AND ISSUE_STATUS = 'voting'
ORDER BY
created_time DESC
LIMIT #{pageNo},
#{pageSize}
</select>
<!-- 查询已关闭议题列表 -->
<select id="selectClosedList" parameterType="com.epmet.dto.form.CommonIssueListFormDTO" resultType="com.epmet.dto.result.ClosedIssueListResultDTO">
SELECT
ID AS issueId,
IFNULL(ISSUE_TITLE,'') AS issueTitle,
IFNULL(CLOSE_REASON,'') AS solution,
UNIX_TIMESTAMP( created_time ) AS issueClosedTime,
SOURCE_ID AS sourceId
FROM
issue
WHERE
DEL_FLAG = '0'
AND GRID_ID = #{gridId}
AND ISSUE_STATUS = 'closed'
AND RESOLVE_TYPE = 'resolved'
ORDER BY
created_time DESC
LIMIT #{pageNo},
#{pageSize}
</select>
<!-- 查询已关闭议题列表 政府端 -->
<select id="selectClosedListGov" parameterType="com.epmet.dto.form.CommonIssueListFormDTO" resultType="com.epmet.dto.result.ClosedIssueListGovResultDTO">
SELECT
ID AS issueId,
IFNULL(ISSUE_TITLE,'') AS issueTitle,
IFNULL(CLOSE_REASON,'') AS closeReason,
UNIX_TIMESTAMP( closed_time ) AS closedTime
FROM
issue
WHERE
DEL_FLAG = '0'
AND GRID_ID = #{gridId}
AND ISSUE_STATUS = 'closed'
ORDER BY
created_time DESC
LIMIT #{pageNo},
#{pageSize}
</select>
<!-- 判断某人是不是议题发起人 -->
<select id="checkIssuePublisher" resultType="integer" parameterType="com.epmet.dto.form.VoteFormDTO">
SELECT
COUNT(*) AS publisher
FROM
issue
WHERE
del_flag = 0
AND created_by = #{createdBy}
AND id = #{issueId}
</select>
<!-- 获取转项目或者议题关闭时间 -->
<select id="operateTime" resultType="java.lang.String">
SELECT
DATE_FORMAT(updated_time,'%Y-%m-%d') AS updateTime
FROM
issue
WHERE
del_flag = 0
AND id = #{issueId}
</select>
<!-- 生成昨日的话题统计信息 -->
<select id="getIssueVotingStatistical" resultType="com.epmet.dto.result.IssuesToBeCountedResultDTO">
SELECT
issue.ID,
issue.ISSUE_STATUS,
vote.ATTITUDE,
vote.VOTE_COUNT,
totalvote.ATTITUDE AS ATTITUDE_UP_TO_YESTERDAY,
totalvote.VOTE_COUNT AS VOTE_COUNT_UP_TO_YESTERDAY
FROM
ISSUE issue
LEFT JOIN (
SELECT ISSUE_ID ,
ATTITUDE,
count(ATTITUDE) AS VOTE_COUNT
FROM issue_vote_detail
WHERE DEL_FLAG = '0'
AND TO_DAYS( NOW( ) ) - TO_DAYS( CREATED_TIME ) <![CDATA[>]]> 0
GROUP BY ISSUE_ID , ATTITUDE
) totalvote ON issue.ID = totalvote.ISSUE_ID
LEFT JOIN (
SELECT ISSUE_ID ,
ATTITUDE,
count(ATTITUDE) AS VOTE_COUNT
FROM issue_vote_detail
WHERE DEL_FLAG = '0'
AND TO_DAYS( NOW( ) ) - TO_DAYS( CREATED_TIME ) <![CDATA[<=]]> 1
AND TO_DAYS( NOW( ) ) - TO_DAYS( CREATED_TIME ) <![CDATA[>]]> 0
GROUP BY ISSUE_ID , ATTITUDE
) vote ON issue.ID = vote.ISSUE_ID AND totalvote.ATTITUDE = vote.ATTITUDE
WHERE
issue.DEL_FLAG = '0'
AND (
issue.ISSUE_STATUS = 'voting'
OR (
TO_DAYS( NOW( ) ) - TO_DAYS( issue.CLOSED_TIME ) <![CDATA[<=]]> 1
AND
TO_DAYS( NOW( ) ) - TO_DAYS( issue.CLOSED_TIME ) <![CDATA[>]]> 0
)
OR (
TO_DAYS( NOW( ) ) - TO_DAYS( issue.SHIFTED_TIME ) <![CDATA[<=]]> 1
AND
TO_DAYS( NOW( ) ) - TO_DAYS( issue.SHIFTED_TIME ) > 0
)
)
ORDER BY
issue.ID
</select>
<select id="selectIssueList" resultType="com.epmet.entity.IssueEntity">
SELECT
*
FROM issue
WHERE del_flag = '0'
AND customer_id = #{latestListForm.customerId}
AND grid_id = #{latestListForm.gridId}
<foreach item="issueId" collection="issueIdList" separator="OR" open="AND (" close=")" index="">
id = #{issueId}
</foreach>
ORDER BY field(
id,
<foreach item="issueId" collection="issueIdList" separator=",">
#{issueId}
</foreach>
)
LIMIT #{latestListForm.pageNo}, #{latestListForm.pageSize}
</select>
<select id="selectNewestIssueList" resultType="com.epmet.entity.IssueEntity">
SELECT
*
FROM issue
WHERE del_flag = '0'
AND customer_id = #{customerId}
AND grid_id = #{gridId}
AND issue_status = 'voting'
ORDER BY created_time DESC
LIMIT #{pageSize}
</select>
<!-- 条件查询出符合指定条件的议题ID集合 以及从昨天到现在被关闭或者转项目的议题 -->
<select id="selectIssueIdsByCondition" parameterType="com.epmet.dto.IssueDTO" resultType="com.epmet.dto.IssueDTO">
SELECT
ID,
GRID_ID
FROM
ISSUE
WHERE
DEL_FLAG = '0'
AND
ISSUE_STATUS = #{issueStatus}
</select>
<!-- 校验话题是否已转议题 -->
<select id="checkTopicShiftIssue" resultType="integer" parameterType="com.epmet.resi.group.dto.topic.form.TopicInfoFormDTO">
SELECT
COUNT(*) AS issueCount
FROM
issue
WHERE
del_flag = 0
AND source_id = #{topicId}
</select>
<select id="selectIssueListByTopic" resultType="com.epmet.entity.IssueEntity">
SELECT
*
FROM
issue
WHERE
DEL_FLAG = '0'
AND GRID_ID = #{gridId}
AND ISSUE_STATUS = 'shift_project'
ORDER BY UPDATED_TIME DESC
</select>
<select id="selectShiftIssueByTopic" resultType="com.epmet.entity.IssueEntity">
SELECT
ID,
IFNULL(ISSUE_TITLE, '') AS issueTitle
FROM
issue
WHERE
DEL_FLAG = '0'
AND SOURCE_TYPE = 'resi_topic'
<foreach item="topic" collection="topicIds" separator="OR" open="AND (" close=")" index="">
SOURCE_ID = #{topic}
</foreach>
AND ISSUE_STATUS = 'shift_project'
ORDER BY UPDATED_TIME DESC
LIMIT #{pageNo}, #{pageSize}
</select>
<select id="selectVotingListByTopic" resultType="com.epmet.resi.group.dto.group.result.GroupVotingListResultDTO">
SELECT
ID AS "issueId",
IFNULL(ISSUE_TITLE, '') AS "issueTitle",
UNIX_TIMESTAMP( CREATED_TIME ) AS "issuePublishTime",
IFNULL(SUGGESTION, '') AS "suggestion"
FROM
issue
WHERE
DEL_FLAG = '0'
AND SOURCE_TYPE = 'resi_topic'
<foreach item="topic" collection="topicIds" separator="OR" open="AND (" close=")" index="">
SOURCE_ID = #{topic}
</foreach>
AND ISSUE_STATUS = 'voting'
ORDER BY CREATED_TIME DESC
LIMIT #{pageNo}, #{pageSize}
</select>
<select id="selectClosedListByTopic" resultType="com.epmet.resi.group.dto.group.result.GroupClosedListResultDTO">
SELECT
ID AS "issueId",
IFNULL(ISSUE_TITLE, '') AS "issueTitle",
IFNULL(CLOSE_REASON, '') AS "solution",
UNIX_TIMESTAMP( UPDATED_TIME ) AS "issueClosedTime"
FROM
issue
WHERE
DEL_FLAG = '0'
AND SOURCE_TYPE = 'resi_topic'
<foreach item="topic" collection="topicIds" separator="OR" open="AND (" close=")" index="">
SOURCE_ID = #{topic}
</foreach>
AND ISSUE_STATUS = 'closed'
ORDER BY UPDATED_TIME DESC
LIMIT #{pageNo}, #{pageSize}
</select>
<!-- 个人中心-我发起的议题列表-表决中 -->
<select id="myPubIssuesAuditing" resultType="com.epmet.dto.result.MyPubIssuesAuditingResultDTO">
SELECT
i.ID AS issueId,
i.SUGGESTION,
i.ISSUE_TITLE,
i.SOURCE_ID AS topicId,
i.GRID_ID AS gridId,
UNIX_TIMESTAMP(i.CREATED_TIME) AS shiftIssueTime
FROM issue i
WHERE i.DEL_FLAG = '0'
AND i.ISSUE_STATUS = 'voting'
AND i.CREATED_BY = #{userId}
ORDER BY i.CREATED_TIME DESC
</select>
<!-- 查询我发起的议题(可根据状态查询)-->
<select id="selectMyPubIssues" parameterType="map" resultType="com.epmet.dto.IssueDTO">
SELECT
i.*,
UNIX_TIMESTAMP(i.CLOSED_TIME) AS closedTimeStamp,
UNIX_TIMESTAMP(i.SHIFTED_TIME) AS shiftedTimeStamp,
m.PROJECT_ID
FROM
issue i
left join issue_project_relation m
on(i.id=m.ISSUE_ID and m.del_flag='0')
WHERE
i.DEL_FLAG = '0'
AND i.CREATED_BY = #{userId}
<if test ='null != issueStatus and "" != issueStatus'>
and i.ISSUE_STATUS=#{issueStatus}
</if>
<if test="issueStatus == 'shift_project'">
ORDER BY
m.CREATED_TIME DESC
</if>
<if test="issueStatus == 'closed'">
ORDER BY
i.CLOSED_TIME DESC
</if>
LIMIT #{pageNo}, #{pageSize}
</select>
<!-- 个人中心-我发表的话题列表-已转议题列表 -->
<select id="myShiftIssueTopics" resultType="com.epmet.dto.result.MyShiftIssueTopicsResultDTO">
SELECT
ID AS issueId,
SOURCE_ID AS topicId,
UNIX_TIMESTAMP(CREATED_TIME) AS shiftIssueTime,
SUGGESTION,
ISSUE_TITLE,
GRID_ID
FROM issue
WHERE DEL_FLAG = '0'
AND ISSUE_STATUS != 'shift_project'
AND CUSTOMER_ID = #{customerId}
AND
<foreach collection="topicIds" item="topicId" separator=" OR ">
SOURCE_ID = #{topicId}
</foreach>
ORDER BY CREATED_TIME DESC
</select>
<select id="selectIssueRedDot" parameterType="map" resultType="com.epmet.dto.result.GridVotingIssueCountResultDTO">
SELECT
temp.gridId,
sum( total ) AS count
FROM
(
SELECT
i.GRID_ID AS gridId,
count(*) AS total
FROM
issue i
WHERE
i.DEL_FLAG = '0'
AND i.ISSUE_STATUS = 'voting'
<if test="gridIdList!=null and gridIdList.size()!=0">
AND i.GRID_ID in
<foreach collection="gridIdList" item="gridId" open="(" close=")" separator=",">
#{gridId}
</foreach>
</if>
GROUP BY
i.GRID_ID
UNION ALL
SELECT
ia.GRID_ID AS gridId,
count(*) AS total
FROM
issue_application ia
WHERE
ia.DEL_FLAG = '0'
AND ia.APPLY_STATUS = 'under_auditing'
<if test="gridIdList!=null and gridIdList.size()!=0">
AND ia.GRID_ID in
<foreach collection="gridIdList" item="gridId" open="(" close=")" separator=",">
#{gridId}
</foreach>
</if>
GROUP BY
ia.GRID_ID
) temp
GROUP BY
temp.gridId
</select>
<select id="selectUnResolvedList" resultType="com.epmet.dto.result.UnResolvedResultDTO">
SELECT
ID AS issueId,
IFNULL(ISSUE_TITLE,'') AS issueTitle,
IFNULL(CLOSE_REASON,'') AS solution,
UNIX_TIMESTAMP( CLOSED_TIME ) AS closedTime,
SOURCE_ID AS sourceId
FROM
issue
WHERE
DEL_FLAG = '0'
AND GRID_ID = #{gridId}
AND ISSUE_STATUS = 'closed'
AND RESOLVE_TYPE = 'unresolved'
</select>
<!-- 查询表决前50名 -->
<select id="selectIssueLimit50" resultType="com.epmet.dto.result.ResiBuzzDTO">
SELECT
i.ID AS issueId,
i.ISSUE_TITLE,
i.SUGGESTION,
i.CREATED_BY,
(CASE WHEN i.ISSUE_STATUS = 'shift_project' THEN '已转项目'
WHEN i.ISSUE_STATUS = 'voting' THEN '表决中'
WHEN i.ISSUE_STATUS = 'closed' THEN '已关闭'
ELSE '表决中' END ) AS `status`,
i.CREATED_TIME,
s.SUPPORT_COUNT,
s.OPPOSITION_COUNT,
CONCAT(s.SUPPORT_COUNT + s.OPPOSITION_COUNT,'/',s.VOTABLE_COUNT) AS voteAccount
FROM issue i
LEFT JOIN issue_vote_statistical s ON (s.ISSUE_ID = i.ID AND s.DEL_FLAG = '0')
WHERE i.DEL_FLAG = '0'
<if test='status != "all" '>
AND i.ISSUE_STATUS = #{status}
</if>
<if test='orgType == "grid" '>
AND i.GRID_ID = #{orgId}
</if>
<if test='orgType == "agency" '>
AND i.ORG_ID_PATH LIKE CONCAT('%',#{orgId})
</if>
ORDER BY (s.SUPPORT_COUNT + s.OPPOSITION_COUNT) DESC,i.created_time DESC
</select>
<!-- 查询客户下1级分类的长度 -->
<select id="selectOneLevelCategoryLength" resultType="java.lang.Integer">
SELECT LENGTH(CATEGORY_CODE) FROM issue_project_category_dict
WHERE DEL_FLAG = '0'
AND CUSTOMER_ID = #{customerId}
AND IS_DISABLE = 'enable'
AND CATEGORY_TYPE = '1'
LIMIT 1
</select>
<!-- 查询居民热议左侧饼图 -->
<select id="resiBuzzLeftPieChart" resultType="com.epmet.dto.result.ResiBuzzLeftPieChartResultDTO">
SELECT COUNT(issueId) AS count,categoryCode,categoryName FROM
(SELECT
i.ID AS issueId,
IFNULL(LEFT(ic.CATEGORY_CODE,#{length}),'') AS categoryCode,
IFNULL(cd.CATEGORY_NAME,'其他') AS categoryName
FROM issue i
LEFT JOIN issue_vote_statistical s ON (s.ISSUE_ID = i.ID AND s.DEL_FLAG = '0')
LEFT JOIN issue_category ic ON (ic.ISSUE_ID = i.ID AND ic.DEL_FLAG = '0' AND ic.CUSTOMER_ID = i.CUSTOMER_ID)
LEFT JOIN issue_project_category_dict cd ON (cd.CATEGORY_CODE = ic.CATEGORY_CODE AND cd.DEL_FLAG = '0' AND cd.CUSTOMER_ID = ic.CUSTOMER_ID)
WHERE i.DEL_FLAG = '0'
<if test='orgType == "grid" '>
AND i.GRID_ID = #{orgId}
</if>
<if test='orgType == "agency" '>
AND i.ORG_ID_PATH LIKE CONCAT('%',#{orgId})
</if>
ORDER BY (s.SUPPORT_COUNT + s.OPPOSITION_COUNT) DESC,i.created_time DESC LIMIT 50)temp
GROUP BY categoryCode
</select>
</mapper>