<?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.ApsProcessOperationProcessEquBackupDao">

    <resultMap id="BaseResultMap" type="com.rongwei.bsentity.domain.ApsProcessOperationProcessEquBackupDo">
            <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="processid" column="PROCESSID" jdbcType="VARCHAR"/>
            <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="closestatus" column="CLOSESTATUS" jdbcType="VARCHAR"/>
            <result property="planprocessrall" column="PLANPROCESSRALL" 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="workstatus" column="WORKSTATUS" jdbcType="VARCHAR"/>
            <result property="bachmaterialprocess" column="BACHMATERIALPROCESS" jdbcType="VARCHAR"/>
            <result property="waitreportid" column="WAITREPORTID" jdbcType="VARCHAR"/>
            <result property="lockmark" column="LOCKMARK" jdbcType="VARCHAR"/>
            <result property="blankid" column="BLANKID" jdbcType="VARCHAR"/>
            <result property="backupuser" column="BACKUPUSER" jdbcType="VARCHAR"/>
            <result property="backupuserid" column="BACKUPUSERID" jdbcType="VARCHAR"/>
            <result property="backupdate" column="BACKUPDATE" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        ID,TENANTID,ROPTION,
        DELETED,REMARK,CREATEDATE,
        CREATEUSERID,MODIFYDATE,MODIFYUSERID,
        CREATEUSERNAME,MODIFYUSERNAME,OWNEDFACTORY,
        PROCESSID,PROCESSWORKSHOPID,PROCESSWORKSHOP,
        PROCESSDEVICEID,PROCESSDEVICE,PLANSTARTDATE,
        ACTUALSTARTDATE,PLANENDDATE,ACTUALFINISHDATE,
        CLOSESTATUS,PLANPROCESSRALL,STARTINGROLL,
        REPORTROLL,CHECKOUTROLL,UNFINISHROLL,
        WORKSTATUS,BACHMATERIALPROCESS,WAITREPORTID,
        LOCKMARK,BLANKID,BACKUPUSER,
        BACKUPUSERID,BACKUPDATE
    </sql>
    <insert id="processOperationEquBackup">
        <if test="equDos != null and equDos.size() >0">
            <foreach collection="equDos" item="data" separator=";">
                INSERT INTO aps_process_operation_process_equ_backup (<include refid="Base_Column_List"/>)
                VALUES (#{data.id},#{data.tenantid},#{data.roption},
                #{data.deleted},#{data.remark},#{data.createdate},
                #{data.createuserid},#{data.modifydate},#{data.modifyuserid},
                #{data.createusername},#{data.modifyusername},#{data.ownedfactory},
                #{data.processid},#{data.processworkshopid},#{data.processworkshop},
                #{data.processdeviceid},#{data.processdevice},#{data.planstartdate},
                #{data.actualstartdate},#{data.planenddate},#{data.actualfinishdate},
                #{data.closestatus},#{data.planprocessrall},#{data.startingroll},
                #{data.reportroll},#{data.checkoutroll},#{data.unfinishroll},
                #{data.workstatus},#{data.bachmaterialprocess},#{data.waitreportid},
                #{data.lockmark},#{data.blankid},#{userName} ,#{userId} ,NOW())
                ON DUPLICATE KEY UPDATE DELETED='0'
            </foreach>
        </if>
    </insert>

    <delete id="deletedByBlankId">
        DELETE FROM aps_process_operation_process_equ_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="processOperationEquCopy">
        INSERT INTO aps_process_operation_process_equ_backup (<include refid="Base_Column_List"/>)
        SELECT
        ID,TENANTID,ROPTION,
        DELETED,REMARK,CREATEDATE,
        CREATEUSERID,MODIFYDATE,MODIFYUSERID,
        CREATEUSERNAME,MODIFYUSERNAME,OWNEDFACTORY,
        PROCESSID,PROCESSWORKSHOPID,PROCESSWORKSHOP,
        PROCESSDEVICEID,PROCESSDEVICE,PLANSTARTDATE,
        ACTUALSTARTDATE,PLANENDDATE,ACTUALFINISHDATE,
        CLOSESTATUS,PLANPROCESSRALL,STARTINGROLL,
        REPORTROLL,CHECKOUTROLL,UNFINISHROLL,
        WORKSTATUS,BACHMATERIALPROCESS,WAITREPORTID,
        LOCKMARK,BLANKID,#{userName} AS BACKUPUSER ,#{userId} AS BACKUPUSERID,NOW() AS BACKUPDATE
        FROM aps_process_operation_process_equ
        WHERE  DELETED ='0'
          and WORKSTATUS ='待开工'
          AND PROCESSID IN
        <foreach collection="processOperationIds" item="processOperationId" open="(" close=")" separator=",">
            #{processOperationId}
        </foreach>
        ON DUPLICATE KEY UPDATE DELETED='0'
    </insert>
</mapper>
