From 572466e8ebaa67f1809a97ecf912d30e8802fd98 Mon Sep 17 00:00:00 2001 From: Lius <Lius2225@163.com> Date: 星期一, 28 四月 2025 14:18:39 +0800 Subject: [PATCH] update --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/LogTableServiceImpl.java | 50 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 30 insertions(+), 20 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..884c72c 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}") @@ -77,6 +70,9 @@ @Value("${fileService.newFilePath}") private String newFilePath; + + @Value("${fileService.failedLocFilePath}") + private String failedLocFilePath; @Resource private IMdcPassLogService mdcPassLogService; @@ -218,16 +214,30 @@ @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); +// throw new JeecgBootException("鎵цsql澶辫触锛�"); + } } + if (!failedSqlList.isEmpty()) { + try { + FileUtil.appendLines(failedSqlList, failedLocFilePath, "UTF-8"); + } catch (Exception e) { + throw new JeecgBootException("鏁版嵁鍐欏叆鏂囦欢澶辫触锛�"); + } + } +// String sqlList = fileReader.readString(); + if (Integer.parseInt(file.getName().substring(file.getName().length() - 10, file.getName().length() - 4)) == 1) { // 鍒犻櫎鍘嗗彶鏂囦欢 FileUtil.clean(newFilePath); -- Gitblit v1.9.3