<?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.emsprodplanyear.mapper.EmsProdplanYearMapper">
  <resultMap id="BaseResultMap" type="com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear">
    <id column="NO" jdbcType="VARCHAR" property="no" />
    <result column="LINE" jdbcType="VARCHAR" property="line" />
    <result column="YEARMONTH" jdbcType="DATE" property="yearmonth" />
    <result column="UNIT" jdbcType="VARCHAR" property="unit" />
    <result column="WEIGHT" jdbcType="DECIMAL" property="weight" />
    <result column="CJR" jdbcType="VARCHAR" property="cjr" />
    <result column="CJSJ" jdbcType="TIMESTAMP" property="cjsj" />
    <result column="JZSJ" jdbcType="TIMESTAMP" property="jzsj" />
    <result column="XGR" jdbcType="VARCHAR" property="xgr" />
    <result column="XGSJ" jdbcType="TIMESTAMP" property="xgsj" />
    <result column="MEMO" jdbcType="VARCHAR" property="memo" />
    <result column="CP" jdbcType="VARCHAR" property="cp" />
    <result column="WEIGHT1" jdbcType="DECIMAL" property="weight1" />
    <result column="WEIGHT2" jdbcType="DECIMAL" property="weight2" />
    <result column="WEIGHT3" jdbcType="DECIMAL" property="weight3" />
    <result column="WEIGHT4" jdbcType="DECIMAL" property="weight4" />
    <result column="ZT" jdbcType="VARCHAR" property="zt" />
    <result column="PARENTID" jdbcType="VARCHAR" property="parentid"/>
    <result column="PRODUCTID" jdbcType="VARCHAR" property="productid"/>
  </resultMap>
  <sql id="columns">
    NO, LINE, YEARMONTH, UNIT, WEIGHT, CJR, CJSJ, XGR, XGSJ, MEMO, CP, WEIGHT1, WEIGHT2,JZSJ,PARENTID,PRODUCTID
  </sql>
  <sql id="columns_alias">
    t.NO, t.LINE, t.YEARMONTH, t.UNIT, t.WEIGHT, t.CJR, t.CJSJ, t.XGR, t.XGSJ, t.MEMO, 
    t.CP, t.WEIGHT1, t.WEIGHT2,t.JZSJ,t.ZT,t.PARENTID
  </sql>
  <sql id="select">
    SELECT <include refid="columns"/> FROM EMS_PRODPLAN_YEAR
  </sql>
  <sql id="select_alias">
    SELECT <include refid="columns_alias"/> FROM EMS_PRODPLAN_YEAR t
  </sql>
  <sql id="where">
    <where> 
      <if test="no != null and no != ''">
        and NO = #{no}
      </if>
      <if test="line != null and line != ''">
        and LINE  in (#{line})
      </if>
      <if test="unit != null and unit != ''">
        and UNIT = #{unit}
      </if>
      <if test="weight != null">
        and WEIGHT = #{weight}
      </if>
      <if test=" yearmonth != null and yearmonth != ''">
       and  to_char(YEARMONTH,'yyyy')  = #{yearmonth}
      </if>
      <if test="cjr != null and cjr != '' ">
        and CJR = #{cjr}
      </if>
      <if test="xgr != null and xgr != ''">
        and XGR = #{xgr}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO = #{memo}
      </if>
      <if test="cp != null and cp != ''">
        and CP = #{cp}
      </if>
      <if test="weight1 != null">
        and WEIGHT1 = #{weight1}
      </if>
      <if test="weight2 != null">
        and WEIGHT2 = #{weight2}
      </if>
      <if test="zt != null">
        and ZT = #{zt}
      </if>
      <if test=" parentid!= null">
        and PARENTID = #{parentid}
      </if>
    </where>
  </sql>
  <sql id="whereLike">
    <where> 
      <if test="no != null and no != ''">
        and NO LIKE '%${no}%'
      </if>
      <if test="line != null and line != ''">
        and LINE LIKE '%${line}%'
      </if>
      <if test="yearmonth != null and yearmonth != ''">
        and YEARMONTH LIKE '%${yearmonth}%'
      </if>
      <if test="unit != null and unit != ''">
        and UNIT LIKE '%${unit}%'
      </if>
      <if test="weight != null">
        and WEIGHT = #{weight}
      </if>
      <if test="cjr != null and cjr != ''">
        and CJR LIKE '%${cjr}%'
      </if>
      <if test="cjsj != null">
        and TO_CHAR(CJSJ,'yyyy-MM-dd') = #{cjsj}
      </if>
      <if test="xgr != null and xgr != ''">
        and XGR LIKE '%${xgr}%'
      </if>
      <if test="xgsj != null">
        and TO_CHAR(XGSJ,'yyyy-MM-dd') = #{xgsj}
      </if>
      <if test="memo != null and memo != ''">
        and MEMO LIKE '%${memo}%'
      </if>
      <if test="cp != null and cp != ''">
        and CP LIKE '%${cp}%'
      </if>
      <if test="weight1 != null">
        and WEIGHT1 = #{weight1}
      </if>
      <if test="weight2 != null">
        and WEIGHT2 = #{weight2}
      </if>
    </where>
  </sql>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from EMS_PRODPLAN_YEAR
    where NO = #{no,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteBySelectiveElement" parameterType="java.util.HashMap">
    delete from EMS_PRODPLAN_YEAR
    where 1!=1 
      <if test="line != null and line != ''">
        or LINE = #{line}
      </if>
      <if test="yearmonth != null and yearmonth != ''">
        or YEARMONTH = #{yearmonth}
      </if>
      <if test="unit != null and unit != ''">
        or UNIT = #{unit}
      </if>
      <if test="weight != null">
        or WEIGHT = #{weight}
      </if>
      <if test="cjr != null and cjr != ''">
        or CJR = #{cjr}
      </if>
      <if test="cjsj != null">
        or TO_CHAR(CJSJ,'yyyy-MM-dd') = '#{cjsj}'
      </if>
      <if test="xgr != null and xgr != ''">
        or XGR = #{xgr}
      </if>
      <if test="xgsj != null">
        or TO_CHAR(XGSJ,'yyyy-MM-dd hh24:mi:ss') = '#{xgsj}'
      </if>
      <if test="memo != null and memo != ''">
        or MEMO = #{memo}
      </if>
      <if test="cp != null and cp != ''">
        or CP = #{cp}
      </if>
      <if test="weight1 != null">
        or WEIGHT1 = #{weight1}
      </if>
      <if test="weight2 != null">
        or WEIGHT2 = #{weight2}
      </if>
  </delete>
  <insert id="insert" parameterType="com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear">
    insert into EMS_PRODPLAN_YEAR (NO, LINE, YEARMONTH, 
      UNIT, WEIGHT, CJR, 
      CJSJ, XGR, XGSJ, 
      MEMO, CP, WEIGHT1, WEIGHT2,JZSJ,ZT,PARENTID,PRODUCTID
      )
    values (#{no,jdbcType=VARCHAR}, #{line,jdbcType=VARCHAR}, #{yearmonth,jdbcType=VARCHAR}, 
      #{unit,jdbcType=VARCHAR}, #{weight,jdbcType=DECIMAL}, #{cjr,jdbcType=VARCHAR}, 
      #{cjsj,jdbcType=TIMESTAMP}, #{xgr,jdbcType=VARCHAR}, #{xgsj,jdbcType=TIMESTAMP}, 
      #{memo,jdbcType=VARCHAR}, #{cp,jdbcType=VARCHAR}, #{weight1,jdbcType=DECIMAL}, #{weight2,jdbcType=DECIMAL},
      #{jzsj,jdbcType=TIMESTAMP},#{zt,jdbcType=VARCHAR},#{parentid,jdbcType=VARCHAR},#{productid,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear">
    insert into EMS_PRODPLAN_YEAR
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="no != null">
        NO,
      </if>
      <if test="line != null">
        LINE,
      </if>
      <if test="yearmonth != null">
        YEARMONTH,
      </if>
      <if test="unit != null">
        UNIT,
      </if>
      <if test="weight != null">
        WEIGHT,
      </if>
      <if test="cjr != null">
        CJR,
      </if>
      <if test="cjsj != null">
        CJSJ,
      </if>
      <if test="xgr != null">
        XGR,
      </if>
      <if test="xgsj != null">
        XGSJ,
      </if>
      <if test="memo != null">
        MEMO,
      </if>
      <if test="cp != null">
        CP,
      </if>
      <if test="weight1 != null">
        WEIGHT1,
      </if>
      <if test="weight2 != null">
        WEIGHT2,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="no != null">
        #{no,jdbcType=VARCHAR},
      </if>
      <if test="line != null">
        #{line,jdbcType=VARCHAR},
      </if>
      <if test="yearmonth != null">
        #{yearmonth,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        #{unit,jdbcType=VARCHAR},
      </if>
      <if test="weight != null">
        #{weight,jdbcType=DECIMAL},
      </if>
      <if test="cjr != null">
        #{cjr,jdbcType=VARCHAR},
      </if>
      <if test="cjsj != null">
        #{cjsj,jdbcType=TIMESTAMP},
      </if>
      <if test="xgr != null">
        #{xgr,jdbcType=VARCHAR},
      </if>
      <if test="xgsj != null">
        #{xgsj,jdbcType=TIMESTAMP},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=VARCHAR},
      </if>
      <if test="cp != null">
        #{cp,jdbcType=VARCHAR},
      </if>
      <if test="weight1 != null">
        #{weight1,jdbcType=DECIMAL},
      </if>
      <if test="weight2 != null">
        #{weight2,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKey" parameterType="com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear">
    update EMS_PRODPLAN_YEAR
    set LINE = #{line,jdbcType=VARCHAR},
      YEARMONTH = #{yearmonth,jdbcType=VARCHAR},
      UNIT = #{unit,jdbcType=VARCHAR},
      WEIGHT = #{weight,jdbcType=DECIMAL},
      CJR = #{cjr,jdbcType=VARCHAR},
      CJSJ = #{cjsj,jdbcType=TIMESTAMP},
      XGR = #{xgr,jdbcType=VARCHAR},
      XGSJ = #{xgsj,jdbcType=TIMESTAMP},
      MEMO = #{memo,jdbcType=VARCHAR},
      CP = #{cp,jdbcType=VARCHAR},
      WEIGHT1 = #{weight1,jdbcType=DECIMAL},
      WEIGHT2 = #{weight2,jdbcType=DECIMAL}
    where NO = #{no,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.steerinfo.ems.emsprodplanyear.model.EmsProdplanYear">
    update EMS_PRODPLAN_YEAR
    <set>
      <if test="line != null">
        LINE = #{line,jdbcType=VARCHAR},
      </if>
      <if test="yearmonth != null">
        YEARMONTH = #{yearmonth,jdbcType=VARCHAR},
      </if>
      <if test="unit != null">
        UNIT = #{unit,jdbcType=VARCHAR},
      </if>
      <if test="weight != null">
        WEIGHT = #{weight,jdbcType=DECIMAL},
      </if>
      <if test="cjr != null">
        CJR = #{cjr,jdbcType=VARCHAR},
      </if>
      <if test="cjsj != null">
        CJSJ = #{cjsj,jdbcType=TIMESTAMP},
      </if>
      <if test="xgr != null">
        XGR = #{xgr,jdbcType=VARCHAR},
      </if>
      <if test=""></if>
      <if test="xgsj != null">
        XGSJ = #{xgsj,jdbcType=TIMESTAMP},
      </if>
      <if test="memo != null">
        MEMO = #{memo,jdbcType=VARCHAR},
      </if>
      <if test="cp != null">
        CP = #{cp,jdbcType=VARCHAR},
      </if>
      <if test="weight1 != null">
        WEIGHT1 = #{weight1,jdbcType=DECIMAL},
      </if>
      <if test="weight2 != null">
        WEIGHT2 = #{weight2,jdbcType=DECIMAL},
      </if>
    </set>
    where NO = #{no,jdbcType=VARCHAR}
  </update>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
    <include refid="select"/>
    where NO = #{no,jdbcType=VARCHAR}
  </select>
  <select id="selectByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="where"/>
    order by YEARMONTH
  </select>
  <select id="selectLikeByParameters" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    <include refid="select"/>
    <include refid="whereLike"/>
  </select>
  <insert id="batchInsert" parameterType="java.util.List">
    insert into EMS_PRODPLAN_YEAR 
      (NO, 
      LINE, YEARMONTH, UNIT, 
      WEIGHT, CJR, CJSJ, 
      XGR, XGSJ, MEMO, 
      CP, WEIGHT1, WEIGHT2
      )
    ( <foreach collection="list" item="item" separator="union all"> 
   select  
      #{item.no,jdbcType=VARCHAR}, 
      #{item.line,jdbcType=VARCHAR}, #{item.yearmonth,jdbcType=VARCHAR}, #{item.unit,jdbcType=VARCHAR}, 
      #{item.weight,jdbcType=DECIMAL}, #{item.cjr,jdbcType=VARCHAR}, #{item.cjsj,jdbcType=TIMESTAMP}, 
      #{item.xgr,jdbcType=VARCHAR}, #{item.xgsj,jdbcType=TIMESTAMP}, #{item.memo,jdbcType=VARCHAR}, 
      #{item.cp,jdbcType=VARCHAR}, #{item.weight2,jdbcType=DECIMAL}, #{item.weight2,jdbcType=DECIMAL}
       from dual  
   </foreach> )
  </insert>
  <update id="batchUpdate" parameterType="java.util.List">
     update EMS_PRODPLAN_YEAR
     set
       NO=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.no,jdbcType=VARCHAR}
       </foreach>
       ,LINE=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.line,jdbcType=VARCHAR}
       </foreach>
       ,YEARMONTH=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.yearmonth,jdbcType=VARCHAR}
       </foreach>
       ,UNIT=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.unit,jdbcType=VARCHAR}
       </foreach>
       ,WEIGHT=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.weight,jdbcType=DECIMAL}
       </foreach>
       ,CJR=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.cjr,jdbcType=VARCHAR}
       </foreach>
       ,CJSJ=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.cjsj,jdbcType=TIMESTAMP}
       </foreach>
       ,XGR=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.xgr,jdbcType=VARCHAR}
       </foreach>
       ,XGSJ=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.xgsj,jdbcType=TIMESTAMP}
       </foreach>
       ,MEMO=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.memo,jdbcType=VARCHAR}
       </foreach>
       ,CP=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.cp,jdbcType=VARCHAR}
       </foreach>
       ,WEIGHT1=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.weight1,jdbcType=DECIMAL}
       </foreach>
       ,WEIGHT2=
       <foreach collection="list" item="item" index="index" separator=" " open="case NO" close="end">
          when #{item.no,jdbcType=VARCHAR} then #{item.weight2,jdbcType=DECIMAL}
       </foreach>
     where NO in 
     <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
    #{item.no,jdbcType=VARCHAR}
     </foreach> 
  </update>
  <delete id="batchDelete" parameterType="java.util.List">
    delete from EMS_PRODPLAN_YEAR
    where NO in 
    <foreach collection="list" item="id" open="(" close=")" separator=",">
      #{id}
    </foreach>
  </delete>
  <!-- 友情提示！！！-->
  <!-- 请将自己写的代码放在此标签之下，方便以后粘贴复制。-->

<!--    &lt;!&ndash;生成表数据&ndash;&gt;-->
<!--  <select id="getDateForProduct" parameterType="java.util.HashMap" resultMap="BaseResultMap">-->
<!--    select  #{cjsj}  cjsj ,#{yearmonth} yearmonth, '0' zt,t.line,t.unit,t.cjr,-->
<!--    t.memo,t.cp-->
<!--    from (select t.*,-->
<!--    row_number() over(PARTITION BY t.   line order by t.yearmonth ) as row_flg-->
<!--    from EMS_PRODPLAN_YEAR t-->
<!--    where t.parentid in (#{parentid})) t-->
<!--    where t.row_flg  = '1'-->
<!--    ORDER BY t.line-->
<!--  </select>-->
  <select id="getDateForProduct" parameterType="java.util.HashMap" resultMap="BaseResultMap">
    select t.* from EMS_PRODPLAN_YEAR t
    <where>
      <if test=" yearmonth != null and yearmonth != ''">
        and  to_char(t.YEARMONTH,'yyyy-mm')  = #{yearmonth}
      </if>
      <if test=" productid != null and productid != ''">
        and  t.PRODUCTID  = #{productid}
      </if>
      <if test="line != null and line != ''">
        and t.LINE = #{line}
      </if>
    </where>
  </select>


</mapper>