<?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.rongwei.bscommon.sys.dao.ApsProcessOperationBackupDao">

    <resultMap id="BaseResultMap" type="com.rongwei.bsentity.domain.ApsProcessOperationBackupDo">
        <id property="id" column="ID" jdbcType="VARCHAR"/>
        <result property="tenantid" column="TENANTID" jdbcType="VARCHAR"/>
        <result property="roption" column="ROPTION" jdbcType="VARCHAR"/>
        <result property="deleted" column="DELETED" jdbcType="VARCHAR"/>
        <result property="remark" column="REMARK" jdbcType="VARCHAR"/>
        <result property="createdate" column="CREATEDATE" jdbcType="TIMESTAMP"/>
        <result property="createuserid" column="CREATEUSERID" jdbcType="VARCHAR"/>
        <result property="modifydate" column="MODIFYDATE" jdbcType="TIMESTAMP"/>
        <result property="modifyuserid" column="MODIFYUSERID" jdbcType="VARCHAR"/>
        <result property="createusername" column="CREATEUSERNAME" jdbcType="VARCHAR"/>
        <result property="modifyusername" column="MODIFYUSERNAME" jdbcType="VARCHAR"/>
        <result property="ownedfactory" column="OWNEDFACTORY" jdbcType="VARCHAR"/>
        <result property="craftstepid" column="CRAFTSTEPID" jdbcType="VARCHAR"/>
        <result property="stepnum" column="STEPNUM" jdbcType="VARCHAR"/>
        <result property="processid" column="PROCESSID" jdbcType="VARCHAR"/>
        <result property="processcode" column="PROCESSCODE" jdbcType="VARCHAR"/>
        <result property="process" column="PROCESS" jdbcType="VARCHAR"/>
        <result property="processname" column="PROCESSNAME" jdbcType="VARCHAR"/>
        <result property="processway" column="PROCESSWAY" jdbcType="VARCHAR"/>
        <result property="numunit" column="NUMUNIT" jdbcType="VARCHAR"/>
        <result property="onceprocessval" column="ONCEPROCESSVAL" jdbcType="DECIMAL"/>
        <result property="onceprocessmin" column="ONCEPROCESSMIN" jdbcType="DECIMAL"/>
        <result property="pertimecapacity" column="PERTIMECAPACITY" jdbcType="DECIMAL"/>
        <result property="timeunit" column="TIMEUNIT" jdbcType="VARCHAR"/>
        <result property="prepressworkmin" column="PREPRESSWORKMIN" jdbcType="DECIMAL"/>
        <result property="loadingmin" column="LOADINGMIN" jdbcType="DECIMAL"/>
        <result property="cuttingmin" column="CUTTINGMIN" jdbcType="DECIMAL"/>
        <result property="cutfinishmin" column="CUTFINISHMIN" jdbcType="DECIMAL"/>
        <result property="minflowbatch" column="MINFLOWBATCH" jdbcType="DECIMAL"/>
        <result property="minflowwaitmin" column="MINFLOWWAITMIN" jdbcType="DECIMAL"/>
        <result property="maxflowwaitmin" column="MAXFLOWWAITMIN" jdbcType="DECIMAL"/>
        <result property="ifblankprocess" column="IFBLANKPROCESS" jdbcType="VARCHAR"/>
        <result property="materialcode" column="MATERIALCODE" jdbcType="VARCHAR"/>
        <result property="materialname" column="MATERIALNAME" jdbcType="VARCHAR"/>
        <result property="thickness" column="THICKNESS" jdbcType="DECIMAL"/>
        <result property="thickstr" column="THICKSTR" jdbcType="DECIMAL"/>
        <result property="thickend" column="THICKEND" jdbcType="DECIMAL"/>
        <result property="prowidth" column="PROWIDTH" jdbcType="DECIMAL"/>
        <result property="widthstr" column="WIDTHSTR" jdbcType="DECIMAL"/>
        <result property="widthend" column="WIDTHEND" jdbcType="DECIMAL"/>
        <result property="prolength" column="PROLENGTH" jdbcType="DECIMAL"/>
        <result property="lengthstr" column="LENGTHSTR" jdbcType="DECIMAL"/>
        <result property="lengthend" column="LENGTHEND" jdbcType="DECIMAL"/>
        <result property="inmatercondition" column="INMATERCONDITION" jdbcType="VARCHAR"/>
        <result property="outmaterrequest" column="OUTMATERREQUEST" jdbcType="VARCHAR"/>
        <result property="canchoosedeviceid" column="CANCHOOSEDEVICEID" jdbcType="VARCHAR"/>
        <result property="chooseequ" column="CHOOSEEQU" jdbcType="VARCHAR"/>
        <result property="blankid" column="BLANKID" jdbcType="VARCHAR"/>
        <result property="planinputid" column="PLANINPUTID" jdbcType="VARCHAR"/>
        <result property="planinput" column="PLANINPUT" jdbcType="VARCHAR"/>
        <result property="planoutput" column="PLANOUTPUT" jdbcType="VARCHAR"/>
        <result property="planinrall" column="PLANINRALL" jdbcType="INTEGER"/>
        <result property="planblankrall" column="PLANBLANKRALL" jdbcType="INTEGER"/>
        <result property="planprocessrall" column="PLANPROCESSRALL" jdbcType="INTEGER"/>
        <result property="processworkshopid" column="PROCESSWORKSHOPID" jdbcType="VARCHAR"/>
        <result property="processworkshop" column="PROCESSWORKSHOP" jdbcType="VARCHAR"/>
        <result property="processdeviceid" column="PROCESSDEVICEID" jdbcType="VARCHAR"/>
        <result property="processdevice" column="PROCESSDEVICE" jdbcType="VARCHAR"/>
        <result property="planstartdate" column="PLANSTARTDATE" jdbcType="TIMESTAMP"/>
        <result property="actualstartdate" column="ACTUALSTARTDATE" jdbcType="TIMESTAMP"/>
        <result property="planenddate" column="PLANENDDATE" jdbcType="TIMESTAMP"/>
        <result property="actualfinishdate" column="ACTUALFINISHDATE" jdbcType="TIMESTAMP"/>
        <result property="actualimputroll" column="ACTUALIMPUTROLL" jdbcType="INTEGER"/>
        <result property="inputunqualifiedroll" column="INPUTUNQUALIFIEDROLL" jdbcType="INTEGER"/>
        <result property="actualcanprocessroll" column="ACTUALCANPROCESSROLL" jdbcType="INTEGER"/>
        <result property="closestatus" column="CLOSESTATUS" jdbcType="VARCHAR"/>
        <result property="secondroll" column="SECONDROLL" jdbcType="INTEGER"/>
        <result property="startingroll" column="STARTINGROLL" jdbcType="INTEGER"/>
        <result property="reportroll" column="REPORTROLL" jdbcType="INTEGER"/>
        <result property="checkoutroll" column="CHECKOUTROLL" jdbcType="INTEGER"/>
        <result property="unfinishroll" column="UNFINISHROLL" jdbcType="INTEGER"/>
        <result property="cancelroll" column="CANCELROLL" jdbcType="INTEGER"/>
        <result property="workstatus" column="WORKSTATUS" jdbcType="VARCHAR"/>
        <result property="processstatus" column="PROCESSSTATUS" jdbcType="VARCHAR"/>
        <result property="bachmaterialprocess" column="BACHMATERIALPROCESS" jdbcType="VARCHAR"/>
        <result property="processtotaltime" column="PROCESSTOTALTIME" jdbcType="DECIMAL"/>
        <result property="waitreportid" column="WAITREPORTID" jdbcType="VARCHAR"/>
        <result property="planprocessnum" column="PLANPROCESSNUM" jdbcType="INTEGER"/>
        <result property="previousprocessid" column="PREVIOUSPROCESSID" jdbcType="VARCHAR"/>
        <result property="previousprocess" column="PREVIOUSPROCESS" jdbcType="VARCHAR"/>
        <result property="nextprocessid" column="NEXTPROCESSID" jdbcType="VARCHAR"/>
        <result property="nextprocess" column="NEXTPROCESS" jdbcType="VARCHAR"/>
        <result property="level" column="LEVEL" jdbcType="INTEGER"/>
        <result property="producttypeid" column="PRODUCTTYPEID" jdbcType="VARCHAR"/>
        <result property="producttype" column="PRODUCTTYPE" jdbcType="VARCHAR"/>
        <result property="metal" column="METAL" jdbcType="VARCHAR"/>
        <result property="metalstate" column="METALSTATE" jdbcType="VARCHAR"/>
        <result property="outputqualifiednum" column="OUTPUTQUALIFIEDNUM" jdbcType="INTEGER"/>
        <result property="outputunqualifiednum" column="OUTPUTUNQUALIFIEDNUM" jdbcType="INTEGER"/>
        <result property="changeinmeter" column="CHANGEINMETER" jdbcType="VARCHAR"/>
        <result property="singlerollweight" column="SINGLEROLLWEIGHT" jdbcType="DECIMAL"/>
        <result property="lockmark" column="LOCKMARK" jdbcType="VARCHAR"/>
        <result property="backupuser" column="BACKUPUSER" jdbcType="VARCHAR"/>
        <result property="backupuserid" column="BACKUPUSERID" jdbcType="VARCHAR"/>
        <result property="backupdate" column="BACKUPDATE" jdbcType="TIMESTAMP"/>
        <result property="timeway" column="TIMEWAY" jdbcType="VARCHAR"/>
        <result property="workspeed" column="WORKSPEED" jdbcType="DECIMAL"/>
    </resultMap>

    <sql id="Base_Column_List">
        ID,TENANTID,ROPTION,
        DELETED,REMARK,CREATEDATE,
        CREATEUSERID,MODIFYDATE,MODIFYUSERID,
        CREATEUSERNAME,MODIFYUSERNAME,OWNEDFACTORY,
        CRAFTSTEPID,STEPNUM,PROCESSID,
        PROCESSCODE,PROCESS,PROCESSNAME,
        PROCESSWAY,NUMUNIT,ONCEPROCESSVAL,
        ONCEPROCESSMIN,PERTIMECAPACITY,TIMEUNIT,
        PREPRESSWORKMIN,LOADINGMIN,CUTTINGMIN,
        CUTFINISHMIN,MINFLOWBATCH,MINFLOWWAITMIN,
        MAXFLOWWAITMIN,IFBLANKPROCESS,MATERIALCODE,
        MATERIALNAME,THICKNESS,THICKSTR,
        THICKEND,PROWIDTH,WIDTHSTR,
        WIDTHEND,PROLENGTH,LENGTHSTR,
        LENGTHEND,INMATERCONDITION,OUTMATERREQUEST,
        CANCHOOSEDEVICEID,CHOOSEEQU,BLANKID,
        PLANINPUTID,PLANINPUT,PLANOUTPUT,
        PLANINRALL,PLANBLANKRALL,PLANPROCESSRALL,
        PROCESSWORKSHOPID,PROCESSWORKSHOP,PROCESSDEVICEID,
        PROCESSDEVICE,PLANSTARTDATE,ACTUALSTARTDATE,
        PLANENDDATE,ACTUALFINISHDATE,ACTUALIMPUTROLL,
        INPUTUNQUALIFIEDROLL,ACTUALCANPROCESSROLL,CLOSESTATUS,
        SECONDROLL,STARTINGROLL,REPORTROLL,
        CHECKOUTROLL,UNFINISHROLL,CANCELROLL,
        WORKSTATUS,PROCESSSTATUS,BACHMATERIALPROCESS,
        PROCESSTOTALTIME,WAITREPORTID,PLANPROCESSNUM,
        PREVIOUSPROCESSID,PREVIOUSPROCESS,NEXTPROCESSID,
        NEXTPROCESS,LEVEL,PRODUCTTYPEID,
        PRODUCTTYPE,METAL,METALSTATE,
        OUTPUTQUALIFIEDNUM,OUTPUTUNQUALIFIEDNUM,CHANGEINMETER,
        SINGLEROLLWEIGHT,LOCKMARK,TIMEWAY,WORKSPEED,BACKUPUSER,
        BACKUPUSERID,BACKUPDATE
    </sql>
    <insert id="processOperationBackup">
        <if test="processOperationIdList != null and processOperationIdList.size() >0">
            <foreach collection="processOperationIdList" item="id" separator=";">
                INSERT INTO aps_process_operation_backup (<include refid="Base_Column_List"/>)
                SELECT
                ID,TENANTID,ROPTION,
                DELETED,REMARK,CREATEDATE,
                CREATEUSERID,MODIFYDATE,MODIFYUSERID,
                CREATEUSERNAME,MODIFYUSERNAME,OWNEDFACTORY,
                CRAFTSTEPID,STEPNUM,PROCESSID,
                PROCESSCODE,PROCESS,PROCESSNAME,
                PROCESSWAY,NUMUNIT,ONCEPROCESSVAL,
                ONCEPROCESSMIN,PERTIMECAPACITY,TIMEUNIT,
                PREPRESSWORKMIN,LOADINGMIN,CUTTINGMIN,
                CUTFINISHMIN,MINFLOWBATCH,MINFLOWWAITMIN,
                MAXFLOWWAITMIN,IFBLANKPROCESS,MATERIALCODE,
                MATERIALNAME,THICKNESS,THICKSTR,
                THICKEND,PROWIDTH,WIDTHSTR,
                WIDTHEND,PROLENGTH,LENGTHSTR,
                LENGTHEND,INMATERCONDITION,OUTMATERREQUEST,
                CANCHOOSEDEVICEID,CHOOSEEQU,BLANKID,
                PLANINPUTID,PLANINPUT,PLANOUTPUT,
                PLANINRALL,PLANBLANKRALL,PLANPROCESSRALL,
                PROCESSWORKSHOPID,PROCESSWORKSHOP,PROCESSDEVICEID,
                PROCESSDEVICE,PLANSTARTDATE,ACTUALSTARTDATE,
                PLANENDDATE,ACTUALFINISHDATE,ACTUALIMPUTROLL,
                INPUTUNQUALIFIEDROLL,ACTUALCANPROCESSROLL,CLOSESTATUS,
                SECONDROLL,STARTINGROLL,REPORTROLL,
                CHECKOUTROLL,UNFINISHROLL,CANCELROLL,
                WORKSTATUS,PROCESSSTATUS,BACHMATERIALPROCESS,
                PROCESSTOTALTIME,WAITREPORTID,PLANPROCESSNUM,
                PREVIOUSPROCESSID,PREVIOUSPROCESS,NEXTPROCESSID,
                NEXTPROCESS,LEVEL,PRODUCTTYPEID,
                PRODUCTTYPE,METAL,METALSTATE,
                OUTPUTQUALIFIEDNUM,OUTPUTUNQUALIFIEDNUM,CHANGEINMETER,
                SINGLEROLLWEIGHT,LOCKMARK,TIMEWAY,WORKSPEED,#{userName} AS BACKUPUSER ,#{userId} AS BACKUPUSERID,NOW() AS BACKUPDATE
                FROM aps_process_operation
                WHERE ID=#{id} and PROCESSSTATUS = '20'
                ON DUPLICATE KEY UPDATE DELETED='0'
            </foreach>
        </if>
    </insert>
    <delete id="deletedByBlankId">
        DELETE FROM aps_process_operation_backup
            <where>
                <if test="blankIds != null and blankIds.size() >0">
                    BLANKID in
                    <foreach collection="blankIds" item="id" open="(" close=")" separator=",">
                        #{id}
                    </foreach>
                </if>
                <if test="factoryId != null and factoryId!=''">
                    and TENANTID=#{factoryId}
                </if>
            </where>
    </delete>
    <insert id="processOperationCopy">
        INSERT INTO aps_process_operation_backup (<include refid="Base_Column_List"/>)
        SELECT
        ID,TENANTID,ROPTION,
        DELETED,REMARK,CREATEDATE,
        CREATEUSERID,MODIFYDATE,MODIFYUSERID,
        CREATEUSERNAME,MODIFYUSERNAME,OWNEDFACTORY,
        CRAFTSTEPID,STEPNUM,PROCESSID,
        PROCESSCODE,PROCESS,PROCESSNAME,
        PROCESSWAY,NUMUNIT,ONCEPROCESSVAL,
        ONCEPROCESSMIN,PERTIMECAPACITY,TIMEUNIT,
        PREPRESSWORKMIN,LOADINGMIN,CUTTINGMIN,
        CUTFINISHMIN,MINFLOWBATCH,MINFLOWWAITMIN,
        MAXFLOWWAITMIN,IFBLANKPROCESS,MATERIALCODE,
        MATERIALNAME,THICKNESS,THICKSTR,
        THICKEND,PROWIDTH,WIDTHSTR,
        WIDTHEND,PROLENGTH,LENGTHSTR,
        LENGTHEND,INMATERCONDITION,OUTMATERREQUEST,
        CANCHOOSEDEVICEID,CHOOSEEQU,BLANKID,
        PLANINPUTID,PLANINPUT,PLANOUTPUT,
        PLANINRALL,PLANBLANKRALL,PLANPROCESSRALL,
        PROCESSWORKSHOPID,PROCESSWORKSHOP,PROCESSDEVICEID,
        PROCESSDEVICE,PLANSTARTDATE,ACTUALSTARTDATE,
        PLANENDDATE,ACTUALFINISHDATE,ACTUALIMPUTROLL,
        INPUTUNQUALIFIEDROLL,ACTUALCANPROCESSROLL,CLOSESTATUS,
        SECONDROLL,STARTINGROLL,REPORTROLL,
        CHECKOUTROLL,UNFINISHROLL,CANCELROLL,
        WORKSTATUS,PROCESSSTATUS,BACHMATERIALPROCESS,
        PROCESSTOTALTIME,WAITREPORTID,PLANPROCESSNUM,
        PREVIOUSPROCESSID,PREVIOUSPROCESS,NEXTPROCESSID,
        NEXTPROCESS,LEVEL,PRODUCTTYPEID,
        PRODUCTTYPE,METAL,METALSTATE,
        OUTPUTQUALIFIEDNUM,OUTPUTUNQUALIFIEDNUM,CHANGEINMETER,
        SINGLEROLLWEIGHT,LOCKMARK,
        #{userName} AS BACKUPUSER ,#{userId} AS BACKUPUSERID,NOW() AS BACKUPDATE
        FROM aps_process_operation
        WHERE  PROCESSSTATUS in('20','30','40')
        ON DUPLICATE KEY UPDATE DELETED='0'
    </insert>
</mapper>
