<?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.jeeplus.business.evection.mapper.EvectionMapper">

    <select id="findPageList" resultType="com.jeeplus.business.evection.service.dto.EvectionDTO">
        select distinct
            a.id,
            a.create_by_id as createById,
            su.name as createName,
            a.create_time,
            a.update_by_id as updateById,
            a.update_time,
            a.project_id,
            (select group_concat(name) from jy_project_record pr where FIND_IN_SET(pr.id,(select project_id from jy_evection where id=a.id))) as projectName,
            a.evection_men,
            (select group_concat(name) from sys_user su where FIND_IN_SET(su.id,(select evection_men from jy_evection where id=a.id))) as userName,
            (select dv.label from sys_dict_value dv LEFT JOIN sys_dict_type dt on dt.id=dv.dict_type_id where dv.value=a.status and dt.type='program_project_list_info_status') as evectionStatus,
            a.start_time,
            a.end_time,
            a.remarks,
            a.target_city,
            a.status,
            a.proc_ins_id,
            a.evection_reason,
            a.process_definition_id,
            so.name as createOffice,
            art1.ID_ as task_id,
            b.name as cityName,
            so.name as officeName
        from
            jy_evection a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_office so on su.office_id = so.id and so.del_flag = '0'
        LEFT JOIN sys_area b ON a.target_city = b.`code`
        LEFT JOIN act_ru_task art1 ON a.proc_ins_id = art1.PROC_INST_ID_
        left join sys_user_manage_office sumo on sumo.office_id = su.office_id
         ${ew.customSqlSegment}
        ORDER BY a.update_time DESC
    </select>

    <select id="findList" resultType="com.jeeplus.sys.domain.WorkAttachmentInfo">
		SELECT * FROM work_attachment WHERE del_flag = 0 AND attachment_id = #{id}
	</select>

    <select id="findIsExit" resultType="java.lang.Integer">
		SELECT
			COUNT( 0 )
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{id}
			AND attachment_name = #{name}
	</select>

    <select id="findDtos" resultType="com.jeeplus.sys.domain.WorkAttachmentInfo">
		SELECT
			id,
			url,
			attachment_name AS `name`,
			create_by_id AS `by`,
			create_time
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{id}
	</select>

    <select id="findById" resultType="com.jeeplus.business.evection.service.dto.EvectionDTO">
        select distinct
            a.id,
            a.create_by_id as createById,
            su.name as createName,
            a.create_time,
            a.update_by_id as updateById,
            a.update_time,
            a.project_id,
            (select group_concat(name) from jy_project_record pr where FIND_IN_SET(pr.id,(select project_id from jy_evection where id=a.id))) as projectName,
            a.evection_men,
            (select group_concat(name) from sys_user su where FIND_IN_SET(su.id,(select evection_men from jy_evection where id=a.id))) as userName,
            a.start_time,
            a.end_time,
            a.remarks,
            a.target_city,
            a.status,
            a.proc_ins_id,
            a.evection_reason,
            a.process_definition_id,
            so.name as createOffice,
            art1.ID_ as task_id,
            so.name as officeName
        from
            jy_evection a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_office so on su.office_id = so.id and so.del_flag = '0'
        LEFT JOIN act_ru_task art1 ON a.proc_ins_id = art1.PROC_INST_ID_
         where a.id=#{id}
    </select>

    <update id="updateStatusById">
        update jy_evection set status = #{status} where id=#{id}
    </update>

    <update id="updateInfoById">
        UPDATE
            jy_evection
        SET
            update_by_id =#{evection.updateById},
            update_time = #{evection.updateTime},
            project_id = #{evection.projectId},
            evection_men = #{evection.evectionMen},
            start_time = #{evection.startTime},
            end_time = #{evection.endTime},
            evection_reason = #{evection.evectionReason},
            target_city = #{evection.targetCity},
            remarks = #{evection.remarks}
        WHERE id = #{evection.id}
    </update>


</mapper>