<?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.meterworkpreprocess.mapper.MeterWorkPreProcessMapper">
    <resultMap id="BaseResultMap" type="com.steerinfo.meterwork.meterworkpreprocess.model.MeterWorkPreProcess">
        <id column="PRE_PROCESS_NO" jdbcType="VARCHAR" property="preProcessNo"/>
        <result column="PREDICTION_NO" jdbcType="VARCHAR" property="predictionNo"/>
        <result column="PROCESS_NO" jdbcType="VARCHAR" property="processNo"/>
        <result column="CAR_NO" jdbcType="VARCHAR" property="carNo"/>
        <result column="METER_TYPE_NO" jdbcType="VARCHAR" property="meterTypeNo"/>
        <result column="METER_TYPE_NAME" jdbcType="VARCHAR" property="meterTypeName"/>
        <result column="MATTER_NO" jdbcType="VARCHAR" property="matterNo"/>
        <result column="MATTER_NAME" jdbcType="VARCHAR" property="matterName"/>
        <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"/>
    </resultMap>
    <sql id="columns">
    PRE_PROCESS_NO, PREDICTION_NO, PROCESS_NO, CAR_NO, METER_TYPE_NO, METER_TYPE_NAME, 
    MATTER_NO, MATTER_NAME, VALUE_FLAG, CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
  </sql>
    <sql id="columns_alias">
    t.PRE_PROCESS_NO, t.PREDICTION_NO, t.PROCESS_NO, t.CAR_NO, t.METER_TYPE_NO, t.METER_TYPE_NAME, 
    t.MATTER_NO, t.MATTER_NAME, t.VALUE_FLAG, t.CREATE_MAN_NO, t.CREATE_MAN_NAME, t.CREATE_TIME
  </sql>
    <sql id="select">
        SELECT
        <include refid="columns"/>
        FROM METER_WORK_PRE_PROCESS
    </sql>
    <sql id="select_alias">
        SELECT
        <include refid="columns_alias"/>
        FROM METER_WORK_PRE_PROCESS t
    </sql>
    <sql id="where">
        <where>
            <if test="predictionNo != null and predictionNo != ''">
                and PREDICTION_NO = #{predictionNo}
            </if>
            <if test="processNo != null and processNo != ''">
                and PROCESS_NO = #{processNo}
            </if>
            <if test="carNo != null and carNo != ''">
                and CAR_NO = #{carNo}
            </if>
            <if test="meterTypeNo != null and meterTypeNo != ''">
                and METER_TYPE_NO = #{meterTypeNo}
            </if>
            <if test="meterTypeName != null and meterTypeName != ''">
                and METER_TYPE_NAME = #{meterTypeName}
            </if>
            <if test="matterNo != null and matterNo != ''">
                and MATTER_NO = #{matterNo}
            </if>
            <if test="matterName != null and matterName != ''">
                and MATTER_NAME = #{matterName}
            </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>
        </where>
    </sql>
    <sql id="whereLike">
        <where>
            <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="carNo != null and carNo != ''">
                and CAR_NO LIKE '%${carNo}%'
            </if>
            <if test="meterTypeNo != null and meterTypeNo != ''">
                and METER_TYPE_NO LIKE '%${meterTypeNo}%'
            </if>
            <if test="meterTypeName != null and meterTypeName != ''">
                and METER_TYPE_NAME LIKE '%${meterTypeName}%'
            </if>
            <if test="matterNo != null and matterNo != ''">
                and MATTER_NO LIKE '%${matterNo}%'
            </if>
            <if test="matterName != null and matterName != ''">
                and MATTER_NAME LIKE '%${matterName}%'
            </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>
        </where>
    </sql>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from METER_WORK_PRE_PROCESS
    where PRE_PROCESS_NO = #{preProcessNo,jdbcType=VARCHAR}
  </delete>
    <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
        delete from METER_WORK_PRE_PROCESS
        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="carNo != null and carNo != ''">
            or CAR_NO = #{carNo}
        </if>
        <if test="meterTypeNo != null and meterTypeNo != ''">
            or METER_TYPE_NO = #{meterTypeNo}
        </if>
        <if test="meterTypeName != null and meterTypeName != ''">
            or METER_TYPE_NAME = #{meterTypeName}
        </if>
        <if test="matterNo != null and matterNo != ''">
            or MATTER_NO = #{matterNo}
        </if>
        <if test="matterName != null and matterName != ''">
            or MATTER_NAME = #{matterName}
        </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>
    </delete>
    <insert id="insert" parameterType="com.steerinfo.meterwork.meterworkpreprocess.model.MeterWorkPreProcess">
    insert into METER_WORK_PRE_PROCESS (PRE_PROCESS_NO, PREDICTION_NO, PROCESS_NO, 
      CAR_NO, METER_TYPE_NO, METER_TYPE_NAME, 
      MATTER_NO, MATTER_NAME, VALUE_FLAG, 
      CREATE_MAN_NO, CREATE_MAN_NAME, CREATE_TIME
      )
    values (#{preProcessNo,jdbcType=VARCHAR}, #{predictionNo,jdbcType=VARCHAR}, #{processNo,jdbcType=VARCHAR}, 
      #{carNo,jdbcType=VARCHAR}, #{meterTypeNo,jdbcType=VARCHAR}, #{meterTypeName,jdbcType=VARCHAR}, 
      #{matterNo,jdbcType=VARCHAR}, #{matterName,jdbcType=VARCHAR}, #{valueFlag,jdbcType=VARCHAR}, 
      #{createManNo,jdbcType=VARCHAR}, #{createManName,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}
      )
  </insert>
    <insert id="insertSelective" parameterType="com.steerinfo.meterwork.meterworkpreprocess.model.MeterWorkPreProcess">
        insert into METER_WORK_PRE_PROCESS
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="preProcessNo != null">
                PRE_PROCESS_NO,
            </if>
            <if test="predictionNo != null">
                PREDICTION_NO,
            </if>
            <if test="processNo != null">
                PROCESS_NO,
            </if>
            <if test="carNo != null">
                CAR_NO,
            </if>
            <if test="meterTypeNo != null">
                METER_TYPE_NO,
            </if>
            <if test="meterTypeName != null">
                METER_TYPE_NAME,
            </if>
            <if test="matterNo != null">
                MATTER_NO,
            </if>
            <if test="matterName != null">
                MATTER_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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="preProcessNo != null">
                #{preProcessNo,jdbcType=VARCHAR},
            </if>
            <if test="predictionNo != null">
                #{predictionNo,jdbcType=VARCHAR},
            </if>
            <if test="processNo != null">
                #{processNo,jdbcType=VARCHAR},
            </if>
            <if test="carNo != null">
                #{carNo,jdbcType=VARCHAR},
            </if>
            <if test="meterTypeNo != null">
                #{meterTypeNo,jdbcType=VARCHAR},
            </if>
            <if test="meterTypeName != null">
                #{meterTypeName,jdbcType=VARCHAR},
            </if>
            <if test="matterNo != null">
                #{matterNo,jdbcType=VARCHAR},
            </if>
            <if test="matterName != null">
                #{matterName,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>
        </trim>
    </insert>
    <update id="updateByPrimaryKey"
            parameterType="com.steerinfo.meterwork.meterworkpreprocess.model.MeterWorkPreProcess">
    update METER_WORK_PRE_PROCESS
    set PREDICTION_NO = #{predictionNo,jdbcType=VARCHAR},
      PROCESS_NO = #{processNo,jdbcType=VARCHAR},
      CAR_NO = #{carNo,jdbcType=VARCHAR},
      METER_TYPE_NO = #{meterTypeNo,jdbcType=VARCHAR},
      METER_TYPE_NAME = #{meterTypeName,jdbcType=VARCHAR},
      MATTER_NO = #{matterNo,jdbcType=VARCHAR},
      MATTER_NAME = #{matterName,jdbcType=VARCHAR},
      VALUE_FLAG = #{valueFlag,jdbcType=VARCHAR},
      CREATE_MAN_NO = #{createManNo,jdbcType=VARCHAR},
      CREATE_MAN_NAME = #{createManName,jdbcType=VARCHAR},
      CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}
    where PRE_PROCESS_NO = #{preProcessNo,jdbcType=VARCHAR}
  </update>
    <update id="updateByPrimaryKeySelective"
            parameterType="com.steerinfo.meterwork.meterworkpreprocess.model.MeterWorkPreProcess">
        update METER_WORK_PRE_PROCESS
        <set>
            <if test="predictionNo != null">
                PREDICTION_NO = #{predictionNo,jdbcType=VARCHAR},
            </if>
            <if test="processNo != null">
                PROCESS_NO = #{processNo,jdbcType=VARCHAR},
            </if>
            <if test="carNo != null">
                CAR_NO = #{carNo,jdbcType=VARCHAR},
            </if>
            <if test="meterTypeNo != null">
                METER_TYPE_NO = #{meterTypeNo,jdbcType=VARCHAR},
            </if>
            <if test="meterTypeName != null">
                METER_TYPE_NAME = #{meterTypeName,jdbcType=VARCHAR},
            </if>
            <if test="matterNo != null">
                MATTER_NO = #{matterNo,jdbcType=VARCHAR},
            </if>
            <if test="matterName != null">
                MATTER_NAME = #{matterName,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>
        </set>
        where PRE_PROCESS_NO = #{preProcessNo,jdbcType=VARCHAR}
    </update>
    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        <include refid="select"/>
        where PRE_PROCESS_NO = #{preProcessNo,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_PROCESS
        (PRE_PROCESS_NO,
        PREDICTION_NO, PROCESS_NO, CAR_NO,
        METER_TYPE_NO, METER_TYPE_NAME, MATTER_NO,
        MATTER_NAME, VALUE_FLAG, CREATE_MAN_NO,
        CREATE_MAN_NAME, CREATE_TIME)
        ( <foreach collection="list" item="item" separator="union all">
        select
        #{item.preProcessNo,jdbcType=VARCHAR},
        #{item.predictionNo,jdbcType=VARCHAR}, #{item.processNo,jdbcType=VARCHAR}, #{item.carNo,jdbcType=VARCHAR},
        #{item.meterTypeNo,jdbcType=VARCHAR}, #{item.meterTypeName,jdbcType=VARCHAR}, #{item.matterNo,jdbcType=VARCHAR},
        #{item.matterName,jdbcType=VARCHAR}, #{item.valueFlag,jdbcType=VARCHAR}, #{item.createManNo,jdbcType=VARCHAR},
        #{item.createManName,jdbcType=VARCHAR}, #{item.createTime,jdbcType=TIMESTAMP} from dual
    </foreach> )
    </insert>
    <update id="batchUpdate" parameterType="java.util.List">
        update METER_WORK_PRE_PROCESS
        set
        PRE_PROCESS_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.preProcessNo,jdbcType=VARCHAR}
        </foreach>
        ,PREDICTION_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.predictionNo,jdbcType=VARCHAR}
        </foreach>
        ,PROCESS_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.processNo,jdbcType=VARCHAR}
        </foreach>
        ,CAR_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.carNo,jdbcType=VARCHAR}
        </foreach>
        ,METER_TYPE_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.meterTypeNo,jdbcType=VARCHAR}
        </foreach>
        ,METER_TYPE_NAME=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.meterTypeName,jdbcType=VARCHAR}
        </foreach>
        ,MATTER_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.matterNo,jdbcType=VARCHAR}
        </foreach>
        ,MATTER_NAME=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.matterName,jdbcType=VARCHAR}
        </foreach>
        ,VALUE_FLAG=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.valueFlag,jdbcType=VARCHAR}
        </foreach>
        ,CREATE_MAN_NO=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.createManNo,jdbcType=VARCHAR}
        </foreach>
        ,CREATE_MAN_NAME=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.createManName,jdbcType=VARCHAR}
        </foreach>
        ,CREATE_TIME=
        <foreach collection="list" item="item" index="index" separator=" " open="case PRE_PROCESS_NO" close="end">
            when #{item.preProcessNo,jdbcType=VARCHAR} then #{item.createTime,jdbcType=TIMESTAMP}
        </foreach>
        where PRE_PROCESS_NO in
        <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
            #{item.preProcessNo,jdbcType=VARCHAR}
        </foreach>
    </update>
    <delete id="batchDelete" parameterType="java.util.List">
        delete from METER_WORK_PRE_PROCESS
        where PRE_PROCESS_NO in
        <foreach collection="list" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </delete>
    <!-- 友情提示！！！-->
    <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->
    <select id="selectByType" parameterType="java.lang.String" resultMap="BaseResultMap">
    select t2.prediction_no PREDICTION_NO,t1.process_no PROCESS_NO,t2.car_no CAR_NO,t1.meter_type_no METER_TYPE_NO,t1.meter_type_name METER_TYPE_NAME,
        t2.matter_no MATTER_NO,t2.matter_name MATTER_NAME
    from METER_WORK_METER_PROCESS t1,PRE_TRACK_SCALE t2
    where t1.meter_type_no = #{meterTypeNo,jdbcType=VARCHAR}
          and t1.meter_type_name = #{meterTypeName,jdbcType=VARCHAR}
          and t2.prediction_no = #{predictionNo,jdbcType=VARCHAR} and t1.VALUE_FLAG= '0'
  </select>

  <!--序列号修改为5位;并且添加日期数据-->
    <select id="getNewID" parameterType="java.lang.String" resultType="java.lang.String">
    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(PRE_PROCESS_NO, LENGTH(PRE_PROCESS_NO) -4))),0) + 1,5,'0') PRE_PROCESS_NO
    FROM METER_WORK_PRE_PROCESS where instr(PRE_PROCESS_NO,to_char(sysdate,'yyyyMMdd'))>0
  </select>


    <select id="findWithCondition" parameterType="java.util.HashMap" resultMap="BaseResultMap">
        SELECT
        <include refid="columns_alias"/>
        FROM METER_WORK_PRE_PROCESS 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>
        </where>
        order by PREDICTION_NO asc
    </select>
</mapper>