From f73f8cb6753f8d8ab2c689b4640cd2688e6f6f62 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期二, 16 九月 2025 11:06:42 +0800 Subject: [PATCH] update --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java | 50 ++++++++++++++++++++++++++++---------------------- 1 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java index 87eac22..e6578f1 100644 --- a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java @@ -2,26 +2,23 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.file.FileReader; -import cn.hutool.core.io.file.FileWriter; -import cn.hutool.core.net.NetUtil; import cn.hutool.crypto.SmUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import me.zhyd.oauth.log.Log; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; import org.jeecg.common.exception.JeecgBootException; -import org.jeecg.modules.mdc.util.SqlExecutor; -import org.jeecg.modules.system.vo.SysLogTypeObjectDto; import org.jeecg.modules.mdc.entity.LogTable; -import org.jeecg.modules.system.entity.MdcPassLog; import org.jeecg.modules.mdc.mapper.LogTableMapper; import org.jeecg.modules.mdc.service.ILogTableService; -import org.jeecg.modules.system.service.IMdcPassLogService; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.util.FileClient; -import org.jeecg.modules.system.util.FileUtils; +import org.jeecg.modules.mdc.util.SqlExecutor; import org.jeecg.modules.mdc.util.SyslogClient; -import org.springframework.beans.factory.annotation.Autowired; +import org.jeecg.modules.system.entity.MdcPassLog; +import org.jeecg.modules.system.service.IMdcPassLogService; +import org.jeecg.modules.system.util.FileUtils; +import org.jeecg.modules.system.vo.SysLogTypeObjectDto; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -29,20 +26,16 @@ import javax.annotation.Resource; import java.io.File; import java.net.InetAddress; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.sql.Connection; -import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; -import java.util.stream.Stream; /** * @author Lius * @date 2024/12/18 14:29 */ @Service +@Slf4j public class LogTableServiceImpl extends ServiceImpl<LogTableMapper, LogTable> implements ILogTableService { @Value("${fileService.localFilePath}") @@ -78,6 +71,9 @@ @Value("${fileService.newFilePath}") private String newFilePath; + @Value("${fileService.failedLocFilePath}") + private String failedLocFilePath; + @Resource private IMdcPassLogService mdcPassLogService; @@ -111,8 +107,6 @@ // 鏂囦欢璺緞 String locFilePath = localFilePath + TYPE + today + String.format("%06d", sequenceNumber) + ".xml"; -// FileWriter writer = new FileWriter(locFilePath); -// writer.writeLines(sqlList); String listSql = String.join("\n", sqlList); try { FileUtils.fileWriterSql(locFilePath, listSql); @@ -218,16 +212,28 @@ @Transactional(rollbackFor = Exception.class) public void importXmlToData() { File[] files = FileUtil.ls(localFilePath); + List<String> failedSqlList = new ArrayList<>(); // 鐢ㄤ簬瀛樺偍鎵ц澶辫触鐨� SQL for (File file : files) { if (file.isFile()) { String loFilePath = localFilePath + file.getName(); FileReader fileReader = new FileReader(loFilePath); - String sqlList = fileReader.readString(); - try { - sqlExecutor.execute(sqlList); - } catch (Exception e) { - throw new JeecgBootException("鎵цsql澶辫触锛�"); + List<String> sqlList = fileReader.readLines(); + log.info("鎴愬姛璇诲彇鍒皗}鏉ql,鎵ц鎿嶄綔", sqlList.size()); + for (String sql : sqlList) { + try { + sqlExecutor.execute(sql); + } catch (Exception e) { + failedSqlList.add(sql); + } } + if (!failedSqlList.isEmpty()) { + try { + FileUtil.appendLines(failedSqlList, failedLocFilePath, "UTF-8"); + } catch (Exception e) { + throw new JeecgBootException("鏁版嵁鍐欏叆鏂囦欢澶辫触锛�"); + } + } + if (Integer.parseInt(file.getName().substring(file.getName().length() - 10, file.getName().length() - 4)) == 1) { // 鍒犻櫎鍘嗗彶鏂囦欢 FileUtil.clean(newFilePath); -- Gitblit v1.9.3