设备配置同步
This commit is contained in:
parent
7adbdf88b3
commit
63da8e002c
|
|
@ -0,0 +1,121 @@
|
|||
package com.nu.modules.iot.tplink.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-TPLINK项目信息
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("nu_iot_tplink_project")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="nu_iot_tplink_project对象", description="护理单元-物联管理-TPLINK项目信息")
|
||||
public class AppProjectInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**ID*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Integer id;
|
||||
/**项目ID*/
|
||||
@Excel(name = "项目ID", width = 15)
|
||||
@ApiModelProperty(value = "项目ID")
|
||||
private String projectId;
|
||||
/**项目名称*/
|
||||
@Excel(name = "项目名称", width = 15)
|
||||
@ApiModelProperty(value = "项目名称")
|
||||
private String projectName;
|
||||
/**机构ID*/
|
||||
@Excel(name = "机构ID", width = 15)
|
||||
@ApiModelProperty(value = "机构ID")
|
||||
@Dict(dicCode = "id" , dictTable = "sys_depart" , dicText = "depart_name")
|
||||
private String institutionId;
|
||||
/**创建时间戳,单位秒*/
|
||||
@ApiModelProperty(value = "创建时间戳,单位秒")
|
||||
private String createTime;
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "创建时间,年月日时分秒")
|
||||
private String createTimeStr;
|
||||
/**设备数量*/
|
||||
@Excel(name = "设备数量", width = 15)
|
||||
@ApiModelProperty(value = "设备数量")
|
||||
private Integer deviceNum;
|
||||
/**消息数量*/
|
||||
@Excel(name = "消息数量", width = 15)
|
||||
@ApiModelProperty(value = "消息数量")
|
||||
private Integer messageNum;
|
||||
/**项目次序*/
|
||||
@Excel(name = "项目次序", width = 15)
|
||||
@ApiModelProperty(value = "项目次序")
|
||||
private Integer sort;
|
||||
/**项目次序,接口对应字段,在数据库中是关键字,数据库中用sort代替order*/
|
||||
@ApiModelProperty(value = "项目次序")
|
||||
@TableField(exist = false)
|
||||
private String order;
|
||||
/** 离线设备数*/
|
||||
@Excel(name = "离线设备数", width = 15)
|
||||
@ApiModelProperty(value = "离线设备数")
|
||||
private Integer offlineNum;
|
||||
/**异常设备数*/
|
||||
@Excel(name = "异常设备数", width = 15)
|
||||
@ApiModelProperty(value = "异常设备数")
|
||||
private Integer abnormalNum;
|
||||
/**未读消息数*/
|
||||
@Excel(name = "未读消息数", width = 15)
|
||||
@ApiModelProperty(value = "未读消息数")
|
||||
private Integer unreadMessageNum;
|
||||
/**nms设备总数*/
|
||||
@Excel(name = "nms设备总数", width = 15)
|
||||
@ApiModelProperty(value = "nms设备总数")
|
||||
private Integer totalNmsDevNum;
|
||||
/**vms设备总数*/
|
||||
@Excel(name = "vms设备总数", width = 15)
|
||||
@ApiModelProperty(value = "vms设备总数")
|
||||
private Integer totalVmsDevNum;
|
||||
/**nbs设备总数*/
|
||||
@Excel(name = "nbs设备总数", width = 15)
|
||||
@ApiModelProperty(value = "nbs设备总数")
|
||||
private Integer totalNbsDevNum;
|
||||
/**离线nms设备总数*/
|
||||
@Excel(name = "离线nms设备总数", width = 15)
|
||||
@ApiModelProperty(value = "离线nms设备总数")
|
||||
private Integer offlineNmsDevNum;
|
||||
/**离线vms设备总数*/
|
||||
@Excel(name = "离线vms设备总数", width = 15)
|
||||
@ApiModelProperty(value = "离线vms设备总数")
|
||||
private Integer offlineVmsDevNum;
|
||||
/**离线nbs设备总数*/
|
||||
@Excel(name = "离线nbs设备总数", width = 15)
|
||||
@ApiModelProperty(value = "离线nbs设备总数")
|
||||
private Integer offlineNbsDevNum;
|
||||
/**运行时间,单位s*/
|
||||
@Excel(name = "运行时间,单位s", width = 15)
|
||||
@ApiModelProperty(value = "运行时间,单位s")
|
||||
private Integer runningTime;
|
||||
@TableField(exist = false)
|
||||
@ApiModelProperty(value = "运行天数")
|
||||
private String runningTimeStr;
|
||||
/**状态1正常 2冻结*/
|
||||
@Excel(name = "状态1正常 2冻结", width = 15)
|
||||
@ApiModelProperty(value = "状态1正常 2冻结")
|
||||
private Integer status;
|
||||
/**是否有叶子节点: 1是0否*/
|
||||
@Excel(name = "是否有叶子节点: 1是0否", width = 15)
|
||||
@ApiModelProperty(value = "是否有叶子节点: 1是0否")
|
||||
private Integer izLeaf;
|
||||
}
|
||||
|
|
@ -0,0 +1,118 @@
|
|||
package com.nu.modules.iot.tplink.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-TPLINK分组信息
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-02-20
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("nu_iot_tplink_region")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="nu_iot_tplink_region对象", description="护理单元-物联管理-TPLINK分组信息")
|
||||
public class AppRegionInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**ID*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Integer id;
|
||||
/**分组ID*/
|
||||
@Excel(name = "分组ID", width = 15)
|
||||
@ApiModelProperty(value = "分组ID")
|
||||
private String regionId;
|
||||
/**分组名称*/
|
||||
@Excel(name = "分组名称", width = 15)
|
||||
@ApiModelProperty(value = "分组名称")
|
||||
private String regionName;
|
||||
/**机构ID*/
|
||||
@Excel(name = "区域ID", width = 15)
|
||||
@ApiModelProperty(value = "区域ID")
|
||||
@Dict(dicCode = "id" , dictTable = "sys_depart" , dicText = "depart_name")
|
||||
private String areaId;
|
||||
@Excel(name = "机构ID", width = 15)
|
||||
@ApiModelProperty(value = "机构ID")
|
||||
@Dict(dicCode = "id" , dictTable = "sys_depart" , dicText = "depart_name")
|
||||
private String institutionId;
|
||||
/**分组层级*/
|
||||
@Excel(name = "分组层级", width = 15)
|
||||
@ApiModelProperty(value = "分组层级")
|
||||
private String regionLevel;
|
||||
/**分组次序,接口对应字段,在数据库中是关键字,数据库中用sort代替order*/
|
||||
@ApiModelProperty(value = "项目次序")
|
||||
@TableField(exist = false)
|
||||
private String order;
|
||||
/**项目次序*/
|
||||
@Excel(name = "项目次序", width = 15)
|
||||
@ApiModelProperty(value = "项目次序")
|
||||
private Integer sort;
|
||||
/**父分组ID*/
|
||||
@Excel(name = "父分组ID", width = 15)
|
||||
@ApiModelProperty(value = "父分组ID")
|
||||
private String parentId;
|
||||
/**父分组ID*/
|
||||
@Excel(name = "父分组", width = 15)
|
||||
@ApiModelProperty(value = "父分组")
|
||||
@TableField(exist = false)
|
||||
private String parentName;
|
||||
/**项目ID*/
|
||||
@Excel(name = "项目ID", width = 15)
|
||||
@ApiModelProperty(value = "项目ID")
|
||||
private String projectId;
|
||||
/**项目名称*/
|
||||
@Excel(name = "项目名称", width = 15)
|
||||
@ApiModelProperty(value = "项目名称")
|
||||
@TableField(exist = false)
|
||||
private String projectName;
|
||||
/**系统类型*/
|
||||
@Excel(name = "系统类型", width = 15)
|
||||
@ApiModelProperty(value = "系统类型")
|
||||
private String sysType;
|
||||
/**流道*/
|
||||
@Excel(name = "流道", width = 15)
|
||||
@ApiModelProperty(value = "流道")
|
||||
private String streamWay;
|
||||
/**是否有子分组*/
|
||||
@Excel(name = "是否有子分组", width = 15)
|
||||
@ApiModelProperty(value = "是否有子分组 0无 1有")
|
||||
private String hasChildren;
|
||||
/**分组类型*/
|
||||
@Excel(name = "分组类型", width = 15)
|
||||
@ApiModelProperty(value = "分组类型")
|
||||
private String regionType;
|
||||
/**更新时间*/
|
||||
@Excel(name = "更新时间", width = 15)
|
||||
@ApiModelProperty(value = "更新时间,年月日时分秒")
|
||||
private String updateTime;
|
||||
/**流媒体服务器ID*/
|
||||
@Excel(name = "流媒体服务器ID", width = 15)
|
||||
@ApiModelProperty(value = "流媒体服务器ID")
|
||||
private String mediaServerId;
|
||||
/**备用流媒体服务器ID*/
|
||||
@Excel(name = "备用流媒体服务器ID", width = 15)
|
||||
@ApiModelProperty(value = "备用流媒体服务器ID")
|
||||
private String backupMediaServerId;
|
||||
/**绑定类型*/
|
||||
@Excel(name = "绑定类型", width = 15)
|
||||
@ApiModelProperty(value = "绑定类型 0:设备直接取流/流媒体转发模式,1: 自动模式")
|
||||
private String bindType;
|
||||
/**是否有叶子节点: 1是0否*/
|
||||
@Excel(name = "是否有叶子节点: 1是0否", width = 15)
|
||||
@ApiModelProperty(value = "是否有叶子节点: 1是0否")
|
||||
private Integer izLeaf;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.nu.modules.iot.tplink.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.iot.tplink.entity.AppProjectInfo;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-TPLINK项目信息
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface AppProjectInfoMapper extends BaseMapper<AppProjectInfo> {
|
||||
void addProjectInfo(AppProjectInfo projectInfo);
|
||||
void deleteProjectInfo();
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.nu.modules.iot.tplink.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.iot.tplink.entity.AppRegionInfo;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-TPLINK分组信息
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-02-20
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface AppRegionInfoMapper extends BaseMapper<AppRegionInfo> {
|
||||
void addRegionInfo(AppRegionInfo regionInfo);
|
||||
void deleteRegionInfo();
|
||||
}
|
||||
|
|
@ -14,4 +14,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
@Mapper
|
||||
public interface AppTumsConfigMapper extends BaseMapper<AppTumsConfig> {
|
||||
AppTumsConfig getByCode();
|
||||
void addConfig(AppTumsConfig appTumsConfig);
|
||||
void deleteConfig();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?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.nu.modules.iot.tplink.mapper.AppProjectInfoMapper">
|
||||
|
||||
<insert id="addProjectInfo">
|
||||
insert into nu_iot_tplink_project(
|
||||
id,
|
||||
project_id,
|
||||
project_name
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{projectId},
|
||||
#{projectName}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteProjectInfo">
|
||||
delete from nu_iot_tplink_project
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
<?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.nu.modules.iot.tplink.mapper.AppRegionInfoMapper">
|
||||
|
||||
<insert id="addRegionInfo">
|
||||
insert into nu_iot_tplink_region(
|
||||
id,
|
||||
region_id,
|
||||
region_name,
|
||||
project_id,
|
||||
region_type
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{regionId},
|
||||
#{regionName},
|
||||
#{projectId},
|
||||
#{regionType}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteRegionInfo">
|
||||
delete from nu_iot_tplink_region
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -19,4 +19,35 @@
|
|||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="addConfig">
|
||||
insert into nu_iot_tplink_tums_base(
|
||||
id,
|
||||
tums_url,
|
||||
tums_username,
|
||||
tums_password,
|
||||
ftp_ip,
|
||||
ftp_port,
|
||||
ftp_username,
|
||||
ftp_password,
|
||||
ftp_uploadpath,
|
||||
update_date
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{tumsUrl},
|
||||
#{tumsUsername},
|
||||
#{tumsPassword},
|
||||
#{ftpIp},
|
||||
#{ftpPort},
|
||||
#{ftpUsername},
|
||||
#{ftpPassword},
|
||||
#{ftpUploadpath},
|
||||
#{updateDate}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="deleteConfig">
|
||||
delete from nu_iot_tplink_tums_base
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -1,8 +1,16 @@
|
|||
package com.nu.modules.iot.tplink.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nu.modules.iot.tplink.entity.AppProjectInfo;
|
||||
import com.nu.modules.iot.tplink.entity.AppRegionInfo;
|
||||
import com.nu.modules.iot.tplink.entity.AppTumsConfig;
|
||||
import com.nu.modules.iot.tplink.enums.AppApiEnum;
|
||||
import com.nu.modules.iot.tplink.mapper.AppProjectInfoMapper;
|
||||
import com.nu.modules.iot.tplink.mapper.AppRegionInfoMapper;
|
||||
import com.nu.modules.iot.tplink.mapper.AppTumsConfigMapper;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import com.tplink.ignite.libs.developersdk.api.TumsClient;
|
||||
import com.tplink.ignite.libs.developersdk.vo.ResultVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
|
@ -21,6 +29,12 @@ public class AppTumsApi {
|
|||
|
||||
@Autowired
|
||||
private AppTumsConfigMapper tumsConfigMapper;
|
||||
@Autowired
|
||||
private AppProjectInfoMapper projectInfoMapper;
|
||||
@Autowired
|
||||
private AppRegionInfoMapper regionInfoMapper;
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
/**
|
||||
* 创建tumsClient
|
||||
|
|
@ -45,6 +59,71 @@ public class AppTumsApi {
|
|||
private void initTumsConfig(){
|
||||
if(tumsConfig==null){
|
||||
tumsConfig = tumsConfigMapper.getByCode();
|
||||
if(tumsConfig==null){
|
||||
//调用接口从运维平台获取配置信息
|
||||
getConfigByApi();
|
||||
getProjectByApi();
|
||||
getRegionByApi();
|
||||
tumsConfig = tumsConfigMapper.getByCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getConfigByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tplink/config/getConfig";
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
tumsConfigMapper.deleteConfig();
|
||||
AppTumsConfig tumsConfig = JSON.parseObject(result.toJSONString(), AppTumsConfig.class);
|
||||
tumsConfigMapper.addConfig(tumsConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void getProjectByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tplink/config/getProject";
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
projectInfoMapper.deleteProjectInfo();
|
||||
AppProjectInfo projectInfo = JSON.parseObject(result.toJSONString(), AppProjectInfo.class);
|
||||
projectInfoMapper.addProjectInfo(projectInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void getRegionByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tplink/config/getRegion";
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
regionInfoMapper.deleteRegionInfo();
|
||||
AppRegionInfo regionInfo = JSON.parseObject(result.toJSONString(), AppRegionInfo.class);
|
||||
regionInfoMapper.addRegionInfo(regionInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.nu.modules.iot.tq.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-电水表-配置信息
|
||||
* @Author: caolei
|
||||
* @Date: 2025-06-04
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("nu_iot_tq_config")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="nu_iot_tq_config", description="护理单元-物联管理-电水表-配置信息")
|
||||
public class AppTqConfig implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**ID*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Integer id;
|
||||
private String requestUrl; //后台系统地址
|
||||
private String authCode; //授权码
|
||||
private String randomCode; //随机字符串,签名时需要
|
||||
private String notifyUrl; //通知地址
|
||||
private String updateDate; //更新时间
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package com.nu.modules.iot.tq.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* 接口枚举类
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum AppTqApiEnum {
|
||||
|
||||
METER_INFO("/Api/Meter","查询设备列表和当前状态"),
|
||||
COLLECTOR_INFO("/Api/Collector","查询采集器列表和当前状态"),
|
||||
ELE_RESET("/Api_v2/ele_security/reset","电表清零"),
|
||||
WATER_RESET("/Api_v2/water_security/reset","水表清零"),
|
||||
ELE_CONTROL("/Api_v2/ele_control","电表开关闸"),
|
||||
WATER_CONTROL("/Api_v2/water_control","水表开关闸"),
|
||||
ELE_READ("/Api_v2/ele_read","电表抄表"),
|
||||
WATER_READ("/Api_v2/water_read","水表抄表");
|
||||
|
||||
private final String value;//自定义属性,枚举值,获取:如ApiEnum.GET_ENCRYPT_KEY_FOR_LOGIN.getValue();
|
||||
private final String remark;//自定义属性,枚举描述,获取:如ApiEnum.GET_ENCRYPT_KEY_FOR_LOGIN.getRemark();
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.nu.modules.iot.tq.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.iot.tq.entity.AppTqConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-电水表配置信息
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface AppTqConfigMapper extends BaseMapper<AppTqConfig> {
|
||||
AppTqConfig getConfig();
|
||||
void addConfig(AppTqConfig tqConfig);
|
||||
void deleteConfig();
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
<?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.nu.modules.iot.tq.mapper.AppTqConfigMapper">
|
||||
|
||||
<select id="getConfig" parameterType="String" resultType="com.nu.modules.iot.tq.entity.AppTqConfig">
|
||||
select
|
||||
id,
|
||||
request_url as requestUrl,
|
||||
auth_code as authCode,
|
||||
random_code as randomCode,
|
||||
notify_url as notifyUrl,
|
||||
update_date as updateDate
|
||||
from nu_iot_tq_config
|
||||
order by id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="addConfig">
|
||||
insert into nu_iot_tq_config(
|
||||
id,
|
||||
request_url,
|
||||
auth_code,
|
||||
random_code,
|
||||
notify_url,
|
||||
update_date
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{requestUrl},
|
||||
#{authCode},
|
||||
#{randomCode},
|
||||
#{notifyUrl},
|
||||
#{updateDate}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="deleteConfig">
|
||||
delete from nu_iot_tq_config
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
package com.nu.modules.iot.tq.utils;
|
||||
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClientBuilder;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AppHttpTool {
|
||||
|
||||
public static String generateOperateId() {
|
||||
return UUID.randomUUID().toString().replaceAll("-", "");
|
||||
}
|
||||
|
||||
public static String getUrlParams(Map<String, Object> map) {
|
||||
if (map == null || map.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
List<String> list = new ArrayList<>();
|
||||
map.forEach((key, value)->{
|
||||
try {
|
||||
list.add(key + "=" + URLEncoder.encode(value.toString(), "UTF-8"));
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
return String.join("&", list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送http GET请求
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static String httpClientGet(String url) {
|
||||
try {
|
||||
CloseableHttpClient client = HttpClients.createDefault();
|
||||
HttpGet httpGet = new HttpGet(url);
|
||||
CloseableHttpResponse Response = client.execute(httpGet);
|
||||
HttpEntity entity = Response.getEntity();
|
||||
String resp = EntityUtils.toString(entity, "UTF-8");
|
||||
Response.close();
|
||||
return resp;
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送http POST请求
|
||||
* @param url
|
||||
* @param bodyMap
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String httpClientPost(String url, Map<String, String> bodyMap) throws Exception {
|
||||
System.out.println("请求地址:" + url);
|
||||
System.out.println("发送参数:" + bodyMap.toString());
|
||||
HttpClient client = HttpClientBuilder.create().build();
|
||||
HttpPost postRequest = new HttpPost(url);
|
||||
|
||||
List<NameValuePair> nvps = new ArrayList<>();
|
||||
|
||||
for(String key : bodyMap.keySet()) {
|
||||
nvps.add(new BasicNameValuePair(key,bodyMap.get(key)));
|
||||
}
|
||||
postRequest.setEntity(new UrlEncodedFormEntity(nvps,"utf-8"));
|
||||
|
||||
|
||||
int retry = 3;
|
||||
HttpResponse execute = null;
|
||||
while(retry-- > 0) {
|
||||
try {
|
||||
execute = client.execute(postRequest);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
Thread.sleep(5000);
|
||||
}
|
||||
}
|
||||
if(execute == null) {
|
||||
throw new Exception("接口请求失败");
|
||||
}
|
||||
String resp = EntityUtils.toString(execute.getEntity(), "UTF-8");
|
||||
System.out.println("接口返回:" + resp);
|
||||
return resp;
|
||||
}
|
||||
|
||||
// public static String postUrl(String url, Map<String,Object> map){
|
||||
// String errorMsg = "";
|
||||
// Gson gson = new Gson();
|
||||
// String map2 = gson.toJson(map);
|
||||
// System.out.println(map2);
|
||||
// try {
|
||||
// URL obj = new URL(url);
|
||||
// HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
// // 设置请求方法为 POST
|
||||
// con.setRequestMethod("POST");
|
||||
// // 设置请求头
|
||||
// con.setRequestProperty("Content-Type", "application/json"); // 声明发送 JSON
|
||||
// con.setRequestProperty("Accept", "application/json"); // 声明期望接收 JSON
|
||||
// con.setDoOutput(true); // 允许写入请求体
|
||||
// // 写入 JSON 请求体
|
||||
// try (OutputStream os = con.getOutputStream()) {
|
||||
// byte[] input = map2.getBytes("utf-8");
|
||||
// os.write(input, 0, input.length);
|
||||
// }
|
||||
// // 获取响应码
|
||||
// int responseCode = con.getResponseCode();
|
||||
// System.out.println("Response Code: " + responseCode);
|
||||
// // 读取响应(成功时)
|
||||
// if (responseCode == HttpURLConnection.HTTP_OK) { // 200
|
||||
// try (BufferedReader br = new BufferedReader(
|
||||
// new InputStreamReader(con.getInputStream(), "UTF-8"))) {
|
||||
// StringBuilder response = new StringBuilder();
|
||||
// String responseLine;
|
||||
// while ((responseLine = br.readLine()) != null) {
|
||||
// response.append(responseLine.trim());
|
||||
// }
|
||||
// System.out.println("Response: " + response.toString());
|
||||
// JSONObject result = new JSONObject(response.toString());
|
||||
// String status = result.getStr("status");
|
||||
// if(status.equals("SUCCESS")){
|
||||
// errorMsg = "";
|
||||
// }else{
|
||||
// errorMsg = result.getStr("error_msg");
|
||||
// }
|
||||
// }
|
||||
// } else { // 错误时读取错误流
|
||||
// try (BufferedReader br = new BufferedReader(
|
||||
// new InputStreamReader(con.getErrorStream(), "UTF-8"))) {
|
||||
// StringBuilder errorResponse = new StringBuilder();
|
||||
// String errorLine;
|
||||
// while ((errorLine = br.readLine()) != null) {
|
||||
// errorResponse.append(errorLine.trim());
|
||||
// }
|
||||
// errorMsg = errorResponse.toString();
|
||||
// System.out.println("Error Response: " + errorResponse.toString());
|
||||
// }
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return errorMsg;
|
||||
// }
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package com.nu.modules.iot.tq.utils;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class AppSignTool {
|
||||
|
||||
// 生成签名字符串
|
||||
public static String getSign(String nonce,Map<String, String> data)
|
||||
{
|
||||
// 获取关键字列表
|
||||
List<String> keys = new ArrayList<>(data.keySet());
|
||||
// 关键字列表排序
|
||||
keys.sort(Comparator.naturalOrder());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String key : keys)
|
||||
{
|
||||
// 取各个字段内容拼接字符串
|
||||
sb.append(data.get(key));
|
||||
}
|
||||
// 加上双方约定随机字符串
|
||||
String txt = sb.toString() + nonce;
|
||||
|
||||
// 计算哈希值
|
||||
return getMD5(txt);
|
||||
}
|
||||
|
||||
public static boolean checkSign(String response_content, String timestamp, String sign,String nonce) {
|
||||
String buf = response_content + timestamp + nonce;
|
||||
String encode = getMD5(buf);
|
||||
return encode.equals(sign);
|
||||
}
|
||||
|
||||
// md5加密
|
||||
public static String getMD5(String password) {
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
byte[] byteArray = password.getBytes(StandardCharsets.UTF_8);
|
||||
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
StringBuilder hexValue = new StringBuilder();
|
||||
for (byte md5Byte : md5Bytes) {
|
||||
int val = ((int) md5Byte) & 0xff;
|
||||
if (val < 16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
package com.nu.modules.iot.tq.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nu.modules.iot.tq.entity.AppTqConfig;
|
||||
import com.nu.modules.iot.tq.enums.AppTqApiEnum;
|
||||
import com.nu.modules.iot.tq.mapper.AppTqConfigMapper;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AppTqApi {
|
||||
|
||||
AppTqConfig tqConfig;
|
||||
|
||||
@Autowired
|
||||
AppTqConfigMapper tqConfigMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
private void initTqConfig(){
|
||||
if(tqConfig==null){
|
||||
tqConfig = tqConfigMapper.getConfig();
|
||||
if(tqConfig==null){
|
||||
getConfigByApi();
|
||||
tqConfig = tqConfigMapper.getConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getConfigByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tq/config/getConfig";
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
tqConfigMapper.deleteConfig();
|
||||
AppTqConfig tqConfig = JSON.parseObject(result.toJSONString(), AppTqConfig.class);
|
||||
tqConfigMapper.addConfig(tqConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public AppTqConfig getTqConfig(){
|
||||
this.initTqConfig();
|
||||
return tqConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表和当前状态
|
||||
*/
|
||||
public String getMeters(){
|
||||
this.initTqConfig();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("auth", tqConfig.getAuthCode());
|
||||
String urlParams = AppHttpTool.getUrlParams(params);
|
||||
log.info("getMeters:request:{}",urlParams);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.METER_INFO.getValue()+"?"+urlParams;
|
||||
String responseStr = AppHttpTool.httpClientGet(url);
|
||||
log.info("getMeters:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询采集器列表和当前状态
|
||||
*/
|
||||
public String getCollectors(){
|
||||
this.initTqConfig();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("auth", tqConfig.getAuthCode());
|
||||
String urlParams = AppHttpTool.getUrlParams(params);
|
||||
log.info("getCollectors:request:{}",urlParams);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.COLLECTOR_INFO.getValue()+"?"+urlParams;
|
||||
String responseStr = AppHttpTool.httpClientGet(url);
|
||||
log.info("getCollectors:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电表清零
|
||||
*/
|
||||
public String eleReset(List<Map<String, Object>> req){
|
||||
this.initTqConfig();
|
||||
String request_content = JSON.toJSONString(req);
|
||||
log.info("eleReset:request:{}",request_content);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.ELE_RESET.getValue();
|
||||
String notifyUrl = tqConfig.getNotifyUrl()+"/electricityMeter/eleResetNotify";
|
||||
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||
log.info("eleReset:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电表开关闸
|
||||
*/
|
||||
public String eleControl(List<Map<String, Object>> req){
|
||||
this.initTqConfig();
|
||||
String request_content = JSON.toJSONString(req);
|
||||
log.info("eleControl:request:{}",request_content);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.ELE_CONTROL.getValue();
|
||||
String notifyUrl = tqConfig.getNotifyUrl()+"/electricityMeter/eleControlNotify";
|
||||
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||
log.info("eleControl:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 电表抄表
|
||||
*/
|
||||
public String eleRead(List<Map<String, Object>> req){
|
||||
this.initTqConfig();
|
||||
String request_content = JSON.toJSONString(req);
|
||||
log.info("eleRead:request:{}",request_content);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.ELE_READ.getValue();
|
||||
String notifyUrl = tqConfig.getNotifyUrl()+"/electricityMeter/eleReadNotify";
|
||||
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||
log.info("eleRead:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 水表清零
|
||||
*/
|
||||
public String waterReset(List<Map<String, Object>> req){
|
||||
this.initTqConfig();
|
||||
String request_content = JSON.toJSONString(req);
|
||||
log.info("waterReset:request:{}",request_content);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.WATER_RESET.getValue();
|
||||
String notifyUrl = tqConfig.getNotifyUrl()+"/waterMeter/waterResetNotify";
|
||||
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||
log.info("waterReset:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 水表开关闸
|
||||
*/
|
||||
public String waterControl(List<Map<String, Object>> req){
|
||||
this.initTqConfig();
|
||||
String request_content = JSON.toJSONString(req);
|
||||
log.info("waterControl:request:{}",request_content);
|
||||
String url = tqConfig.getRequestUrl()+AppTqApiEnum.WATER_CONTROL.getValue();
|
||||
String notifyUrl = tqConfig.getNotifyUrl()+"/waterMeter/waterControlNotify";
|
||||
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||
log.info("waterControl:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 水表抄表
|
||||
*/
|
||||
public String waterRead(List<Map<String, Object>> req){
|
||||
this.initTqConfig();
|
||||
String request_content = JSON.toJSONString(req);
|
||||
log.info("waterRead:request:{}",request_content);
|
||||
String url = tqConfig.getRequestUrl()+ AppTqApiEnum.WATER_READ.getValue();
|
||||
String notifyUrl = tqConfig.getNotifyUrl()+"/waterMeter/waterReadNotify";
|
||||
String responseStr = requestAsync(url,request_content,notifyUrl);
|
||||
log.info("waterRead:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
private String requestAsync(String url, String request_content,String notifyUrl){
|
||||
// 时间戳
|
||||
String timestamp = String.valueOf(new Date().getTime()/1000);
|
||||
// 用于签名的内容
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("timestamp", timestamp);
|
||||
data.put("auth_code", tqConfig.getAuthCode());
|
||||
data.put("request_content", request_content);
|
||||
data.put("notify_url", notifyUrl);
|
||||
// 获取签名
|
||||
String sign = AppSignTool.getSign(tqConfig.getRandomCode(),data);
|
||||
data.put("sign", sign);
|
||||
try {
|
||||
return AppHttpTool.httpClientPost(url, data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.nu.modules.iot.yiweilian.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-易维联-配置信息
|
||||
* @Author: caolei
|
||||
* @Date: 2025-06-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("nu_iot_yiweilian_config")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="nu_iot_yiweilian_config", description="护理单元-物联管理-易维联-配置信息")
|
||||
public class AppYiweilianConfig implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
/**ID*/
|
||||
@TableId(type = IdType.AUTO)
|
||||
@ApiModelProperty(value = "ID")
|
||||
private Integer id;
|
||||
private String requestUrl; //云平台系统地址
|
||||
private String clientId; //识别用户的唯一标识
|
||||
private String updateDate; //更新时间
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.nu.modules.iot.yiweilian.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* 接口枚举类
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum AppYiweilianApiEnum {
|
||||
|
||||
ADD_DEVICE("/mtInterface/device/addDevice","添加设备"),
|
||||
UPDATE_DEVICE_CONFIG("/mtInterface/device/updateDeviceConfig","修改设备配置"),
|
||||
DELETE_DEVICE("/mtInterface/device/deleteDevice","删除设备"),
|
||||
// GET_DEVICES("/mtInterface/device/getDevices","查询设备列表(分页)"),
|
||||
GET_DEVICE_CONFIGS("/mtInterface/device/getDeciveConfigs","查询设备列表含配置信息(分页)"),
|
||||
GET_REAL_TIME("/mtInterface/realTime/getRealTime","查询设备实时数据(分页)"),
|
||||
GET_WARNING_DATA("/mtInterface/warning/getWarningData","查询告警记录(分页)");
|
||||
|
||||
private final String value;//自定义属性,枚举值,获取:如ApiEnum.GET_ENCRYPT_KEY_FOR_LOGIN.getValue();
|
||||
private final String remark;//自定义属性,枚举描述,获取:如ApiEnum.GET_ENCRYPT_KEY_FOR_LOGIN.getRemark();
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.nu.modules.iot.yiweilian.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.iot.yiweilian.entity.AppYiweilianConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-易维联-配置信息
|
||||
* @Author: caolei
|
||||
* @Date: 2025-08-08
|
||||
* @Version: V1.0
|
||||
*/
|
||||
|
||||
@Mapper
|
||||
public interface AppYiweilianConfigMapper extends BaseMapper<AppYiweilianConfig> {
|
||||
AppYiweilianConfig getConfig();
|
||||
void addConfig(AppYiweilianConfig yiweilianConfig);
|
||||
void deleteConfig();
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?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.nu.modules.iot.yiweilian.mapper.AppYiweilianConfigMapper">
|
||||
|
||||
<select id="getConfig" parameterType="String" resultType="com.nu.modules.iot.yiweilian.entity.AppYiweilianConfig">
|
||||
select
|
||||
id,
|
||||
request_url as requestUrl,
|
||||
client_id as clientId,
|
||||
update_date as updateDate
|
||||
from nu_iot_yiweilian_config
|
||||
order by id desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="addConfig">
|
||||
insert into nu_iot_yiweilian_config(
|
||||
id,
|
||||
request_url,
|
||||
client_id,
|
||||
update_date
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{requestUrl},
|
||||
#{clientId},
|
||||
#{updateDate}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="deleteConfig">
|
||||
delete from nu_iot_yiweilian_config
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.nu.modules.iot.yiweilian.utils;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
public class AppHttpTool {
|
||||
|
||||
/**
|
||||
* 发送http POST请求
|
||||
* @param url
|
||||
* @param map
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String httpClientPost(String url, Map<String,Object> map){
|
||||
String errorMsg = "";
|
||||
Gson gson = new Gson();
|
||||
String map2 = gson.toJson(map);
|
||||
System.out.println(map2);
|
||||
try {
|
||||
URL obj = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
|
||||
// 设置请求方法为 POST
|
||||
con.setRequestMethod("POST");
|
||||
// 设置请求头
|
||||
con.setRequestProperty("Content-Type", "application/json"); // 声明发送 JSON
|
||||
con.setRequestProperty("Accept", "application/json"); // 声明期望接收 JSON
|
||||
con.setDoOutput(true); // 允许写入请求体
|
||||
// 写入 JSON 请求体
|
||||
try (OutputStream os = con.getOutputStream()) {
|
||||
byte[] input = map2.getBytes("utf-8");
|
||||
os.write(input, 0, input.length);
|
||||
}
|
||||
// 获取响应码
|
||||
int responseCode = con.getResponseCode();
|
||||
System.out.println("Response Code: " + responseCode);
|
||||
// 读取响应(成功时)
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) { // 200
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(con.getInputStream(), "UTF-8"))) {
|
||||
StringBuilder response = new StringBuilder();
|
||||
String responseLine;
|
||||
while ((responseLine = br.readLine()) != null) {
|
||||
response.append(responseLine.trim());
|
||||
}
|
||||
System.out.println("Response: " + response.toString());
|
||||
errorMsg = response.toString();
|
||||
}
|
||||
} else { // 错误时读取错误流
|
||||
try (BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(con.getErrorStream(), "UTF-8"))) {
|
||||
StringBuilder errorResponse = new StringBuilder();
|
||||
String errorLine;
|
||||
while ((errorLine = br.readLine()) != null) {
|
||||
errorResponse.append(errorLine.trim());
|
||||
}
|
||||
System.out.println("Error Response: " + errorResponse.toString());
|
||||
errorMsg = "{\"code\":"+responseCode+",\"msg\":\""+errorResponse.toString()+"\" }";
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
package com.nu.modules.iot.yiweilian.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nu.modules.iot.yiweilian.entity.AppYiweilianConfig;
|
||||
import com.nu.modules.iot.yiweilian.enums.AppYiweilianApiEnum;
|
||||
import com.nu.modules.iot.yiweilian.mapper.AppYiweilianConfigMapper;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AppYiweilianApi {
|
||||
|
||||
AppYiweilianConfig yiweilianConfig;
|
||||
|
||||
@Autowired
|
||||
AppYiweilianConfigMapper yiweilianConfigMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
private void initYiweilianConfig(){
|
||||
if(yiweilianConfig==null){
|
||||
yiweilianConfig = yiweilianConfigMapper.getConfig();
|
||||
if(yiweilianConfig==null){
|
||||
getConfigByApi();
|
||||
yiweilianConfig = yiweilianConfigMapper.getConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getConfigByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/yiweilian/config/getConfig";
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
yiweilianConfigMapper.deleteConfig();
|
||||
AppYiweilianConfig yiweilianConfig = JSON.parseObject(result.toJSONString(), AppYiweilianConfig.class);
|
||||
yiweilianConfigMapper.addConfig(yiweilianConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public AppYiweilianConfig getYiweilianConfig(){
|
||||
this.initYiweilianConfig();
|
||||
return yiweilianConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加设备
|
||||
*/
|
||||
public String addDevice(Map<String, Object> params){
|
||||
this.initYiweilianConfig();
|
||||
params.put("clientId", yiweilianConfig.getClientId());
|
||||
log.info("addDevice:request:{}",params);
|
||||
String url = yiweilianConfig.getRequestUrl()+ AppYiweilianApiEnum.ADD_DEVICE.getValue();
|
||||
String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
log.info("addDevice:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改设备配置
|
||||
*/
|
||||
public String updateDeviceConfig(Map<String, Object> params){
|
||||
this.initYiweilianConfig();
|
||||
params.put("clientId", yiweilianConfig.getClientId());
|
||||
log.info("updateDeviceConfig:request:{}",params);
|
||||
String url = yiweilianConfig.getRequestUrl()+AppYiweilianApiEnum.UPDATE_DEVICE_CONFIG.getValue();
|
||||
String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
log.info("updateDeviceConfig:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除设备
|
||||
*/
|
||||
public String deleteDevice(Map<String, Object> params){
|
||||
this.initYiweilianConfig();
|
||||
params.put("clientId", yiweilianConfig.getClientId());
|
||||
log.info("deleteDevice:request:{}",params);
|
||||
String url = yiweilianConfig.getRequestUrl()+AppYiweilianApiEnum.DELETE_DEVICE.getValue();
|
||||
String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
log.info("deleteDevice:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表(分页)
|
||||
*/
|
||||
// public String getDevices(Map<String, Object> params){
|
||||
// this.initYiweilianConfig();
|
||||
// params.put("clientId", yiweilianConfig.getClientId());
|
||||
// log.info("getDevices:request:{}",params);
|
||||
// String url = yiweilianConfig.getRequestUrl()+AppYiweilianApiEnum.GET_DEVICES.getValue();
|
||||
// String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
// log.info("getDevices:response:{}",responseStr);
|
||||
// return responseStr;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 查询设备列表含配置信息(分页)
|
||||
*/
|
||||
public String getDeviceConfigs(Map<String, Object> params){
|
||||
this.initYiweilianConfig();
|
||||
params.put("clientId", yiweilianConfig.getClientId());
|
||||
log.info("getDeviceConfigs:request:{}",params);
|
||||
String url = yiweilianConfig.getRequestUrl()+AppYiweilianApiEnum.GET_DEVICE_CONFIGS.getValue();
|
||||
String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
log.info("getDeviceConfigs:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备实时数据(分页)
|
||||
*/
|
||||
public String getRealTime(Map<String, Object> params){
|
||||
this.initYiweilianConfig();
|
||||
params.put("clientId", yiweilianConfig.getClientId());
|
||||
log.info("getRealTime:request:{}",params);
|
||||
String url = yiweilianConfig.getRequestUrl()+ AppYiweilianApiEnum.GET_REAL_TIME.getValue();
|
||||
String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
log.info("getRealTime:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询告警记录(分页)
|
||||
*/
|
||||
public String getWarningData(Map<String, Object> params){
|
||||
this.initYiweilianConfig();
|
||||
params.put("clientId", yiweilianConfig.getClientId());
|
||||
log.info("getWarningData:request:{}",params);
|
||||
String url = yiweilianConfig.getRequestUrl()+AppYiweilianApiEnum.GET_WARNING_DATA.getValue();
|
||||
String responseStr = AppHttpTool.httpClientPost(url, params);
|
||||
log.info("getWarningData:response:{}",responseStr);
|
||||
return responseStr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -46,7 +46,13 @@
|
|||
<version>2.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-admin-local-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -16,4 +16,6 @@ import java.util.Map;
|
|||
@Mapper
|
||||
public interface TumsConfigMapper extends BaseMapper<TumsConfig> {
|
||||
TumsConfig getByCode();
|
||||
void addConfig(TumsConfig tumsConfig);
|
||||
void deleteConfig();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,35 @@
|
|||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="addConfig">
|
||||
insert into nu_iot_tplink_tums_base(
|
||||
id,
|
||||
tums_url,
|
||||
tums_username,
|
||||
tums_password,
|
||||
ftp_ip,
|
||||
ftp_port,
|
||||
ftp_username,
|
||||
ftp_password,
|
||||
ftp_uploadpath,
|
||||
update_date
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{tumsUrl},
|
||||
#{tumsUsername},
|
||||
#{tumsPassword},
|
||||
#{ftpIp},
|
||||
#{ftpPort},
|
||||
#{ftpUsername},
|
||||
#{ftpPassword},
|
||||
#{ftpUploadpath},
|
||||
#{updateDate}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="deleteConfig">
|
||||
delete from nu_iot_tplink_tums_base
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -25,4 +25,7 @@ public interface ProjectInfoMapper extends BaseMapper<ProjectInfo> {
|
|||
int deleteByProjectId(String projectId);
|
||||
int updateLeafByPId(Map<String, String> map);
|
||||
List<ProjectInfo> queryTreeList();
|
||||
|
||||
void addProjectInfo(ProjectInfo projectInfo);
|
||||
void deleteProjectInfo();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -238,4 +238,21 @@
|
|||
order by sort
|
||||
</select>
|
||||
|
||||
<insert id="addProjectInfo">
|
||||
insert into nu_iot_tplink_project(
|
||||
id,
|
||||
project_id,
|
||||
project_name
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{projectId},
|
||||
#{projectName}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteProjectInfo">
|
||||
delete from nu_iot_tplink_project
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -24,4 +24,7 @@ public interface RegionInfoMapper extends BaseMapper<RegionInfo> {
|
|||
int findChildrenCount(String regionId);
|
||||
int deleteByRegionId(String regionId);
|
||||
List<RegionInfo> queryTreeListByPid(String parentId,String projectId);
|
||||
|
||||
void addRegionInfo(RegionInfo regionInfo);
|
||||
void deleteRegionInfo();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -284,4 +284,25 @@
|
|||
and a.project_id = #{projectId}
|
||||
</select>
|
||||
|
||||
<insert id="addRegionInfo">
|
||||
insert into nu_iot_tplink_region(
|
||||
id,
|
||||
region_id,
|
||||
region_name,
|
||||
project_id,
|
||||
region_type
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{regionId},
|
||||
#{regionName},
|
||||
#{projectId},
|
||||
#{regionType}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<delete id="deleteRegionInfo">
|
||||
delete from nu_iot_tplink_region
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -1,13 +1,19 @@
|
|||
package com.nu.modules.tplink.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.modules.tplink.common.entity.TumsConfig;
|
||||
import com.nu.modules.tplink.common.mapper.TumsConfigMapper;
|
||||
import com.nu.modules.tplink.project.entity.ProjectInfo;
|
||||
import com.nu.modules.tplink.project.mapper.ProjectInfoMapper;
|
||||
import com.nu.modules.tplink.region.entity.RegionInfo;
|
||||
import com.nu.modules.tplink.region.mapper.RegionInfoMapper;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import com.tplink.ignite.libs.developersdk.api.TumsClient;
|
||||
import com.tplink.ignite.libs.developersdk.vo.ResultVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.nu.modules.tplink.enums.ApiEnum;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
|
@ -21,6 +27,13 @@ public class TumsApi {
|
|||
|
||||
@Autowired
|
||||
private TumsConfigMapper tumsConfigMapper;
|
||||
@Autowired
|
||||
private ProjectInfoMapper projectInfoMapper;
|
||||
@Autowired
|
||||
private RegionInfoMapper regionInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
/**
|
||||
* 创建tumsClient
|
||||
|
|
@ -45,6 +58,73 @@ public class TumsApi {
|
|||
private void initTumsConfig(){
|
||||
if(tumsConfig==null){
|
||||
tumsConfig = tumsConfigMapper.getByCode();
|
||||
if(tumsConfig==null){
|
||||
//调用接口从运维平台获取配置信息
|
||||
getConfigByApi();
|
||||
getProjectByApi();
|
||||
getRegionByApi();
|
||||
tumsConfig = tumsConfigMapper.getByCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getConfigByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tplink/config/getConfig";
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
tumsConfigMapper.deleteConfig();
|
||||
TumsConfig tumsConfig = JSON.parseObject(result.toJSONString(), TumsConfig.class);
|
||||
tumsConfigMapper.addConfig(tumsConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void getProjectByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tplink/config/getProject";
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
projectInfoMapper.deleteProjectInfo();
|
||||
ProjectInfo projectInfo = JSON.parseObject(result.toJSONString(), ProjectInfo.class);
|
||||
projectInfoMapper.addProjectInfo(projectInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void getRegionByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tplink/config/getRegion";
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
regionInfoMapper.deleteRegionInfo();
|
||||
RegionInfo regionInfo = JSON.parseObject(result.toJSONString(), RegionInfo.class);
|
||||
regionInfoMapper.addRegionInfo(regionInfo);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.nu.modules.tq.common.mapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.tq.common.entity.TqConfig;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 护理单元-物联管理-电水表配置信息
|
||||
|
|
@ -15,4 +14,6 @@ import java.util.Map;
|
|||
@Mapper
|
||||
public interface TqConfigMapper extends BaseMapper<TqConfig> {
|
||||
TqConfig getConfig();
|
||||
void addConfig(TqConfig tqConfig);
|
||||
void deleteConfig();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,4 +15,27 @@
|
|||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="addConfig">
|
||||
insert into nu_iot_tq_config(
|
||||
id,
|
||||
request_url,
|
||||
auth_code,
|
||||
random_code,
|
||||
notify_url,
|
||||
update_date
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{requestUrl},
|
||||
#{authCode},
|
||||
#{randomCode},
|
||||
#{notifyUrl},
|
||||
#{updateDate}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="deleteConfig">
|
||||
delete from nu_iot_tq_config
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -1,13 +1,17 @@
|
|||
package com.nu.modules.tq.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.modules.tq.enums.TqApiEnum;
|
||||
import com.nu.modules.tq.common.entity.TqConfig;
|
||||
import com.nu.modules.tq.common.mapper.TqConfigMapper;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
|
|
@ -19,9 +23,36 @@ public class TqApi {
|
|||
@Autowired
|
||||
TqConfigMapper tqConfigMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
private void initTqConfig(){
|
||||
if(tqConfig==null){
|
||||
tqConfig = tqConfigMapper.getConfig();
|
||||
if(tqConfig==null){
|
||||
getConfigByApi();
|
||||
tqConfig = tqConfigMapper.getConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getConfigByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/tq/config/getConfig?orgCode="+sysUser.getOrgCode();
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
tqConfigMapper.deleteConfig();
|
||||
TqConfig tqConfig = JSON.parseObject(result.toJSONString(), TqConfig.class);
|
||||
tqConfigMapper.addConfig(tqConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,38 +195,4 @@ public class TqApi {
|
|||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Map<String, Object>> req = new ArrayList<>();
|
||||
Map<String, Object> item = new HashMap<>();
|
||||
item.put("opr_id", HttpTool.generateOperateId());
|
||||
item.put("time_out", 0);
|
||||
item.put("must_online", true);
|
||||
item.put("retry_times", 1);
|
||||
item.put("cid", "250425201185");
|
||||
item.put("address", "250425201185");
|
||||
item.put("type", 3);
|
||||
req.add(item);
|
||||
String request_content = JSON.toJSONString(req);
|
||||
String url = "https://100.znchaobiao.com/Api_v2/ele_read";
|
||||
String notifyUrl = "https://www.focusnu.com/nursingunit101/iot/tq/api/electricityMeter/eleReadNotify";
|
||||
|
||||
// 时间戳
|
||||
String timestamp = String.valueOf(new Date().getTime()/1000);
|
||||
// 用于签名的内容
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("timestamp", timestamp);
|
||||
data.put("auth_code", "6d82b4941f64ce0db13463218b0eb1d3");
|
||||
data.put("request_content", request_content);
|
||||
data.put("notify_url", notifyUrl);
|
||||
// 获取签名
|
||||
String sign = SignTool.getSign("qU2OX8FTMzfDsNZWR47gmwANIJ",data);
|
||||
data.put("sign", sign);
|
||||
try {
|
||||
HttpTool.httpClientPost(url, data);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,4 +14,6 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
@Mapper
|
||||
public interface YiweilianConfigMapper extends BaseMapper<YiweilianConfig> {
|
||||
YiweilianConfig getConfig();
|
||||
void addConfig(YiweilianConfig yiweilianConfig);
|
||||
void deleteConfig();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,4 +13,23 @@
|
|||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="addConfig">
|
||||
insert into nu_iot_yiweilian_config(
|
||||
id,
|
||||
request_url,
|
||||
client_id,
|
||||
update_date
|
||||
)
|
||||
values (
|
||||
#{id},
|
||||
#{requestUrl},
|
||||
#{clientId},
|
||||
#{updateDate}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="deleteConfig">
|
||||
delete from nu_iot_yiweilian_config
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
|
|
@ -1,8 +1,12 @@
|
|||
package com.nu.modules.yiweilian.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.modules.yiweilian.common.entity.YiweilianConfig;
|
||||
import com.nu.modules.yiweilian.common.mapper.YiweilianConfigMapper;
|
||||
import com.nu.modules.yiweilian.enums.YiweilianApiEnum;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -17,9 +21,35 @@ public class YiweilianApi {
|
|||
@Autowired
|
||||
YiweilianConfigMapper yiweilianConfigMapper;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
private void initYiweilianConfig(){
|
||||
if(yiweilianConfig==null){
|
||||
yiweilianConfig = yiweilianConfigMapper.getConfig();
|
||||
if(yiweilianConfig==null){
|
||||
getConfigByApi();
|
||||
yiweilianConfig = yiweilianConfigMapper.getConfig();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void getConfigByApi(){
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "devops_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/iot/yiweilian/config/getConfig";
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
yiweilianConfigMapper.deleteConfig();
|
||||
YiweilianConfig yiweilianConfig = JSON.parseObject(result.toJSONString(), YiweilianConfig.class);
|
||||
yiweilianConfigMapper.addConfig(yiweilianConfig);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue