<?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.steerinfo.meterwork.meterworkprelink.mapper.MeterWorkPreLinkMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink">
    <id column="PRE_LINK_NO" jdbcType="VARCHAR" property="preLinkNo" />
    <result column="PREDICTION_NO" jdbcType="VARCHAR" property="predictionNo" />
    <result column="PROCESS_NO" jdbcType="VARCHAR" property="processNo" />
    <result column="PRE_PROCESS_NO" jdbcType="VARCHAR" property="preProcessNo" />
    <result column="LINK_CODE" jdbcType="VARCHAR" property="linkCode" />
    <result column="LINK_NAME" jdbcType="VARCHAR" property="linkName" />
    <result column="VALUE_FLAG" jdbcType="VARCHAR" property="valueFlag" />
    <result column="CREATE_MAN_NO" jdbcType="VARCHAR" property="createManNo" />
    <result column="CREATE_MAN_NAME" jdbcType="VARCHAR" property="createManName" />
    <result column="CREATE_TIME" jdbcType="TIMESTAMP" property="createTime" />
    <result column="SEQ_NO" jdbcType="DECIMAL" property="seqNo" />
    <result column="LINK_NO" jdbcType="VARCHAR" property="linkNo" />
    <result column="UPDATE_MAN_NO" jdbcType="VARCHAR" property="updateManNo" />
    <result column="UPDATE_MAN_NAME" jdbcType="VARCHAR" property="updateManName" />
    <result column="UPDATE_TIME" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="columns">
    PRE_LINK_NO, PREDICTION_NO, PROCESS_NO, PRE_PROCESS_NO, LINK_CODE, LINK_NAME, VALUE_FLAG,
    CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME, SEQ_NO, LINK_NO, UPDATE_MAN_NO, UPDATE_MAN_NAME,
    UPDATE_TIME
  </sql>
  <sql id="columns_alias">
    t.PRE_LINK_NO, t.PREDICTION_NO, t.PROCESS_NO, t.PRE_PROCESS_NO, t.LINK_CODE, t.LINK_NAME,
    t.VALUE_FLAG, t.CREATE_MAN_NO, t.CREATE_MAN_NAME, t.CREATE_TIME, t.SEQ_NO, t.LINK_NO,
    t.UPDATE_MAN_NO, t.UPDATE_MAN_NAME, t.UPDATE_TIME
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM METER_WORK_PRE_LINK
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM METER_WORK_PRE_LINK t
  </sql>
  <sql id="where">
    <where>
      <if test="preLinkNo != null and preLinkNo != ''">
        and PRE_LINK_NO = #{preLinkNo}
      </if>
      <if test="predictionNo != null and predictionNo != ''">
        and PREDICTION_NO = #{predictionNo}
      </if>
      <if test="processNo != null and processNo != ''">
        and PROCESS_NO = #{processNo}
      </if>
      <if test="preProcessNo != null and preProcessNo != ''">
        and PRE_PROCESS_NO = #{preProcessNo}
      </if>
      <if test="linkCode != null and linkCode != ''">
        and LINK_CODE = #{linkCode}
      </if>
      <if test="linkName != null and linkName != ''">
        and LINK_NAME = #{linkName}
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG = #{valueFlag}
      </if>
      <if test="createManNo != null and createManNo != ''">
        and CREATE_MAN_NO = #{createManNo}
      </if>
      <if test="createManName != null and createManName != ''">
        and CREATE_MAN_NAME = #{createManName}
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="seqNo != null">
        and SEQ_NO = #{seqNo}
      </if>
      <if test="linkNo != null and linkNo != ''">
        and LINK_NO = #{linkNo}
      </if>
      <if test="updateManNo != null and updateManNo != ''">
        and UPDATE_MAN_NO = #{updateManNo}
      </if>
      <if test="updateManName != null and updateManName != ''">
        and UPDATE_MAN_NAME = #{updateManName}
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where>
      <if test="preLinkNo != null and preLinkNo != ''">
        and PRE_LINK_NO LIKE '%${preLinkNo}%'
      </if>
      <if test="predictionNo != null and predictionNo != ''">
        and PREDICTION_NO LIKE '%${predictionNo}%'
      </if>
      <if test="processNo != null and processNo != ''">
        and PROCESS_NO LIKE '%${processNo}%'
      </if>
      <if test="preProcessNo != null and preProcessNo != ''">
        and PRE_PROCESS_NO LIKE '%${preProcessNo}%'
      </if>
      <if test="linkCode != null and linkCode != ''">
        and LINK_CODE LIKE '%${linkCode}%'
      </if>
      <if test="linkName != null and linkName != ''">
        and LINK_NAME LIKE '%${linkName}%'
      </if>
      <if test="valueFlag != null and valueFlag != ''">
        and VALUE_FLAG LIKE '%${valueFlag}%'
      </if>
      <if test="createManNo != null and createManNo != ''">
        and CREATE_MAN_NO LIKE '%${createManNo}%'
      </if>
      <if test="createManName != null and createManName != ''">
        and CREATE_MAN_NAME LIKE '%${createManName}%'
      </if>
      <if test="createTime != null">
        and TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = #{createTime}
      </if>
      <if test="seqNo != null">
        and SEQ_NO = #{seqNo}
      </if>
      <if test="linkNo != null and linkNo != ''">
        and LINK_NO LIKE '%${linkNo}%'
      </if>
      <if test="updateManNo != null and updateManNo != ''">
        and UPDATE_MAN_NO LIKE '%${updateManNo}%'
      </if>
      <if test="updateManName != null and updateManName != ''">
        and UPDATE_MAN_NAME LIKE '%${updateManName}%'
      </if>
      <if test="updateTime != null">
        and TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = #{updateTime}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_WORK_PRE_LINK
    where PRE_LINK_NO = #{preLinkNo,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from METER_WORK_PRE_LINK
    where 1!=1
    <if test="predictionNo != null and predictionNo != ''">
      or PREDICTION_NO = #{predictionNo}
    </if>
    <if test="processNo != null and processNo != ''">
      or PROCESS_NO = #{processNo}
    </if>
    <if test="preProcessNo != null and preProcessNo != ''">
      or PRE_PROCESS_NO = #{preProcessNo}
    </if>
    <if test="linkCode != null and linkCode != ''">
      or LINK_CODE = #{linkCode}
    </if>
    <if test="linkName != null and linkName != ''">
      or LINK_NAME = #{linkName}
    </if>
    <if test="valueFlag != null and valueFlag != ''">
      or VALUE_FLAG = #{valueFlag}
    </if>
    <if test="createManNo != null and createManNo != ''">
      or CREATE_MAN_NO = #{createManNo}
    </if>
    <if test="createManName != null and createManName != ''">
      or CREATE_MAN_NAME = #{createManName}
    </if>
    <if test="createTime != null">
      or TO_CHAR(CREATE_TIME,'yyyy-MM-dd') = '#{createTime}'
    </if>
    <if test="seqNo != null">
      or SEQ_NO = #{seqNo}
    </if>
    <if test="linkNo != null and linkNo != ''">
      or LINK_NO = #{linkNo}
    </if>
    <if test="updateManNo != null and updateManNo != ''">
      or UPDATE_MAN_NO = #{updateManNo}
    </if>
    <if test="updateManName != null and updateManName != ''">
      or UPDATE_MAN_NAME = #{updateManName}
    </if>
    <if test="updateTime != null">
      or TO_CHAR(UPDATE_TIME,'yyyy-MM-dd') = '#{updateTime}'
    </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink">
    insert into METER_WORK_PRE_LINK (PRE_LINK_NO, PREDICTION_NO, PROCESS_NO,
      PRE_PROCESS_NO, LINK_CODE, LINK_NAME,
      VALUE_FLAG, CREATE_MAN_NO, CREATE_MAN_NAME,
      CREATE_TIME, SEQ_NO, LINK_NO,
      UPDATE_MAN_NO, UPDATE_MAN_NAME, UPDATE_TIME
      )
    values (#{preLinkNo,jdbcType=VARCHAR}, #{predictionNo,jdbcType=VARCHAR}, #{processNo,jdbcType=VARCHAR},
      #{preProcessNo,jdbcType=VARCHAR}, #{linkCode,jdbcType=VARCHAR}, #{linkName,jdbcType=VARCHAR},
      #{valueFlag,jdbcType=VARCHAR}, #{createManNo,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR},
      #{createTime,jdbcType=TIMESTAMP}, #{seqNo,jdbcType=DECIMAL}, #{linkNo,jdbcType=VARCHAR},
      #{updateManNo,jdbcType=VARCHAR}, #{updateManName,jdbcType=VARCHAR}, #{updateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink">
    insert into METER_WORK_PRE_LINK
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="preLinkNo != null">
        PRE_LINK_NO,
      </if>
      <if test="predictionNo != null">
        PREDICTION_NO,
      </if>
      <if test="processNo != null">
        PROCESS_NO,
      </if>
      <if test="preProcessNo != null">
        PRE_PROCESS_NO,
      </if>
      <if test="linkCode != null">
        LINK_CODE,
      </if>
      <if test="linkName != null">
        LINK_NAME,
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG,
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO,
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME,
      </if>
      <if test="createTime != null">
        CREATE_TIME,
      </if>
      <if test="seqNo != null">
        SEQ_NO,
      </if>
      <if test="linkNo != null">
        LINK_NO,
      </if>
      <if test="updateManNo != null">
        UPDATE_MAN_NO,
      </if>
      <if test="updateManName != null">
        UPDATE_MAN_NAME,
      </if>
      <if test="updateTime != null">
        UPDATE_TIME,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="preLinkNo != null">
        #{preLinkNo,jdbcType=VARCHAR},
      </if>
      <if test="predictionNo != null">
        #{predictionNo,jdbcType=VARCHAR},
      </if>
      <if test="processNo != null">
        #{processNo,jdbcType=VARCHAR},
      </if>
      <if test="preProcessNo != null">
        #{preProcessNo,jdbcType=VARCHAR},
      </if>
      <if test="linkCode != null">
        #{linkCode,jdbcType=VARCHAR},
      </if>
      <if test="linkName != null">
        #{linkName,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        #{valueFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManNo != null">
        #{createManNo,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="seqNo != null">
        #{seqNo,jdbcType=DECIMAL},
      </if>
      <if test="linkNo != null">
        #{linkNo,jdbcType=VARCHAR},
      </if>
      <if test="updateManNo != null">
        #{updateManNo,jdbcType=VARCHAR},
      </if>
      <if test="updateManName != null">
        #{updateManName,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink">
    update METER_WORK_PRE_LINK
    set PREDICTION_NO = #{predictionNo,jdbcType=VARCHAR},
      PROCESS_NO = #{processNo,jdbcType=VARCHAR},
      PRE_PROCESS_NO = #{preProcessNo,jdbcType=VARCHAR},
      LINK_CODE = #{linkCode,jdbcType=VARCHAR},
      LINK_NAME = #{linkName,jdbcType=VARCHAR},
      VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      SEQ_NO = #{seqNo,jdbcType=DECIMAL},
      LINK_NO = #{linkNo,jdbcType=VARCHAR},
      UPDATE_MAN_NO = #{updateManNo,jdbcType=VARCHAR},
      UPDATE_MAN_NAME = #{updateManName,jdbcType=VARCHAR},
      UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP}
    where PRE_LINK_NO = #{preLinkNo,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink">
    update METER_WORK_PRE_LINK
    <set>
      <if test="predictionNo != null">
        PREDICTION_NO = #{predictionNo,jdbcType=VARCHAR},
      </if>
      <if test="processNo != null">
        PROCESS_NO = #{processNo,jdbcType=VARCHAR},
      </if>
      <if test="preProcessNo != null">
        PRE_PROCESS_NO = #{preProcessNo,jdbcType=VARCHAR},
      </if>
      <if test="linkCode != null">
        LINK_CODE = #{linkCode,jdbcType=VARCHAR},
      </if>
      <if test="linkName != null">
        LINK_NAME = #{linkName,jdbcType=VARCHAR},
      </if>
      <if test="valueFlag != null">
        VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      </if>
      <if test="createManNo != null">
        CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      </if>
      <if test="createManName != null">
        CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        CREATE_TIME = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="seqNo != null">
        SEQ_NO = #{seqNo,jdbcType=DECIMAL},
      </if>
      <if test="linkNo != null">
        LINK_NO = #{linkNo,jdbcType=VARCHAR},
      </if>
      <if test="updateManNo != null">
        UPDATE_MAN_NO = #{updateManNo,jdbcType=VARCHAR},
      </if>
      <if test="updateManName != null">
        UPDATE_MAN_NAME = #{updateManName,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null">
        UPDATE_TIME = #{updateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where PRE_LINK_NO = #{preLinkNo,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where PRE_LINK_NO = #{preLinkNo,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
    order by CREATE_TIME  desc
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
    order by CREATE_TIME  desc
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into METER_WORK_PRE_LINK
    (PRE_LINK_NO,
    PREDICTION_NO, PROCESS_NO, PRE_PROCESS_NO,
    LINK_CODE, LINK_NAME, VALUE_FLAG,
    CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME,
    SEQ_NO, LINK_NO, UPDATE_MAN_NO,
    UPDATE_MAN_NAME, UPDATE_TIME)
    ( <foreach collection="list" item="item" separator="union all">
    select
    #{item.preLinkNo,jdbcType=VARCHAR},
    #{item.predictionNo,jdbcType=VARCHAR}, #{item.processNo,jdbcType=VARCHAR}, #{item.preProcessNo,jdbcType=VARCHAR},
    #{item.linkCode,jdbcType=VARCHAR}, #{item.linkName,jdbcType=VARCHAR}, #{item.valueFlag,jdbcType=VARCHAR},
    #{item.createManNo,jdbcType=VARCHAR}, #{item.createManName,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP},
    #{item.seqNo,jdbcType=DECIMAL}, #{item.linkNo,jdbcType=VARCHAR}, #{item.updateManNo,jdbcType=VARCHAR},
    #{item.updateManName,jdbcType=VARCHAR}, #{item.updateTime,jdbcType=TIMESTAMP} from dual
  </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
    update METER_WORK_PRE_LINK
    set
    PRE_LINK_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.preLinkNo,jdbcType=VARCHAR}
    </foreach>
    ,PREDICTION_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.predictionNo,jdbcType=VARCHAR}
    </foreach>
    ,PROCESS_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.processNo,jdbcType=VARCHAR}
    </foreach>
    ,PRE_PROCESS_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.preProcessNo,jdbcType=VARCHAR}
    </foreach>
    ,LINK_CODE=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.linkCode,jdbcType=VARCHAR}
    </foreach>
    ,LINK_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.linkName,jdbcType=VARCHAR}
    </foreach>
    ,VALUE_FLAG=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.valueFlag,jdbcType=VARCHAR}
    </foreach>
    ,CREATE_MAN_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.createManNo,jdbcType=VARCHAR}
    </foreach>
    ,CREATE_MAN_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
    </foreach>
    ,CREATE_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
    </foreach>
    ,SEQ_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.seqNo,jdbcType=DECIMAL}
    </foreach>
    ,LINK_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.linkNo,jdbcType=VARCHAR}
    </foreach>
    ,UPDATE_MAN_NO=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.updateManNo,jdbcType=VARCHAR}
    </foreach>
    ,UPDATE_MAN_NAME=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.updateManName,jdbcType=VARCHAR}
    </foreach>
    ,UPDATE_TIME=
    <foreach collection="list" item="item" index="index" separator=" " open="case PRE_LINK_NO" close="end">
      when #{item.preLinkNo,jdbcType=VARCHAR} then #{item.updateTime,jdbcType=TIMESTAMP}
    </foreach>
    where PRE_LINK_NO in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.preLinkNo,jdbcType=VARCHAR}
    </foreach>
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from METER_WORK_PRE_LINK
    where PRE_LINK_NO in
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->

  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
  <select id="selectByType" parameterType="java.lang.String" resultMap="BaseResultMap">
    select  t1.prediction_no PREDICTION_NO,t.process_no PROCESS_NO,t1.pre_process_no PRE_PROCESS_NO,
            t.link_code LINK_CODE,t.link_name LINK_NAME,t.link_order_num SEQ_NO,t.LINK_NO LINK_NO
    from METER_WORK_METER_LINK t,METER_WORK_PRE_PROCESS t1
    where t.process_no=#{processNo,jdbcType=VARCHAR} and t1.pre_process_no=#{preProcessNo,jdbcType=VARCHAR}
  </select>

  <select id="getNewID" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(PRE_LINK_NO, LENGTH(PRE_LINK_NO) - 3))),0) + 1,4,'0') PRE_LINK_NO
    FROM METER_WORK_PRE_LINK where instr(PRE_LINK_NO,#{afl,jdbcType=VARCHAR})>0
  </select>

  <select id="getNextFlag"  parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t.*
    from METER_WORK_PRE_LINK t
    where  t.prediction_no = #{predictionNo}  and t.seq_no in (select t1.seq_no +1 no
      from METER_WORK_PRE_LINK t1
      where t1.link_code = #{linkCode}   and  t1.prediction_no = #{predictionNo})
    order by seq_no,CREATE_TIME desc
  </select>

  <select id="getPer"  parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t.*
    from METER_WORK_PRE_LINK t
    where  t.prediction_no = #{predictionNo}  and t.seq_no <![CDATA[  <=  ]]> (select distinct(t1.seq_no)  no
    from METER_WORK_PRE_LINK t1
    where t1.link_code = #{linkCode}   and  t1.prediction_no = #{predictionNo})
  </select>

  <select id="getNext"  parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t.*
    from METER_WORK_PRE_LINK t
    where t.prediction_no = #{predictionNo}  and t.seq_no <![CDATA[  >=  ]]> (select t1.seq_no  no
    from METER_WORK_PRE_LINK t1
    where t1.link_code = #{linkCode}   and  t1.prediction_no = #{predictionNo})
  </select>

  <select id="batchReset"  parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select *
    from Meter_Work_Pre_Link t1
    where exists (select 1
          from Meter_Work_Pre_Link t2
         where t1.seq_no = t2.seq_no
           and t2.prediction_no = #{predictionNo}
           and t2.value_flag = #{valueFlag}
         group by t2.seq_no
        having max(t2.rowid) = t1.rowid)
  </select>

  <select id="findWithCondition" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    SELECT <include refid="columns_alias"/> FROM METER_WORK_PRE_LINK t
    <where>
      <if test="valueFlag != null and valueFlag != '' and valueFlag != 'x'.toString()">
        VALUE_FLAG = #{valueFlag}
      </if>
      <if test ="valueFlag == 'x'.toString()">
        t.value_flag in ('0','1')
      </if>
      ${cxxx}
    </where>
    order by  PREDICTION_NO,SEQ_NO  asc
  </select>

  <update id="updateByPrimaryKeySelectivePart" parameterType="com.steerinfo.meterwork.meterworkprelink.model.MeterWorkPreLink">
    update METER_WORK_PRE_LINK
    <set>
      <if test="valueFlag != null">
        VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      </if>
    </set>
    where PRE_LINK_NO = #{preLinkNo,jdbcType=VARCHAR}
  </update>

  <select id="combinedLink" parameterType="java.util.List" resultMap="BaseResultMap">
    select t.*
    from METER_WORK_PRE_LINK t
   where t.prediction_no in
   <foreach collection="list" item="id" open="(" close=")" separator=",">
    #{id}
   </foreach>
     and t.link_code = '001021004' and t.value_flag = '0'
     and t.prediction_no in (select t1.prediction_no
                        from METER_WORK_PRE_LINK t1
                       where t1.link_code = '001021003'
                         and t1.value_flag = '1')
  </select>

  <update id="batchUpdateForUse" parameterType="java.util.List">
    update METER_WORK_PRE_LINK
    set VALUE_FLAG = '1'
    where PRE_LINK_NO in
    <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
      #{item.preLinkNo,jdbcType=VARCHAR}
    </foreach>
  </update>

  <!--按车号查询：历史未卸货/装货的数据-->
  <select id="doQueryNoXh" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t2.*
    from pre_track_scale t
        left join METER_WORK_PRE_LINK t2
        on t.prediction_no = t2.prediction_no
    where t.value_flag ='2' and t2.link_code in ('001021004','001021007') and t2.value_flag = '0'
    <if test="predictionNo != null and predictionNo != ''">
      and T.CAR_NO = #{predictionNo}
    </if>
  </select>

  <update id="doUpdateFlag" parameterType="java.util.HashMap">
    update METER_WORK_PRE_LINK set VALUE_FLAG = '1' where PREDICTION_NO = #{predictionNo}
  </update>
</mapper>