<?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.screen.dao.ScreenProjectDataDao" >
<resultMap type= "com.elink.esua.epdc.dto.screen.result.UploadProjectInfoDTO" id= "uploadprojectinfoMap" >
<result property= "orgType" column= "orgType" />
<result property= "orgId" column= "orgId" />
<result property= "orgName" column= "orgName" />
<result property= "parentId" column= "parentId" />
<result property= "allParentIds" column= "allParentIds" />
<result property= "projectId" column= "projectId" />
<result property= "linkName" column= "linkName" />
<result property= "linkMobile" column= "linkMobile" />
<result property= "projectTitle" column= "projectTitle" />
<result property= "projectContent" column= "projectContent" />
<result property= "projectCreateTime" column= "projectCreateTime" />
<result property= "projectAddress" column= "projectAddress" />
<result property= "latitude" column= "latitude" />
<result property= "longitude" column= "longitude" />
<result property= "projectStatusCode" column= "projectStatusCode" />
<result property= "allCategoryName" column= "allCategoryName" />
<result property= "closeCaseTime" column= "closeCaseTime" />
<collection property= "projectImgUrl" ofType= "java.lang.String" >
<result property= "projectImgUrl" column= "projectImgUrl" />
</collection>
</resultMap>
<select id= "uploadProjectInfo" resultMap= "uploadprojectinfoMap" >
select
'grid' as orgType,
t1.GRID_ID as orgId,
t1.GRID as orgName,
SUBSTRING_INDEX(t1.PARENT_DEPT_IDS,',',-1) as parentId,
PARENT_DEPT_IDS as allParentIds,
t1.ID as projectId,
t1.NICK_NAME as linkName,
t1.MOBILE as linkMobile,
LEFT(t1.ITEM_CONTENT,50)projectTitle,
t1.ITEM_CONTENT as projectContent,
t1.DISTRIBUTE_TIME as projectCreateTime,
t1.ISSUE_ADDRESS as projectAddress,
t1.ISSUE_LATITUDE as latitude,
t1.ISSUE_LONGITUDE as longitude,
case t1.ITEM_STATE WHEN 0 THEN 'pending' WHEN 5 THEN 'closed' WHEN '10' THEN 'closed_case' ELSE '' END AS projectStatusCode,
t1.CATEGORY_FULL_NAME as allCategoryName,
t2.IMG_URL as projectImgUrl,
t3.CREATED_TIME as closeCaseTime,
case
when t1.ITEM_STATE = 10 then 3
when (select ID from esua_epdc_events.epdc_item_handle_process where STATE != 10 and DEL_FLAG ='0' and ITEM_ID = t1.ID group by t1.ID) is null then 1
else 2 end as projectLevel
from (select * from(select * from esua_epdc_events.epdc_item where DEL_FLAG = '0'
and GRID_ID not in ( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
order by ID)a group by a.EVENT_ID) t1
left join esua_epdc_events.epdc_img t2 on t1.EVENT_ID = t2.REFERENCE_ID and t1.DEL_FLAG = '0'
left join esua_epdc_events.epdc_item_handle_process t3 on t3.ITEM_ID = t1.ID and t3.DEL_FLAG = '0' and t3.STATE = 10
where date_format(t1.UPDATED_TIME, '%Y-%m-%d') >= STR_TO_DATE(#{yearMonthDay}, '%Y-%m-%d')
and date_format(t1.UPDATED_TIME, '%Y-%m-%d') < = date_sub(curdate(),interval 1 day)
order by t2.CREATED_TIME
</select>
<resultMap type= "com.elink.esua.epdc.dto.screen.result.UploadProjectProcessDTO" id= "uploadprojectprocessMap" >
<result property= "processId" column= "processId" />
<result property= "projectId" column= "projectId" />
<result property= "transferDeptName" column= "transferDeptName" />
<result property= "transferDeptIds" column= "transferDeptIds" />
<result property= "handlerName" column= "handlerName" />
<result property= "handlerId" column= "handlerId" />
<result property= "handlerType" column= "handlerType" />
<result property= "operation" column= "operation" />
<result property= "publicReply" column= "publicReply" />
<result property= "internalRemark" column= "internalRemark" />
<result property= "processTime" column= "processTime" />
<collection property= "attachments" ofType= "com.elink.esua.epdc.dto.screen.result.Attachments" >
<result property= "attachmentId" column= "attachmentId" />
<result property= "filePlace" column= "filePlace" />
<result property= "attachmentUrl" column= "attachmentUrl" />
<result property= "delFlag" column= "DEL_FLAG" />
</collection>
</resultMap>
<select id= "uploadProjectProcess"
resultMap="uploadprojectprocessMap">
select t.*,
t3.ID as attachmentId,
case t3.IMG_TYPE when 'itemHandle' then 'internal' when 'itemOutHandle' then 'public' else null End as filePlace,
t3.IMG_URL as attachmentUrl,
t3.DEL_FLAG
from (
select
t1.ID as processId,
t1.ITEM_ID as projectId,
group_concat(t4.DEPT_NAME)transferDeptName,
group_concat(t4.DEPT_ID)transferDeptIds,
t1.HANDLER_DEPT as handlerName,
t1.HANDLER_DEPT_ID as handlerId,
'unknown' as handlerType,
case
when (t4.ID is not null and t1.STATE = 0 and t1.CREATED_TIME != (select min(t.CREATED_TIME) from esua_epdc_events.epdc_item_handle_process t where t.DEL_FLAG = '0' and t1.ITEM_ID = t.ITEM_ID group by t.ITEM_ID)) then 'transfer'
when (t4.ID is null and t1.STATE = 0 and t1.CREATED_TIME != (select min(t.CREATED_TIME) from esua_epdc_events.epdc_item_handle_process t where t.DEL_FLAG = '0' and t1.ITEM_ID = t.ITEM_ID group by t.ITEM_ID)) then 'response'
when (t1.STATE = 0 and t1.CREATED_TIME = (select min(t.CREATED_TIME) from esua_epdc_events.epdc_item_handle_process t where t.DEL_FLAG = '0' and t1.ITEM_ID = t.ITEM_ID group by t.ITEM_ID)) then 'created'
when t1.STATE = 5 then 'close'
when t1.STATE = 10 then 'closed_case'
else '' END as operation,
t1.OUT_HANDLE_ADVICE as publicReply,
t1.HANDLE_ADVICE as internalRemark,
t1.CREATED_TIME as processTime
from esua_epdc_events.epdc_item_handle_process t1
left join esua_epdc_events.epdc_item_dept t4 on t4.ITEM_HANDLE_ID = t1.ID and t4.DEL_FLAG = '0'
where date_format(t1.UPDATED_TIME, '%Y-%m-%d') >= STR_TO_DATE(#{yearMonthDay}, '%Y-%m-%d')
and date_format(t1.UPDATED_TIME, '%Y-%m-%d') < = date_sub(curdate(),interval 1 day) and t1.DEL_FLAG = '0'
and t1.HANDLER_DEPT_ID not in ( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by t1.ID
)t
left join esua_epdc_events.epdc_img t3 on t3.REFERENCE_ID = t.processId and t3.DEL_FLAG = '0'
order by t3.CREATED_TIME
</select>
<select id= "selectProjectGridDaily" resultType= "com.elink.esua.epdc.dto.screen.result.ProjectGridDailyDTO" >
SELECT sd.`id` AS gridId,
sd.pid AS pid,
sd.pids AS pids,
count(it.id) as projectTotal,
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as
resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000')
as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join (select lin.* from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m-%d' ) < = #{yesterDayDate}
group by lin.EVENT_ID) it on it.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by sd.id
</select>
<select id= "selectProjectOrgDaily" resultType= "com.elink.esua.epdc.dto.screen.result.ProjectOrgDailyDTO" >
SELECT di.`id` AS orgId,
'district' as orgType,
di.pid AS pid,
di.pids AS pids,
count(it.id) as projectTotal,
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000') as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join `esua_epdc_admin`.`sys_dept` st on st.id=co.pid
left join `esua_epdc_admin`.`sys_dept` di on di.id=st.pid
left join (select lin.* from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m-%d' ) < =#{yesterDayDate}
group by lin.EVENT_ID) it on it.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by di.id
union all
SELECT st.`id` AS orgId,
'street' as orgType,
st.pid AS pid,
st.pids AS pids,
count(it.id) as projectTotal,
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000') as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join `esua_epdc_admin`.`sys_dept` st on st.id=co.pid
left join (select lin.* from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m-%d' ) < =#{yesterDayDate}
group by lin.EVENT_ID) it on it.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by st.id
union all
SELECT co.`id` AS orgId,
'community' as orgType,
co.pid AS pid,
co.pids AS pids,
count(it.id) as projectTotal,
count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null) as resolvedNum,
ifnull(format(round(count((it.ITEM_STATE=5 or it.ITEM_STATE=10) or null)/count(it.id),4),4),'0.0000') as resolvedRatio,
ifnull(format(round(count((it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null)/count(it.id),4),4),'0.0000') as goodRatio,
count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as evaluateTotal,
count( (it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null) as goodTotal,
count( it.EVALUATION_SCORE=0 or null) as badTotal,
ifnull(format(round(count(it.EVALUATION_SCORE=0 or null)/count( (it.EVALUATION_SCORE=0 or it.EVALUATION_SCORE=1 or it.EVALUATION_SCORE=2) or null),4),4),'0.0000') as badRatio
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join (select lin.* from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m-%d' ) < =#{yesterDayDate}
group by lin.EVENT_ID) it on it.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by co.id
</select>
<select id= "selectQuantityGridMonthly"
resultType="com.elink.esua.epdc.dto.screen.result.QuantityGridMonthly">
SELECT sd.`id` AS gridId,
sd.pid AS pid,
sd.pids AS pids,
ifnull(it.projectIncr,0) as projectIncr,
ifnull(it.closedIncr,0) as closedIncr,
ifnull(li2.projectTotal,0) as projectTotal,
ifnull(li2.unClosedTotal,0) as unClosedTotal,
ifnull(li2.closedTotal,0) as closedTotal
FROM `esua_epdc_admin`.`sys_dept` sd
left join (select li.GRID_ID,
count(li.id) as projectIncr,
count((li.ITEM_STATE= 5 or li.ITEM_STATE = 10) or null) as closedIncr
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) = #{yearMonth}
group by lin.EVENT_ID)li
group by li.GRID_ID)it on it.GRID_ID=sd.id
left join (select al.GRID_ID,
count(al.id) as projectTotal,
count(al.ITEM_STATE= 0 or null) as unClosedTotal,
count((al.ITEM_STATE= 5 or al.ITEM_STATE = 10) or null) as closedTotal
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) < = #{yearMonth}
group by lin.EVENT_ID)al
group by al.GRID_ID)li2 on li2.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by sd.id
</select>
<select id= "selectQuantityOrgMonthly"
resultType="com.elink.esua.epdc.dto.screen.result.QuantityOrgMonthlyDTO">
SELECT di.`id` AS orgId,
'district' as orgType,
di.pid AS pid,
di.pids AS pids,
ifnull(it.projectIncr,0) as projectIncr,
ifnull(it.closedIncr,0) as closedIncr,
ifnull(li2.projectTotal,0) as projectTotal,
ifnull(li2.unClosedTotal,0) as unClosedTotal,
ifnull(li2.closedTotal,0) as closedTotal
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join `esua_epdc_admin`.`sys_dept` st on st.id=co.pid
left join `esua_epdc_admin`.`sys_dept` di on di.id=st.pid
left join (select li.GRID_ID,
count(li.id) as projectIncr,
count((li.ITEM_STATE= 5 or li.ITEM_STATE = 10) or null) as closedIncr
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) =#{yearMonth}
group by lin.EVENT_ID)li
group by li.GRID_ID)it on it.GRID_ID=sd.id
left join (select al.GRID_ID,
count(al.id) as projectTotal,
count(al.ITEM_STATE= 0 or null) as unClosedTotal,
count((al.ITEM_STATE= 5 or al.ITEM_STATE = 10) or null) as closedTotal
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) < =#{yearMonth}
group by lin.EVENT_ID)al
group by al.GRID_ID)li2 on li2.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by di.id
union all
SELECT st.`id` AS orgId,
'street' as orgType,
st.pid AS pid,
st.pids AS pids,
ifnull(it.projectIncr,0) as projectIncr,
ifnull(it.closedIncr,0) as closedIncr,
ifnull(li2.projectTotal,0) as projectTotal,
ifnull(li2.unClosedTotal,0) as unClosedTotal,
ifnull(li2.closedTotal,0) as closedTotal
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join `esua_epdc_admin`.`sys_dept` st on st.id=co.pid
left join (select li.GRID_ID,
count(li.id) as projectIncr,
count((li.ITEM_STATE= 5 or li.ITEM_STATE = 10) or null) as closedIncr
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) =#{yearMonth}
group by lin.EVENT_ID)li
group by li.GRID_ID)it on it.GRID_ID=sd.id
left join (select al.GRID_ID,
count(al.id) as projectTotal,
count(al.ITEM_STATE= 0 or null) as unClosedTotal,
count((al.ITEM_STATE= 5 or al.ITEM_STATE = 10) or null) as closedTotal
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) < =#{yearMonth}
group by lin.EVENT_ID)al
group by al.GRID_ID)li2 on li2.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by st.id
union all
SELECT co.`id` AS orgId,
'community' as orgType,
co.pid AS pid,
co.pids AS pids,
ifnull(it.projectIncr,0) as projectIncr,
ifnull(it.closedIncr,0) as closedIncr,
ifnull(li2.projectTotal,0) as projectTotal,
ifnull(li2.unClosedTotal,0) as unClosedTotal,
ifnull(li2.closedTotal,0) as closedTotal
FROM `esua_epdc_admin`.`sys_dept` sd
left join `esua_epdc_admin`.`sys_dept` co on co.id=sd.pid
left join (select li.GRID_ID,
count(li.id) as projectIncr,
count((li.ITEM_STATE= 5 or li.ITEM_STATE = 10) or null) as closedIncr
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) =#{yearMonth}
group by lin.EVENT_ID)li
group by li.GRID_ID)it on it.GRID_ID=sd.id
left join (select al.GRID_ID,
count(al.id) as projectTotal,
count(al.ITEM_STATE= 0 or null) as unClosedTotal,
count((al.ITEM_STATE= 5 or al.ITEM_STATE = 10) or null) as closedTotal
from (select lin.*
from (select * from esua_epdc_events.epdc_item order by id) lin
where lin.DEL_FLAG=0
AND date_format( lin.CREATED_TIME, '%Y-%m' ) < =#{yearMonth}
group by lin.EVENT_ID)al
group by al.GRID_ID)li2 on li2.GRID_ID=sd.id
WHERE sd.`del_flag`= 0
AND sd.`type_key`= 'grid_party'
AND sd.`id` NOT IN( SELECT t.`dept_id`
FROM `esua_epdc_admin`.`sys_dept_config` t
WHERE t.`del_flag`= 0)
group by co.id
</select>
</mapper>