mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 17:35:54 +08:00
+f;新增授权码功能
1、产品表添加 is_authorize 是否启用授权码字段; 2、产品授权码功能:基础增删改查、批量生成授权码、绑定设备。
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user