<?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.quality.mapper.SelfReportMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.foreverwin.mesnac.quality.model.SelfReport">
        <id column="HANDLE" property="handle" />
        <result column="SITE" property="site" />
        <result column="TASK_NO" property="taskNo" />
        <result column="WORK_CENTER" property="workCenter" />
        <result column="SHOP_ORDER" property="shopOrder" />
        <result column="ITEM" property="item" />
        <result column="OP_STEP" property="opStep" />
        <result column="RESRCE" property="resrce" />
        <result column="SFC" property="sfc" />
        <result column="NC_CODE" property="ncCode" />
        <result column="NC_QTY" property="ncQty" />
        <result column="LOCATION" property="location" />
        <result column="STATE" property="state" />
        <result column="REMARK" property="remark" />
        <result column="CREATE_USER" property="createUser" />
        <result column="CREATED_DATE_TIME" property="createdDateTime" />
        <result column="MODIFY_USER" property="modifyUser" />
        <result column="MODIFIED_DATE_TIME" property="modifiedDateTime" />
        <result column="NC_CODE_DESC" property="ncCodeDesc" />
        <result column="REPORT_USER_GROUP" property="reportUserGroup" />
        <result column="PB_USER" property="pbUser" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        HANDLE, SITE, TASK_NO, WORK_CENTER, SHOP_ORDER, ITEM, OP_STEP, RESRCE, SFC, NC_CODE, NC_QTY, LOCATION, STATE, REMARK, CREATE_USER, CREATED_DATE_TIME, MODIFY_USER, MODIFIED_DATE_TIME, NC_CODE_DESC, REPORT_USER_GROUP
    </sql>

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

    <select id="selectByMap" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List"></include>
        FROM Z_SELF_REPORT
        <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_SELF_REPORT 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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
            <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
            <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
            <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
            <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
            <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
            <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
            <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
            <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
            <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
            <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
            <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
            <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
            <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
            <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</if>
        </where>
    </select>

    <select id="selectCount" resultType="Integer">
        SELECT COUNT(1) FROM Z_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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.quality.model.SelfReport">
        INSERT INTO Z_SELF_REPORT
        <trim prefix="(" suffix=")" suffixOverrides=",">
            HANDLE,
            <if test="site!=null">SITE,</if>
            <if test="taskNo!=null">TASK_NO,</if>
            <if test="workCenter!=null">WORK_CENTER,</if>
            <if test="shopOrder!=null">SHOP_ORDER,</if>
            <if test="item!=null">ITEM,</if>
            <if test="opStep!=null">OP_STEP,</if>
            <if test="resrce!=null">RESRCE,</if>
            <if test="sfc!=null">SFC,</if>
            <if test="ncCode!=null">NC_CODE,</if>
            <if test="ncQty!=null">NC_QTY,</if>
            <if test="location!=null">LOCATION,</if>
            <if test="state!=null">STATE,</if>
            <if test="remark!=null">REMARK,</if>
            <if test="createUser!=null">CREATE_USER,</if>
            <if test="createdDateTime!=null">CREATED_DATE_TIME,</if>
            <if test="modifyUser!=null">MODIFY_USER,</if>
            <if test="modifiedDateTime!=null">MODIFIED_DATE_TIME,</if>
            <if test="ncCodeDesc!=null">NC_CODE_DESC,</if>
            <if test="reportUserGroup!=null">REPORT_USER_GROUP,</if>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            <if test="site!=null">#{site},</if>
            <if test="taskNo!=null">#{taskNo},</if>
            <if test="workCenter!=null">#{workCenter},</if>
            <if test="shopOrder!=null">#{shopOrder},</if>
            <if test="item!=null">#{item},</if>
            <if test="opStep!=null">#{opStep},</if>
            <if test="resrce!=null">#{resrce},</if>
            <if test="sfc!=null">#{sfc},</if>
            <if test="ncCode!=null">#{ncCode},</if>
            <if test="ncQty!=null">#{ncQty},</if>
            <if test="location!=null">#{location},</if>
            <if test="state!=null">#{state},</if>
            <if test="remark!=null">#{remark},</if>
            <if test="createUser!=null">#{createUser},</if>
            <if test="createdDateTime!=null">#{createdDateTime},</if>
            <if test="modifyUser!=null">#{modifyUser},</if>
            <if test="modifiedDateTime!=null">#{modifiedDateTime},</if>
            <if test="ncCodeDesc!=null">#{ncCodeDesc},</if>
            <if test="reportUserGroup!=null">#{reportUserGroup},</if>
        </trim>
    </insert>

    <insert id="insertAllColumn" parameterType="com.foreverwin.mesnac.quality.model.SelfReport">
        INSERT INTO Z_SELF_REPORT
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <include refid="Base_Column_List"></include>
        </trim> VALUES
        <trim prefix="(" suffix=")" suffixOverrides=",">
            #{handle},
            #{site},
            #{taskNo},
            #{workCenter},
            #{shopOrder},
            #{item},
            #{opStep},
            #{resrce},
            #{sfc},
            #{ncCode},
            #{ncQty},
            #{location},
            #{state},
            #{remark},
            #{createUser},
            #{createdDateTime},
            #{modifyUser},
            #{modifiedDateTime},
            #{ncCodeDesc},
            #{reportUserGroup},
        </trim>
    </insert>


    <update id="updateById">
        UPDATE Z_SELF_REPORT <trim prefix="SET" suffixOverrides=",">
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.taskNo!=null">TASK_NO=#{et.taskNo},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.shopOrder!=null">SHOP_ORDER=#{et.shopOrder},</if>
        <if test="et.item!=null">ITEM=#{et.item},</if>
        <if test="et.opStep!=null">OP_STEP=#{et.opStep},</if>
        <if test="et.resrce!=null">RESRCE=#{et.resrce},</if>
        <if test="et.sfc!=null">SFC=#{et.sfc},</if>
        <if test="et.ncCode!=null">NC_CODE=#{et.ncCode},</if>
        <if test="et.ncQty!=null">NC_QTY=#{et.ncQty},</if>
        <if test="et.location!=null">LOCATION=#{et.location},</if>
        <if test="et.state!=null">STATE=#{et.state},</if>
        <if test="et.remark!=null">REMARK=#{et.remark},</if>
        <if test="et.createUser!=null">CREATE_USER=#{et.createUser},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
        <if test="et.modifyUser!=null">MODIFY_USER=#{et.modifyUser},</if>
        <if test="et.modifiedDateTime!=null">MODIFIED_DATE_TIME=#{et.modifiedDateTime},</if>
        <if test="et.ncCodeDesc!=null">NC_CODE_DESC=#{et.ncCodeDesc},</if>
        <if test="et.reportUserGroup!=null">REPORT_USER_GROUP=#{et.reportUserGroup},</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_SELF_REPORT <trim prefix="SET" suffixOverrides=",">
        SITE=#{et.site},
        TASK_NO=#{et.taskNo},
        WORK_CENTER=#{et.workCenter},
        SHOP_ORDER=#{et.shopOrder},
        ITEM=#{et.item},
        OP_STEP=#{et.opStep},
        RESRCE=#{et.resrce},
        SFC=#{et.sfc},
        NC_CODE=#{et.ncCode},
        NC_QTY=#{et.ncQty},
        LOCATION=#{et.location},
        STATE=#{et.state},
        REMARK=#{et.remark},
        CREATE_USER=#{et.createUser},
        CREATED_DATE_TIME=#{et.createdDateTime},
        MODIFY_USER=#{et.modifyUser},
        MODIFIED_DATE_TIME=#{et.modifiedDateTime},
        NC_CODE_DESC=#{et.ncCodeDesc},
        REPORT_USER_GROUP=#{et.reportUserGroup},
     </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_SELF_REPORT <trim prefix="SET" suffixOverrides=",">
        <if test="et.site!=null">SITE=#{et.site},</if>
        <if test="et.taskNo!=null">TASK_NO=#{et.taskNo},</if>
        <if test="et.workCenter!=null">WORK_CENTER=#{et.workCenter},</if>
        <if test="et.shopOrder!=null">SHOP_ORDER=#{et.shopOrder},</if>
        <if test="et.item!=null">ITEM=#{et.item},</if>
        <if test="et.opStep!=null">OP_STEP=#{et.opStep},</if>
        <if test="et.resrce!=null">RESRCE=#{et.resrce},</if>
        <if test="et.sfc!=null">SFC=#{et.sfc},</if>
        <if test="et.ncCode!=null">NC_CODE=#{et.ncCode},</if>
        <if test="et.ncQty!=null">NC_QTY=#{et.ncQty},</if>
        <if test="et.location!=null">LOCATION=#{et.location},</if>
        <if test="et.state!=null">STATE=#{et.state},</if>
        <if test="et.remark!=null">REMARK=#{et.remark},</if>
        <if test="et.createUser!=null">CREATE_USER=#{et.createUser},</if>
        <if test="et.createdDateTime!=null">CREATED_DATE_TIME=#{et.createdDateTime},</if>
        <if test="et.modifyUser!=null">MODIFY_USER=#{et.modifyUser},</if>
        <if test="et.modifiedDateTime!=null">MODIFIED_DATE_TIME=#{et.modifiedDateTime},</if>
        <if test="et.ncCodeDesc!=null">NC_CODE_DESC=#{et.ncCodeDesc},</if>
        <if test="et.reportUserGroup!=null">REPORT_USER_GROUP=#{et.reportUserGroup},</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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT WHERE HANDLE=#{handle}
    </delete>

    <delete id="deleteByMap">
        DELETE FROM Z_SELF_REPORT
        <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_SELF_REPORT
        <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.taskNo!=null"> AND TASK_NO=#{ew.entity.taskNo}</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.item!=null"> AND ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null"> AND OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null"> AND SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null"> AND STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="ew.entity.ncCodeDesc!=null"> AND NC_CODE_DESC=#{ew.entity.ncCodeDesc}</if>
                    <if test="ew.entity.reportUserGroup!=null"> AND REPORT_USER_GROUP=#{ew.entity.reportUserGroup}</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_SELF_REPORT WHERE HANDLE IN (
        <foreach item="item" index="index" collection="coll" separator=",">#{item}
        </foreach>)
    </delete>
    <!-- BaseMapper标准查询/修改/删除 -->

    <!--自定义sql-->
    <select id="selectListByCondition" resultMap="BaseResultMap">
        SELECT ZSR.HANDLE, ZSR.SITE, ZSR.TASK_NO, ZSR.WORK_CENTER,ZSR.NC_CODE_DESC, ZSR.SHOP_ORDER, ZSR.ITEM, ZSR.OP_STEP, ZSR.RESRCE, ZSR.SFC, ZSR.NC_CODE, ZSR.NC_QTY, ZSR.LOCATION, ZSR.STATE, ZSR.REMARK, B.FULL_NAME CREATE_USER,ZSR. CREATED_DATE_TIME,IT.DESCRIPTION,ZSR.CREATE_USER PB_USER,CF.VALUE CHECK_USR FROM Z_SELF_REPORT ZSR
        JOIN ITEM I ON I.ITEM = ZSR.ITEM AND I.CURRENT_REVISION='true'
        LEFT JOIN ITEM_T IT ON I.HANDLE = IT.ITEM_BO AND IT.LOCALE = #{locale}
        LEFT JOIN Z_NWA_USER B ON ZSR.SITE = B.SITE AND ZSR.CREATE_USER = B.USER_NAME
        JOIN SHOP_ORDER SO ON SO.shop_order=zsr.SHOP_order and so.site=zsr.site
        LEFT JOIN CUSTOM_FIELDS PC ON PC.HANDLE = SO.HANDLE AND PC."ATTRIBUTE" = 'PRODUCT_CATEGORY'
        LEFT JOIN RESRCE R ON R.RESRCE = ZSR.RESRCE AND R.SITE = ZSR.SITE
        LEFT JOIN CUSTOM_FIELDS CF ON CF.HANDLE = R.HANDLE AND CF."ATTRIBUTE" = 'CHECK_USR'
        <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 ZSR.SITE=#{ew.entity.site}</if>
                    <if test="ew.entity.taskNo!=null"> AND ZSR.TASK_NO=#{ew.entity.taskNo}</if>
                    <if test="ew.entity.workCenter!=null and ew.entity.workCenter!='' "> AND ZSR.WORK_CENTER=#{ew.entity.workCenter}</if>
                    <if test="ew.entity.checkUsr!=null and ew.entity.checkUsr!='' "> AND CF.VALUE=#{ew.entity.checkUsr}</if>
                    <if test="ew.entity.shopOrder!=null and ew.entity.shopOrder!=''"> AND ZSR.SHOP_ORDER=#{ew.entity.shopOrder}</if>
                    <if test="ew.entity.item!=null and ew.entity.item!=''"> AND ZSR.ITEM=#{ew.entity.item}</if>
                    <if test="ew.entity.opStep!=null and ew.entity.opStep!=''"> AND ZSR.OP_STEP=#{ew.entity.opStep}</if>
                    <if test="ew.entity.resrce!=null"> AND ZSR.RESRCE=#{ew.entity.resrce}</if>
                    <if test="ew.entity.sfc!=null  and ew.entity.sfc!='' "> AND ZSR.SFC=#{ew.entity.sfc}</if>
                    <if test="ew.entity.ncCode!=null"> AND ZSR.NC_CODE=#{ew.entity.ncCode}</if>
                    <if test="ew.entity.ncQty!=null"> AND ZSR.NC_QTY=#{ew.entity.ncQty}</if>
                    <if test="ew.entity.location!=null"> AND ZSR.LOCATION=#{ew.entity.location}</if>
                    <if test="ew.entity.state!=null  and ew.entity.state!=''"> AND ZSR.STATE=#{ew.entity.state}</if>
                    <if test="ew.entity.remark!=null"> AND ZSR.REMARK=#{ew.entity.remark}</if>
                    <if test="ew.entity.createUser!=null"> AND ZSR.CREATE_USER=#{ew.entity.createUser}</if>
                    <if test="ew.entity.createdDateTime!=null"> AND ZSR.CREATED_DATE_TIME=#{ew.entity.createdDateTime}</if>
                    <if test="ew.entity.modifyUser!=null"> AND ZSR.MODIFY_USER=#{ew.entity.modifyUser}</if>
                    <if test="ew.entity.modifiedDateTime!=null"> AND ZSR.MODIFIED_DATE_TIME=#{ew.entity.modifiedDateTime}</if>
                    <if test="userGroupList != null">
                        <if test="userGroupList.size &lt;= 0">
                            AND 1 = 2
                        </if>
                        <if test="userGroupList.size > 0">
                            AND ZSR.REPORT_USER_GROUP IN
                            <foreach item="item" index="index" collection="userGroupList" separator="," open="(" close=")">
                                UPPER(#{item.userGroup})
                            </foreach>
                        </if>
                    </if>
                </if>
                <if test="ew.entity.productCategory!=null and ew.entity.productCategory!=''"> AND PC.VALUE LIKE '%'|| #{ew.entity.productCategory}|| '%' </if>
                <if test="startTime!=null"> AND ZSR.CREATED_DATE_TIME >=#{startTime}</if>
                <if test="endTime!=null"> AND ZSR.CREATED_DATE_TIME &lt;=#{endTime}</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="selectResourceAndCheckUsr" resultMap="BaseResultMap">
        SELECT R.RESRCE ,R.DESCRIPTION ,CF.VALUE CHECK_USR  FROM RESRCE R
        INNER JOIN CUSTOM_FIELDS CF ON CF.HANDLE = R.HANDLE AND CF."ATTRIBUTE" = 'CHECK_USR'
        WHERE R.SITE = #{site}
    </select>


    <!--自定义sql-->

</mapper>
