<?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.ruoyi.oa.mapper.CmcDeviceLogMapper">
    
    <resultMap type="CmcDeviceLog" id="CmcDeviceLogResult">
        <result property="logId"    column="log_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="usageType"    column="usage_type"    />
        <result property="useDate"    column="use_date"    />
        <result property="weather"    column="weather"    />
        <result property="position"    column="position"    />
        <result property="heightType"    column="height_type"    />
        <result property="height"    column="height"    />
        <result property="dryTemperature"    column="dry_temperature"    />
        <result property="wetTemperature"    column="wet_temperature"    />
        <result property="airPressure"    column="air_pressure"    />
        <result property="powerOn"    column="power_on"    />
        <result property="powerOff"    column="power_off"    />
        <result property="userId"    column="user_id"    />
        <association property="user"    javaType="SysUser"         resultMap="SysUserResult" />
        <association property="device"    javaType="CmcDevice"         resultMap="CmcDeviceResult" />
        <association property="project"    javaType="CmcProject"         resultMap="CmcProjectResult" />
    </resultMap>

    <resultMap type="SysUser" id="SysUserResult">
        <result property="userId"    column="user_id"    />
        <result property="nickName"    column="nick_name"    />
    </resultMap>

    <resultMap type="CmcDevice" id="CmcDeviceResult">
        <result property="deviceId"    column="device_id"    />
        <result property="deviceNumber"    column="device_number"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="series"    column="series"    />
        <result property="brand"    column="brand"    />
    </resultMap>

    <resultMap type="CmcProject" id="CmcProjectResult">
        <result property="projectId"    column="project_id"    />
        <result property="projectNumber"    column="project_number"    />
        <result property="projectName"    column="project_name"    />
    </resultMap>

    <sql id="selectCmcDeviceLogVo">
        select dl.log_id, dl.device_id, d.device_number, d.code, d.name, d.series, d.brand, dl.project_id, p.project_name, p.project_number, dl.usage_type, dl.use_date,
               dl.weather, dl.position, dl.height_type, dl.height, dl.dry_temperature, dl.wet_temperature, dl.air_pressure, dl.power_on, dl.power_off, dl.user_id, u.nick_name from cmc_device_log as dl
        left join sys_user as u on u.user_id = dl.user_id
        left join cmc_device as d on d.device_id = dl.device_id
        left join cmc_project as p on p.project_id = dl.project_id
    </sql>

    <select id="selectCmcDeviceLogList" parameterType="CmcDeviceLog" resultMap="CmcDeviceLogResult">
        <include refid="selectCmcDeviceLogVo"/>
        <where>  
            <if test="deviceId != null "> and dl.device_id = #{deviceId}</if>
            <if test="projectId != null  and projectId != ''"> and dl.project_id = #{projectId}</if>
            <if test="usageType != null  and usageType != ''"> and dl.usage_type = #{usageType}</if>
            <if test="useDate != null "> and dl.use_date = #{useDate}</if>
            <if test="weather != null  and weather != ''"> and dl.weather = #{weather}</if>
            <if test="position != null  and position != ''"> and dl.position = #{position}</if>
            <if test="heightType != null  and heightType != ''"> and dl.height_type = #{heightType}</if>
            <if test="height != null "> and dl.height = #{height}</if>
            <if test="dryTemperature != null  and dryTemperature != ''"> and dl.dry_temperature = #{dryTemperature}</if>
            <if test="wetTemperature != null  and wetTemperature != ''"> and dl.wet_temperature = #{wetTemperature}</if>
            <if test="airPressure != null  and airPressure != ''"> and dl.air_pressure = #{airPressure}</if>
            <if test="powerOn != null "> and dl.power_on = #{powerOn}</if>
            <if test="powerOff != null "> and dl.power_off = #{powerOff}</if>
            <if test="userId != null "> and dl.user_id = #{userId}</if>
        </where>
    </select>
    
    <select id="selectCmcDeviceLogByLogId" parameterType="Integer" resultMap="CmcDeviceLogResult">
        <include refid="selectCmcDeviceLogVo"/>
        where log_id = #{logId}
    </select>
        
    <insert id="insertCmcDeviceLog" parameterType="CmcDeviceLog" useGeneratedKeys="true" keyProperty="logId">
        insert into cmc_device_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="usageType != null">usage_type,</if>
            <if test="useDate != null">use_date,</if>
            <if test="weather != null">weather,</if>
            <if test="position != null">position,</if>
            <if test="heightType != null">height_type,</if>
            <if test="height != null">height,</if>
            <if test="dryTemperature != null">dry_temperature,</if>
            <if test="wetTemperature != null">wet_temperature,</if>
            <if test="airPressure != null">air_pressure,</if>
            <if test="powerOn != null">power_on,</if>
            <if test="powerOff != null">power_off,</if>
            <if test="userId != null">user_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="usageType != null">#{usageType},</if>
            <if test="useDate != null">#{useDate},</if>
            <if test="weather != null">#{weather},</if>
            <if test="position != null">#{position},</if>
            <if test="heightType != null">#{heightType},</if>
            <if test="height != null">#{height},</if>
            <if test="dryTemperature != null">#{dryTemperature},</if>
            <if test="wetTemperature != null">#{wetTemperature},</if>
            <if test="airPressure != null">#{airPressure},</if>
            <if test="powerOn != null">#{powerOn},</if>
            <if test="powerOff != null">#{powerOff},</if>
            <if test="userId != null">#{userId},</if>
         </trim>
    </insert>

    <update id="updateCmcDeviceLog" parameterType="CmcDeviceLog">
        update cmc_device_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="usageType != null">usage_type = #{usageType},</if>
            <if test="useDate != null">use_date = #{useDate},</if>
            <if test="weather != null">weather = #{weather},</if>
            <if test="position != null">position = #{position},</if>
            <if test="heightType != null">height_type = #{heightType},</if>
            <if test="height != null">height = #{height},</if>
            <if test="dryTemperature != null">dry_temperature = #{dryTemperature},</if>
            <if test="wetTemperature != null">wet_temperature = #{wetTemperature},</if>
            <if test="airPressure != null">air_pressure = #{airPressure},</if>
            power_on = #{powerOn},
            power_off = #{powerOff},
            <if test="userId != null">user_id = #{userId},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteCmcDeviceLogByLogId" parameterType="Integer">
        delete from cmc_device_log where log_id = #{logId}
    </delete>

    <delete id="deleteCmcDeviceLogByLogIds" parameterType="String">
        delete from cmc_device_log where log_id in 
        <foreach item="logId" collection="array" open="(" separator="," close=")">
            #{logId}
        </foreach>
    </delete>
</mapper>