导出加密
This commit is contained in:
parent
4f6b03cd53
commit
d3432062b8
@ -0,0 +1,69 @@
|
|||||||
|
package com.example.demo.common.domain;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
import java.io.Serial;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入导出加密传输对象
|
||||||
|
* 用于封装导入导出的统一数据结构
|
||||||
|
*
|
||||||
|
* @author 岳佳君 (2025年10月15日 16:29:01)
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
@Schema(description = "导入导出加密传输对象")
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@SuperBuilder
|
||||||
|
@Accessors(chain=true)
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class BaseXPortData implements Serializable {
|
||||||
|
|
||||||
|
@Serial
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@Schema(description = "ID")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间戳
|
||||||
|
*/
|
||||||
|
@Schema(description = "时间戳")
|
||||||
|
private String ts;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 签名
|
||||||
|
*/
|
||||||
|
@Schema(description = "签名")
|
||||||
|
private String sign;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 完整性
|
||||||
|
*/
|
||||||
|
@Schema(description = "完整性")
|
||||||
|
private String gritty;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 版本
|
||||||
|
*/
|
||||||
|
@Schema(description = "版本")
|
||||||
|
private String version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据
|
||||||
|
*/
|
||||||
|
@Schema(description = "数据")
|
||||||
|
private String data;
|
||||||
|
|
||||||
|
}
|
@ -62,6 +62,12 @@ public interface BaseService<Entity extends BaseEntity, VO extends BaseVO, DTO e
|
|||||||
*/
|
*/
|
||||||
VO detail(String id);
|
VO detail(String id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出导入盐
|
||||||
|
* @return 导出导入盐
|
||||||
|
*/
|
||||||
|
byte[] configXPort(String ts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入细节(用于导入 jsonl)
|
* 导入细节(用于导入 jsonl)
|
||||||
* @param line 导入行内容
|
* @param line 导入行内容
|
||||||
|
@ -2,9 +2,14 @@ package com.example.demo.common.typography;
|
|||||||
|
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.core.util.ZipUtil;
|
import cn.hutool.core.util.ZipUtil;
|
||||||
|
import cn.hutool.crypto.SmUtil;
|
||||||
|
import cn.hutool.crypto.symmetric.SymmetricCrypto;
|
||||||
import cn.zhxu.bs.BeanSearcher;
|
import cn.zhxu.bs.BeanSearcher;
|
||||||
import cn.zhxu.bs.SearchResult;
|
import cn.zhxu.bs.SearchResult;
|
||||||
import cn.zhxu.bs.operator.Contain;
|
import cn.zhxu.bs.operator.Contain;
|
||||||
@ -12,10 +17,7 @@ import cn.zhxu.bs.util.MapUtils;
|
|||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.example.demo.common.constant.GlobalConstants;
|
import com.example.demo.common.constant.GlobalConstants;
|
||||||
import com.example.demo.common.domain.BaseDTO;
|
import com.example.demo.common.domain.*;
|
||||||
import com.example.demo.common.domain.BaseEntity;
|
|
||||||
import com.example.demo.common.domain.BaseQueryDTO;
|
|
||||||
import com.example.demo.common.domain.BaseVO;
|
|
||||||
import com.example.demo.common.exception.BusinessException;
|
import com.example.demo.common.exception.BusinessException;
|
||||||
import com.fhs.trans.service.impl.TransService;
|
import com.fhs.trans.service.impl.TransService;
|
||||||
import com.mybatisflex.core.BaseMapper;
|
import com.mybatisflex.core.BaseMapper;
|
||||||
@ -34,10 +36,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 统一 Service 实现类
|
* 统一 Service 实现类
|
||||||
@ -177,6 +177,12 @@ public abstract class BaseServiceImpl<
|
|||||||
return wordVO;
|
return wordVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] configXPort(String ts) {
|
||||||
|
String fixed = "国密";
|
||||||
|
return ensureKeyLength(fixed + ts, 16);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object importDetail(String line) {
|
public Object importDetail(String line) {
|
||||||
log.warn("导入细节(暂无实现)");
|
log.warn("导入细节(暂无实现)");
|
||||||
@ -275,17 +281,30 @@ public abstract class BaseServiceImpl<
|
|||||||
throw new BusinessException("导出ID列表不能为空");
|
throw new BusinessException("导出ID列表不能为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String ts = String.valueOf(System.currentTimeMillis());
|
||||||
|
byte[] keyBytes = configXPort(ts);
|
||||||
|
SymmetricCrypto sm4 = SmUtil.sm4(keyBytes);
|
||||||
|
|
||||||
// 验证并获取所有要导出的数据
|
// 验证并获取所有要导出的数据
|
||||||
List<Object> list = new ArrayList<>();
|
List<Object> list = new ArrayList<>();
|
||||||
for (String id : ids) {
|
for (String id : ids) {
|
||||||
try {
|
try {
|
||||||
// 使用detail方法验证ID是否存在,并获取数据
|
// 使用detail方法验证ID是否存在,并获取数据
|
||||||
Object templateVO = exportDetail(id);
|
Object obj = exportDetail(id);
|
||||||
if (templateVO == null) {
|
if (obj == null) {
|
||||||
throw new BusinessException("不存在: " + id);
|
throw new BusinessException("不存在: " + id);
|
||||||
}
|
}
|
||||||
|
String content = JSON.toJSONString(obj);
|
||||||
|
// 加密
|
||||||
|
sm4.encryptHex(content);
|
||||||
|
// 统一结构体
|
||||||
|
BaseXPortData xPortData = BaseXPortData.builder()
|
||||||
|
.id(id)
|
||||||
|
.ts(ts)
|
||||||
|
.data(content)
|
||||||
|
.build();
|
||||||
// 添加到导出列表
|
// 添加到导出列表
|
||||||
list.add(templateVO);
|
list.add(xPortData);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
@ -298,9 +317,17 @@ public abstract class BaseServiceImpl<
|
|||||||
StringBuilder jsonlContent = new StringBuilder();
|
StringBuilder jsonlContent = new StringBuilder();
|
||||||
for (Object object : list) {
|
for (Object object : list) {
|
||||||
String jsonContent = JSON.toJSONString(object);
|
String jsonContent = JSON.toJSONString(object);
|
||||||
// TODO 加密
|
|
||||||
jsonlContent.append(jsonContent).append("\n");
|
jsonlContent.append(jsonContent).append("\n");
|
||||||
}
|
}
|
||||||
|
InputStream is = IoUtil.toStream(jsonlContent.toString(), StandardCharsets.UTF_8);
|
||||||
|
fileNameUniqueList.add(
|
||||||
|
String.format("%s-%s-%s.jsonl",
|
||||||
|
// getOperationName(),
|
||||||
|
"数据",
|
||||||
|
DateUtil.format(new Date(), "yyyyMMdd"),
|
||||||
|
IdUtil.simpleUUID()
|
||||||
|
));
|
||||||
|
inputStreams.add(is);
|
||||||
// 转换为数组
|
// 转换为数组
|
||||||
String[] fileNamesArr = fileNameUniqueList.toArray(new String[0]);
|
String[] fileNamesArr = fileNameUniqueList.toArray(new String[0]);
|
||||||
InputStream[] inputStreamsArr = inputStreams.toArray(new InputStream[0]);
|
InputStream[] inputStreamsArr = inputStreams.toArray(new InputStream[0]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user