<?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.assess.reimbursement.reimbursementInfo.mapper.ReimbursementInfoMapper">

	<select id="findList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.RetureListDto">
		SELECT
			DISTINCT a.id,
			a.`no`,
			(CASE
			WHEN a.source_type = 1 THEN b.type_id
			WHEN a.source_type = 2 THEN b2.type_id
			WHEN a.source_type = 4 THEN b4.type_id
									ELSE b5.type_id END) AS type_id,
			(CASE
			WHEN a.source_type = 1 THEN t.name
			WHEN a.source_type = 2 THEN t2.name
			WHEN a.source_type = 4 THEN t4.name
									ELSE t5.name END) AS type_name,
			(CASE
			WHEN a.source_type = 1 THEN b.project_id
			WHEN a.source_type = 2 THEN b2.contract_id
			WHEN a.source_type = 4 THEN b4.project_id
									ELSE b5.project_id END) AS project_id,
			(CASE
			WHEN a.source_type = 1 THEN p.name
			WHEN a.source_type = 2 THEN contr2.name
			WHEN a.source_type = 4 THEN b4.project_name
									ELSE b5.project_name END) AS project_name,
			(CASE
			WHEN a.source_type = 1 THEN b.report_number
			WHEN a.source_type = 2 THEN b2.report_number
			WHEN a.source_type = 4 THEN b4.report_number
									ELSE b5.report_number END) AS report_number,
			(CASE
			WHEN a.source_type = 1 THEN so.name
			WHEN a.source_type = 2 THEN so2.name
			WHEN a.source_type = 4 THEN so4.name
									ELSE so5.name END) AS dept_name,
			(CASE
			WHEN a.source_type = 1 THEN us.name
			WHEN a.source_type = 2 THEN us2.name
			WHEN a.source_type = 4 THEN us4.name
									ELSE us5.name END) AS name,
			(CASE
			WHEN a.source_type = 1 THEN  trim(b.`number`)
			WHEN a.source_type = 2 THEN trim(b2.`number`)
			WHEN a.source_type = 4 THEN trim(b4.`number`)
									ELSE trim(b5.`number`) END) AS `number`,
			a.user_name,
			a.reim_date,
			a.type,
			a.proc_ins_id,
			a.process_definition_id,
			d.ID_ AS task_id,
			a.create_by_id as create_id,
			a.source_type,
			a.purchase_id,
			a.reimbursement_type,
			a.approval_time,
			a.payment_status,
			a.payment_time
-- 			pru.purchase_no
		FROM
			reimbursement_info a

			LEFT JOIN reimbursement_detail_info b ON a.id = b.info_id AND b.del_flag = 0
			left join cw_reimbursement_type_info t on b.type_id = t.id and t.del_flag = 0
			left join program_project_list_info p on p.id = b.project_id and p.del_flag = 0
			left join sys_office so on so.id = b.dept_id and so.del_flag = 0
			left join sys_user us on us.id = b.user_id and us.del_flag = 0

			LEFT JOIN reimbursement_detail_info_contract b2 ON a.id = b2.info_id AND b2.del_flag = 0
			left join cw_reimbursement_type_info t2 on b2.type_id = t2.id and t2.del_flag = 0
			left join work_contract_info contr2 on contr2.id = b2.contract_id and contr2.del_flag = 0
			left join sys_office so2 on so2.id = b2.dept_id and so2.del_flag = 0
			left join sys_user us2 on us2.id = b2.user_id and us2.del_flag = 0

			LEFT JOIN reimbursement_detail_info_other b4 ON a.id = b4.info_id AND b4.del_flag = 0
			left join cw_reimbursement_type_info t4 on b4.type_id = t4.id and t4.del_flag = 0
			left join program_project_list_info p4 on p4.id = b4.project_id and p4.del_flag = 0
			left join sys_office so4 on so4.id = b4.dept_id and so4.del_flag = 0
			left join sys_user us4 on us4.id = b4.user_id and us4.del_flag = 0

			LEFT JOIN reimbursement_detail_info_procured b5 ON a.id = b5.info_id AND b5.del_flag = 0
			left join cw_reimbursement_type_info t5 on b5.type_id = t5.id and t5.del_flag = 0
			left join program_project_list_info p5 on p5.id = b5.project_id and p5.del_flag = 0
			left join sys_office so5 on so5.id = b5.dept_id and so5.del_flag = 0
			left join sys_user us5 on us5.id = b5.user_id and us5.del_flag = 0



			LEFT JOIN sys_user c ON a.create_by_id =  c.id
			left join sys_user_manage_office sumo on sumo.office_id = c.office_id
			LEFT JOIN act_ru_task d ON a.proc_ins_id = d.PROC_INST_ID_
-- 			left join material_management_pruchase_request_basics pru on pru.id = a.purchase_id and pru.del_flag = '0'
			${ew.customSqlSegment}
		ORDER BY a.update_time DESC
	</select>

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

	<update id="updateStatusById">
		UPDATE reimbursement_info SET type = #{type}
	    WHERE id = #{id}
	</update>

	<select id="findOfficeList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office WHERE del_flag = 0
	</select>

	<select id="findOfficeListByNotTenantId" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office WHERE del_flag = 0 and tenant_id != #{tenantId}
	</select>

	<select id="findOfficeListByTenantId" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office WHERE del_flag = 0 and tenant_id = #{tenantId}
	</select>

	<select id="findOfficeList2" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office WHERE del_flag = 0
	</select>

	<select id="findOfficeListByCompanyId" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office WHERE del_flag = 0 and (id = #{companyId} or parent_ids like concat ('%',#{companyId},'%'))
	</select>

	<select id="findOfficeListByCompanyId2" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office WHERE del_flag = 0 and (id = #{companyId} or parent_ids like concat ('%',#{companyId},'%'))
	</select>

	<select id="findUserList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
			a.id,
			a.`name`,
			a.office_id AS parent_id,
			b.`name` AS office_name,
			true AS is_user
		FROM
			sys_user a
			LEFT JOIN sys_office b ON a.office_id = b.id
		WHERE
			a.del_flag = 0 and a.is_admin is null and a.login_flag = 1
			<if test="name != null and name != ''">
				and a.`name` LIKE CONCAT ('%', #{name}, '%')
			</if>
	</select>

	<select id="findZhglgsUserList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		WHERE
		a.del_flag = 0 and a.is_admin is null and a.login_flag = 1 and a.tenant_id = '10002'
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>

	<select id="findZsUserList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		WHERE
		a.del_flag = 0 and a.is_admin is null and a.login_flag = 1 and a.tenant_id = '10004' and b.name = #{zsOfficeName}
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>

	<select id="findCwglgsUserList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		WHERE
		a.del_flag = 0 and a.is_admin is null and a.login_flag = 1 and a.tenant_id = '10003'
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>

	<select id="finduserAllList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		WHERE
		a.del_flag = 0 and a.is_admin is null
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>

	<select id="findCertUserList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		left join sys_cert sc on a.id = sc.user_id and sc.del_flag = '0'
		WHERE
		a.del_flag = 0 and a.is_admin is null and a.login_flag = 1 and sc.type = '6' and a.tenant_id = '10003'
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>

	<select id="findZhglgsUserList2" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		left join sys_cert sc on a.id = sc.user_id and sc.del_flag = '0'
		WHERE
		a.del_flag = 0 and a.is_admin is null and a.login_flag = 1 and a.tenant_id = '10002' and sc.type = '6'
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>

	<select id="findZhglgsUserList3" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT
		a.id,
		a.`name`,
		a.office_id AS parent_id,
		b.`name` AS office_name,
		true AS is_user
		FROM
		sys_user a
		LEFT JOIN sys_office b ON a.office_id = b.id
		WHERE
		a.del_flag = 0 and a.is_admin is null and a.login_flag = 1 and a.tenant_id = '10004' and a.login_flag = '1' and a.office_id = #{officeId}
		<if test="name != null and name != ''">
			and a.`name` LIKE CONCAT ('%', #{name}, '%')
		</if>
	</select>


	<select id="findExportList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.RetureListDto">
		SELECT
			a.id,
			a.`no`,
			b.type_id,
			b.type_name,
			b.project_id,
			b.project_name,
			b.report_number,
			a.user_name,
			b.user_name AS `name`,
			b.dept_name,
			a.reim_date,
			b.`number`,
			a.type,
			a.proc_ins_id,
			a.process_definition_id,
			d.ID_ AS task_id
		FROM
			reimbursement_info a
			LEFT JOIN reimbursement_detail_info b ON a.id = b.info_id AND b.del_flag = 0
			LEFT JOIN sys_user c ON a.create_by_id =  c.id
			LEFT JOIN act_ru_task d ON a.proc_ins_id = d.PROC_INST_ID_
			${ew.customSqlSegment}
		ORDER BY a.update_time DESC
	</select>

	<select id="relationReimbursementList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.RetureListDto">
		SELECT
			a.id,
			a.`no`,
			b.type_id,
			b.type_name,
			b.project_id,
			b.project_name,
			b.report_number,
			a.user_name,
			b.user_name AS `name`,
			b.dept_name,
			a.reim_date,
			b.`number`,
			a.type,
			a.proc_ins_id,
			a.process_definition_id,
			d.ID_ AS task_id
		FROM
			reimbursement_info a
			LEFT JOIN reimbursement_detail_info b ON a.id = b.info_id AND b.del_flag = 0
			LEFT JOIN sys_user c ON a.create_by_id =  c.id
			LEFT JOIN act_ru_task d ON a.proc_ins_id = d.PROC_INST_ID_
		WHERE
			a.del_flag = 0
			AND a.project_id IN (SELECT id FROM program_project_list_info WHERE del_flag = 0 AND contract_id = #{id})
		ORDER BY a.update_time DESC
	</select>
	<select id="findOfficeListByUserName"
			resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT a.id,a.`name`,a.parent_id FROM sys_office a
		LEFT JOIN sys_user b
		on a.id = b.office_id
		WHERE a.del_flag = 0 and b.name = #{name}
	</select>

	<select id="getContractDetailList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.domain.ReimbursementDetailInfoContract">
		select
		a.id,
		a.create_by_id,
		a.create_time,
		a.del_flag,
		a.info_id,
		a.user_id,
		a.dept_id,
		a.type_id,
		a.contract_id,
		a.report_number,
		a.number,
		a.ordinary_number,
		a.receipt_number,
		a.ordinary_receipt_number,
		a.receipt_number_count,
		a.number_count,
		a.days,
		a.content,
		su.name as user_name,
		so.name as dept_name,
		pg_type.name as type_name,
		pg_contract.name as contract_name
		from reimbursement_detail_info_contract a
		left join sys_user su on a.user_id = su.id and su.del_flag = '0'
		left join sys_office so on a.dept_id = so.id and so.del_flag = '0'
		left join cw_reimbursement_type_info pg_type on pg_type.id = a.type_id and pg_type.del_flag = '0'
		left join work_contract_info pg_contract on pg_contract.id = a.contract_id and pg_contract.del_flag = '0'
		where a.del_flag = '0' and a.info_id = #{id}
		order by a.number asc
	</select>

	<select id="getDetailList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.domain.ReimbursementDetailInfo">
		select
		a.id,
		a.create_by_id,
		a.create_time,
		a.del_flag,
		a.info_id,
		a.user_id,
		a.dept_id,
		a.type_id,
		a.project_id,
		a.report_number,
		a.number,
		a.ordinary_number,
		a.receipt_number,
		a.ordinary_receipt_number,
		a.receipt_number_count,
		a.number_count,
		a.days,
		a.content,
		a.reimbursement_type,
		a.unique_id,
		su.name as user_name,
		so.name as dept_name,
		pg_type.name as type_name,
		pg_project.name as project_name
		from reimbursement_detail_info a
		left join sys_user su on a.user_id = su.id and su.del_flag = '0'
		left join sys_office so on a.dept_id = so.id and so.del_flag = '0'
		left join cw_reimbursement_type_info pg_type on pg_type.id = a.type_id and pg_type.del_flag = '0'
		left join program_project_list_info pg_project on pg_project.id = a.project_id and pg_project.del_flag = '0'
		where a.del_flag = '0' and a.info_id = #{id}
		order by a.sort+0 asc
	</select>

	<select id="getOtherDetailList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.domain.ReimbursementDetailInfoOther">
		select
		a.id,
		a.create_by_id,
		a.create_time,
		a.del_flag,
		a.info_id,
		a.user_id,
		a.dept_id,
		a.type_id,
		a.project_id,
		a.report_number,
		a.number,
		a.ordinary_number,
		a.receipt_number,
		a.ordinary_receipt_number,
		a.receipt_number_count,
		a.number_count,
		a.days,
		a.content,
		a.reimbursement_type,
		a.unique_id,
		su.name as user_name,
		so.name as dept_name,
		pg_type.name as type_name,
		a.project_name as project_name
		from reimbursement_detail_info_other a
		left join sys_user su on a.user_id = su.id and su.del_flag = '0'
		left join sys_office so on a.dept_id = so.id and so.del_flag = '0'
		left join cw_reimbursement_type_info pg_type on pg_type.id = a.type_id and pg_type.del_flag = '0'
		left join program_project_list_info pg_project on pg_project.id = a.project_id and pg_project.del_flag = '0'
		where a.del_flag = '0' and a.info_id = #{id}
		order by a.sort+0 asc
	</select>

	<select id="getProcuredDetailList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.domain.ReimbursementDetailInfoProcured">
		select
		a.id,
		a.create_by_id,
		a.create_time,
		a.del_flag,
		a.info_id,
		a.user_id,
		a.dept_id,
		a.type_id,
		a.project_id,
		a.report_number,
		a.number,
		a.ordinary_number,
		a.receipt_number,
		a.ordinary_receipt_number,
		a.receipt_number_count,
		a.number_count,
		a.days,
		a.content,
		su.name as user_name,
		so.name as dept_name,
		pg_type.name as type_name,
		a.project_name as project_name
		from reimbursement_detail_info_procured a
		left join sys_user su on a.user_id = su.id and su.del_flag = '0'
		left join sys_office so on a.dept_id = so.id and so.del_flag = '0'
		left join cw_reimbursement_type_info pg_type on pg_type.id = a.type_id and pg_type.del_flag = '0'
		left join program_project_list_info pg_project on pg_project.id = a.project_id and pg_project.del_flag = '0'
		where a.del_flag = '0' and a.info_id = #{id}
		order by a.number asc
	</select>


	<select id="getNumberById" resultType="java.lang.String">
		select no from reimbursement_info where id = #{id}
	</select>


	<select id="getEffectiveDataByInvoiceNumber" resultType="java.lang.Integer">
		select count(a.id) as count from reimbursement_amount_info a
		left join reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number = #{invoiceNumber} and a.del_flag = 0
			<if test="id != null and id != ''">
				and a.info_id != #{id}
			</if>
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5')
		</where>
	</select>

	<select id="getEffectiveDataByNumbers" resultType="string">
		select a.number as count from reimbursement_amount_info a
		left join reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number in
			<foreach collection="invoiceNumber" item="number" index="index" open="(" close=")" separator=",">
				#{number}
			</foreach>
			and a.del_flag = 0
			<if test="id != null and id != ''">
				and a.info_id != #{id}
			</if>
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5')
		</where>
	</select>

	<select id="getEffectiveDataByNumbers2" resultType="string">
		SELECT IFNULL(GROUP_CONCAT(CAST(count AS CHAR) SEPARATOR ','), '') AS counts
		FROM (
		select a.number as count from ccpm_reimbursement_amount_info a
		left join ccpm_reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number in
			<foreach collection="invoiceNumber" item="number" index="index" open="(" close=")" separator=",">
				#{number}
			</foreach>
			and a.del_flag = 0
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5') and a.info_id != #{id}
		</where>
		union all
		select a.number as count from reimbursement_amount_info a
		left join reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number in
			<foreach collection="invoiceNumber" item="number" index="index" open="(" close=")" separator=",">
				#{number}
			</foreach>
			and a.del_flag = 0
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5') and a.info_id != #{id}
		</where>
		union all
		select a.number as count from cw_reimbursement_amount_info a
		left join cw_reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number in
			<foreach collection="invoiceNumber" item="number" index="index" open="(" close=")" separator=",">
				#{number}
			</foreach>
			and a.del_flag = 0
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5') and a.info_id != #{id}
		</where>
		union all
		select a.number as count from zs_reimbursement_amount_info a
		left join zs_reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number in
			<foreach collection="invoiceNumber" item="number" index="index" open="(" close=")" separator=",">
				#{number}
			</foreach>
			and a.del_flag = 0
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5') and a.info_id != #{id}
		</where>
		union all
		select a.number as count from consultancy_reimbursement_amount_info a
		left join consultancy_reimbursement_info ri on ri.id = a.info_id
		<where>
			a.number in
			<foreach collection="invoiceNumber" item="number" index="index" open="(" close=")" separator=",">
				#{number}
			</foreach>
			and a.del_flag = 0
			and ri.del_flag = 0
			and (ri.type = '2' or ri.type = '5') and a.info_id != #{id}
		</where>
		)AS result;

	</select>

	<select id="getInvoiceReimbursementAmountList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.ReimbursementAmountInfoDTO">
		select
		a.id,
		a.create_by_id,
		a.create_time,
		a.update_by_id,
		a.update_time,
		a.del_flag,
		a.info_id,
		a.code,
		a.number,
		a.amount,
		a.tax_amount,
		a.count,
		a.tenant_id,
		a.reimbursement_type,
		a.invoice_type,
		a.invoice_project_name,
		date_format(a.invoice_date,'%Y-%m-%d %h:%i:%s') as 'invoiceDate',
		a.invoice_date,
		a.invoice_unit,
		a.buyer_name,
		a.remarks,
		ri.type as "status",
		date_format(ri.reim_date,'%Y-%m-%d') as 'reimDate',
		su.name as "reimbursementApplicantName",
		so.name as "officeName",
		sdv.label as "invoiceTypeStr"
		from
		reimbursement_amount_info a
		left join reimbursement_info ri on ri.id = a.info_id
		left join sys_user su on su.id = ri.create_by_id
		left join sys_office so on so.id = su.office_id
		left join sys_dict_value sdv on sdv.value = a.invoice_type
		left join sys_dict_type sdt on sdt.id = sdv.dict_type_id and sdt.type = 'invoice_reimbursement_type'
		<where>
			a.del_flag = 0
			and a.info_id in
			<foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
				#{id}
			</foreach>
		</where>
	</select>
	<select id="findOfficeListByIdList" resultType="com.jeeplus.assess.reimbursement.reimbursementInfo.service.dto.TreeUserDto">
		SELECT id,`name`,parent_id FROM sys_office
		<where>
			del_flag = 0
			and id in
			<foreach collection="idList" item="id" index="index" open="(" close=")" separator=",">
				#{id}
			</foreach>
		</where>
	</select>

	<update id="updatePaymentById">
		update
			reimbursement_info
		set payment_status = #{paymentStatus},
		payment_time = case
			when #{paymentStatus} = '1' then NOW()
			else null end
		where id = #{id}
	</update>


	<delete id="deleteByIdAndNumber">
		delete from reimbursement_amount_info
		<where>
			number = #{invoiceNumber}
			and info_id = #{id}
		</where>
	</delete>

	<select id="findReimFiles" resultType="com.jeeplus.sys.domain.WorkAttachmentInfo">
		SELECT
			id,
			url,
			type,
			file_size as `fileSize`,
			attachment_name AS `name`,
			create_by_id AS `by`,
			attachment_flag AS `attachmentFlag`,
			attachment_id AS `attachmentId`,
			create_time
		FROM
			work_attachment
		WHERE
			del_flag = 0
			AND attachment_id = #{infoId} and attachment_flag = #{attachmentFlag}
	</select>

</mapper>
