P2-3: 横切服务桩换 framework 真实现(文件/日志/消息)
保真层原样移植三块横切服务,删除对应桩,bean 名/包名/签名不动: - 文件 com.dsasp.server.file.*:FileServiceImpl(bean fileService)真实现, 存储后端经替换类 FTPClientTemplate(保包名/类名/签名,FTP→本地盘, 根目录 eip4.file.root 配置化默认 ./data/files,resolveSafe 防 ../ 逃逸); BASE64Decoder→java.util.Base64、ant zip→java.util.zip、commons-codec→MessageDigest。 - 日志 com.dsasp.server.log.*:SystemLogManagerImpl/DataOperatorLogger/ DataLogRecorderImpl + 异步调度(DataLogManager/ProcessLogThread/ProcessSysLogThread) 原样移植,落 SYS_LOG/SYS_DATA_LOG/SYS_DATA_LOGITEM(后者 insert-only 无审计列,§5.1)。 - 消息 com.dsasp.server.mail.*:SystemEmailServiceImpl + SystemEmail/SystemEmailService 移植;SMTP 配置缺省时降级 no-op + WARN,不阻塞启动(§5.38)。 装配/配置/自举/验证: - LegacyXmlWiring 等价补齐三处 jdbcTemplate setter + MainApp.destPath 注入(§4.1); - application.yml 加 eip4.file.root;bootstrap-xservice.sql 自举四张横切表 + LOGLEVEL; - 删除 StubFileService/StubSystemLogManager/StubDataOperatorLog(StubProjectSwitchService 属 viewframework 域非本任务范畴,保留); - 单测 12 + 本地 DB 集成 4,全模块 mvn clean test 绿(含 ArchUnit);8087 启动验证毕已 kill。 报告:platform-auth/P2横切服务实测报告.md;坑入 docs/迁移手册.md §3.1/§3.2/§5.36-5.38。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,21 @@
|
||||
package com.eip4.platform.app.config;
|
||||
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import com.fasterxml.jackson.datatype.joda.JodaModule;
|
||||
import com.dsasp.server.common.util.MainApp;
|
||||
|
||||
import com.dsasp.server.common.log.service.DataOperatorLog;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager;
|
||||
import com.dsasp.server.core.service.FlowServiceImpl;
|
||||
import com.dsasp.server.file.service.FileServiceImpl;
|
||||
import com.dsasp.server.log.service.DataLogRecorderImpl;
|
||||
import com.dsasp.server.log.service.SystemLogManagerImpl;
|
||||
import com.dsasp.server.dataDic.service.POJOCRUDServiceImpl;
|
||||
import com.dsasp.server.dataDic.service.POJOServiceImpl;
|
||||
import com.dsasp.server.organize.service.AssignmentHandlerImpl;
|
||||
@@ -41,6 +46,13 @@ public class LegacyXmlWiring implements SmartInitializingSingleton {
|
||||
private final UserFindServiceImpl userFindService;
|
||||
private final UserOtpServiceImpl userOtpService;
|
||||
private final AssignmentHandlerImpl assignmentHandler;
|
||||
private final FileServiceImpl fileService;
|
||||
private final SystemLogManagerImpl systemLogManagerImpl;
|
||||
private final DataLogRecorderImpl dataLogRecorder;
|
||||
|
||||
/** 附件本地盘根目录(配置化,默认 ./data/files);注入保真层 MainApp.destPath。 */
|
||||
@Value("${eip4.file.root:./data/files}")
|
||||
private String fileRoot;
|
||||
|
||||
public LegacyXmlWiring(POJOCRUDServiceImpl pojoCRUDService,
|
||||
POJOServiceImpl pojoService,
|
||||
@@ -51,7 +63,10 @@ public class LegacyXmlWiring implements SmartInitializingSingleton {
|
||||
OrganizationServiceImpl organizationService,
|
||||
UserFindServiceImpl userFindService,
|
||||
UserOtpServiceImpl userOtpService,
|
||||
AssignmentHandlerImpl assignmentHandler) {
|
||||
AssignmentHandlerImpl assignmentHandler,
|
||||
FileServiceImpl fileService,
|
||||
SystemLogManagerImpl systemLogManagerImpl,
|
||||
DataLogRecorderImpl dataLogRecorder) {
|
||||
this.pojoCRUDService = pojoCRUDService;
|
||||
this.pojoService = pojoService;
|
||||
this.systemLogManager = systemLogManager;
|
||||
@@ -62,6 +77,9 @@ public class LegacyXmlWiring implements SmartInitializingSingleton {
|
||||
this.userFindService = userFindService;
|
||||
this.userOtpService = userOtpService;
|
||||
this.assignmentHandler = assignmentHandler;
|
||||
this.fileService = fileService;
|
||||
this.systemLogManagerImpl = systemLogManagerImpl;
|
||||
this.dataLogRecorder = dataLogRecorder;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,6 +101,18 @@ public class LegacyXmlWiring implements SmartInitializingSingleton {
|
||||
userOtpService.setJdbcTemplate(jdbcTemplate);
|
||||
assignmentHandler.setOrganizationService(organizationService);
|
||||
assignmentHandler.setUserFindService(userFindService);
|
||||
|
||||
// P2 横切服务(文件/日志):FileServiceImpl / SystemLogManagerImpl / DataLogRecorderImpl
|
||||
// 的 jdbcTemplate 在 framework 同为 XML <property> setter 注入(非 @Autowired),
|
||||
// 这里等价补齐(见 §4.1)。三块真实现接替原 Stub*,bean 名一致(fileService/
|
||||
// systemLogManager/dataLogRecorder),旧引擎调用方零感知。
|
||||
fileService.setJdbcTemplate(jdbcTemplate);
|
||||
systemLogManagerImpl.setJdbcTemplate(jdbcTemplate);
|
||||
dataLogRecorder.setJdbcTemplate(jdbcTemplate);
|
||||
|
||||
// 附件本地盘根目录配置化(eip4.file.root,默认 ./data/files)注入保真层 MainApp。
|
||||
// 保真层不反向依赖现代层(ArchUnit),故由现代层单向 set,旧 FileServiceImpl 零修改。
|
||||
MainApp.setDestPath(fileRoot);
|
||||
}
|
||||
|
||||
/** 引擎字段值含 joda DateTime(CREATETIME 等),Boot 3 需显式注册序列化模块。 */
|
||||
|
||||
@@ -29,6 +29,10 @@ eip4:
|
||||
secret: ${EIP4_AUTH_JWT_SECRET:dev-only-eip4-jwt-secret-change-me-in-production-0123456789}
|
||||
expire-seconds: 28800 # 8h
|
||||
issuer: eip4-platform
|
||||
# 附件横切服务(P2):本地盘存储根目录。注入保真层 MainApp.destPath。
|
||||
# 默认 ./data/files(相对启动工作目录),生产经环境变量 EIP4_FILE_ROOT 覆盖为绝对路径。
|
||||
file:
|
||||
root: ${EIP4_FILE_ROOT:./data/files}
|
||||
|
||||
logging:
|
||||
level:
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
package com.eip4.platform.app;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import com.dsasp.server.common.email.bean.SystemEmail;
|
||||
import com.dsasp.server.common.email.service.SystemEmailService;
|
||||
import com.dsasp.server.common.log.bean.DataLogDetail;
|
||||
import com.dsasp.server.common.log.bean.DataLogItem;
|
||||
import com.dsasp.server.common.log.bean.SysLogItem;
|
||||
import com.dsasp.server.common.log.service.DataLogRecorder;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager;
|
||||
import com.dsasp.server.common.log.service.SystemLogManager.LogType;
|
||||
import com.dsasp.server.common.util.MainApp;
|
||||
import com.dsasp.server.file.upload.FTPClientTemplate;
|
||||
|
||||
/**
|
||||
* P2 横切服务(文件/日志/消息)真实现 DB 落地集成测试(local profile,eip4m0 自举库)。
|
||||
*
|
||||
* <p>用 bootstrap-sys.sql + bootstrap-xservice.sql 自举 SYS_LOG / SYS_DATA_LOG /
|
||||
* SYS_DATA_LOGITEM,经容器内真实 bean(systemLogManager / dataLogRecorder)写库再读回,
|
||||
* 验证落库字段语义与老系统一致;附件经替换类 FTPClientTemplate 本地盘上传→下载字节一致;
|
||||
* 邮件降级路径不抛。eip4m0 不可达时整类跳过(assumeTrue),CI 无该库不红。
|
||||
*/
|
||||
@SpringBootTest
|
||||
@ActiveProfiles("local")
|
||||
class XServiceLocalIT {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("systemLogManager")
|
||||
private SystemLogManager systemLogManager;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("dataLogRecorder")
|
||||
private DataLogRecorder dataLogRecorder;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("systemEmailService")
|
||||
private SystemEmailService systemEmailService;
|
||||
|
||||
private boolean ensureBootstrap() {
|
||||
try {
|
||||
jdbcTemplate.queryForObject("select 1", Integer.class);
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
runSql("bootstrap/bootstrap-sys.sql");
|
||||
runSql("bootstrap/bootstrap-xservice.sql");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException("自举 SQL 执行失败:" + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void runSql(String classpath) throws IOException {
|
||||
String sql = StreamUtils.copyToString(
|
||||
new ClassPathResource(classpath).getInputStream(), StandardCharsets.UTF_8);
|
||||
jdbcTemplate.execute(sql);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("系统日志真实现:log(List) 批量落 SYS_LOG,字段语义(类型/内容/操作人/时间)正确")
|
||||
void systemLog_persists_to_sys_log() {
|
||||
assumeTrue(ensureBootstrap(), "本地 eip4m0 不可达,跳过");
|
||||
jdbcTemplate.update("DELETE FROM sys_log");
|
||||
|
||||
List<SysLogItem> items = new ArrayList<>();
|
||||
items.add(new SysLogItem(LogType.INFO, "P2 集成测试:系统日志落库", "tester-001"));
|
||||
systemLogManager.log(items);
|
||||
|
||||
Map<String, Object> row = jdbcTemplate.queryForMap(
|
||||
"SELECT type, content, createby, updateby, isactive, version, createtime FROM sys_log LIMIT 1");
|
||||
assertEquals("Info", String.valueOf(row.get("type")).trim());
|
||||
assertEquals("P2 集成测试:系统日志落库", row.get("content"));
|
||||
assertEquals("tester-001", String.valueOf(row.get("createby")).trim());
|
||||
assertEquals("tester-001", String.valueOf(row.get("updateby")).trim());
|
||||
assertEquals(1, ((Number) row.get("isactive")).intValue());
|
||||
assertEquals(0, ((Number) row.get("version")).intValue());
|
||||
assertTrue(((Number) row.get("createtime")).longValue() > 0, "createtime 应为 joda 毫秒");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("数据操作日志真实现:recorderLogs 落 SYS_DATA_LOG + SYS_DATA_LOGITEM(insert-only)")
|
||||
void dataLog_persists_main_and_detail() {
|
||||
assumeTrue(ensureBootstrap(), "本地 eip4m0 不可达,跳过");
|
||||
jdbcTemplate.update("DELETE FROM sys_data_logitem");
|
||||
jdbcTemplate.update("DELETE FROM sys_data_log");
|
||||
|
||||
String dlId = UUID.randomUUID().toString();
|
||||
DataLogItem item = new DataLogItem();
|
||||
item.setDataLogItem_Id(dlId);
|
||||
item.setTableName("EIP4PT_CUSTOMER");
|
||||
item.setRecordId("rec-itest");
|
||||
item.setType(DataLogItem.OPERATE_NEW);
|
||||
item.setUserId("tester-002");
|
||||
DataLogDetail d = new DataLogDetail();
|
||||
d.setDataLogId(dlId);
|
||||
d.setColumnName("NAME");
|
||||
d.setOldValue(null);
|
||||
d.setNewValue("集成测试客户");
|
||||
item.addDataLogDetail(d);
|
||||
|
||||
List<DataLogItem> list = new ArrayList<>();
|
||||
list.add(item);
|
||||
dataLogRecorder.recorderLogs(list);
|
||||
|
||||
Map<String, Object> main = jdbcTemplate.queryForMap(
|
||||
"SELECT tablename, recordid, type, updateby FROM sys_data_log WHERE sys_data_log_id=?", dlId);
|
||||
assertEquals("EIP4PT_CUSTOMER", main.get("tablename"));
|
||||
assertEquals("rec-itest", String.valueOf(main.get("recordid")).trim());
|
||||
assertEquals(DataLogItem.OPERATE_NEW.intValue(), ((Number) main.get("type")).intValue());
|
||||
assertEquals("tester-002", String.valueOf(main.get("updateby")).trim());
|
||||
|
||||
Map<String, Object> detail = jdbcTemplate.queryForMap(
|
||||
"SELECT columnname, oldvalue, newvalue FROM sys_data_logitem WHERE sys_datalogid=?", dlId);
|
||||
assertEquals("NAME", detail.get("columnname"));
|
||||
assertEquals("集成测试客户", detail.get("newvalue"));
|
||||
assertEquals(null, detail.get("oldvalue"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("附件真实现:本地盘上传→下载字节一致,删除生效")
|
||||
void file_upload_download_roundtrip(@org.junit.jupiter.api.io.TempDir java.nio.file.Path tmp) throws Exception {
|
||||
assumeTrue(ensureBootstrap(), "本地 eip4m0 不可达,跳过");
|
||||
String saved = MainApp.destPath;
|
||||
try {
|
||||
MainApp.setDestPath(tmp.toFile().getAbsolutePath());
|
||||
byte[] payload = "集成测试附件内容-binary".getBytes(StandardCharsets.UTF_8);
|
||||
File src = tmp.resolve("in.bin").toFile();
|
||||
Files.write(src.toPath(), payload);
|
||||
|
||||
FTPClientTemplate tpl = new FTPClientTemplate();
|
||||
String remote = "/SYS_DOC/0/itest.zip";
|
||||
tpl.uploadFileAndZip(remote, src.getAbsolutePath(), "itest.txt");
|
||||
assertTrue(tpl.fileExists(remote), "落盘后远端应存在");
|
||||
|
||||
File out = tmp.resolve("out.bin").toFile();
|
||||
tpl.downloadFile(remote, out.getAbsolutePath());
|
||||
assertArrayEquals(payload, Files.readAllBytes(out.toPath()), "下载字节须一致");
|
||||
|
||||
assertTrue(tpl.delete(remote));
|
||||
assertFalse(tpl.fileExists(remote));
|
||||
} finally {
|
||||
MainApp.destPath = saved;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("消息真实现:配置缺省降级路径,sendEmail 不抛、不阻塞")
|
||||
void mail_degrades_without_config() {
|
||||
assumeTrue(ensureBootstrap(), "本地 eip4m0 不可达,跳过");
|
||||
SystemEmail email = new SystemEmail();
|
||||
email.setSubject("集成测试通知");
|
||||
email.setContent("正文");
|
||||
email.setAddress(java.util.Arrays.asList("u-1"));
|
||||
assertNotNull(systemEmailService);
|
||||
// 不抛即通过(降级 no-op + WARN)
|
||||
systemEmailService.sendEmail(email);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user