微调
This commit is contained in:
@@ -14,6 +14,9 @@ import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.JwtUtil;
|
||||
import com.njcn.common.utils.LogUtil;
|
||||
import com.njcn.gather.system.auth.pojo.Token;
|
||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import com.njcn.gather.system.log.pojo.enums.LogOperationTypeEnum;
|
||||
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
|
||||
import com.njcn.gather.system.log.service.ISysLogAuditService;
|
||||
@@ -48,6 +51,7 @@ public class AuthController extends BaseController {
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
private final ISysLogAuditService sysLogAuditService;
|
||||
private final ISysTestConfigService sysTestConfigService;
|
||||
|
||||
// @RequestMapping("/login")
|
||||
// public HttpResult<Token> login() {
|
||||
@@ -146,4 +150,14 @@ public class AuthController extends BaseController {
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, null, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON)
|
||||
@ApiOperation("获取当前场景")
|
||||
@GetMapping("/getCurrentScene")
|
||||
public HttpResult<String> getCurrentScene() {
|
||||
String methodDescribe = getMethodDescribe("getCurrentScene");
|
||||
LogUtil.njcnDebug(log, "{},获取当前场景", methodDescribe);
|
||||
String currrentScene= sysTestConfigService.getCurrrentScene();
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, currrentScene, methodDescribe);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,4 +35,6 @@ public interface ISysTestConfigService extends IService<SysTestConfig> {
|
||||
* @return
|
||||
*/
|
||||
SysTestConfig getOneConfig();
|
||||
|
||||
String getCurrrentScene();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.njcn.gather.system.config.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.yulichang.wrapper.MPJLambdaWrapper;
|
||||
@@ -9,6 +10,7 @@ import com.njcn.gather.system.config.pojo.param.SysTestConfigParam;
|
||||
import com.njcn.gather.system.config.pojo.po.SysTestConfig;
|
||||
import com.njcn.gather.system.config.service.ISysTestConfigService;
|
||||
import com.njcn.gather.system.dictionary.pojo.po.DictData;
|
||||
import com.njcn.gather.system.dictionary.service.IDictDataService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -24,6 +26,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@RequiredArgsConstructor
|
||||
public class SysTestConfigServiceImpl extends ServiceImpl<SysTestConfigMapper, SysTestConfig> implements ISysTestConfigService {
|
||||
|
||||
private final IDictDataService dictDataService;
|
||||
|
||||
@Override
|
||||
public SysTestConfig getConfig() {
|
||||
return this.getOne(new QueryWrapper<SysTestConfig>().last("LIMIT 1"));
|
||||
@@ -55,4 +59,14 @@ public class SysTestConfigServiceImpl extends ServiceImpl<SysTestConfigMapper, S
|
||||
.eq(SysTestConfig::getState, DataStateEnum.ENABLE.getCode());
|
||||
return this.getBaseMapper().selectJoinOne(SysTestConfig.class, queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrrentScene() {
|
||||
String scene = getOneConfig().getScene();
|
||||
DictData dictData = dictDataService.getDictDataById(scene);
|
||||
if(ObjectUtil.isNotNull(dictData)){
|
||||
return dictData.getValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.njcn.gather.system.reg.pojo.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
* @data 2025-03-13
|
||||
*/
|
||||
@Getter
|
||||
public enum RegStatusEnum {
|
||||
UNREGISTERED(0, "未激活"),
|
||||
REGISTERED(1, "已激活"),
|
||||
EXPIRED(2, "已过期");
|
||||
|
||||
private int code;
|
||||
private String message;
|
||||
RegStatusEnum(int code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -12,17 +12,37 @@ import java.util.List;
|
||||
@Data
|
||||
public class SysRegResVO {
|
||||
/**
|
||||
* 注册码
|
||||
* 注册码。如果未激活,则为null
|
||||
*/
|
||||
private String code;
|
||||
|
||||
/**
|
||||
* 注册的模式
|
||||
* 模拟式激活状态。0:未激活;1:已激活;2:已过期
|
||||
*/
|
||||
private List<String> typeList;
|
||||
private int simulateStatus;
|
||||
|
||||
/**
|
||||
* 到期时间
|
||||
* 模拟式激活到期日期。如果未激活,则为null
|
||||
*/
|
||||
private List<String> expireDateList;
|
||||
private String simulateExpireDate;
|
||||
|
||||
/**
|
||||
* 数字式激活状态。0:未激活;1:已激活;2:已过期
|
||||
*/
|
||||
private int digitalStatus;
|
||||
|
||||
/**
|
||||
* 数字式激活到期日期。如果未激活,则为null
|
||||
*/
|
||||
private String digitalExpireDate;
|
||||
|
||||
/**
|
||||
* 比对式激活状态。0:未激活;1:已激活;2:已过期
|
||||
*/
|
||||
private int contrastStatus;
|
||||
|
||||
/**
|
||||
* 比对式激活到期日期。如果未激活,则为null
|
||||
*/
|
||||
private String contrastExpireDate;
|
||||
}
|
||||
|
||||
@@ -8,14 +8,13 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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.pojo.dto.RegInfoData;
|
||||
import com.njcn.gather.system.reg.pojo.enums.RegResponseEnum;
|
||||
import com.njcn.gather.system.reg.pojo.enums.RegStatusEnum;
|
||||
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.vo.SysRegResVO;
|
||||
@@ -35,8 +34,12 @@ import java.security.PrivateKey;
|
||||
import java.security.PublicKey;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author caozehui
|
||||
@@ -97,23 +100,28 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
||||
if (!mac.equals(regInfoData.getMacAddress())) {
|
||||
throw new BusinessException(RegResponseEnum.MAC_ADDRESS_NOT_MATCH);
|
||||
}
|
||||
|
||||
List<String> expireDateList = regInfoData.getExpireDateList();
|
||||
for (int i = 0; i < regInfoData.getTypeList().size(); i++) {
|
||||
expireDateList.set(i, formatDate(expireDateList.get(i)));
|
||||
}
|
||||
// 比对到期日期
|
||||
String maxExpireDate = regInfoData.getExpireDateList().stream().max((a, b) -> a.compareTo(b)).get();
|
||||
String maxExpireDate = expireDateList.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;
|
||||
}
|
||||
// if (isExpire(expireDateList.get(i))) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
SysRegRes sysRegRes = new SysRegRes();
|
||||
BeanUtil.copyProperties(sysRegResParam, sysRegRes);
|
||||
sysRegRes.setState(DataStateEnum.ENABLE.getCode());
|
||||
sysRegRes.setCode(sysRegResParam.getCode());
|
||||
sysRegRes.setExpireDate(EncryptionUtil.encodeString(1,regInfoData.getExpireDateList().get(i)));
|
||||
sysRegRes.setExpireDate(EncryptionUtil.encodeString(1, formatDate(regInfoData.getExpireDateList().get(i))));
|
||||
|
||||
DictData dictData = dictDataService.getDictDataByCode(regInfoData.getTypeList().get(i));
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
@@ -124,7 +132,7 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
||||
sysRegRes.setStatistics(5);
|
||||
sysRegRes.setFlicker(1);
|
||||
|
||||
if(regInfoData.getTypeList().get(i).equals(DictDataEnum.CONTRAST.getCode())){
|
||||
if (regInfoData.getTypeList().get(i).equals(DictDataEnum.CONTRAST.getCode())) {
|
||||
sysRegRes.setWaveRecord(1);
|
||||
sysRegRes.setRealTime(200);
|
||||
sysRegRes.setStatistics(5);
|
||||
@@ -155,31 +163,87 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
||||
public SysRegResVO listRegRes() {
|
||||
// todo 需要切面检测是否到期,到期则状态设为0
|
||||
SysRegResVO sysRegResVO = new SysRegResVO();
|
||||
List<String> typeList = new ArrayList<>();
|
||||
List<String> expireDateList = new ArrayList<>();
|
||||
List<SysRegRes> regResList = this.lambdaQuery().eq(SysRegRes::getState, DataStateEnum.ENABLE.getCode()).list();
|
||||
if(ObjectUtil.isNotEmpty(regResList)){
|
||||
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());
|
||||
sysRegResVO.setSimulateStatus(RegStatusEnum.UNREGISTERED.getCode());
|
||||
sysRegResVO.setDigitalStatus(RegStatusEnum.UNREGISTERED.getCode());
|
||||
sysRegResVO.setContrastStatus(RegStatusEnum.UNREGISTERED.getCode());
|
||||
for (SysRegRes regRes : regResList) {
|
||||
DictData dictData = dictDataService.getDictDataById(regRes.getType());
|
||||
String s = EncryptionUtil.decoderString(1, regRes.getExpireDate());
|
||||
boolean expire = isExpire(s);
|
||||
if (ObjectUtil.isNotNull(dictData)) {
|
||||
if (dictData.getCode().equals(DictDataEnum.SIMULATE.getCode())) {
|
||||
if (expire) {
|
||||
sysRegResVO.setSimulateStatus(RegStatusEnum.EXPIRED.getCode());
|
||||
} else {
|
||||
sysRegResVO.setSimulateStatus(RegStatusEnum.REGISTERED.getCode());
|
||||
}
|
||||
sysRegResVO.setSimulateExpireDate(s);
|
||||
}
|
||||
if (dictData.getCode().equals(DictDataEnum.DIGITAL.getCode())) {
|
||||
if (expire) {
|
||||
sysRegResVO.setDigitalStatus(RegStatusEnum.EXPIRED.getCode());
|
||||
} else {
|
||||
sysRegResVO.setDigitalStatus(RegStatusEnum.REGISTERED.getCode());
|
||||
}
|
||||
sysRegResVO.setDigitalExpireDate(s);
|
||||
}
|
||||
if (dictData.getCode().equals(DictDataEnum.CONTRAST.getCode())) {
|
||||
if (expire) {
|
||||
sysRegResVO.setContrastStatus(RegStatusEnum.EXPIRED.getCode());
|
||||
} else {
|
||||
sysRegResVO.setContrastStatus(RegStatusEnum.REGISTERED.getCode());
|
||||
}
|
||||
sysRegResVO.setContrastExpireDate(s);
|
||||
}
|
||||
} else {
|
||||
throw new BusinessException("字典数据缺失,请联系管理员!");
|
||||
}
|
||||
}
|
||||
expireDateList.add(EncryptionUtil.decoderString(1, item.getExpireDate()));
|
||||
});
|
||||
sysRegResVO.setTypeList(typeList);
|
||||
sysRegResVO.setExpireDateList(expireDateList);
|
||||
}
|
||||
return sysRegResVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化日期 (将日期格式化为yyyy-MM-dd)
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
private String formatDate(String date) {
|
||||
String[] split = date.split("-");
|
||||
if (split[1].length() == 1) {
|
||||
split[1] = "0" + split[1];
|
||||
}
|
||||
if (split[2].length() == 1) {
|
||||
split[2] = "0" + split[2];
|
||||
}
|
||||
return split[0] + "-" + split[1] + "-" + split[2];
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否到期
|
||||
*
|
||||
* @param expireDate 到期日期
|
||||
* @return
|
||||
*/
|
||||
private boolean isExpire(String expireDate) {
|
||||
expireDate = formatDate(expireDate);
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
||||
if (today.compareTo(expireDate) >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用hutool工具获取本机mac地址
|
||||
*
|
||||
* @return mac地址
|
||||
*/
|
||||
private static String getMAC() {
|
||||
private String getMAC() {
|
||||
InetAddress inetAddress = null;
|
||||
try {
|
||||
inetAddress = InetAddress.getLocalHost();
|
||||
@@ -196,7 +260,7 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
||||
* @return 密钥对象
|
||||
* @throws Exception
|
||||
*/
|
||||
private static Key parsePemKey(String pem) throws Exception {
|
||||
private Key parsePemKey(String pem) throws Exception {
|
||||
// 去掉 PEM 格式中的头部和尾部
|
||||
String cleanPem = pem
|
||||
.replaceAll("-----BEGIN (.*?)-----", "")
|
||||
@@ -225,7 +289,7 @@ public class SysRegResServiceImpl extends ServiceImpl<SysRegResMapper, SysRegRes
|
||||
* @param encryptedCode 加密后的注册码
|
||||
* @return
|
||||
*/
|
||||
public static RegInfoData decodeRegistrationCode(String encryptedCode) {
|
||||
private RegInfoData decodeRegistrationCode(String encryptedCode) {
|
||||
try {
|
||||
byte[] encryptedData = Base64.getDecoder().decode(encryptedCode);
|
||||
Key privateKey = parsePemKey(fixedPrivateKeyStr);
|
||||
|
||||
Reference in New Issue
Block a user