<?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.foreverwin.mesnac.anomaly.mapper.AbnormalPlanMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.anomaly.model.AbnormalPlan">
        <id column="HANDLE" property="handle" />
        <result column="SITE" property="site" />
        <result column="ABNORMAL_NO" property="abnormalNo" />
        <result column="STATUS" property="status" />
        <result column="WORK_CENTER" property="workCenter" />
        <result column="ABNORMAL_METHOD" property="abnormalMethod" />
        <result column="SHOP_ORDER" property="shopOrder" />
        <result column="RESRCE" property="resrce" />
        <result column="ITEM_BO" property="itemBo" />
        <result column="QTY" property="qty" />
        <result column="PROCESSOR" property="processor" />
        <result column="SEND_USER_GROUP" property="sendUserGroup" />
        <result column="SEND_DATE_TIME" property="sendDateTime" />
        <result column="CLOSED_USER" property="closedUser" />
        <result column="CLOSED_DATE_TIME" property="closedDateTime" />
        <result column="CREATED_USER" property="createdUser" />
        <result column="CREATED_DATE_TIME" property="createdDateTime" />
        <result column="MODIFIED_USER" property="modifiedUser" />
        <result column="MODIFIED_DATE_TIME" property="modifiedDateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        HANDLE, SITE, ABNORMAL_NO, STATUS, WORK_CENTER, ABNORMAL_METHOD, SHOP_ORDER, RESRCE, ITEM_BO, QTY, PROCESSOR, SEND_USER_GROUP, SEND_DATE_TIME, CLOSED_USER, CLOSED_DATE_TIME, CREATED_USER, CREATED_DATE_TIME, MODIFIED_USER, MODIFIED_DATE_TIME
    </sql>

    <resultMap id="abnormalPlanDto" type="com.foreverwin.mesnac.anomaly.dto.AbnormalPlanDto" extends="BaseResultMap">
        <result column="ITEM_DESCRIPTION" property="itemDescription"/>
        <result column="FULL_NAME" property="fullName"/>
        <result column="RESRCE_DESCRIPTION" property="resrceDescription"/>
    </resultMap>

    <!-- BaseMapper标准查询/修改/删除 -->
    <select id="selectById" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM Z_ABNORMAL_PLAN WHERE HANDLE=#{handle}
    </select>

    <select id="selectByMap" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_ABNORMAL_PLAN
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </select>

    <select id="selectBatchIds" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_ABNORMAL_PLAN WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </select>

    <select id="selectOne" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include> FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew.entity.handle!=null">
              HANDLE=#{ew.handle}
            </if>
            <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
            <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
            <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
            <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
            <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
            <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
            <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
            <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
            <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
            <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
            <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
            <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
            <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
            <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
            <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
            <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
            <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
            <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
        </where>
    </select>

    <select id="selectCount" resultType="Integer">
        SELECT COUNT(1) FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                <if test="ew.entity.handle!=null">
                    HANDLE=#{ew.entity.handle}
                </if>
                <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectList" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMaps" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectObjs" resultType="Object">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectPage" resultMap="BaseResultMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <select id="selectMapsPage" resultType="HashMap">
        SELECT <choose><when test="ew != null and ew.sqlSelect != null">${ew.sqlSelect}</when><otherwise><include refid="Base_Column_List"></include></otherwise></choose> FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </select>

    <insert id="insert" parameterType="com.foreverwin.mesnac.anomaly.model.AbnormalPlan">
        INSERT INTO Z_ABNORMAL_PLAN
        <trim prefix="(" suffix=")" suffixOverrides=",">
            HANDLE,
            <if test="site!=null">SITE,</if>
            <if test="abnormalNo!=null">ABNORMAL_NO,</if>
            <if test="status!=null">STATUS,</if>
            <if test="workCenter!=null">WORK_CENTER,</if>
            <if test="abnormalMethod!=null">ABNORMAL_METHOD,</if>
            <if test="shopOrder!=null">SHOP_ORDER,</if>
            <if test="resrce!=null">RESRCE,</if>
            <if test="itemBo!=null">ITEM_BO,</if>
            <if test="qty!=null">QTY,</if>
            <if test="processor!=null">PROCESSOR,</if>
            <if test="sendUserGroup!=null">SEND_USER_GROUP,</if>
            <if test="sendDateTime!=null">SEND_DATE_TIME,</if>
            <if test="closedUser!=null">CLOSED_USER,</if>
            <if test="closedDateTime!=null">CLOSED_DATE_TIME,</if>
            <if test="createdUser!=null">CREATED_USER,</if>
            <if test="createdDateTime!=null">CREATED_DATE_TIME,</if>
            <if test="modifiedUser!=null">MODIFIED_USER,</if>
            <if test="modifiedDateTime!=null">MODIFIED_DATE_TIME,</if>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            <if test="site!=null">#{site},</if>
            <if test="abnormalNo!=null">#{abnormalNo},</if>
            <if test="status!=null">#{status},</if>
            <if test="workCenter!=null">#{workCenter},</if>
            <if test="abnormalMethod!=null">#{abnormalMethod},</if>
            <if test="shopOrder!=null">#{shopOrder},</if>
            <if test="resrce!=null">#{resrce},</if>
            <if test="itemBo!=null">#{itemBo},</if>
            <if test="qty!=null">#{qty},</if>
            <if test="processor!=null">#{processor},</if>
            <if test="sendUserGroup!=null">#{sendUserGroup},</if>
            <if test="sendDateTime!=null">#{sendDateTime},</if>
            <if test="closedUser!=null">#{closedUser},</if>
            <if test="closedDateTime!=null">#{closedDateTime},</if>
            <if test="createdUser!=null">#{createdUser},</if>
            <if test="createdDateTime!=null">#{createdDateTime},</if>
            <if test="modifiedUser!=null">#{modifiedUser},</if>
            <if test="modifiedDateTime!=null">#{modifiedDateTime},</if>
        </trim>
    </insert>

    <insert id="insertAllColumn" parameterType="com.foreverwin.mesnac.anomaly.model.AbnormalPlan">
        INSERT INTO Z_ABNORMAL_PLAN
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <include refid="Base_Column_List"></include>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            #{site},
            #{abnormalNo},
            #{status},
            #{workCenter},
            #{abnormalMethod},
            #{shopOrder},
            #{resrce},
            #{itemBo},
            #{qty},
            #{processor},
            #{sendUserGroup},
            #{sendDateTime},
            #{closedUser},
            #{closedDateTime},
            #{createdUser},
            #{createdDateTime},
            #{modifiedUser},
            #{modifiedDateTime},
        </trim>
    </insert>


    <update id="updateById">
        UPDATE Z_ABNORMAL_PLAN <trim prefix="SET" suffixOverrides=",">
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.abnormalNo!=null">ABNORMAL_NO=#{et.abnormalNo},</if>
        <if test="et.status!=null">STATUS=#{et.status},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.abnormalMethod!=null">ABNORMAL_METHOD=#{et.abnormalMethod},</if>
        <if test="et.shopOrder!=null">SHOP_ORDER=#{et.shopOrder},</if>
        <if test="et.resrce!=null">RESRCE=#{et.resrce},</if>
        <if test="et.itemBo!=null">ITEM_BO=#{et.itemBo},</if>
        <if test="et.qty!=null">QTY=#{et.qty},</if>
        <if test="et.processor!=null">PROCESSOR=#{et.processor},</if>
        <if test="et.sendUserGroup!=null">SEND_USER_GROUP=#{et.sendUserGroup},</if>
        <if test="et.sendDateTime!=null">SEND_DATE_TIME=#{et.sendDateTime},</if>
        <if test="et.closedUser!=null">CLOSED_USER=#{et.closedUser},</if>
        <if test="et.closedDateTime!=null">CLOSED_DATE_TIME=#{et.closedDateTime},</if>
        <if test="et.createdUser!=null">CREATED_USER=#{et.createdUser},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
        <if test="et.modifiedUser!=null">MODIFIED_USER=#{et.modifiedUser},</if>
        <if test="et.modifiedDateTime!=null">MODIFIED_DATE_TIME=#{et.modifiedDateTime},</if>
        </trim> WHERE HANDLE=#{et.handle} <if test="et instanceof java.util.Map"><if test="et.MP_OPTLOCK_VERSION_ORIGINAL!=null">and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}</if></if>
    </update>


    <update id="updateAllColumnById">
        UPDATE Z_ABNORMAL_PLAN <trim prefix="SET" suffixOverrides=",">
        SITE=#{et.site},
        ABNORMAL_NO=#{et.abnormalNo},
        STATUS=#{et.status},
        WORK_CENTER=#{et.workCenter},
        ABNORMAL_METHOD=#{et.abnormalMethod},
        SHOP_ORDER=#{et.shopOrder},
        RESRCE=#{et.resrce},
        ITEM_BO=#{et.itemBo},
        QTY=#{et.qty},
        PROCESSOR=#{et.processor},
        SEND_USER_GROUP=#{et.sendUserGroup},
        SEND_DATE_TIME=#{et.sendDateTime},
        CLOSED_USER=#{et.closedUser},
        CLOSED_DATE_TIME=#{et.closedDateTime},
        CREATED_USER=#{et.createdUser},
        CREATED_DATE_TIME=#{et.createdDateTime},
        MODIFIED_USER=#{et.modifiedUser},
        MODIFIED_DATE_TIME=#{et.modifiedDateTime},
     </trim> WHERE HANDLE=#{et.handle} <if test="et instanceof java.util.Map"><if test="et.MP_OPTLOCK_VERSION_ORIGINAL!=null">and ${et.MP_OPTLOCK_VERSION_COLUMN}=#{et.MP_OPTLOCK_VERSION_ORIGINAL}</if></if>
    </update>


    <update id="update">
        UPDATE Z_ABNORMAL_PLAN <trim prefix="SET" suffixOverrides=",">
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.abnormalNo!=null">ABNORMAL_NO=#{et.abnormalNo},</if>
        <if test="et.status!=null">STATUS=#{et.status},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.abnormalMethod!=null">ABNORMAL_METHOD=#{et.abnormalMethod},</if>
        <if test="et.shopOrder!=null">SHOP_ORDER=#{et.shopOrder},</if>
        <if test="et.resrce!=null">RESRCE=#{et.resrce},</if>
        <if test="et.itemBo!=null">ITEM_BO=#{et.itemBo},</if>
        <if test="et.qty!=null">QTY=#{et.qty},</if>
        <if test="et.processor!=null">PROCESSOR=#{et.processor},</if>
        <if test="et.sendUserGroup!=null">SEND_USER_GROUP=#{et.sendUserGroup},</if>
        <if test="et.sendDateTime!=null">SEND_DATE_TIME=#{et.sendDateTime},</if>
        <if test="et.closedUser!=null">CLOSED_USER=#{et.closedUser},</if>
        <if test="et.closedDateTime!=null">CLOSED_DATE_TIME=#{et.closedDateTime},</if>
        <if test="et.createdUser!=null">CREATED_USER=#{et.createdUser},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
        <if test="et.modifiedUser!=null">MODIFIED_USER=#{et.modifiedUser},</if>
        <if test="et.modifiedDateTime!=null">MODIFIED_DATE_TIME=#{et.modifiedDateTime},</if>
    </trim>
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    HANDLE=#{ew.entity.handle}
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </update>

    <delete id="deleteById">
        DELETE FROM Z_ABNORMAL_PLAN WHERE HANDLE=#{handle}
    </delete>

    <delete id="deleteByMap">
        DELETE FROM Z_ABNORMAL_PLAN
        <if test="cm!=null and !cm.isEmpty">
            <where>
                <foreach collection="cm.keys" item="k" separator="AND">
                    <if test="cm[k] != null">
                        ${k} = #{cm[${k}]}
                    </if>
                </foreach>
            </where>
        </if>
    </delete>

    <delete id="delete">
        DELETE FROM Z_ABNORMAL_PLAN
        <where>
            <if test="ew!=null">
                <if test="ew.entity!=null">
                    <if test="ew.entity.handle!=null">
                        HANDLE=#{ew.entity.handle}
                    </if>
                    <if test="ew.entity.site!=null"> AND SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.abnormalNo!=null"> AND ABNORMAL_NO=#{ew.entity.abnormalNo}</if>
                    <if test="ew.entity.status!=null"> AND STATUS=#{ew.entity.status}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.abnormalMethod!=null"> AND ABNORMAL_METHOD=#{ew.entity.abnormalMethod}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.qty!=null"> AND QTY=#{ew.entity.qty}</if>
                    <if test="ew.entity.processor!=null"> AND PROCESSOR=#{ew.entity.processor}</if>
                    <if test="ew.entity.sendUserGroup!=null"> AND SEND_USER_GROUP=#{ew.entity.sendUserGroup}</if>
                    <if test="ew.entity.sendDateTime!=null"> AND SEND_DATE_TIME=#{ew.entity.sendDateTime}</if>
                    <if test="ew.entity.closedUser!=null"> AND CLOSED_USER=#{ew.entity.closedUser}</if>
                    <if test="ew.entity.closedDateTime!=null"> AND CLOSED_DATE_TIME=#{ew.entity.closedDateTime}</if>
                    <if test="ew.entity.createdUser!=null"> AND CREATED_USER=#{ew.entity.createdUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifiedUser!=null"> AND MODIFIED_USER=#{ew.entity.modifiedUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                </if>
                <if test="ew!=null and ew.sqlSegment!=null and ew.nonEmptyOfWhere">
                    ${ew.sqlSegment}
                </if>
            </if>
        </where>
        <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">
            ${ew.sqlSegment}
        </if>
    </delete>

    <delete id="deleteBatchIds">
        DELETE FROM Z_ABNORMAL_PLAN WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </delete>
    <!-- BaseMapper标准查询/修改/删除 -->


    <select id="findAbnormalPlan" resultMap="abnormalPlanDto">
        SELECT  ZAP.ABNORMAL_NO ABNORMAL_NO ,ZAP.ABNORMAL_METHOD ABNORMAL_METHOD ,
        ZAP.SHOP_ORDER SHOP_ORDER ,R.DESCRIPTION RESRCE_DESCRIPTION,ZAP.STATUS STATUS ,
        IT.DESCRIPTION ITEM_DESCRIPTION,ZAP.QTY QTY ,ZNU.FULL_NAME FULL_NAME,
               ZAP.SEND_USER_GROUP SEND_USER_GROUP
        FROM  Z_ABNORMAL_PLAN ZAP
        INNER JOIN Z_ABNORMAL_BILL ZAB  ON ZAB.ABNORMAL_NO = ZAP.ABNORMAL_NO AND ZAB.SITE = #{abnormalPlanDto.site}
                    AND ZAB.TYPE = 'Z'
        LEFT JOIN RESRCE R ON R.RESRCE = ZAP.RESRCE AND R.SITE = ZAP.SITE
        LEFT JOIN ITEM_T IT ON IT.ITEM_BO = ZAP.ITEM_BO AND IT.LOCALE = #{locale}
        LEFT JOIN Z_NWA_USER ZNU ON ZNU.USER_NAME = ZAP.PROCESSOR AND ZNU.SITE = ZAP.SITE
        <where>
            ZAP.SITE =#{abnormalPlanDto.site}
            <if test="abnormalPlanDto.workCenter != null and abnormalPlanDto.workCenter != ''">
                AND ZAP.WORK_CENTER = #{abnormalPlanDto.workCenter}
            </if>
            <if test="abnormalPlanDto.resrce != null and abnormalPlanDto.resrce != ''">
                AND ZAP.RESRCE =#{abnormalPlanDto.resrce}
            </if>
            <if test="abnormalPlanDto.shopOrder != null and abnormalPlanDto.shopOrder != ''">
                AND ZAP.SHOP_ORDER = #{abnormalPlanDto.shopOrder}
            </if>
            <if test="abnormalPlanDto.abnormalNo != null and abnormalPlanDto.abnormalNo != '' ">
                AND ZAP.ABNORMAL_NO = #{abnormalPlanDto.abnormalNo}
            </if>
            <if test="abnormalPlanDto.status != null and abnormalPlanDto.status != ''">
                AND ZAP.STATUS = #{abnormalPlanDto.status}
            </if>
            <if test="abnormalPlanDto.abnormalMethod != null and abnormalPlanDto.abnormalMethod != ''">
                AND ZAP.ABNORMAL_METHOD = #{abnormalPlanDto.abnormalMethod}
            </if>
            <if test="abnormalPlanDto.startDateTime != null ">
                AND ZAP.CLOSED_DATE_TIME &gt;= #{abnormalPlanDto.startDateTime}
            </if>
            <if test="abnormalPlanDto.endDateTime != null">
                AND ZAP.CLOSED_DATE_TIME &lt;= #{abnormalPlanDto.endDateTime}
            </if>
        </where>
    </select>

</mapper>
