<?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.flossom.common.core.mapper.WxInstrumentMapper">
    
    <resultMap type="WxInstrument" id="WxInstrumentResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="type"    column="type"    />
        <result property="model"    column="model"    />
        <result property="banner"    column="banner"    />
        <result property="logo"    column="logo"    />
        <result property="serial"    column="serial"    />
        <result property="guarantee"    column="guarantee"    />
        <result property="dailyClockCredit"    column="daily_clock_credit"    />
        <result property="isExtraClock"    column="is_extra_clock"    />
        <result property="extraClockCredit"    column="extra_clock_credit"    />
        <result property="bindingCredit"    column="binding_credit"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="miniTagIds"    column="mini_tag_ids"    />
        <result property="miniTagNames"    column="mini_tag_names"    />
        <result property="wecomTagIds"    column="wecom_tag_ids"    />
        <result property="wecomTagNames"    column="wecom_tag_names"    />
        <result property="nursingTime"    column="nursing_time"    />
        <result property="iotVersion"    column="iot_version"    />
        <result property="iotUpgradeData"    column="iot_upgrade_data"    />
        <result property="isScanCode"    column="is_scan_code"    />
        <result property="isPurchase"    column="is_purchase"    />
        <result property="shoppingAppid"    column="shopping_appid"    />
        <result property="shoppingPath"    column="shopping_path"    />
        <result property="bluetoothConnectingTitle"    column="bluetooth_connecting_title"    />
        <result property="bluetoothConnectingContent"    column="bluetooth_connecting_content"    />
        <result property="bluetoothConnecting"    column="bluetooth_connecting"    />
        <result property="bluetoothClosedTitle"    column="bluetooth_closed_title"    />
        <result property="bluetoothClosedContent"    column="bluetooth_closed_content"    />
        <result property="bluetoothClosed"    column="bluetooth_closed"    />
        <result property="bluetoothConnectFailTitle"    column="bluetooth_connect_fail_title"    />
        <result property="bluetoothConnectFailContent"    column="bluetooth_connect_fail_content"    />
        <result property="bluetoothConnectFail"    column="bluetooth_connect_fail"    />
        <result property="iotVersionUpgrade"    column="iot_version_upgrade"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="status"    column="status"    />
        <result property="manualCodeBinding"    column="manual_code_binding"    />
        <result property="scanCodeBinding"    column="scan_code_binding"    />
        <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="remark"    column="remark"    />
        <result property="we200IotVersion"    column="we200_iot_version"    />
        <result property="we200IotUpgradeData"    column="we200_iot_upgrade_data"    />
        <result property="we200IotVersionUpgrade"    column="we200_iot_version_upgrade"    />
    </resultMap>

    <sql id="selectWxInstrumentVo">
        select id, name, type, model, banner, logo, serial, guarantee, daily_clock_credit, is_extra_clock, binding_credit, extra_clock_credit, start_time, end_time, mini_tag_ids, mini_tag_names, wecom_tag_ids, wecom_tag_names, nursing_time, iot_version, iot_upgrade_data, is_scan_code, is_purchase, shopping_appid, shopping_path, bluetooth_connecting_title, bluetooth_connecting_content,bluetooth_connecting, bluetooth_closed_title, bluetooth_closed_content, bluetooth_closed, bluetooth_connect_fail_title, bluetooth_connect_fail_content, bluetooth_connect_fail, iot_version_upgrade, sort_no, status, manual_code_binding, scan_code_binding, create_by, create_time, update_by, update_time, remark, we200_iot_version, we200_iot_upgrade_data, we200_iot_version_upgrade from wx_instrument
    </sql>

    <select id="selectWxInstrumentList" parameterType="WxInstrument" resultMap="WxInstrumentResult">
        <include refid="selectWxInstrumentVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="model != null  and model != ''"> and model = #{model}</if>
            <if test="banner != null  and banner != ''"> and banner = #{banner}</if>
            <if test="logo != null  and logo != ''"> and logo = #{logo}</if>
            <if test="serial != null  and serial != ''"> and serial = #{serial}</if>
            <if test="guarantee != null "> and guarantee = #{guarantee}</if>
            <if test="dailyClockCredit != null "> and daily_clock_credit = #{dailyClockCredit}</if>
            <if test="isExtraClock != null "> and is_extra_clock = #{isExtraClock}</if>
            <if test="extraClockCredit != null "> and extra_clock_credit = #{extraClockCredit}</if>
            <if test="startTime != null "> and start_time = #{startTime}</if>
            <if test="endTime != null "> and end_time = #{endTime}</if>
            <if test="bindingCredit != null "> and binding_credit = #{bindingCredit}</if>
            <if test="miniTagIds != null  and miniTagIds != ''"> and mini_tag_ids = #{miniTagIds}</if>
            <if test="miniTagNames != null  and miniTagNames != ''"> and mini_tag_names = #{miniTagNames}</if>
            <if test="wecomTagIds != null  and wecomTagIds != ''"> and wecom_tag_ids = #{wecomTagIds}</if>
            <if test="wecomTagNames != null  and wecomTagNames != ''"> and wecom_tag_names = #{wecomTagNames}</if>
            <if test="nursingTime != null "> and nursing_time = #{nursingTime}</if>
            <if test="iotVersion != null  and iotVersion != ''"> and iot_version = #{iotVersion}</if>
            <if test="iotUpgradeData != null  and iotUpgradeData != ''"> and iot_upgrade_data = #{iotUpgradeData}</if>
            <if test="isScanCode != null "> and is_scan_code = #{isScanCode}</if>
            <if test="isPurchase != null "> and is_purchase = #{isPurchase}</if>
            <if test="shoppingAppid != null  and shoppingAppid != ''"> and shopping_appid = #{shoppingAppid}</if>
            <if test="shoppingPath != null  and shoppingPath != ''"> and shopping_path = #{shoppingPath}</if>
            <if test="bluetoothConnectingTitle != null  and bluetoothConnectingTitle != ''"> and bluetooth_connecting_title = #{bluetoothConnectingTitle}</if>
            <if test="bluetoothConnectingContent != null  and bluetoothConnectingContent != ''"> and bluetooth_connecting_content = #{bluetoothConnectingContent}</if>
            <if test="bluetoothConnecting != null  and bluetoothConnecting != ''"> and bluetooth_connecting = #{bluetoothConnecting}</if>
            <if test="bluetoothClosedTitle != null  and bluetoothClosedTitle != ''"> and bluetooth_closed_content = #{bluetoothClosedContent}</if>
            <if test="bluetoothClosedTitle != null  and bluetoothClosedTitle != ''"> and bluetooth_closed_title = #{bluetoothClosedTitle}</if>
            <if test="bluetoothClosed != null  and bluetoothClosed != ''"> and bluetooth_closed = #{bluetoothClosed}</if>
            <if test="bluetoothConnectFailTitle != null  and bluetoothConnectFailTitle != ''"> and bluetooth_connect_fail_title = #{bluetoothConnectFailTitle}</if>
            <if test="bluetoothConnectFailTitle != null  and bluetoothConnectFailTitle != ''"> and bluetooth_connect_fail_content = #{bluetoothConnectFailContent}</if>
            <if test="bluetoothConnectFail != null  and bluetoothConnectFail != ''"> and bluetooth_connect_fail = #{bluetoothConnectFail}</if>
            <if test="iotVersionUpgrade != null  and iotVersionUpgrade != ''"> and iot_version_upgrade = #{iotVersionUpgrade}</if>
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="manualCodeBinding != null  and manualCodeBinding != ''"> and manual_code_binding = #{manualCodeBinding}</if>
            <if test="scanCodeBinding != null  and scanCodeBinding != ''"> and scan_code_binding = #{scanCodeBinding}</if>
            <if test="we200IotVersion != null  and we200IotVersion != ''"> and we200_iot_version = #{we200IotVersion}</if>
            <if test="we200IotUpgradeData != null  and we200IotUpgradeData != ''"> and we200_iot_upgrade_data = #{we200IotUpgradeData}</if>
            <if test="we200IotVersionUpgrade != null  and we200IotVersionUpgrade != ''"> and we200_iot_version_upgrade = #{we200IotVersionUpgrade}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectWxInstrumentPage" parameterType="WxInstrumentReq" resultMap="WxInstrumentResult">
        <include refid="selectWxInstrumentVo"/>
        <where>
            <if test="id != null"> and id like concat('%', #{id}, '%')</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectWxInstrumentById" parameterType="Long" resultMap="WxInstrumentResult">
        <include refid="selectWxInstrumentVo"/>
        where id = #{id}
    </select>

    <select id="selectBindingInstrumentListByUserId" resultMap="WxInstrumentResult" parameterType="Long">
        SELECT
            ins.*
        FROM
            wx_user_instrument ui
            LEFT JOIN wx_instrument ins ON ui.instrument_id = ins.id
        WHERE
            ui.user_id = #{userId}
            AND ui.binding_status = 0
            AND ui.`STATUS` = 0
        ORDER BY
            ins.sort_no DESC,
            ui.create_time DESC
    </select>

    <select id="selectUnbindingInstrumentListByUserId" resultMap="WxInstrumentResult" parameterType="Long">
        SELECT
            ins.*
        FROM
            wx_instrument ins
        WHERE
            ins.id NOT IN (
                SELECT
                    ui.instrument_id
                FROM
                    wx_user_instrument ui
                WHERE
                    ui.user_id = #{userId}
                    AND ui.binding_status = 0
                    AND ui.`STATUS` = 0
            )
        ORDER BY ins.sort_no DESC
    </select>

    <insert id="insertWxInstrument" parameterType="WxInstrument" useGeneratedKeys="true" keyProperty="id">
        <selectKey keyProperty="id" resultType="Long" order="AFTER">
            SELECT LAST_INSERT_ID()
        </selectKey>
        insert into wx_instrument
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="type != null">type,</if>
            <if test="model != null and model != ''">model,</if>
            <if test="banner != null and banner != ''">banner,</if>
            <if test="logo != null and logo != ''">logo,</if>
            <if test="serial != null and serial != ''">serial,</if>
            <if test="guarantee != null">guarantee,</if>
            <if test="dailyClockCredit != null">daily_clock_credit,</if>
            <if test="isExtraClock != null">is_extra_clock,</if>
            <if test="extraClockCredit != null">extra_clock_credit,</if>
            <if test="startTime != null">start_time,</if>
            <if test="bindingCredit != null">binding_credit,</if>
            <if test="endTime != null">end_time,</if>
            <if test="miniTagIds != null">mini_tag_ids,</if>
            <if test="miniTagNames != null">mini_tag_names,</if>
            <if test="wecomTagIds != null">wecom_tag_ids,</if>
            <if test="wecomTagNames != null">wecom_tag_names,</if>
            <if test="nursingTime != null">nursing_time,</if>
            <if test="iotVersion != null">iot_version,</if>
            <if test="iotUpgradeData != null">iot_upgrade_data,</if>
            <if test="isScanCode != null">is_scan_code,</if>
            <if test="isPurchase != null">is_purchase,</if>
            <if test="shoppingAppid != null">shopping_appid,</if>
            <if test="shoppingPath != null">shopping_path,</if>
            <if test="bluetoothConnectingTitle != null">bluetooth_connecting_title,</if>
            <if test="bluetoothConnectingContent != null">bluetooth_connecting_Content,</if>
            <if test="bluetoothConnecting != null">bluetooth_connecting,</if>
            <if test="bluetoothClosedTitle != null">bluetooth_closed_title,</if>
            <if test="bluetoothClosedContent != null">bluetooth_closed_content,</if>
            <if test="bluetoothClosed != null">bluetooth_closed,</if>
            <if test="bluetoothConnectFailTitle != null">bluetooth_connect_fail_title,</if>
            <if test="bluetoothConnectFailContent != null">bluetooth_connect_fail_content,</if>
            <if test="bluetoothConnectFail != null">bluetooth_connect_fail,</if>
            <if test="iotVersionUpgrade != null">iot_version_upgrade,</if>
            <if test="sortNo != null">sort_no,</if>
            <if test="status != null">status,</if>
            <if test="manualCodeBinding != null and manualCodeBinding != ''">manual_code_binding,</if>
            <if test="scanCodeBinding != null and scanCodeBinding != ''">scan_code_binding,</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="remark != null">remark,</if>
            <if test="we200IotVersion != null">we200_iot_version,</if>
            <if test="we200IotUpgradeData != null">we200_iot_upgrade_data,</if>
            <if test="we200IotVersionUpgrade != null">we200_iot_version_upgrade,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="type != null">#{type},</if>
            <if test="model != null and model != ''">#{model},</if>
            <if test="banner != null and banner != ''">#{banner},</if>
            <if test="logo != null and logo != ''">#{logo},</if>
            <if test="serial != null and serial != ''">#{serial},</if>
            <if test="guarantee != null">#{guarantee},</if>
            <if test="dailyClockCredit != null">#{dailyClockCredit},</if>
            <if test="isExtraClock != null">#{isExtraClock},</if>
            <if test="extraClockCredit != null">#{extraClockCredit},</if>
            <if test="bindingCredit != null">#{bindingCredit},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="miniTagIds != null">#{miniTagIds},</if>
            <if test="miniTagNames != null">#{miniTagNames},</if>
            <if test="wecomTagIds != null">#{wecomTagIds},</if>
            <if test="wecomTagNames != null">#{wecomTagNames},</if>
            <if test="nursingTime != null">#{nursingTime},</if>
            <if test="iotVersion != null">#{iotVersion},</if>
            <if test="iotUpgradeData != null">#{iotUpgradeData},</if>
            <if test="isScanCode != null">#{isScanCode},</if>
            <if test="isPurchase != null">#{isPurchase},</if>
            <if test="shoppingAppid != null">#{shoppingAppid},</if>
            <if test="shoppingPath != null">#{shoppingPath},</if>
            <if test="bluetoothConnectingTitle != null">#{bluetoothConnectingTitle},</if>
            <if test="bluetoothConnectingContent != null">#{bluetoothConnectingContent},</if>
            <if test="bluetoothConnecting != null">#{bluetoothConnecting},</if>
            <if test="bluetoothClosedTitle != null">#{bluetoothClosedTitle},</if>
            <if test="bluetoothClosedContent != null">#{bluetoothClosedContent},</if>
            <if test="bluetoothClosed != null">#{bluetoothClosed},</if>
            <if test="bluetoothConnectFailTitle != null">#{bluetoothConnectFailTitle},</if>
            <if test="bluetoothConnectFailContent != null">#{bluetoothConnectFailContent},</if>
            <if test="bluetoothConnectFail != null">#{bluetoothConnectFail},</if>
            <if test="iotVersionUpgrade != null">#{iotVersionUpgrade},</if>
            <if test="sortNo != null">#{sortNo},</if>
            <if test="status != null">#{status},</if>
            <if test="manualCodeBinding != null and manualCodeBinding != ''">#{manualCodeBinding},</if>
            <if test="scanCodeBinding != null and scanCodeBinding != ''">#{scanCodeBinding},</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="remark != null">#{remark},</if>
            <if test="we200IotVersion != null">#{we200IotVersion},</if>
            <if test="we200IotUpgradeData != null">#{we200IotUpgradeData},</if>
            <if test="we200IotVersionUpgrade != null">#{we200IotVersionUpgrade},</if>
         </trim>
    </insert>

    <update id="updateWxInstrument" parameterType="WxInstrument">
        update wx_instrument
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="type != null">type = #{type},</if>
            <if test="model != null and model != ''">model = #{model},</if>
            <if test="banner != null and banner != ''">banner = #{banner},</if>
            <if test="logo != null and logo != ''">logo = #{logo},</if>
            <if test="serial != null and serial != ''">serial = #{serial},</if>
            <if test="guarantee != null">guarantee = #{guarantee},</if>
            <if test="dailyClockCredit != null">daily_clock_credit = #{dailyClockCredit},</if>
            <if test="isExtraClock != null">is_extra_clock = #{isExtraClock},</if>
            <if test="extraClockCredit != null">extra_clock_credit = #{extraClockCredit},</if>
            <if test="bindingCredit != null">binding_credit = #{bindingCredit},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="miniTagIds != null">mini_tag_ids = #{miniTagIds},</if>
            <if test="miniTagNames != null">mini_tag_names = #{miniTagNames},</if>
            <if test="wecomTagIds != null">wecom_tag_ids = #{wecomTagIds},</if>
            <if test="wecomTagNames != null">wecom_tag_names = #{wecomTagNames},</if>
            <if test="nursingTime != null">nursing_time = #{nursingTime},</if>
            <if test="iotVersion != null">iot_version = #{iotVersion},</if>
            <if test="iotUpgradeData != null">iot_upgrade_data = #{iotUpgradeData},</if>
            <if test="isScanCode != null">is_scan_code = #{isScanCode},</if>
            <if test="isPurchase != null">is_purchase = #{isPurchase},</if>
            <if test="shoppingAppid != null">shopping_appid = #{shoppingAppid},</if>
            <if test="shoppingPath != null">shopping_path = #{shoppingPath},</if>
            <if test="bluetoothConnectingTitle != null">bluetooth_connecting_title = #{bluetoothConnectingTitle},</if>
            <if test="bluetoothConnectingContent != null">bluetooth_connecting_content = #{bluetoothConnectingContent},</if>
            <if test="bluetoothConnecting != null">bluetooth_connecting = #{bluetoothConnecting},</if>
            <if test="bluetoothClosedTitle != null">bluetooth_closed_title = #{bluetoothClosedTitle},</if>
            <if test="bluetoothClosedContent != null">bluetooth_closed_content = #{bluetoothClosedContent},</if>
            <if test="bluetoothClosed != null">bluetooth_closed = #{bluetoothClosed},</if>
            <if test="bluetoothConnectFailTitle != null">bluetooth_connect_fail_title = #{bluetoothConnectFailTitle},</if>
            <if test="bluetoothConnectFailContent != null">bluetooth_connect_fail_content = #{bluetoothConnectFailContent},</if>
            <if test="bluetoothConnectFail != null">bluetooth_connect_fail = #{bluetoothConnectFail},</if>
            <if test="iotVersionUpgrade != null">iot_version_upgrade = #{iotVersionUpgrade},</if>
            <if test="sortNo != null">sort_no = #{sortNo},</if>
            <if test="status != null">status = #{status},</if>
            <if test="manualCodeBinding != null and manualCodeBinding != ''">manual_code_binding = #{manualCodeBinding},</if>
            <if test="scanCodeBinding != null and scanCodeBinding != ''">scan_code_binding = #{scanCodeBinding},</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="remark != null">remark = #{remark},</if>
            <if test="we200IotVersion != null">we200_iot_version = #{we200IotVersion},</if>
            <if test="we200IotUpgradeData != null">we200_iot_upgrade_data = #{we200IotUpgradeData},</if>
            <if test="we200IotVersionUpgrade != null">we200_iot_version_upgrade = #{we200IotVersionUpgrade},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteWxInstrumentById" parameterType="Long">
        delete from wx_instrument where id = #{id}
    </delete>

    <delete id="deleteWxInstrumentByIds" parameterType="Long">
        UPDATE wx_instrument SET status = IF(status = 1, 0, 1) where id = #{id}
    </delete>
</mapper>