【物料变更】大批量导入
This commit is contained in:
parent
4613acf253
commit
d7315a9183
|
|
@ -0,0 +1,28 @@
|
|||
package com.nflg.product.material.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
public class RedisTemplateConfig {
|
||||
|
||||
/**
|
||||
* redis 解决key和value前多出一段xACxEDx00
|
||||
* c.r. https://blog.csdn.net/u010667710/article/details/131452820
|
||||
*
|
||||
* @param redisTemplate
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public RedisTemplate<Object, Object> redisStringTemplate(RedisTemplate<Object, Object> redisTemplate) {
|
||||
StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
redisTemplate.setKeySerializer(stringRedisSerializer);
|
||||
// 如果手动将Value转换成了JSON,就不要再用JSON序列化器了。
|
||||
// redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
|
||||
redisTemplate.setValueSerializer(stringRedisSerializer);
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -405,14 +405,12 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
importVO.setInBatches(false);
|
||||
if (lastColIndex == 4) {
|
||||
List<MaterialStateUpExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), MaterialStateUpExcelDTO.class);
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 100) {
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + "1:updateBatchImport"), file.getOriginalFilename());
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + "2:updateBatchImport"), file.getOriginalFilename());
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + "3:updateBatchImport"), file.getOriginalFilename());
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + ":updateBatchImport"), file.getOriginalFilename());
|
||||
// 大数据量,子线程分批次提交OA(每批1000条),主线程提前返回结果给前端
|
||||
CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, 100);
|
||||
List<List<MaterialStateUpExcelDTO>> lists = Lists.partition(excelContext, 1000);
|
||||
lists.forEach(items -> this.handleImportDataForState(items, applyDeptName, deptEnt, realName, userCode));
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("物料变更批量导入耗时(ms): {}", endTime - startTime);
|
||||
|
|
@ -435,6 +433,7 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
// 制作物料
|
||||
List<TwentyMaterialTemplateExcelDTO> excelContext = EecExcelUtil.getExcelContext(file.getInputStream(), TwentyMaterialTemplateExcelDTO.class);
|
||||
if (CollectionUtil.isNotEmpty(excelContext) && excelContext.size() > 1000) {
|
||||
redisTemplate.opsForValue().set(buildKey(userCode + ":updateBatchImport"), file.getOriginalFilename());
|
||||
// 大数据量,子线程分批次提交OA(每批1000条),主线程提前返回结果给前端
|
||||
CompletableFuture<Integer> task1 = CompletableFuture.supplyAsync(() -> {
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
|
@ -442,11 +441,13 @@ public class MaterialUpdateBillService extends ServiceImpl<MaterialUpdateBillMap
|
|||
lists.forEach(items -> this.handleImportDataForSummary(items, applyDeptName, deptEnt, realName, userCode));
|
||||
long endTime = System.currentTimeMillis();
|
||||
log.info("物料变更批量导入耗时(ms): {}", endTime - startTime);
|
||||
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
|
||||
return 1;
|
||||
});
|
||||
task1.exceptionally(ex -> {
|
||||
// 异常处理器,打印异常信息并返回默认值
|
||||
log.error("物料变更批量导入异常: " + ex.getMessage());
|
||||
redisTemplate.delete(buildKey(userCode + ":updateBatchImport"));
|
||||
return -1;
|
||||
});
|
||||
// task1.join(); // 阻塞获取结果
|
||||
|
|
|
|||
Loading…
Reference in New Issue