<?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.mosty.base.manager.mapper.TbJcglBxxMapper">

    <resultMap type="com.mosty.base.model.entity.jcgl.TbJcglBxx" id="resultMap">
        <result property="id" column="id"/>
        <result property="ssXfqyId" column="ss_xfqy_id" jdbcType="VARCHAR"/>
        <result property="bxxMc" column="bxx_mc" jdbcType="VARCHAR"/>
        <result property="bxxLx" column="bxx_lx" jdbcType="VARCHAR"/>
        <result property="jzId" column="jz_id" jdbcType="NUMERIC"/>
        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.LineStringTypeHandler"/>
        <result property="xzqhdm" column="xzqhdm" jdbcType="VARCHAR"/>
        <result property="ssbm" column="ssbm" jdbcType="VARCHAR"/>
        <result property="ssbmdm" column="ssbmdm" jdbcType="VARCHAR"/>
        <result property="ssxgaj" column="ssxgaj" jdbcType="VARCHAR"/>
        <result property="ssxgajdm" column="ssxgajdm" jdbcType="VARCHAR"/>
        <result property="sssgaj" column="sssgaj" jdbcType="VARCHAR"/>
        <result property="sssgajdm" column="sssgajdm" jdbcType="VARCHAR"/>
        <result property="xtSjly" column="xt_sjly" jdbcType="VARCHAR"/>
        <result property="xtSjzt" column="xt_sjzt" jdbcType="VARCHAR"/>
        <result property="xtScbz" column="xt_scbz" jdbcType="VARCHAR"/>
        <result property="xtCjip" column="xt_cjip" jdbcType="VARCHAR"/>
        <result property="xtCjsj" column="xt_cjsj" jdbcType="VARCHAR"/>
        <result property="xtCjrId" column="xt_cjr_id" jdbcType="VARCHAR"/>
        <result property="xtCjr" column="xt_cjr" jdbcType="VARCHAR"/>
        <result property="xtCjbmdm" column="xt_cjbmdm" jdbcType="VARCHAR"/>
        <result property="xtCjbmmc" column="xt_cjbm" jdbcType="VARCHAR"/>
        <result property="xtZhgxip" column="xt_zhgxip" jdbcType="VARCHAR"/>
        <result property="xtZhgxsj" column="xt_zhgxsj" jdbcType="VARCHAR"/>
        <result property="xtZhgxrid" column="xt_zhgxrid" jdbcType="VARCHAR"/>
        <result property="xtZhgxr" column="xt_zhgxr" jdbcType="VARCHAR"/>
        <result property="xtZhgxbmdm" column="xt_zhgxbmdm" jdbcType="VARCHAR"/>
        <result property="xtZhgxbm" column="xt_zhgxbm" jdbcType="VARCHAR"/>
        <result property="bz" column="bz" jdbcType="VARCHAR"/>
        <result property="sssgajid" column="sssgajid" jdbcType="VARCHAR"/>
        <result property="ssxgajid" column="ssxgajid" jdbcType="VARCHAR"/>
        <result property="ssbmid" column="ssbmid" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="base_column_list">
        id
        ,ss_xfqy_id,bxx_mc,bxx_lx,jz_id,xzqhdm,
        ssbm,ssbmdm,ssxgaj,ssxgajdm,ssbmid,ssxgajid,sssgajid,
            sssgaj,sssgajdm,xt_sjly,xt_sjzt,xt_scbz,xt_cjip,xt_cjsj,xt_cjr_id,xt_cjr,xt_cjbmdm,xt_cjbmmc,xt_zhgxip,
            xt_zhgxsj,xt_zhgxrid,xt_zhgxr,xt_zhgxbmdm,xt_zhgxbm,bz
    </sql>

    <sql id="zb_sql">
        ST_ASWKT
        (zb) as zb
    </sql>

    <!--保存必巡线信息-->
    <insert id="insertEntity" parameterType="com.mosty.base.model.entity.jcgl.TbJcglBxx">
        insert into tb_jcgl_bxx (id, ss_xfqy_id, bxx_mc, bxx_lx, jz_id, xzqhdm, zb, ssbm, ssbmdm, ssxgaj, ssxgajdm,
                                 sssgaj, sssgajdm, xt_sjly, xt_sjzt, xt_scbz, xt_cjip, xt_cjsj, xt_cjr_id, xt_cjr,
                                 xt_cjbmdm, xt_cjbmmc, xt_zhgxip,ssbmid,ssxgajid,sssgajid,
                                 xt_zhgxsj, xt_zhgxrid, xt_zhgxr, xt_zhgxbmdm, xt_zhgxbm, bz)
        values (#{id}, #{ssXfqyId}, #{bxxMc}, #{bxxLx}, #{jzId}, #{xzqhdm},
                ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.LineStringTypeHandler}),
                #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{ssxgajdm},
                #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId}, #{xtCjr},
                #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip},#{ssbmid},#{ssxgajid},#{sssgajid},
                #{xtZhgxsj}, #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz})
    </insert>

    <!--修改-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.jcgl.TbJcglKfd">
        update tb_jcgl_bxx
        <set>
            <if test="ssXfqyId != null and ssXfqyId != ''">
                ss_xfqy_id = #{ssXfqyId},
            </if>
            <if test="bxxMc != null and bxxMc != ''">
                bxx_mc = #{bxxMc},
            </if>
            <if test="bxxLx != null and bxxLx != ''">
                bxx_lx = #{bxxLx},
            </if>
            <if test="jzId != null and jzId != ''">
                jz_id = #{jzId},
            </if>
            <if test="zb != null">
                zb = ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.LineStringTypeHandler}),
            </if>
            <if test="xzqhdm != null and xzqhdm != ''">
                xzqhdm = #{xzqhdm},
            </if>
            <if test="ssbm != null and ssbm != ''">
                ssbm = #{ssbm},
            </if>
            <if test="ssbmid != null and ssbmid != ''">
                ssbmid = #{ssbmid},
            </if>
            <if test="ssxgajid != null and ssxgajid != ''">
                ssxgajid = #{ssxgajid},
            </if>
            <if test="sssgajid != null and sssgajid != ''">
                sssgajid = #{sssgajid},
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                ssbmdm = #{ssbmdm},
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                ssxgaj = #{ssxgaj},
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                ssxgajdm = #{ssxgajdm},
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                sssgaj = #{sssgaj},
            </if>
            <if test="sssgajdm != null and sssgajdm != ''">
                sssgajdm = #{sssgajdm},
            </if>
            <if test="xtSjly != null and xtSjly != ''">
                xt_sjly = #{xtSjly},
            </if>
            <if test="xtSjzt != null and xtSjzt != ''">
                xt_sjzt = #{xtSjzt},
            </if>
            <if test="xtScbz != null and xtScbz != ''">
                xt_scbz = #{xtScbz},
            </if>
            <if test="xtCjip != null and xtCjip != ''">
                xt_cjip = #{xtCjip},
            </if>
            <if test="xtCjsj != null">
                xt_cjsj = #{xtCjsj},
            </if>
            <if test="xtCjrId != null and xtCjrId != ''">
                xt_cjr_id = #{xtCjrId},
            </if>
            <if test="xtCjr != null and xtCjr != ''">
                xt_cjr = #{xtCjr},
            </if>
            <if test="xtCjbmdm != null and xtCjbmdm != ''">
                xt_cjbmdm = #{xtCjbmdm},
            </if>
            <if test="xtCjbmmc != null and xtCjbmmc != ''">
                xt_cjbmmc = #{xtCjbmmc},
            </if>
            <if test="xtZhgxip != null and xtZhgxip != ''">
                xt_zhgxip = #{xtZhgxip},
            </if>
            <if test="xtZhgxsj != null">
                xt_zhgxsj = #{xtZhgxsj},
            </if>
            <if test="xtZhgxrid != null and xtZhgxrid != ''">
                xt_zhgxrid = #{xtZhgxrid},
            </if>
            <if test="xtZhgxr != null and xtZhgxr != ''">
                xt_zhgxr = #{xtZhgxr},
            </if>
            <if test="xtZhgxbmdm != null and xtZhgxbmdm != ''">
                xt_zhgxbmdm = #{xtZhgxbmdm},
            </if>
            <if test="xtZhgxbm != null and xtZhgxbm != ''">
                xt_zhgxbm = #{xtZhgxbm},
            </if>
            <if test="bz != null and bz != ''">
                bz = #{bz}
            </if>
        </set>
        where id = #{id}
    </update>

    <!--查询分页-->
    <select id="getPageList" parameterType="Map" resultMap="resultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_jcgl_bxx where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.ssXfqyId != null and dto.ssXfqyId != ''">
            and ss_xfqy_id = #{dto.ssXfqyId}
        </if>
        <if test="dto.bxxLx != null and dto.bxxLx != ''">
            and bxx_lx = #{dto.bxxLx}
        </if>
        <if test="dto.bxxMc != null and dto.bxxMc != ''">
            and bxx_mc like concat('%',#{dto.bxxMc},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>
<!--        <if test="dto.ssbmid != null and dto.ssbmid != ''">-->
<!--            and ssbmid = #{dto.ssbmid}-->
<!--        </if>-->
<!--        ${useSql}-->
        order by xt_cjsj desc
        limit #{pageIndex},#{pageSize}
    </select>

    <!--查询分页-->
    <select id="getCount" parameterType="Map" resultType="Integer">
        select count(1) from tb_jcgl_bxx where xt_sjzt = '1' and xt_scbz = '0'
        <if test="dto.ssXfqyId != null and dto.ssXfqyId != ''">
            and ss_xfqy_id = #{dto.ssXfqyId}
        </if>
        <if test="dto.bxxLx != null and dto.bxxLx != ''">
            and bxx_lx = #{dto.bxxLx}
        </if>
        <if test="dto.bxxMc != null and dto.bxxMc != ''">
            and bxx_mc like concat('%',#{dto.bxxMc},'%')
        </if>
        <if test="dto.ssbmdm != null and dto.ssbmdm != ''">
            and ssbmdm like concat(#{dto.ssbmdm},'%')
        </if>
<!--        <if test="dto.ssbmid != null and dto.ssbmid != ''">-->
<!--            and ssbmid = #{dto.ssbmid}-->
<!--        </if>-->
<!--        ${useSql}-->
    </select>

    <!--获取详情-->
    <select id="getById" resultMap="resultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_jcgl_bxx where xt_sjzt = '1' and xt_scbz = '0'
        and id = #{id}
    </select>

    <!--批量删除-->
    <delete id="deleteBatch">
        delete from tb_jcgl_bxx where id in
        <foreach collection="list" item="item" separator="," open="(" close=")">
            #{item}
        </foreach>
    </delete>

</mapper>
