<?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.ObjAcciMapper">
    <resultMap type="com.goldenwater.slaj.acci.domain.ObjAcci" id="ObjAcciResult">
        <result property="guid" column="guid"/>
        <result property="acciName" column="acci_name"/>
        <result property="pGuid" column="p_guid"/>
        <result property="acciWiunGuid" column="acci_wiun_guid"/>
        <result property="acciWiunType" column="acci_wiun_type"/>
        <result property="acciCate" column="acci_cate"/>
        <result property="occuTime" column="occu_time"/>
        <result property="occuLoc" column="occu_loc"/>
        <result property="missNum" column="miss_num"/>
        <result property="serInjNum" column="ser_inj_num"/>
        <result property="casNum" column="cas_num"/>
        <result property="econLoss" column="econ_loss"/>
        <result property="orgGuid" column="org_guid"/>
        <result property="acciDesc" column="acci_desc"/>
        <result property="occuLong" column="occu_long"/>
        <result property="occuLat" column="occu_lat"/>
        <result property="otlcolGuuiVicm" column="otlcol_guui_vicm"/>
        <result property="rescTreaMeas" column="resc_trea_meas"/>
        <result property="contaPers" column="conta_pers"/>
        <result property="offiTel" column="offi_tel"/>
        <result property="repStat" column="rep_stat"/>
        <result property="note" column="note"/>
        <result property="collTime" column="coll_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="recPers" column="rec_pers"/>
        <result property="sgdwName" column="sgdw_name"/>
        <result property="acciGrad" column="acci_grad"/>
        <result property="engGuid" column="eng_guid"/>
        <result property="toDate" column="to_date"/>
        <result property="tendGuid" column="tend_guid"/>
    </resultMap>
    <sql id="selectObjAcciVo">
        select guid, acci_name, p_guid, acci_wiun_guid, acci_wiun_type, acci_cate, occu_time,
               occu_loc, miss_num, ser_inj_num, cas_num, econ_loss, org_guid, acci_desc,
               occu_long, occu_lat, otlcol_guui_vicm,
               resc_trea_meas, conta_pers, offi_tel, rep_stat, note, coll_time,
               upd_time, rec_pers, sgdw_name, acci_grad, eng_guid, to_date, tend_guid
        from obj_acci
    </sql>
    <select id="selectObjAcciByGuid" parameterType="String" resultMap="ObjAcciResult">
        <include refid="selectObjAcciVo"/>
        where guid = #{guid}
    </select>
    <select id="selectObjAcciList" parameterType="com.goldenwater.slaj.acci.domain.ObjAcci" resultMap="ObjAcciResult">
        <include refid="selectObjAcciVo"/>
        <where>
            <if test="guid != null and guid != ''">AND guid = #{guid}</if>
            <if test="pGuid != null and pGuid != ''">AND p_guid = #{pGuid}</if>
            <if test="acciWiunGuid != null and acciWiunGuid != ''">AND acci_wiun_guid = #{acciWiunGuid}</if>
            <if test="acciWiunType != null and acciWiunType != ''">AND acci_wiun_type = #{acciWiunType}</if>
            <if test="acciCate != null and acciCate != ''">AND acci_cate = #{acciCate}</if>
            <if test="occuTime != null and occuTime != ''">AND occu_time = #{occuTime}</if>
            <if test="occuLoc != null and occuLoc != ''">AND occu_loc like '%' || #{occuLoc} || '%'</if>
            <if test="missNum != null and missNum != ''">AND miss_num = #{missNum}</if>
            <if test="serInjNum != null and serInjNum != ''">AND ser_inj_num = #{serInjNum}</if>
            <if test="casNum != null and casNum != ''">AND cas_num = #{casNum}</if>
            <if test="repStat != null and repStat != ''">AND rep_stat = #{repStat}</if>
            <if test="sgdwName != null and sgdwName != ''">AND sgdw_name like '%' || #{sgdwName} || '%'</if>
            <if test="acciGrad != null and acciGrad != ''">AND acci_grad = #{acciGrad}</if>
            <if test="engGuid != null and engGuid != ''">AND eng_guid = #{engGuid}</if>
            <if test="recPers != null and recPers != ''">AND rec_pers = #{recPers}</if>
        </where>
    </select>
    <insert id="insertObjAcci" parameterType="com.goldenwater.slaj.acci.domain.ObjAcci">
        insert into obj_acci (
            guid, acci_name, p_guid, acci_wiun_guid, acci_wiun_type, acci_cate, occu_time,
            occu_loc, miss_num, ser_inj_num, cas_num, econ_loss, org_guid, acci_desc,
            occu_long, occu_lat, otlcol_guui_vicm,
            resc_trea_meas, conta_pers, offi_tel, rep_stat, note, coll_time,
            upd_time, rec_pers, sgdw_name, acci_grad, eng_guid, to_date, tend_guid
        ) values (
            #{guid}, #{acciName}, #{pGuid}, #{acciWiunGuid}, #{acciWiunType}, #{acciCate}, #{occuTime},
            #{occuLoc}, #{missNum}, #{serInjNum}, #{casNum}, #{econLoss}, #{orgGuid}, #{acciDesc},
            #{occuLong}, #{occuLat}, #{otlcolGuuiVicm},
            #{rescTreaMeas}, #{contaPers}, #{offiTel}, #{repStat}, #{note}, #{collTime},
            #{updTime}, #{recPers}, #{sgdwName}, #{acciGrad}, #{engGuid}, #{toDate}, #{tendGuid}
        )
    </insert>
    <update id="updateObjAcci" parameterType="com.goldenwater.slaj.acci.domain.ObjAcci">
        update obj_acci
        <set>
            <if test="acciName != null">acci_name = #{acciName},</if>
            <if test="pGuid != null">p_guid = #{pGuid},</if>
            <if test="acciWiunGuid != null">acci_wiun_guid = #{acciWiunGuid},</if>
            <if test="acciWiunType != null">acci_wiun_type = #{acciWiunType},</if>
            <if test="acciCate != null">acci_cate = #{acciCate},</if>
            <if test="occuTime != null">occu_time = #{occuTime},</if>
            <if test="occuLoc != null">occu_loc = #{occuLoc},</if>
            <if test="missNum != null">miss_num = #{missNum},</if>
            <if test="serInjNum != null">ser_inj_num = #{serInjNum},</if>
            <if test="casNum != null">cas_num = #{casNum},</if>
            <if test="econLoss != null">econ_loss = #{econLoss},</if>
            <if test="orgGuid != null">org_guid = #{orgGuid},</if>
            <if test="acciDesc != null">acci_desc = #{acciDesc},</if>
            <if test="occuLong != null">occu_long = #{occuLong},</if>
            <if test="occuLat != null">occu_lat = #{occuLat},</if>
            <if test="otlcolGuuiVicm != null">otlcol_guui_vicm = #{otlcolGuuiVicm},</if>
            <if test="rescTreaMeas != null">resc_trea_meas = #{rescTreaMeas},</if>
            <if test="contaPers != null">conta_pers = #{contaPers},</if>
            <if test="offiTel != null">offi_tel = #{offiTel},</if>
            <if test="repStat != null">rep_stat = #{repStat},</if>
            <if test="note != null">note = #{note},</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="sgdwName != null">sgdw_name = #{sgdwName},</if>
            <if test="acciGrad != null">acci_grad = #{acciGrad},</if>
            <if test="engGuid != null">eng_guid = #{engGuid},</if>
            <if test="toDate != null">to_date = #{toDate},</if>
            <if test="tendGuid != null">tend_guid = #{tendGuid},</if>
        </set>
        where guid = #{guid}
    </update>
    <delete id="deleteObjAcciByGuid" parameterType="String">
        delete from obj_acci where guid = #{guid}
    </delete>
    <delete id="deleteObjAcciByGuids" parameterType="String">
        delete from obj_acci where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>

    <select id="selectTrendChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
        select substr(occu_time, 1, 7) as month,
               count(1) as acciCount
        from obj_acci
        <where>
            <if test="startTime != null and startTime != ''">AND occu_time &gt;= #{startTime}</if>
            <if test="endTime != null and endTime != ''">AND occu_time &lt;= #{endTime}</if>
            <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
        </where>
        group by substr(occu_time, 1, 7)
        order by month
    </select>

    <select id="selectCatePieChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
        select acci_cate as name,
               count(1) as value
        from obj_acci
        <where>
            <if test="startTime != null and startTime != ''">AND occu_time &gt;= #{startTime}</if>
            <if test="endTime != null and endTime != ''">AND occu_time &lt;= #{endTime}</if>
            <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
        </where>
        group by acci_cate
        order by value desc
    </select>

    <select id="selectGradPieChart" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
        select acci_grad as name,
               count(1) as value
        from obj_acci
        <where>
            <if test="startTime != null and startTime != ''">AND occu_time &gt;= #{startTime}</if>
            <if test="endTime != null and endTime != ''">AND occu_time &lt;= #{endTime}</if>
            <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
        </where>
        group by acci_grad
        order by value desc
    </select>

    <select id="selectGisData" parameterType="java.util.Map" resultType="java.util.LinkedHashMap">
        select guid, acci_name as acciName, occu_long as occuLong, occu_lat as occuLat,
               acci_cate as acciCate, acci_grad as acciGrad, occu_loc as occuLoc,
               occu_time as occuTime, cas_num as casNum, ser_inj_num as serInjNum,
               org_guid as orgGuid
        from obj_acci
        <where>
            occu_long is not null and occu_lat is not null
            and occu_long != '' and occu_lat != ''
            <if test="startTime != null and startTime != ''">AND occu_time &gt;= #{startTime}</if>
            <if test="endTime != null and endTime != ''">AND occu_time &lt;= #{endTime}</if>
            <if test="orgGuid != null and orgGuid != ''">AND org_guid = #{orgGuid}</if>
        </where>
        order by occu_time desc
    </select>
</mapper>
