1.设备出厂时生成mqtt连接信息
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package com.njcn.csdevice.pojo.po;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @since 2023-06-29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@TableName("mqtt_user")
|
||||||
|
public class MqttUser {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
@TableId(value = "id", type = IdType.INPUT)
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private String salt;
|
||||||
|
|
||||||
|
private Integer isSuperuser;
|
||||||
|
|
||||||
|
private LocalDateTime created;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -79,6 +79,16 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>cn.hutool</groupId>
|
||||||
|
<artifactId>hutool-all</artifactId>
|
||||||
|
<version>5.8.5</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class DevModelController extends BaseController {
|
|||||||
@PostMapping("/addDevModel")
|
@PostMapping("/addDevModel")
|
||||||
@ApiOperation("新增设备模板")
|
@ApiOperation("新增设备模板")
|
||||||
@ApiImplicitParam(name = "csDevModelAddParm", value = "新增设备模板参数", required = true)
|
@ApiImplicitParam(name = "csDevModelAddParm", value = "新增设备模板参数", required = true)
|
||||||
|
@Deprecated
|
||||||
public HttpResult<CsDevModelPO> addDevModel(@RequestBody @Validated CsDevModelAddParm csDevModelAddParm){
|
public HttpResult<CsDevModelPO> addDevModel(@RequestBody @Validated CsDevModelAddParm csDevModelAddParm){
|
||||||
String methodDescribe = getMethodDescribe("addDevModel");
|
String methodDescribe = getMethodDescribe("addDevModel");
|
||||||
CsDevModelPO flag = csDevModelService.addDevModel (csDevModelAddParm);
|
CsDevModelPO flag = csDevModelService.addDevModel (csDevModelAddParm);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import com.njcn.csdevice.pojo.param.ProjectEquipmentQueryParm;
|
|||||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
import com.njcn.csdevice.pojo.vo.*;
|
import com.njcn.csdevice.pojo.vo.*;
|
||||||
import com.njcn.csdevice.service.CsEquipmentDeliveryService;
|
import com.njcn.csdevice.service.CsEquipmentDeliveryService;
|
||||||
|
import com.njcn.csdevice.service.IMqttUserService;
|
||||||
import com.njcn.web.controller.BaseController;
|
import com.njcn.web.controller.BaseController;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
@@ -43,6 +44,8 @@ public class EquipmentDeliveryController extends BaseController {
|
|||||||
|
|
||||||
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
|
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||||
|
|
||||||
|
private final IMqttUserService mqttUserService;
|
||||||
|
|
||||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||||
@PostMapping("/addEquipmentDelivery")
|
@PostMapping("/addEquipmentDelivery")
|
||||||
@ApiOperation("新增出厂设备")
|
@ApiOperation("新增出厂设备")
|
||||||
@@ -50,6 +53,10 @@ public class EquipmentDeliveryController extends BaseController {
|
|||||||
public HttpResult<Boolean> addEquipmentDelivery(@RequestBody @Validated CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm){
|
public HttpResult<Boolean> addEquipmentDelivery(@RequestBody @Validated CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm){
|
||||||
String methodDescribe = getMethodDescribe("addEquipmentDelivery");
|
String methodDescribe = getMethodDescribe("addEquipmentDelivery");
|
||||||
Boolean flag = csEquipmentDeliveryService.save (csEquipmentDeliveryAddParm);
|
Boolean flag = csEquipmentDeliveryService.save (csEquipmentDeliveryAddParm);
|
||||||
|
if (flag){
|
||||||
|
//初始化装置mqtt连接信息(使用sha256加密)
|
||||||
|
mqttUserService.insertMqttUser(csEquipmentDeliveryAddParm.getNdid());
|
||||||
|
}
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.njcn.csdevice.controller.equipment;
|
||||||
|
|
||||||
|
|
||||||
|
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.csdevice.pojo.param.CsDevModelAddParm;
|
||||||
|
import com.njcn.csdevice.pojo.po.CsDevModelPO;
|
||||||
|
import com.njcn.csdevice.service.IMqttUserService;
|
||||||
|
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;
|
||||||
|
import com.njcn.web.controller.BaseController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @since 2023-06-29
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/mqttUser")
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "MqttUser录入")
|
||||||
|
public class MqttUserController extends BaseController {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.njcn.csdevice.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.njcn.csdevice.pojo.po.MqttUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Mapper 接口
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @since 2023-06-29
|
||||||
|
*/
|
||||||
|
public interface MqttUserMapper extends BaseMapper<MqttUser> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?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.njcn.csdevice.mapper.MqttUserMapper">
|
||||||
|
|
||||||
|
|
||||||
|
</mapper>
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.njcn.csdevice.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.njcn.csdevice.pojo.po.MqttUser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @since 2023-06-29
|
||||||
|
*/
|
||||||
|
public interface IMqttUserService extends IService<MqttUser> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据密码生成mqtt连接信息
|
||||||
|
* @param password
|
||||||
|
*/
|
||||||
|
void insertMqttUser(String password);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -61,6 +61,8 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
|||||||
|
|
||||||
private final ICsLedgerService csLedgerService;
|
private final ICsLedgerService csLedgerService;
|
||||||
|
|
||||||
|
private final IMqttUserService mqttUserService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public Boolean save(CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm) {
|
public Boolean save(CsEquipmentDeliveryAddParm csEquipmentDeliveryAddParm) {
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.njcn.csdevice.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
|
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njcn.csdevice.mapper.MqttUserMapper;
|
||||||
|
import com.njcn.csdevice.pojo.po.MqttUser;
|
||||||
|
import com.njcn.csdevice.service.IMqttUserService;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 服务实现类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author xuyang
|
||||||
|
* @since 2023-06-29
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
@DS("mqtt")
|
||||||
|
public class MqttUserServiceImpl extends ServiceImpl<MqttUserMapper, MqttUser> implements IMqttUserService {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void insertMqttUser(String password) {
|
||||||
|
Random r = new Random();
|
||||||
|
MqttUser mqttUser = new MqttUser();
|
||||||
|
mqttUser.setId(1000000000 + (int)(r.nextDouble() * 999999999));
|
||||||
|
mqttUser.setUsername(password);
|
||||||
|
mqttUser.setSalt("mqtt");
|
||||||
|
mqttUser.setIsSuperuser(1);
|
||||||
|
mqttUser.setPassword(DigestUtil.sha256Hex(password + "mqtt"));
|
||||||
|
this.save(mqttUser);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,6 +92,11 @@
|
|||||||
<version>1.0.0</version>
|
<version>1.0.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>dynamic-datasource-spring-boot-starter</artifactId>
|
||||||
|
<version>3.5.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
Reference in New Issue
Block a user