<?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.finance.contractRegistration.mapper.ContractFileMapper">
    <update id="updateStatusById">
        UPDATE cw_work_contract_file SET filed_type = #{filedType}, filed_data = NOW()
<!--        <if test="filedType == '4'.toString()">-->
<!--            ,proc_ins_id = null-->
<!--            ,process_definition_id = null-->
<!--        </if>-->
        WHERE del_flag = 0 AND contract_info_id = #{id}
    </update>
    <delete id="deleteFileInfo">
        delete from work_attachment where attachment_id = #{attachmentId}
    </delete>
    <select id="selectFileByContractInfoId"
            resultType="com.jeeplus.finance.contractRegistration.domain.ContractFile">
        SELECT * FROM `cw_work_contract_file` WHERE del_flag = 0 AND contract_info_id = #{id}
    </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="findById" resultType="com.jeeplus.finance.contractRegistration.domain.ContractFile">
        SELECT
			a.id,
			b.id as fileId,
			c.`name` AS createBy,
			c.`id` AS createId,
			a.create_time,
			a.update_by_id,
			a.update_time,
			a.del_flag,
			a.contract_no as contractNo,
			a.contract_name as contractName,
			a.payer_subject as payerSubject,
			a.payment_method as paymentMethod,
			DATE_FORMAT(a.signing_date,'%Y-%m-%d') as signingDate,
            a.contract_amount as contractAmount,
            a.actual_contract_amount as actualContractAmount,
            a.contract_num as contractNum,
            a.payment_agreement as paymentAgreement,
            a.change_num as changeNum,
            a.department,
            a.client_contacts as clientContacts,
            a.client_contacts_phone as clientContactsPhone,
            a.contract_approval_type as contractApprovalType,
            a.proc_ins_id as procInsId,
            a.status,
            b.filed_type as filedType,
            b.contract_info_id as contractInfoId
		FROM
			cw_work_contract_info a
            LEFT JOIN cw_work_contract_file b on a.id = b.contract_info_id
            LEFT JOIN sys_user c ON a.create_by_id = c.id
        WHERE
			a.id = #{id}
			AND a.del_flag = 0
    </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="findByInfoId" resultType="com.jeeplus.finance.contractRegistration.domain.ContractFile">
        SELECT
			b.id as fileId,
			c.`name` AS createBy,
			c.`id` AS createId,
			a.create_time,
			a.update_by_id,
			a.update_time,
			a.del_flag,
			a.contract_no as contractNo,
			a.contract_name as contractName,
			a.payer_subject as payerSubject,
			a.payment_method as paymentMethod,
			DATE_FORMAT(a.signing_date,'%Y-%m-%d') as signingDate,
            a.contract_amount as contractAmount,
            a.actual_contract_amount as actualContractAmount,
            a.contract_num as contractNum,
            a.payment_agreement as paymentAgreement,
            a.change_num as changeNum,
            a.department,
            a.client_contacts as clientContacts,
            a.client_contacts_phone as clientContactsPhone,
            a.contract_approval_type as contractApprovalType,
            a.proc_ins_id as procInsId,
            a.status,
            b.filed_type as filedType,
            b.contract_info_id as contractInfoId
		FROM
			cw_work_contract_file b
            LEFT JOIN cw_work_contract_info a on a.id = b.contract_info_id
            LEFT JOIN sys_user c ON a.create_by_id = c.id
        WHERE
			b.id = #{id}
			AND b.del_flag = 0
    </select>
    <select id="getInfoByConId" resultType="com.jeeplus.finance.contractRegistration.domain.ContractFile">
        select * from cw_work_contract_file where contract_info_id = #{id}
    </select>
    <select id="getById" resultType="com.jeeplus.finance.contractRegistration.domain.ContractFile">
        select * from cw_work_contract_file where id = #{id}
    </select>
</mapper>
