no message
							parent
							
								
									140cfa1b5b
								
							
						
					
					
						commit
						a13024aaa9
					
				| 
						 | 
					@ -1 +1 @@
 | 
				
			||||||
27324
 | 
					59148
 | 
				
			||||||
| 
						 | 
					@ -1,18 +1,14 @@
 | 
				
			||||||
package com.youchain;
 | 
					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.dto.ApiDictQueryCriteria;
 | 
				
			||||||
import com.youchain.modules.system.service.impl.ApiDictServiceImpl;
 | 
					import com.youchain.modules.system.service.impl.ApiDictServiceImpl;
 | 
				
			||||||
import com.youchain.utils.RedisUtils;
 | 
					 | 
				
			||||||
import com.youchain.utils.SpringContextHolder;
 | 
					import com.youchain.utils.SpringContextHolder;
 | 
				
			||||||
import lombok.extern.slf4j.Slf4j;
 | 
					import lombok.extern.slf4j.Slf4j;
 | 
				
			||||||
import org.springframework.context.ApplicationListener;
 | 
					import org.springframework.context.ApplicationListener;
 | 
				
			||||||
import org.springframework.context.event.ContextRefreshedEvent;
 | 
					import org.springframework.context.event.ContextRefreshedEvent;
 | 
				
			||||||
import org.springframework.stereotype.Component;
 | 
					import org.springframework.stereotype.Component;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @description: ApplicationListener
 | 
					 * @description: ApplicationListener
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,81 +1,72 @@
 | 
				
			||||||
package com.youchain.utils;
 | 
					package com.youchain.utils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.youchain.basicdata.domain.Area;
 | 
				
			||||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
					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 org.springframework.transaction.annotation.Transactional;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import javax.persistence.EntityManager;
 | 
					import java.sql.PreparedStatement;
 | 
				
			||||||
 | 
					import java.sql.SQLException;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Component
 | 
					@Service
 | 
				
			||||||
public class BatchUtils {
 | 
					public class BatchUtils {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private EntityManager entityManager;
 | 
					    private JdbcTemplate jdbcTemplate;
 | 
				
			||||||
 | 
					 | 
				
			||||||
    /**
 | 
					 | 
				
			||||||
     * 批量插入实体。
 | 
					 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 批量更新实体。
 | 
					     * 批量插入库区数据
 | 
				
			||||||
     *
 | 
					 | 
				
			||||||
     * @param entities 要更新的实体列表
 | 
					 | 
				
			||||||
     * @param <T>      实体类型
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @Transactional
 | 
					    @Transactional
 | 
				
			||||||
    public <T> void batchUpdate(List<T> entities, int batchSize) {
 | 
					    public int[] batchInsertAreas(List<Area> areas) {
 | 
				
			||||||
        if (entities.isEmpty()) {
 | 
					        String sql = "insert into base_area (code, name, enabled, dept_id,create_by,update_by,create_time,update_time) VALUES (?, ?, ?, ?,?,?,?,?)";
 | 
				
			||||||
            return;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        for (int i = 0; i < entities.size(); i++) {
 | 
					        return jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {
 | 
				
			||||||
            entityManager.merge(entities.get(i));
 | 
					            @Override
 | 
				
			||||||
 | 
					            public void setValues(PreparedStatement ps, int i) throws SQLException {
 | 
				
			||||||
            if ((i + 1) % batchSize == 0) {
 | 
					                Area area = areas.get(i);
 | 
				
			||||||
                entityManager.flush();
 | 
					                ps.setString(1, area.getCode());
 | 
				
			||||||
                entityManager.clear();
 | 
					                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());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 处理剩余记录
 | 
					            @Override
 | 
				
			||||||
        entityManager.flush();
 | 
					            public int getBatchSize() {
 | 
				
			||||||
        entityManager.clear();
 | 
					                return areas.size();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Transactional
 | 
					    /**
 | 
				
			||||||
    public <T> void batchUpdate(List<T> entities) {
 | 
					     * 批量更新库区域数据(根据ID)
 | 
				
			||||||
        batchUpdate(entities, 500);
 | 
					     */
 | 
				
			||||||
    }
 | 
					    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();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -132,7 +132,7 @@ public class FastExcelUtils {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 读取 Excel 文件头部的所有内容(第一行)
 | 
					     * 读取 Excel 指定目录指定行
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param file Excel 文件
 | 
					     * @param file Excel 文件
 | 
				
			||||||
     * @return 回返指定目录指定行返回的内容
 | 
					     * @return 回返指定目录指定行返回的内容
 | 
				
			||||||
| 
						 | 
					@ -145,7 +145,7 @@ public class FastExcelUtils {
 | 
				
			||||||
                    .headRowNumber(headRowNumber)
 | 
					                    .headRowNumber(headRowNumber)
 | 
				
			||||||
                    .doReadSync();
 | 
					                    .doReadSync();
 | 
				
			||||||
        } catch (IOException e) {
 | 
					        } catch (IOException e) {
 | 
				
			||||||
            throw new BadRequestException("数据格式存在问题,无法读取");
 | 
					            throw new BadRequestException("Excel 文件读取失败: " + e.getMessage());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // 检查是否有数据
 | 
					        // 检查是否有数据
 | 
				
			||||||
| 
						 | 
					@ -153,15 +153,17 @@ public class FastExcelUtils {
 | 
				
			||||||
            throw new BadRequestException("数据为空");
 | 
					            throw new BadRequestException("数据为空");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 获取并验证首行数据
 | 
				
			||||||
        Object firstRow = data.get(0);
 | 
					        Object firstRow = data.get(0);
 | 
				
			||||||
        // 将头部内容转换为字符串列表
 | 
					        if (!(firstRow instanceof Map)) {
 | 
				
			||||||
        if (firstRow instanceof Map) {
 | 
					 | 
				
			||||||
            Map<?, ?> rowMap = (Map<?, ?>) firstRow;
 | 
					 | 
				
			||||||
            return rowMap.values().stream()
 | 
					 | 
				
			||||||
                    .map(value -> value == null ? "" : value.toString())
 | 
					 | 
				
			||||||
                    .collect(Collectors.toList());
 | 
					 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            throw new BadRequestException("读取Excel头部内容格式异常");
 | 
					            throw new BadRequestException("读取Excel头部内容格式异常");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 将头部内容转换为字符串列表
 | 
				
			||||||
 | 
					        Map<?, ?> rowMap = (Map<?, ?>) firstRow;
 | 
				
			||||||
 | 
					        return rowMap.values().stream()
 | 
				
			||||||
 | 
					                .map(value -> value == null ? "" : value.toString())
 | 
				
			||||||
 | 
					                .collect(Collectors.toList());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,7 @@
 | 
				
			||||||
       _                 _           _
 | 
					${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}
 | 
				
			||||||
 :: Spring Boot ::       (v2.6.4)
 | 
					 | 
				
			||||||
| 
						 | 
					@ -6,7 +6,7 @@ spring:
 | 
				
			||||||
  freemarker:
 | 
					  freemarker:
 | 
				
			||||||
    check-template-location: false
 | 
					    check-template-location: false
 | 
				
			||||||
  profiles:
 | 
					  profiles:
 | 
				
			||||||
    active: prod
 | 
					    active: dev
 | 
				
			||||||
  jackson:
 | 
					  jackson:
 | 
				
			||||||
    time-zone: GMT+8
 | 
					    time-zone: GMT+8
 | 
				
			||||||
  data:
 | 
					  data:
 | 
				
			||||||
| 
						 | 
					@ -26,27 +26,31 @@ spring:
 | 
				
			||||||
      hibernate:
 | 
					      hibernate:
 | 
				
			||||||
        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
 | 
					        dialect: org.hibernate.dialect.MySQL5InnoDBDialect
 | 
				
			||||||
        jdbc:
 | 
					        jdbc:
 | 
				
			||||||
          batch_size: 500
 | 
					          batch_size: 1000
 | 
				
			||||||
          batch_versioned_data: true
 | 
					          batch_versioned_data: true
 | 
				
			||||||
          order_inserts: true
 | 
					        order_inserts: true
 | 
				
			||||||
          order_updates: true
 | 
					        order_updates: true
 | 
				
			||||||
          generate_statistics: false
 | 
					        generate_statistics: false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  redis:
 | 
					  redis:
 | 
				
			||||||
    #数据库索引
 | 
					    #数据库索引
 | 
				
			||||||
    database: ${REDIS_DB:1}
 | 
					    #database: ${REDIS_DB:1}
 | 
				
			||||||
    host: ${REDIS_HOST:10.172.64.114}
 | 
					    #host: ${REDIS_HOST:10.172.64.114}
 | 
				
			||||||
    password: ${REDIS_PWD:Youchain@56}
 | 
					    #password: ${REDIS_PWD:Youchain@56}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    #database: ${REDIS_DB:3}
 | 
					    database: ${REDIS_DB:3}
 | 
				
			||||||
    #host: ${REDIS_HOST:127.0.0.1}
 | 
					    host: ${REDIS_HOST:127.0.0.1}
 | 
				
			||||||
    #password: ${REDIS_PWD:}
 | 
					    password: ${REDIS_PWD:Youchain@56}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    port: ${REDIS_PORT:6379}
 | 
					    port: ${REDIS_PORT:6379}
 | 
				
			||||||
    #连接超时时间
 | 
					    #连接超时时间
 | 
				
			||||||
    timeout: 5000
 | 
					    timeout: 5000
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  output:
 | 
				
			||||||
 | 
					    ansi:
 | 
				
			||||||
 | 
					     enabled: ALWAYS
 | 
				
			||||||
 | 
					
 | 
				
			||||||
task:
 | 
					task:
 | 
				
			||||||
  pool:
 | 
					  pool:
 | 
				
			||||||
    # 核心线程池大小
 | 
					    # 核心线程池大小
 | 
				
			||||||
| 
						 | 
					@ -71,3 +75,4 @@ code:
 | 
				
			||||||
rsa:
 | 
					rsa:
 | 
				
			||||||
  private_key: MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEA0vfvyTdGJkdbHkB8mp0f3FE0GYP3AYPaJF7jUd1M0XxFSE2ceK3k2kw20YvQ09NJKk+OMjWQl9WitG9pB6tSCQIDAQABAkA2SimBrWC2/wvauBuYqjCFwLvYiRYqZKThUS3MZ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eyrns8D9UAIdDtp4sUvIADBnWlVtXNt+68a8BnlYptvpW9m0MCJZlmIzxAQY4RrpHnXF29yQB9AuPwjzwIDAQAB
 | 
					  licenseKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxZQwZ6yk55wG10wn1Id34avNXV2VHf4tHM2zRolkfbOKHDRCiv32zMfELIIW91CtzB+1X/u1+3CDl2hDuYPphqLukTyp/1rKoLRoVYnWu2Ti2L+6tiwZMc5AfylAponRA/tSa3ttk+5DebaPOIk9iUTMmDpMR3SBwHGFacU6qWCR1mKxiOk78OL9nC/r24XzfvmWjvcbXs7If9F5ND2VS9e5WeOv6yMFuXSh/V5qZAkyDbEV76Tto21nLuNFLUD3iNcUYeyrns8D9UAIdDtp4sUvIADBnWlVtXNt+68a8BnlYptvpW9m0MCJZlmIzxAQY4RrpHnXF29yQB9AuPwjzwIDAQAB
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue