<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  "https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zioinfo.mes.routing.mapper.RoutingMapper">

  <resultMap id="routingMap" type="com.zioinfo.mes.routing.MesRouting">
    <id property="id" column="id"/>
    <result property="itemCode" column="item_code"/>
    <result property="opSeq" column="op_seq"/>
    <result property="processCode" column="process_code"/>
    <result property="processName" column="process_name"/>
    <result property="equipmentCode" column="equipment_code"/>
    <result property="stdTimeMin" column="std_time_min"/>
    <result property="setupTimeMin" column="setup_time_min"/>
    <result property="routingVersion" column="routing_version"/>
    <result property="status" column="status"/>
    <result property="createdBy" column="created_by"/>
    <result property="createdAt" column="created_at"/>
  </resultMap>

  <select id="findByItem" resultMap="routingMap">
    SELECT * FROM mes_routing WHERE item_code = #{itemCode} ORDER BY op_seq ASC
  </select>
  <select id="findAll" resultMap="routingMap">SELECT * FROM mes_routing ORDER BY item_code, op_seq</select>
  <select id="findById" resultMap="routingMap">SELECT * FROM mes_routing WHERE id = #{id}</select>

  <insert id="insert" parameterType="com.zioinfo.mes.routing.MesRouting" useGeneratedKeys="true" keyProperty="id">
    INSERT INTO mes_routing (item_code, op_seq, process_code, process_name, equipment_code,
      std_time_min, setup_time_min, routing_version, status, created_by)
    VALUES (#{itemCode}, #{opSeq}, #{processCode}, #{processName}, #{equipmentCode},
      #{stdTimeMin}, #{setupTimeMin}, #{routingVersion}, #{status}, #{createdBy})
  </insert>

  <update id="update" parameterType="com.zioinfo.mes.routing.MesRouting">
    UPDATE mes_routing SET item_code = #{itemCode}, op_seq = #{opSeq}, process_code = #{processCode},
      process_name = #{processName}, equipment_code = #{equipmentCode}, std_time_min = #{stdTimeMin},
      setup_time_min = #{setupTimeMin}, routing_version = #{routingVersion}, status = #{status}
    WHERE id = #{id}
  </update>

  <delete id="delete">DELETE FROM mes_routing WHERE id = #{id}</delete>

</mapper>
