<?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.yifu.cloud.plus.v1.yifu.insurances.mapper.insurances.TInsuranceDetailMapper">

    <resultMap id="BaseResultMap" type="com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceDetail">
            <id property="id" column="ID" jdbcType="VARCHAR"/>
            <result property="empName" column="EMP_NAME" jdbcType="VARCHAR"/>
            <result property="empIdcardNo" column="EMP_IDCARD_NO" jdbcType="VARCHAR"/>
            <result property="deptNo" column="DEPT_NO" jdbcType="VARCHAR"/>
            <result property="post" column="POST" jdbcType="VARCHAR"/>
            <result property="insuranceCompanyName" column="INSURANCE_COMPANY_NAME" jdbcType="VARCHAR"/>
            <result property="insuranceTypeName" column="INSURANCE_TYPE_NAME" jdbcType="VARCHAR"/>
            <result property="insuranceTypeId" column="INSURANCE_TYPE_ID" jdbcType="BIGINT"/>
            <result property="buyStandard" column="BUY_STANDARD" jdbcType="VARCHAR"/>
            <result property="rate" column="RATE" jdbcType="DECIMAL"/>
            <result property="billingType" column="BILLING_TYPE" jdbcType="TINYINT"/>
            <result property="medicalQuota" column="MEDICAL_QUOTA" jdbcType="VARCHAR"/>
            <result property="dieDisableQuota" column="DIE_DISABLE_QUOTA" jdbcType="VARCHAR"/>
            <result property="policyNo" column="POLICY_NO" jdbcType="VARCHAR"/>
            <result property="policyStart" column="POLICY_START" jdbcType="DATE"/>
            <result property="policyEnd" column="POLICY_END" jdbcType="DATE"/>
            <result property="policyEffect" column="POLICY_EFFECT" jdbcType="DATE"/>
            <result property="batchDate" column="BATCH_DATE" jdbcType="TIMESTAMP"/>
			<result property="settleMonth" column="SETTLE_MONTH" jdbcType="VARCHAR"/>
            <result property="invoiceNo" column="INVOICE_NO" jdbcType="VARCHAR"/>
            <result property="buyType" column="BUY_TYPE" jdbcType="TINYINT"/>
            <result property="insuranceProvince" column="INSURANCE_PROVINCE" jdbcType="TINYINT"/>
            <result property="insuranceProvinceName" column="INSURANCE_PROVINCE_NAME" jdbcType="VARCHAR"/>
            <result property="insuranceCity" column="INSURANCE_CITY" jdbcType="TINYINT"/>
            <result property="insuranceCityName" column="INSURANCE_CITY_NAME" jdbcType="VARCHAR"/>
            <result property="insuranceHandleProvince" column="INSURANCE_HANDLE_PROVINCE" jdbcType="TINYINT"/>
            <result property="insuranceHandleProvinceName" column="INSURANCE_HANDLE_PROVINCE_NAME" jdbcType="VARCHAR"/>
            <result property="insuranceHandleCity" column="INSURANCE_HANDLE_CITY" jdbcType="TINYINT"/>
            <result property="insuranceHandleCityName" column="INSURANCE_HANDLE_CITY_NAME" jdbcType="VARCHAR"/>
            <result property="settleType" column="SETTLE_TYPE" jdbcType="TINYINT"/>
            <result property="actualPremium" column="ACTUAL_PREMIUM" jdbcType="DECIMAL"/>
            <result property="estimatePremium" column="ESTIMATE_PREMIUM" jdbcType="DECIMAL"/>
            <result property="signFlag" column="SIGN_FLAG" jdbcType="TINYINT"/>
            <result property="buyHandleStatus" column="BUY_HANDLE_STATUS" jdbcType="TINYINT"/>
            <result property="defaultSettleId" column="DEFAULT_SETTLE_ID" jdbcType="VARCHAR"/>
            <result property="reduceHandleStatus" column="REDUCE_HANDLE_STATUS" jdbcType="TINYINT"/>
            <result property="isUse" column="IS_USE" jdbcType="TINYINT"/>
            <result property="isEffect" column="IS_EFFECT" jdbcType="TINYINT"/>
            <result property="isOverdue" column="IS_OVERDUE" jdbcType="TINYINT"/>
            <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
            <result property="createBy" column="CREATE_BY" jdbcType="VARCHAR"/>
            <result property="createName" column="CREATE_NAME" jdbcType="VARCHAR"/>
            <result property="createTime" column="CREATE_TIME" jdbcType="TIMESTAMP"/>
            <result property="updateBy" column="UPDATE_BY" jdbcType="VARCHAR"/>
            <result property="updateTime" column="UPDATE_TIME" jdbcType="TIMESTAMP"/>
            <result property="deleteFlag" column="DELETE_FLAG" jdbcType="TINYINT"/>
			<result property="handledBy" column="HANDLED_BY" jdbcType="VARCHAR"/>
			<result property="handledTime" column="HANDLED_TIME" jdbcType="TIMESTAMP"/>
	</resultMap>

    <sql id="Base_Column_List">
        ID,EMP_NAME,
        EMP_IDCARD_NO,DEPT_NO,POST,INSURANCE_COMPANY_NAME,INSURANCE_TYPE_NAME,
        INSURANCE_TYPE_ID,BUY_STANDARD,RATE,BILLING_TYPE,MEDICAL_QUOTA,DIE_DISABLE_QUOTA,POLICY_NO,
        POLICY_START,POLICY_END,POLICY_EFFECT,
        BATCH_DATE,SETTLE_MONTH,INVOICE_NO,
        BUY_TYPE,INSURANCE_PROVINCE,INSURANCE_PROVINCE_NAME,INSURANCE_CITY,INSURANCE_CITY_NAME,
        INSURANCE_HANDLE_PROVINCE,INSURANCE_HANDLE_PROVINCE_NAME,INSURANCE_HANDLE_CITY,INSURANCE_HANDLE_CITY_NAME,SETTLE_TYPE,
        ACTUAL_PREMIUM,ESTIMATE_PREMIUM,SIGN_FLAG,
        BUY_HANDLE_STATUS,DEFAULT_SETTLE_ID,REDUCE_HANDLE_STATUS,
        IS_USE,IS_EFFECT,IS_OVERDUE,REMARK,
        CREATE_BY,CREATE_NAME,CREATE_TIME,
        UPDATE_BY,UPDATE_TIME,DELETE_FLAG,DEFAULT_SETTLE_ID,HANDLED_BY,HANDLED_TIME
	</sql>
	<!--投保分页查询-->
	<select id="getInsuranceListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO">
		select detail.id as id,
		detail.EMP_NAME as empName,
		detail.EMP_IDCARD_NO as empIdcardNo,
		detail.BUY_TYPE as buyType,
		detail.POST as post,
		detail.DEPT_NO as deptNo,
		detail.POLICY_START as policyStart,
		detail.POLICY_END as policyEnd,
		detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		detail.INSURANCE_TYPE_NAME as insuranceTypeName,
	    detail.BUY_STANDARD as buyStandard,
		detail.CREATE_BY as createBy,
		detail.CREATE_NAME as createName,
		detail.BUY_HANDLE_STATUS as buyHandleStatus,
		detail.SETTLE_TYPE as settleType,
		detail.SETTLE_MONTH as settleMonth
		from t_insurance_detail detail
		where detail.DELETE_FLAG = 0
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.deptNo == null or param.deptNo.trim() == ''">
			and detail.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.buyHandleStatus != null">
			and detail.BUY_HANDLE_STATUS = #{param.buyHandleStatus}
		</if>
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and detail.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyHandleStatusList != null and param.buyHandleStatusList.size > 0">
			and detail.BUY_HANDLE_STATUS in
			<foreach collection="param.buyHandleStatusList" index="index" item="item" open="(" separator="," close=")">
				 #{item}
			</foreach>
		</if>
		<if test="param.buyType != null">
			and detail.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and detail.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.startDate != null and param.startDate.trim() != '' and param.endDate != null and param.endDate.trim() != ''">
			and detail.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and detail.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		ORDER BY detail.BUY_HANDLE_STATUS,detail.CREATE_TIME DESC
	</select>

	<!--投保不分页查询-->
	<select id="getInsuranceList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO">
		select detail.id as id,
		detail.EMP_NAME as empName,
		detail.EMP_IDCARD_NO as empIdcardNo,
		detail.BUY_TYPE as buyType,
		detail.POST as post,
		detail.DEPT_NO as deptNo,
		detail.POLICY_START as policyStart,
		detail.POLICY_END as policyEnd,
		detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		detail.INSURANCE_TYPE_NAME as insuranceTypeName,
		detail.BUY_STANDARD as buyStandard,
		detail.CREATE_BY as createBy,
		detail.CREATE_NAME as createName,
		detail.BUY_HANDLE_STATUS as buyHandleStatus,
		detail.SETTLE_TYPE as settleType,
		detail.SETTLE_MONTH as settleMonth
		from t_insurance_detail detail
		where detail.DELETE_FLAG = 0
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.deptNo == null or param.deptNo.trim() == ''">
			and detail.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.buyHandleStatus != null">
			and detail.BUY_HANDLE_STATUS = #{param.buyHandleStatus}
		</if>
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and detail.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyHandleStatusList != null and param.buyHandleStatusList.size > 0">
			and detail.BUY_HANDLE_STATUS in
			<foreach collection="param.buyHandleStatusList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.buyType != null">
			and detail.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and detail.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.startDate != null and param.startDate.trim() != '' and param.endDate != null and param.endDate.trim() != ''">
			and detail.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and detail.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		ORDER BY detail.BUY_HANDLE_STATUS,detail.CREATE_TIME DESC
	</select>

	<!--投保办理分页查询-->
	<select id="getInsuranceHandleListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO">
		select detail.id as id,
		detail.EMP_NAME as empName,
		detail.EMP_IDCARD_NO as empIdcardNo,
		detail.BUY_TYPE as buyType,
		detail.POST as post,
		detail.DEPT_NO as deptNo,
		detail.POLICY_START as policyStart,
		detail.POLICY_END as policyEnd,
		detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		detail.INSURANCE_TYPE_NAME as insuranceTypeName,
		detail.BUY_STANDARD as buyStandard,
		detail.CREATE_NAME as createName,
		detail.BUY_HANDLE_STATUS as buyHandleStatus,
		detail.SETTLE_TYPE as settleType,
		detail.SETTLE_MONTH as settleMonth
		from t_insurance_detail detail
		where detail.DELETE_FLAG = 0
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.buyHandleStatus != null">
			and detail.BUY_HANDLE_STATUS = #{param.buyHandleStatus}
		</if>
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and detail.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyHandleStatusList != null and param.buyHandleStatusList.size > 0">
			and detail.BUY_HANDLE_STATUS in
			<foreach collection="param.buyHandleStatusList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.regionSql != null and param.regionSql.trim() != ''">
			and  ${param.regionSql}
		</if>
		<if test="param.updateBy != null and param.updateBy.trim() != ''">
			and detail.HANDLED_BY = #{param.updateBy}
		</if>
		<if test="param.buyType != null">
			and detail.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and detail.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.startDate != null and param.startDate.trim() != '' and param.endDate != null and param.endDate.trim() != ''">
			and detail.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and detail.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		ORDER BY detail.BUY_HANDLE_STATUS,detail.CREATE_TIME DESC
	</select>

	<select id="getInsuranceDetailById" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceDetailVO">
		select
		detail.id as id,
		detail.EMP_NAME as empName,
		detail.EMP_IDCARD_NO as empIdcardNo,
		detail.BUY_TYPE as buyType,
		detail.DEPT_NO as deptNo,
		detail.POST as post,
		detail.POLICY_START as policyStart,
		detail.POLICY_END as policyEnd,
		detail.POLICY_EFFECT as policyEffect,
		detail.POLICY_NO as policyNo,
		detail.INSURANCE_TYPE_NAME as insuranceTypeName,
		detail.INSURANCE_TYPE_ID as insuranceTypeId,
		detail.BUY_STANDARD as buyStandard,
		detail.MEDICAL_QUOTA as medicalQuota,
		detail.DIE_DISABLE_QUOTA as dieDisableQuota,
		detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		detail.SETTLE_TYPE as premiumType,
		detail.ESTIMATE_PREMIUM as estimatePremium,
		detail.ACTUAL_PREMIUM as actualPremium,
		detail.INVOICE_NO as invoiceNo,
		detail.SETTLE_TYPE as settleType,
		detail.SETTLE_MONTH as settleMonth,
		detail.BUY_HANDLE_STATUS as buyHandleStatus,
		detail.REDUCE_HANDLE_STATUS as reduceHandleStatus,
		tis.SETTLE_HANDLE_STATUS as settleHandleStatus,
		detail.IS_USE as isUse,
		detail.IS_EFFECT as isEffect,
		detail.IS_OVERDUE as isOverdue,
		detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
		detail.INSURANCE_PROVINCE as insuranceProvince,
		detail.INSURANCE_CITY_NAME as insuranceCityName,
		detail.INSURANCE_CITY as insuranceCity,
		detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
		detail.INSURANCE_HANDLE_PROVINCE as insuranceHandleProvince,
		detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
		detail.INSURANCE_HANDLE_CITY as insuranceHandleCity,
		detail.CREATE_NAME as createName,
		detail.CREATE_TIME as createTime,
		detail.REMARK as remark,
		detail.BILLING_TYPE as billingType,
		detail.RATE as  rate
		from t_insurance_detail detail
		left join t_insurance_settle tis on detail.DEFAULT_SETTLE_ID = tis.ID
		where detail.ID = #{id}
	</select>
	<!-- 导出办理勾选查询结果-->
	<select id="getInsuranceExportListBySelect" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceExportListVO">
		select detail.id as id,
		detail.DEPT_NO as deptNo,
		detail.EMP_NAME as empName,
		detail.EMP_IDCARD_NO as empIdcardNo,
		detail.BUY_TYPE as buyType,
		detail.BUY_HANDLE_STATUS as buyHandleStatus,
		detail.POST as post,
		detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
		detail.INSURANCE_CITY_NAME as insuranceCityName,
		detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
		detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
		detail.POLICY_START as policyStart,
		detail.POLICY_END as policyEnd,
		detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		detail.INSURANCE_TYPE_NAME as insuranceTypeName,
		detail.BUY_STANDARD as buyStandard,
		detail.MEDICAL_QUOTA as medicalQuota,
		detail.DIE_DISABLE_QUOTA as dieDisableQuota,
		detail.SETTLE_MONTH as settleMonth,
		detail.SETTLE_TYPE as settleType,
		detail.CREATE_NAME as createName,
		detail.POLICY_NO as policyNo,
		detail.REMARK as remark
		from t_insurance_detail detail
		where detail.DELETE_FLAG = 0 and detail.id in
		<foreach collection="idList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
		ORDER BY detail.CREATE_TIME DESC
	</select>
	<!--出办理非勾选查询结果-->
	<select id="getInsuranceExportList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceExportListVO">
		select detail.id as id,
			detail.DEPT_NO as deptNo,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.BUY_TYPE as buyType,
			detail.POST as post,
			detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			detail.INSURANCE_CITY_NAME as insuranceCityName,
			detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.INSURANCE_TYPE_NAME as insuranceTypeName,
			detail.BUY_STANDARD as buyStandard,
			detail.MEDICAL_QUOTA as medicalQuota,
			detail.DIE_DISABLE_QUOTA as dieDisableQuota,
			detail.SETTLE_MONTH as settleMonth,
			detail.SETTLE_TYPE as settleType,
			detail.CREATE_NAME as createName,
			detail.POLICY_NO as policyNo,
			detail.REMARK as remark
		from t_insurance_detail detail
		where detail.DELETE_FLAG = 0 and detail.BUY_HANDLE_STATUS = 1
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO like concat('%',replace(replace(#{param.deptNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME like concat('%',replace(replace(#{param.insuranceCompanyName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.regionSql != null and param.regionSql.trim() != ''">
			and  ${param.regionSql}
		</if>
		<if test="param.buyType != null">
			and detail.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and detail.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.startDate != null and param.startDate.trim() != '' and param.endDate != null and param.endDate.trim() != ''">
			and detail.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and detail.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		ORDER BY detail.CREATE_TIME DESC
	</select>

	<update id="updatePolicyNoBatch">
		<foreach collection="details" index="index" item="item" separator=";">
				update t_insurance_detail set POLICY_NO = #{item.policyNo} where ID = #{item.id}
		</foreach>
	</update>

	<!-- ***********************减员办理******************************** -->
	<!-- 已投保列表分页查询-->
	<select id="getInsuredListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuredListVo">
		select
			detail.id as id,
			detail.REDUCE_HANDLE_STATUS as reduceHandleStatus,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.BUY_TYPE as buyType,
			detail.DEPT_NO as deptNo,
			detail.POST as post,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.POLICY_EFFECT as policyEffect,
			detail.IS_USE as isUse,
			detail.IS_EFFECT as isEffect,
			detail.IS_OVERDUE as isOverdue,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.INSURANCE_TYPE_NAME as insuranceTypeName,
			detail.BUY_STANDARD as buyStandard
		from
		     t_insurance_detail detail
		where
			detail.DELETE_FLAG = 0
		and
			detail.BUY_HANDLE_STATUS = 3
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.deptNo == null or param.deptNo.trim() == ''">
			and detail.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and detail.POLICY_NO like concat('%',replace(replace(#{param.policyNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd == null and param.policyEnd.trim() == ''">
			AND detail.POLICY_END   <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00')
		</if>
		<if test="param.policyEnd != null and param.policyEnd.trim() != '' and param.policyStart == null and param.policyStart.trim() == ''">
			AND detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd != null and param.policyEnd.trim() != ''">
			and (
			(detail.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
				)
		</if>
		<if test="param.invoiceNo != null and param.invoiceNo.trim() != ''">
			and detail.INVOICE_NO like concat('%',replace(replace(#{param.invoiceNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.isUse != null">
			and detail.IS_USE = #{param.isUse}
		</if>
		<if test="param.isOverdue != null">
			and detail.IS_OVERDUE = #{param.isOverdue}
		</if>
		<if test="param.createStartTime != null and param.createStartTime.trim() != ''">
			AND detail.CREATE_TIME  <![CDATA[ >= ]]>  concat(#{param.createStartTime}, ' 00:00:00')
		</if>
		<if test="param.createEndTime != null and param.createEndTime.trim() != ''">
			AND detail.CREATE_TIME  <![CDATA[ <= ]]> concat(#{param.createEndTime}, ' 23:59:59')
		</if>
		ORDER BY detail.CREATE_TIME DESC ,detail.ID ASC
	</select>
	<!-- 已投保列表不分页查询-->
	<select id="getInsuredList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuredListVo">
		select
			detail.id as id,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.BUY_TYPE as buyType,
			detail.DEPT_NO as deptNo,
			detail.POST as post,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.INSURANCE_TYPE_NAME as insuranceTypeName,
			detail.BUY_STANDARD as buyStandard,
			detail.MEDICAL_QUOTA as medicalQuota,
			detail.DIE_DISABLE_QUOTA as dieDisableQuota,
			detail.ESTIMATE_PREMIUM as estimatePremium,
			detail.ACTUAL_PREMIUM as actualPremium,
			detail.POLICY_NO as policyNo,
			detail.INVOICE_NO as invoiceNo,
			detail.POLICY_EFFECT as policyEffect,
			detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			detail.INSURANCE_CITY_NAME as insuranceCityName,
			detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			detail.IS_USE as isUse,
			detail.IS_EFFECT as isEffect,
			detail.IS_OVERDUE as isOverdue,
			detail.CREATE_TIME as createTime,
			detail.CREATE_NAME as createName
		from
		    t_insurance_detail detail
		where
		    detail.DELETE_FLAG = 0
		and
			detail.BUY_HANDLE_STATUS = 3
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.deptNo == null or param.deptNo.trim() == ''">
			and detail.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and detail.POLICY_NO like concat('%',replace(replace(#{param.policyNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd == null and param.policyEnd.trim() == ''">
			AND detail.POLICY_END   <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00')
		</if>
		<if test="param.policyEnd != null and param.policyEnd.trim() != '' and param.policyStart == null and param.policyStart.trim() == ''">
			AND detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd != null and param.policyEnd.trim() != ''">
			and (
			(detail.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
			)
		</if>
		<if test="param.invoiceNo != null and param.invoiceNo.trim() != ''">
			and detail.INVOICE_NO like concat('%',replace(replace(#{param.invoiceNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.isUse != null">
			and detail.IS_USE = #{param.isUse}
		</if>
		<if test="param.isOverdue != null ">
			and detail.IS_OVERDUE = #{param.isOverdue}
		</if>
		<if test="param.createStartTime != null and param.createStartTime.trim() != ''">
			AND detail.CREATE_TIME  <![CDATA[ >= ]]>  concat(#{param.createStartTime}, ' 00:00:00')
		</if>
		<if test="param.createEndTime != null and param.createEndTime.trim() != ''">
			AND detail.CREATE_TIME  <![CDATA[ <= ]]> concat(#{param.createEndTime}, ' 23:59:59')
		</if>
		ORDER BY detail.CREATE_TIME DESC
	</select>
	<!-- 已减员列表分页查询-->
	<select id="getInsuranceRefundPageList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceRefundListVo">
		select
		    detail.id as id,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.POST as post,
			detail.DEPT_NO as deptNo,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.POLICY_NO as policyNo,
			refund.CREATE_TIME as refundCreateTime
		from
			t_insurance_detail detail,
			t_insurance_refund refund
		where
		    detail.DELETE_FLAG = 0
		and
			detail.ID = refund.INS_DETAIL_ID
		and
			detail.REDUCE_HANDLE_STATUS = 4
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.deptNo == null or param.deptNo.trim() == ''">
			and detail.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and detail.POLICY_NO like concat('%',replace(replace(#{param.policyNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd == null and param.policyEnd.trim() == ''">
			AND detail.POLICY_END   <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00')
		</if>
		<if test="param.policyEnd != null and param.policyEnd.trim() != '' and param.policyStart == null and param.policyStart.trim() == ''">
			AND detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd != null and param.policyEnd.trim() != ''">
			and (
			(detail.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
			)
		</if>
		ORDER BY refund.CREATE_TIME DESC,detail.ID ASC
	</select>
	<!-- 已减员列表不分页查询-->
	<select id="getInsuranceRefundList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceRefundListVo">
		select
			detail.id as id,
			detail.DEPT_NO as deptNo,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.BUY_TYPE as buyType,
			detail.POST as post,
			detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			detail.INSURANCE_CITY_NAME as insuranceCityName,
			detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.INSURANCE_TYPE_NAME as insuranceTypeName,
			detail.BUY_STANDARD as buyStandard,
			detail.MEDICAL_QUOTA as medicalQuota,
			detail.DIE_DISABLE_QUOTA as dieDisableQuota,
			refund.CREATE_TIME as refundCreateTime
		from
			t_insurance_detail detail,
			t_insurance_refund refund
		where
			detail.ID = refund.INS_DETAIL_ID
		and
			detail.DELETE_FLAG = 0
		and
			detail.REDUCE_HANDLE_STATUS = 4
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.deptNo == null or param.deptNo.trim() == ''">
			and detail.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and detail.POLICY_NO like concat('%',replace(replace(#{param.policyNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd == null and param.policyEnd.trim() == ''">
			AND detail.POLICY_END   <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00')
		</if>
		<if test="param.policyEnd != null and param.policyEnd.trim() != '' and param.policyStart == null and param.policyStart.trim() == ''">
			AND detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')
		</if>
		<if test="param.policyStart != null and param.policyStart.trim() != '' and param.policyEnd != null and param.policyEnd.trim() != ''">
			and (
			(detail.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(detail.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and detail.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
			)
		</if>
		ORDER BY refund.CREATE_TIME DESC
	</select>
	<!-- 减员办理列表分页查询-->
	<select id="getInsuranceRefundHandlingPageList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.RefundExportListVo">
		select
		DISTINCT
		detail.id as id,
		detail.EMP_NAME as empName,
		detail.EMP_IDCARD_NO as empIdcardNo,
		detail.BUY_TYPE as buyType,
		detail.DEPT_NO as deptNo,
		detail.POST as post,
		detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
		detail.INSURANCE_CITY_NAME as insuranceCityName,
		detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
		detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
		detail.POLICY_START as policyStart,
		detail.POLICY_END as policyEnd,
		detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		detail.INSURANCE_TYPE_NAME as insuranceTypeName,
		detail.BUY_STANDARD as buyStandard,
		detail.MEDICAL_QUOTA as medicalQuota,
		detail.DIE_DISABLE_QUOTA as dieDisableQuota,
		refund.CREATE_NAME as createName,
		detail.REDUCE_HANDLE_STATUS as reduceHandleStatus
		from
			t_insurance_detail detail,
			t_insurance_refund refund
		where
			detail.ID = refund.INS_DETAIL_ID
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.reduceHandleStatus != null">
			and detail.REDUCE_HANDLE_STATUS = #{param.reduceHandleStatus}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and detail.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.regionSql != null and param.regionSql.trim() != ''">
			and  ${param.regionSql}
		</if>
		<if test="param.updateBy != null and param.updateBy.trim() != ''">
			and  refund.UPDATE_BY = #{param.updateBy}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and refund.CREATE_NAME like concat('%',replace(replace(#{param.createName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.startDate != null and param.startDate.trim() != ''">
			AND refund.CREATE_TIME   <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00')
		</if>
		<if test="param.endDate != null and param.endDate.trim() != ''">
			AND refund.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		ORDER BY refund.CREATE_TIME DESC,detail.ID ASC
	</select>
	<!-- 查询保单列表-->
	<select id="selectDetailListByIds"
			resultType="com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceDetail">
		select
			<include refid="Base_Column_List"></include>
		from
				t_insurance_detail
		where
			ID in
			<foreach collection="param.idList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
	</select>
	<!-- 查询保单减员退费信息-->
	<select id="selectRefundDetail" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.TInsuranceRefundDetail">
		select
			detail.DEPT_NO as deptNo,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			refund.ID as id,
			refund.INS_DETAIL_ID as insDetailId,
			refund.REFUND_MONEY as refundMoney
		from
			t_insurance_detail detail,
			t_insurance_refund refund
		where
			detail.DELETE_FLAG = 0
		and
			detail.ID = refund.INS_DETAIL_ID
		and
			detail.BUY_HANDLE_STATUS = 5
		and
			detail.REDUCE_HANDLE_STATUS = 4
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME = #{param.empName}
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO = #{param.empIdcardNo}
		</if>
		<if test="param.policyNo!= null and param.policyNo.trim() != ''">
			and detail.POLICY_NO = #{param.policyNo}
		</if>
	</select>
	<!-- 根据ID导出减员办理列表-->
	<select id="getRefundExportListBySelect" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.RefundExportListVo">
		select
			detail.id as id,
			detail.DEPT_NO as deptNo,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.BUY_TYPE as buyType,
			detail.POST as post,
			detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			detail.INSURANCE_CITY_NAME as insuranceCityName,
			detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.INSURANCE_TYPE_NAME as insuranceTypeName,
			detail.BUY_STANDARD as buyStandard,
			detail.MEDICAL_QUOTA as medicalQuota,
			detail.DIE_DISABLE_QUOTA as dieDisableQuota,
			detail.SETTLE_MONTH as settleMonth,
			detail.SETTLE_TYPE as settleType,
			detail.CREATE_NAME as createName,
			detail.REDUCE_HANDLE_STATUS as reduceHandleStatus,
			detail.REMARK as remark
		from
		    t_insurance_detail detail
		where
		    detail.id in
		<foreach collection="idList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
		ORDER BY detail.CREATE_TIME DESC
	</select>
	<!-- 根据查询参数导出减员办理列表-->
	<select id="getRefundExportList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.RefundExportListVo">
		select
		    detail.id as id,
			detail.DEPT_NO as deptNo,
			detail.EMP_NAME as empName,
			detail.EMP_IDCARD_NO as empIdcardNo,
			detail.BUY_TYPE as buyType,
			detail.POST as post,
			detail.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			detail.INSURANCE_CITY_NAME as insuranceCityName,
			detail.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			detail.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			detail.POLICY_START as policyStart,
			detail.POLICY_END as policyEnd,
			detail.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			detail.INSURANCE_TYPE_NAME as insuranceTypeName,
			detail.BUY_STANDARD as buyStandard,
			detail.MEDICAL_QUOTA as medicalQuota,
			detail.DIE_DISABLE_QUOTA as dieDisableQuota,
			detail.SETTLE_MONTH as settleMonth,
			detail.SETTLE_TYPE as settleType,
			detail.CREATE_NAME as createName,
			detail.REMARK as remark
		from
			t_insurance_detail detail
		where
		    detail.DELETE_FLAG = 0 and detail.REDUCE_HANDLE_STATUS = 1
		<if test="param.empName != null and param.empName.trim() != ''">
			and detail.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and detail.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and detail.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and detail.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and detail.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.regionSql != null and param.regionSql.trim() != ''">
			and  ${param.regionSql}
		</if>
		ORDER BY detail.CREATE_TIME DESC
	</select>
	<!-- 减员办理-->
	<update id="updateInsuranceRefund">
		update
			t_insurance_detail detail
		set
			UPDATE_BY = #{param.updateBy},
			REDUCE_HANDLE_STATUS = #{param.refundType},
			UPDATE_TIME = #{param.refundCreateTime}
		where
		      detail.ID in
		<foreach collection="param.idList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
	</update>
	<!--根据身份证查询商险信息-->
	<select id="getInsuranceListByIdCard" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListByIdCardVo">
		SELECT
		<include refid="Base_Column_List"/>
		FROM t_insurance_detail
		<where>
			1=1
			AND EMP_IDCARD_NO = #{idCard}
			and DEPT_NO = #{deptNo}
		</where>
		ORDER BY CREATE_TIME desc
	</select>
    <select id="selectListByempIdcardNo" resultType="com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceDetail">
		SELECT
			<include refid="Base_Column_List"/>
		FROM
		  t_insurance_detail
		<where>
		    EMP_IDCARD_NO = #{empIdcardNo}
			AND IS_EFFECT = 0
			AND IS_USE =0
			and IS_OVERDUE = 0
			and DELETE_FLAG = 0
			and BUY_HANDLE_STATUS =3
			and (REDUCE_HANDLE_STATUS is null or REDUCE_HANDLE_STATUS = 3)
		</where>
		ORDER BY CREATE_TIME desc
	</select>
	<select id="selectByregionSQL" resultType="com.yifu.cloud.plus.v1.yifu.insurances.entity.TInsuranceDetail">
		SELECT
		<include refid="Base_Column_List"/>
		FROM
		t_insurance_detail detail
		<where>
			detail.ID = #{id}
			<if test="regionSql != null and regionSql.trim() != ''">
				and  ${regionSql}
			</if>
		</where>
		ORDER BY CREATE_TIME desc
	</select>
</mapper>
