<?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.bonus.zlpt.equip.mapper.UpOffMapper">
    
    <resultMap type="com.bonus.zlpt.equip.api.domain.UpOff" id="UpOffResult">
        <result property="id"    column="id"    />
        <result property="maId"    column="ma_id"    />
        <result property="applyTime"    column="apply_time"    />
        <result property="applyUser"    column="apply_user"    />
        <result property="applyCompany"    column="apply_company"    />
        <result property="type"    column="type"    />
        <result property="auditUser"    column="audit_user"    />
        <result property="auditTime"    column="audit_time"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectUpOffVo">
        select id, ma_id, apply_time, apply_user, apply_company, type, audit_user, audit_time, status from ma_up_off
    </sql>

    <select id="selectUpOffList" parameterType="com.bonus.zlpt.equip.api.domain.UpOff" resultMap="UpOffResult">
        <include refid="selectUpOffVo"/>
        <where>  
            <if test="maId != null "> and ma_id = #{maId}</if>
            <if test="applyTime != null  and applyTime != ''"> and apply_time = #{applyTime}</if>
            <if test="applyUser != null  and applyUser != ''"> and apply_user = #{applyUser}</if>
            <if test="applyCompany != null  and applyCompany != ''"> and apply_company = #{applyCompany}</if>
            <if test="type != null  and type != ''"> and type = #{type}</if>
            <if test="auditUser != null  and auditUser != ''"> and audit_user = #{auditUser}</if>
            <if test="auditTime != null  and auditTime != ''"> and audit_time = #{auditTime}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectUpOffById" parameterType="Long" resultMap="UpOffResult">
        <include refid="selectUpOffVo"/>
        where id = #{id}
    </select>


    <select id="selectList" resultType="com.bonus.zlpt.equip.api.domain.vo.MaDevInfoVo">
        select
            d.*,c.company_name companyName,t.type_name devTypeName
        from
            ma_dev_info d,bm_company_info c,ma_type_info t
        <where>
            and d.type_id = t.type_id
            and d.own_co = `c`.company_id
        <if test="code != null and code != ''">and d.code LIKE CONCAT('%',#{code},'%')</if>
        <if test="name != null and name != ''">and t.type_name LIKE CONCAT('%',#{name},'%')</if>
        <if test="companyName != null and companyName != ''">and c.company_name LIKE CONCAT('%',#{companyName},'%')</if>
        <if test="typeId != null ">and t.parent_id = #{typeId}</if>
        </where>
    </select>

    <insert id="insertUpOff" parameterType="com.bonus.zlpt.equip.api.domain.UpOff">
        insert into ma_up_off
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="maId != null">ma_id,</if>
            <if test="applyUser != null">apply_user,</if>
            <if test="applyCompany != null">apply_company,</if>
            <if test="type != null">type,</if>
            <if test="auditUser != null">audit_user,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="status != null">status,</if>
            apply_time
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="maId != null">#{maId},</if>
            <if test="applyUser != null">#{applyUser},</if>
            <if test="applyCompany != null">#{applyCompany},</if>
            <if test="type != null">#{type},</if>
            <if test="auditUser != null">#{auditUser},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="status != null">#{status},</if>
            sysdate()
         </trim>
    </insert>

    <update id="updateUpOff" parameterType="com.bonus.zlpt.equip.api.domain.UpOff">
        update ma_up_off
        <trim prefix="SET" suffixOverrides=",">
            <if test="maId != null">ma_id = #{maId},</if>
            <if test="applyTime != null">apply_time = #{applyTime},</if>
            <if test="applyUser != null">apply_user = #{applyUser},</if>
            <if test="applyCompany != null">apply_company = #{applyCompany},</if>
            <if test="type != null">type = #{type},</if>
            <if test="auditUser != null">audit_user = #{auditUser},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="status != null">status = #{status},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteUpOffById" parameterType="Long">
        delete from ma_up_off where id = #{id}
    </delete>

    <delete id="deleteUpOffByIds" parameterType="String">
        delete from ma_up_off where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="UpdateUpOffLIst" parameterType="com.bonus.zlpt.equip.api.domain.UpOff">
    update ma_up_off set type = #{type}  where ma_id = #{maId}
    </update>
</mapper>