feat: 地图实时显示设备位置,功能代码提交。
This commit is contained in:
@@ -39,6 +39,15 @@ spring:
|
||||
# 共享配置
|
||||
shared-configs:
|
||||
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
|
||||
|
||||
# 管理端点配置
|
||||
management:
|
||||
health:
|
||||
db:
|
||||
enabled: false # 临时禁用数据库健康检查
|
||||
endpoint:
|
||||
health:
|
||||
show-details: always
|
||||
# 用于服务监控可在线查看日志,该配置用于生产环境
|
||||
logging:
|
||||
file:
|
||||
|
||||
@@ -44,12 +44,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<!-- Swagger UI -->
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${swagger.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Mysql Connector -->
|
||||
<!-- <dependency>-->
|
||||
@@ -87,27 +81,10 @@
|
||||
<artifactId>intc-common-swagger</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--mysql脚本版本管理-->
|
||||
<dependency>
|
||||
<groupId>org.flywaydb</groupId>
|
||||
<artifactId>flyway-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.taosdata.jdbc</groupId>
|
||||
<artifactId>taos-jdbcdriver</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intc</groupId>
|
||||
<artifactId>intc-api-tdengine</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.intc</groupId>
|
||||
<artifactId>intc-api-iot-basics</artifactId>
|
||||
<version>3.6.3</version>
|
||||
<scope>compile</scope>
|
||||
<version>2.0.38</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package com.intc.tdengine.controller;
|
||||
|
||||
|
||||
import com.intc.common.core.web.controller.BaseController;
|
||||
import com.intc.tdengine.service.DataDemoService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* TDEngine监控数据信息Controller
|
||||
*
|
||||
* @author YaphetS
|
||||
* @date 2023-03-13
|
||||
*/
|
||||
@Api(tags="TDEngine监控数据")
|
||||
@RestController
|
||||
@RequestMapping("/data/demo")
|
||||
public class DataDemoController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private DataDemoService dataService;
|
||||
|
||||
@GetMapping("/send")
|
||||
public String send(){
|
||||
dataService.dataDemo();
|
||||
return "SUCESS";
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,13 @@
|
||||
package com.intc.tdengine.controller;
|
||||
|
||||
import com.intc.api.tdengine.domain.DataAvdVo;
|
||||
import com.intc.api.tdengine.domain.DataDto;
|
||||
import com.intc.api.tdengine.domain.RealDataVo;
|
||||
|
||||
import com.intc.common.core.web.controller.BaseController;
|
||||
import com.intc.common.core.web.domain.AjaxResult;
|
||||
import com.intc.tdengine.domain.DeviceSensorData;
|
||||
import com.intc.tdengine.service.TdEngineService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
@@ -30,31 +27,29 @@ public class TdEngineController extends BaseController
|
||||
@Resource
|
||||
private TdEngineService tdEngineService;
|
||||
|
||||
@GetMapping("/getLastData")
|
||||
public List<DeviceSensorData> getLastData()
|
||||
{
|
||||
return tdEngineService.getLastData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询TDEngine监控数据列表
|
||||
* 批量插入设备传感器数据
|
||||
*/
|
||||
@ApiOperation(value="按类型查询对应点最新数据的平均值和最大最小值")
|
||||
@PostMapping("/selectMaxMinAvgData")
|
||||
public DataAvdVo selectMaxMinAvgData(@RequestParam(value = "tagTypeId") String tagTypeId)
|
||||
@PostMapping("/batchInsert")
|
||||
@ApiOperation(value = "批量插入设备传感器数据", notes = "批量插入TDEngine监控数据")
|
||||
public AjaxResult batchInsertData(@RequestBody List<DeviceSensorData> dataList)
|
||||
{
|
||||
return tdEngineService.selectMaxMinAvgData(tagTypeId);
|
||||
}
|
||||
@ApiOperation(value="按类型查询对应点最新数据的平均值和最大最小值")
|
||||
@PostMapping("/selectDataListToMap")
|
||||
public Map<String, String> selectDataListToMap(DataDto dataDto)
|
||||
{
|
||||
return tdEngineService.selectDataListToMap(dataDto);
|
||||
}
|
||||
@ApiOperation(value="查询最新数据")
|
||||
@PostMapping("/getLastData")
|
||||
public RealDataVo getLastData(@RequestParam(value = "tagId") String tagId)
|
||||
{
|
||||
return tdEngineService.getLastData(tagId);
|
||||
}
|
||||
@ApiOperation(value="查询历史数据")
|
||||
@PostMapping("/getHistoryData")
|
||||
public List<RealDataVo> getHistoryData(@RequestParam(value = "tagId") String tagId, @RequestParam(value = "startTime") String startTime, @RequestParam(value = "endTime") String endTime)
|
||||
{
|
||||
return tdEngineService.getHistoryData(tagId,startTime,endTime);
|
||||
if (dataList == null || dataList.isEmpty()) {
|
||||
return AjaxResult.error("数据列表不能为空");
|
||||
}
|
||||
try {
|
||||
tdEngineService.batchInsertDeviceSensorData(dataList);
|
||||
return AjaxResult.success("成功插入 " + dataList.size() + " 条数据");
|
||||
} catch (Exception e) {
|
||||
logger.error("批量插入数据失败", e);
|
||||
return AjaxResult.error("批量插入数据失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.intc.tdengine.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor // 生成无参构造方法
|
||||
@AllArgsConstructor // 生成全参构造方法
|
||||
public class DeviceSensorData {
|
||||
|
||||
// 测量字段(随时间变化的数值)
|
||||
private String time; // 时序主键时间戳
|
||||
private String createTime; // 数据创建时间
|
||||
private Double longitude; // 经度
|
||||
private Double latitude; // 纬度
|
||||
// 标签字段(元数据,不随时间频繁变化)
|
||||
private String deviceId; // 设备序列号
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package com.intc.tdengine.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author 22024089
|
||||
*/
|
||||
@Data
|
||||
public class RealTimeDataT implements Serializable {
|
||||
|
||||
private String tagId;
|
||||
private String buildingId;
|
||||
private String valueType;
|
||||
private String tagShowType;
|
||||
private String deviceId;
|
||||
private String tagTypeId;
|
||||
private Date dataTime;
|
||||
private String val;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.intc.tdengine.mapper;
|
||||
|
||||
|
||||
import com.intc.tdengine.domain.RealTimeDataT;
|
||||
|
||||
/**
|
||||
* @author 22024089
|
||||
*/
|
||||
public interface DataDemoMapper {
|
||||
/**
|
||||
* 新增实时数据
|
||||
*
|
||||
* @param realTimeData 实时数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
|
||||
public int insertRealTimeDataT(RealTimeDataT realTimeData);
|
||||
|
||||
public int createTableT(RealTimeDataT realTimeData);
|
||||
}
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.intc.tdengine.mapper;
|
||||
|
||||
import com.intc.api.tdengine.domain.DataAvdVo;
|
||||
import com.intc.api.tdengine.domain.DataDto;
|
||||
import com.intc.api.tdengine.domain.RealDataVo;
|
||||
|
||||
import com.intc.tdengine.domain.DeviceSensorData;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
@@ -15,17 +14,50 @@ import java.util.List;
|
||||
*/
|
||||
public interface TdEngineMapper
|
||||
{
|
||||
|
||||
/**
|
||||
* 点类型统计信息
|
||||
* 删除数据库
|
||||
*
|
||||
* @param tagTypeId 点类型ID
|
||||
* @return 点类型统计信息
|
||||
* @return 结果
|
||||
*/
|
||||
public DataAvdVo selectMaxMinAvgData(String tagTypeId);
|
||||
void dropDB();
|
||||
|
||||
RealDataVo getLastData(String tagId);
|
||||
/**
|
||||
* 创建数据库
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
void createDB();
|
||||
|
||||
/**
|
||||
* 创建超级表
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
void createSuperTable();
|
||||
|
||||
/**
|
||||
* 创建子表
|
||||
*
|
||||
* @param deviceSensorData 数据信息
|
||||
* @return 结果
|
||||
*/
|
||||
void createTable(DeviceSensorData deviceSensorData);
|
||||
|
||||
/**
|
||||
* 获取最新数据
|
||||
*
|
||||
* @return 结果
|
||||
*/
|
||||
List<DeviceSensorData> getLastData();
|
||||
|
||||
/**
|
||||
* 批量插入数据
|
||||
*
|
||||
* @param dataList 数据列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int batchInsertDeviceSensorData(@Param("dataList") List<DeviceSensorData> dataList);
|
||||
|
||||
List<RealDataVo> selectDataList(DataDto dataDto);
|
||||
|
||||
List<RealDataVo> getHistoryDataList(@Param("tagId") String tagId,@Param("startTime") String startTime,@Param("endTime") String endTime);
|
||||
}
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
package com.intc.tdengine.service;
|
||||
|
||||
|
||||
import com.intc.api.basics.RemoteDeviceService;
|
||||
import com.intc.api.basics.domain.TagBasicInfoApiDto;
|
||||
import com.intc.api.basics.domain.TagBasicInfoApiVo;
|
||||
import com.intc.common.core.utils.DateUtils;
|
||||
import com.intc.common.core.utils.LocalDateUtils;
|
||||
import com.intc.tdengine.domain.RealTimeDataT;
|
||||
import com.intc.tdengine.mapper.DataDemoMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 设备实时状态Service业务层处理
|
||||
*
|
||||
* @author tianyongbao
|
||||
* @date 2023-03-10
|
||||
*/
|
||||
@Service
|
||||
public class DataDemoService
|
||||
{
|
||||
@Resource
|
||||
private RemoteDeviceService remoteDeviceService;
|
||||
@Resource
|
||||
private DataDemoMapper dataDemoMapper;
|
||||
public void dataDemo(){
|
||||
TagBasicInfoApiDto tagBasicInfoApiDto = new TagBasicInfoApiDto();
|
||||
tagBasicInfoApiDto.setIsShow("1");
|
||||
long time = DateUtils.parseDate(DateUtils.dateTimeNow("yyyy-MM-dd HH:00:00")).getTime();
|
||||
List<TagBasicInfoApiVo> tagBasicInfoVos = remoteDeviceService.tagListAll(tagBasicInfoApiDto).getData();
|
||||
for (TagBasicInfoApiVo tagBasicInfoVo : tagBasicInfoVos) {
|
||||
for (int i = 0; i < 48; i++) {
|
||||
String data="20";
|
||||
Double num=20.0;
|
||||
if("1".equals(tagBasicInfoVo.getValueType())){
|
||||
data=String.valueOf((int) (Math.random()*99)/50);
|
||||
|
||||
}else if("2".equals(tagBasicInfoVo.getValueType())){
|
||||
/**氧气浓度*/
|
||||
if(14==tagBasicInfoVo.getTagTypeId()){
|
||||
num=num+new Random().nextDouble()*2;
|
||||
num=num-new Random().nextDouble()*2;
|
||||
} /**温度*/
|
||||
else if(16==tagBasicInfoVo.getTagTypeId()){
|
||||
num=num+new Random().nextDouble()*2;
|
||||
}/**湿度*/
|
||||
else if(15==tagBasicInfoVo.getTagTypeId()){
|
||||
num=45.0;
|
||||
num=num-new Random().nextDouble()*2;
|
||||
}/**甲烷*/
|
||||
else if(23==tagBasicInfoVo.getTagTypeId()){
|
||||
num=0.0;
|
||||
}/**硫化氢*/
|
||||
else if(22==tagBasicInfoVo.getTagTypeId()){
|
||||
num=0.0;
|
||||
}
|
||||
/**位移*/
|
||||
else if(4==tagBasicInfoVo.getTagTypeId()){
|
||||
num=9.0;
|
||||
}
|
||||
/**沉降*/
|
||||
else if(5==tagBasicInfoVo.getTagTypeId()){
|
||||
num=9.0;
|
||||
}
|
||||
/**压力*/
|
||||
else if(7==tagBasicInfoVo.getTagTypeId()){
|
||||
num=50.0;
|
||||
}
|
||||
/**流量*/
|
||||
else if(8==tagBasicInfoVo.getTagTypeId()){
|
||||
num=50.0;
|
||||
}else{
|
||||
num=25.0;
|
||||
num=num-new Random().nextDouble()*2;
|
||||
}
|
||||
num=(double) Math.round(num * 100) / 100;
|
||||
data= String.valueOf(num);
|
||||
}
|
||||
|
||||
// num=num+new Random().nextDouble()*5;
|
||||
|
||||
RealTimeDataT realTimeData = new RealTimeDataT();
|
||||
realTimeData.setTagId(String.valueOf(tagBasicInfoVo.getId()));
|
||||
|
||||
realTimeData.setDeviceId(tagBasicInfoVo.getDeviceId());
|
||||
realTimeData.setBuildingId(tagBasicInfoVo.getBuildingId());
|
||||
realTimeData.setTagTypeId(String.valueOf(tagBasicInfoVo.getTagTypeId()));
|
||||
realTimeData.setValueType(tagBasicInfoVo.getValueType());
|
||||
realTimeData.setTagShowType(tagBasicInfoVo.getIsShow());
|
||||
realTimeData.setDataTime(LocalDateUtils.LocalDateTimetoDate(LocalDateTime.now().minusMinutes(i*30),null));
|
||||
realTimeData.setVal(data);
|
||||
if(i==0){
|
||||
dataDemoMapper.createTableT(realTimeData);
|
||||
}
|
||||
dataDemoMapper.insertRealTimeDataT(realTimeData);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
System.out.println(String.valueOf((int) (Math.random()*99)/50));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.intc.tdengine.service;
|
||||
|
||||
import com.intc.api.tdengine.domain.DataAvdVo;
|
||||
import com.intc.api.tdengine.domain.DataDto;
|
||||
import com.intc.api.tdengine.domain.RealDataVo;
|
||||
import com.intc.tdengine.domain.DeviceSensorData;
|
||||
import com.intc.tdengine.mapper.TdEngineMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,44 +21,19 @@ import java.util.Map;
|
||||
public class TdEngineService {
|
||||
@Resource
|
||||
private TdEngineMapper tdEngineMapper;
|
||||
public DataAvdVo selectMaxMinAvgData(String tagTypeId){
|
||||
DataAvdVo dataAvdVo=new DataAvdVo();
|
||||
try {
|
||||
dataAvdVo= tdEngineMapper.selectMaxMinAvgData(tagTypeId);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return dataAvdVo;
|
||||
}
|
||||
|
||||
public RealDataVo getLastData(String tagId) {
|
||||
RealDataVo lastData=null;
|
||||
try {
|
||||
lastData = tdEngineMapper.getLastData(tagId);
|
||||
}catch (Exception e){
|
||||
lastData=new RealDataVo();
|
||||
|
||||
}
|
||||
return lastData;
|
||||
}
|
||||
|
||||
public Map<String, String> selectDataListToMap(DataDto dataDto) {
|
||||
Map<String,String> map=new HashMap<>();
|
||||
List<RealDataVo> dataVoList=tdEngineMapper.selectDataList(dataDto);
|
||||
if(dataVoList!=null&&dataVoList.size()>0){
|
||||
for (RealDataVo realDataVo : dataVoList) {
|
||||
map.put(realDataVo.getTagId(),realDataVo.getVal());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public List<RealDataVo> getHistoryData(String tagId, String startTime, String endTime) {
|
||||
List<RealDataVo> list=new ArrayList<>();
|
||||
try {
|
||||
list=tdEngineMapper.getHistoryDataList(tagId,startTime,endTime);
|
||||
}catch (Exception e){
|
||||
|
||||
}
|
||||
public List<DeviceSensorData> getLastData() {
|
||||
List<DeviceSensorData> list = new ArrayList<>();
|
||||
list = tdEngineMapper.getLastData();
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量插入数据
|
||||
*
|
||||
* @param dataList 数据列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
public void batchInsertDeviceSensorData(List<DeviceSensorData> dataList) {
|
||||
tdEngineMapper.batchInsertDeviceSensorData(dataList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,13 +14,17 @@ spring:
|
||||
nacos:
|
||||
discovery:
|
||||
namespace: intc
|
||||
# 服务注册地址
|
||||
server-addr: 101.126.95.100:8858
|
||||
group: dev
|
||||
username: nacos
|
||||
password: ZmNDMacAng
|
||||
# 配置中心地址
|
||||
server-addr: 172.16.0.4:8858
|
||||
group: intc
|
||||
config:
|
||||
namespace: intc
|
||||
username: nacos
|
||||
password: ZmNDMacAng
|
||||
# 配置中心地址
|
||||
server-addr: 101.126.95.100:8858
|
||||
server-addr: 172.16.0.4:8858
|
||||
# 配置文件格式
|
||||
file-extension: yml
|
||||
# 共享配置
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?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.intc.tdengine.mapper.DataDemoMapper">
|
||||
|
||||
<insert id="createTableT" parameterType="RealTimeDataT">
|
||||
create table if not exists
|
||||
pg_d.t${tagId}
|
||||
USING pg_d.pg_monitor_data(buildingId,valueType,tagId,deviceId,tagShowType,tagTypeId)
|
||||
TAGS (#{buildingId}, #{valueType}, #{tagId}, #{deviceId}, #{tagShowType}, #{tagTypeId})
|
||||
</insert>
|
||||
<insert id="insertRealTimeDataT" parameterType="RealTimeDataT">
|
||||
insert into pg_d.t${tagId} VALUES (#{dataTime},NOW, #{val});
|
||||
</insert>
|
||||
<update id="createSuperTable">
|
||||
create table if not exists
|
||||
pg_d.pg_monitor_data(time timestamp,createTime timestamp, val nchar(100))
|
||||
tags(buildingId nchar(100),valueType nchar(10), tagId nchar(100),deviceId nchar(100),tagShowType nchar(50),tagTypeId nchar(100))
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -3,55 +3,52 @@
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.intc.tdengine.mapper.TdEngineMapper">
|
||||
<!-- <update id="createSuperTable">-->
|
||||
<!-- create table if not exists-->
|
||||
<!-- pg_d.pg_monitor_data(time timestamp,createTime timestamp, val nchar(20))-->
|
||||
<!-- tags(buildingId nchar(100),valueType nchar(10), tagId nchar(100),deviceId nchar(100),tagShowType nchar(50),tagTypeId nchar(100))-->
|
||||
<!-- </update>-->
|
||||
<!-- <insert id="createTable" parameterType="RealTimeData">-->
|
||||
<!-- create table if not exists-->
|
||||
<!-- pg_d.t${tagId}-->
|
||||
<!-- USING pg_d.pg_monitor_data(buildingId,valueType,tagId,deviceId,tagShowType,tagTypeId)-->
|
||||
<!-- TAGS (#{buildingId}, #{valueType}, #{tagId}, #{deviceId}, #{tagshowType}, #{tagTypeId})-->
|
||||
<!-- </insert>-->
|
||||
<!-- <insert id="insertRealTimeData" parameterType="RealTimeData">-->
|
||||
<!-- insert into pg_d.t${tagId} VALUES (#{dataTime},NOW, #{val});-->
|
||||
<!-- </insert>-->
|
||||
<select id="selectMaxMinAvgData" parameterType="String" resultType="DataAvdVo">
|
||||
select avg(cast(val as double)) as avg,max(cast(val as double)) as max,min(cast(val as double)) as min
|
||||
from ( select last_row(*)
|
||||
from pg_d.pg_monitor_data
|
||||
<where>
|
||||
tagtypeid=#{tagTypeId} and valueType!='3'
|
||||
</where>
|
||||
group by tagid
|
||||
)
|
||||
|
||||
</select>
|
||||
<select id="getLastData" parameterType="String" resultType="RealDataVo">
|
||||
select last_row(*)
|
||||
from pg_d.t${tagId}
|
||||
</select>
|
||||
<resultMap type="RealDataVo" id="RealDataVoResult">
|
||||
<result property="time" column="last_row(time)" />
|
||||
<result property="createTime" column="last_row(createtime)" />
|
||||
<result property="val" column="last_row(val)" />
|
||||
</resultMap>
|
||||
<select id="selectDataList" parameterType="DataDto" resultType="RealDataVo" >
|
||||
select last_row(time,createTime,val),tagid from pg_d.pg_monitor_data
|
||||
<update id="dropDB">
|
||||
drop database if exists bds
|
||||
</update>
|
||||
|
||||
<update id="createDB">
|
||||
create database if not exists bds
|
||||
</update>
|
||||
|
||||
<update id="createSuperTable">
|
||||
create table if not exists
|
||||
bds.sensor_data(time timestamp,createTime timestamp, longitude double, latitude double)
|
||||
tags(
|
||||
deviceId nchar(100)
|
||||
)
|
||||
</update>
|
||||
<select id="getLastData" resultType="DeviceSensorData">
|
||||
select last_row(time,createTime,longitude,latitude),deviceId from bds.sensor_data
|
||||
<where>
|
||||
time>=now-1d
|
||||
<if test="tagId != null and tagId != ''"> AND tagid=#{tagId}</if>
|
||||
<if test="deviceId != null and deviceId != ''"> AND deviceid=#{deviceId}</if>
|
||||
<if test="buildingId != null and buildingId != ''"> AND buildingId=#{buildingId}</if>
|
||||
<if test="tagTypeId != null and tagTypeId != ''"> AND tagTypeId=#{tagTypeId}</if>
|
||||
</where>
|
||||
group by tagid
|
||||
</select>
|
||||
<select id="getHistoryDataList" parameterType="String" resultType="RealDataVo">
|
||||
select time,createTime,val,tagId from pg_d.t${tagId}
|
||||
<where>
|
||||
time >= #{startTime} and time <= #{endTime}
|
||||
<if test="deviceId != null and deviceId != ''"> AND deviceId=#{deviceId}</if>
|
||||
</where>
|
||||
group by deviceId
|
||||
</select>
|
||||
|
||||
<insert id="batchInsertDeviceSensorData">
|
||||
insert into
|
||||
<foreach collection="dataList" item="data" open="" close="" separator=" ">
|
||||
`bds`.t_#{data.deviceId}
|
||||
|
||||
using bds.sensor_data
|
||||
|
||||
tags(#{data.deviceId})
|
||||
|
||||
(time, createTime, longitude, latitude) values (#{data.time}, ${data.createTime}, ${data.longitude}, ${data.latitude})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="createTable" parameterType="com.intc.tdengine.domain.DeviceSensorData">
|
||||
|
||||
create table if not exists
|
||||
|
||||
`bds`.t_#{deviceId}
|
||||
|
||||
using bds.sensor_data
|
||||
|
||||
tags(#{deviceId})
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
@@ -1,58 +1,78 @@
|
||||
package com.intc.weixin.controller;
|
||||
|
||||
import com.intc.weixin.utils.CheckUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import com.intc.common.core.web.domain.AjaxResult;
|
||||
import com.intc.weixin.entity.WxUser;
|
||||
import com.intc.weixin.service.WxUserService;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import com.intc.weixin.entity.WxOpenDataDTO;
|
||||
import com.intc.weixin.utils.ThirdSessionHolder;
|
||||
|
||||
/**
|
||||
* 业务模块
|
||||
*
|
||||
* @author tianyongbao
|
||||
* @date 2025/1/8
|
||||
*/
|
||||
|
||||
/**
|
||||
* 服务器验证
|
||||
* 微信小程序接口
|
||||
*
|
||||
* @author tianyongbao
|
||||
* @date 2025/1/8
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("/api")
|
||||
@Api(tags = "对接微信模块")
|
||||
@RequestMapping("/weixin/api")
|
||||
@Api(tags = "微信小程序接口")
|
||||
public class WeChatController {
|
||||
/**
|
||||
* 功能描述: 签名校验
|
||||
*/
|
||||
@GetMapping("/wx")
|
||||
@ApiOperation(value = "签名校验", notes = "签名校验")
|
||||
public void login(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
|
||||
request.setCharacterEncoding("UTF-8");
|
||||
String signature = request.getParameter("signature");
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
String nonce = request.getParameter("nonce");
|
||||
String echostr = request.getParameter("echostr");
|
||||
PrintWriter out = null;
|
||||
private final WxUserService wxUserService;
|
||||
|
||||
@PostMapping("/ma/wxuser/login")
|
||||
@ApiOperation(value = "微信小程序登录", notes = "通过 appId + jsCode 进行登录,返回 thirdSession")
|
||||
public AjaxResult loginMini(@RequestParam("appId") String appId,
|
||||
@RequestParam("jsCode") String jsCode) {
|
||||
if (StringUtils.isBlank(appId) || StringUtils.isBlank(jsCode)) {
|
||||
return AjaxResult.error("appId 或 jsCode 不能为空");
|
||||
}
|
||||
try {
|
||||
out = response.getWriter();
|
||||
if (CheckUtil.checkSignature(signature, timestamp, nonce)) {
|
||||
out.write(echostr);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
out.close();
|
||||
WxUser wxUser = wxUserService.loginMa(appId, jsCode);
|
||||
return AjaxResult.success(wxUser);
|
||||
} catch (WxErrorException e) {
|
||||
return AjaxResult.error(e.getMessage());
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("登录失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/ma/wxuser/decrypt-save")
|
||||
@ApiOperation(value = "小程序用户信息解密并保存", notes = "通过 encryptedData + iv 解密用户信息,并保存到数据库")
|
||||
public AjaxResult decryptAndSaveMaUser(@RequestParam("appId") String appId,
|
||||
@RequestParam("encryptedData") String encryptedData,
|
||||
@RequestParam("iv") String iv,
|
||||
@RequestParam(value = "rawData", required = false) String rawData,
|
||||
@RequestParam(value = "signature", required = false) String signature) {
|
||||
if (StringUtils.isBlank(appId) || StringUtils.isBlank(encryptedData) || StringUtils.isBlank(iv)) {
|
||||
return AjaxResult.error("appId、encryptedData 或 iv 不能为空");
|
||||
}
|
||||
try {
|
||||
// 从 ThirdSession 中获取用户ID与会话密钥
|
||||
String userId = ThirdSessionHolder.getWxUserId();
|
||||
String sessionKey = ThirdSessionHolder.getThirdSession().getSessionKey();
|
||||
|
||||
WxOpenDataDTO dto = new WxOpenDataDTO();
|
||||
dto.setAppId(appId);
|
||||
dto.setUserId(userId);
|
||||
dto.setEncryptedData(encryptedData);
|
||||
dto.setIv(iv);
|
||||
dto.setRawData(rawData);
|
||||
dto.setSignature(signature);
|
||||
dto.setSessionKey(sessionKey);
|
||||
|
||||
WxUser wxUser = wxUserService.saveOrUptateWxUser(dto);
|
||||
return AjaxResult.success(wxUser);
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("解密失败或保存异常,请稍后重试");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user