代码提交

master
yqy 3 years ago
parent 2ad1d3fe28
commit a81291f3c0

@ -0,0 +1,101 @@
package com.baiye.util;
import lombok.extern.slf4j.Slf4j;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Base64;
/**
* AES
*/
@Slf4j
public class AESUtils {
/** 密钥长度: 128, 192 or 256 */
private static final int KEY_SIZE = 128;
/** 加密/解密算法名称 */
private static final String ALGORITHM = "AES";
/** 随机数生成器RNG算法名称 */
private static final String RNG_ALGORITHM = "SHA1PRNG";
/**
*
*/
private static SecretKey generateKey(byte[] key) throws Exception {
// 创建安全随机数生成器
SecureRandom random = SecureRandom.getInstance(RNG_ALGORITHM);
// 设置 密钥key的字节数组 作为安全随机数生成器的种子
random.setSeed(key);
// 创建 AES算法生成器
KeyGenerator gen = KeyGenerator.getInstance(ALGORITHM);
// 初始化算法生成器
gen.init(KEY_SIZE, random);
// 生成 AES密钥对象, 也可以直接创建密钥对象: return new SecretKeySpec(key, ALGORITHM);
return gen.generateKey();
}
/**
* : ->
*/
public static String encrypt(String plainBytes, String key) {
try {
// 生成密钥对象
SecretKey secKey = generateKey(key.getBytes(StandardCharsets.UTF_8));
// 获取 AES 密码器
Cipher cipher = Cipher.getInstance(ALGORITHM);
// 初始化密码器(加密模型)
cipher.init(Cipher.ENCRYPT_MODE, secKey);
//数据反转加密
String s = new StringBuilder(plainBytes).reverse().toString();
// 加密数据, 返回密文
byte[] cipherBytes = cipher.doFinal(s.getBytes(StandardCharsets.UTF_8));
//base64加密
String str = Base64.getEncoder().encodeToString(cipherBytes);
return str;
}catch (Exception e){
log.info("加密失败"+e.fillInStackTrace());
return null;
}
}
/**
* : ->
*/
public static String decrypt(String cipherBytes, String key){
try {
// 生成密钥对象
SecretKey secKey = generateKey(key.getBytes(StandardCharsets.UTF_8));
// 获取 AES 密码器
Cipher cipher = Cipher.getInstance(ALGORITHM);
// 初始化密码器(解密模型)
cipher.init(Cipher.DECRYPT_MODE, secKey);
//base64解密
byte[] bytes = Base64.getDecoder().decode(cipherBytes);
// 解密数据, 返回明文
byte[] plainBytes = cipher.doFinal(bytes);
//反转解密的结果返回
String str = new StringBuilder(new String(plainBytes, "utf-8")).reverse().toString();
return str;
}catch (Exception e){
log.info("解密密失败"+e.fillInStackTrace());
return null;
}
}
}

@ -0,0 +1,24 @@
package com.baiye.util;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
/**
* @author YQY
* @date : 2022/01/12
*/
@Converter
public class JpaConverterAes implements AttributeConverter<Object, String> {
private final String secret = "ad-platform";
@Override
public String convertToDatabaseColumn(Object obj) {
return AESUtils.encrypt((String) obj, secret);
}
@Override
public Object convertToEntityAttribute(String s) {
return AESUtils.decrypt(s,secret);
}
}

@ -1,5 +1,6 @@
package com.baiye.model.entity;
import com.baiye.util.JpaConverterAes;
import com.baiye.util.JpaConverterListJson;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -31,6 +32,7 @@ public class BaseClue implements Serializable {
@ApiModelProperty(value = "nid")
@Column(name = "nid")
@Convert(converter = JpaConverterAes.class)
private String nid;
@ApiModelProperty(value = "微信")

@ -37,7 +37,7 @@ public class UploadFileController {
@RequestParam(value = "uploadType") Integer uploadType,
@RequestParam(value = "userId") Long userId) {
if (file.length > 0 && uploadType != null && userId != null){
if (file.length > 0){
return uploadFileService.singleFileUpload(file,uploadType,userId);
}
return new ResponseEntity<>(CommonResponse.createBySuccess(ResponseCode.EMPTY_ARGUMENT.getDesc()), HttpStatus.OK);

@ -27,7 +27,7 @@ public class ClueMiddle{
@Id
@ApiModelProperty(value = "线索id")
@Column(name = "clue_id")
@NotNull
@NotNull(message = "资源id不能为空")
private Long clueId;
@ApiModelProperty(value = "小组id")

@ -64,9 +64,7 @@ public class ClueServiceImpl implements ClueService {
List<Long> clueLists = new ArrayList<>();
List<ClueMiddle> clueMiddleList = clueMiddleRepository.findByTaskId(taskId);
if (clueMiddleList.size() > 0) {
for (ClueMiddle clueMiddle : clueMiddleList) {
clueLists.add(clueMiddle.getClueId());
}
clueMiddleList.stream().forEach(ct -> clueLists.add(ct.getClueId()));
}
return clueLists;
}
@ -85,9 +83,7 @@ public class ClueServiceImpl implements ClueService {
public void batchUpdateOrganize(DistributeResponseDTO distributeResponseDTO) {
List<Long> responseList = distributeResponseDTO.getResponseList();
Long deptId = distributeResponseDTO.getDeptId();
for (Long id : responseList) {
clueMiddleRepository.updateOrganizeIdById(id, deptId);
}
responseList.stream().forEach(id -> clueMiddleRepository.updateOrganizeIdById(id, deptId));
}
/**

@ -74,7 +74,6 @@ public class UploadFileServiceImpl implements UploadFileService {
List<ClueRecord> clueRecords = new ArrayList<>();
int totalNum = 0;
// controller层已经判空可直接取第一个文件名拼接任务名称
String oneFileName = files[0].getOriginalFilename();
long taskId = IdUtil.getSnowflake(workerId, datacenterId).nextId();
//处理文件数据

@ -18,6 +18,7 @@ public class ExportExcelUtil {
*/
@SneakyThrows //处理异常try
public static void downloadEasyExcel(HttpServletResponse response, Object obj, List list){
// 不要用postman测试会出现乱码
String fileName = URLEncoder.encode("表单", "UTF-8");
response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8");

@ -36,6 +36,10 @@ snowflake:
workerId: 9
datacenterId: 9
#AES秘钥
aes:
secret: ad-platform
ribbon:
#建立连接超时时间

@ -3,8 +3,10 @@
<contextName>trade-account</contextName>
<!-- 定义日志格式基础信息 -->
<property name="LOG_DIR" value="./log/"/>
<property name="LOG_PATTERN"
value="%white(%contextName-) %d{yyyy-MM-dd HH:mm:ss:SS} %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{50}) - %cyan(%msg%n)"/>
<property name="LOG_CHARSET" value="utf-8"/>
<!--输出到控制台-->
@ -32,7 +34,7 @@
<encoder>
<pattern>${LOG_PATTERN}</pattern>
<charset>utf-8</charset>
<charset>utf- </charset>
</encoder>
<!-- 不写TRACE DEBUG -->
@ -41,11 +43,6 @@
</filter>
</appender>
<!--普通日志输出到控制台-->
<root level="info">
<appender-ref ref="stdAppender"/>
</root>
<!--监控sql日志输出 -->
<logger name="jdbc.sqlonly" level="INFO" additivity="false">
<appender-ref ref="stdAppender"/>

Loading…
Cancel
Save