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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.anomaly.model.AbnormalBill">
        <id column="HANDLE" property="handle" />
        <result column="SITE" property="site" />
        <result column="ABNORMAL_NO" property="abnormalNo" />
        <result column="STATUS" property="status" />
        <result column="CORRECTION" property="correction" />
        <result column="PROGRAM" property="program" />
        <result column="TYPE" property="type" />
        <result column="ITEM_BO" property="itemBo" />
        <result column="SFC" property="sfc" />
        <result column="OPERATION" property="operation" />
        <result column="WORK_CENTER" property="workCenter" />
        <result column="SHOP_ORDER" property="shopOrder" />
        <result column="MESSAGE_TYPE" property="messageType" />
        <result column="RESRCE" property="resrce" />
        <result column="NC_CODE" property="ncCode" />
        <result column="SHUT_DOWN" property="shutDown" />
        <result column="RESPONSE_USER" property="responseUser" />
        <result column="RESPONSE_DATE_TIME" property="responseDateTime" />
        <result column="PB_DESCRIPTION" property="pbDescription" />
        <result column="NC_QTY" property="ncQty" />
        <result column="PB_GRADE" property="pbGrade" />
        <result column="PB_USER" property="pbUser" />
        <result column="PB_QTY" property="pbQty" />
        <result column="REPAIR_DATE_TIME" property="repairDateTime" />
        <result column="DISCOVER" property="discover" />
        <result column="INSPECTOR" property="inspector" />
        <result column="ENTITY_LOCATION" property="entityLocation" />
        <result column="REPORT_FROM" property="reportFrom" />
        <result column="OBJECT_BO" property="objectBo" />
        <result column="PB_PHOTOSHOP" property="pbPhotoshop" />
        <result column="CANCEL_CODE" property="cancelCode" />
        <result column="CANCEL_REASON" property="cancelReason" />
        <result column="CANCEL_DATE_TIME" property="cancelDateTime" />
        <result column="CANCEL_USER" property="cancelUser" />
        <result column="REPORT_SEND_USER_GROUP" property="reportSendUserGroup" />
        <result column="CANCEL_SEND_USER_GROUP" property="cancelSendUserGroup" />
        <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>



    <resultMap id="abnormalBillDto" type="com.foreverwin.mesnac.anomaly.dto.AbnormalBillDto" extends="BaseResultMap">
        <result column="SEQ" property="seq"/>
        <result column="ITEM_DESCRIPTION" property="itemDescription"/>
        <result column="START_DATE_TIME" property="startDateTime"/>
        <result column="END_DATE_TIME" property="endDateTime"/>
        <result column="WORK_CENTER_DESCRIPTION" property="workCenterDescription"/>
        <result column="RESRCE_DESCRIPTION" property="resrceDescription"/>
        <result column="REPORT_USER" property="reportUser"/>
        <result column="ABNORMAL_METHOD" property="abnormalMethod"/>
        <result column="CONFIRM_USER" property="confirmUser"/>
        <result column="RESOLVE_REMARK" property="resolveRemark"/>
        <result column="REPORT_SEND_USER_GROUP" property="reportSendUserGroup"/>
        <result column="NC_CODE_DESCRIPTION" property="ncCodeDescription"/>
    </resultMap>

    <resultMap id="scrapDto" type="com.foreverwin.mesnac.common.dto.ScrapDto" >
        <result column="SFC" property="sfc"/>
        <result column="STATUS" property="status"/>
        <result column="OPERATION" property="operation"/>
        <result column="RESRCE" property="resrce"/>
        <result column="SHOP_ORDER" property="shopOrder"/>
        <result column="ITEM" property="item"/>
        <result column="ROUTER" property="router"/>
        <result column="BOM" property="bom"/>
        <result column="REASON" property="reason"/>
        <result column="TYPE" property="type"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        HANDLE, SITE, ABNORMAL_NO, STATUS, CORRECTION, PROGRAM, TYPE, ITEM_BO, SFC, OPERATION, WORK_CENTER, SHOP_ORDER, MESSAGE_TYPE, RESRCE, NC_CODE, SHUT_DOWN, RESPONSE_USER, RESPONSE_DATE_TIME, PB_DESCRIPTION, NC_QTY, PB_GRADE, PB_USER, PB_QTY, REPAIR_DATE_TIME, DISCOVER, INSPECTOR, ENTITY_LOCATION, REPORT_FROM, OBJECT_BO, PB_PHOTOSHOP, CANCEL_CODE, CANCEL_REASON, CANCEL_DATE_TIME, CANCEL_USER, REPORT_SEND_USER_GROUP, CANCEL_SEND_USER_GROUP, CREATED_USER, CREATED_DATE_TIME, MODIFIED_USER, MODIFIED_DATE_TIME
    </sql>

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

    <select id="selectByMap" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_ABNORMAL_BILL
        <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_BILL 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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
            <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
            <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
            <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
            <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
            <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
            <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
            <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
            <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
            <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
            <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
            <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
            <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
            <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
            <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
            <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
            <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
            <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
            <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
            <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
            <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
            <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
            <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
            <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
            <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
            <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
            <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
            <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
            <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
            <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
            <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
            <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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.AbnormalBill">
        INSERT INTO Z_ABNORMAL_BILL
        <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="correction!=null">CORRECTION,</if>
            <if test="program!=null">PROGRAM,</if>
            <if test="type!=null">TYPE,</if>
            <if test="itemBo!=null">ITEM_BO,</if>
            <if test="sfc!=null">SFC,</if>
            <if test="operation!=null">OPERATION,</if>
            <if test="workCenter!=null">WORK_CENTER,</if>
            <if test="shopOrder!=null">SHOP_ORDER,</if>
            <if test="messageType!=null">MESSAGE_TYPE,</if>
            <if test="resrce!=null">RESRCE,</if>
            <if test="ncCode!=null">NC_CODE,</if>
            <if test="shutDown!=null">SHUT_DOWN,</if>
            <if test="responseUser!=null">RESPONSE_USER,</if>
            <if test="responseDateTime!=null">RESPONSE_DATE_TIME,</if>
            <if test="pbDescription!=null">PB_DESCRIPTION,</if>
            <if test="ncQty!=null">NC_QTY,</if>
            <if test="pbGrade!=null">PB_GRADE,</if>
            <if test="pbUser!=null">PB_USER,</if>
            <if test="pbQty!=null">PB_QTY,</if>
            <if test="repairDateTime!=null">REPAIR_DATE_TIME,</if>
            <if test="discover!=null">DISCOVER,</if>
            <if test="inspector!=null">INSPECTOR,</if>
            <if test="entityLocation!=null">ENTITY_LOCATION,</if>
            <if test="reportFrom!=null">REPORT_FROM,</if>
            <if test="objectBo!=null">OBJECT_BO,</if>
            <if test="pbPhotoshop!=null">PB_PHOTOSHOP,</if>
            <if test="cancelCode!=null">CANCEL_CODE,</if>
            <if test="cancelReason!=null">CANCEL_REASON,</if>
            <if test="cancelDateTime!=null">CANCEL_DATE_TIME,</if>
            <if test="cancelUser!=null">CANCEL_USER,</if>
            <if test="reportSendUserGroup!=null">REPORT_SEND_USER_GROUP,</if>
            <if test="cancelSendUserGroup!=null">CANCEL_SEND_USER_GROUP,</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="correction!=null">#{correction},</if>
            <if test="program!=null">#{program},</if>
            <if test="type!=null">#{type},</if>
            <if test="itemBo!=null">#{itemBo},</if>
            <if test="sfc!=null">#{sfc},</if>
            <if test="operation!=null">#{operation},</if>
            <if test="workCenter!=null">#{workCenter},</if>
            <if test="shopOrder!=null">#{shopOrder},</if>
            <if test="messageType!=null">#{messageType},</if>
            <if test="resrce!=null">#{resrce},</if>
            <if test="ncCode!=null">#{ncCode},</if>
            <if test="shutDown!=null">#{shutDown},</if>
            <if test="responseUser!=null">#{responseUser},</if>
            <if test="responseDateTime!=null">#{responseDateTime},</if>
            <if test="pbDescription!=null">#{pbDescription},</if>
            <if test="ncQty!=null">#{ncQty},</if>
            <if test="pbGrade!=null">#{pbGrade},</if>
            <if test="pbUser!=null">#{pbUser},</if>
            <if test="pbQty!=null">#{pbQty},</if>
            <if test="repairDateTime!=null">#{repairDateTime},</if>
            <if test="discover!=null">#{discover},</if>
            <if test="inspector!=null">#{inspector},</if>
            <if test="entityLocation!=null">#{entityLocation},</if>
            <if test="reportFrom!=null">#{reportFrom},</if>
            <if test="objectBo!=null">#{objectBo},</if>
            <if test="pbPhotoshop!=null">#{pbPhotoshop},</if>
            <if test="cancelCode!=null">#{cancelCode},</if>
            <if test="cancelReason!=null">#{cancelReason},</if>
            <if test="cancelDateTime!=null">#{cancelDateTime},</if>
            <if test="cancelUser!=null">#{cancelUser},</if>
            <if test="reportSendUserGroup!=null">#{reportSendUserGroup},</if>
            <if test="cancelSendUserGroup!=null">#{cancelSendUserGroup},</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.AbnormalBill">
        INSERT INTO Z_ABNORMAL_BILL
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <include refid="Base_Column_List"></include>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            #{site},
            #{abnormalNo},
            #{status},
            #{correction},
            #{program},
            #{type},
            #{itemBo},
            #{sfc},
            #{operation},
            #{workCenter},
            #{shopOrder},
            #{messageType},
            #{resrce},
            #{ncCode},
            #{shutDown},
            #{responseUser},
            #{responseDateTime},
            #{pbDescription},
            #{ncQty},
            #{pbGrade},
            #{pbUser},
            #{pbQty},
            #{repairDateTime},
            #{discover},
            #{inspector},
            #{entityLocation},
            #{reportFrom},
            #{objectBo},
            #{pbPhotoshop},
            #{cancelCode},
            #{cancelReason},
            #{cancelDateTime},
            #{cancelUser},
            #{reportSendUserGroup},
            #{cancelSendUserGroup},
            #{createdUser},
            #{createdDateTime},
            #{modifiedUser},
            #{modifiedDateTime},
        </trim>
    </insert>


    <update id="updateById">
        UPDATE Z_ABNORMAL_BILL <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.correction!=null">CORRECTION=#{et.correction},</if>
        <if test="et.program!=null">PROGRAM=#{et.program},</if>
        <if test="et.type!=null">TYPE=#{et.type},</if>
        <if test="et.itemBo!=null">ITEM_BO=#{et.itemBo},</if>
        <if test="et.sfc!=null">SFC=#{et.sfc},</if>
        <if test="et.operation!=null">OPERATION=#{et.operation},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.shopOrder!=null">SHOP_ORDER=#{et.shopOrder},</if>
        <if test="et.messageType!=null">MESSAGE_TYPE=#{et.messageType},</if>
        <if test="et.resrce!=null">RESRCE=#{et.resrce},</if>
        <if test="et.ncCode!=null">NC_CODE=#{et.ncCode},</if>
        <if test="et.shutDown!=null">SHUT_DOWN=#{et.shutDown},</if>
        <if test="et.responseUser!=null">RESPONSE_USER=#{et.responseUser},</if>
        <if test="et.responseDateTime!=null">RESPONSE_DATE_TIME=#{et.responseDateTime},</if>
        <if test="et.pbDescription!=null">PB_DESCRIPTION=#{et.pbDescription},</if>
        <if test="et.ncQty!=null">NC_QTY=#{et.ncQty},</if>
        <if test="et.pbGrade!=null">PB_GRADE=#{et.pbGrade},</if>
        <if test="et.pbUser!=null">PB_USER=#{et.pbUser},</if>
        <if test="et.pbQty!=null">PB_QTY=#{et.pbQty},</if>
        <if test="et.repairDateTime!=null">REPAIR_DATE_TIME=#{et.repairDateTime},</if>
        <if test="et.discover!=null">DISCOVER=#{et.discover},</if>
        <if test="et.inspector!=null">INSPECTOR=#{et.inspector},</if>
        <if test="et.entityLocation!=null">ENTITY_LOCATION=#{et.entityLocation},</if>
        <if test="et.reportFrom!=null">REPORT_FROM=#{et.reportFrom},</if>
        <if test="et.objectBo!=null">OBJECT_BO=#{et.objectBo},</if>
        <if test="et.pbPhotoshop!=null">PB_PHOTOSHOP=#{et.pbPhotoshop},</if>
        <if test="et.cancelCode!=null">CANCEL_CODE=#{et.cancelCode},</if>
        <if test="et.cancelReason!=null">CANCEL_REASON=#{et.cancelReason},</if>
        <if test="et.cancelDateTime!=null">CANCEL_DATE_TIME=#{et.cancelDateTime},</if>
        <if test="et.cancelUser!=null">CANCEL_USER=#{et.cancelUser},</if>
        <if test="et.reportSendUserGroup!=null">REPORT_SEND_USER_GROUP=#{et.reportSendUserGroup},</if>
        <if test="et.cancelSendUserGroup!=null">CANCEL_SEND_USER_GROUP=#{et.cancelSendUserGroup},</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_BILL <trim prefix="SET" suffixOverrides=",">
        SITE=#{et.site},
        ABNORMAL_NO=#{et.abnormalNo},
        STATUS=#{et.status},
        CORRECTION=#{et.correction},
        PROGRAM=#{et.program},
        TYPE=#{et.type},
        ITEM_BO=#{et.itemBo},
        SFC=#{et.sfc},
        OPERATION=#{et.operation},
        WORK_CENTER=#{et.workCenter},
        SHOP_ORDER=#{et.shopOrder},
        MESSAGE_TYPE=#{et.messageType},
        RESRCE=#{et.resrce},
        NC_CODE=#{et.ncCode},
        SHUT_DOWN=#{et.shutDown},
        RESPONSE_USER=#{et.responseUser},
        RESPONSE_DATE_TIME=#{et.responseDateTime},
        PB_DESCRIPTION=#{et.pbDescription},
        NC_QTY=#{et.ncQty},
        PB_GRADE=#{et.pbGrade},
        PB_USER=#{et.pbUser},
        PB_QTY=#{et.pbQty},
        REPAIR_DATE_TIME=#{et.repairDateTime},
        DISCOVER=#{et.discover},
        INSPECTOR=#{et.inspector},
        ENTITY_LOCATION=#{et.entityLocation},
        REPORT_FROM=#{et.reportFrom},
        OBJECT_BO=#{et.objectBo},
        PB_PHOTOSHOP=#{et.pbPhotoshop},
        CANCEL_CODE=#{et.cancelCode},
        CANCEL_REASON=#{et.cancelReason},
        CANCEL_DATE_TIME=#{et.cancelDateTime},
        CANCEL_USER=#{et.cancelUser},
        REPORT_SEND_USER_GROUP=#{et.reportSendUserGroup},
        CANCEL_SEND_USER_GROUP=#{et.cancelSendUserGroup},
        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_BILL <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.correction!=null">CORRECTION=#{et.correction},</if>
        <if test="et.program!=null">PROGRAM=#{et.program},</if>
        <if test="et.type!=null">TYPE=#{et.type},</if>
        <if test="et.itemBo!=null">ITEM_BO=#{et.itemBo},</if>
        <if test="et.sfc!=null">SFC=#{et.sfc},</if>
        <if test="et.operation!=null">OPERATION=#{et.operation},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.shopOrder!=null">SHOP_ORDER=#{et.shopOrder},</if>
        <if test="et.messageType!=null">MESSAGE_TYPE=#{et.messageType},</if>
        <if test="et.resrce!=null">RESRCE=#{et.resrce},</if>
        <if test="et.ncCode!=null">NC_CODE=#{et.ncCode},</if>
        <if test="et.shutDown!=null">SHUT_DOWN=#{et.shutDown},</if>
        <if test="et.responseUser!=null">RESPONSE_USER=#{et.responseUser},</if>
        <if test="et.responseDateTime!=null">RESPONSE_DATE_TIME=#{et.responseDateTime},</if>
        <if test="et.pbDescription!=null">PB_DESCRIPTION=#{et.pbDescription},</if>
        <if test="et.ncQty!=null">NC_QTY=#{et.ncQty},</if>
        <if test="et.pbGrade!=null">PB_GRADE=#{et.pbGrade},</if>
        <if test="et.pbUser!=null">PB_USER=#{et.pbUser},</if>
        <if test="et.pbQty!=null">PB_QTY=#{et.pbQty},</if>
        <if test="et.repairDateTime!=null">REPAIR_DATE_TIME=#{et.repairDateTime},</if>
        <if test="et.discover!=null">DISCOVER=#{et.discover},</if>
        <if test="et.inspector!=null">INSPECTOR=#{et.inspector},</if>
        <if test="et.entityLocation!=null">ENTITY_LOCATION=#{et.entityLocation},</if>
        <if test="et.reportFrom!=null">REPORT_FROM=#{et.reportFrom},</if>
        <if test="et.objectBo!=null">OBJECT_BO=#{et.objectBo},</if>
        <if test="et.pbPhotoshop!=null">PB_PHOTOSHOP=#{et.pbPhotoshop},</if>
        <if test="et.cancelCode!=null">CANCEL_CODE=#{et.cancelCode},</if>
        <if test="et.cancelReason!=null">CANCEL_REASON=#{et.cancelReason},</if>
        <if test="et.cancelDateTime!=null">CANCEL_DATE_TIME=#{et.cancelDateTime},</if>
        <if test="et.cancelUser!=null">CANCEL_USER=#{et.cancelUser},</if>
        <if test="et.reportSendUserGroup!=null">REPORT_SEND_USER_GROUP=#{et.reportSendUserGroup},</if>
        <if test="et.cancelSendUserGroup!=null">CANCEL_SEND_USER_GROUP=#{et.cancelSendUserGroup},</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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL WHERE HANDLE=#{handle}
    </delete>

    <delete id="deleteByMap">
        DELETE FROM Z_ABNORMAL_BILL
        <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_BILL
        <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.correction!=null"> AND CORRECTION=#{ew.entity.correction}</if>
                    <if test="ew.entity.program!=null"> AND PROGRAM=#{ew.entity.program}</if>
                    <if test="ew.entity.type!=null"> AND TYPE=#{ew.entity.type}</if>
                    <if test="ew.entity.itemBo!=null"> AND ITEM_BO=#{ew.entity.itemBo}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.operation!=null"> AND OPERATION=#{ew.entity.operation}</if>
                    <if test="ew.entity.workCenter!=null"> AND WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.shopOrder!=null"> AND SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.messageType!=null"> AND MESSAGE_TYPE=#{ew.entity.messageType}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.shutDown!=null"> AND SHUT_DOWN=#{ew.entity.shutDown}</if>
                    <if test="ew.entity.responseUser!=null"> AND RESPONSE_USER=#{ew.entity.responseUser}</if>
                    <if test="ew.entity.responseDateTime!=null"> AND RESPONSE_DATE_TIME=#{ew.entity.responseDateTime}</if>
                    <if test="ew.entity.pbDescription!=null"> AND PB_DESCRIPTION=#{ew.entity.pbDescription}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.pbGrade!=null"> AND PB_GRADE=#{ew.entity.pbGrade}</if>
                    <if test="ew.entity.pbUser!=null"> AND PB_USER=#{ew.entity.pbUser}</if>
                    <if test="ew.entity.pbQty!=null"> AND PB_QTY=#{ew.entity.pbQty}</if>
                    <if test="ew.entity.repairDateTime!=null"> AND REPAIR_DATE_TIME=#{ew.entity.repairDateTime}</if>
                    <if test="ew.entity.discover!=null"> AND DISCOVER=#{ew.entity.discover}</if>
                    <if test="ew.entity.inspector!=null"> AND INSPECTOR=#{ew.entity.inspector}</if>
                    <if test="ew.entity.entityLocation!=null"> AND ENTITY_LOCATION=#{ew.entity.entityLocation}</if>
                    <if test="ew.entity.reportFrom!=null"> AND REPORT_FROM=#{ew.entity.reportFrom}</if>
                    <if test="ew.entity.objectBo!=null"> AND OBJECT_BO=#{ew.entity.objectBo}</if>
                    <if test="ew.entity.pbPhotoshop!=null"> AND PB_PHOTOSHOP=#{ew.entity.pbPhotoshop}</if>
                    <if test="ew.entity.cancelCode!=null"> AND CANCEL_CODE=#{ew.entity.cancelCode}</if>
                    <if test="ew.entity.cancelReason!=null"> AND CANCEL_REASON=#{ew.entity.cancelReason}</if>
                    <if test="ew.entity.cancelDateTime!=null"> AND CANCEL_DATE_TIME=#{ew.entity.cancelDateTime}</if>
                    <if test="ew.entity.cancelUser!=null"> AND CANCEL_USER=#{ew.entity.cancelUser}</if>
                    <if test="ew.entity.reportSendUserGroup!=null"> AND REPORT_SEND_USER_GROUP=#{ew.entity.reportSendUserGroup}</if>
                    <if test="ew.entity.cancelSendUserGroup!=null"> AND CANCEL_SEND_USER_GROUP=#{ew.entity.cancelSendUserGroup}</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_BILL WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </delete>
    <!-- BaseMapper标准查询/修改/删除 -->


    <select id="backLog" resultMap="abnormalBillDto">
        SELECT ROW_NUMBER() OVER(ORDER BY ZAB.ABNORMAL_NO ASC) SEQ,ZAB.ABNORMAL_NO ABNORMAL_NO,
        ZAB.STATUS STATUS, IT.DESCRIPTION ITEM_DESCRIPTION, ZAB.CREATED_DATE_TIME CREATED_DATE_TIME,
        ZAB.RESPONSE_DATE_TIME RESPONSE_DATE_TIME,
        ZNU.FULL_NAME CREATED_USER,
        ZAB.NC_CODE NC_CODE,ZAB.PB_DESCRIPTION PB_DESCRIPTION,
        SUBSTR(LISTAGG(NCT.DESCRIPTION || ',') WITHIN GROUP(ORDER BY ZAB.ABNORMAL_NO),0,LENGTH(LISTAGG(NCT.DESCRIPTION || ',') WITHIN GROUP(ORDER BY ZAB.ABNORMAL_NO))-1) NC_CODE_DESCRIPTION
        FROM Z_ABNORMAL_BILL ZAB
        LEFT JOIN Z_ABNORMAL_BILL_DISPOSE ZABD ON ZABD.ABNORMAL_BILL_BO = ZAB.HANDLE
        LEFT JOIN ITEM I ON ZAB.ITEM_BO = I.HANDLE
        LEFT JOIN ITEM_T IT ON I.HANDLE = IT.ITEM_BO AND IT.LOCALE = #{language}
        LEFT JOIN Z_NWA_USER ZNU ON ZNU.USER_NAME = ZAB.CREATED_USER AND ZNU.SITE = ZAB.SITE
        LEFT JOIN SHOP_ORDER SO ON SO.SHOP_ORDER = ZAB.SHOP_ORDER AND SO.SITE = ZAB.SITE
        LEFT JOIN CUSTOM_FIELDS CF ON CF.HANDLE = SO.HANDLE AND CF."ATTRIBUTE" = 'WORK_ORDER'
        LEFT JOIN Z_ABNORMAL_NC_CODE ZANC ON ZANC.ABNORMAL_BILL_BO = ZAB.HANDLE
        LEFT JOIN NC_CODE_T NCT ON NCT.NC_CODE_BO = 'NCCodeBO:'|| ZAB.SITE || ',' || ZANC.NC_CODE  AND NCT.LOCALE = #{language}
        <where>
            <if test="abnormalBill != null">
                <if test="abnormalBill.site != null and abnormalBill.site != ''">
                    zab.SITE = #{abnormalBill.site}
                </if>
                <if test="abnormalBill.resrce != null and abnormalBill.resrce != ''">
                    AND zab.RESRCE = #{abnormalBill.resrce}
                </if>
                <if test="abnormalBill.shopOrder != null and abnormalBill.shopOrder != ''">
                    AND zab.SHOP_ORDER = #{abnormalBill.shopOrder}
                </if>
                <if test="abnormalBill.abnormalNo != null and abnormalBill.abnormalNo != ''">
                    AND zab.ABNORMAL_NO = #{abnormalBill.abnormalNo}
                </if>
                <if test="abnormalBill.status != null and abnormalBill.status != ''">
                    AND zab.STATUS = #{abnormalBill.status}
                </if>
                <if test="abnormalBill.startDateTime != null ">
                    AND zab.CREATED_DATE_TIME &gt;= #{abnormalBill.startDateTime}
                </if>
                <if test="abnormalBill.endDateTime != null">
                    AND zab.CREATED_DATE_TIME &lt;= #{abnormalBill.endDateTime}
                </if>
                <if test="abnormalBill.workCenter != null and abnormalBill.workCenter != ''">
                    AND zab.WORK_CENTER = #{abnormalBill.workCenter}
                </if>
                <if test="abnormalBill.type != null and abnormalBill.type != ''">
                    AND zab.TYPE = #{abnormalBill.type}
                </if>
                <if test="abnormalBill.reportFrom != null and abnormalBill.reportFrom != ''">
                    AND zab.REPORT_FROM = #{abnormalBill.reportFrom}
                </if>
                <if test="abnormalBill.workOrder != null and abnormalBill.workOrder != ''">
                    AND CF.VALUE LIKE '%${abnormalBill.workOrder}%'
                </if>
                <choose>
                    <when test="userGroupList != null and userGroupList.size != 0">
                         AND ZAB.REPORT_SEND_USER_GROUP IN
                        <foreach item="item" index="index" collection="userGroupList" separator="," open="(" close=")">
                            UPPER(#{item.userGroup})
                        </foreach>

<!--                        OR ZAB.STATUS =-->
<!--                        CASE WHEN ZAB.STATUS = 'X' AND ZAB.REPORT_SEND_USER_GROUP IN-->
<!--                        <foreach item="item" index="index" collection="userGroupList" separator="," open="(" close=")">-->
<!--                            UPPER(#{item.userGroup})-->
<!--                        </foreach>-->
<!--                        THEN-->
<!--                        'X'-->
<!--                        END-->

<!--                        OR ZAB.STATUS =-->
<!--                        CASE WHEN ZAB.STATUS = 'Q' AND ZAB.CANCEL_SEND_USER_GROUP IN-->
<!--                        <foreach item="item" index="index" collection="userGroupList" separator="," open="(" close=")">-->
<!--                            UPPER(#{item.userGroup})-->
<!--                        </foreach>-->
<!--                        THEN-->
<!--                        'Q'-->
<!--                        END-->

<!--                        OR ZAB.STATUS =-->
<!--                        CASE WHEN ZAB.STATUS = 'J' AND ZABD.DUTY_SEND_USER_GROUP IN-->
<!--                        <foreach item="item" index="index" collection="userGroupList" separator="," open="(" close=")">-->
<!--                            UPPER(#{item.userGroup})-->
<!--                        </foreach>-->
<!--                        THEN-->
<!--                        'J'-->
<!--                        END-->

<!--                        OR ZAB.STATUS =-->
<!--                        CASE WHEN ZAB.STATUS = 'F' AND ZABD.RESOLVE_SEND_USER_GROUP IN-->
<!--                        <foreach item="item" index="index" collection="userGroupList" separator="," open="(" close=")">-->
<!--                            UPPER(#{item.userGroup})-->
<!--                        </foreach>-->
<!--                        THEN-->
<!--                        'F'-->
<!--                        END)-->
                    </when>
                    <otherwise>
                        <if test="userGroupList == null">

                        </if>
                        <if test="userGroupList != null and userGroupList.size == 0">
                            AND 1 == 2
                        </if>
                    </otherwise>
                </choose>
            </if>
        </where>
        GROUP BY zab.ABNORMAL_NO,zab.STATUS,it.DESCRIPTION,zab.CREATED_DATE_TIME,zab.RESPONSE_DATE_TIME,
        ZNU.FULL_NAME,zab.NC_CODE,zab.PB_DESCRIPTION
    </select>

    <select id="findAllByAbnormalNoDevice" resultMap="abnormalBillDto">
        SELECT ZAB.ABNORMAL_NO ABNORMAL_NO , ZAB.STATUS STATUS ,ZAB.REPORT_FROM  REPORT_FROM ,WCT.DESCRIPTION  WORK_CENTER_DESCRIPTION,
        ZAB.RESRCE RESRCE ,R.DESCRIPTION RESRCE_DESCRIPTION,ZNU.FULL_NAME REPORT_USER,ZAB.MESSAGE_TYPE MESSAGE_TYPE ,
        ZAB.NC_CODE  NC_CODE ,ZAB.PB_DESCRIPTION PB_DESCRIPTION ,ZAB.SHUT_DOWN SHUT_DOWN ,ZAB.RESPONSE_USER RESPONSE_USER,ZAB.RESPONSE_DATE_TIME RESPONSE_DATE_TIME,
        ZABD.ABNORMAL_METHOD ABNORMAL_METHOD,ZNU3.FULL_NAME CONFIRM_USER,ZABD.RESOLVE_REMARK RESOLVE_REMARK,
        ZAB.CANCEL_CODE CANCEL_CODE,ZAB.CANCEL_DATE_TIME CANCEL_DATE_TIME,ZNU4.FULL_NAME CANCEL_USER,ZAB.CANCEL_REASON CANCEL_REASON,
        ZAB.REPORT_SEND_USER_GROUP REPORT_SEND_USER_GROUP,
        SUBSTR(LISTAGG(NCT.DESCRIPTION || ',') WITHIN GROUP(ORDER BY ZAB.ABNORMAL_NO),0,LENGTH(LISTAGG(NCT.DESCRIPTION || ',') WITHIN GROUP(ORDER BY ZAB.ABNORMAL_NO))-1) NC_CODE_DESCRIPTION
        FROM
        Z_ABNORMAL_BILL ZAB
        INNER JOIN Z_ABNORMAL_BILL_DISPOSE ZABD ON ZABD.ABNORMAL_BILL_BO  = ZAB.HANDLE
        INNER JOIN RESRCE R ON R.RESRCE = ZAB.RESRCE AND R.SITE = ZAB.SITE
        LEFT JOIN Z_ABNORMAL_NC_CODE zanc ON  zanc.ABNORMAL_BILL_BO = ZAB.HANDLE
        LEFT JOIN NC_CODE_T NCT ON NCT.NC_CODE_BO = 'NCCodeBO:'|| ZAB.SITE || ',' || ZANC.NC_CODE  AND NCT.LOCALE = #{language}
        LEFT JOIN WORK_CENTER_T WCT ON WCT.WORK_CENTER_BO  = ('WorkCenterBO:' || ZAB.SITE || ',' || ZAB.WORK_CENTER) AND WCT.LOCALE =#{language}
        LEFT JOIN Z_NWA_USER ZNU ON ZNU.USER_NAME  = ZAB.CREATED_USER AND ZNU.SITE = ZAB.SITE
        LEFT JOIN Z_NWA_USER ZNU2 ON ZNU2.USER_NAME = ZAB.RESPONSE_USER AND  ZNU2.SITE = ZAB.SITE
        LEFT JOIN Z_NWA_USER ZNU3 ON ZNU3.USER_NAME = ZABD.RESOLVE_USER AND  ZNU3.SITE = ZAB.SITE
        LEFT JOIN Z_NWA_USER ZNU4 ON ZNU4.USER_NAME = ZAB.CANCEL_USER AND  ZNU4.SITE = ZAB.SITE
        <where>
            <if test="abnormalBill != null">
                <if test="abnormalBill.site != null and abnormalBill.site != ''">
                    ZAB.SITE = #{abnormalBill.site}
                </if>
                <if test="abnormalBill.abnormalNo != null and abnormalBill.abnormalNo != ''">
                    AND ZAB.ABNORMAL_NO = #{abnormalBill.abnormalNo}
                </if>
            </if>
        </where>
        GROUP BY
        ZAB.ABNORMAL_NO , ZAB.STATUS  ,ZAB.REPORT_FROM   ,WCT.DESCRIPTION ,
        ZAB.RESRCE  ,R.DESCRIPTION ,ZNU.FULL_NAME ,ZAB.MESSAGE_TYPE  ,
        ZAB.NC_CODE   ,ZAB.PB_DESCRIPTION  ,ZAB.SHUT_DOWN  ,ZAB.RESPONSE_USER ,ZAB.RESPONSE_DATE_TIME ,
        ZABD.ABNORMAL_METHOD ,ZNU3.FULL_NAME ,ZABD.RESOLVE_REMARK ,
        ZAB.CANCEL_CODE ,ZAB.CANCEL_DATE_TIME ,ZNU4.FULL_NAME ,ZAB.CANCEL_REASON ,
        ZAB.REPORT_SEND_USER_GROUP
    </select>

    <select id="findCountBySfc" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_ABNORMAL_BILL
        <where>
            <if test="site != null and site != ''">
                SITE = #{site}
            </if>
            <if test="status != null and status.size() != 0">
                AND  STATUS NOT IN
                <foreach collection="status" item="item" index="index" separator="," open="(" close=")">
                    #{item}
                </foreach>
            </if>
            <if test="type != null and type != ''">
                AND "TYPE" = #{type}
            </if>
            <if test="sfc != null and sfc != ''">
                AND SFC = #{sfc}
            </if>

        </where>
    </select>

    <select id="findAbnormalMethodBySFC" resultType="int">
        SELECT COUNT(*)
        FROM Z_ABNORMAL_BILL_VIEW zabv
        WHERE  SITE = #{site} AND  SFC = #{sfc} AND ABNORMAL_METHOD = 'C'
    </select>

    <select id="findScrapDtoBySfc" resultMap="scrapDto">
        SELECT   S.SFC SFC,
        S2.STATUS STATUS,
        SUBSTR(SS.OPERATION_BO ,INSTR(SS.OPERATION_BO ,',',1)+1,(INSTR(SS.OPERATION_BO ,'#',1)-1)-(INSTR(SS.OPERATION_BO ,',',1)+1)) || '/' || SS.STEP_ID OPERATION,
        ZSD2.RESRCE RESRCE,ZSD2.SHOP_ORDER SHOP_ORDER,
        CASE WHEN I.ITEM != 'NULL'  THEN I.ITEM || '/' || I.REVISION END ITEM,
        CASE WHEN R.ROUTER != 'NULL'  THEN R.ROUTER || '/' || R.REVISION END ROUTER ,
        CASE WHEN B.BOM != 'NULL'  THEN B.BOM || '/' || B.REVISION END BOM,
        CASE WHEN ZSS.HANDLE != 'NULL' THEN ZSS.REASON
        ELSE ZABV.PB_DESCRIPTION
        END REASON,
        ZSS.TYPE TYPE
        FROM SFC S
        INNER JOIN SFC_ROUTING SR ON SR.SFC_BO  = S.HANDLE
        INNER JOIN SFC_ROUTER ST ON ST.SFC_ROUTING_BO  = SR.HANDLE
        INNER JOIN SFC_STEP SS ON SS.SFC_ROUTER_BO = ST.HANDLE/* AND (SS.QTY_IN_QUEUE > 0 OR SS.QTY_IN_WORK > 0)*/
        INNER JOIN STATUS S2 ON S2.HANDLE = S.STATUS_BO
        LEFT JOIN Z_SFC_DISPATCH ZSD2 ON ZSD2.DISPATCH_NO = S.SFC || '-' || SS.STEP_ID
                                      AND ZSD2.DISPATCH_STATUS IN ('START','COMPLETE')
        LEFT JOIN SHOP_ORDER SO ON SO.SHOP_ORDER = ZSD2.SHOP_ORDER AND SO.SITE = S.SITE
        LEFT JOIN ITEM I ON I.HANDLE = SO.PLANNED_ITEM_BO
        LEFT JOIN ROUTER R ON R.HANDLE  = ZSD2.ROUTER_BO
        LEFT JOIN Z_SFC_SCRAP ZSS ON ZSS.SFC = S.SFC AND ZSS.SITE = S.SITE
        LEFT JOIN BOM B ON B.HANDLE = SO.PLANNED_BOM_BO
        INNER JOIN ( SELECT * FROM Z_ABNORMAL_BILL_VIEW ZABV  WHERE ZABV.HANDLE = (SELECT MAX(HANDLE) FROM Z_ABNORMAL_BILL_VIEW ZABV2
        <where>
            ZABV2.SFC = #{sfc}
        </where>
        )) ZABV ON ZABV.SFC = S.SFC AND ZABV.SITE= S.SITE
        <where>
            S.SITE = #{site} AND S.SFC = #{sfc}
        </where>
    </select>

    <select id="getQCAbnormalList" resultMap="BaseResultMap">
        SELECT * FROM Z_ABNORMAL_BILL zab
                          JOIN sfc s ON zab.SITE=s.SITE AND zab.SFC=s.SFC
                          JOIN Z_ABNORMAL_BILL_DISPOSE ZABD ON ZABD.ABNORMAL_BILL_BO= ZAB.HANDLE
        WHERE zab.SITE=#{site} AND zab.STATUS='G' AND zab."TYPE"='Z'   AND s.QTY>1 AND (ZABD.ABNORMAL_METHOD='F'  OR  ZABD.ABNORMAL_METHOD='C')  ORDER BY  ZABD.CLOSED_DATE_TIME DESC
    </select>

</mapper>
