Browse Source

修改上南生成数据日期

dev-sn
Gaoby 2 years ago
parent
commit
572196e1dc
  1. 40
      device_cars/src/main/java/com/xr/device_car/config/common/TypeNameConverter.java
  2. 200
      device_display/src/main/java/com/xr/device_display/config/utils/CryptoUtil.java
  3. 4
      device_display/src/main/java/com/xr/device_display/modules/analysis/service/impl/MeterReadingRecordServiceImpl.java

40
device_cars/src/main/java/com/xr/device_car/config/common/TypeNameConverter.java

@ -1,40 +0,0 @@
package com.xr.device_car.config.common;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
public class TypeNameConverter implements Converter<String> {
@Override
public Class supportJavaTypeKey() {
return null;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return null;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
@Override
public CellData convertToExcelData(String s, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
//表计形状(0圆形指针1扇形指针2数字类表计3状态类表计
if (s.equals("0")){
return new CellData("圆形指针");
}else if (s.equals("1")){
return new CellData("扇形指针");
}else if (s.equals("2")){
return new CellData("数字类表计");
}else if (s.equals("3")){
return new CellData("状态类表计");
}else {
return new CellData(s);
}
}
}

200
device_display/src/main/java/com/xr/device_display/config/utils/CryptoUtil.java

@ -1,200 +0,0 @@
package com.xr.device_display.config.utils;
import com.xr.device_display.config.common.LoginConfig;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Random;
public class CryptoUtil {
public static boolean isNullOrEmpty(String x) {
return x == null || x.length() == 0;
}
public static void main(String[] args) throws Exception {
String content = "123456";
System.out.println("加密前:" + content);
System.out.println(new Date().getTime());
String key = LoginConfig.CryptoKey;
System.out.println("加密密钥和解密密钥:" + key);
String encrypt = aesEncrypt(content, key);
System.out.println("加密后:" + encrypt);
String decrypt = aesDecrypt("EReac0gCF7wAgh38nJfupg==", key);
System.out.println("解密后:" + decrypt);
}
/**
* 将byte[]转为各种进制的字符串
*
* @param bytes byte[]
* @param radix 可以转换进制的范围从Character.MIN_RADIX到Character.MAX_RADIX超出范围后变为10进制
* @return 转换后的字符串
*/
public static String binary(byte[] bytes, int radix) {
return new BigInteger(1, bytes).toString(radix);// 这里的1代表正数
}
/**
* base 64 encode
*
* @param bytes 待编码的byte[]
* @return 编码后的base 64 code
*/
public static String base64Encode(byte[] bytes) {
return new BASE64Encoder().encode(bytes);
}
/**
* base 64 decode
*
* @param base64Code 待解码的base 64 code
* @return 解码后的byte[]
* @throws Exception
*/
public static byte[] base64Decode(String base64Code) throws Exception {
return isNullOrEmpty(base64Code) ? null : new BASE64Decoder().decodeBuffer(base64Code);
}
/**
* 获取byte[]的md5值
*
* @param bytes byte[]
* @return md5
* @throws Exception
*/
public static byte[] md5(byte[] bytes) throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(bytes);
return md.digest();
}
/**
* 获取字符串md5值
*
* @param msg
* @return md5
* @throws Exception
*/
public static byte[] md5(String msg) throws Exception {
return isNullOrEmpty(msg) ? null : md5(msg.getBytes());
}
/**
* 结合base64实现md5加密
*
* @param msg 待加密字符串
* @return 获取md5后转为base64
* @throws Exception
*/
public static String md5Encrypt(String msg) throws Exception {
return isNullOrEmpty(msg) ? null : base64Encode(md5(msg));
}
/**
* AES加密
*
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的byte[]
* @throws Exception
*/
public static byte[] aesEncryptToBytes(String content, String encryptKey) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(encryptKey.getBytes());
kgen.init(128, secureRandom);
// kgen.init(128, new SecureRandom(encryptKey.getBytes()));
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
return cipher.doFinal(content.getBytes("utf-8"));
}
/**
* AES加密为base 64 code
*
* @param content 待加密的内容
* @param encryptKey 加密密钥
* @return 加密后的base 64 code
* @throws Exception
*/
public static String aesEncrypt(String content, String encryptKey) throws Exception {
return base64Encode(aesEncryptToBytes(content, encryptKey));
}
/**
* AES解密
*
* @param encryptBytes 待解密的byte[]
* @param decryptKey 解密密钥
* @return 解密后的String
* @throws Exception
*/
public static String aesDecryptByBytes(byte[] encryptBytes, String decryptKey) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom.setSeed(decryptKey.getBytes());
kgen.init(128, secureRandom);
// kgen.init(128, new SecureRandom(decryptKey.getBytes()));
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(kgen.generateKey().getEncoded(), "AES"));
byte[] decryptBytes = cipher.doFinal(encryptBytes);
return new String(decryptBytes);
}
/**
* 将base 64 code AES解密
*
* @param encryptStr 待解密的base 64 code
* @param decryptKey 解密密钥
* @return 解密后的string
* @throws Exception
*/
public static String aesDecrypt(String encryptStr, String decryptKey) throws Exception {
return isNullOrEmpty(encryptStr) ? null : aesDecryptByBytes(base64Decode(encryptStr), decryptKey);
}
/**
* 生成随即密码
*
* @param pwd_len 生成的密码的总长度
* @return 密码的字符串
*/
public static String genRandomNum(int pwd_len) {
// 35是因为数组是从0开始的,26个字母+10个数字
final int maxNum = 35;
int i; // 生成的随机数
int count = 0; // 生成的密码的长度
char[] str = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', '0', '1', '2', '3', '4',
'5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L'};
StringBuffer pwd = new StringBuffer("");
Random r = new Random();
while (count < pwd_len) {
// 生成随机数,取绝对值,防止生成负数,
i = Math.abs(r.nextInt(maxNum)); // 生成的数最大为36-1
if (i >= 0 && i < str.length) {
pwd.append(str[i]);
count++;
}
}
return pwd.toString();
}
}

4
device_display/src/main/java/com/xr/device_display/modules/analysis/service/impl/MeterReadingRecordServiceImpl.java

@ -253,9 +253,9 @@ public class MeterReadingRecordServiceImpl extends ServiceImpl<MeterReadingRecor
Map<Integer, List<MeterConfig>> idMeterConfigMap = getMeterMessage();
// Map<Integer,String> readingMap = readingMap();
// 设置起始日期
LocalDate startDate = LocalDate.of(2024, 1, 15);
LocalDate startDate = LocalDate.of(2024, 2, 5);
// 设置结束日期
LocalDate endDate = LocalDate.of(2024, 1, 29);
LocalDate endDate = LocalDate.of(2024, 3, 20);
// 设置每隔15分钟插入一条记录
Duration duration = Duration.ofMinutes(15);

Loading…
Cancel
Save