<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!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.csp.mapper.EmployeeRegistrationLeaveInsuranceMapper">

  <resultMap id="employeeRegistrationLeaveInsuranceMap" type="com.yifu.cloud.plus.v1.csp.entity.EmployeeRegistrationLeaveInsurance">
    <id property="id" column="id"/>
    <result property="leaveId" column="leave_id"/>
    <result property="insuranceId" column="insurance_id"/>
    <result property="doStatusInsurance" column="do_status_insurance"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.id,
                a.leave_id,
                a.insurance_id,
                a.do_status_insurance
    </sql>

    <!--list-->
    <select id="getLeaveInsuranceList" resultMap="employeeRegistrationLeaveInsuranceMap">
        SELECT
        	<include refid="Base_Column_List"/>
        FROM employee_registration_leave_insurance a
        <where>
            1=1
			<if test="leaveId != null and leaveId.trim() != ''">
				AND a.leave_id = #{leaveId}
			</if>
			<if test="insuranceId != null and insuranceId.trim() != ''">
				AND a.insurance_id = #{insuranceId}
			</if>
        </where>
    </select>

    <select id="getLeaveInsuranceListByIdAndStatus" resultType="java.lang.String">
        SELECT
        	a.insurance_id
        FROM employee_registration_leave_insurance a
        <where>
			do_status_insurance in ('0','2','3','9')
			<if test="idList != null">
				AND a.insurance_id in
				<foreach item="idStr" index="index" collection="idList" open="(" separator="," close=")">
					#{idStr}
				</foreach>
			</if>
        </where>
    </select>

	<update id="updateLeaveInsuranceListByIdAndStatus" >
		update employee_registration_leave_insurance
		<set>
			do_status_insurance = #{status}
		</set>
		where do_status_insurance in ('0','2','3','9') and insurance_id in
		<foreach item="idStr" index="index" collection="idList" open="(" separator="," close=")">
			#{idStr}
		</foreach>
	</update>

	<!-- 避免数据重复，保存前，删除历史数据 -->
	<delete id="deleteLeaveInsurance" >
		delete from employee_registration_leave_insurance where leave_id = #{leaveId}
	</delete>
</mapper>
