<?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.ems.ifmesemsproductorder.mapper.IfMesEmsProductorderMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.ifmesemsproductorder.model.IfMesEmsProductorder">
    <result column="FID" jdbcType="VARCHAR" property="fid" />
    <result column="WORKS" jdbcType="VARCHAR" property="works" />
    <result column="PRODLINE" jdbcType="VARCHAR" property="prodline" />
    <result column="SPRODATE" jdbcType="DATE" property="sprodate" />
    <result column="EPRODATE" jdbcType="DATE" property="eprodate" />
    <result column="ORDERNO" jdbcType="VARCHAR" property="orderno" />
    <result column="MATERIALCODE" jdbcType="VARCHAR" property="materialcode" />
    <result column="MATERIALNAME" jdbcType="VARCHAR" property="materialname" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="QTY" jdbcType="DECIMAL" property="qty" />
    <result column="CREATETIME" jdbcType="DATE" property="createtime" />
    <result column="STATUS" jdbcType="VARCHAR" property="status" />
    <result column="SENDTIME" jdbcType="DATE" property="sendtime" />
    <result column="MEMO" jdbcType="VARCHAR" property="memo" />
  </resultMap>

  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    select FID, WORKS, PRODLINE, SPRODATE, EPRODATE, ORDERNO, MATERIALCODE, MATERIALNAME, UNIT, QTY, CREATETIME, STATUS, SENDTIME, MEMO
    from IF_MES_EMS_PRODUCTORDER
    where FID = #{id,jdbcType=VARCHAR}
  </select>
  
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select FID, WORKS, PRODLINE, SPRODATE, EPRODATE, ORDERNO, MATERIALCODE, MATERIALNAME, UNIT, QTY, CREATETIME, STATUS, SENDTIME, MEMO
      from IF_MES_EMS_PRODUCTORDER
    <where>
        <if test="fid != null and fid != ''">
            and FID = #{fid}
        </if>
        <if test="works != null and works != ''">
            and WORKS = #{works}
        </if>
        <if test="prodline != null and prodline != ''">
            and PRODLINE = #{prodline}
        </if>
        <if test="sprodate != null and sprodate != ''">
            and SPRODATE = #{sprodate}
        </if>
        <if test="eprodate != null and eprodate != ''">
            and EPRODATE &gt;= to_date(#{eprodate} , 'YYYY-MM')
        </if>
        <if test="orderno != null and orderno != ''">
            and ORDERNO = #{orderno}
        </if>
        <if test="materialcode != null and materialcode != ''">
            and MATERIALCODE = #{materialcode}
        </if>
        <if test="materialname != null and materialname != ''">
            and MATERIALNAME = #{materialname}
        </if>
        <if test="unit != null and unit != ''">
            and UNIT = #{unit}
        </if>
        <if test="qty != null and qty != ''">
            and QTY = #{qty}
        </if>
        <if test="createtime != null and createtime != ''">
            and CREATETIME = #{createtime}
        </if>
        <if test="status != null and status != ''">
            and STATUS = #{status}
        </if>
        <if test="sendtime != null and sendtime != ''">
            and SENDTIME = #{sendtime}
        </if>
        <if test="memo != null and memo != ''">
            and MEMO = #{memo}
        </if>
    </where>
  </select>

  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select FID, WORKS, PRODLINE, SPRODATE, EPRODATE, ORDERNO, MATERIALCODE, MATERIALNAME, UNIT, QTY, CREATETIME, STATUS, SENDTIME, MEMO
      from IF_MES_EMS_PRODUCTORDER
    <where>
        <if test="fid != null and fid != ''">
            and FID LIKE '%${fid}%'
        </if>
        <if test="works != null and works != ''">
            and WORKS LIKE '%${works}%'
        </if>
        <if test="prodline != null and prodline != ''">
            and PRODLINE LIKE '%${prodline}%'
        </if>
        <if test="sprodate != null and sprodate != ''">
            and SPRODATE LIKE '%${sprodate}%'
        </if>
        <if test="eprodate != null and eprodate != ''">
            and EPRODATE LIKE '%${eprodate}%'
        </if>
        <if test="orderno != null and orderno != ''">
            and ORDERNO LIKE '%${orderno}%'
        </if>
        <if test="materialcode != null and materialcode != ''">
            and MATERIALCODE LIKE '%${materialcode}%'
        </if>
        <if test="materialname != null and materialname != ''">
            and MATERIALNAME LIKE '%${materialname}%'
        </if>
        <if test="unit != null and unit != ''">
            and UNIT LIKE '%${unit}%'
        </if>
        <if test="qty != null and qty != ''">
            and QTY LIKE '%${qty}%'
        </if>
        <if test="createtime != null and createtime != ''">
            and CREATETIME LIKE '%${createtime}%'
        </if>
        <if test="status != null and status != ''">
            and STATUS = #{status}
        </if>
        <if test="sendtime != null and sendtime != ''">
            and SENDTIME LIKE '%${sendtime}%'
        </if>
        <if test="memo != null and memo != ''">
            and MEMO LIKE '%${memo}%'
        </if>
    </where>
  </select>

  <!-- 暂时只统计铁前工序的计划，钢后的计划先不管 -->
  <select id="selectNewMaterial" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select FID, WORKS, PRODLINE, SPRODATE, EPRODATE, ORDERNO, MATERIALCODE, MATERIALNAME, UNIT, QTY, CREATETIME, STATUS, SENDTIME, MEMO
      from IF_MES_EMS_PRODUCTORDER
      where STATUS in ('0','9')
      order by EPRODATE, PRODLINE, MATERIALCODE
  </select>

  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.ifmesemsproductorder.model.IfMesEmsProductorder">
    update IF_MES_EMS_PRODUCTORDER
    set WORKS = #{works,jdbcType=VARCHAR},
      PRODLINE = #{prodline,jdbcType=VARCHAR},
      SPRODATE = to_date ( #{sprodate} , 'YYYY-MM-DD HH24:MI:SS' ),
      EPRODATE = to_date ( #{eprodate} , 'YYYY-MM-DD HH24:MI:SS' ),
      ORDERNO = #{orderno,jdbcType=VARCHAR},
      MATERIALCODE = #{materialcode,jdbcType=VARCHAR},
      MATERIALNAME = #{materialname,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      QTY = #{qty,jdbcType=VARCHAR},
      CREATETIME = to_date(#{createtime}, 'YYYY-MM-DD HH24:MI:SS'),
      STATUS = #{status,jdbcType=VARCHAR},
      MEMO = #{memo,jdbcType=VARCHAR}
    where FID = #{fid,jdbcType=VARCHAR}
  </update>

  <update id="updateStatus" parameterType="java.util.HashMap">
    update IF_MES_EMS_PRODUCTORDER
    <set>
      <if test="status != null">
        STATUS = #{status,jdbcType=VARCHAR},
        SENDTIME = SYSDATE,
      </if>
    </set>
    where FID = #{fid,jdbcType=VARCHAR}
  </update>

  <insert id="insert" parameterType="com.steerinfo.ems.ifmesemsproductorder.model.IfMesEmsProductorder">
    insert into IF_MES_EMS_PRODUCTORDER
    <trim prefix="(" suffix=")" suffixOverrides=",">
        <if test="fid != null">
            FID,
        </if>
        <if test="works != null">
            WORKS,
        </if>
        <if test="prodline != null">
            PRODLINE,
        </if>
        <if test="sprodate != null">
            SPRODATE,
        </if>
        <if test="eprodate != null">
            EPRODATE,
        </if>
        <if test="orderno != null">
            ORDERNO,
        </if>
        <if test="materialcode != null">
            MATERIALCODE,
        </if>
        <if test="materialname != null">
            MATERIALNAME,
        </if>
        <if test="unit != null">
            UNIT,
        </if>
        <if test="qty != null">
            QTY,
        </if>
        <if test="createtime != null">
            CREATETIME,
        </if>
            STATUS,
        <if test="memo != null">
            MEMO,
        </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
        <if test="fid != null">
            #{fid,jdbcType=VARCHAR},
        </if>
        <if test="works != null">
            #{works,jdbcType=VARCHAR},
        </if>
        <if test="prodline != null">
            #{prodline,jdbcType=VARCHAR},
        </if>
        <if test="sprodate != null">
            to_date ( #{sprodate} , 'YYYY-MM-DD HH24:MI:SS' ),
        </if>
        <if test="eprodate != null">
            to_date ( #{eprodate} , 'YYYY-MM-DD HH24:MI:SS' ),
        </if>
        <if test="orderno != null">
            #{orderno,jdbcType=VARCHAR},
        </if>
        <if test="materialcode != null">
            #{materialcode,jdbcType=VARCHAR},
        </if>
        <if test="materialname != null">
            #{materialname,jdbcType=VARCHAR},
        </if>
        <if test="unit != null">
            #{unit,jdbcType=VARCHAR},
        </if>
        <if test="qty != null">
            #{qty,jdbcType=DECIMAL},
        </if>
        <if test="createtime != null">
            to_date ( #{createtime} , 'YYYY-MM-DD HH24:MI:SS' ),
        </if>
        <if test="status != null">
            #{status,jdbcType=VARCHAR},
        </if>
        <if test="memo != null">
            #{memo,jdbcType=VARCHAR},
        </if>
    </trim>
  </insert>

</mapper>