微调
This commit is contained in:
@@ -2,7 +2,7 @@ package com.njcn.gather.device.pojo.vo;
|
|||||||
|
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.njcn.gather.util.DeviceUtil;
|
import com.njcn.common.utils.EncryptionUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public class PreDetection {
|
|||||||
|
|
||||||
public String getDevKey() {
|
public String getDevKey() {
|
||||||
if (StrUtil.isNotBlank(devKey)) {
|
if (StrUtil.isNotBlank(devKey)) {
|
||||||
String key = DeviceUtil.decoderString(1, devKey);
|
String key = EncryptionUtil.decoderString(1, devKey);
|
||||||
if (StrUtil.isNotBlank(key)) {
|
if (StrUtil.isNotBlank(key)) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ public class PreDetection {
|
|||||||
|
|
||||||
public String getDevCode() {
|
public String getDevCode() {
|
||||||
if (StrUtil.isNotBlank(devCode)) {
|
if (StrUtil.isNotBlank(devCode)) {
|
||||||
String code = DeviceUtil.decoderString(1, devCode);
|
String code = EncryptionUtil.decoderString(1, devCode);
|
||||||
if (StrUtil.isNotBlank(code)) {
|
if (StrUtil.isNotBlank(code)) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
|||||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
import com.njcn.common.pojo.exception.BusinessException;
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
import com.njcn.common.pojo.poi.PullDown;
|
import com.njcn.common.pojo.poi.PullDown;
|
||||||
|
import com.njcn.common.utils.EncryptionUtil;
|
||||||
import com.njcn.db.mybatisplus.constant.DbConstant;
|
import com.njcn.db.mybatisplus.constant.DbConstant;
|
||||||
import com.njcn.gather.device.mapper.PqDevMapper;
|
import com.njcn.gather.device.mapper.PqDevMapper;
|
||||||
import com.njcn.gather.device.pojo.enums.*;
|
import com.njcn.gather.device.pojo.enums.*;
|
||||||
@@ -37,7 +38,6 @@ import com.njcn.gather.system.dictionary.service.IDictDataService;
|
|||||||
import com.njcn.gather.system.dictionary.service.IDictTypeService;
|
import com.njcn.gather.system.dictionary.service.IDictTypeService;
|
||||||
import com.njcn.gather.type.pojo.po.DevType;
|
import com.njcn.gather.type.pojo.po.DevType;
|
||||||
import com.njcn.gather.type.service.IDevTypeService;
|
import com.njcn.gather.type.service.IDevTypeService;
|
||||||
import com.njcn.gather.util.DeviceUtil;
|
|
||||||
import com.njcn.web.factory.PageFactory;
|
import com.njcn.web.factory.PageFactory;
|
||||||
import com.njcn.web.utils.ExcelUtil;
|
import com.njcn.web.utils.ExcelUtil;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -72,10 +72,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
Page<PqDev> page1 = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), this.getQueryWrapper(queryParam));
|
Page<PqDev> page1 = this.page(new Page<>(PageFactory.getPageNum(queryParam), PageFactory.getPageSize(queryParam)), this.getQueryWrapper(queryParam));
|
||||||
page1.getRecords().forEach(p -> {
|
page1.getRecords().forEach(p -> {
|
||||||
if (ObjectUtil.isNotNull(p.getSeries())) {
|
if (ObjectUtil.isNotNull(p.getSeries())) {
|
||||||
p.setSeries(DeviceUtil.decoderString(1, p.getSeries()));
|
p.setSeries(EncryptionUtil.decoderString(1, p.getSeries()));
|
||||||
}
|
}
|
||||||
if (ObjectUtil.isNotNull(p.getDevKey())) {
|
if (ObjectUtil.isNotNull(p.getDevKey())) {
|
||||||
p.setDevKey(DeviceUtil.decoderString(1, p.getDevKey()));
|
p.setDevKey(EncryptionUtil.decoderString(1, p.getDevKey()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -103,8 +103,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
BeanUtil.copyProperties(pqDevParam, pqDev);
|
BeanUtil.copyProperties(pqDevParam, pqDev);
|
||||||
if (pqDevParam.getEncryptionFlag() == 1) {
|
if (pqDevParam.getEncryptionFlag() == 1) {
|
||||||
if (StrUtil.isNotBlank(pqDevParam.getSeries()) && StrUtil.isNotBlank(pqDevParam.getDevKey())) {
|
if (StrUtil.isNotBlank(pqDevParam.getSeries()) && StrUtil.isNotBlank(pqDevParam.getDevKey())) {
|
||||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
||||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
pqDev.setDevKey(EncryptionUtil.encodeString(1, pqDev.getDevKey()));
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
||||||
}
|
}
|
||||||
@@ -137,8 +137,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
BeanUtil.copyProperties(updateParam, pqDev);
|
BeanUtil.copyProperties(updateParam, pqDev);
|
||||||
if (pqDev.getEncryptionFlag() == 1) {
|
if (pqDev.getEncryptionFlag() == 1) {
|
||||||
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
||||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
pqDev.setDevKey(EncryptionUtil.encodeString(1, pqDev.getDevKey()));
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
||||||
}
|
}
|
||||||
@@ -434,10 +434,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(pqDev.getSeries())) {
|
if (StrUtil.isNotBlank(pqDev.getSeries())) {
|
||||||
pqDev.setSeries(DeviceUtil.decoderString(1, pqDev.getSeries()));
|
pqDev.setSeries(EncryptionUtil.decoderString(1, pqDev.getSeries()));
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(pqDev.getDevKey())) {
|
if (StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||||
pqDev.setDevKey(DeviceUtil.decoderString(1, pqDev.getDevKey()));
|
pqDev.setDevKey(EncryptionUtil.decoderString(1, pqDev.getDevKey()));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -470,10 +470,10 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(pqDev.getSeries())) {
|
if (StrUtil.isNotBlank(pqDev.getSeries())) {
|
||||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(pqDev.getDevKey())) {
|
if (StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
pqDev.setDevKey(EncryptionUtil.encodeString(1, pqDev.getDevKey()));
|
||||||
}
|
}
|
||||||
pqDev.setState(DataStateEnum.ENABLE.getCode());
|
pqDev.setState(DataStateEnum.ENABLE.getCode());
|
||||||
pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
pqDev.setTimeCheckResult(TimeCheckResultEnum.UNKNOWN.getValue());
|
||||||
@@ -701,8 +701,8 @@ public class PqDevServiceImpl extends ServiceImpl<PqDevMapper, PqDev> implements
|
|||||||
|
|
||||||
if (pqDev.getEncryptionFlag() == 1) {
|
if (pqDev.getEncryptionFlag() == 1) {
|
||||||
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
if (StrUtil.isNotBlank(pqDev.getSeries()) && StrUtil.isNotBlank(pqDev.getDevKey())) {
|
||||||
pqDev.setSeries(DeviceUtil.encodeString(1, pqDev.getSeries()));
|
pqDev.setSeries(EncryptionUtil.encodeString(1, pqDev.getSeries()));
|
||||||
pqDev.setDevKey(DeviceUtil.encodeString(1, pqDev.getDevKey()));
|
pqDev.setDevKey(EncryptionUtil.encodeString(1, pqDev.getDevKey()));
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
throw new BusinessException(DevResponseEnum.SERIES_AND_DEVKEY_NOT_BLANK);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
package com.njcn.gather.util;
|
|
||||||
|
|
||||||
import com.njcn.common.utils.sm.Sm4Utils;
|
|
||||||
import com.njcn.common.utils.sm.ThreeDesUtil;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pqs
|
|
||||||
*
|
|
||||||
* @author cdf
|
|
||||||
* @date 2022/1/6
|
|
||||||
*/
|
|
||||||
public class DeviceUtil {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cd 系统配置的解密方式
|
|
||||||
* content 需要解密的内容
|
|
||||||
* 解密对应内容
|
|
||||||
*
|
|
||||||
* @author cdf
|
|
||||||
* @date 2021/10/12
|
|
||||||
*/
|
|
||||||
public static String decoderString(Integer cd, String content) {
|
|
||||||
String seriesTmp = null;
|
|
||||||
if (cd == 0) {
|
|
||||||
seriesTmp = Base64.decodeBase64(content).toString();
|
|
||||||
} else if (cd == 1) {
|
|
||||||
seriesTmp = ThreeDesUtil.decryptThreeDes(content);
|
|
||||||
} else if (cd == 2) {
|
|
||||||
//SM4加密密码
|
|
||||||
String secretkey = Sm4Utils.globalSecretKey;
|
|
||||||
Sm4Utils sm4 = new Sm4Utils(secretkey);
|
|
||||||
seriesTmp = sm4.decryptData_ECB(content);
|
|
||||||
}
|
|
||||||
return seriesTmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cd 系统配置的加密方式
|
|
||||||
* content 需要加密的内容
|
|
||||||
* 加密对应内容
|
|
||||||
*
|
|
||||||
* @author cdf
|
|
||||||
* @date 2021/10/12
|
|
||||||
*/
|
|
||||||
public static String encodeString(Integer cd, String content) {
|
|
||||||
String key = null;
|
|
||||||
if (cd == 0) {
|
|
||||||
key = Base64.encodeBase64String(content.getBytes());
|
|
||||||
} else if (cd == 1) {
|
|
||||||
key = ThreeDesUtil.encryptThreeDes(content);
|
|
||||||
} else if (cd == 2) {
|
|
||||||
//SM4加密密码
|
|
||||||
// String secretkey = Sm4Utils.globalSecretKey;
|
|
||||||
// Sm4Utils sm4 = new Sm4Utils(secretkey);
|
|
||||||
// key = sm4.encryptData_ECB(content);
|
|
||||||
}
|
|
||||||
return key;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -39,10 +39,10 @@ public class SysRegResController extends BaseController {
|
|||||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("查询注册版本列表")
|
@ApiOperation("查询注册版本列表")
|
||||||
public HttpResult<Map<String,SysRegResVO>> listRegRes() {
|
public HttpResult<SysRegResVO> listRegRes() {
|
||||||
String methodDescribe = getMethodDescribe("listRegRes");
|
String methodDescribe = getMethodDescribe("listRegRes");
|
||||||
LogUtil.njcnDebug(log, "{},查询参数为空", methodDescribe);
|
LogUtil.njcnDebug(log, "{},查询参数为空", methodDescribe);
|
||||||
Map<String,SysRegResVO> result = sysRegResService.listRegRes();
|
SysRegResVO result = sysRegResService.listRegRes();
|
||||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.njcn.gather.system.reg.pojo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2025-02-11
|
||||||
|
*/
|
||||||
|
public interface RegResValidMessage {
|
||||||
|
String CODE_NOT_BLANK="注册码不能为空";
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.njcn.gather.system.reg.pojo.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2025-02-11
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RegInfoData {
|
||||||
|
/**
|
||||||
|
* mac地址
|
||||||
|
*/
|
||||||
|
private String macAddress;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册模式
|
||||||
|
*/
|
||||||
|
private List<String> typeList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 到期日期
|
||||||
|
*/
|
||||||
|
private List<String> expireDateList;
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.njcn.gather.system.reg.pojo.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author caozehui
|
||||||
|
* @data 2025-02-11
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public enum RegResponseEnum {
|
||||||
|
|
||||||
|
GET_MAC_ADDRESS_FAILED("A005001", "获取本机MAC地址失败"),
|
||||||
|
REGISTRATION_CODE_FORMAT_ERROR("A005002", "注册码格式错误"),
|
||||||
|
MAC_ADDRESS_NOT_MATCH("A005003","注册码中的MAC地址与本机MAC地址不匹配"),
|
||||||
|
REGISTRATION_CODE_EXPIRED("A005004","注册码已过期"),;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
RegResponseEnum(String code, String message) {
|
||||||
|
this.message = message;
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.njcn.gather.system.reg.pojo.param;
|
|||||||
|
|
||||||
import com.njcn.common.pojo.constant.PatternRegex;
|
import com.njcn.common.pojo.constant.PatternRegex;
|
||||||
import com.njcn.gather.system.pojo.constant.SystemValidMessage;
|
import com.njcn.gather.system.pojo.constant.SystemValidMessage;
|
||||||
|
import com.njcn.gather.system.reg.pojo.RegResValidMessage;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
@@ -21,7 +22,7 @@ public class SysRegResParam {
|
|||||||
// private String type;
|
// private String type;
|
||||||
|
|
||||||
@ApiModelProperty("注册码")
|
@ApiModelProperty("注册码")
|
||||||
@NotBlank(message = SystemValidMessage.CODE_NOT_BLANK)
|
@NotBlank(message = RegResValidMessage.CODE_NOT_BLANK)
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
// @ApiModelProperty("密钥")
|
// @ApiModelProperty("密钥")
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ public class SysRegRes extends BaseEntity implements Serializable {
|
|||||||
/**
|
/**
|
||||||
* 到期时间
|
* 到期时间
|
||||||
*/
|
*/
|
||||||
private LocalDate expireDate;
|
// private LocalDate expireDate;
|
||||||
|
private String expireDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 录波数据有效组数
|
* 录波数据有效组数
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ package com.njcn.gather.system.reg.pojo.vo;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
* @data 2024-11-25
|
* @data 2024-11-25
|
||||||
@@ -13,8 +16,13 @@ public class SysRegResVO {
|
|||||||
*/
|
*/
|
||||||
private String code;
|
private String code;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册的模式
|
||||||
|
*/
|
||||||
|
private List<String> typeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 到期时间
|
* 到期时间
|
||||||
*/
|
*/
|
||||||
private String expireDate;
|
private List<String> expireDateList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,5 +37,5 @@ public interface ISysRegResService extends IService<SysRegRes> {
|
|||||||
* 查询版本注册表列表
|
* 查询版本注册表列表
|
||||||
* @return 版本注册信息
|
* @return 版本注册信息
|
||||||
*/
|
*/
|
||||||
Map<String,SysRegResVO> listRegRes();
|
SysRegResVO listRegRes();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,21 @@
|
|||||||
package com.njcn.gather.system.reg.service.impl;
|
package com.njcn.gather.system.reg.service.impl;
|
||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.net.NetUtil;
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
import com.njcn.common.pojo.enums.common.DataStateEnum;
|
||||||
|
import com.njcn.common.pojo.exception.BusinessException;
|
||||||
|
import com.njcn.common.utils.EncryptionUtil;
|
||||||
|
import com.njcn.common.utils.sm.Sm4Utils;
|
||||||
|
import com.njcn.gather.system.dictionary.pojo.enums.DictDataEnum;
|
||||||
|
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||||
|
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||||
|
import com.njcn.gather.system.dictionary.service.IDictTypeService;
|
||||||
import com.njcn.gather.system.reg.mapper.SysRegResMapper;
|
import com.njcn.gather.system.reg.mapper.SysRegResMapper;
|
||||||
|
import com.njcn.gather.system.reg.pojo.dto.RegInfoData;
|
||||||
|
import com.njcn.gather.system.reg.pojo.enums.RegResponseEnum;
|
||||||
import com.njcn.gather.system.reg.pojo.param.SysRegResParam;
|
import com.njcn.gather.system.reg.pojo.param.SysRegResParam;
|
||||||
import com.njcn.gather.system.reg.pojo.po.SysRegRes;
|
import com.njcn.gather.system.reg.pojo.po.SysRegRes;
|
||||||
import com.njcn.gather.system.reg.pojo.vo.SysRegResVO;
|
import com.njcn.gather.system.reg.pojo.vo.SysRegResVO;
|
||||||
@@ -13,8 +25,18 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import javax.crypto.Cipher;
|
||||||
import java.util.Map;
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.Key;
|
||||||
|
import java.security.KeyFactory;
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.PublicKey;
|
||||||
|
import java.security.spec.PKCS8EncodedKeySpec;
|
||||||
|
import java.security.spec.X509EncodedKeySpec;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author caozehui
|
* @author caozehui
|
||||||
@@ -24,6 +46,39 @@ import java.util.Map;
|
|||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes> implements ISysRegResService {
|
public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes> implements ISysRegResService {
|
||||||
|
/**
|
||||||
|
* 固定私钥
|
||||||
|
*/
|
||||||
|
private static final String fixedPrivateKeyStr = "-----BEGIN PRIVATE KEY-----\n" +
|
||||||
|
"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDTC6MQkjHAIyPQ\n" +
|
||||||
|
"12tfSBsmS12OspsmJORW2cf7s+xwe3lJ3nb9KohjAuRBG4jLceAXdZoCuk1+Xt8l\n" +
|
||||||
|
"kesXp930DWmb7SBHLa7imGgvIm/9hP7Y48yDJqM2Ia6CFbMCmLYCiU3oDLZ2DuUq\n" +
|
||||||
|
"QbE2j9QuTTMiOVHBy4M82XwkEXNfIQez9PB+Osex2X9FesyMoWvsoOcnDD8iWmbP\n" +
|
||||||
|
"Ag0syuutt4YkrU8IWC5v2vyTxb+N+F36wqbC8td1wOgUrf2K3kQtTe7xB1b3i5RI\n" +
|
||||||
|
"DAsjxPd1a3uzJVjJ7Onla+B4dkFGOSlX/w8/GJQzMgegskKEPRONyXRWCaVpBt9O\n" +
|
||||||
|
"6yDjKz7vAgMBAAECggEATnj+vowlnJRUXnSjM5AbrD8MwCEQSHwiPVsIHcLWkTKQ\n" +
|
||||||
|
"NFPYeaVFhk9OcRkcYc1rbj2nsQj2BJ2hKpaZzDd6c6NDGBvxSxYk95OE9bW/34wC\n" +
|
||||||
|
"uMHnSwLkYB3hBfSslbQTxVipk7WaaMZ8FpzLmIaddkP1Ve3rRPx3xXn2y3CDriRs\n" +
|
||||||
|
"WxVKm4+ri8Ncnk0dBqjEBNwgdsvRlxPMAB9t4mTxS6NENriIWgiBGDiMFT3dstkw\n" +
|
||||||
|
"tIvxX/gdrLCd9CbV1iZgH+a/CiKIYcSGzPiYfwEi446cPZwfwYo65C1HBS1mMJju\n" +
|
||||||
|
"FwLw0r9OQ9LEsO+ar6d7hss4RmHgRR1JdQyBoq/wbQKBgQD1kkE1TfJpFmCpWR/P\n" +
|
||||||
|
"wdl88ABnwEZtaKKMS1A+T2+ywEl3y+iUPoouJ+69zG0s7NuwpeJ2c1S0BB+yFRWx\n" +
|
||||||
|
"ExGjJ2Z0GbK++f2R38Y3kvj2lGiB4AZ1sentTuatGHWRzwEd913swrKd/fkFBA/I\n" +
|
||||||
|
"x38Mmq7wDqkqIxNh20W2jWWd3QKBgQDcAgg39l5zYeNIUdm/PQINd4G1UjCTcgvn\n" +
|
||||||
|
"+7AFpuoCYfx9ReXzvLjGDs8VmuoBIg5Y4bWIUhTSQVQIIRE12EXrysawHs7loegp\n" +
|
||||||
|
"FTU6cZAjxT72sRhesr12f5s5Hd3zaMB0Y8PUljAG7lvAVNPQDUkAL7+bmYLxWokq\n" +
|
||||||
|
"G/FHJooBOwKBgQCidDWVKNKTuI0Lmv0TeL8DCtaJzEYK/OyDeRNFlVFkZBZ2HLvo\n" +
|
||||||
|
"zhKlhB9JCiKzVKHlE2hkSdmgGRZKve4SrXW+hEMfzRxVgJXB2dKMUztGDFmyiVxc\n" +
|
||||||
|
"oe0J42dw3Txx0AqCI3HMPeTh5fDF47D5dxhSY0YVYu2ABaI920wb/yBZNQKBgGlz\n" +
|
||||||
|
"P+Uy3QqIvJuJP8j9wOIbibwS7N1/KF3EsRXEbx09Qfv5aMJujlG//1nnqolofV/0\n" +
|
||||||
|
"r0HrtbchQNm0n78jLkBaLOl1ms1N0Sz/0Ud17xR2EjvDnl6lZVJKz2eM/TkR2Ezx\n" +
|
||||||
|
"FIfshJCN5sRE5FEwTPEd8cTuy2hLcLsSMY9c1YDJAoGBAMIPLraI8c7h4hOCNE66\n" +
|
||||||
|
"Eg2nEOcqCzmIYTS6ARCPYrOC4cx23+uAScbZCq+vBk34KSJyun1OgfvnRmVerpUU\n" +
|
||||||
|
"lld8v62FR3FnNwSY/zeySP8ENCzAUluql0yHzgpBwF3NNYihVdYY4Lm3vlUe4fTt\n" +
|
||||||
|
"krNC84FOePuC5qaIefZ03oRX\n" +
|
||||||
|
"-----END PRIVATE KEY-----";
|
||||||
|
|
||||||
|
private final IDictDataService dictDataService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SysRegRes getRegResByType(String type) {
|
public SysRegRes getRegResByType(String type) {
|
||||||
@@ -33,11 +88,56 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
|||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = {Exception.class})
|
@Transactional(rollbackFor = {Exception.class})
|
||||||
public boolean addRegRes(SysRegResParam sysRegResParam) {
|
public boolean addRegRes(SysRegResParam sysRegResParam) {
|
||||||
|
List<SysRegRes> regResList = new ArrayList<>();
|
||||||
|
|
||||||
|
RegInfoData regInfoData = decodeRegistrationCode(sysRegResParam.getCode());
|
||||||
|
if (ObjectUtil.isNotNull(regInfoData)) {
|
||||||
|
// 对比Mac地址
|
||||||
|
String mac = getMAC();
|
||||||
|
if (!mac.equals(regInfoData.getMacAddress())) {
|
||||||
|
throw new BusinessException(RegResponseEnum.MAC_ADDRESS_NOT_MATCH);
|
||||||
|
}
|
||||||
|
// 比对到期日期
|
||||||
|
String maxExpireDate = regInfoData.getExpireDateList().stream().max((a, b) -> a.compareTo(b)).get();
|
||||||
|
if (LocalDate.parse(maxExpireDate).isBefore(LocalDate.now())) {
|
||||||
|
throw new BusinessException(RegResponseEnum.REGISTRATION_CODE_EXPIRED);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < regInfoData.getTypeList().size(); i++) {
|
||||||
|
// 忽略过期的
|
||||||
|
if(LocalDate.parse(regInfoData.getExpireDateList().get(i)).isBefore(LocalDate.now())){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
SysRegRes sysRegRes = new SysRegRes();
|
SysRegRes sysRegRes = new SysRegRes();
|
||||||
BeanUtil.copyProperties(sysRegResParam, sysRegRes);
|
BeanUtil.copyProperties(sysRegResParam, sysRegRes);
|
||||||
sysRegRes.setState(DataStateEnum.ENABLE.getCode());
|
sysRegRes.setState(DataStateEnum.ENABLE.getCode());
|
||||||
// todo 解析注册码
|
sysRegRes.setCode(sysRegResParam.getCode());
|
||||||
return this.save(sysRegRes);
|
sysRegRes.setExpireDate(EncryptionUtil.encodeString(1,regInfoData.getExpireDateList().get(i)));
|
||||||
|
|
||||||
|
DictData dictData = dictDataService.getDictDataByCode(regInfoData.getTypeList().get(i));
|
||||||
|
if (ObjectUtil.isNotNull(dictData)) {
|
||||||
|
sysRegRes.setType(dictData.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
sysRegRes.setRealTime(20);
|
||||||
|
sysRegRes.setStatistics(5);
|
||||||
|
sysRegRes.setFlicker(1);
|
||||||
|
|
||||||
|
if(regInfoData.getTypeList().get(i).equals(DictDataEnum.CONTRAST.getCode())){
|
||||||
|
sysRegRes.setWaveRecord(1);
|
||||||
|
sysRegRes.setRealTime(200);
|
||||||
|
sysRegRes.setStatistics(5);
|
||||||
|
sysRegRes.setFlicker(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
regResList.add(sysRegRes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 删除原有的所有数据
|
||||||
|
this.remove(null);
|
||||||
|
return this.saveBatch(regResList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -52,13 +152,100 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, SysRegResVO> listRegRes() {
|
public SysRegResVO listRegRes() {
|
||||||
Map<String, SysRegResVO> map = new HashMap<>();
|
// todo 需要切面检测是否到期,到期则状态设为0
|
||||||
this.list().forEach(item -> {
|
|
||||||
SysRegResVO sysRegResVO = new SysRegResVO();
|
SysRegResVO sysRegResVO = new SysRegResVO();
|
||||||
BeanUtil.copyProperties(item, sysRegResVO);
|
List<String> typeList = new ArrayList<>();
|
||||||
map.put(item.getType(), sysRegResVO);
|
List<String> expireDateList = new ArrayList<>();
|
||||||
|
List<SysRegRes> regResList = this.lambdaQuery().eq(SysRegRes::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||||
|
if(ObjectUtil.isNotEmpty(regResList)){
|
||||||
|
sysRegResVO.setCode(regResList.get(0).getCode());
|
||||||
|
}
|
||||||
|
regResList.forEach(item -> {
|
||||||
|
DictData dictData = dictDataService.getDictDataById(item.getType());
|
||||||
|
if (ObjectUtil.isNotNull(dictData)) {
|
||||||
|
typeList.add(dictData.getCode());
|
||||||
|
}
|
||||||
|
expireDateList.add(EncryptionUtil.decoderString(1, item.getExpireDate()));
|
||||||
});
|
});
|
||||||
return map;
|
sysRegResVO.setTypeList(typeList);
|
||||||
|
sysRegResVO.setExpireDateList(expireDateList);
|
||||||
|
return sysRegResVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 使用hutool工具获取本机mac地址
|
||||||
|
*
|
||||||
|
* @return mac地址
|
||||||
|
*/
|
||||||
|
private static String getMAC() {
|
||||||
|
InetAddress inetAddress = null;
|
||||||
|
try {
|
||||||
|
inetAddress = InetAddress.getLocalHost();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
throw new BusinessException(RegResponseEnum.GET_MAC_ADDRESS_FAILED);
|
||||||
|
}
|
||||||
|
return NetUtil.getMacAddress(inetAddress);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析 PEM 格式的密钥
|
||||||
|
*
|
||||||
|
* @param pem PEM 格式的密钥
|
||||||
|
* @return 密钥对象
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private static Key parsePemKey(String pem) throws Exception {
|
||||||
|
// 去掉 PEM 格式中的头部和尾部
|
||||||
|
String cleanPem = pem
|
||||||
|
.replaceAll("-----BEGIN (.*?)-----", "")
|
||||||
|
.replaceAll("-----END (.*?)-----", "")
|
||||||
|
.replaceAll("\\s+", ""); // 移除换行和空格
|
||||||
|
|
||||||
|
byte[] decodedKey = Base64.getDecoder().decode(cleanPem);
|
||||||
|
|
||||||
|
// 根据密钥类型导入密钥
|
||||||
|
if (pem.contains("PRIVATE")) {
|
||||||
|
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(decodedKey);
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
|
||||||
|
return privateKey;
|
||||||
|
} else {
|
||||||
|
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(decodedKey);
|
||||||
|
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
|
||||||
|
PublicKey publicKey = keyFactory.generatePublic(keySpec);
|
||||||
|
return publicKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析注册码
|
||||||
|
*
|
||||||
|
* @param encryptedCode 加密后的注册码
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static RegInfoData decodeRegistrationCode(String encryptedCode) {
|
||||||
|
try {
|
||||||
|
byte[] encryptedData = Base64.getDecoder().decode(encryptedCode);
|
||||||
|
Key privateKey = parsePemKey(fixedPrivateKeyStr);
|
||||||
|
|
||||||
|
// 使用 RSA/OAEP 解密
|
||||||
|
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-256AndMGF1Padding");
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||||
|
byte[] decryptedData = cipher.doFinal(encryptedData);
|
||||||
|
|
||||||
|
// 将解密后的字节数组转换为字符串
|
||||||
|
String decodedString = new String(decryptedData, StandardCharsets.UTF_8);
|
||||||
|
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
RegInfoData regInfoData = objectMapper.readValue(decodedString, RegInfoData.class);
|
||||||
|
if (ObjectUtil.isNull(regInfoData) || regInfoData.getTypeList().size() == 0 || regInfoData.getTypeList().size() != regInfoData.getExpireDateList().size()) {
|
||||||
|
throw new BusinessException(RegResponseEnum.REGISTRATION_CODE_FORMAT_ERROR);
|
||||||
|
}
|
||||||
|
return regInfoData;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new BusinessException(RegResponseEnum.REGISTRATION_CODE_FORMAT_ERROR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user