Bonus-Cloud-JYY-Canteen/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/device/DoubleScreenMachineMapper.xml

250 lines
9.6 KiB
XML
Raw Normal View History

2025-04-08 18:13:48 +08:00
<?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.device.mapper.DoubleScreenMachineMapper">
<insert id="insertMachine" useGeneratedKeys="true" keyProperty="deviceId">
insert into device_info(tenant_id,device_ip, device_mac, device_gateway, device_sn, device_name, device_num, device_pwd,
2025-04-14 23:16:37 +08:00
device_addr, device_key,device_type)
2025-04-08 18:13:48 +08:00
values (#{tenantId},#{deviceIp}, #{deviceMac}, #{deviceGateway}, #{deviceSn}, #{deviceName}, #{deviceNum}, #{devicePwd},
2025-04-14 23:16:37 +08:00
#{deviceAddr}, #{deviceKey},#{deviceType})
2025-04-08 18:13:48 +08:00
</insert>
<insert id="insertMachineBind">
insert into device_bind(device_id,area_id,canteen_id,stall_id)
values (#{deviceId},#{areaId},#{canteenId},#{stallId})
</insert>
<update id="updateMachine">
update device_info
<set>
<if test="deviceIp != null and deviceIp != ''">
device_ip = #{deviceIp},
</if>
<if test="deviceMac != null and deviceMac != ''">
device_mac = #{deviceMac},
</if>
<if test="deviceGateway != null and deviceGateway != ''">
device_gateway = #{deviceGateway},
</if>
<if test="deviceSn != null and deviceSn != ''">
device_sn = #{deviceSn},
</if>
<if test="deviceName != null and deviceName != ''">
device_name = #{deviceName},
</if>
<if test="deviceNum != null and deviceNum != ''">
device_num = #{deviceNum},
</if>
<if test="devicePwd != null and devicePwd != ''">
device_pwd = #{devicePwd},
</if>
<if test="deviceAddr != null and deviceAddr != ''">
device_addr = #{deviceAddr},
</if>
<if test="deviceKey != null and deviceKey != ''">
device_key = #{deviceKey},
</if>
</set>
where device_id = #{deviceId}
</update>
<update id="updateMachineBind">
update device_bind
<set>
<if test="areaId != null and areaId != ''">
area_id = #{areaId},
</if>
<if test="canteenId != null and canteenId != ''">
canteen_id = #{canteenId},
</if>
<if test="stallId != null and stallId != ''">
stall_id = #{stallId},
</if>
</set>
where device_id = #{deviceId}
</update>
<update id="updateTimeBySn">
update device_info
set last_update_time = unix_timestamp()
where device_sn = #{sn}
</update>
<delete id="deleteMachine">
delete from device_info where device_id = #{deviceId}
</delete>
<delete id="deleteMachineBind">
delete from device_bind where device_id = #{deviceId}
</delete>
<select id="getDoubleScreenMachineList" resultType="com.bonus.canteen.core.device.vo.DeviceFullInfoVO">
SELECT
di.device_id AS deviceId,
di.device_num AS deviceNum,
di.device_name AS deviceName,
dr.recipe_name AS recipeName, -- 聚合菜谱名称,避免重复行
if((UNIX_TIMESTAMP() - di.last_update_time) > 120, '2','1' ) AS onlineState,
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.version_code AS versionCode,
2025-04-09 09:53:15 +08:00
di.device_state AS deviceState,
di.device_ip as deviceIp,
di.device_mac as deviceMac,
di.device_gateway AS deviceGateway,
di.device_sn AS deviceSn,
di.device_pwd as devicePwd,
di.device_addr AS deviceAddr,
di.device_key AS deviceKey
2025-04-08 18:13:48 +08:00
FROM device_info di
<!-- 根据条件动态选择INNER JOIN或LEFT JOIN device_bind -->
<choose>
<when test="areaId != null or canteenId != null or stallId != null or canteenIdList != null or stallIdList != null">
INNER JOIN device_bind db ON di.device_id = db.device_id
</when>
<otherwise>
LEFT JOIN device_bind db ON di.device_id = db.device_id
</otherwise>
</choose>
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
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>
<if test="keyWord != null and keyWord != ''">
and (
di.device_num like concat('%',#{keyWord},'%')
or di.device_name like concat('%',#{keyWord},'%')
or di.device_sn like concat('%',#{keyWord},'%')
)
</if>
<if test="areaId != null and areaId != ''">
AND db.area_id = #{areaId}
</if>
<if test="canteenId != null and canteenId != ''">
AND db.canteen_id = #{canteenId}
</if>
<if test="stallId != null and stallId != ''">
AND db.stall_id = #{stallId}
</if>
<if test="canteenIdList != null and canteenIdList.size() > 0">
AND db.canteen_id IN
<foreach collection="canteenIdList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="stallIdList != null and stallIdList.size() > 0">
AND db.stall_id IN
<foreach collection="stallIdList" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
</where>
GROUP BY di.device_id -- 通过分组去重,确保每个设备一行数据
</select>
<select id="checkIsExist" resultType="java.lang.Integer">
select count(1)
from device_info
2025-04-29 09:27:24 +08:00
where (device_num = #{keyWord}
or device_name = #{keyWord}
or device_sn = #{keyWord})
2025-04-08 18:13:48 +08:00
<if test="deviceId != null and deviceId != ''">
and device_id != #{deviceId}
</if>
</select>
2025-05-08 15:43:56 +08:00
<select id="checkIsExistDeviceNum" resultType="java.lang.Integer">
select count(1)
from device_info
where device_num = #{deviceNum}
<if test="deviceId != null and deviceId != ''">
and device_id != #{deviceId}
</if>
</select>
<select id="checkIsExistDeviceName" resultType="java.lang.Integer">
select count(1)
from device_info
where device_name = #{deviceName}
<if test="deviceId != null and deviceId != ''">
and device_id != #{deviceId}
</if>
</select>
<select id="checkIsExistDeviceSn" resultType="java.lang.Integer">
select count(1)
from device_info
where device_sn = #{deviceSn}
<if test="deviceId != null and deviceId != ''">
and device_id != #{deviceId}
</if>
</select>
2025-05-09 17:46:23 +08:00
<select id="getApkByType" resultType="com.bonus.canteen.core.device.dto.ApkDTO">
2025-05-12 09:26:47 +08:00
select *
from app_version
where 1 = 1
<if test="version != null and version != ''">
and version = #{version}
</if>
<if test="type != null and type != ''">
and type = #{type}
order by version desc
limit 1
</if>
2025-05-09 17:46:23 +08:00
</select>
2025-04-17 14:04:14 +08:00
<insert id="insertDeviceRecipe">
insert into device_recipe(id,device_id, canteen_id,stall_id,
revision)
values (#{id},#{deviceId}, #{canteenId}, #{stallId},'0')
</insert>
2025-05-09 17:46:23 +08:00
<insert id="insertApk">
insert into app_version(version, version_name, apk_name, apk_path, update_content, deploy_user, type)
values (#{version}, #{versionName}, #{apkName}, #{apkPath}, #{updateContent}, #{deployUser}, #{type})
</insert>
2025-04-17 14:04:14 +08:00
<update id="updateDeviceRecipe" >
update device_recipe
<set>
<if test="canteenId != null and canteenId != ''">
canteen_id = #{canteenId},
</if>
<if test="stallId != null and stallId != ''">
stall_id = #{stallId},
</if>
<if test="recipeId != null and recipeId != ''">
recipe_id = #{recipeId},
</if>
</set>
where device_id = #{deviceId}
</update>
2025-05-09 17:46:23 +08:00
<update id="updateApk">
update app_version
<set>
<if test="version != null and version != ''">
version = #{version},
</if>
<if test="versionName != null and versionName != ''">
version_name = #{versionName},
</if>
<if test="apkName != null and apkName != ''">
apk_name = #{apkName},
</if>
<if test="apkPath != null and apkPath != ''">
apk_path = #{apkPath},
</if>
<if test="updateContent != null and updateContent != ''">
update_content = #{updateContent},
</if>
<if test="deployUser != null and deployUser != ''">
deploy_user = #{deployUser},
</if>
<if test="type != null and type != ''">
type = #{type},
</if>
</set>
where version = #{version}
</update>
2025-04-17 14:04:14 +08:00
</mapper>