Commit 7e9a64b4 authored by 赵啸非's avatar 赵啸非

修改平台编码

parent f96f6a97
......@@ -8,10 +8,7 @@
<Field :span="20" label="平台类型" prop="platformId" v-model="form.platformId" type="select" :enumData="dict.platformId" placeholder="请选择平台类型"/>
<Field :span="20" label="产品类型" prop="productId" v-model="form.productId" type="select" :enumData="dict.productId" placeholder="请选择产品类型"/>
<Field :span="20" label="设备的MAC地址" prop="deviceMac" v-model="form.deviceMac" placeholder="请输入设备的MAC地址"/>
<Field :span="20" label="中心设备编码" v-model="form.centernum" placeholder="请输入中心设备编码"/>
<Field :span="20" disabled label="设备访问ip" v-model="form.ip" />
<Field :span="20" disabled label="端口" v-model="form.port" />
<Field :span="20" disabled label="站点编号" v-model="form.siteNum" />
<Field
:span="20"
......
......@@ -76,7 +76,7 @@ export default {
},
activeDevice(row) {
this.$post("/device/save", {
this.$post("/device/active", {
"entity.id": row.id,
"entity.active": 1,
})
......
......@@ -5,7 +5,7 @@
<el-row>
<Field :span="20" label="平台名称" prop="platformName" v-model="form.platformName" placeholder="请输入平台名称,名称唯一"/>
<Field :span="20" label="平台编码" prop="platformSn" v-model="form.platformSn" placeholder="请输入平台编码,编码唯一"/>
<Field :span="20" label="发送参数配置" prop="sendConfig" v-model="form.sendConfig" type="textarea" placeholder="请输入发送参数配置,如发送消息地址等,xml结构,根据消息类型变化"/>
<Field :span="20" label="发送地址" prop="sendUrl" v-model="form.sendUrl" type="textarea" placeholder="请输入发送httpurl地址"/>
<Field :span="20" label="发送消息类型" prop="sendMsgType" v-model="form.sendMsgType" type="radio" :enumData="dict.sendMsgType" placeholder="请选择发送第三方平台消息类型"/>
<Field :span="20" label="是否发送消息" prop="sendSwitch" v-model="form.sendSwitch" type="radio" :enumData="dict.sendSwitch" placeholder="请选择是否启用发送消息"/>
<Field :span="20" label="备注" prop="platformRemark" v-model="form.platformRemark" type="textarea" placeholder="请输入备注"/>
......
......@@ -103,7 +103,7 @@ public class MessageServiceImpl implements MessageService {
if (code == YesNoEnum.YES.getValue()) {
JSONObject dataObj = jsonObject.getJSONObject("data");
String authtoken = dataObj.getString("token");
cacheService.setnx(Constant.BASEPLATFORM_AUTHTOKEN,authtoken,7*24*60*60*1000);
cacheService.setnx(Constant.BASEPLATFORM_AUTHTOKEN,authtoken,7*24*60);
return authtoken;
} else {
throw new AppException("异常");
......
......@@ -11,9 +11,9 @@ import java.io.Serializable;
public class DeviceReq implements Serializable {
/**
* 状态,0:新增,1:修改,2:删除,3:激活,4:上线,5:下线
* 1:新增,2:修改,3:删除,4:激活,5:启用,6:停用
*/
private Integer deviceStatus;
private Integer receiveMethod;
/**
* 平台系统编码
*/
......@@ -42,6 +42,10 @@ public class DeviceReq implements Serializable {
* 设备备注信息
*/
private String deviceRemark;
/**
* 设备
*/
private String homeUrl;
}
......@@ -4,7 +4,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
/**
* 设备状态,1:新增,2:修改,3:删除,4:激活,5:上线,6:下线
* 设备状态,1:新增,2:修改,3:删除,4:激活,5:启用,6:停用
*
* @author zxfei
*/
......@@ -13,8 +13,8 @@ public enum DeviceStatusEnum {
UPDATE(2, "修改"),
DEL(3, "删除"),
ACTIVE(4, "激活"),
ONLINE(5, "上线"),
OFFLINE(6, "下线");
ENABLED(5, "启用"),
STOP(6, "停用");
private Integer value;
private String desc;
......
package com.mortals.xhx.common.utils;
import com.alibaba.fastjson.JSON;
import com.mortals.framework.util.HttpUtil;
import com.mortals.xhx.busiz.req.ApiThirdPartyReq;
import com.mortals.xhx.busiz.req.DeviceReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.MessageTypeEnum;
import com.mortals.xhx.common.code.YesNoEnum;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import java.util.HashMap;
import java.util.Map;
import static com.mortals.framework.util.HttpUtil.HEADER_CONTENT_TYPE;
/**
* 发送任务
*
......@@ -20,13 +31,17 @@ public class SendTask implements Runnable {
private String content;
@Override
public void run() {
// TODO: 2022/4/28
ApiThirdPartyReq<String> deviceReqApiReq = new ApiThirdPartyReq<>();
deviceReqApiReq.setCode(YesNoEnum.YES.getValue());
deviceReqApiReq.setType(MessageTypeEnum.TRANSACTION.getValue());
deviceReqApiReq.setData(content);
String resp = null;
try {
// log.debug("启动发送"+smsGateQueueEntity);
String resp = HttpUtil.doPost(sendUrl, content);
log.debug("http resp:{}", resp);
Map<String, String> header = new HashMap<>();
header.put(HEADER_CONTENT_TYPE, "application/json");
resp = HttpUtil.doPost(sendUrl, header, JSON.toJSONString(deviceReqApiReq));
} catch (Exception e) {
log.error("发送异常:" + e);
log.error("异常:", e);
}
}
}
......@@ -166,7 +166,7 @@ public class DemoApiController {
TbQueueMsgHeaders header = new DefaultTbQueueMsgHeaders();
header.put(MessageHeader.MESSAGETYPE, Constant.MESSAGETYPE_HEARTBEAT);
UploadDeviceReq uploadDeviceReq = new UploadDeviceReq();
uploadDeviceReq.setDeviceMac(deviceEntity.getDeviceMac());
//uploadDeviceReq.setDeviceMac(deviceEntity.getDeviceMac());
uploadDeviceReq.setDeviceCode(deviceEntity.getDeviceCode());
for (int i = 0; i < 100; i++) {
......
......@@ -69,6 +69,8 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
if (!ObjectUtils.isEmpty(mainConsumer)) {
//订阅所有已几快活设备
Set<TopicPartitionInfo> topicPartitionInfoSet = deviceService.find(new DeviceQuery().active(ActiveEnum.已激活.getValue()).status(StatusEnum.启用.getValue())).stream()
.filter(f->!ObjectUtils.isEmpty(platformService.get(f.getPlatformId())))
.filter(f->!ObjectUtils.isEmpty(productService.get(f.getProductId())))
.map(item -> {
PlatformEntity platformEntity = platformService.get(item.getPlatformId());
ProductEntity productEntity = productService.get(item.getProductId());
......@@ -161,8 +163,6 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
}
deviceEntity.setOnlineTime(new Date());
deviceEntity.setDeviceOnlineStatus(DeviceOnlineStatusEnum.在线.getValue());
deviceEntity.setIp(deviceReq.getIp());
deviceEntity.setPort(deviceReq.getPort());
deviceService.update(deviceEntity);
DeviceLogEntity deviceLogEntity = new DeviceLogEntity();
......@@ -179,11 +179,14 @@ public class DeviceMsgComsumerStartedService implements IApplicationStartedServi
//获取exchange,
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
if (!ObjectUtils.isEmpty(platformEntity) && platformEntity.getSendSwitch() == YesNoEnum.YES.getValue()) {
if (platformEntity.getSendMsgType() == SendMsgTypeEnum.http.getValue() && !ObjectUtils.isEmpty(platformEntity.getSendConfig())) {
if (platformEntity.getSendMsgType() == SendMsgTypeEnum.http.getValue() && !ObjectUtils.isEmpty(platformEntity.getSendUrl())) {
//http方式
//通过线程池进行发送消息
SendTask sendTask = new SendTask(platformEntity.getSendConfig(), new String(queueMsg.getData()));
sendTaskThreadPool.execute(sendTask);
SendTask sendTask = new SendTask(platformEntity.getSendUrl(), new String(queueMsg.getData()));
sendTaskThreadPool.execute(sendTask);
}
}
// if (bool) {
......
......@@ -31,5 +31,12 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{
*/
void active(String deviceCode,Context context);
/**
* 设备启用停用
* @param deviceCode
* @param context
*/
void deviceEnabled(String deviceCode,Integer status,Context context);
}
\ No newline at end of file
package com.mortals.xhx.module.device.service.impl;
import cn.hutool.core.lang.PatternPool;
import cn.hutool.http.HttpUtil;
import com.mortals.framework.exception.AppException;
import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
......@@ -26,10 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
/**
* DeviceService
......@@ -80,6 +76,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
public void onSuccess(TbQueueMsgMetadata metadata) {
log.info("消息投递成功,设备通道编码:" + deviceEntity.getDeviceMac());
}
@Override
public void onFailure(Throwable t) {
log.error("消息投递成功,设备通道编码:" + deviceEntity.getDeviceMac(), t);
......@@ -114,7 +111,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(deviceEntity, deviceReq, BeanUtil.getNullPropertyNames(deviceEntity));
deviceReq.setDeviceStatus(DeviceStatusEnum.ACTIVE.getValue());
deviceReq.setReceiveMethod(DeviceStatusEnum.ACTIVE.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
......@@ -128,6 +125,16 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
}
@Override
public void deviceEnabled(String deviceCode, Integer status, Context context) {
DeviceEntity deviceEntity = this.selectOne(new DeviceQuery().deviceCode(deviceCode));
if (!ObjectUtils.isEmpty(deviceEntity)) throw new AppException("当前设备不存在!");
deviceEntity.setStatus(status);
deviceEntity.setUpdateTime(new Date());
deviceEntity.setUpdateUserId(getContextUserId(context));
this.update(deviceEntity, context);
}
@Override
protected void saveAfter(DeviceEntity entity, Context context) throws AppException {
......@@ -162,7 +169,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(entity, deviceReq, BeanUtil.getNullPropertyNames(entity));
deviceReq.setDeviceStatus(DeviceStatusEnum.ADD.getValue());
deviceReq.setReceiveMethod(DeviceStatusEnum.ADD.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
......@@ -187,7 +194,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(entity, deviceReq, BeanUtil.getNullPropertyNames(entity));
deviceReq.setDeviceStatus(DeviceStatusEnum.UPDATE.getValue());
deviceReq.setReceiveMethod(DeviceStatusEnum.UPDATE.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
......@@ -228,7 +235,7 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(deviceEntity, deviceReq, BeanUtil.getNullPropertyNames(deviceEntity));
deviceReq.setDeviceStatus(DeviceStatusEnum.DEL.getValue());
deviceReq.setReceiveMethod(DeviceStatusEnum.DEL.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
......
......@@ -188,4 +188,26 @@ public class DeviceController extends BaseCRUDJsonMappingController<DeviceServic
return jsonObject.toJSONString();
}
/**
* 设备启用停用
*/
@PostMapping(value = "enable")
public String deviceEnable(@RequestParam(value = "deviceCode") String deviceCode,@RequestParam(value = "status") Integer status) {
JSONObject jsonObject = new JSONObject();
Map<String, Object> model = new HashMap<>();
String busiDesc = this.getModuleDesc() + "设备启用停用";
try {
this.service.active(deviceCode, getContext());
this.init(request, response, null, model, getContext());
recordSysLog(request, busiDesc + " 【成功】");
jsonObject.put(KEY_RESULT_DATA, model);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_SUCCESS);
} catch (Exception e) {
log.error("设备激活消息", e);
jsonObject.put(KEY_RESULT_CODE, VALUE_RESULT_FAILURE);
jsonObject.put(KEY_RESULT_MSG, super.convertException(e));
}
return jsonObject.toJSONString();
}
}
\ No newline at end of file
......@@ -150,14 +150,6 @@ password|String|平台用户密码|是|-
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
&emsp;platformList|array|平台列表|数组
&emsp;&emsp;id|Long|ID|-
&emsp;&emsp;platformName|String|平台名称,名称唯一|-
&emsp;&emsp;platformSn|String|平台编码,编码唯一|-
&emsp;productList|array|产品列表|数组
&emsp;&emsp;id|Long|ID|-
&emsp;&emsp;productName|String|产品名称,名称唯一|-
&emsp;&emsp;productCode|String|产品编码,编码唯一|-
**响应消息样例:**
......@@ -167,9 +159,9 @@ data|object|数据对象|-
### 新增或更新设备
### 接收第三方平台设备消息
**请求URL:** m/api/saveOrUpdate
**请求URL:** m/api/receive
**请求方式:** POST
......@@ -177,13 +169,13 @@ data|object|数据对象|-
**内容类型:** application/json;charset=utf-8
**简要描述:** 保存或更新设备,设备deviceCode存在更新,不存在新增,
请求需添加接口鉴权token信息,来源getToken接口
**简要描述:**
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
receiveMethod|Integer|1:新增,2:修改,3:删除,4:激活,5:启用,6:停用|是|-
deviceName|String|设备名称|否|-
deviceCode|String|设备编码,如MAC地址|是|-
platformCode|String|平台系统编码|是|见平台编码附录
......@@ -213,87 +205,6 @@ data|object|数据对象|-
```
### 激活设备
**请求URL:** m/api/active
**请求方式:** POST
**鉴权头信息:** Authorization: {{token}}
**内容类型:** application/json;charset=utf-8
**简要描述:** 激活设备
请求需添加接口鉴权token信息,来源getToken接口
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
deviceCode|String|设备编码|是|-
**请求样例:**
```
{
"deviceCode":"yte9s3",
}
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
**响应消息样例:**
```
```
### 删除设备
**请求URL:** m/api/deviceDel
**请求方式:** POST
**鉴权头信息:** Authorization: {{token}}
**内容类型:** application/json;charset=utf-8
**简要描述:** 删除设备
请求需添加接口鉴权token信息,来源getToken接口
**请求参数:**
参数名称|类型|备注|必填|其它
---|---|---|---|---
deviceCode|String|设备编码|是|-
**请求样例:**
```
{
"deviceCode":"yte9s3",
}
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
**响应消息样例:**
```
```
### 回调各个平台通知消息
......@@ -313,7 +224,7 @@ code|Integer|结果码(-1.失败,1.成功)|是|-
msg|String|消息|否|-
type|Integer|消息类型|是|0:设备增删改查,data数据域封装具体设备消息,1:设备消息类,数据域透传设备上行消息体。|-
data|object|数据对象|是|-
&emsp;deviceStatus|Integer|状态,1:新增,2:修改,3:删除,4:激活,5:上线,6:下线|是|-
&emsp;deviceStatus|Integer|状态,1:新增,2:修改,3:删除,4:激活,5:启用,6:停用,7:上线,8:下线|是|-
&emsp;deviceName|String|设备名称|否|-
&emsp;deviceCode|String|设备编码,如MAC地址|是|-
&emsp;platformCode|String|平台系统编码|是|见平台编码附录
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment