<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.disputeresolution" name="调解管理">

    <select id="selectDisputeResolutionList" parameterType="page"
            resultType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolution">
        select bb.*
        from (select jdr.id,
        jdr.name,
        phone,
        organization,
        resolution_type as resolutionType,
        qualifications,
        workload,
        create_time     as createTime,
        update_time     as updateTime,
        update_user     as updateUser,
        create_user     as createUser,
        jdr.del_flag    as delFlag,
        city,
        city.name as cityName,
        area,
        area.name       as areaName,
        street,
        street.name     as streetName,
        city.sort       as sort1,
        area.sort       as sort2,
        street.sort     as sort3
        from jl_dispute_resolution jdr
        left join sys_area city on jdr.city = city.code
        left join sys_area area on jdr.area = area.code
        left join sys_area street on jdr.street = street.code
        where jdr.del_flag = '0'
        <if test="params.name != null and params.name != ''">
            and jdr.name like concat('%',#{params.name},'%')
        </if>
        <if test="params.phone != null and params.phone != ''">
            and jdr.phone like concat('%',#{params.phone},'%')
        </if>
        <if test="params.city != null and params.city != ''">
            and jdr.city like concat('%',#{params.city},'%')
        </if>
        <if test="params.area != null and params.area != ''">
            and jdr.area like concat('%',#{params.area},'%')
        </if>
        <if test="params.street != null and params.street != ''">
            and jdr.street like concat('%',#{params.street},'%')
        </if>
        <if test="params.organization != null and params.organization != ''">
            and jdr.organization  = #{params.organization}
        </if>
        <if test="params.resolutionType != null and params.resolutionType != ''">
            and jdr.resolution_type  = #{params.resolutionType}
        </if>
        order by sort1, sort2, sort3) bb
    </select>

    <select id="selectDisputeResolutionFilesList"
            parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolution"
            resultType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolutionFile">
        select id,
        jl_dispute_resolution_id jlDisputeResolutionId,
        obs_key as obsKey,
        prefix,
        content,
        file_name as fileName,
        create_time as createTime,
        create_user as createUser,
        update_time as updateTime,
        update_user as updateUser,
        prefix,
        del_flag delFlag,
        file_url fileUrl
        from jl_dispute_resolution_file
        where jl_dispute_resolution_file.jl_dispute_resolution_id = #{id}
    </select>

    <insert id="insertDisputeResolutionFiles" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolutionFile">
        insert into jl_dispute_resolution_file
        (id, jl_dispute_resolution_id,obs_key,file_name,create_time,update_time,create_user,update_user,del_flag,prefix, content,file_url)
        values
        (#{id}, #{jlDisputeResolutionId},#{obsKey},#{fileName}, now(), now(),#{_user.id},#{_user.id}, 0, #{prefix}, #{content},#{fileUrl})
    </insert>

    <delete id="deleteDisputeResolutionById" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolution">
        update jl_dispute_resolution
        set
        del_flag = '1'
        where
        id = #{id}
    </delete>

    <insert id="insertDisputeResolution" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolution">
        insert into jl_dispute_resolution
        (id,
        name,
        phone,
        organization,
        resolution_type,
        qualifications,
        workload,
        create_time,
        update_time,
        update_user,
        create_user,
        del_flag,city, area, street)
        values
        (#{id},
        #{name},
        #{phone},
        #{organization},
        #{resolutionType},
        #{qualifications},
        #{workload},
        now(),
       now(), #{_user.id},  #{_user.id}, '0'
        ,#{city}, #{area}, #{street}
        )
    </insert>

    <update id="updateDisputeResolutionFiles" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolution">
        delete from jl_dispute_resolution_file where jl_dispute_resolution_id = #{id}
    </update>

    <update id="updateDisputeResolution" parameterType="com.scpyun.platform.jilinsscgsdp.bean.entity.DisputeResolution">
        update jl_dispute_resolution
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="phone != null and phone != ''">
                phone = #{phone},
            </if>
            <if test="organization != null and organization != ''">
                organization = #{organization},
            </if>
            <if test="resolutionType != null and resolutionType != ''">
                resolution_type = #{resolutionType},
            </if>
            <if test="qualifications != null and qualifications != ''">
                qualifications = #{qualifications},
            </if>
            <if test="workload != null and workload != ''">
                workload = #{workload},
            </if>
            <if test="city != null and city != ''">
                city = #{city},
            </if>
            <if test="area != null and area != ''">
                area = #{area},
            </if>
            <if test="street != null and street != ''">
                street = #{street},
            </if>
            update_user = #{_user.id},
            update_time =now()
        </set>
        where
        id = #{id}
    </update>





</mapper>
