<?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.ximai.mes.pro.mapper.ProProductionLogMapper">

    <resultMap type="ProProductionLog" id="ProProductionLogResult">
        <result property="recordId"    column="record_id"    />
        <result property="taskId"    column="task_id"    />
        <result property="workstationId"    column="workstation_id"    />
        <result property="operatorId"    column="operator_id"    />
        <result property="operatorName"    column="operator_name"    />
        <result property="faultDescription"    column="fault_description"    />
        <result property="status"    column="status"    />
        <result property="operatorTime"    column="operator_time"    />
        <result property="remark"    column="remark"    />
        <result property="attr1"    column="attr1"    />
        <result property="attr2"    column="attr2"    />
        <result property="attr3"    column="attr3"    />
        <result property="attr4"    column="attr4"    />
    </resultMap>

    <sql id="selectProProductionLogVo">
        select record_id, task_id, workstation_id, operator_id, operator_name, fault_description, status, operator_time, remark, attr1, attr2, attr3, attr4 from pro_production_log
    </sql>

    <select id="selectProProductionLogList" parameterType="ProProductionLog" resultMap="ProProductionLogResult">
        <include refid="selectProProductionLogVo"/>
        <where>
            <if test="taskId != null "> and task_id = #{taskId}</if>
            <if test="workstationId != null "> and workstation_id = #{workstationId}</if>
            <if test="operatorId != null "> and operator_id = #{operatorId}</if>
            <if test="operatorName != null  and operatorName != ''"> and operator_name like concat('%', #{operatorName}, '%')</if>
            <if test="faultDescription != null  and faultDescription != ''"> and fault_description = #{faultDescription}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="operatorTime != null "> and operator_time = #{operatorTime}</if>
            <if test="attr1 != null  and attr1 != ''"> and attr1 = #{attr1}</if>
            <if test="attr2 != null  and attr2 != ''"> and attr2 = #{attr2}</if>
            <if test="attr3 != null "> and attr3 = #{attr3}</if>
            <if test="attr4 != null "> and attr4 = #{attr4}</if>
        </where>
    </select>

    <select id="selectProProductionLogByRecordId" parameterType="Long" resultMap="ProProductionLogResult">
        <include refid="selectProProductionLogVo"/>
        where record_id = #{recordId}
    </select>

    <insert id="insertProProductionLog" parameterType="ProProductionLog">
        insert into pro_production_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="recordId != null">record_id,</if>
            <if test="taskId != null">task_id,</if>
            <if test="workstationId != null">workstation_id,</if>
            <if test="operatorId != null">operator_id,</if>
            <if test="operatorName != null">operator_name,</if>
            <if test="faultDescription != null">fault_description,</if>
            <if test="status != null">status,</if>
            <if test="operatorTime != null">operator_time,</if>
            <if test="remark != null">remark,</if>
            <if test="attr1 != null">attr1,</if>
            <if test="attr2 != null">attr2,</if>
            <if test="attr3 != null">attr3,</if>
            <if test="attr4 != null">attr4,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="recordId != null">#{recordId},</if>
            <if test="taskId != null">#{taskId},</if>
            <if test="workstationId != null">#{workstationId},</if>
            <if test="operatorId != null">#{operatorId},</if>
            <if test="operatorName != null">#{operatorName},</if>
            <if test="faultDescription != null">#{faultDescription},</if>
            <if test="status != null">#{status},</if>
            <if test="operatorTime != null">#{operatorTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="attr1 != null">#{attr1},</if>
            <if test="attr2 != null">#{attr2},</if>
            <if test="attr3 != null">#{attr3},</if>
            <if test="attr4 != null">#{attr4},</if>
         </trim>
    </insert>

    <update id="updateProProductionLog" parameterType="ProProductionLog">
        update pro_production_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="workstationId != null">workstation_id = #{workstationId},</if>
            <if test="operatorId != null">operator_id = #{operatorId},</if>
            <if test="operatorName != null">operator_name = #{operatorName},</if>
            <if test="faultDescription != null">fault_description = #{faultDescription},</if>
            <if test="status != null">status = #{status},</if>
            <if test="operatorTime != null">operator_time = #{operatorTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="attr1 != null">attr1 = #{attr1},</if>
            <if test="attr2 != null">attr2 = #{attr2},</if>
            <if test="attr3 != null">attr3 = #{attr3},</if>
            <if test="attr4 != null">attr4 = #{attr4},</if>
        </trim>
        where record_id = #{recordId}
    </update>

    <delete id="deleteProProductionLogByRecordId" parameterType="Long">
        delete from pro_production_log where record_id = #{recordId}
    </delete>

    <delete id="deleteProProductionLogByRecordIds" parameterType="String">
        delete from pro_production_log where record_id in
        <foreach item="recordId" collection="array" open="(" separator="," close=")">
            #{recordId}
        </foreach>
    </delete>
</mapper>
