mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-17 08:25:53 +08:00
+f;新增授权码功能
1、产品表添加 is_authorize 是否启用授权码字段; 2、产品授权码功能:基础增删改查、批量生成授权码、绑定设备。
This commit is contained in:
19
springboot/sql/update/is_authorize_update.sql
Normal file
19
springboot/sql/update/is_authorize_update.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
ALTER TABLE `iot_product`
|
||||
ADD COLUMN `is_authorize` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否启用授权码(0-否,1-是)' AFTER `is_sys`;
|
||||
|
||||
CREATE TABLE `iot_product_authorize` (
|
||||
`authorize_id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '授权码ID',
|
||||
`authorize_code` varchar(32) NOT NULL COMMENT '授权码',
|
||||
`product_id` bigint NOT NULL COMMENT '产品ID',
|
||||
`device_id` bigint NULL COMMENT '设备ID',
|
||||
`serial_number` varchar(64) NULL COMMENT '设备编号',
|
||||
`user_id` bigint NULL COMMENT '用户ID',
|
||||
`user_name` varchar(30) NULL COMMENT '用户名称',
|
||||
`del_flag` char(1) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '0' COMMENT '删除标志(0代表存在 2代表删除)',
|
||||
`create_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '创建者',
|
||||
`create_time` datetime NOT NULL COMMENT '创建时间',
|
||||
`update_by` varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT '' COMMENT '更新者',
|
||||
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
|
||||
`remark` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '备注',
|
||||
PRIMARY KEY (`authorize_id`)
|
||||
) COMMENT = '产品授权码表';
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.ruoyi.iot.controller;
|
||||
|
||||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.ruoyi.iot.model.ProductAuthorizeVO;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.ruoyi.common.annotation.Log;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.enums.BusinessType;
|
||||
import com.ruoyi.iot.domain.ProductAuthorize;
|
||||
import com.ruoyi.iot.service.IProductAuthorizeService;
|
||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
|
||||
/**
|
||||
* 产品授权码Controller
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/iot/authorize")
|
||||
public class ProductAuthorizeController extends BaseController
|
||||
{
|
||||
@Autowired
|
||||
private IProductAuthorizeService productAuthorizeService;
|
||||
|
||||
/**
|
||||
* 查询产品授权码列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(ProductAuthorize productAuthorize)
|
||||
{
|
||||
startPage();
|
||||
List<ProductAuthorize> list = productAuthorizeService.selectProductAuthorizeList(productAuthorize);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出产品授权码列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:export')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, ProductAuthorize productAuthorize)
|
||||
{
|
||||
List<ProductAuthorize> list = productAuthorizeService.selectProductAuthorizeList(productAuthorize);
|
||||
ExcelUtil<ProductAuthorize> util = new ExcelUtil<ProductAuthorize>(ProductAuthorize.class);
|
||||
util.exportExcel(response, list, "产品授权码数据");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取产品授权码详细信息
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:query')")
|
||||
@GetMapping(value = "/{authorizeId}")
|
||||
public AjaxResult getInfo(@PathVariable("authorizeId") Long authorizeId)
|
||||
{
|
||||
return AjaxResult.success(productAuthorizeService.selectProductAuthorizeByAuthorizeId(authorizeId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品授权码
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:add')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody ProductAuthorize productAuthorize)
|
||||
{
|
||||
return toAjax(productAuthorizeService.insertProductAuthorize(productAuthorize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数量批量新增产品授权码
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:add')")
|
||||
@Log(title = "根据数量批量新增产品授权码", businessType = BusinessType.INSERT)
|
||||
@PostMapping("addProductAuthorizeByNum")
|
||||
public AjaxResult addProductAuthorizeByNum(@RequestBody ProductAuthorizeVO productAuthorizeVO)
|
||||
{
|
||||
return toAjax(productAuthorizeService.addProductAuthorizeByNum(productAuthorizeVO));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品授权码
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:edit')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public AjaxResult edit(@RequestBody ProductAuthorize productAuthorize)
|
||||
{
|
||||
return toAjax(productAuthorizeService.updateProductAuthorize(productAuthorize));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品授权码
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('iot:authorize:remove')")
|
||||
@Log(title = "产品授权码", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{authorizeIds}")
|
||||
public AjaxResult remove(@PathVariable Long[] authorizeIds)
|
||||
{
|
||||
return toAjax(productAuthorizeService.deleteProductAuthorizeByAuthorizeIds(authorizeIds));
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.file.FileUploadUtils;
|
||||
import com.ruoyi.common.utils.file.FileUtils;
|
||||
import com.ruoyi.iot.domain.Device;
|
||||
import com.ruoyi.iot.domain.ProductAuthorize;
|
||||
import com.ruoyi.iot.model.AuthenticateInputModel;
|
||||
import com.ruoyi.iot.model.DeviceAuthenticateModel;
|
||||
import com.ruoyi.iot.model.MqttClientConnectModel;
|
||||
@@ -24,6 +25,7 @@ import com.ruoyi.iot.model.ThingsModels.ThingsModelShadow;
|
||||
import com.ruoyi.iot.mqtt.EmqxService;
|
||||
import com.ruoyi.iot.mqtt.MqttConfig;
|
||||
import com.ruoyi.iot.service.IDeviceService;
|
||||
import com.ruoyi.iot.service.IProductAuthorizeService;
|
||||
import com.ruoyi.iot.service.IToolService;
|
||||
import com.ruoyi.iot.service.impl.ThingsModelServiceImpl;
|
||||
import com.ruoyi.iot.util.AESUtils;
|
||||
@@ -77,6 +79,8 @@ public class ToolController extends BaseController {
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
private IProductAuthorizeService authorizeService;
|
||||
|
||||
@Autowired
|
||||
private ThingsModelServiceImpl thingsModelService;
|
||||
|
||||
@@ -139,6 +143,8 @@ public class ToolController extends BaseController {
|
||||
Device device = deviceService.selectShortDeviceBySerialNumber(deviceNum);
|
||||
if (device !=null && mqttConfig.getusername().equals(username) && mqttConfig.getpassword().equals(password)) {
|
||||
System.out.println("-----------认证成功,clientId:" + clientid + "---------------");
|
||||
ProductAuthorize authorize = new ProductAuthorize(null, device.getProductId(), device.getDeviceId(), device.getSerialNumber(), 1L, "admin");
|
||||
authorizeService.boundProductAuthorize(authorize);
|
||||
return ResponseEntity.ok().body("ok");
|
||||
}
|
||||
return returnUnauthorized(clientid, username, password, "认证信息有误");
|
||||
@@ -172,12 +178,16 @@ public class ToolController extends BaseController {
|
||||
// 设备状态验证 (1-未激活,2-禁用,3-在线,4-离线)
|
||||
if (model.getDeviceId() != null && model.getDeviceId() != 0 && model.getStatus() != 2) {
|
||||
System.out.println("-----------认证成功,clientId:" + clientid + "---------------");
|
||||
ProductAuthorize authorize = new ProductAuthorize(null, model.getProductId(), model.getDeviceId(), model.getSerialNumber(), 1L, "admin");
|
||||
authorizeService.boundProductAuthorize(authorize);
|
||||
return ResponseEntity.ok().body("ok");
|
||||
} else {
|
||||
// 自动添加设备
|
||||
int result = deviceService.insertDeviceAuto(deviceNum, userId, productId);
|
||||
if (result == 1) {
|
||||
System.out.println("-----------认证成功,clientId:" + clientid + "---------------");
|
||||
ProductAuthorize authorize = new ProductAuthorize(null, model.getProductId(), model.getDeviceId(), model.getSerialNumber(), 1L, "admin");
|
||||
authorizeService.boundProductAuthorize(authorize);
|
||||
return ResponseEntity.ok().body("ok");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ public class Product extends BaseEntity
|
||||
@Excel(name = "是否系统通用", readConverterExp = "0=-否,1-是")
|
||||
private Integer isSys;
|
||||
|
||||
/** 是否启用授权码(0-否,1-是) */
|
||||
@Excel(name = "是否启用授权码", readConverterExp = "0=-否,1-是")
|
||||
private Integer isAuthorize;
|
||||
|
||||
/** mqtt账号 */
|
||||
private String mqttAccount;
|
||||
|
||||
@@ -164,6 +168,9 @@ public class Product extends BaseEntity
|
||||
return isSys;
|
||||
}
|
||||
|
||||
public void setIsAuthorize(Integer isAuthorize) {this.isAuthorize = isAuthorize;}
|
||||
public Integer getIsAuthorize() {return isAuthorize;}
|
||||
|
||||
public void setMqttAccount(String mqttAccount)
|
||||
{
|
||||
this.mqttAccount = mqttAccount;
|
||||
@@ -238,6 +245,7 @@ public class Product extends BaseEntity
|
||||
.append("tenantId", getTenantId())
|
||||
.append("tenantName", getTenantName())
|
||||
.append("isSys", getIsSys())
|
||||
.append("isAuthorize", getIsAuthorize())
|
||||
.append("status", getStatus())
|
||||
.append("deviceType", getDeviceType())
|
||||
.append("networkMethod", getNetworkMethod())
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.ruoyi.iot.domain;
|
||||
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
|
||||
/**
|
||||
* 产品授权码对象 iot_product_authorize
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
public class ProductAuthorize extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 授权码ID */
|
||||
private Long authorizeId;
|
||||
|
||||
/** 授权码 */
|
||||
@Excel(name = "授权码")
|
||||
private String authorizeCode;
|
||||
|
||||
/** 产品ID */
|
||||
@Excel(name = "产品ID")
|
||||
private Long productId;
|
||||
|
||||
/** 设备ID */
|
||||
@Excel(name = "设备ID")
|
||||
private Long deviceId;
|
||||
|
||||
/** 设备编号 */
|
||||
@Excel(name = "设备编号")
|
||||
private String serialNumber;
|
||||
|
||||
/** 用户ID */
|
||||
@Excel(name = "用户ID")
|
||||
private Long userId;
|
||||
|
||||
/** 用户名称 */
|
||||
@Excel(name = "用户名称")
|
||||
private String userName;
|
||||
|
||||
/** 删除标志(0代表存在 2代表删除) */
|
||||
private String delFlag;
|
||||
|
||||
public ProductAuthorize() {
|
||||
}
|
||||
|
||||
public ProductAuthorize(String authorizeCode, Long productId, Long deviceId, String serialNumber, Long userId, String userName) {
|
||||
this.authorizeCode = authorizeCode;
|
||||
this.productId = productId;
|
||||
this.deviceId = deviceId;
|
||||
this.serialNumber = serialNumber;
|
||||
this.userId = userId;
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public void setAuthorizeId(Long authorizeId)
|
||||
{
|
||||
this.authorizeId = authorizeId;
|
||||
}
|
||||
|
||||
public Long getAuthorizeId()
|
||||
{
|
||||
return authorizeId;
|
||||
}
|
||||
public void setAuthorizeCode(String authorizeCode)
|
||||
{
|
||||
this.authorizeCode = authorizeCode;
|
||||
}
|
||||
|
||||
public String getAuthorizeCode()
|
||||
{
|
||||
return authorizeCode;
|
||||
}
|
||||
public void setProductId(Long productId)
|
||||
{
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public Long getProductId()
|
||||
{
|
||||
return productId;
|
||||
}
|
||||
public void setDeviceId(Long deviceId)
|
||||
{
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public Long getDeviceId()
|
||||
{
|
||||
return deviceId;
|
||||
}
|
||||
public void setSerialNumber(String serialNumber)
|
||||
{
|
||||
this.serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
public String getSerialNumber()
|
||||
{
|
||||
return serialNumber;
|
||||
}
|
||||
public void setUserId(Long userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public Long getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
public void setUserName(String userName)
|
||||
{
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getUserName()
|
||||
{
|
||||
return userName;
|
||||
}
|
||||
public void setDelFlag(String delFlag)
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("authorizeId", getAuthorizeId())
|
||||
.append("authorizeCode", getAuthorizeCode())
|
||||
.append("productId", getProductId())
|
||||
.append("deviceId", getDeviceId())
|
||||
.append("serialNumber", getSerialNumber())
|
||||
.append("userId", getUserId())
|
||||
.append("userName", getUserName())
|
||||
.append("delFlag", getDelFlag())
|
||||
.append("createBy", getCreateBy())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateBy", getUpdateBy())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("remark", getRemark())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.ruoyi.iot.mapper;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.ProductAuthorize;
|
||||
|
||||
/**
|
||||
* 产品授权码Mapper接口
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
public interface ProductAuthorizeMapper
|
||||
{
|
||||
/**
|
||||
* 查询产品授权码
|
||||
*
|
||||
* @param authorizeId 产品授权码主键
|
||||
* @return 产品授权码
|
||||
*/
|
||||
public ProductAuthorize selectProductAuthorizeByAuthorizeId(Long authorizeId);
|
||||
|
||||
/**
|
||||
* 查询产品授权码列表
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 产品授权码集合
|
||||
*/
|
||||
public List<ProductAuthorize> selectProductAuthorizeList(ProductAuthorize productAuthorize);
|
||||
|
||||
/**
|
||||
* 新增产品授权码
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertProductAuthorize(ProductAuthorize productAuthorize);
|
||||
|
||||
/**
|
||||
* 修改产品授权码
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateProductAuthorize(ProductAuthorize productAuthorize);
|
||||
|
||||
/**
|
||||
* 删除产品授权码
|
||||
*
|
||||
* @param authorizeId 产品授权码主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductAuthorizeByAuthorizeId(Long authorizeId);
|
||||
|
||||
/**
|
||||
* 批量删除产品授权码
|
||||
*
|
||||
* @param authorizeIds 需要删除的数据主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductAuthorizeByAuthorizeIds(Long[] authorizeIds);
|
||||
|
||||
/**
|
||||
* 批量新增产品授权码
|
||||
* @param list
|
||||
* @return
|
||||
*/
|
||||
public int insertBatchAuthorize(List<ProductAuthorize> list);
|
||||
|
||||
/**
|
||||
* 根据产品id查询一条未绑定的授权码
|
||||
* @param authorize
|
||||
* @return
|
||||
*/
|
||||
ProductAuthorize selectOneUnboundAuthorizeByProductId(ProductAuthorize authorize);
|
||||
|
||||
/**
|
||||
* 根据授权码查询一条未绑定的授权码
|
||||
* @param authorize
|
||||
* @return
|
||||
*/
|
||||
ProductAuthorize selectOneUnboundAuthorizeByAuthorizeCode(ProductAuthorize authorize);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.ruoyi.iot.model;
|
||||
|
||||
/**
|
||||
* 批量新增产品授权码VO
|
||||
*
|
||||
* @author Venus Zhang
|
||||
* @create 2022-04-11 15:04
|
||||
*/
|
||||
|
||||
public class ProductAuthorizeVO {
|
||||
|
||||
private Long productId;
|
||||
private int createNum;
|
||||
|
||||
public Long getProductId() {
|
||||
return productId;
|
||||
}
|
||||
|
||||
public void setProductId(Long productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
public int getCreateNum() {
|
||||
return createNum;
|
||||
}
|
||||
|
||||
public void setCreateNum(int createNum) {
|
||||
this.createNum = createNum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.ruoyi.iot.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.iot.domain.ProductAuthorize;
|
||||
import com.ruoyi.iot.model.ProductAuthorizeVO;
|
||||
|
||||
/**
|
||||
* 产品授权码Service接口
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
public interface IProductAuthorizeService
|
||||
{
|
||||
/**
|
||||
* 查询产品授权码
|
||||
*
|
||||
* @param authorizeId 产品授权码主键
|
||||
* @return 产品授权码
|
||||
*/
|
||||
public ProductAuthorize selectProductAuthorizeByAuthorizeId(Long authorizeId);
|
||||
|
||||
/**
|
||||
* 查询产品授权码列表
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 产品授权码集合
|
||||
*/
|
||||
public List<ProductAuthorize> selectProductAuthorizeList(ProductAuthorize productAuthorize);
|
||||
|
||||
/**
|
||||
* 新增产品授权码
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertProductAuthorize(ProductAuthorize productAuthorize);
|
||||
|
||||
/**
|
||||
* 修改产品授权码
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateProductAuthorize(ProductAuthorize productAuthorize);
|
||||
|
||||
/**
|
||||
* 批量删除产品授权码
|
||||
*
|
||||
* @param authorizeIds 需要删除的产品授权码主键集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductAuthorizeByAuthorizeIds(Long[] authorizeIds);
|
||||
|
||||
/**
|
||||
* 删除产品授权码信息
|
||||
*
|
||||
* @param authorizeId 产品授权码主键
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteProductAuthorizeByAuthorizeId(Long authorizeId);
|
||||
|
||||
/**
|
||||
* 根据数量批量新增产品授权码
|
||||
* @param productAuthorizeVO
|
||||
* @return
|
||||
*/
|
||||
public int addProductAuthorizeByNum(ProductAuthorizeVO productAuthorizeVO);
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品id和设备序列号绑定授权码
|
||||
* @param productAuthorize
|
||||
* @return
|
||||
*/
|
||||
public int boundProductAuthorize(ProductAuthorize productAuthorize);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
package com.ruoyi.iot.service.impl;
|
||||
|
||||
import com.ruoyi.common.constant.HttpStatus;
|
||||
import com.ruoyi.common.core.domain.entity.SysUser;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||
import com.ruoyi.iot.domain.ProductAuthorize;
|
||||
import com.ruoyi.iot.mapper.ProductAuthorizeMapper;
|
||||
import com.ruoyi.iot.model.ProductAuthorizeVO;
|
||||
import com.ruoyi.iot.service.IProductAuthorizeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.ruoyi.common.utils.SecurityUtils.getLoginUser;
|
||||
|
||||
/**
|
||||
* 产品授权码Service业务层处理
|
||||
*
|
||||
* @author kami
|
||||
* @date 2022-04-11
|
||||
*/
|
||||
@Service
|
||||
public class ProductAuthorizeServiceImpl implements IProductAuthorizeService
|
||||
{
|
||||
@Autowired
|
||||
private ProductAuthorizeMapper productAuthorizeMapper;
|
||||
|
||||
/**
|
||||
* 查询产品授权码
|
||||
*
|
||||
* @param authorizeId 产品授权码主键
|
||||
* @return 产品授权码
|
||||
*/
|
||||
@Override
|
||||
public ProductAuthorize selectProductAuthorizeByAuthorizeId(Long authorizeId)
|
||||
{
|
||||
return productAuthorizeMapper.selectProductAuthorizeByAuthorizeId(authorizeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询产品授权码列表
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 产品授权码
|
||||
*/
|
||||
@Override
|
||||
public List<ProductAuthorize> selectProductAuthorizeList(ProductAuthorize productAuthorize)
|
||||
{
|
||||
return productAuthorizeMapper.selectProductAuthorizeList(productAuthorize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增产品授权码
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int insertProductAuthorize(ProductAuthorize productAuthorize)
|
||||
{
|
||||
productAuthorize.setCreateTime(DateUtils.getNowDate());
|
||||
return productAuthorizeMapper.insertProductAuthorize(productAuthorize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改产品授权码
|
||||
*
|
||||
* @param productAuthorize 产品授权码
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int updateProductAuthorize(ProductAuthorize productAuthorize)
|
||||
{
|
||||
productAuthorize.setUpdateTime(DateUtils.getNowDate());
|
||||
return productAuthorizeMapper.updateProductAuthorize(productAuthorize);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除产品授权码
|
||||
*
|
||||
* @param authorizeIds 需要删除的产品授权码主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteProductAuthorizeByAuthorizeIds(Long[] authorizeIds)
|
||||
{
|
||||
return productAuthorizeMapper.deleteProductAuthorizeByAuthorizeIds(authorizeIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除产品授权码信息
|
||||
*
|
||||
* @param authorizeId 产品授权码主键
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
public int deleteProductAuthorizeByAuthorizeId(Long authorizeId)
|
||||
{
|
||||
return productAuthorizeMapper.deleteProductAuthorizeByAuthorizeId(authorizeId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据数量批量新增产品授权码
|
||||
* @param productAuthorizeVO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int addProductAuthorizeByNum(ProductAuthorizeVO productAuthorizeVO) {
|
||||
Long productId = productAuthorizeVO.getProductId();
|
||||
int createNum = productAuthorizeVO.getCreateNum();
|
||||
List<ProductAuthorize> list = new ArrayList<>(createNum);
|
||||
SysUser user = getLoginUser().getUser();
|
||||
for (int i = 0; i < createNum; i++) {
|
||||
ProductAuthorize authorize = new ProductAuthorize();
|
||||
authorize.setProductId(productId);
|
||||
authorize.setCreateBy(user.getUserName());
|
||||
authorize.setCreateTime(DateUtils.getNowDate());
|
||||
authorize.setAuthorizeCode(IdUtils.fastSimpleUUID().toUpperCase());
|
||||
list.add(authorize);
|
||||
}
|
||||
return productAuthorizeMapper.insertBatchAuthorize(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据产品id和设备序列号绑定授权码
|
||||
*
|
||||
* @param productAuthorize
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public int boundProductAuthorize(ProductAuthorize productAuthorize){
|
||||
ProductAuthorize authorize = null;
|
||||
if(StringUtils.isEmpty(productAuthorize.getAuthorizeCode())){
|
||||
//TODO-kami: 2022/4/11 13:34 后期无需查询,硬件调用直接传入参数,可以删除
|
||||
authorize = productAuthorizeMapper.selectOneUnboundAuthorizeByProductId(productAuthorize);
|
||||
productAuthorize.setAuthorizeCode(authorize.getAuthorizeCode());
|
||||
}else {
|
||||
authorize = productAuthorizeMapper.selectOneUnboundAuthorizeByAuthorizeCode(productAuthorize);
|
||||
}
|
||||
if (authorize == null){
|
||||
throw new ServiceException("授权码数据异常", HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
productAuthorize.setAuthorizeId(authorize.getAuthorizeId());
|
||||
productAuthorize.setUpdateTime(DateUtils.getNowDate());
|
||||
return productAuthorizeMapper.updateProductAuthorize(productAuthorize);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?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.ruoyi.iot.mapper.ProductAuthorizeMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.iot.domain.ProductAuthorize" id="ProductAuthorizeResult">
|
||||
<result property="authorizeId" column="authorize_id" />
|
||||
<result property="authorizeCode" column="authorize_code" />
|
||||
<result property="productId" column="product_id" />
|
||||
<result property="deviceId" column="device_id" />
|
||||
<result property="serialNumber" column="serial_number" />
|
||||
<result property="userId" column="user_id" />
|
||||
<result property="userName" column="user_name" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectProductAuthorizeVo">
|
||||
select authorize_id, authorize_code, product_id, device_id, serial_number, user_id, user_name, del_flag, create_by, create_time, update_by, update_time, remark from iot_product_authorize
|
||||
</sql>
|
||||
|
||||
<select id="selectProductAuthorizeList" parameterType="com.ruoyi.iot.domain.ProductAuthorize" resultMap="ProductAuthorizeResult">
|
||||
<include refid="selectProductAuthorizeVo"/>
|
||||
<where>
|
||||
<if test="authorizeCode != null and authorizeCode != ''"> and authorize_code = #{authorizeCode}</if>
|
||||
<if test="productId != null "> and product_id = #{productId}</if>
|
||||
<if test="deviceId != null "> and device_id = #{deviceId}</if>
|
||||
<if test="serialNumber != null and serialNumber != ''"> and serial_number = #{serialNumber}</if>
|
||||
<if test="userId != null "> and user_id = #{userId}</if>
|
||||
<if test="userName != null and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
|
||||
</where>
|
||||
order by
|
||||
device_id desc
|
||||
</select>
|
||||
|
||||
<select id="selectProductAuthorizeByAuthorizeId" parameterType="Long" resultMap="ProductAuthorizeResult">
|
||||
<include refid="selectProductAuthorizeVo"/>
|
||||
where authorize_id = #{authorizeId}
|
||||
</select>
|
||||
<select id="selectOneUnboundAuthorizeByProductId" parameterType="com.ruoyi.iot.domain.ProductAuthorize" resultType="com.ruoyi.iot.domain.ProductAuthorize">
|
||||
<include refid="selectProductAuthorizeVo"/>
|
||||
where
|
||||
del_flag = 0
|
||||
and product_id = #{productId}
|
||||
and serial_number is null
|
||||
and device_id is null
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<select id="selectOneUnboundAuthorizeByAuthorizeCode" parameterType="com.ruoyi.iot.domain.ProductAuthorize" resultType="com.ruoyi.iot.domain.ProductAuthorize">
|
||||
<include refid="selectProductAuthorizeVo"/>
|
||||
where
|
||||
del_flag = 0
|
||||
and authorize_code = #{authorizeCode}
|
||||
and serial_number is null
|
||||
and device_id is null
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="insertProductAuthorize" parameterType="com.ruoyi.iot.domain.ProductAuthorize">
|
||||
insert into iot_product_authorize
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="authorizeCode != null and authorizeCode != ''">authorize_code,</if>
|
||||
<if test="productId != null">product_id,</if>
|
||||
<if test="deviceId != null">device_id,</if>
|
||||
<if test="serialNumber != null">serial_number,</if>
|
||||
<if test="userId != null">user_id,</if>
|
||||
<if test="userName != null">user_name,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="authorizeCode != null and authorizeCode != ''">#{authorizeCode},</if>
|
||||
<if test="productId != null">#{productId},</if>
|
||||
<if test="deviceId != null">#{deviceId},</if>
|
||||
<if test="serialNumber != null">#{serialNumber},</if>
|
||||
<if test="userId != null">#{userId},</if>
|
||||
<if test="userName != null">#{userName},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
<insert id="insertBatchAuthorize" parameterType="com.ruoyi.iot.domain.ProductAuthorize" useGeneratedKeys="true" keyProperty="authorizeId">
|
||||
insert into iot_product_authorize (authorize_code,product_id,create_by,create_time)
|
||||
values
|
||||
<foreach item="item" collection="list" separator=",">
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
#{item.authorizeCode},#{item.productId},#{item.createBy},#{item.createTime}
|
||||
</trim>
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<update id="updateProductAuthorize" parameterType="com.ruoyi.iot.domain.ProductAuthorize">
|
||||
update iot_product_authorize
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
user_id = #{userId},
|
||||
device_id = #{deviceId},
|
||||
<if test="authorizeCode != null and authorizeCode != ''">authorize_code = #{authorizeCode},</if>
|
||||
<if test="productId != null">product_id = #{productId},</if>
|
||||
<if test="serialNumber != null">serial_number = #{serialNumber},</if>
|
||||
<if test="userName != null">user_name = #{userName},</if>
|
||||
<if test="delFlag != null and delFlag != ''">del_flag = #{delFlag},</if>
|
||||
<if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
</trim>
|
||||
where authorize_id = #{authorizeId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteProductAuthorizeByAuthorizeId" parameterType="Long">
|
||||
delete from iot_product_authorize where authorize_id = #{authorizeId}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteProductAuthorizeByAuthorizeIds" parameterType="String">
|
||||
delete from iot_product_authorize where authorize_id in
|
||||
<foreach item="authorizeId" collection="array" open="(" separator="," close=")">
|
||||
#{authorizeId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
@@ -12,6 +12,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="tenantId" column="tenant_id" />
|
||||
<result property="tenantName" column="tenant_name" />
|
||||
<result property="isSys" column="is_sys" />
|
||||
<result property="isAuthorize" column="is_authorize" />
|
||||
<result property="mqttAccount" column="mqtt_account" />
|
||||
<result property="mqttPassword" column="mqtt_password" />
|
||||
<result property="mqttSecret" column="mqtt_secret" />
|
||||
@@ -31,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectProductVo">
|
||||
select product_id, product_name, category_id, category_name, tenant_id, tenant_name, is_sys,mqtt_account,mqtt_password,mqtt_secret ,status, device_type, network_method, vertificate_method, create_time, update_time, img_url,remark from iot_product
|
||||
select product_id, product_name, category_id, category_name, tenant_id, tenant_name, is_sys, is_authorize, mqtt_account,mqtt_password,mqtt_secret ,status, device_type, network_method, vertificate_method, create_time, update_time, img_url,remark from iot_product
|
||||
</sql>
|
||||
|
||||
<select id="selectProductList" parameterType="com.ruoyi.iot.domain.Product" resultMap="ProductResult">
|
||||
@@ -43,6 +44,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tenantId != null "> and tenant_id = #{tenantId}</if>
|
||||
<if test="tenantName != null and tenantName != ''"> and tenant_name like concat('%', #{tenantName}, '%')</if>
|
||||
<if test="isSys != null "> and is_sys = #{isSys}</if>
|
||||
<if test="isAuthorize != null "> and is_authorize = #{isAuthorize}</if>
|
||||
<if test="status != null "> and status = #{status}</if>
|
||||
<if test="deviceType != null "> and device_type = #{deviceType}</if>
|
||||
<if test="networkMethod != null "> and network_method = #{networkMethod}</if>
|
||||
@@ -70,6 +72,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tenantId != null">tenant_id,</if>
|
||||
<if test="tenantName != null and tenantName != ''">tenant_name,</if>
|
||||
<if test="isSys != null">is_sys,</if>
|
||||
<if test="isAuthorize != null">is_authorize,</if>
|
||||
<if test="mqttAccount != null and mqttAccount != ''">mqtt_account,</if>
|
||||
<if test="mqttPassword != null and mqttPassword != ''">mqtt_password,</if>
|
||||
<if test="mqttSecret != null and mqttSecret != ''">mqtt_secret,</if>
|
||||
@@ -92,6 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tenantId != null">#{tenantId},</if>
|
||||
<if test="tenantName != null and tenantName != ''">#{tenantName},</if>
|
||||
<if test="isSys != null">#{isSys},</if>
|
||||
<if test="isAuthorize != null">#{isAuthorize},</if>
|
||||
<if test="mqttAccount != null and mqttAccount != ''">#{mqttAccount},</if>
|
||||
<if test="mqttPassword != null and mqttPassword != ''">#{mqttPassword},</if>
|
||||
<if test="mqttSecret != null and mqttSecret != ''">#{mqttSecret},</if>
|
||||
@@ -118,6 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="tenantId != null">tenant_id = #{tenantId},</if>
|
||||
<if test="tenantName != null and tenantName != ''">tenant_name = #{tenantName},</if>
|
||||
<if test="isSys != null">is_sys = #{isSys},</if>
|
||||
<if test="isAuthorize != null">is_authorize = #{isAuthorize},</if>
|
||||
<if test="mqttAccount != null and mqttAccount != ''">mqtt_account = #{mqttAccount},</if>
|
||||
<if test="mqttPassword != null and mqttPassword != ''">mqtt_password = #{mqttPassword},</if>
|
||||
<if test="mqttSecret != null and mqttSecret != ''">mqtt_secret = #{mqttSecret},</if>
|
||||
|
||||
Reference in New Issue
Block a user