<?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.DevInfoMapper">
    <resultMap type="com.bonus.zlpt.common.core.domain.equip.DevInfo" id="DevInfoResult">
        <result property="maId"    column="ma_id"    />
        <result property="code"    column="code"    />
        <result property="typeId"    column="type_id"    />
        <result property="maStatus"    column="ma_status"    />
        <result property="leaseScope"    column="lease_scope"    />
        <result property="location"    column="location"    />
        <result property="brand"    column="brand"    />
        <result property="modelName"    column="model_name"    />
        <result property="productionDate"    column="production_date"    />
        <result property="workingHours"    column="working_hours"    />
        <result property="serialNumber"    column="serial_number"    />
        <result property="monthLeasePrice"    column="month_lease_price"    />
        <result property="dayLeasePrice"    column="day_lease_price"    />
        <result property="picUrl"    column="pic_url"    />
        <result property="jsMonthPrice"    column="js_month_price"    />
        <result property="jsDayPrice"    column="js_day_price"    />
        <result property="description"    column="description"    />
        <result property="gpsCode"    column="gps_code"    />
        <result property="ownCo"    column="own_co"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="deposit"    column="deposit"    />
        <result property="isActive"    column="is_active"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectDevInfoVo">
        select ma_id, code, type_id, ma_status, lease_scope, location, brand, model_name, production_date, working_hours, serial_number, month_lease_price, day_lease_price, pic_url, js_month_price, js_day_price, description, gps_code, own_co, create_time, creator, deposit, is_active, update_time, update_by from ma_dev_info
    </sql>

    <select id="selectDevInfoList" parameterType="com.bonus.zlpt.common.core.domain.equip.vo.DevInfoVo" resultType="com.bonus.zlpt.common.core.domain.equip.vo.DevInfoVo">
        select d.*,t.type_name,c.company_name
        from ma_dev_info d
            left join ma_type_info t on d.type_id = t.type_id
            left join bm_company_info c on d.own_co = c.company_id
        <where>  
            <if test="maId != null "> and d.ma_id = #{maId}</if>
            <if test="code != null  and code != ''"> and d.code = #{code}</if>
            <if test="typeId != null "> and d.type_id = #{typeId}</if>
            <if test="maStatus != null  and maStatus != ''"> and d.ma_status = #{maStatus}</if>
            <if test="leaseScope != null "> and d.lease_scope = #{leaseScope}</if>
            <if test="location != null  and location != ''"> and d.location = #{location}</if>
            <if test="brand != null  and brand != ''"> and d.brand = #{brand}</if>
            <if test="modelName != null  and modelName != ''"> and d.model_name like concat('%', #{modelName}, '%')</if>
            <if test="productionDate != null  and productionDate != ''"> and d.production_date = #{productionDate}</if>
            <if test="workingHours != null  and workingHours != ''"> and d.working_hours = #{workingHours}</if>
            <if test="serialNumber != null  and serialNumber != ''"> and d.serial_number = #{serialNumber}</if>
            <if test="monthLeasePrice != null  and monthLeasePrice != ''"> and d.month_lease_price = #{monthLeasePrice}</if>
            <if test="dayLeasePrice != null  and dayLeasePrice != ''"> and d.day_lease_price = #{dayLeasePrice}</if>
            <if test="picUrl != null  and picUrl != ''"> and d.pic_url = #{picUrl}</if>
            <if test="jsMonthPrice != null  and jsMonthPrice != ''"> and d.js_month_price = #{jsMonthPrice}</if>
            <if test="jsDayPrice != null  and jsDayPrice != ''"> and d.js_day_price = #{jsDayPrice}</if>
            <if test="description != null  and description != ''"> and d.description = #{description}</if>
            <if test="gpsCode != null  and gpsCode != ''"> and d.gps_code = #{gpsCode}</if>
            <if test="ownCo != null "> and d.own_co = #{ownCo}</if>
            <if test="creator != null "> and d.creator = #{creator}</if>
            <if test="deposit != null "> and d.deposit = #{deposit}</if>
            <if test="isActive != null  and isActive != ''"> and d.is_active = #{isActive}</if>
            <if test="keyWord != null and keyWord != ''">
                and (
                    locate(#{typeName},t.type_name) > 0
                    or locate(#{companyName},c.company_name) > 0
                    or locate(#{maId},d.ma_id) > 0
                    or locate(#{modelName},d.model_name) > 0
                    or locate(#{serialNumber},d.serial_number) > 0
                    or locate(#{description},d.description) > 0
                )
            </if>
        </where>
    </select>
    
    <select id="selectDevInfoByMaId" parameterType="Long" resultType="com.bonus.zlpt.common.core.domain.equip.vo.DevInfoVo">
        select d.*,t.type_name,c.company_name
        from ma_dev_info d
            left join ma_type_info t on d.type_id = t.type_id
            left join bm_company_info c on d.own_co = c.company_id
        where d.ma_id = #{maId}
    </select>
        
    <insert id="insertDevInfo" parameterType="com.bonus.zlpt.common.core.domain.equip.DevInfo">
        insert into ma_dev_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="maId != null">ma_id,</if>
            <if test="code != null">code,</if>
            <if test="typeId != null">type_id,</if>
            <if test="maStatus != null">ma_status,</if>
            <if test="leaseScope != null">lease_scope,</if>
            <if test="location != null">location,</if>
            <if test="brand != null">brand,</if>
            <if test="modelName != null">model_name,</if>
            <if test="productionDate != null">production_date,</if>
            <if test="workingHours != null">working_hours,</if>
            <if test="serialNumber != null">serial_number,</if>
            <if test="monthLeasePrice != null">month_lease_price,</if>
            <if test="dayLeasePrice != null">day_lease_price,</if>
            <if test="picUrl != null">pic_url,</if>
            <if test="jsMonthPrice != null">js_month_price,</if>
            <if test="jsDayPrice != null">js_day_price,</if>
            <if test="description != null">description,</if>
            <if test="gpsCode != null">gps_code,</if>
            <if test="ownCo != null">own_co,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
            <if test="deposit != null">deposit,</if>
            <if test="isActive != null">is_active,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="maId != null">#{maId},</if>
            <if test="code != null">#{code},</if>
            <if test="typeId != null">#{typeId},</if>
            <if test="maStatus != null">#{maStatus},</if>
            <if test="leaseScope != null">#{leaseScope},</if>
            <if test="location != null">#{location},</if>
            <if test="brand != null">#{brand},</if>
            <if test="modelName != null">#{modelName},</if>
            <if test="productionDate != null">#{productionDate},</if>
            <if test="workingHours != null">#{workingHours},</if>
            <if test="serialNumber != null">#{serialNumber},</if>
            <if test="monthLeasePrice != null">#{monthLeasePrice},</if>
            <if test="dayLeasePrice != null">#{dayLeasePrice},</if>
            <if test="picUrl != null">#{picUrl},</if>
            <if test="jsMonthPrice != null">#{jsMonthPrice},</if>
            <if test="jsDayPrice != null">#{jsDayPrice},</if>
            <if test="description != null">#{description},</if>
            <if test="gpsCode != null">#{gpsCode},</if>
            <if test="ownCo != null">#{ownCo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="deposit != null">#{deposit},</if>
            <if test="isActive != null">#{isActive},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateDevInfo" parameterType="com.bonus.zlpt.common.core.domain.equip.DevInfo">
        update ma_dev_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null">code = #{code},</if>
            <if test="typeId != null">type_id = #{typeId},</if>
            <if test="maStatus != null">ma_status = #{maStatus},</if>
            <if test="leaseScope != null">lease_scope = #{leaseScope},</if>
            <if test="location != null">location = #{location},</if>
            <if test="brand != null">brand = #{brand},</if>
            <if test="modelName != null">model_name = #{modelName},</if>
            <if test="productionDate != null">production_date = #{productionDate},</if>
            <if test="workingHours != null">working_hours = #{workingHours},</if>
            <if test="serialNumber != null">serial_number = #{serialNumber},</if>
            <if test="monthLeasePrice != null">month_lease_price = #{monthLeasePrice},</if>
            <if test="dayLeasePrice != null">day_lease_price = #{dayLeasePrice},</if>
            <if test="picUrl != null">pic_url = #{picUrl},</if>
            <if test="jsMonthPrice != null">js_month_price = #{jsMonthPrice},</if>
            <if test="jsDayPrice != null">js_day_price = #{jsDayPrice},</if>
            <if test="description != null">description = #{description},</if>
            <if test="gpsCode != null">gps_code = #{gpsCode},</if>
            <if test="ownCo != null">own_co = #{ownCo},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="deposit != null">deposit = #{deposit},</if>
            <if test="isActive != null">is_active = #{isActive},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where ma_id = #{maId}
    </update>

    <delete id="deleteDevInfoByMaId" parameterType="Long">
        delete from ma_dev_info where ma_id = #{maId}
    </delete>

    <delete id="deleteDevInfoByMaIds" parameterType="String">
        delete from ma_dev_info where ma_id in 
        <foreach item="maId" collection="array" open="(" separator="," close=")">
            #{maId}
        </foreach>
    </delete>
</mapper>