<?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.zehong.system.mapper.TDeviceReportDataMapper">
    
    <resultMap type="TDeviceReportData" id="TDeviceReportDataResult">
        <result property="deviceReportDataId"    column="device_report_data_id"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceNum"    column="device_num"    />
        <result property="standardConditionAccumulation"    column="standard_condition_accumulation"    />
        <result property="workingConditionAccumulation"    column="working_condition_accumulation"    />
        <result property="backingStandardConditionAccumulation"    column="backing_standard_condition_accumulation"    />
        <result property="residualQuantity"    column="residual_quantity"    />
        <result property="standardConditionFlow"    column="standard_condition_flow"    />
        <result property="workingConditionFlow"    column="working_condition_flow"    />
        <result property="temperature"    column="temperature"    />
        <result property="pressure"    column="pressure"    />
        <result property="reportTime"    column="report_time"    />
        <result property="communicationStatus"    column="communication_status"    />
        <result property="deviceStatus"    column="device_status"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="beyondDeviceName"    column="beyondDeviceName"    />
        <result property="deviceType"    column="device_type"    />
    </resultMap>

    <sql id="selectTDeviceReportDataVo">
        SELECT
            report.device_report_data_id,
            report.device_name,
            report.device_num,
            report.standard_condition_accumulation,
            report.working_condition_accumulation,
            report.backing_standard_condition_accumulation,
            report.residual_quantity,
            report.standard_condition_flow,
            report.working_condition_flow,
            report.temperature,
            report.pressure,
            report.report_time,
            report.communication_status,
            report.device_status,
            report.beyond_enterprise_id,
            enterprise.enterprise_name AS beyond_enterprise_name,
            report.create_by,
            report.create_time,
            report.update_by,
            report.update_time,
            report.is_del,
            report.remarks,
          device.device_name AS beyondDeviceName
        FROM
            t_device_report_data report
        INNER JOIN t_relation_device_detail_info detail ON detail.iot_no = report.device_num
        INNER JOIN t_device_info device ON device.device_id = detail.relation_device_id
        INNER JOIN t_enterprise_info enterprise ON enterprise.enterprise_id = report.beyond_enterprise_id
    </sql>

    <select id="selectTDeviceReportDataList" parameterType="TDeviceReportData" resultMap="TDeviceReportDataResult">
        <include refid="selectTDeviceReportDataVo"/>
        <where>  
            <if test="deviceName != null  and deviceName != ''"> and report.device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceNum != null  and deviceNum != ''"> and report.device_num like concat('%', #{deviceNum}, '%')</if>
            <if test="standardConditionAccumulation != null "> and report.standard_condition_accumulation = #{standardConditionAccumulation}</if>
            <if test="workingConditionAccumulation != null "> and report.working_condition_accumulation = #{workingConditionAccumulation}</if>
            <if test="backingStandardConditionAccumulation != null "> and report.backing_standard_condition_accumulation = #{backingStandardConditionAccumulation}</if>
            <if test="residualQuantity != null "> and report.residual_quantity = #{residualQuantity}</if>
            <if test="standardConditionFlow != null "> and report.standard_condition_flow = #{standardConditionFlow}</if>
            <if test="workingConditionFlow != null "> and report.working_condition_flow = #{workingConditionFlow}</if>
            <if test="temperature != null "> and report.temperature = #{temperature}</if>
            <if test="pressure != null "> and report.pressure = #{pressure}</if>
            <if test="reportTime != null "> and report.report_time = #{reportTime}</if>
            <if test="communicationStatus != null  and communicationStatus != ''"> and report.communication_status = #{communicationStatus}</if>
            <if test="deviceStatus != null  and deviceStatus != ''"> and report.device_status = #{deviceStatus}</if>
            <if test="beyondEnterpriseId != null "> and report.beyond_enterprise_id = #{beyondEnterpriseId}</if>
            <if test="beyondEnterpriseName != null  and beyondEnterpriseName != ''"> and report.beyond_enterprise_name like concat('%', #{beyondEnterpriseName}, '%')</if>
            <if test="isDel != null  and isDel != ''"> and report.is_del = #{isDel}</if>
            <if test="remarks != null  and remarks != ''"> and report.remarks = #{remarks}</if>
            <if test="deviceType != null  and deviceType != ''">AND detail.device_type = #{deviceType}</if>
        </where>
    </select>
    
    <select id="selectTDeviceReportDataById" parameterType="Long" resultMap="TDeviceReportDataResult">
        <include refid="selectTDeviceReportDataVo"/>
        where report.device_report_data_id = #{deviceReportDataId}
    </select>
        
    <insert id="insertTDeviceReportData" parameterType="TDeviceReportData" useGeneratedKeys="true" keyProperty="deviceReportDataId">
        insert into t_device_report_data
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">device_name,</if>
            <if test="deviceNum != null and deviceNum != ''">device_num,</if>
            <if test="standardConditionAccumulation != null">standard_condition_accumulation,</if>
            <if test="workingConditionAccumulation != null">working_condition_accumulation,</if>
            <if test="backingStandardConditionAccumulation != null">backing_standard_condition_accumulation,</if>
            <if test="residualQuantity != null">residual_quantity,</if>
            <if test="standardConditionFlow != null">standard_condition_flow,</if>
            <if test="workingConditionFlow != null">working_condition_flow,</if>
            <if test="temperature != null">temperature,</if>
            <if test="pressure != null">pressure,</if>
            <if test="reportTime != null">report_time,</if>
            <if test="communicationStatus != null">communication_status,</if>
            <if test="deviceStatus != null">device_status,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceNum != null and deviceNum != ''">#{deviceNum},</if>
            <if test="standardConditionAccumulation != null">#{standardConditionAccumulation},</if>
            <if test="workingConditionAccumulation != null">#{workingConditionAccumulation},</if>
            <if test="backingStandardConditionAccumulation != null">#{backingStandardConditionAccumulation},</if>
            <if test="residualQuantity != null">#{residualQuantity},</if>
            <if test="standardConditionFlow != null">#{standardConditionFlow},</if>
            <if test="workingConditionFlow != null">#{workingConditionFlow},</if>
            <if test="temperature != null">#{temperature},</if>
            <if test="pressure != null">#{pressure},</if>
            <if test="reportTime != null">#{reportTime},</if>
            <if test="communicationStatus != null">#{communicationStatus},</if>
            <if test="deviceStatus != null">#{deviceStatus},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTDeviceReportData" parameterType="TDeviceReportData">
        update t_device_report_data
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceNum != null and deviceNum != ''">device_num = #{deviceNum},</if>
            <if test="standardConditionAccumulation != null">standard_condition_accumulation = #{standardConditionAccumulation},</if>
            <if test="workingConditionAccumulation != null">working_condition_accumulation = #{workingConditionAccumulation},</if>
            <if test="backingStandardConditionAccumulation != null">backing_standard_condition_accumulation = #{backingStandardConditionAccumulation},</if>
            <if test="residualQuantity != null">residual_quantity = #{residualQuantity},</if>
            <if test="standardConditionFlow != null">standard_condition_flow = #{standardConditionFlow},</if>
            <if test="workingConditionFlow != null">working_condition_flow = #{workingConditionFlow},</if>
            <if test="temperature != null">temperature = #{temperature},</if>
            <if test="pressure != null">pressure = #{pressure},</if>
            <if test="reportTime != null">report_time = #{reportTime},</if>
            <if test="communicationStatus != null">communication_status = #{communicationStatus},</if>
            <if test="deviceStatus != null">device_status = #{deviceStatus},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where device_report_data_id = #{deviceReportDataId}
    </update>

    <delete id="deleteTDeviceReportDataById" parameterType="Long">
        delete from t_device_report_data where device_report_data_id = #{deviceReportDataId}
    </delete>

    <delete id="deleteTDeviceReportDataByIds" parameterType="String">
        delete from t_device_report_data where device_report_data_id in 
        <foreach item="deviceReportDataId" collection="array" open="(" separator="," close=")">
            #{deviceReportDataId}
        </foreach>
    </delete>
</mapper>