<?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.inscription.mapper.InscriptionMapper">

    <select id="findPageList" resultType="com.jeeplus.business.inscription.service.dto.InscriptionDTO">
        select distinct
            a.id,
            a.create_by_id,
            su.name as createName,
            a.create_time,
            so.name as officeName,
            a.project_id,
            pr.name as projectName,
            art1.ID_ as task_id,
            a.process_definition_id,
            a.proc_ins_id,
            (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 inscriptionStatus,
            a.status
        from
            jy_inscription 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_
        left join jy_project_record pr on a.project_id = pr.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="findById" resultType="com.jeeplus.business.inscription.service.dto.InscriptionDTO">
        select
            a.id,
            a.create_by_id,
            su.name as createName,
            a.create_time,
            so.name as officeName,
            a.project_id,
            pr.name as projectName,
            art1.ID_ as task_id,
            a.process_definition_id,
            a.proc_ins_id,
            a.status,
            a.normal_page,
            a.color_page,
            a.bookbinding_num,
            a.other_num,
            a.content
        from
            jy_inscription a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_user su1 on a.minister = su1.id and su.del_flag = '0'
        left join sys_user su2 on a.examiner = su2.id and su.del_flag = '0'
        left join sys_user su3 on a.approver = su3.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_
        left join jy_project_record pr on a.project_id = pr.id
        where a.id=#{id}
    </select>

    <select id="findCheckerById" resultType="com.jeeplus.business.inscription.service.dto.InscriptionDTO">
        select
            a.id,
            a.create_by_id,
            su.name as createName,
            a.create_time,
            so.name as officeName,
            a.project_id,
            pr.name as projectName,
            art1.ID_ as task_id,
            a.process_definition_id,
            a.proc_ins_id,
            a.status,
            a.normal_page,
            a.color_page,
            a.bookbinding_num,
            a.other_num,
            a.content,
            su1.name as minister,
            su2.name as examiner,
            su3.name as approver
        from
            jy_inscription a
        left join sys_user su on a.create_by_id = su.id and su.del_flag = '0'
        left join sys_user su1 on a.minister = su1.id and su.del_flag = '0'
        left join sys_user su2 on a.examiner = su2.id and su.del_flag = '0'
        left join sys_user su3 on a.approver = su3.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_
        left join jy_project_record pr on a.project_id = pr.id
        where a.id=#{id}
    </select>

    <update id="updateInfoById">
        update
            jy_inscription
        set
            update_by_id =#{inscription.updateById},
            update_time = #{inscription.updateTime},
            normal_page = #{inscription.normalPage},
            color_page = #{inscription.colorPage},
            bookbinding_num = #{inscription.bookbindingNum},
            other_num = #{inscription.otherNum},
            content = #{inscription.content},
            project_id = #{inscription.projectId}
        where
            id = #{inscription.id}
    </update>


</mapper>