<?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.wzzx.mapper.TbWzRywzMapper">
    <resultMap type="com.mosty.base.model.entity.wzzx.TbWzRywz" id="BaseResultMap">
        <result property="id" column="id"/>
        <result property="yhId" column="yh_id"/>
        <result property="yhSfzh" column="yh_sfzh"/>
        <result property="yhXm" column="yh_xm"/>
        <result property="zb" column="zb" typeHandler="com.mosty.base.feign.handle.LineStringTypeHandler"/>
        <result property="zbsl" column="zbsl"/>
        <result property="dwrq" column="dwrq"/>
        <result property="kssj" column="kssj"/>
        <result property="sc" column="sc"/>
        <result property="lc" column="lc"/>
        <result property="jd" column="jd"/>
        <result property="wd" column="wd"/>
        <result property="zhgxsj" column="zhgxsj"/>
        <result property="ssbm" column="ssbm"/>
        <result property="ssbmid" column="ssbmid"/>
        <result property="ssbmdm" column="ssbmdm"/>
        <result property="ssxgaj" column="ssxgaj"/>
        <result property="ssxgajid" column="ssxgajid"/>
        <result property="ssxgajdm" column="ssxgajdm"/>
        <result property="sssgajid" column="sssgajid"/>
        <result property="sssgaj" column="sssgaj"/>
        <result property="sssgajdm" column="sssgajdm"/>
        <result property="xtSjly" column="xt_sjly"/>
        <result property="xtSjzt" column="xt_sjzt"/>
        <result property="xtScbz" column="xt_scbz"/>
        <result property="xtCjip" column="xt_cjip"/>
        <result property="xtCjsj" column="xt_cjsj"/>
        <result property="xtCjrId" column="xt_cjr_id"/>
        <result property="xtCjr" column="xt_cjr"/>
        <result property="xtCjbmdm" column="xt_cjbmdm"/>
        <result property="xtCjbmmc" column="xt_cjbmmc"/>
        <result property="xtZhgxip" column="xt_zhgxip"/>
        <result property="xtZhgxsj" column="xt_zhgxsj"/>
        <result property="xtZhgxrid" column="xt_zhgxrid"/>
        <result property="xtZhgxr" column="xt_zhgxr"/>
        <result property="xtZhgxbmdm" column="xt_zhgxbmdm"/>
        <result property="xtZhgxbm" column="xt_zhgxbm"/>
        <result property="bz" column="bz"/>
    </resultMap>

    <sql id="base_column_list">
        id, yh_id, yh_sfzh, yh_xm,
        zbsl, dwrq, kssj, jssj, sc, lc, jd, wd, zhgxsj,
         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.wzzx.TbWzRywz">
        insert into tb_wz_rywz (id, yh_id, yh_sfzh, yh_xm,
                                zb,
                                zbsl, dwrq, kssj, jssj, sc, lc, jd, wd, zhgxsj,
                                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)
        values (#{id}, #{yhId}, #{yhSfzh}, #{yhXm},
                ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.LineStringTypeHandler}),
                #{zbsl}, #{dwrq}, #{kssj}, #{jssj}, #{sc}, #{lc}, #{jd}, #{wd}, #{zhgxsj},
                #{ssbm}, #{ssbmdm}, #{ssxgaj}, #{ssxgajdm}, #{ssbmid}, #{ssxgajid}, #{sssgajid},
                #{sssgaj}, #{sssgajdm}, #{xtSjly}, #{xtSjzt}, #{xtScbz}, #{xtCjip}, #{xtCjsj}, #{xtCjrId}, #{xtCjr},
                #{xtCjbmdm}, #{xtCjbmmc}, #{xtZhgxip},
                #{xtZhgxsj}, #{xtZhgxrid}, #{xtZhgxr}, #{xtZhgxbmdm}, #{xtZhgxbm}, #{bz})
    </insert>

    <!--修改-->
    <update id="updateEntity" parameterType="com.mosty.base.model.entity.wzzx.TbWzRywz">
        update tb_wz_rywz
        <set>
            <if test="yhId != null and yhId != ''">
                yh_id = #{yhId},
            </if>
            <if test="yhSfzh != null and yhSfzh != ''">
                yh_sfzh = #{yhSfzh},
            </if>
            <if test="yhXm != null and yhXm != ''">
                yh_xm = #{yhXm},
            </if>
            <if test="zb != null">
                zb = ST_GEOMFROMTEXT(#{zb,typeHandler = com.mosty.base.feign.handle.LineStringTypeHandler}),
            </if>
            <if test="zbsl != null and zbsl != ''">
                zbsl = #{zbsl},
            </if>
            <if test="dwrq != null">
                dwrq = #{dwrq},
            </if>
            <if test="kssj != null">
                kssj = #{kssj},
            </if>
            <if test="jssj != null and jssj != ''">
                jssj = #{jssj},
            </if>
            <if test="sc != null and sc != ''">
                sc = #{sc},
            </if>
            <if test="lc != null and lc != ''">
                lc = #{lc},
            </if>
            <if test="jd != null and jd != ''">
                jd = #{jd},
            </if>
            <if test="wd != null and wd != ''">
                wd = #{wd},
            </if>
            <if test="zhgxsj != null">
                zhgxsj = #{zhgxsj},
            </if>
            <if test="ssbm != null and ssbm != ''">
                ssbm = #{ssbm},
            </if>
            <if test="ssbmid != null and ssbmid != ''">
                ssbmid = #{ssbmid},
            </if>
            <if test="ssbmdm != null and ssbmdm != ''">
                ssbmdm = #{ssbmdm},
            </if>
            <if test="ssxgaj != null and ssxgaj != ''">
                ssxgaj = #{ssxgaj},
            </if>
            <if test="ssxgajid != null and ssxgajid != ''">
                ssxgajid = #{ssxgajid},
            </if>
            <if test="ssxgajdm != null and ssxgajdm != ''">
                ssxgajdm = #{ssxgajdm},
            </if>
            <if test="sssgaj != null and sssgaj != ''">
                sssgaj = #{sssgaj},
            </if>
            <if test="sssgajid != null and sssgajid != ''">
                sssgajid = #{sssgajid},
            </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="queryBySfzh" resultMap="BaseResultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_wz_rywz
        where xt_scbz = '0'
        and yh_sfzh = #{yhSfzh,jdbcType=VARCHAR}
        and TO_DAYS(dwrq) = TO_DAYS(NOW())
    </select>

    <select id="selectBySfz" resultMap="BaseResultMap">
        select
        <include refid="base_column_list"/>,
        <include refid="zb_sql"/>
        from tb_wz_rywz
        where xt_scbz = '0' and xt_sjzt = '1'
        <if test="sfzh != null and sfzh != ''">
            and yh_sfzh = #{sfzh}
        </if>
        <if test="dwrq != null and dwrq != ''">
            and dwrq = #{dwrq}
        </if>
        limit 1
    </select>

    <select id="getRysltjCount" resultType="java.lang.Integer">
        select count(DISTINCT yh_id) from tb_wz_rywz where xt_scbz = '0' and xt_sjzt = '1'
        <if test="kssj != null and kssj != ''">
            and dwrq >= #{kssj}
        </if>
        <if test="jssj != null and jssj != ''">
            and dwrq &lt;= #{jssj}
        </if>
        ${useSql}
    </select>

</mapper>
