Commit 229f8acb authored by 赵啸非's avatar 赵啸非

修改平台编码

parent 12e00717
...@@ -55,8 +55,10 @@ CREATE TABLE mortals_xhx_platform( ...@@ -55,8 +55,10 @@ CREATE TABLE mortals_xhx_platform(
`platformName` varchar(20) NOT NULL COMMENT '平台名称,名称唯一', `platformName` varchar(20) NOT NULL COMMENT '平台名称,名称唯一',
`platformSn` varchar(256) NOT NULL COMMENT '平台编码,编码唯一(编码加上站点编码,如phxt-51010251-1做Vhost虚拟机编码)', `platformSn` varchar(256) NOT NULL COMMENT '平台编码,编码唯一(编码加上站点编码,如phxt-51010251-1做Vhost虚拟机编码)',
`sendMsgType` tinyint(2) NOT NULL COMMENT '发送第三方平台消息类型(0.http,1.jms)', `sendMsgType` tinyint(2) NOT NULL COMMENT '发送第三方平台消息类型(0.http,1.jms)',
`sendConfig` varchar(2048) COMMENT '发送参数配置,如发送消息地址等,xml结构,根据消息类型变化', `sendUrl` varchar(512) COMMENT '发送参数请求地址',
`callbackUrl` varchar(512) COMMENT '回调参数地址',
`sendSwitch` tinyint(2) NOT NULL COMMENT '是否启用发送消息(0.停用,1.启用)', `sendSwitch` tinyint(2) NOT NULL COMMENT '是否启用发送消息(0.停用,1.启用)',
`homeUrl` varchar(512) COMMENT '首页地址',
`platformRemark` varchar(256) COMMENT '备注', `platformRemark` varchar(256) COMMENT '备注',
`createUserId` bigint(20) NOT NULL COMMENT '创建用户', `createUserId` bigint(20) NOT NULL COMMENT '创建用户',
`createTime` datetime NOT NULL COMMENT '创建时间', `createTime` datetime NOT NULL COMMENT '创建时间',
...@@ -64,6 +66,7 @@ CREATE TABLE mortals_xhx_platform( ...@@ -64,6 +66,7 @@ CREATE TABLE mortals_xhx_platform(
`updateTime` datetime COMMENT '更新时间', `updateTime` datetime COMMENT '更新时间',
PRIMARY KEY (`id`) PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='平台系统'; ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='平台系统';
-- ---------------------------- -- ----------------------------
-- 产品表 -- 产品表
-- ---------------------------- -- ----------------------------
......
package com.mortals.xhx.base.system.message; package com.mortals.xhx.base.system.message;
import com.mortals.xhx.busiz.req.DeviceReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.queue.TbQueueCallback; import com.mortals.xhx.queue.TbQueueCallback;
import com.mortals.xhx.queue.TbQueueMsgHeaders; import com.mortals.xhx.queue.TbQueueMsgHeaders;
import com.mortals.xhx.queue.TopicPartitionInfo; import com.mortals.xhx.queue.TopicPartitionInfo;
...@@ -45,4 +47,8 @@ public interface MessageService { ...@@ -45,4 +47,8 @@ public interface MessageService {
String siteTree(); String siteTree();
ApiResp<String> sendThirdParty(String sendUrl,Integer messageType, DeviceReq deviceReq);
} }
\ No newline at end of file
...@@ -10,6 +10,9 @@ import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; ...@@ -10,6 +10,9 @@ import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.framework.util.DateUtils; import com.mortals.framework.util.DateUtils;
import com.mortals.framework.util.HttpUtil; import com.mortals.framework.util.HttpUtil;
import com.mortals.xhx.base.system.message.MessageService; import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.req.ApiReq;
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.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.code.YesNoEnum; import com.mortals.xhx.common.code.YesNoEnum;
...@@ -143,4 +146,21 @@ public class MessageServiceImpl implements MessageService { ...@@ -143,4 +146,21 @@ public class MessageServiceImpl implements MessageService {
return resp; return resp;
} }
@Override
public ApiResp<String> sendThirdParty(String sendUrl,Integer messageType, DeviceReq deviceReq) {
ApiThirdPartyReq<DeviceReq> deviceReqApiReq = new ApiThirdPartyReq<>();
deviceReqApiReq.setCode(YesNoEnum.YES.getValue());
deviceReqApiReq.setType(messageType);
String resp = null;
try {
Map<String, String> header = new HashMap<>();
header.put(HEADER_CONTENT_TYPE, "application/json");
resp = HttpUtil.doPost(sendUrl, header, JSON.toJSONString(deviceReqApiReq));
return JSON.parseObject(resp,ApiResp.class);
} catch (Exception e) {
log.error("异常:", e);
}
return null;
}
} }
\ No newline at end of file
...@@ -342,6 +342,12 @@ public class UserEntity extends UserEntityExt implements IUser { ...@@ -342,6 +342,12 @@ public class UserEntity extends UserEntityExt implements IUser {
public Long getSiteId() { public Long getSiteId() {
return this.siteId; return this.siteId;
} }
@Override
public String getSiteIds() {
return null;
}
/** /**
* 设置 站点id * 设置 站点id
* @param siteId * @param siteId
......
package com.mortals.xhx.busiz.req;
import lombok.Data;
@Data
public class ApiThirdPartyReq<T> {
/**
* 结果编码
*/
private int code;
/**
* 结果描述
*/
private String msg;
/**
* 0:设备增删改查,data数据域封装具体设备消息,1:设备消息类,数据域透传设备上行消息体。
*/
private Integer type;
/**
* 响应数据
*/
private T data;
}
...@@ -9,19 +9,27 @@ import java.io.Serializable; ...@@ -9,19 +9,27 @@ import java.io.Serializable;
@Data @Data
public class DeviceReq implements Serializable { public class DeviceReq implements Serializable {
/**
* 状态,0:新增,1:修改,2:删除,3:激活,4:上线,5:下线
*/
private Integer deviceStatus;
/**
* 平台系统编码
*/
private String platformCode;
/**
* 产品编码
*/
private String productCode;
/** /**
* 设备名称 * 设备名称
*/ */
private String deviceName; private String deviceName;
/** /**
* 设备编码(暂定mac地址) * 设备编码(暂定mac地址)
*/ */
private String deviceCode; private String deviceCode;
/**
* mac地址
*/
private String deviceMac;
/** /**
* 所属站点编码 * 所属站点编码
*/ */
...@@ -30,33 +38,10 @@ public class DeviceReq implements Serializable { ...@@ -30,33 +38,10 @@ public class DeviceReq implements Serializable {
* 所属站点名称 * 所属站点名称
*/ */
private String siteName; private String siteName;
/**
* 设备ip
*/
private String ip;
/**
* 设备端口
*/
private String port;
/**
* 平台id
*/
private Long platformId;
/**
* 产品Id
*/
private Long productId;
/** /**
* 设备备注信息 * 设备备注信息
*/ */
private String deviceRemark; private String deviceRemark;
public static void main(String[] args) {
// DeviceReq deviceReq = new DeviceReq();
// deviceReq.setIsAdmin();
// deviceReq.seti
}
} }
...@@ -53,7 +53,6 @@ import java.util.stream.Collectors; ...@@ -53,7 +53,6 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@RequestMapping("/api") @RequestMapping("/api")
public class DeviceApiController { public class DeviceApiController {
@Autowired @Autowired
private DeviceService deviceService; private DeviceService deviceService;
@Autowired @Autowired
...@@ -64,7 +63,6 @@ public class DeviceApiController { ...@@ -64,7 +63,6 @@ public class DeviceApiController {
private IAuthTokenService authTokenService; private IAuthTokenService authTokenService;
@Autowired @Autowired
private PlatformService platformService; private PlatformService platformService;
@Value("${queue.rabbitmq.virtual_host:}") @Value("${queue.rabbitmq.virtual_host:}")
private String virtualHost; private String virtualHost;
@Value("${queue.rabbitmq.password:}") @Value("${queue.rabbitmq.password:}")
......
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* 设备状态,1:新增,2:修改,3:删除,4:激活,5:上线,6:下线
*
* @author zxfei
*/
public enum DeviceStatusEnum {
ADD(1, "新增"),
UPDATE(2, "修改"),
DEL(3, "删除"),
ACTIVE(4, "激活"),
ONLINE(5, "上线"),
OFFLINE(6, "下线");
private Integer value;
private String desc;
DeviceStatusEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static DeviceStatusEnum getByValue(Integer value) {
for (DeviceStatusEnum deviceTypeEnum : DeviceStatusEnum.values()) {
if (deviceTypeEnum.getValue() == value) {
return deviceTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (DeviceStatusEnum item : DeviceStatusEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.code;
import java.util.LinkedHashMap;
import java.util.Map;
public enum MessageTypeEnum {
CRUD(0, "设备增删改查"),
TRANSACTION(1, "设备消息类,数据域透传设备上行消息体");
private Integer value;
private String desc;
MessageTypeEnum(Integer value, String desc) {
this.value = value;
this.desc = desc;
}
public Integer getValue() {
return this.value;
}
public String getDesc() {
return this.desc;
}
public static MessageTypeEnum getByValue(Integer value) {
for (MessageTypeEnum sendMsgTypeEnum : MessageTypeEnum.values()) {
if (sendMsgTypeEnum.getValue() == value) {
return sendMsgTypeEnum;
}
}
return null;
}
/**
* 获取Map集合
*
* @param eItem 不包含项
* @return
*/
public static Map<String, String> getEnumMap(Integer... eItem) {
Map<String, String> resultMap = new LinkedHashMap<>();
for (MessageTypeEnum item : MessageTypeEnum.values()) {
try {
boolean hasE = false;
for (Integer e : eItem) {
if (item.getValue() == e) {
hasE = true;
break;
}
}
if (!hasE) {
resultMap.put(item.getValue() + "", item.getDesc());
}
} catch (Exception ex) {
}
}
return resultMap;
}
}
\ No newline at end of file
package com.mortals.xhx.common.key;
/**
* 错误码
*
* @author: zxfei
* @date: 2022/5/12 14:56
*/
public interface ErrorCode {
public static final int STATUS_MS_EXCEPTION = 500;
public static final int STATUS_VALIDATE_EXCEPTION = 420;
public static final int STATUS_UNCHECKED_EXCEPTION = 605;
public static final int STATUS_TOKEN_NULL_EXCEPTION = 604;
public static final int STATUS_CODE_SUCCESS = 0;
public static final int STATUS_CODE_WARN = 1;
public static final int STATUS_CODE_ERROR = 2;
public static final int STATUS_CODE_INFO = 3;
public static final int STATUS_CODE_TOKEN_EXPIRED = 4;
public static final int STATUS_CODE_FATAL = 5;
public static final int STATUS_CODE_TRADE_PWD_NOT_SET = 6;
public static final int STATUS_ACCOUNT_LOCKED = 7;
public static final int STATUS_TRADE_PWD_OVER_THREE_TIME = 8;
public static final int STATUS_TRADE_PWD_ERROR = 9;
public static final int STATUS_EMPTY_PWD_ERROR = 10;
public static final int STATUS_TEL_NOT_RGI_ERROR = 11;
public static final int STATUS_TEL_ALREADY_REGI = 12;
public static final int STATUS_SAFETY_RISK = 13;
public static final int STATUS_LOGIN_CODE = 15;
public static final int BOOK_FAKUAN_CODE = 16;//还有未付款的订单code
public static final String ERROR_TOKEN_EXPIRED = "登陆过期,请重新登录";
public static final String ERROR_TRADE_PWD_OVER_THREE_TIME = "支付密码错误,请15分钟后再试";
public static final String ERROR_TRADE_PWD_ERROR = "支付密码错误,请重试";
public static final String ERROR_EMPTY_PWD_ERROR = "请设置登录密码";
public static final String ERROR_TEL_NOT_RGI = "该号码未注册";
public static final String ERROR_USERNAME_OR_PASSWORD = "用户名或者密码错误";
public static final String ERROR_TRADE_PWD = "交易密码错误";
public static final String ERROR_FORBIDDEN_OPER = "非法操作";
public static final String ERROR_TRADE_PWD_NOT_SET = "非法操作";
public static final String ERROR_NOT_REAL_NAME_AUTH = "您未实名认证,禁止该操作";
public static final String ERROR_INTERNAL_SERVER_ERROR = "服务器内部错误";
public static final String ERROR_UNAUTHORIZED = "token不正确或已过期";
public static final String ERROR_TOKEN_IS_NULL = "token不能为空";
public static final String ERROR_MISS_SERVLET = "服务不存在";
public static final String ERROR_CAPTCHA_OFTEN = "验证码已发送";
public static final String ERROR_CAPTCHA_WRONG = "验证码错误";
public static final String ERROR_TEL_ALREADY_REGI = "该手机号已被注册";
public static final String ERROR_CODE_DUPLICATE_KEY = "重复添加信息(含部分)";
public static final String ERROR_NOT_EXITS = "对应记录不存在";
public static final String ERROR_STATUS_CATEGORY = "状态错误";
public static final String ERROR_FRIEND_SHIP_ALREADY = "已经是你好友";
public static final String ERROR_FRIEND_SHIP_WAIT = "已向改好友发出邀请,等待接受";
public static final String ERROR_CODE_ACCOUNT_LOCKED = "账号被锁定,请联系客服";
public static final String WARN_ARGUMENT = "参数错误";
public static final String ERROR_USERNAME_EXIST = "该号码已被注册";
public static final String ERROR_SAFETY_RISK = "不在常用设备上登录";
public static final String INFO_TEL_BIND = "手机号码已经被绑定";
public static final String INFO_TEL_FORMAT_WRONG = "手机号码格式不正确";
public static final String ERROR_NOT_FOUND = "404 not found";
public static final String DISABLED="该账号已被封禁,如有疑问请联系平台";
public static final String DATENULL="缺少参数";
public static final String ERRDATE="无效参数";
public static final String ERRSTAE="状态异常";
public static final String EXTDATE="参数异常";
public static final String NUMEXE="账号异常";
public static final String CAPDON="资产已被冻结,如有疑问请联系平台";
public static final String CONOTS="操作失败";
public static final String OK="成功!";
public static final String TOKENX="身份验证失败,请重新登录";
public static final String CAPNOT="充值余额不足请充值";
public static final String SYSNOT="系统繁忙,请稍后再试...";
public static final String NOWER="没有权限";
public static final String PAGEDATA="分页参数不能为空";
public static final String CARADD_MEMBERS="该司机已有绑定车辆,不能绑定多个";
}
package com.mortals.xhx.common.key;
/**
*
*
* @author: zxfei
* @date: 2022/5/12 14:57
*/
public class HttpStatus {
/**
* 操作成功
*/
public static final int SUCCESS = 200;
/**
* 对象创建成功
*/
public static final int CREATED = 201;
/**
* 请求已经被接受
*/
public static final int ACCEPTED = 202;
/**
* 操作已经执行成功,但是没有返回数据
*/
public static final int NO_CONTENT = 204;
/**
* 资源已被移除
*/
public static final int MOVED_PERM = 301;
/**
* 重定向
*/
public static final int SEE_OTHER = 303;
/**
* 资源没有被修改
*/
public static final int NOT_MODIFIED = 304;
/**
* 参数列表错误(缺少,格式不匹配)
*/
public static final int BAD_REQUEST = 400;
/**
* 未授权
*/
public static final int UNAUTHORIZED = 401;
/**
* 访问受限,授权过期
*/
public static final int FORBIDDEN = 403;
/**
* 资源,服务未找到
*/
public static final int NOT_FOUND = 404;
/**
* 不允许的http方法
*/
public static final int BAD_METHOD = 405;
/**
* 资源冲突,或者资源被锁
*/
public static final int CONFLICT = 409;
/**
* 不支持的数据,媒体类型
*/
public static final int UNSUPPORTED_TYPE = 415;
/**
* 系统内部错误
*/
public static final int ERROR = 500;
/**
* 接口未实现
*/
public static final int NOT_IMPLEMENTED = 501;
}
...@@ -24,7 +24,12 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{ ...@@ -24,7 +24,12 @@ public interface DeviceService extends ICRUDCacheService<DeviceEntity,Long>{
ApiResp<String> sendDeviceMessage(List<Long> deviceIds, TopicPartitionInfo info,TbQueueMsgHeaders header, String message , Context context); ApiResp<String> sendDeviceMessage(List<Long> deviceIds, TopicPartitionInfo info,TbQueueMsgHeaders header, String message , Context context);
/**
* 设备激活
* @param deviceCode
* @param context
*/
void active(String deviceCode,Context context);
} }
\ No newline at end of file
package com.mortals.xhx.module.device.service.impl; 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.exception.AppException;
import com.mortals.framework.model.Context; import com.mortals.framework.model.Context;
import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl; import com.mortals.framework.service.impl.AbstractCRUDCacheServiceImpl;
import com.mortals.xhx.base.system.message.MessageService; import com.mortals.xhx.base.system.message.MessageService;
import com.mortals.xhx.busiz.req.DeviceReq;
import com.mortals.xhx.busiz.rsp.ApiResp; import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum; import com.mortals.xhx.common.code.*;
import com.mortals.xhx.common.key.Constant; import com.mortals.xhx.common.key.Constant;
import com.mortals.xhx.common.utils.BeanUtil;
import com.mortals.xhx.module.device.dao.DeviceDao; import com.mortals.xhx.module.device.dao.DeviceDao;
import com.mortals.xhx.module.device.model.DeviceEntity; import com.mortals.xhx.module.device.model.DeviceEntity;
import com.mortals.xhx.module.device.model.DeviceQuery; import com.mortals.xhx.module.device.model.DeviceQuery;
...@@ -17,6 +21,7 @@ import com.mortals.xhx.module.product.model.ProductEntity; ...@@ -17,6 +21,7 @@ import com.mortals.xhx.module.product.model.ProductEntity;
import com.mortals.xhx.module.product.service.ProductService; import com.mortals.xhx.module.product.service.ProductService;
import com.mortals.xhx.queue.*; import com.mortals.xhx.queue.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -55,10 +60,10 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -55,10 +60,10 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
@Override @Override
protected void validData(DeviceEntity entity, Context context) throws AppException { protected void validData(DeviceEntity entity, Context context) throws AppException {
if(!ObjectUtils.isEmpty(entity.getPlatformId())){ if (!ObjectUtils.isEmpty(entity.getPlatformId())) {
throw new AppException("所属平台不能为空!"); throw new AppException("所属平台不能为空!");
} }
if(!ObjectUtils.isEmpty(entity.getProductId())){ if (!ObjectUtils.isEmpty(entity.getProductId())) {
throw new AppException("所属产品不能为空!"); throw new AppException("所属产品不能为空!");
} }
...@@ -75,11 +80,9 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -75,11 +80,9 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
public void onSuccess(TbQueueMsgMetadata metadata) { public void onSuccess(TbQueueMsgMetadata metadata) {
log.info("消息投递成功,设备通道编码:" + deviceEntity.getDeviceMac()); log.info("消息投递成功,设备通道编码:" + deviceEntity.getDeviceMac());
} }
@Override @Override
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
log.error("消息投递成功,设备通道编码:" + deviceEntity.getDeviceMac(), t); log.error("消息投递成功,设备通道编码:" + deviceEntity.getDeviceMac(), t);
} }
}; };
messageService.send(info, header, message, callback); messageService.send(info, header, message, callback);
...@@ -98,6 +101,33 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -98,6 +101,33 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
return resp; return resp;
} }
@Override
public void active(String deviceCode, Context context) {
DeviceEntity deviceEntity = this.selectOne(new DeviceQuery().deviceCode(deviceCode));
if (!ObjectUtils.isEmpty(deviceEntity)) throw new AppException("当前设备不存在!");
if (deviceEntity.getActive() == ActiveEnum.已激活.getValue()) throw new AppException("当前设备已激活!");
deviceEntity.setActive(ActiveEnum.已激活.getValue());
this.update(deviceEntity, context);
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(deviceEntity, deviceReq, BeanUtil.getNullPropertyNames(deviceEntity));
deviceReq.setDeviceStatus(DeviceStatusEnum.ACTIVE.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
if (PatternPool.URL_HTTP.matcher(platformEntity.getSendUrl()).find()) {
ApiResp<String> resp = messageService.sendThirdParty(platformEntity.getSendUrl(), MessageTypeEnum.CRUD.getValue(), deviceReq);
} else {
throw new AppException("http send url 不合法!" + platformEntity.getSendUrl());
}
}
}
}
@Override @Override
protected void saveAfter(DeviceEntity entity, Context context) throws AppException { protected void saveAfter(DeviceEntity entity, Context context) throws AppException {
...@@ -128,14 +158,49 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -128,14 +158,49 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
//创建下行队列 //创建下行队列
info = TopicPartitionInfo.builder().exchangeName(exchangeName).topic(Constant.DOWN_TOPIC + entity.getDeviceCode()).build(); info = TopicPartitionInfo.builder().exchangeName(exchangeName).topic(Constant.DOWN_TOPIC + entity.getDeviceCode()).build();
messageService.queueDeclare(info, callback); messageService.queueDeclare(info, callback);
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(entity, deviceReq, BeanUtil.getNullPropertyNames(entity));
deviceReq.setDeviceStatus(DeviceStatusEnum.ADD.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
if (PatternPool.URL_HTTP.matcher(platformEntity.getSendUrl()).find()) {
ApiResp<String> resp = messageService.sendThirdParty(platformEntity.getSendUrl(), MessageTypeEnum.CRUD.getValue(), deviceReq);
} else {
throw new AppException("http send url 不合法!" + platformEntity.getSendUrl());
}
}
} else { } else {
throw new AppException("产品或平台不存在!"); throw new AppException("产品或平台不存在!");
} }
super.saveAfter(entity, context);
}
super.saveAfter(entity, context); @Override
protected void updateAfter(DeviceEntity entity, Context context) throws AppException {
PlatformEntity platformEntity = platformService.get(entity.getPlatformId());
ProductEntity productEntity = productService.get(entity.getProductId());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(entity, deviceReq, BeanUtil.getNullPropertyNames(entity));
deviceReq.setDeviceStatus(DeviceStatusEnum.UPDATE.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
if (PatternPool.URL_HTTP.matcher(platformEntity.getSendUrl()).find()) {
ApiResp<String> resp = messageService.sendThirdParty(platformEntity.getSendUrl(), MessageTypeEnum.CRUD.getValue(), deviceReq);
} else {
throw new AppException("http send url 不合法!" + platformEntity.getSendUrl());
}
}
} }
super.updateAfter(entity, context);
}
@Override @Override
protected void removeBefore(Long[] ids, Context context) throws AppException { protected void removeBefore(Long[] ids, Context context) throws AppException {
...@@ -146,14 +211,35 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D ...@@ -146,14 +211,35 @@ public class DeviceServiceImpl extends AbstractCRUDCacheServiceImpl<DeviceDao, D
public void onSuccess(TbQueueMsgMetadata metadata) { public void onSuccess(TbQueueMsgMetadata metadata) {
log.info("队列删除成功"); log.info("队列删除成功");
} }
@Override @Override
public void onFailure(Throwable t) { public void onFailure(Throwable t) {
log.error("队列删除失败", t); log.error("队列删除失败", t);
} }
}; };
messageService.delQueue(Constant.UPLOAD_TOPIC + deviceEntity.getDeviceCode(),callback); messageService.delQueue(Constant.UPLOAD_TOPIC + deviceEntity.getDeviceCode(), callback);
messageService.delQueue(Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(),callback); messageService.delQueue(Constant.DOWN_TOPIC + deviceEntity.getDeviceCode(), callback);
PlatformEntity platformEntity = platformService.get(deviceEntity.getPlatformId());
ProductEntity productEntity = productService.get(deviceEntity.getProductId());
if (!ObjectUtils.isEmpty(platformEntity) && !ObjectUtils.isEmpty(productEntity)) {
//新增设备通知第三方平台
DeviceReq deviceReq = new DeviceReq();
BeanUtils.copyProperties(deviceEntity, deviceReq, BeanUtil.getNullPropertyNames(deviceEntity));
deviceReq.setDeviceStatus(DeviceStatusEnum.DEL.getValue());
deviceReq.setProductCode(productEntity.getProductCode());
deviceReq.setPlatformCode(platformEntity.getPlatformSn());
if (!ObjectUtils.isEmpty(platformEntity.getSendUrl()) && platformEntity.getSendSwitch() == SendSwitchEnum.启用.getValue()) {
if (PatternPool.URL_HTTP.matcher(platformEntity.getSendUrl()).find()) {
ApiResp<String> resp = messageService.sendThirdParty(platformEntity.getSendUrl(), MessageTypeEnum.CRUD.getValue(), deviceReq);
} else {
throw new AppException("http send url 不合法!" + platformEntity.getSendUrl());
}
}
}
}); });
super.removeBefore(ids, context); super.removeBefore(ids, context);
......
...@@ -7,11 +7,11 @@ import com.mortals.framework.annotation.Excel; ...@@ -7,11 +7,11 @@ import com.mortals.framework.annotation.Excel;
import com.mortals.framework.model.BaseEntityLong; import com.mortals.framework.model.BaseEntityLong;
import com.mortals.xhx.module.platform.model.vo.PlatformVo; import com.mortals.xhx.module.platform.model.vo.PlatformVo;
/** /**
* 平台系统实体对象 * 平台系统实体对象
* *
* @author zxfei * @author zxfei
* @date 2022-04-25 * @date 2022-05-30
*/ */
public class PlatformEntity extends PlatformVo { public class PlatformEntity extends PlatformVo {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
...@@ -30,13 +30,21 @@ public class PlatformEntity extends PlatformVo { ...@@ -30,13 +30,21 @@ public class PlatformEntity extends PlatformVo {
*/ */
private Integer sendMsgType; private Integer sendMsgType;
/** /**
* 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 发送参数请求地址
*/
private String sendUrl;
/**
* 回调参数地址
*/ */
private String sendConfig; private String callbackUrl;
/** /**
* 是否启用发送消息(0.停用,1.启用) * 是否启用发送消息(0.停用,1.启用)
*/ */
private Integer sendSwitch; private Integer sendSwitch;
/**
* 首页地址
*/
private String homeUrl;
/** /**
* 备注 * 备注
*/ */
...@@ -88,18 +96,32 @@ public class PlatformEntity extends PlatformVo { ...@@ -88,18 +96,32 @@ public class PlatformEntity extends PlatformVo {
this.sendMsgType = sendMsgType; this.sendMsgType = sendMsgType;
} }
/** /**
* 获取 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 获取 发送参数请求地址
* @return String * @return String
*/ */
public String getSendConfig(){ public String getSendUrl(){
return sendConfig; return sendUrl;
} }
/** /**
* 设置 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 设置 发送参数请求地址
* @param sendConfig * @param sendUrl
*/ */
public void setSendConfig(String sendConfig){ public void setSendUrl(String sendUrl){
this.sendConfig = sendConfig; this.sendUrl = sendUrl;
}
/**
* 获取 回调参数地址
* @return String
*/
public String getCallbackUrl(){
return callbackUrl;
}
/**
* 设置 回调参数地址
* @param callbackUrl
*/
public void setCallbackUrl(String callbackUrl){
this.callbackUrl = callbackUrl;
} }
/** /**
* 获取 是否启用发送消息(0.停用,1.启用) * 获取 是否启用发送消息(0.停用,1.启用)
...@@ -115,6 +137,20 @@ public class PlatformEntity extends PlatformVo { ...@@ -115,6 +137,20 @@ public class PlatformEntity extends PlatformVo {
public void setSendSwitch(Integer sendSwitch){ public void setSendSwitch(Integer sendSwitch){
this.sendSwitch = sendSwitch; this.sendSwitch = sendSwitch;
} }
/**
* 获取 首页地址
* @return String
*/
public String getHomeUrl(){
return homeUrl;
}
/**
* 设置 首页地址
* @param homeUrl
*/
public void setHomeUrl(String homeUrl){
this.homeUrl = homeUrl;
}
/** /**
* 获取 备注 * 获取 备注
* @return String * @return String
...@@ -154,8 +190,10 @@ public class PlatformEntity extends PlatformVo { ...@@ -154,8 +190,10 @@ public class PlatformEntity extends PlatformVo {
sb.append(",platformName:").append(getPlatformName()); sb.append(",platformName:").append(getPlatformName());
sb.append(",platformSn:").append(getPlatformSn()); sb.append(",platformSn:").append(getPlatformSn());
sb.append(",sendMsgType:").append(getSendMsgType()); sb.append(",sendMsgType:").append(getSendMsgType());
sb.append(",sendConfig:").append(getSendConfig()); sb.append(",sendUrl:").append(getSendUrl());
sb.append(",callbackUrl:").append(getCallbackUrl());
sb.append(",sendSwitch:").append(getSendSwitch()); sb.append(",sendSwitch:").append(getSendSwitch());
sb.append(",homeUrl:").append(getHomeUrl());
sb.append(",platformRemark:").append(getPlatformRemark()); sb.append(",platformRemark:").append(getPlatformRemark());
return sb.toString(); return sb.toString();
} }
...@@ -168,10 +206,14 @@ public class PlatformEntity extends PlatformVo { ...@@ -168,10 +206,14 @@ public class PlatformEntity extends PlatformVo {
this.sendMsgType = 0; this.sendMsgType = 0;
this.sendConfig = ""; this.sendUrl = "";
this.callbackUrl = "";
this.sendSwitch = 0; this.sendSwitch = 0;
this.homeUrl = "";
this.platformRemark = ""; this.platformRemark = "";
} }
} }
\ No newline at end of file
...@@ -3,11 +3,11 @@ package com.mortals.xhx.module.platform.model; ...@@ -3,11 +3,11 @@ package com.mortals.xhx.module.platform.model;
import java.util.List; import java.util.List;
import com.mortals.xhx.module.platform.model.PlatformEntity; import com.mortals.xhx.module.platform.model.PlatformEntity;
/** /**
* 平台系统查询对象 * 平台系统查询对象
* *
* @author zxfei * @author zxfei
* @date 2022-04-25 * @date 2022-05-30
*/ */
public class PlatformQuery extends PlatformEntity { public class PlatformQuery extends PlatformEntity {
/** 开始 主键ID,主键,自增长 */ /** 开始 主键ID,主键,自增长 */
private Long idStart; private Long idStart;
...@@ -39,8 +39,11 @@ public class PlatformQuery extends PlatformEntity { ...@@ -39,8 +39,11 @@ public class PlatformQuery extends PlatformEntity {
/** 发送第三方平台消息类型(0.http,1.jms)列表 */ /** 发送第三方平台消息类型(0.http,1.jms)列表 */
private List <Integer> sendMsgTypeList; private List <Integer> sendMsgTypeList;
/** 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 */ /** 发送参数请求地址 */
private List<String> sendConfigList; private List<String> sendUrlList;
/** 回调参数地址 */
private List<String> callbackUrlList;
/** 开始 是否启用发送消息(0.停用,1.启用) */ /** 开始 是否启用发送消息(0.停用,1.启用) */
private Integer sendSwitchStart; private Integer sendSwitchStart;
...@@ -54,6 +57,9 @@ public class PlatformQuery extends PlatformEntity { ...@@ -54,6 +57,9 @@ public class PlatformQuery extends PlatformEntity {
/** 是否启用发送消息(0.停用,1.启用)列表 */ /** 是否启用发送消息(0.停用,1.启用)列表 */
private List <Integer> sendSwitchList; private List <Integer> sendSwitchList;
/** 首页地址 */
private List<String> homeUrlList;
/** 备注 */ /** 备注 */
private List<String> platformRemarkList; private List<String> platformRemarkList;
...@@ -260,19 +266,34 @@ public class PlatformQuery extends PlatformEntity { ...@@ -260,19 +266,34 @@ public class PlatformQuery extends PlatformEntity {
} }
/** /**
* 获取 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 获取 发送参数请求地址
* @return sendConfigList * @return sendUrlList
*/
public List<String> getSendUrlList(){
return this.sendUrlList;
}
/**
* 设置 发送参数请求地址
* @param sendUrlList
*/
public void setSendUrlList(List<String> sendUrlList){
this.sendUrlList = sendUrlList;
}
/**
* 获取 回调参数地址
* @return callbackUrlList
*/ */
public List<String> getSendConfigList(){ public List<String> getCallbackUrlList(){
return this.sendConfigList; return this.callbackUrlList;
} }
/** /**
* 设置 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 设置 回调参数地址
* @param sendConfigList * @param callbackUrlList
*/ */
public void setSendConfigList(List<String> sendConfigList){ public void setCallbackUrlList(List<String> callbackUrlList){
this.sendConfigList = sendConfigList; this.callbackUrlList = callbackUrlList;
} }
/** /**
* 获取 开始 是否启用发送消息(0.停用,1.启用) * 获取 开始 是否启用发送消息(0.停用,1.启用)
...@@ -338,6 +359,21 @@ public class PlatformQuery extends PlatformEntity { ...@@ -338,6 +359,21 @@ public class PlatformQuery extends PlatformEntity {
this.sendSwitchList = sendSwitchList; this.sendSwitchList = sendSwitchList;
} }
/**
* 获取 首页地址
* @return homeUrlList
*/
public List<String> getHomeUrlList(){
return this.homeUrlList;
}
/**
* 设置 首页地址
* @param homeUrlList
*/
public void setHomeUrlList(List<String> homeUrlList){
this.homeUrlList = homeUrlList;
}
/** /**
* 获取 备注 * 获取 备注
* @return platformRemarkList * @return platformRemarkList
...@@ -675,20 +711,39 @@ public class PlatformQuery extends PlatformEntity { ...@@ -675,20 +711,39 @@ public class PlatformQuery extends PlatformEntity {
/** /**
* 设置 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 设置 发送参数请求地址
* @param sendConfig * @param sendUrl
*/ */
public PlatformQuery sendConfig(String sendConfig){ public PlatformQuery sendUrl(String sendUrl){
setSendConfig(sendConfig); setSendUrl(sendUrl);
return this; return this;
} }
/** /**
* 设置 发送参数配置,如发送消息地址等,xml结构,根据消息类型变化 * 设置 发送参数请求地址
* @param sendConfigList * @param sendUrlList
*/ */
public PlatformQuery sendConfigList(List<String> sendConfigList){ public PlatformQuery sendUrlList(List<String> sendUrlList){
this.sendConfigList = sendConfigList; this.sendUrlList = sendUrlList;
return this;
}
/**
* 设置 回调参数地址
* @param callbackUrl
*/
public PlatformQuery callbackUrl(String callbackUrl){
setCallbackUrl(callbackUrl);
return this;
}
/**
* 设置 回调参数地址
* @param callbackUrlList
*/
public PlatformQuery callbackUrlList(List<String> callbackUrlList){
this.callbackUrlList = callbackUrlList;
return this; return this;
} }
...@@ -738,6 +793,25 @@ public class PlatformQuery extends PlatformEntity { ...@@ -738,6 +793,25 @@ public class PlatformQuery extends PlatformEntity {
} }
/**
* 设置 首页地址
* @param homeUrl
*/
public PlatformQuery homeUrl(String homeUrl){
setHomeUrl(homeUrl);
return this;
}
/**
* 设置 首页地址
* @param homeUrlList
*/
public PlatformQuery homeUrlList(List<String> homeUrlList){
this.homeUrlList = homeUrlList;
return this;
}
/** /**
* 设置 备注 * 设置 备注
* @param platformRemark * @param platformRemark
......
...@@ -49,10 +49,6 @@ public class PlatformController extends BaseCRUDJsonMappingController<PlatformSe ...@@ -49,10 +49,6 @@ public class PlatformController extends BaseCRUDJsonMappingController<PlatformSe
@Autowired @Autowired
private ParamService paramService; private ParamService paramService;
private ICacheService cacheService = LocalCacheServiceImpl.getInstance();
private final String KEY = "base-platform:admin,admin";//基础服务平台获取token
public PlatformController() { public PlatformController() {
super.setFormClass(PlatformForm.class); super.setFormClass(PlatformForm.class);
super.setModuleDesc("平台系统"); super.setModuleDesc("平台系统");
...@@ -64,133 +60,4 @@ public class PlatformController extends BaseCRUDJsonMappingController<PlatformSe ...@@ -64,133 +60,4 @@ public class PlatformController extends BaseCRUDJsonMappingController<PlatformSe
this.addDict(model, "sendSwitch", paramService.getParamBySecondOrganize("Platform", "sendSwitch")); this.addDict(model, "sendSwitch", paramService.getParamBySecondOrganize("Platform", "sendSwitch"));
super.init(request, response, form, model, context); super.init(request, response, form, model, context);
} }
@GetMapping("getSite")
public String getSite(@RequestParam("parentId") String parentId) {
log.info("【获取站点】【请求体】-->parentId " + parentId);
String res = null;
try {
String token = cacheService.get(KEY);
if(token == null){
token = getToken();
if(token == null){
throw new AppException("未获取到token");
}
}
res = getSiteList(parentId, token);
if(JSONObject.parseObject(res).get("code").equals(-1)){
token = getToken();
res = getSiteList(parentId, token);
}
} catch (Exception e) {
log.error("接收数据失败", e);
return res;
}
log.info("响应【获取站点】【响应体】--> " + res);
return res;
}
//获取基础服务平台站点信息
private String getSiteList(String parentId, String token){
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
String result = "";
try {
// 通过址默认配置创建一个httpClient实例
httpClient = HttpClients.createDefault();
// 创建httpGet远程连接实例
HttpGet httpGet = new HttpGet("http://192.168.0.98:11071/zwfw/area/getListByParentId?parentId=" + parentId);
// 设置请求头信息,鉴权
httpGet.setHeader("Authorization", token);
// 执行get请求得到返回对象
response = httpClient.execute(httpGet);
// 通过返回对象获取返回数据
HttpEntity entity = response.getEntity();
// 通过EntityUtils中的toString方法将结果转换为字符串
result = EntityUtils.toString(entity);
} catch (Exception e) {
log.error("接收数据失败", e);
return JSON.toJSONString(result);
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (httpClient != null) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
JSONObject object = JSONObject.parseObject(result);
if(object == null || object.get("code") == null){
throw new AppException("基础服务平台获取站点信息失败,响应值: " + response);
}
return result;
}
//获取基础服务平台token
private String getToken() {
CloseableHttpResponse httpResponse = null;
String response = "";
Object token = null;
// 创建httpClient实例
CloseableHttpClient httpClient = HttpClients.createDefault();
// 创建httpPost远程连接实例
HttpPost httpPost = new HttpPost("http://192.168.0.98:11071/zwfw/login/login");
JSONObject request = null;
try {
request = new JSONObject();
request.put("loginName", "admin");
request.put("password", "admin");
request.put("securityCode", 8888);
log.info("登录基础服务平台,参数-->" + request);
StringEntity entity = new StringEntity(request.toString());
entity.setContentType("application/json;charset=UTF-8");
httpPost.setEntity(entity);
// httpClient对象执行post请求,并返回响应参数对象
httpResponse = httpClient.execute(httpPost);
// 从响应对象中获取响应内容
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
} catch (IOException e) {
e.printStackTrace();
log.error("基础服务平台登录失败,响应体:" + httpResponse);
} finally {
// 关闭资源
if (null != httpResponse) {
try {
httpResponse.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != httpClient) {
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
JSONObject object = JSONObject.parseObject(response);
if(object == null || object.get("code") == null || object.get("code").equals(-1)){
throw new AppException("基础服务平台登录获取token失败,响应值: " + response);
}
if(object.get("code").equals(1)){
token = JSONObject.parseObject(object.get("data").toString()).get("token");
cacheService.sadd(KEY,token);
return token.toString();
}
return null;
}
} }
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"mybatis-3-mapper.dtd"> "mybatis-3-mapper.dtd">
<mapper namespace="com.mortals.xhx.module.platform.dao.ibatis.PlatformDaoImpl"> <mapper namespace="com.mortals.xhx.module.platform.dao.ibatis.PlatformDaoImpl">
<!-- 字段和属性映射 --> <!-- 字段和属性映射 -->
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
<result property="platformName" column="platformName" /> <result property="platformName" column="platformName" />
<result property="platformSn" column="platformSn" /> <result property="platformSn" column="platformSn" />
<result property="sendMsgType" column="sendMsgType" /> <result property="sendMsgType" column="sendMsgType" />
<result property="sendConfig" column="sendConfig" /> <result property="sendUrl" column="sendUrl" />
<result property="callbackUrl" column="callbackUrl" />
<result property="sendSwitch" column="sendSwitch" /> <result property="sendSwitch" column="sendSwitch" />
<result property="homeUrl" column="homeUrl" />
<result property="platformRemark" column="platformRemark" /> <result property="platformRemark" column="platformRemark" />
<result property="createUserId" column="createUserId" /> <result property="createUserId" column="createUserId" />
<result property="createTime" column="createTime" /> <result property="createTime" column="createTime" />
...@@ -35,12 +37,18 @@ ...@@ -35,12 +37,18 @@
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('sendMsgType') or colPickMode == 1 and data.containsKey('sendMsgType')))"> <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('sendMsgType') or colPickMode == 1 and data.containsKey('sendMsgType')))">
a.sendMsgType, a.sendMsgType,
</if> </if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('sendConfig') or colPickMode == 1 and data.containsKey('sendConfig')))"> <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('sendUrl') or colPickMode == 1 and data.containsKey('sendUrl')))">
a.sendConfig, a.sendUrl,
</if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('callbackUrl') or colPickMode == 1 and data.containsKey('callbackUrl')))">
a.callbackUrl,
</if> </if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('sendSwitch') or colPickMode == 1 and data.containsKey('sendSwitch')))"> <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('sendSwitch') or colPickMode == 1 and data.containsKey('sendSwitch')))">
a.sendSwitch, a.sendSwitch,
</if> </if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('homeUrl') or colPickMode == 1 and data.containsKey('homeUrl')))">
a.homeUrl,
</if>
<if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('platformRemark') or colPickMode == 1 and data.containsKey('platformRemark')))"> <if test="(data == null) or (data != null and ( colPickMode == 0 and !data.containsKey('platformRemark') or colPickMode == 1 and data.containsKey('platformRemark')))">
a.platformRemark, a.platformRemark,
</if> </if>
...@@ -61,18 +69,18 @@ ...@@ -61,18 +69,18 @@
<!-- 新增 区分主键自增加还是业务插入 --> <!-- 新增 区分主键自增加还是业务插入 -->
<insert id="insert" parameterType="PlatformEntity" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" parameterType="PlatformEntity" useGeneratedKeys="true" keyProperty="id">
insert into mortals_xhx_platform insert into mortals_xhx_platform
(platformName,platformSn,sendMsgType,sendConfig,sendSwitch,platformRemark,createUserId,createTime,updateUserId,updateTime) (platformName,platformSn,sendMsgType,sendUrl,callbackUrl,sendSwitch,homeUrl,platformRemark,createUserId,createTime,updateUserId,updateTime)
VALUES VALUES
(#{platformName},#{platformSn},#{sendMsgType},#{sendConfig},#{sendSwitch},#{platformRemark},#{createUserId},#{createTime},#{updateUserId},#{updateTime}) (#{platformName},#{platformSn},#{sendMsgType},#{sendUrl},#{callbackUrl},#{sendSwitch},#{homeUrl},#{platformRemark},#{createUserId},#{createTime},#{updateUserId},#{updateTime})
</insert> </insert>
<!-- 批量新增 --> <!-- 批量新增 -->
<insert id="insertBatch" parameterType="paramDto"> <insert id="insertBatch" parameterType="paramDto">
insert into mortals_xhx_platform insert into mortals_xhx_platform
(platformName,platformSn,sendMsgType,sendConfig,sendSwitch,platformRemark,createUserId,createTime,updateUserId,updateTime) (platformName,platformSn,sendMsgType,sendUrl,callbackUrl,sendSwitch,homeUrl,platformRemark,createUserId,createTime,updateUserId,updateTime)
VALUES VALUES
<foreach collection="data.dataList" item="item" index="index" separator="," > <foreach collection="data.dataList" item="item" index="index" separator="," >
(#{item.platformName},#{item.platformSn},#{item.sendMsgType},#{item.sendConfig},#{item.sendSwitch},#{item.platformRemark},#{item.createUserId},#{item.createTime},#{item.updateUserId},#{item.updateTime}) (#{item.platformName},#{item.platformSn},#{item.sendMsgType},#{item.sendUrl},#{item.callbackUrl},#{item.sendSwitch},#{item.homeUrl},#{item.platformRemark},#{item.createUserId},#{item.createTime},#{item.updateUserId},#{item.updateTime})
</foreach> </foreach>
</insert> </insert>
...@@ -94,8 +102,11 @@ ...@@ -94,8 +102,11 @@
<if test="(colPickMode==0 and data.containsKey('sendMsgTypeIncrement')) or (colPickMode==1 and !data.containsKey('sendMsgTypeIncrement'))"> <if test="(colPickMode==0 and data.containsKey('sendMsgTypeIncrement')) or (colPickMode==1 and !data.containsKey('sendMsgTypeIncrement'))">
a.sendMsgType=ifnull(a.sendMsgType,0) + #{data.sendMsgTypeIncrement}, a.sendMsgType=ifnull(a.sendMsgType,0) + #{data.sendMsgTypeIncrement},
</if> </if>
<if test="(colPickMode==0 and data.containsKey('sendConfig')) or (colPickMode==1 and !data.containsKey('sendConfig'))"> <if test="(colPickMode==0 and data.containsKey('sendUrl')) or (colPickMode==1 and !data.containsKey('sendUrl'))">
a.sendConfig=#{data.sendConfig}, a.sendUrl=#{data.sendUrl},
</if>
<if test="(colPickMode==0 and data.containsKey('callbackUrl')) or (colPickMode==1 and !data.containsKey('callbackUrl'))">
a.callbackUrl=#{data.callbackUrl},
</if> </if>
<if test="(colPickMode==0 and data.containsKey('sendSwitch')) or (colPickMode==1 and !data.containsKey('sendSwitch'))"> <if test="(colPickMode==0 and data.containsKey('sendSwitch')) or (colPickMode==1 and !data.containsKey('sendSwitch'))">
a.sendSwitch=#{data.sendSwitch}, a.sendSwitch=#{data.sendSwitch},
...@@ -103,6 +114,9 @@ ...@@ -103,6 +114,9 @@
<if test="(colPickMode==0 and data.containsKey('sendSwitchIncrement')) or (colPickMode==1 and !data.containsKey('sendSwitchIncrement'))"> <if test="(colPickMode==0 and data.containsKey('sendSwitchIncrement')) or (colPickMode==1 and !data.containsKey('sendSwitchIncrement'))">
a.sendSwitch=ifnull(a.sendSwitch,0) + #{data.sendSwitchIncrement}, a.sendSwitch=ifnull(a.sendSwitch,0) + #{data.sendSwitchIncrement},
</if> </if>
<if test="(colPickMode==0 and data.containsKey('homeUrl')) or (colPickMode==1 and !data.containsKey('homeUrl'))">
a.homeUrl=#{data.homeUrl},
</if>
<if test="(colPickMode==0 and data.containsKey('platformRemark')) or (colPickMode==1 and !data.containsKey('platformRemark'))"> <if test="(colPickMode==0 and data.containsKey('platformRemark')) or (colPickMode==1 and !data.containsKey('platformRemark'))">
a.platformRemark=#{data.platformRemark}, a.platformRemark=#{data.platformRemark},
</if> </if>
...@@ -162,10 +176,17 @@ ...@@ -162,10 +176,17 @@
</choose> </choose>
</foreach> </foreach>
</trim> </trim>
<trim prefix="sendConfig=(case" suffix="ELSE sendConfig end),"> <trim prefix="sendUrl=(case" suffix="ELSE sendUrl end),">
<foreach collection="data.dataList" item="item" index="index" separator="" >
<if test="(colPickMode==0 and item.containsKey('sendUrl')) or (colPickMode==1 and !item.containsKey('sendUrl'))">
when a.id=#{item.id} then #{item.sendUrl}
</if>
</foreach>
</trim>
<trim prefix="callbackUrl=(case" suffix="ELSE callbackUrl end),">
<foreach collection="data.dataList" item="item" index="index" separator="" > <foreach collection="data.dataList" item="item" index="index" separator="" >
<if test="(colPickMode==0 and item.containsKey('sendConfig')) or (colPickMode==1 and !item.containsKey('sendConfig'))"> <if test="(colPickMode==0 and item.containsKey('callbackUrl')) or (colPickMode==1 and !item.containsKey('callbackUrl'))">
when a.id=#{item.id} then #{item.sendConfig} when a.id=#{item.id} then #{item.callbackUrl}
</if> </if>
</foreach> </foreach>
</trim> </trim>
...@@ -181,6 +202,13 @@ ...@@ -181,6 +202,13 @@
</choose> </choose>
</foreach> </foreach>
</trim> </trim>
<trim prefix="homeUrl=(case" suffix="ELSE homeUrl end),">
<foreach collection="data.dataList" item="item" index="index" separator="" >
<if test="(colPickMode==0 and item.containsKey('homeUrl')) or (colPickMode==1 and !item.containsKey('homeUrl'))">
when a.id=#{item.id} then #{item.homeUrl}
</if>
</foreach>
</trim>
<trim prefix="platformRemark=(case" suffix="ELSE platformRemark end),"> <trim prefix="platformRemark=(case" suffix="ELSE platformRemark end),">
<foreach collection="data.dataList" item="item" index="index" separator="" > <foreach collection="data.dataList" item="item" index="index" separator="" >
<if test="(colPickMode==0 and item.containsKey('platformRemark')) or (colPickMode==1 and !item.containsKey('platformRemark'))"> <if test="(colPickMode==0 and item.containsKey('platformRemark')) or (colPickMode==1 and !item.containsKey('platformRemark'))">
...@@ -400,17 +428,32 @@ ...@@ -400,17 +428,32 @@
</if> </if>
<if test="conditionParamRef.containsKey('sendConfig')"> <if test="conditionParamRef.containsKey('sendUrl')">
<if test="conditionParamRef.sendConfig != null and conditionParamRef.sendConfig != ''"> <if test="conditionParamRef.sendUrl != null and conditionParamRef.sendUrl != ''">
${_conditionType_} a.sendConfig like #{${_conditionParam_}.sendConfig} ${_conditionType_} a.sendUrl like #{${_conditionParam_}.sendUrl}
</if>
<if test="conditionParamRef.sendUrl == null">
${_conditionType_} a.sendUrl is null
</if>
</if>
<if test="conditionParamRef.containsKey('sendUrlList')">
${_conditionType_} a.sendUrl in
<foreach collection="conditionParamRef.sendUrlList" open="(" close=")" index="index" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="conditionParamRef.containsKey('callbackUrl')">
<if test="conditionParamRef.callbackUrl != null and conditionParamRef.callbackUrl != ''">
${_conditionType_} a.callbackUrl like #{${_conditionParam_}.callbackUrl}
</if> </if>
<if test="conditionParamRef.sendConfig == null"> <if test="conditionParamRef.callbackUrl == null">
${_conditionType_} a.sendConfig is null ${_conditionType_} a.callbackUrl is null
</if> </if>
</if> </if>
<if test="conditionParamRef.containsKey('sendConfigList')"> <if test="conditionParamRef.containsKey('callbackUrlList')">
${_conditionType_} a.sendConfig in ${_conditionType_} a.callbackUrl in
<foreach collection="conditionParamRef.sendConfigList" open="(" close=")" index="index" item="item" separator=","> <foreach collection="conditionParamRef.callbackUrlList" open="(" close=")" index="index" item="item" separator=",">
#{item} #{item}
</foreach> </foreach>
</if> </if>
...@@ -436,6 +479,21 @@ ...@@ -436,6 +479,21 @@
</if> </if>
<if test="conditionParamRef.containsKey('homeUrl')">
<if test="conditionParamRef.homeUrl != null and conditionParamRef.homeUrl != ''">
${_conditionType_} a.homeUrl like #{${_conditionParam_}.homeUrl}
</if>
<if test="conditionParamRef.homeUrl == null">
${_conditionType_} a.homeUrl is null
</if>
</if>
<if test="conditionParamRef.containsKey('homeUrlList')">
${_conditionType_} a.homeUrl in
<foreach collection="conditionParamRef.homeUrlList" open="(" close=")" index="index" item="item" separator=",">
#{item}
</foreach>
</if>
<if test="conditionParamRef.containsKey('platformRemark')"> <if test="conditionParamRef.containsKey('platformRemark')">
<if test="conditionParamRef.platformRemark != null and conditionParamRef.platformRemark != ''"> <if test="conditionParamRef.platformRemark != null and conditionParamRef.platformRemark != ''">
${_conditionType_} a.platformRemark like #{${_conditionParam_}.platformRemark} ${_conditionType_} a.platformRemark like #{${_conditionParam_}.platformRemark}
...@@ -555,9 +613,14 @@ ...@@ -555,9 +613,14 @@
<if test='orderCol.sendMsgType != null and "DESC".equalsIgnoreCase(orderCol.sendMsgType)'>DESC</if> <if test='orderCol.sendMsgType != null and "DESC".equalsIgnoreCase(orderCol.sendMsgType)'>DESC</if>
, ,
</if> </if>
<if test="orderCol.containsKey('sendConfig')"> <if test="orderCol.containsKey('sendUrl')">
a.sendConfig a.sendUrl
<if test='orderCol.sendConfig != null and "DESC".equalsIgnoreCase(orderCol.sendConfig)'>DESC</if> <if test='orderCol.sendUrl != null and "DESC".equalsIgnoreCase(orderCol.sendUrl)'>DESC</if>
,
</if>
<if test="orderCol.containsKey('callbackUrl')">
a.callbackUrl
<if test='orderCol.callbackUrl != null and "DESC".equalsIgnoreCase(orderCol.callbackUrl)'>DESC</if>
, ,
</if> </if>
<if test="orderCol.containsKey('sendSwitch')"> <if test="orderCol.containsKey('sendSwitch')">
...@@ -565,6 +628,11 @@ ...@@ -565,6 +628,11 @@
<if test='orderCol.sendSwitch != null and "DESC".equalsIgnoreCase(orderCol.sendSwitch)'>DESC</if> <if test='orderCol.sendSwitch != null and "DESC".equalsIgnoreCase(orderCol.sendSwitch)'>DESC</if>
, ,
</if> </if>
<if test="orderCol.containsKey('homeUrl')">
a.homeUrl
<if test='orderCol.homeUrl != null and "DESC".equalsIgnoreCase(orderCol.homeUrl)'>DESC</if>
,
</if>
<if test="orderCol.containsKey('platformRemark')"> <if test="orderCol.containsKey('platformRemark')">
a.platformRemark a.platformRemark
<if test='orderCol.platformRemark != null and "DESC".equalsIgnoreCase(orderCol.platformRemark)'>DESC</if> <if test='orderCol.platformRemark != null and "DESC".equalsIgnoreCase(orderCol.platformRemark)'>DESC</if>
......
...@@ -165,24 +165,38 @@ data|object|数据对象|- ...@@ -165,24 +165,38 @@ data|object|数据对象|-
``` ```
### 获取平台产品列表
**请求URL:** m/api/getPlatformAndProduct
**请求方式:** GET ### 新增或更新设备
**请求URL:** m/api/saveOrUpdate
**请求方式:** POST
**鉴权头信息:** Authorization: {{token}}
**内容类型:** application/json;charset=utf-8 **内容类型:** application/json;charset=utf-8
**简要描述:** 查询平台产品列表数据,用于设备新增提交 **简要描述:** 保存或更新设备,设备deviceCode存在更新,不存在新增,
请求需添加接口鉴权token信息,来源getToken接口
**请求参数:** **请求参数:**
参数名称|类型|备注|必填|其它 参数名称|类型|备注|必填|其它
---|---|---|---|--- ---|---|---|---|---
deviceName|String|设备名称|否|-
deviceCode|String|设备编码,如MAC地址|是|-
platformCode|String|平台系统编码|是|见平台编码附录
productCode|String|产品编码|是|见产品编码附录
siteCode|String|站点编号,来源基础服务平台|是|-
siteName|String|站点名称|是|-
homeUrl|String|首页地址|否|-
deviceRemark|String|备注|是|-
**请求样例:** **请求样例:**
``` ```
{
}
``` ```
**响应参数:** **响应参数:**
...@@ -192,25 +206,16 @@ data|object|数据对象|- ...@@ -192,25 +206,16 @@ data|object|数据对象|-
code|Integer|结果码(-1.失败,1.成功)|- code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|- msg|String|消息|-
data|object|数据对象|- 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|产品编码,编码唯一|-
**响应消息样例:** **响应消息样例:**
``` ```
```
```
### 新增或更新设备 ### 激活设备
**请求URL:** m/api/saveOrUpdate **请求URL:** m/api/active
**请求方式:** POST **请求方式:** POST
...@@ -218,37 +223,20 @@ data|object|数据对象|- ...@@ -218,37 +223,20 @@ data|object|数据对象|-
**内容类型:** application/json;charset=utf-8 **内容类型:** application/json;charset=utf-8
**简要描述:** 保存或更新设备,设备deviceCode存在更新,不存在新增, **简要描述:** 激活设备
请求需添加接口鉴权token信息,来源getToken接口 请求需添加接口鉴权token信息,来源getToken接口
**请求参数:** **请求参数:**
参数名称|类型|备注|必填|其它 参数名称|类型|备注|必填|其它
---|---|---|---|--- ---|---|---|---|---
deviceName|String|设备名称|否|-
deviceCode|String|设备编码|是|- deviceCode|String|设备编码|是|-
deviceMac|String|设备的MAC地址|否|-
platformId|Long|平台系统Id|是|来源接口获取平台产品列表
platformName|String|平台系统名称|是|-
productId|Long|产品Id|是|来源接口获取平台产品列表
productName|String|产品名称|是|-
siteCode|String|站点编号,来源基础服务平台|是|-
siteName|String|站点名称|是|-
deviceRemark|String|备注|是|-
**请求样例:** **请求样例:**
``` ```
{ {
"deviceName":"lmfrs8",
"deviceCode":"yte9s3", "deviceCode":"yte9s3",
"siteCode":"nmyc5u",
"siteName":"a4vxhg",
"deviceMac":"y9tuaw",
"platformId":3125,
"productId":362,
"deviceRemark":"ah98cp",
} }
``` ```
...@@ -266,9 +254,9 @@ data|object|数据对象|- ...@@ -266,9 +254,9 @@ data|object|数据对象|-
``` ```
### 激活设备 ### 删除设备
**请求URL:** m/api/active **请求URL:** m/api/deviceDel
**请求方式:** POST **请求方式:** POST
...@@ -276,7 +264,7 @@ data|object|数据对象|- ...@@ -276,7 +264,7 @@ data|object|数据对象|-
**内容类型:** application/json;charset=utf-8 **内容类型:** application/json;charset=utf-8
**简要描述:** 激活设备 **简要描述:** 删除设备
请求需添加接口鉴权token信息,来源getToken接口 请求需添加接口鉴权token信息,来源getToken接口
**请求参数:** **请求参数:**
...@@ -307,7 +295,52 @@ data|object|数据对象|- ...@@ -307,7 +295,52 @@ data|object|数据对象|-
``` ```
### 回调各个平台通知消息
**请求URL:** 各平台通知地址
**请求方式:** POST
**内容类型:** application/json;charset=utf-8
**简要描述:** 设备新增激活下线等消息通知各个平台,当配置了地址时候
**请求参数:**
参数名称|类型|备注|必填|其它
:---|:---|:---|:---|:---
code|Integer|结果码(-1.失败,1.成功)|是|-
msg|String|消息|否|-
type|Integer|消息类型|是|0:设备增删改查,data数据域封装具体设备消息,1:设备消息类,数据域透传设备上行消息体。|-
data|object|数据对象|是|-
&emsp;deviceStatus|Integer|状态,1:新增,2:修改,3:删除,4:激活,5:上线,6:下线|是|-
&emsp;deviceName|String|设备名称|否|-
&emsp;deviceCode|String|设备编码,如MAC地址|是|-
&emsp;platformCode|String|平台系统编码|是|见平台编码附录
&emsp;productCode|String|产品编码|是|见产品编码附录
&emsp;siteCode|String|站点编号,来源基础服务平台|是|-
&emsp;siteName|String|站点名称|是|-
&emsp;deviceRemark|String|备注|是|-
**请求样例:**
```
{
}
```
**响应参数:**
参数名称 |参数类型|备注|其它
---|---|---|---
code|Integer|结果码(-1.失败,1.成功)|-
msg|String|消息|-
data|object|数据对象|-
**响应消息样例:**
```
```
## 设备消息 ## 设备消息
......
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