<?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.canteen.core.android.mapper.DeviceMapper">
    <select id="getDeviceInfo" resultType="com.bonus.canteen.core.android.vo.DeviceInfoVo">
        SELECT di.device_num                            AS deviceNum,
               di.device_name                           AS deviceName,
               dr.recipe_id                             AS recipeId,
               dr.recipe_name                           AS recipeName,
               CONCAT(aaa.area_name, '/', aa.area_name) AS areaName,
               aa.area_id                               AS areaId,
               ac.canteen_name                          AS canteenName,
               ac.canteen_id                            AS canteenId,
               ast.stall_name                           AS stallName,
               ast.stall_id                             AS stallId,
               di.device_pwd                            as devicePwd
        FROM device_info di
                 LEFT JOIN device_bind db ON di.device_id = db.device_id
                 left join alloc_area aa on db.area_id = aa.area_id
                 left join alloc_area aaa on aaa.area_id = aa.parent_id
                 LEFT JOIN alloc_canteen ac ON db.canteen_id = ac.canteen_id
                 LEFT JOIN alloc_stall ast ON db.stall_id = ast.stall_id
                 LEFT JOIN (SELECT dr.device_id, mr.recipe_name,mr.recipe_id
                            FROM device_recipe dr
                                     LEFT JOIN menu_recipe mr ON dr.recipe_id = mr.recipe_id) dr
                           ON di.device_id = dr.device_id
        where di.device_sn = #{deviceSn}
        GROUP BY di.device_id
    </select>
    <select id="getAppVersion" resultType="com.bonus.canteen.core.android.vo.AppVersionVo">
        select
            version as id,
            version as version,
            version_name as versionName,
            apk_name as apkName,
            apk_path as apkPath,
            update_content as updateContent,
            deploy_time as deployTime,
            deploy_user as deployUser
        from app_version
        where type = #{type} and version > #{id}
    </select>
</mapper>