模拟直连设备在APP注册接入

This commit is contained in:
2023-07-06 11:32:25 +08:00
parent 18aa374215
commit feb30c71dd
111 changed files with 968 additions and 3603 deletions

View File

@@ -1,33 +0,0 @@
package com.njcn.access.controller;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/16 13:58
*/
@Slf4j
@RestController
@RequestMapping("/devAccess")
@RequiredArgsConstructor
@Api(tags = "装置接入")
public class AccessController extends BaseController {
}

View File

@@ -1,20 +1,21 @@
package com.njcn.access.controller;
import com.njcn.access.pojo.param.DevModelParam;
import com.njcn.access.service.IDevModelService;
import com.njcn.access.service.ICsDevModelService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -23,27 +24,26 @@ import org.springframework.web.bind.annotation.RestController;
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/4/10 10:26
* @createTime 2023/7/3 15:31
*/
@Slf4j
@RestController
@RequestMapping("/devModel")
@RequestMapping("/analyzeModel")
@Api(tags = "模板解析")
@AllArgsConstructor
@Validated
@Api(tags = "装置模板录入")
public class DevModelController extends BaseController {
public class CsDevModelController extends BaseController {
private final IDevModelService devModelService;
private final ICsDevModelService csDevModelService;
@PostMapping("/add")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("装置录入模板")
public HttpResult<String> add(DevModelParam devModelParam){
log.info("装置录入模板文件");
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{},装置录入模板文件", methodDescribe);
devModelService.add(devModelParam);
@PostMapping("/addModel")
@ApiOperation("新增设备模板")
@ApiImplicitParam(name = "devModelParam", value = "设备模板参数", required = true)
public HttpResult<String> addModel(@RequestBody @Validated DevModelParam devModelParam){
String methodDescribe = getMethodDescribe("addModel");
csDevModelService.addModel(devModelParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,65 @@
package com.njcn.access.controller;
import com.njcn.access.param.DevAccessParam;
import com.njcn.access.service.ICsDeviceService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/7/4 11:23
*/
@Slf4j
@RestController
@RequestMapping("/device")
@Api(tags = "设备注册接入")
@AllArgsConstructor
@Validated
public class CsDeviceController extends BaseController {
private final ICsDeviceService csDeviceService;
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/register")
@ApiOperation("设备注册")
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
public HttpResult<String> devRegister(@RequestParam String nDid){
csDeviceService.devRegister(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, "设备MQTT通讯状态!");
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/model")
@ApiOperation("获取装置模板信息")
@ApiImplicitParam(name = "nDid", value = "设备识别码", required = true)
public HttpResult<Object> getModel(@RequestParam String nDid){
String methodDescribe = getMethodDescribe("getModel");
Object object = csDeviceService.getModel(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, object, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/access")
@ApiOperation("设备接入")
@ApiImplicitParam(name = "devAccessParam", value = "接入参数", required = true)
public HttpResult<String> devAccess(@RequestBody @Validated DevAccessParam devAccessParam){
String methodDescribe = getMethodDescribe("getModel");
csDeviceService.devAccess(devAccessParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -2,7 +2,7 @@ package com.njcn.access.controller;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -11,18 +11,20 @@ import com.njcn.web.controller.BaseController;
/**
* <p>
* 联网设备 前端控制器
* 监测点模板 前端控制器
* </p>
*
* @author xuyang
* @since 2023-05-17
* @since 2023-07-05
*/
@RestController
@RequestMapping("/csNetDev")
@RequiredArgsConstructor
@Api(tags = "网关管理")
@Slf4j
public class CsNetDevController extends BaseController {
@RestController
@RequestMapping("/csLineModel")
@Api(tags = "监测点模板")
@AllArgsConstructor
public class CsLineModelController extends BaseController {
}

View File

@@ -1,54 +1,54 @@
package com.njcn.access.controller;
import com.njcn.access.pojo.MessageParam;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.validation.Valid;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/4/18 13:53
*/
@Slf4j
@RestController
@RequestMapping("/test")
@Api(value = "TestController", tags = {"测试 API"})
public class KafkaController extends BaseController {
@Resource
private KafkaTemplate<String, String> kafkaTemplate;
@PostMapping("/kafka/sendMessage")
@ApiOperation(value = "发送kafka告警消息")
public void sendKafkaMessage(@Valid @ApiParam("参数") @RequestBody MessageParam param) {
kafkaTemplate.send(param.getTopic(), param.getMessage());
}
@Component
public class KafkaConsumer {
// 消费监听
@KafkaListener(topics = {"topic2"})
public void onMessage1(ConsumerRecord<?, ?> record){
// 消费的哪个topic、partition的消息,打印出消息内容
System.out.println("简单消费:"+record.topic()+"-"+record.partition()+"-"+record.value());
}
}
}
//package com.njcn.access.controller;
//
//import com.njcn.access.pojo.param.MessageParam;
//import com.njcn.web.controller.BaseController;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import io.swagger.annotations.ApiParam;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.kafka.clients.consumer.ConsumerRecord;
//import org.springframework.kafka.annotation.KafkaListener;
//import org.springframework.kafka.core.KafkaTemplate;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.PostMapping;
//import org.springframework.web.bind.annotation.RequestBody;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import javax.annotation.Resource;
//import javax.validation.Valid;
//
///**
// * 类的介绍:
// *
// * @author xuyang
// * @version 1.0.0
// * @createTime 2023/4/18 13:53
// */
//@Slf4j
//@RestController
//@RequestMapping("/test")
//@Api(value = "TestController", tags = {"测试 API"})
//public class KafkaController extends BaseController {
//
// @Resource
// private KafkaTemplate<String, String> kafkaTemplate;
//
// @PostMapping("/kafka/sendMessage")
// @ApiOperation(value = "发送kafka告警消息")
// public void sendKafkaMessage(@Valid @ApiParam("参数") @RequestBody MessageParam param) {
// kafkaTemplate.send(param.getTopic(), param.getMessage());
// }
//
// @Component
// public class KafkaConsumer {
// // 消费监听
// @KafkaListener(topics = {"topic2"})
// public void onMessage1(ConsumerRecord<?, ?> record){
// // 消费的哪个topic、partition的消息,打印出消息内容
// System.out.println("简单消费:"+record.topic()+"-"+record.partition()+"-"+record.value());
// }
// }
//
//
//}

View File

@@ -1,51 +0,0 @@
package com.njcn.access.controller;
import com.njcn.access.enums.AccessResponseEnum;
import com.njcn.access.service.IAccessService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Optional;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/3/31 9:12
*/
@Slf4j
@RestController
@RequestMapping("/devRegister")
@RequiredArgsConstructor
@Api(tags = "装置注册")
public class RegisterController extends BaseController {
private final IAccessService accessService;
@PostMapping("/add")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("平台发起注册")
@ApiImplicitParam(name = "nDid", value = "网关识别码", required = true)
public HttpResult<Object> add(@RequestParam String nDid){
log.info("设备向装置侧发起注册请求请求的nDid为" + nDid);
String methodDescribe = getMethodDescribe("add");
LogUtil.njcnDebug(log, "{}设备向装置侧发起注册请求请求的nDid为{}", methodDescribe, nDid);
accessService.add(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -1,48 +0,0 @@
package com.njcn.access.controller;
import com.njcn.access.service.ICsTopicService;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
* 类的介绍:
*
* @author xuyang
* @version 1.0.0
* @createTime 2023/5/12 10:28
*/
@Slf4j
@RestController
@RequestMapping("/topic")
@RequiredArgsConstructor
@Api(tags = "装置主题")
public class TopicController extends BaseController {
private final ICsTopicService csTopicService;
@PostMapping("/ask")
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@ApiOperation("平台询问装置支持主题")
@ApiImplicitParam(name = "nDid", value = "网关识别码", required = true)
public HttpResult<Object> ask(@RequestParam String nDid){
String methodDescribe = getMethodDescribe("ask");
LogUtil.njcnDebug(log, "{}平台询问装置支持主题请求的nDid为{}", methodDescribe, nDid);
csTopicService.askDevTopic(nDid);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}