<?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.goldenwater.slaj.acci.mapper.BisAcciMontMapper">
    <resultMap type="com.goldenwater.slaj.acci.domain.BisAcciMont" id="BisAcciMontResult">
        <result property="guid" column="guid"/>
        <result property="repWiunCode" column="rep_wiun_code"/>
        <result property="acciCate" column="acci_cate"/>
        <result property="acciGrad" column="acci_grad"/>
        <result property="occuTime" column="occu_time"/>
        <result property="casNum" column="cas_num"/>
        <result property="serInjNum" column="ser_inj_num"/>
        <result property="econLoss" column="econ_loss"/>
        <result property="repAct" column="rep_act"/>
        <result property="note" column="note"/>
        <result property="acciResult" column="acci_result"/>
        <result property="monthlyAudit" column="monthly_audit"/>
        <result property="monthlyAuditResult" column="monthly_audit_result"/>
        <result property="returninfo" column="returninfo"/>
        <result property="revocationAudit" column="revocation_audit"/>
        <result property="revocationAuditResult" column="revocation_audit_result"/>
        <result property="collTime" column="coll_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="recPers" column="rec_pers"/>
        <result property="acciWiunType" column="acci_wiun_type"/>
        <result property="mont" column="mont"/>
        <result property="montStat" column="mont_stat"/>
        <result property="lockStatus" column="lock_status"/>
    </resultMap>
    <sql id="selectBisAcciMontVo">
        select guid, rep_wiun_code, acci_cate, acci_grad, occu_time, cas_num,
               ser_inj_num, econ_loss, rep_act, note, acci_result, monthly_audit,
               monthly_audit_result, returninfo, revocation_audit,
               revocation_audit_result, coll_time, upd_time, rec_pers, acci_wiun_type,
               to_char(occu_time, 'yyyy-MM') as mont,
               case when monthly_audit_result = '1' then '2'
                    when monthly_audit_result = '0' then '3'
                    when rep_act is not null and rep_act != '' then '1'
               else '0' end as mont_stat,
               case when monthly_audit_result is not null then '1' else '0' end as lock_status
        from bis_acci_mont
    </sql>
    <select id="selectBisAcciMontByGuid" parameterType="String" resultMap="BisAcciMontResult">
        <include refid="selectBisAcciMontVo"/>
        where guid = #{guid}
    </select>
    <select id="selectBisAcciMontList" parameterType="com.goldenwater.slaj.acci.domain.BisAcciMont" resultMap="BisAcciMontResult">
        <include refid="selectBisAcciMontVo"/>
        <where>
            <if test="guid != null and guid != ''">AND guid = #{guid}</if>
            <if test="repWiunCode != null and repWiunCode != ''">AND rep_wiun_code = #{repWiunCode}</if>
            <if test="acciCate != null and acciCate != ''">AND acci_cate = #{acciCate}</if>
            <if test="acciGrad != null and acciGrad != ''">AND acci_grad = #{acciGrad}</if>
            <if test="occuTime != null and occuTime != ''">AND occu_time = #{occuTime}</if>
            <if test="acciWiunType != null and acciWiunType != ''">AND acci_wiun_type = #{acciWiunType}</if>
            <if test="recPers != null and recPers != ''">AND rec_pers = #{recPers}</if>
        </where>
    </select>
    <insert id="insertBisAcciMont" parameterType="com.goldenwater.slaj.acci.domain.BisAcciMont">
        insert into bis_acci_mont (
            guid, rep_wiun_code, acci_cate, acci_grad, occu_time, cas_num,
            ser_inj_num, econ_loss, rep_act, note, acci_result, monthly_audit,
            monthly_audit_result, returninfo, revocation_audit,
            revocation_audit_result, coll_time, upd_time, rec_pers, acci_wiun_type
        ) values (
            #{guid}, #{repWiunCode}, #{acciCate}, #{acciGrad}, #{occuTime}, #{casNum},
            #{serInjNum}, #{econLoss}, #{repAct}, #{note}, #{acciResult}, #{monthlyAudit},
            #{monthlyAuditResult}, #{returninfo}, #{revocationAudit},
            #{revocationAuditResult}, #{collTime}, #{updTime}, #{recPers}, #{acciWiunType}
        )
    </insert>
    <update id="updateBisAcciMont" parameterType="com.goldenwater.slaj.acci.domain.BisAcciMont">
        update bis_acci_mont
        <set>
            <if test="repWiunCode != null">rep_wiun_code = #{repWiunCode},</if>
            <if test="acciCate != null">acci_cate = #{acciCate},</if>
            <if test="acciGrad != null">acci_grad = #{acciGrad},</if>
            <if test="occuTime != null">occu_time = #{occuTime},</if>
            <if test="casNum != null">cas_num = #{casNum},</if>
            <if test="serInjNum != null">ser_inj_num = #{serInjNum},</if>
            <if test="econLoss != null">econ_loss = #{econLoss},</if>
            <if test="repAct != null">rep_act = #{repAct},</if>
            <if test="note != null">note = #{note},</if>
            <if test="acciResult != null">acci_result = #{acciResult},</if>
            <if test="monthlyAudit != null">monthly_audit = #{monthlyAudit},</if>
            <if test="monthlyAuditResult != null">monthly_audit_result = #{monthlyAuditResult},</if>
            <if test="returninfo != null">returninfo = #{returninfo},</if>
            <if test="revocationAudit != null">revocation_audit = #{revocationAudit},</if>
            <if test="revocationAuditResult != null">revocation_audit_result = #{revocationAuditResult},</if>
            <if test="collTime != null">coll_time = #{collTime},</if>
            <if test="updTime != null">upd_time = #{updTime},</if>
            <if test="recPers != null">rec_pers = #{recPers},</if>
            <if test="acciWiunType != null">acci_wiun_type = #{acciWiunType},</if>
        </set>
        where guid = #{guid}
    </update>
    <delete id="deleteBisAcciMontByGuid" parameterType="String">
        delete from bis_acci_mont where guid = #{guid}
    </delete>
    <delete id="deleteBisAcciMontByGuids" parameterType="String">
        delete from bis_acci_mont where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>

    <update id="batchUnlock">
        update bis_acci_mont set monthly_audit_result = null, rep_act = '0' where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </update>
</mapper>
