no message

main
HUOJIN\92525 2025-09-20 10:34:59 +08:00
parent 140cfa1b5b
commit a13024aaa9
6 changed files with 84 additions and 91 deletions

View File

@ -1 +1 @@
27324
59148

View File

@ -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

View File

@ -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 <T>
*/
@Transactional
public <T> void batchInsert(List<T> 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 <T> void batchInsert(List<T> entities) {
batchInsert(entities, 500);
}
private JdbcTemplate jdbcTemplate;
/**
*
*
* @param entities
* @param <T>
*
*/
@Transactional
public <T> void batchUpdate(List<T> entities, int batchSize) {
if (entities.isEmpty()) {
return;
}
public int[] batchInsertAreas(List<Area> 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 <T> void batchUpdate(List<T> entities) {
batchUpdate(entities, 500);
}
/**
* ID
*/
public int[] batchUpdateAreasById(List<Area> 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();
}
});
}
}

View File

@ -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());
}
}

View File

@ -1,8 +1,7 @@
_ _ _
| | | | (_)
___| |______ __ _ __| |_ __ ___ _ _ __
/ _ | |______/ _` |/ _` | '_ ` _ \| | '_ \
| __| | | (_| | (_| | | | | | | | | | |
\___|_| \__,_|\__,_|_| |_| |_|_|_| |_|
:: Spring Boot :: (v2.6.4)
${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}

View File

@ -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