<?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"/>
			<result property="orderNo" column="ORDER_NO" jdbcType="VARCHAR"/>
			<result property="createUserDeptId" column="CREATE_USER_DEPT_ID" jdbcType="VARCHAR"/>
			<result property="createUserDeptName" column="CREATE_USER_DEPT_NAME" jdbcType="VARCHAR"/>
			<result property="deptId" column="DEPT_ID" jdbcType="VARCHAR"/>
			<result property="bpoFlag" column="BPO_FLAG" jdbcType="VARCHAR"/>
	</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,BPO_FLAG,
        UPDATE_BY,UPDATE_TIME,DELETE_FLAG,DEFAULT_SETTLE_ID,HANDLED_BY,HANDLED_TIME,ORDER_NO,CREATE_USER_DEPT_ID,CREATE_USER_DEPT_NAME

	</sql>
	<!--投保分页查询-->
	<select id="getInsuranceListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO">
		select a.id as id,
		a.EMP_NAME as empName,
		a.EMP_IDCARD_NO as empIdcardNo,
		a.BUY_TYPE as buyType,
		a.POST as post,
		a.DEPT_NO as deptNo,
		a.POLICY_START as policyStart,
		a.POLICY_END as policyEnd,
		a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		a.INSURANCE_TYPE_NAME as insuranceTypeName,
	    a.BUY_STANDARD as buyStandard,
		a.CREATE_BY as createBy,
		a.CREATE_NAME as createName,
		a.BUY_HANDLE_STATUS as buyHandleStatus,
		a.SETTLE_TYPE as settleType,
		a.CREATE_USER_DEPT_NAME as createUserDeptName,
		a.SETTLE_MONTH as settleMonth
		from t_insurance_detail a
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where a.DELETE_FLAG = 0
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.orderNo != null and param.orderNo.trim() != ''">
			and a.DEPT_NO = #{param.orderNo}
		</if>
		<if test="param.buyHandleStatus != null">
			and a.BUY_HANDLE_STATUS = #{param.buyHandleStatus}
		</if>
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and a.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyHandleStatusList != null and param.buyHandleStatusList.size > 0">
			and a.BUY_HANDLE_STATUS in
			<foreach collection="param.buyHandleStatusList" index="index" item="item" open="(" separator="," close=")">
				 #{item}
			</foreach>
		</if>
		<if test="param.buyType != null">
			and a.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and a.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 a.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and a.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.BUY_HANDLE_STATUS,a.CREATE_TIME DESC
	</select>
	<!--投保不分页查询-->
	<select id="getInsuranceList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO">
		select a.id as id,
		a.EMP_NAME as empName,
		a.EMP_IDCARD_NO as empIdcardNo,
		a.BUY_TYPE as buyType,
		a.POST as post,
		a.DEPT_NO as deptNo,
		a.POLICY_START as policyStart,
		a.POLICY_END as policyEnd,
		a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		a.INSURANCE_TYPE_NAME as insuranceTypeName,
		a.BUY_STANDARD as buyStandard,
		a.CREATE_BY as createBy,
		a.CREATE_NAME as createName,
		a.BUY_HANDLE_STATUS as buyHandleStatus,
		a.SETTLE_TYPE as settleType,
		a.SETTLE_MONTH as settleMonth
		from t_insurance_detail a
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where a.DELETE_FLAG = 0
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.buyHandleStatus != null">
			and a.BUY_HANDLE_STATUS = #{param.buyHandleStatus}
		</if>
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and a.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyHandleStatusList != null and param.buyHandleStatusList.size > 0">
			and a.BUY_HANDLE_STATUS in
			<foreach collection="param.buyHandleStatusList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.buyType != null">
			and a.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and a.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 a.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and a.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.BUY_HANDLE_STATUS,a.CREATE_TIME DESC
	</select>
	<!--投保办理分页查询-->
	<select id="getInsuranceHandleListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceListVO">
		select a.id as id,
		a.EMP_NAME as empName,
		a.EMP_IDCARD_NO as empIdcardNo,
		a.BUY_TYPE as buyType,
		a.POST as post,
		a.DEPT_NO as deptNo,
		a.POLICY_START as policyStart,
		a.POLICY_END as policyEnd,
		a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		a.INSURANCE_TYPE_NAME as insuranceTypeName,
		a.BUY_STANDARD as buyStandard,
		a.CREATE_NAME as createName,
		a.BUY_HANDLE_STATUS as buyHandleStatus,
		a.SETTLE_TYPE as settleType,
		a.SETTLE_MONTH as settleMonth
		from t_insurance_detail a
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where a.DELETE_FLAG = 0
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.buyHandleStatus != null">
			and a.BUY_HANDLE_STATUS = #{param.buyHandleStatus}
		</if>
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and a.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyHandleStatusList != null and param.buyHandleStatusList.size > 0">
			and a.BUY_HANDLE_STATUS in
			<foreach collection="param.buyHandleStatusList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>
		<if test="param.updateBy != null and param.updateBy.trim() != ''">
			and a.HANDLED_BY = #{param.updateBy}
		</if>
		<if test="param.buyType != null">
			and a.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and a.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 a.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and a.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.BUY_HANDLE_STATUS,a.CREATE_TIME DESC
	</select>
	<!--通过id查询商险信息-->
	<select id="getInsuranceDetailById" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceDetailVO">
		select
		a.id as id,
		a.EMP_NAME as empName,
		a.EMP_IDCARD_NO as empIdcardNo,
		a.BUY_TYPE as buyType,
		a.DEPT_NO as deptNo,
		a.POST as post,
		a.POLICY_START as policyStart,
		a.POLICY_END as policyEnd,
		a.POLICY_EFFECT as policyEffect,
		a.POLICY_NO as policyNo,
		a.INSURANCE_TYPE_NAME as insuranceTypeName,
		a.INSURANCE_TYPE_ID as insuranceTypeId,
		a.BUY_STANDARD as buyStandard,
		a.MEDICAL_QUOTA as medicalQuota,
		a.DIE_DISABLE_QUOTA as dieDisableQuota,
		a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		a.SETTLE_TYPE as premiumType,
		a.ESTIMATE_PREMIUM as estimatePremium,
		a.ACTUAL_PREMIUM as actualPremium,
		a.INVOICE_NO as invoiceNo,
		a.SETTLE_TYPE as settleType,
		a.SETTLE_MONTH as settleMonth,
		a.BUY_HANDLE_STATUS as buyHandleStatus,
		a.REDUCE_HANDLE_STATUS as reduceHandleStatus,
		a.IS_USE as isUse,
		a.IS_EFFECT as isEffect,
		a.IS_OVERDUE as isOverdue,
		a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
		a.INSURANCE_PROVINCE as insuranceProvince,
		a.INSURANCE_CITY_NAME as insuranceCityName,
		a.INSURANCE_CITY as insuranceCity,
		a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
		a.INSURANCE_HANDLE_PROVINCE as insuranceHandleProvince,
		a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
		a.INSURANCE_HANDLE_CITY as insuranceHandleCity,
		a.CREATE_NAME as createName,
		a.CREATE_TIME as createTime,
		a.REMARK as remark,
		a.BILLING_TYPE as billingType,
		a.DEFAULT_SETTLE_ID as defaultSettleId,
			a.RATE as  rate
		from t_insurance_detail a
		left join t_insurance_settle tis on a.DEFAULT_SETTLE_ID = tis.ID
		where a.ID = #{id}
	</select>
	<!--导出办理勾选查询结果-->
	<select id="getInsuranceExportListBySelect" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceExportListVO">
		select a.id as id,
		a.DEPT_NO as deptNo,
		a.EMP_NAME as empName,
		a.EMP_IDCARD_NO as empIdcardNo,
		a.BUY_TYPE as buyType,
		a.BUY_HANDLE_STATUS as buyHandleStatus,
		a.POST as post,
		a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
		a.INSURANCE_CITY_NAME as insuranceCityName,
		a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
		a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
		a.POLICY_START as policyStart,
		a.POLICY_END as policyEnd,
		a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		a.INSURANCE_TYPE_NAME as insuranceTypeName,
		a.BUY_STANDARD as buyStandard,
		a.MEDICAL_QUOTA as medicalQuota,
		a.DIE_DISABLE_QUOTA as dieDisableQuota,
		a.SETTLE_MONTH as settleMonth,
		a.SETTLE_TYPE as settleType,
		a.CREATE_NAME as createName,
		a.POLICY_NO as policyNo,
		a.REMARK as remark
		from t_insurance_detail a
		where a.DELETE_FLAG = 0 and a.id in
		<foreach collection="idList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
		ORDER BY a.CREATE_TIME DESC
	</select>
	<!--出办理非勾选查询结果-->
	<select id="getInsuranceExportList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceExportListVO">
		select a.id as id,
			a.DEPT_NO as deptNo,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.BUY_TYPE as buyType,
			a.POST as post,
			a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			a.INSURANCE_CITY_NAME as insuranceCityName,
			a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			a.SETTLE_MONTH as settleMonth,
			a.SETTLE_TYPE as settleType,
			a.CREATE_NAME as createName,
			a.POLICY_NO as policyNo,
			a.REMARK as remark
		from t_insurance_detail a
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where a.DELETE_FLAG = 0 and a.BUY_HANDLE_STATUS = 1
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO like concat('%',replace(replace(#{param.deptNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME like concat('%',replace(replace(#{param.insuranceCompanyName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.buyType != null">
			and a.BUY_TYPE = #{param.buyType}
		</if>
		<if test="param.createName != null and param.createName.trim() != ''">
			and a.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 a.CREATE_TIME <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00') and a.CREATE_TIME <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.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>
	<!--批量更新发票号-->
	<update id="updateInvoiceNoBatch">
		<foreach collection="details" index="index" item="item" separator=";">
			update t_insurance_detail set INVOICE_NO = #{item.invoiceNo} where ID = #{item.id}
		</foreach>
	</update>

	<!-- ***********************减员办理******************************** -->
	<!-- 已投保列表分页查询-->
	<select id="getInsuredListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuredListVo">
		select
			a.id as id,
			a.REDUCE_HANDLE_STATUS as reduceHandleStatus,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.BUY_TYPE as buyType,
			a.DEPT_NO as deptNo,
			a.POST as post,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.POLICY_EFFECT as policyEffect,
			a.IS_USE as isUse,
			a.IS_EFFECT as isEffect,
			a.IS_OVERDUE as isOverdue,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.CREATE_USER_DEPT_NAME as createUserDeptName,
			a.BUY_STANDARD as buyStandard
		from
		     t_insurance_detail a
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where
			a.DELETE_FLAG = 0
		and
			a.BUY_HANDLE_STATUS = 3
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and a.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 a.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 a.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 (
			(a.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
				)
		</if>
		<if test="param.invoiceNo != null and param.invoiceNo.trim() != ''">
			and a.INVOICE_NO like concat('%',replace(replace(#{param.invoiceNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.isUse != null">
			and a.IS_USE = #{param.isUse}
		</if>
		<if test="param.isOverdue != null">
			and a.IS_OVERDUE = #{param.isOverdue}
		</if>
		<if test="param.createStartTime != null and param.createStartTime.trim() != ''">
			AND a.CREATE_TIME  <![CDATA[ >= ]]>  concat(#{param.createStartTime}, ' 00:00:00')
		</if>
		<if test="param.createEndTime != null and param.createEndTime.trim() != ''">
			AND a.CREATE_TIME  <![CDATA[ <= ]]> concat(#{param.createEndTime}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.CREATE_TIME DESC ,a.ID ASC
	</select>
	<!-- 已投保列表不分页查询-->
	<select id="getInsuredList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuredListVo">
		select
			a.id as id,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.BUY_TYPE as buyType,
			a.DEPT_NO as deptNo,
			a.POST as post,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			a.ESTIMATE_PREMIUM as estimatePremium,
			a.ACTUAL_PREMIUM as actualPremium,
			a.POLICY_NO as policyNo,
			a.INVOICE_NO as invoiceNo,
			a.POLICY_EFFECT as policyEffect,
			a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			a.INSURANCE_CITY_NAME as insuranceCityName,
			a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			a.IS_USE as isUse,
			a.IS_EFFECT as isEffect,
			a.IS_OVERDUE as isOverdue,
			a.CREATE_TIME as createTime,
			a.CREATE_NAME as createName
		from
		    t_insurance_detail a
			<if test="param.authSql != null and param.authSql.trim() != ''">
				left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
			</if>
		where
		    a.DELETE_FLAG = 0
		and
			a.BUY_HANDLE_STATUS = 3
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and a.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 a.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 a.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 (
			(a.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
			)
		</if>
		<if test="param.invoiceNo != null and param.invoiceNo.trim() != ''">
			and a.INVOICE_NO like concat('%',replace(replace(#{param.invoiceNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.isUse != null">
			and a.IS_USE = #{param.isUse}
		</if>
		<if test="param.isOverdue != null ">
			and a.IS_OVERDUE = #{param.isOverdue}
		</if>
		<if test="param.createStartTime != null and param.createStartTime.trim() != ''">
			AND a.CREATE_TIME  <![CDATA[ >= ]]>  concat(#{param.createStartTime}, ' 00:00:00')
		</if>
		<if test="param.createEndTime != null and param.createEndTime.trim() != ''">
			AND a.CREATE_TIME  <![CDATA[ <= ]]> concat(#{param.createEndTime}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.CREATE_TIME DESC
	</select>
	<!-- 已减员列表分页查询-->
	<select id="getInsuranceRefundPageList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceRefundListVo">
		select
		    a.id as id,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.POST as post,
			a.DEPT_NO as deptNo,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.POLICY_NO as policyNo,
			refund.CREATE_USER_DEPT_NAME as createUserDeptName,
			refund.CREATE_TIME as refundCreateTime
		from
			(t_insurance_detail a,
			t_insurance_refund refund)
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where
		    a.DELETE_FLAG = 0
		and
			a.REFUND_ID = refund.ID
		and
			a.REDUCE_HANDLE_STATUS = 4
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and a.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 a.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 a.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 (
			(a.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
			)
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY refund.CREATE_TIME DESC,a.ID ASC
	</select>
	<!-- 已减员列表不分页查询-->
	<select id="getInsuranceRefundList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuranceRefundListVo">
		select
			a.id as id,
			a.DEPT_NO as deptNo,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.BUY_TYPE as buyType,
			a.POST as post,
			a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			a.INSURANCE_CITY_NAME as insuranceCityName,
			a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			refund.CREATE_TIME as refundCreateTime
		from
			(t_insurance_detail a,
			t_insurance_refund refund)
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where
			a.REFUND_ID = refund.ID
		and
			a.DELETE_FLAG = 0
		and
			a.REDUCE_HANDLE_STATUS = 4
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.policyNo != null and param.policyNo.trim() != ''">
			and a.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 a.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 a.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 (
			(a.POLICY_START <![CDATA[ <= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ >= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_START <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_START <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59')) OR
			(a.POLICY_END <![CDATA[ >= ]]>  concat(#{param.policyStart}, ' 00:00:00') and a.POLICY_END <![CDATA[ <= ]]> concat(#{param.policyEnd}, ' 23:59:59'))
			)
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY refund.CREATE_TIME DESC
	</select>
	<!-- 减员办理列表分页查询-->
	<select id="getInsuranceRefundHandlingPageList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.RefundExportListVo">
		select
		DISTINCT
		a.id as id,
		a.EMP_NAME as empName,
		a.EMP_IDCARD_NO as empIdcardNo,
		a.BUY_TYPE as buyType,
		a.DEPT_NO as deptNo,
		a.POST as post,
		a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
		a.INSURANCE_CITY_NAME as insuranceCityName,
		a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
		a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
		a.POLICY_START as policyStart,
		a.POLICY_END as policyEnd,
		a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
		a.INSURANCE_TYPE_NAME as insuranceTypeName,
		a.BUY_STANDARD as buyStandard,
		a.MEDICAL_QUOTA as medicalQuota,
		a.DIE_DISABLE_QUOTA as dieDisableQuota,
		refund.CREATE_NAME as createName,
		a.REDUCE_HANDLE_STATUS as reduceHandleStatus
		from
			t_insurance_detail a,
			t_insurance_refund refund
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where
			a.REFUND_ID = refund.ID
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.reduceHandleStatus != null">
			and a.REDUCE_HANDLE_STATUS = #{param.reduceHandleStatus}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and a.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</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>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY refund.CREATE_TIME DESC,a.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
			a.DEPT_NO as deptNo,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			refund.ID as id,
			refund.INS_DETAIL_ID as insDetailId,
			refund.REFUND_MONEY as refundMoney
		from
			t_insurance_detail a,
			t_insurance_refund refund
		where
			a.DELETE_FLAG = 0
		and
			a.REFUND_ID = refund.ID
		and
			a.BUY_HANDLE_STATUS = 5
		and
			a.REDUCE_HANDLE_STATUS = 4
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME = #{param.empName}
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO = #{param.empIdcardNo}
		</if>
		<if test="param.policyNo!= null and param.policyNo.trim() != ''">
			and a.POLICY_NO = #{param.policyNo}
		</if>
	</select>
	<!-- 根据ID导出减员办理列表-->
	<select id="getRefundExportListBySelect" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.RefundExportListVo">
		select
			a.id as id,
			a.DEPT_NO as deptNo,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.BUY_TYPE as buyType,
			a.POST as post,
			a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			a.INSURANCE_CITY_NAME as insuranceCityName,
			a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			a.SETTLE_MONTH as settleMonth,
			a.SETTLE_TYPE as settleType,
			a.CREATE_NAME as createName,
			a.REDUCE_HANDLE_STATUS as reduceHandleStatus,
			a.REMARK as remark
		from
		    t_insurance_detail a
		where
		    a.id in
		<foreach collection="idList" index="index" item="item" open="(" separator="," close=")">
			#{item}
		</foreach>
		ORDER BY a.CREATE_TIME DESC
	</select>
	<!-- 根据查询参数导出减员办理列表-->
	<select id="getRefundExportList" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.RefundExportListVo">
		select
		    a.id as id,
			a.DEPT_NO as deptNo,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.BUY_TYPE as buyType,
			a.POST as post,
			a.INSURANCE_PROVINCE_NAME as insuranceProvinceName,
			a.INSURANCE_CITY_NAME as insuranceCityName,
			a.INSURANCE_HANDLE_PROVINCE_NAME as insuranceHandleProvinceName,
			a.INSURANCE_HANDLE_CITY_NAME as insuranceHandleCityName,
			a.POLICY_START as policyStart,
			a.POLICY_END as policyEnd,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			a.SETTLE_MONTH as settleMonth,
			a.SETTLE_TYPE as settleType,
			a.CREATE_NAME as createName,
			a.REMARK as remark
		from
			t_insurance_detail a
		<if test="param.authSql != null and param.authSql.trim() != ''">
			left join t_insurance_area_res p on p.USER_ID = #{param.createBy}
		</if>
		where
		    a.DELETE_FLAG = 0 and a.REDUCE_HANDLE_STATUS = 1
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.deptNo != null and param.deptNo.trim() != ''">
			and a.DEPT_NO = #{param.deptNo}
		</if>
		<if test="param.insuranceTypeName != null and param.insuranceTypeName.trim() != ''">
			and a.INSURANCE_TYPE_NAME like concat('%',replace(replace(#{param.insuranceTypeName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.insuranceCompanyName != null and param.insuranceCompanyName.trim() != ''">
			and a.INSURANCE_COMPANY_NAME = #{param.insuranceCompanyName}
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		GROUP BY a.id
		ORDER BY a.CREATE_TIME DESC
	</select>
	<!-- 减员办理-->
	<update id="updateInsuranceRefund">
		update
			t_insurance_detail a
		set
			UPDATE_BY = #{param.updateBy},
			REDUCE_HANDLE_STATUS = #{param.refundType},
			UPDATE_TIME = #{param.refundCreateTime}
		where
		      a.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="getOrderInsuredListPage" resultType="com.yifu.cloud.plus.v1.yifu.insurances.vo.InsuredOrderListVo">
		(
		select
			a.id as id,
			a.id as onlyId,
			a.BUY_TYPE as buyType,
			a.CREATE_BY as createBy,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			a.CREATE_NAME as createName,
			a.CREATE_USER_DEPT_NAME as createUserDeptName,
			a.CREATE_TIME as createTime,
			a.BUY_HANDLE_STATUS as buyHandleStatus,
			a.REDUCE_HANDLE_STATUS as reduceHandleStatus
		from
			t_insurance_detail a
		where
			a.DELETE_FLAG = 0
		and
			a.ORDER_NO = #{param.orderNo}
		<if test="param.empName != null and param.empName.trim() != ''">
			and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
			and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
		</if>
		<if test="param.startDate != null ">
			AND a.CREATE_TIME  <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00')
		</if>
		<if test="param.endDate != null ">
			AND a.CREATE_TIME  <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
		</if>
		<if test="param.authSql != null and param.authSql.trim() != ''">
			${param.authSql}
		</if>
		<if test="param.deptNoList != null">
			and a.DEPT_NO in
			<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
				#{item}
			</foreach>
		</if>)
		union all(
		select
			a.id as id,
			refund.id as onlyId,
			refund.BUY_TYPE as buyType,
			refund.CREATE_BY as createBy,
			a.EMP_NAME as empName,
			a.EMP_IDCARD_NO as empIdcardNo,
			a.INSURANCE_COMPANY_NAME as insuranceCompanyName,
			a.INSURANCE_TYPE_NAME as insuranceTypeName,
			a.BUY_STANDARD as buyStandard,
			a.MEDICAL_QUOTA as medicalQuota,
			a.DIE_DISABLE_QUOTA as dieDisableQuota,
			refund.CREATE_NAME as createName,
			refund.CREATE_USER_DEPT_NAME as createUserDeptName,
			refund.CREATE_TIME as createTime,
			a.BUY_HANDLE_STATUS as buyHandleStatus,
			refund.REDUCE_HANDLE_STATUS as reduceHandleStatus
			from
				t_insurance_detail a,
				t_insurance_refund refund
			where
				a.DELETE_FLAG = 0
			and
			    a.ID = refund.INS_DETAIL_ID
			and
				refund.ORDER_NO = #{param.orderNo}
			<if test="param.empName != null and param.empName.trim() != ''">
				and a.EMP_NAME like concat('%',replace(replace(#{param.empName},'_','\_'),'%','\%'),'%')
			</if>
			<if test="param.empIdcardNo != null and param.empIdcardNo.trim() != ''">
				and a.EMP_IDCARD_NO like concat('%',replace(replace(#{param.empIdcardNo},'_','\_'),'%','\%'),'%')
			</if>
			<if test="param.startDate != null">
				AND refund.CREATE_TIME  <![CDATA[ >= ]]>  concat(#{param.startDate}, ' 00:00:00')
			</if>
			<if test="param.endDate != null ">
				AND refund.CREATE_TIME  <![CDATA[ <= ]]> concat(#{param.endDate}, ' 23:59:59')
			</if>
			<if test="param.authSql != null and param.authSql.trim() != ''">
				${param.authSql}
			</if>
			<if test="param.deptNoList != null">
				and a.DEPT_NO in
				<foreach collection="param.deptNoList" index="index" item="item" open="(" separator="," close=")">
					#{item}
				</foreach>
			</if>
		)
		order by createTime desc
	</select>

</mapper>
