<?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.ResiEventDao" >
<!-- 查询报事列表 -->
<resultMap id= "eventUnDisposedListMap" type= "com.epmet.dto.result.EventListResultDTO" >
<result property= "eventContent" column= "eventContent" />
<result property= "eventId" column= "eventId" />
<result property= "eventTime" column= "eventTime" />
<result property= "isProject" column= "isProject" />
<result property= "redDot" column= "redDot" />
<collection property= "eventImgs" ofType= "java.lang.String" >
<result column= "img" />
</collection>
</resultMap>
<select id= "eventUnDisposedList" resultMap= "eventUnDisposedListMap" >
SELECT IFNULL(rea.ATTACHMENT_URL,'') AS img,t.* FROM
(SELECT
re.EVENT_CONTENT AS eventContent,
IFNULL(DATE_FORMAT(re.CREATED_TIME,'%Y-%m-%d %H:%i'),'') AS eventTime,
re.ID AS eventId,
(CASE WHEN re.SHIFT_PROJECT = 1 THEN TRUE ELSE FALSE END) AS isProject,
(CASE WHEN ro.RED_DOT = 1 THEN TRUE ELSE FALSE END) AS redDot
FROM resi_event_report_org ro
INNER JOIN resi_event re ON (ro.RESI_EVENT_ID = re.ID AND re.DEL_FLAG = '0')
AND ro.DEL_FLAG = '0'
and ro.ORG_ID = #{orgId}
<if test= 'eventType == "undisposed" ' >
AND ro.ORG_READ = 'un_read'
ORDER BY re.CREATED_TIME
</if>
<if test= 'eventType == "processed" ' >
AND ro.ORG_READ = 'read'
AND re.`STATUS` = 'processing'
ORDER BY re.LATEST_OPERATED_TIME
</if>
<if test= 'eventType == "transferred" ' >
AND ro.ORG_READ = 'read'
AND re.`STATUS` = 'closed_case'
ORDER BY re.CLOSE_CASE_TIME
</if>
)t
LEFT JOIN resi_event_attachment rea ON (rea.RESI_EVENT_ID = t.eventId AND rea.DEL_FLAG = '0' AND rea.ATTACHMENT_TYPE = 'image' AND (rea.SORT = 0 OR rea.SORT = 1 OR rea.SORT = 2))
</select>
<resultMap id= "MyReportedResultDTOMap" type= "com.epmet.dto.result.MyReportedResultDTO" >
<id property= "resiEventId" column= "id" />
<result property= "eventContent" column= "EVENT_CONTENT" />
<result property= "redDot" column= "RED_DOT" />
<result property= "status" column= "STATUS" />
<result property= "shiftProject" column= "SHIFT_PROJECT" />
<result property= "showTime" column= "LATEST_OPERATED_TIME" />
<result property= "readFlag" column= "READ_FLAG" />
<collection property= "imgList" ofType= "java.lang.String" >
<constructor >
<arg column= "img_url" />
</constructor>
</collection>
</resultMap>
<select id= "queryMyReported" parameterType= "map" resultMap= "MyReportedResultDTOMap" >
select
re.id,
re.EVENT_CONTENT,
(
case when #{statusCondition} ='un_read' then '0'
else re.RED_DOT
end
)as RED_DOT,
re.`STATUS`,
re.SHIFT_PROJECT,
re.LATEST_OPERATED_TIME,
rea.ATTACHMENT_URL as img_url,
re.READ_FLAG
from resi_event re
left join resi_event_attachment rea
on(re.id=rea.RESI_EVENT_ID
and rea.DEL_FLAG='0'
and rea.ATTACHMENT_TYPE='image')
where re.DEL_FLAG='0'
and re.RECALL_FLAG='0'
and re.REPORT_USER_ID=#{userId}
<if test= 'statusCondition == "un_read" ' >
and re.READ_FLAG='0'
</if>
<if test= 'statusCondition != "un_read" ' >
and re.READ_FLAG='1'
and re.`STATUS`=#{statusCondition}
</if>
order by re.LATEST_OPERATED_TIME desc
</select>
<!-- 报事详情 -->
<resultMap id= "selectEventDetailMap" type= "com.epmet.dto.result.EventDetailResultDTO" >
<result property= "isProject" column= "isProject" />
<result property= "eventTime" column= "eventTime" />
<result property= "eventContent" column= "eventContent" />
<result property= "eventAddress" column= "eventAddress" />
<result property= "isClosed" column= "isClosed" />
<result property= "isResolve" column= "isResolve" />
<result property= "isRollback" column= "isRollback" />
<result property= "projectId" column= "projectId" />
<result property= "gridId" column= "gridId" />
<result property= "eventUserId" column= "eventUserId" />
<collection property= "eventImgs" ofType= "java.lang.String" >
<result column= "eventImg" />
</collection>
<collection property= "eventPerson" ofType= "java.lang.String" >
<result column= "person" />
</collection>
<collection property= "orgNameList" ofType= "java.lang.String" >
<result column= "orgId" />
</collection>
</resultMap>
<select id= "selectEventDetail" resultMap= "selectEventDetailMap" >
SELECT
IFNULL(DATE_FORMAT(re.CREATED_TIME,'%Y-%m-%d %H:%i'),'') AS eventTime,
IFNULL(re.EVENT_CONTENT,'') AS eventContent,
IFNULL(re.ADDRESS,'') AS eventAddress,
(CASE WHEN re.`STATUS` = 'processing' THEN FALSE WHEN re.`STATUS` = 'closed_case' THEN TRUE ELSE FALSE END) AS isClosed,
(IF('' = re.RESOLVE_STATUS OR NULL = re.RESOLVE_STATUS, TRUE, FALSE)) AS isResolve,
(CASE WHEN re.READ_FLAG = 1 THEN FALSE ELSE TRUE END) AS isRollback,
(CASE WHEN re.SHIFT_PROJECT = 1 THEN TRUE ELSE FALSE END) AS isProject,
IFNULL(re.project_id,'') AS projectId,
IFNULL(ea.ATTACHMENT_URL,'') AS eventImg,
concat('人大代表-',IFNULL(em.USER_SHOW_NAME,'')) AS person,
re.GRID_ID AS gridId,
re.CREATED_BY AS eventUserId,
ro.ORG_ID AS orgId
FROM resi_event re
LEFT JOIN resi_event_attachment ea ON (ea.RESI_EVENT_ID = re.ID AND ea.DEL_FLAG = '0')
LEFT JOIN resi_event_mention em ON (em.RESI_EVENT_ID = re.ID AND em.DEL_FLAG = '0')
LEFT JOIN resi_event_report_org ro ON (ro.RESI_EVENT_ID = re.ID AND ro.DEL_FLAG = '0')
WHERE re.DEL_FLAG = '0'
AND re.ID = #{eventId}
</select>
<!-- 更新报事人红点状态 -->
<update id= "updateResiEvent" >
UPDATE resi_event
SET RED_DOT = 0,
UPDATED_TIME = NOW()
WHERE DEL_FLAG = '0'
AND ID = #{eventId}
AND REPORT_USER_ID = #{userId}
</update>
<!-- 更新人大代表红点状态 -->
<update id= "updateEventMention" >
UPDATE resi_event_mention
SET RED_DOT = 0,
UPDATED_TIME = NOW()
WHERE DEL_FLAG = '0'
AND USER_ID = #{userId}
AND RESI_EVENT_ID = #{eventId}
</update>
<resultMap id= "newEventsMap" type= "com.epmet.dto.result.NewEventsResultDTO" >
<result property= "eventContent" column= "eventContent" />
<result property= "eventTime" column= "eventTime" />
<result property= "eventId" column= "eventId" />
<collection property= "eventImgs" ofType= "java.lang.String" >
<result column= "img" />
</collection>
</resultMap>
<select id= "newEvents" resultMap= "newEventsMap" >
SELECT
IFNULL(re.EVENT_CONTENT,'') AS eventContent,
DATE_FORMAT(re.CREATED_TIME,'%Y-%m-%d %H:%i') AS eventTime,
IFNULL(ea.ATTACHMENT_URL,'') AS img,
re.id as eventId
FROM resi_event_report_org ro
LEFT JOIN resi_event re ON (re.ID = ro.RESI_EVENT_ID AND re.DEL_FLAG = '0')
LEFT JOIN resi_event_attachment ea ON (ea.RESI_EVENT_ID = ro.RESI_EVENT_ID AND ea.DEL_FLAG = '0' AND
ea.ATTACHMENT_TYPE = 'image' AND ea.SORT IN (0,1,2))
WHERE ro.DEL_FLAG = '0'
AND ro.ORG_READ = 'un_read'
AND ro.ORG_ID IN(
<foreach collection= "orgIds" item= "orgId" separator= "," >
#{orgId}
</foreach> )
ORDER BY ro.CREATED_TIME DESC
</select>
</mapper>