<?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="cn.ezhizao.project.business.mapper.BizDayworkAuxiliaryItemMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizDayworkAuxiliaryItem" id="BizDayworkAuxiliaryItemResult">
        <id column="id" property="id"/>
        <result column="lot_id" property="lotId"/>
        <result column="daywork_id" property="dayworkId"/>
        <result column="process_id" property="processId"/>
        <result column="product_id" property="productId"/>
        <result column="auxiliary_process_id" property="auxiliaryProcessId"/>
        <result column="technological_process_id" property="technologicalProcessId"/>
        <result column="technological_process_detail_id" property="technologicalProcessDetailId"/>
        <result column="production_plan_detail_id" property="productionPlanDetailId"/>
        <association property="isAmend" javaType="java.lang.Integer" column="daywork_id" select="getIsAmend"/>
        <association property="isWasteRecycling" javaType="java.lang.Integer" column="daywork_id"
                     select="getIsWasteRecycling"/>
        <association property="productDescription" javaType="java.lang.String" column="product_id"
                     select="getProductDescription"/>
        <association property="lotCode" javaType="java.lang.String" column="lot_id" select="getLotCode"/>
        <association property="processAlias" javaType="java.lang.String" column="process_id" select="getProcessAlias"/>
        <association property="auxiliaryProcessAlias" javaType="java.lang.String" column="auxiliary_process_id"
                     select="getAuxiliaryProcessAlias"/>
    </resultMap>
    <select id="getProcessAlias" resultType="java.lang.String">
        select process_alias
        from biz_process
        where deleted = 0
        and id = #{process_id}
    </select>
    <select id="getAuxiliaryProcessAlias" resultType="java.lang.String">
        select name
        from biz_auxiliary_process
        where deleted = 0
        and id = #{auxiliary_process_id}
    </select>
    <select id="getIsAmend" resultType="Integer">
        select is_amend from biz_daywork where id = #{daywork_id}
    </select>
    <select id="getIsWasteRecycling" resultType="Integer">
        select is_waste_recycling from biz_daywork where id = #{daywork_id}
    </select>
    <select id="getProductDescription" resultType="java.lang.String">
        select description as productDescription
        from biz_product
        where deleted = 0
        and id = #{product_id}
        <!--              (select product_id from biz_technological_process where deleted = 0 and id = #{technologicalProcessId})-->
    </select>

    <select id="getLotCode" resultType="java.lang.String">
        SELECT lot_code FROM biz_lot WHERE id = #{lot_id}
    </select>

    <select id="getList" parameterType="BizDayworkAuxiliaryItem" resultMap="BizDayworkAuxiliaryItemResult">
        SELECT * FROM biz_daywork_auxiliary_item
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="deptName != null  and deptName != ''">AND dept_name like concat('%', #{deptName}, '%')</if>
            <if test="dayworkId != null">AND daywork_id = #{dayworkId}</if>
            <if test="status != null  and status != ''">AND status = #{status}</if>
            <if test="userName != null  and userName != ''">AND user_name like concat('%', #{userName}, '%')</if>
            <if test="nickName != null  and nickName != ''">AND nick_name like concat('%', #{nickName}, '%')</if>
            <if test="startTime != null ">AND start_time = #{startTime}</if>
            <if test="endTime != null ">AND end_time = #{endTime}</if>
            <if test="auxiliaryProcessId != null">AND auxiliary_process_id = #{auxiliaryProcessId}</if>
            <if test="id != null">AND id = #{id}</if>
        </trim>
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_daywork_auxiliary_item
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
            <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
