diff --git a/application.pid b/application.pid index 982cceb..88689c6 100644 --- a/application.pid +++ b/application.pid @@ -1 +1 @@ -27324 \ No newline at end of file +59148 \ No newline at end of file diff --git a/youchain-system/src/main/java/com/youchain/MyApiDictListener.java b/youchain-system/src/main/java/com/youchain/MyApiDictListener.java index 3144b8a..6d0284b 100644 --- a/youchain-system/src/main/java/com/youchain/MyApiDictListener.java +++ b/youchain-system/src/main/java/com/youchain/MyApiDictListener.java @@ -1,18 +1,14 @@ package com.youchain; -import com.youchain.modules.system.service.dto.ApiDictDetailDto; -import com.youchain.modules.system.service.dto.ApiDictDto; import com.youchain.modules.system.service.dto.ApiDictQueryCriteria; import com.youchain.modules.system.service.impl.ApiDictServiceImpl; -import com.youchain.utils.RedisUtils; import com.youchain.utils.SpringContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.stereotype.Component; -import java.util.List; /** * @description: ApplicationListener diff --git a/youchain-system/src/main/java/com/youchain/utils/BatchUtils.java b/youchain-system/src/main/java/com/youchain/utils/BatchUtils.java index 0713b56..6fc153a 100644 --- a/youchain-system/src/main/java/com/youchain/utils/BatchUtils.java +++ b/youchain-system/src/main/java/com/youchain/utils/BatchUtils.java @@ -1,81 +1,72 @@ package com.youchain.utils; +import com.youchain.basicdata.domain.Area; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.persistence.EntityManager; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.util.List; -@Component +@Service public class BatchUtils { @Autowired - private EntityManager entityManager; - - /** - * 批量插入实体。 - * - * @param entities 要插入的实体列表 - * @param 实体类型 - */ - @Transactional - public void batchInsert(List entities, int batchSize) { - if (entities.isEmpty()) { - return; - } - - for (int i = 0; i < entities.size(); i++) { - entityManager.persist(entities.get(i)); - - if ((i + 1) % batchSize == 0) { - entityManager.flush(); - entityManager.clear(); - } - } - - // 处理剩余记录 - entityManager.flush(); - entityManager.clear(); - } - - // 重载方法,使用默认批量大小 - @Transactional - public void batchInsert(List entities) { - batchInsert(entities, 500); - } + private JdbcTemplate jdbcTemplate; /** - * 批量更新实体。 - * - * @param entities 要更新的实体列表 - * @param 实体类型 + * 批量插入库区数据 */ @Transactional - public void batchUpdate(List entities, int batchSize) { - if (entities.isEmpty()) { - return; - } + public int[] batchInsertAreas(List areas) { + String sql = "insert into base_area (code, name, enabled, dept_id,create_by,update_by,create_time,update_time) VALUES (?, ?, ?, ?,?,?,?,?)"; - for (int i = 0; i < entities.size(); i++) { - entityManager.merge(entities.get(i)); - - if ((i + 1) % batchSize == 0) { - entityManager.flush(); - entityManager.clear(); + return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + Area area = areas.get(i); + ps.setString(1, area.getCode()); + ps.setString(2, area.getName()); + ps.setBoolean(3, area.getEnabled()); + ps.setLong(4, area.getDept().getId()); + ps.setString(5, area.getCreateBy()); + ps.setString(6, area.getUpdateBy()); + ps.setTimestamp(7, area.getCreateTime()); + ps.setTimestamp(8, area.getUpdateTime()); } - } - // 处理剩余记录 - entityManager.flush(); - entityManager.clear(); + @Override + public int getBatchSize() { + return areas.size(); + } + }); } - @Transactional - public void batchUpdate(List entities) { - batchUpdate(entities, 500); - } + /** + * 批量更新库区域数据(根据ID) + */ + public int[] batchUpdateAreasById(List areas) { + String sql = "update base_area set name = ?, code = ?, enabled = ? WHERE id = ?"; + return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() { + @Override + public void setValues(PreparedStatement ps, int i) throws SQLException { + Area area = areas.get(i); + ps.setString(1, area.getName()); + ps.setString(2, area.getCode()); + ps.setBoolean(3, area.getEnabled()); + ps.setLong(4, area.getId()); // WHERE条件 + } + + @Override + public int getBatchSize() { + return areas.size(); + } + }); + } } diff --git a/youchain-system/src/main/java/com/youchain/utils/FastExcelUtils.java b/youchain-system/src/main/java/com/youchain/utils/FastExcelUtils.java index 3c05daa..4ad0d99 100644 --- a/youchain-system/src/main/java/com/youchain/utils/FastExcelUtils.java +++ b/youchain-system/src/main/java/com/youchain/utils/FastExcelUtils.java @@ -132,7 +132,7 @@ public class FastExcelUtils { } /** - * 读取 Excel 文件头部的所有内容(第一行) + * 读取 Excel 指定目录指定行 * * @param file Excel 文件 * @return 回返指定目录指定行返回的内容 @@ -145,7 +145,7 @@ public class FastExcelUtils { .headRowNumber(headRowNumber) .doReadSync(); } catch (IOException e) { - throw new BadRequestException("数据格式存在问题,无法读取"); + throw new BadRequestException("Excel 文件读取失败: " + e.getMessage()); } // 检查是否有数据 @@ -153,15 +153,17 @@ public class FastExcelUtils { throw new BadRequestException("数据为空"); } + // 获取并验证首行数据 Object firstRow = data.get(0); - // 将头部内容转换为字符串列表 - if (firstRow instanceof Map) { - Map rowMap = (Map) firstRow; - return rowMap.values().stream() - .map(value -> value == null ? "" : value.toString()) - .collect(Collectors.toList()); - } else { + if (!(firstRow instanceof Map)) { throw new BadRequestException("读取Excel头部内容格式异常"); } + + // 将头部内容转换为字符串列表 + Map rowMap = (Map) firstRow; + return rowMap.values().stream() + .map(value -> value == null ? "" : value.toString()) + .collect(Collectors.toList()); + } } diff --git a/youchain-system/src/main/resources/banner.txt b/youchain-system/src/main/resources/banner.txt index cc460ce..744b11d 100644 --- a/youchain-system/src/main/resources/banner.txt +++ b/youchain-system/src/main/resources/banner.txt @@ -1,8 +1,7 @@ - _ _ _ - | | | | (_) - ___| |______ __ _ __| |_ __ ___ _ _ __ - / _ | |______/ _` |/ _` | '_ ` _ \| | '_ \ - | __| | | (_| | (_| | | | | | | | | | | - \___|_| \__,_|\__,_|_| |_| |_|_|_| |_| - - :: Spring Boot :: (v2.6.4) \ No newline at end of file +${AnsiColor.BRIGHT_BLUE}███╗ ██╗██╗ ██████╗ ███████╗██████╗ ${AnsiColor.DEFAULT} +${AnsiColor.BRIGHT_CYAN}████╗ ██║██║██╔═████╗ ██╔════╝╚════██╗${AnsiColor.DEFAULT} +${AnsiColor.BRIGHT_GREEN}██╔██╗ ██║██║██║██╔██║█████╗█████╗ █████╔╝${AnsiColor.DEFAULT} +${AnsiColor.BRIGHT_YELLOW}██║╚██╗██║██║████╔╝██║╚════╝██╔══╝ ╚═══██╗${AnsiColor.DEFAULT} +${AnsiColor.BRIGHT_RED}██║ ╚████║██║╚██████╔╝ ██║ ██████╔╝${AnsiColor.DEFAULT} +${AnsiColor.BRIGHT_MAGENTA}╚═╝ ╚═══╝╚═╝ ╚═════╝ ╚═╝ ╚═════╝ ${AnsiColor.DEFAULT} +${AnsiColor.BRIGHT_YELLOW}:: Spring Boot :: ${AnsiColor.BRIGHT_YELLOW} (v2.6.4) ${AnsiColor.DEFAULT} \ No newline at end of file diff --git a/youchain-system/src/main/resources/config/application.yml b/youchain-system/src/main/resources/config/application.yml index 824a765..f85fba4 100644 --- a/youchain-system/src/main/resources/config/application.yml +++ b/youchain-system/src/main/resources/config/application.yml @@ -6,7 +6,7 @@ spring: freemarker: check-template-location: false profiles: - active: prod + active: dev jackson: time-zone: GMT+8 data: @@ -26,27 +26,31 @@ spring: hibernate: dialect: org.hibernate.dialect.MySQL5InnoDBDialect jdbc: - batch_size: 500 + batch_size: 1000 batch_versioned_data: true - order_inserts: true - order_updates: true - generate_statistics: false + order_inserts: true + order_updates: true + generate_statistics: false redis: #数据库索引 - database: ${REDIS_DB:1} - host: ${REDIS_HOST:10.172.64.114} - password: ${REDIS_PWD:Youchain@56} + #database: ${REDIS_DB:1} + #host: ${REDIS_HOST:10.172.64.114} + #password: ${REDIS_PWD:Youchain@56} - #database: ${REDIS_DB:3} - #host: ${REDIS_HOST:127.0.0.1} - #password: ${REDIS_PWD:} + database: ${REDIS_DB:3} + host: ${REDIS_HOST:127.0.0.1} + password: ${REDIS_PWD:Youchain@56} port: ${REDIS_PORT:6379} #连接超时时间 timeout: 5000 + output: + ansi: + enabled: ALWAYS + task: pool: # 核心线程池大小 @@ -71,3 +75,4 @@ code: rsa: private_key: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZlebXJiLB+Ue/gUifAAKIg1avttUZsHBHrop4qfJCwAI0+YRAiEA+W3NK/RaXtnRqmoUUkb59zsZUBLpvZgQPfj1MhyHDz0CIQDYhsAhPJ3mgS64NbUZmGWuuNKp5coY2GIj/zYDMJp6vQIgUueLFXv/eZ1ekgz2Oi67MNCk5jeTF2BurZqNLR3MSmUCIFT3Q6uHMtsB9Eha4u7hS31tj1UWE+D+ADzp59MGnoftAiBeHT7gDMuqeJHPL4b+kC+gzV4FGTfhR9q3tTbklZkD2A== licenseKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxZQwZ6yk55wG10wn1Id34avNXV2VHf4tHM2zRolkfbOKHDRCiv32zMfELIIW91CtzB+1X/u1+3CDl2hDuYPphqLukTyp/1rKoLRoVYnWu2Ti2L+6tiwZMc5AfylAponRA/tSa3ttk+5DebaPOIk9iUTMmDpMR3SBwHGFacU6qWCR1mKxiOk78OL9nC/r24XzfvmWjvcbXs7If9F5ND2VS9e5WeOv6yMFuXSh/V5qZAkyDbEV76Tto21nLuNFLUD3iNcUYeyrns8D9UAIdDtp4sUvIADBnWlVtXNt+68a8BnlYptvpW9m0MCJZlmIzxAQY4RrpHnXF29yQB9AuPwjzwIDAQAB +