<?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.template.mapper.MessageTemplateTypeMapper">
    <insert id="addMessageType">
        INSERT INTO `four`.`message_template_type` ( `message_code`, `message_field`, `start_index`, `end_index`, `data_type_id`, `fixed_value`, `range_value`, `template_id`)
        VALUES ( #{messageCode}, #{messageField}, #{startIndex}, #{endIndex}, #{dataTypeId}, #{fixedValue}, #{rangeValue}, #{templateId});
    </insert>
    <select id="messageTemplateTypeList" resultType="com.template.domain.MessageTemplateType">
        SELECT
            message_template_type.*,
            data_type.data_type_name
        FROM
            message_template_type
                LEFT JOIN data_type ON data_type.data_type_id = message_template_type.data_type_id
    </select>
    <select id="finddeviceStatusData" resultType="com.template.domain.MessageTemplateType">
        SELECT
            message_template_type.*,
            data_type.data_type_name
        FROM
            message_template_type
                LEFT JOIN data_type ON data_type.data_type_id = message_template_type.data_type_id
        where message_template_type.template_id=#{templatedId} and message_template_type.message_class=#{code}
    </select>
    <select id="findvehicleFoundationData" resultType="com.template.domain.MessageTemplateType">
        SELECT
            message_template_type.*,
            data_type.data_type_name
        FROM
            message_template_type
                LEFT JOIN data_type ON data_type.data_type_id = message_template_type.data_type_id
        where message_template_type.template_id=#{templatedId} and message_template_type.message_class=#{code}
    </select>
    <select id="findvehicleData" resultType="com.template.domain.MessageTemplateType">
        SELECT
            message_template_type.*,
            data_type.data_type_name
        FROM
            message_template_type
                LEFT JOIN data_type ON data_type.data_type_id = message_template_type.data_type_id
        where message_template_type.template_id=#{templatedId} and message_template_type.message_class=#{code}
    </select>

    <select id="findMessageByTemplateName" resultType="com.template.domain.MessageTemplateType">
        SELECT
            message_template_type.*,
            data_type.data_type_name
        FROM
            message_template_type
                LEFT JOIN data_type ON data_type.data_type_id = message_template_type.data_type_id
        where message_template_type.template_id=#{templatedId}
    </select>

</mapper>
