<?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.useSeal.mapper.SignetMapper">
    <select id="findPageList" resultType="com.jeeplus.business.useSeal.service.dto.SignetDTO">
        select distinct
            a.id,
            a.create_by_id,
            su.name as createByName,
            a.create_time as createDate,
            a.project_id,
            a.project_name,
            a.type_status,
            a.no,
            (select dv.label from sys_dict_value dv where a.type=dv.id) as type,
            (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.first_type and dt.type='jy_signet_type') as firstType,
            (case when (a.type is null) then (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.first_type and dt.type='jy_signet_type')
            when a.type is not null then CONCAT('项目','-',(select dv.label from sys_dict_value dv where a.type=dv.id))  ELSE '' END) as typeName,
            (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 sealTypeName,
            a.number,
            a.status,
            a.remarks,
            so.name as office,
            so.id as officeId,
            a.proc_ins_id as procInsId ,
            a.process_definition_id as processDefinitionId,
            art.ID_ as task_id
            from  jy_user_signet a
            left join sys_user su on a.create_by_id = su.id
            left join sys_office so on su.office_id=so.id
            left join act_ru_task art ON a.proc_ins_id = art.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="findFileList" 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="findById" resultType="com.jeeplus.business.useSeal.service.dto.SignetDTO">
        select
            a.id,
            a.create_by_id,
            su.name as createByName,
            a.create_time as createDate,
            a.project_id,
            a.project_name,
            a.no,
            a.type,
            a.first_type,
            a.number,
            a.status,
            a.remarks,
            a.proc_ins_id,
            a.type_status,
            a.process_definition_id,
            so.name as office,
            so.id,
            art.ID_ as task_id
            from  jy_user_signet a
            left join sys_user su on a.create_by_id = su.id
            left join sys_office so on su.office_id=so.id
            left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
            where a.id=#{id}
    </select>

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

    <select id="findSeal" resultType="com.jeeplus.business.useSeal.domain.Signet">
        select
            a.id,
            a.create_by_id,
            su.name as createByName,
            a.create_time as createDate,
            a.update_time,
            a.project_id,
            a.project_name,
            a.no,
            a.type,
            a.first_type,
            a.number,
            a.status,
            a.remarks,
            a.proc_ins_id,
            a.process_definition_id,
            so.name as office,
            so.id,
            art.ID_ as task_id
            from  jy_user_signet a
            left join sys_user su on a.create_by_id = su.id
            left join sys_office so on su.office_id=so.id
            left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
            where a.update_time &lt; #{newDate} and a.status = '5' and a.type_status = '1'
    </select>

    <select id="findSealInTime" resultType="com.jeeplus.business.useSeal.domain.Signet">
        select
            a.id,
            a.create_by_id,
            su.name as createByName,
            a.create_time as createDate,
            a.update_time,
            a.project_id,
            a.project_name,
            a.no,
            a.type,
            a.first_type,
            a.number,
            a.status,
            a.remarks,
            a.proc_ins_id,
            a.process_definition_id,
            so.name as office,
            so.id,
            art.ID_ as task_id
            from  jy_user_signet a
            left join sys_user su on a.create_by_id = su.id
            left join sys_office so on su.office_id=so.id
            left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
            where a.update_time &gt;= #{newDate} and a.status = '5' and a.type_status = '1'
    </select>

    <update id="updateStatusBySealId">
        update
            jy_user_signet
        set status='6' , exceed_time_status ='1' where id=#{id}
    </update>
    <select id="getByProjectId" resultType="com.jeeplus.business.useSeal.service.dto.SignetDTO">
        select
            a.id,
            a.create_by_id,
            a.update_by_id,
            a.update_time,
            a.approval_time,
            su.name as createByName,
            a.create_time as createDate,
            a.project_id,
            a.project_name,
            a.no,
            a.type,
            a.first_type,
            a.number,
            a.status,
            a.remarks,
            a.proc_ins_id,
            a.type_status,
            a.process_definition_id,
            so.name as office,
            so.id,
            art.ID_ as task_id
            from  jy_user_signet a
            left join sys_user su on a.create_by_id = su.id
            left join sys_office so on su.office_id=so.id
            left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
            where (FIND_IN_SET(#{projectId},a.project_id) or a.project_id = #{projectId})
                and a.type = (select dv.id from sys_dict_value dv where a.type=dv.id)
                and a.status in ('5')
    </select>

</mapper>