项目迁移

This commit is contained in:
邓文兵
2025-08-13 08:04:41 +08:00
parent 7cd96f160b
commit c39b7a0134
4244 changed files with 355998 additions and 0 deletions

View File

@@ -0,0 +1,122 @@
<?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="cn.iocoder.yudao.module.iot.dal.tdengine.IotDeviceLogMapper">
<update id="createDeviceLogSTable">
CREATE STABLE IF NOT EXISTS device_log (
ts TIMESTAMP,
id NCHAR(50),
product_key NCHAR(50),
device_name NCHAR(50),
type NCHAR(50),
identifier NCHAR(255),
content NCHAR(1024),
code INT,
report_time TIMESTAMP
) TAGS (
device_key NCHAR(50)
)
</update>
<select id="showDeviceLogSTable" resultType="String">
SHOW STABLES LIKE 'device_log'
</select>
<insert id="insert">
INSERT INTO device_log_${deviceKey} (ts, id, product_key, device_name, type, identifier, content, code, report_time)
USING device_log
TAGS ('${deviceKey}')
VALUES (
NOW,
#{id},
#{productKey},
#{deviceName},
#{type},
#{identifier},
#{content},
#{code},
#{reportTime}
)
</insert>
<select id="selectPage" resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.IotDeviceLogDO">
SELECT ts, id, device_key, product_key, type, identifier, content, report_time
FROM device_log_${reqVO.deviceKey}
<where>
<if test="reqVO.type != null and reqVO.type != ''">
AND type = #{reqVO.type}
</if>
<if test="reqVO.identifier != null and reqVO.identifier != ''">
AND identifier LIKE CONCAT('%',#{reqVO.identifier},'%')
</if>
</where>
ORDER BY ts DESC
</select>
<select id="selectCountByCreateTime" resultType="Long">
SELECT COUNT(*)
FROM device_log
<where>
<if test="createTime != null">
AND ts >= #{createTime}
</if>
</where>
</select>
<select id="selectDeviceLogUpCountByHour" resultType="java.util.Map">
SELECT
TIMETRUNCATE(ts, 1h) as time,
COUNT(*) as data
FROM
<choose>
<when test="deviceKey != null and deviceKey != ''">
device_log_${deviceKey}
</when>
<otherwise>
device_log
</otherwise>
</choose>
<where>
<if test="startTime != null">
AND ts >= #{startTime}
</if>
<if test="endTime != null">
AND ts &lt;= #{endTime}
</if>
AND (
identifier IN ('online', 'offline', 'pull', 'progress', 'report', 'register', 'register_sub')
)
</where>
GROUP BY TIMETRUNCATE(ts, 1h)
ORDER BY time ASC
</select>
<select id="selectDeviceLogDownCountByHour" resultType="java.util.Map">
SELECT
TIMETRUNCATE(ts, 1h) as time,
COUNT(*) as data
FROM
<choose>
<when test="deviceKey != null and deviceKey != ''">
device_log_${deviceKey}
</when>
<otherwise>
device_log
</otherwise>
</choose>
<where>
<if test="startTime != null">
AND ts >= #{startTime}
</if>
<if test="endTime != null">
AND ts &lt;= #{endTime}
</if>
AND identifier IN ('set', 'get', 'upgrade', 'unregister_sub', 'topology_add')
</where>
GROUP BY TIMETRUNCATE(ts, 1h)
ORDER BY time ASC
</select>
</mapper>

View File

@@ -0,0 +1,25 @@
<?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="cn.iocoder.yudao.module.iot.dal.mysql.device.IotDeviceMapper">
<select id="selectDeviceCountGroupByState" resultType="java.util.Map">
SELECT
state AS `key`,
COUNT(1) AS `value`
FROM iot_device
WHERE deleted = 0
GROUP BY state
</select>
<select id="selectDeviceCountMapByProductId" resultType="java.util.Map">
SELECT
product_id AS `key`,
COUNT(1) AS `value`
FROM iot_device
WHERE deleted = 0
GROUP BY product_id
</select>
</mapper>

View File

@@ -0,0 +1,78 @@
<?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="cn.iocoder.yudao.module.iot.dal.tdengine.IotDevicePropertyMapper">
<select id="getProductPropertySTableFieldList" resultType="cn.iocoder.yudao.module.iot.framework.tdengine.core.TDengineTableField">
DESCRIBE product_property_${productKey}
</select>
<update id="createProductPropertySTable">
CREATE STABLE product_property_${productKey} (
ts TIMESTAMP,
report_time TIMESTAMP,
<foreach item="field" collection="fields" separator=",">
${field.field} ${field.type}
<if test="field.length != null and field.length > 0">
(${field.length})
</if>
</foreach>
)
TAGS (
device_key NCHAR(50)
)
</update>
<update id="alterProductPropertySTableAddField">
ALTER STABLE product_property_${productKey}
ADD COLUMN ${field.field} ${field.type}
<if test="field.length != null and field.length > 0">
(${field.length})
</if>
</update>
<update id="alterProductPropertySTableModifyField">
ALTER STABLE product_property_${productKey}
MODIFY COLUMN ${field.field} ${field.type}
<if test="field.length != null and field.length > 0">
(${field.length})
</if>
</update>
<update id="alterProductPropertySTableDropField">
ALTER STABLE product_property_${productKey}
DROP COLUMN ${field.field}
</update>
<insert id="insert">
INSERT INTO device_property_${device.deviceKey}
USING product_property_${device.productKey}
TAGS ('${device.deviceKey}')
(ts, report_time,
<foreach item="key" collection="properties.keys" separator=",">
${@cn.hutool.core.util.StrUtil@toUnderlineCase(key)}
</foreach>
)
VALUES
(NOW, #{reportTime},
<foreach item="value" collection="properties.values" separator=",">
#{value}
</foreach>
)
</insert>
<select id="describeSuperTable" resultType="java.util.Map">
DESCRIBE product_property_${productKey}
</select>
<select id="selectPageByHistory" resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.data.IotDevicePropertyRespVO">
SELECT ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} AS `value`, ts AS update_time
FROM device_property_${reqVO.deviceKey}
WHERE ${@cn.hutool.core.util.StrUtil@toUnderlineCase(reqVO.identifier)} IS NOT NULL
AND ts BETWEEN ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[0])}
AND ${@cn.hutool.core.date.LocalDateTimeUtil@toEpochMilli(reqVO.times[1])}
ORDER BY ts DESC
</select>
</mapper>