Commit 4515351c authored by suhuiguang's avatar suhuiguang

1.电梯导出多线程

parent 832141da
......@@ -22,5 +22,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
</dependencies>
</project>
......@@ -11,4 +11,9 @@ public interface BizCommonConstant {
* 所有平台企业数据redisKey
*/
String COMPANY_TREE_REDIS_KEY = "REGULATOR_UNIT_TREE";
/**
* 电梯数据key
*/
String OLD_ELEVATOR_REDIS_KEY = "OLD_ELEVATOR_REDIS_KEY";
}
......@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.common.api.excel.ExcelUtil;
import com.yeejoin.amos.boot.module.elevator.api.common.BizCommonConstant;
import com.yeejoin.amos.boot.module.elevator.api.dto.ElevatorDto;
import com.yeejoin.amos.boot.module.elevator.api.dto.ExportDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.TemplateExport;
......@@ -15,7 +16,10 @@ import com.yeejoin.amos.boot.module.elevator.api.service.IRescueStationService;
import com.yeejoin.amos.boot.module.elevator.api.service.IUseUnitService;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.ElevatorServiceImpl;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.VoiceRecordFileServiceImpl;
import com.yeejoin.amos.boot.module.elevator.biz.utils.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.StopWatch;
import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
......@@ -25,6 +29,7 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executor;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.TemplateExportServiceImpl;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
......@@ -69,6 +74,12 @@ public class TemplateExportController extends BaseController {
@Autowired
VoiceRecordFileServiceImpl voiceRecordFileServiceImpl;
@Autowired
RedisUtil redisUtil;
@Autowired
Executor customExecutor;
/**
* 新增模板表
*
......@@ -177,7 +188,7 @@ public class TemplateExportController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "POST", value = "根据字段类型导出", notes = "根据字段类型导出")
@PostMapping("/exportByTypeParams")
public void exportByTypeParams(@RequestBody ExportDto exportDto, HttpServletResponse response) {
public void exportByTypeParams(@RequestBody ExportDto exportDto, HttpServletResponse response) throws Exception {
if (ValidationUtil.isEmpty(exportDto.getExportArray())
|| ValidationUtil.isEmpty(exportDto.getDataType())
|| ValidationUtil.isEmpty(exportDto.getFileName())
......@@ -206,9 +217,16 @@ public class TemplateExportController extends BaseController {
heads.add(tempList);
}
String fileName = exportDto.getFileName();
if("ELEVATOR".equals(exportDto.getExportType())) { // 查询电梯数据
list = elevatorServiceImpl.selectExportData(exportDto.getExportId());
sheetName = "电梯信息";
// 查询电梯数据
if("ELEVATOR".equals(exportDto.getExportType())) {
if(redisUtil.hasKey(BizCommonConstant.OLD_ELEVATOR_REDIS_KEY)){
list = JSONObject.parseArray(redisUtil.get(BizCommonConstant.OLD_ELEVATOR_REDIS_KEY).toString(),ElevatorDto.class);
} else {
list = elevatorServiceImpl.selectExportData(exportDto.getExportId());
redisUtil.set(BizCommonConstant.OLD_ELEVATOR_REDIS_KEY,JSONObject.toJSONString(list));
}
ExcelUtil.exportWithMplThread2(response,fileName,list,heads,exportDto.getFileType(),customExecutor,10);
return;
} else if("MAINTENANCE_COMPANY".equals(exportDto.getExportType())) { // 查询维保单位数据
list = iMaintenanceUnitService.selectExportData(exportDto.getExportId());
sheetName = "维保单位";
......@@ -222,7 +240,6 @@ public class TemplateExportController extends BaseController {
sheetName = "通话录音";
list = voiceRecordFileServiceImpl.selectExportData(exportDto.getExportId());
}
ExcelUtil.createTemplateWithHeaders(response, fileName, sheetName, list, heads, headstr, exportDto.getFileType());
ExcelUtil.createTemplateWithHeaders(response, fileName, sheetName, list,heads,headstr,exportDto.getFileType());
}
}
package com.yeejoin.amos.boot.module.elevator.biz.core.threadpool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Executor;
/**
* 线程池
*/
@Configuration
public class AmosThreadPool {
/**
* 日志记录器
*/
private static final Logger log = LoggerFactory.getLogger(AmosThreadPool.class);
/**
* 单例
*/
private static AmosThreadPool instance;
/**
* 执行服务
*/
private static ExecutorService executorService;
/**
* 获取单例
*
* @return
*/
public static AmosThreadPool getInstance() {
if (instance == null) {
synchronized (AmosThreadPool.class) {
if (instance == null) {
instance = new AmosThreadPool();
}
}
}
return instance;
}
static {
executorService = Executors
.newFixedThreadPool(20);
}
/**
* 执行线程
*
* @param task
*/
public void execute(Runnable task) {
executorService.execute(task);
@Bean
public Executor customExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
// 初始核心线程数
executor.setCorePoolSize(10);
// 最大线程数
executor.setMaxPoolSize(20);
// 任务队列容量
executor.setQueueCapacity(50);
// 线程名前缀
executor.setThreadNamePrefix("CustomExecutor-");
executor.initialize();
return executor;
}
}
package com.yeejoin.amos.boot.module.elevator.biz.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.module.elevator.api.common.BizCommonConstant;
import com.yeejoin.amos.boot.module.elevator.api.dto.ElevatorDto;
import com.yeejoin.amos.boot.module.elevator.biz.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class ElevatorAppRunner implements ApplicationRunner {
@Autowired
RedisUtil redisUtil;
@Autowired
ElevatorServiceImpl elevatorServiceImpl;
@Override
public void run(ApplicationArguments args) {
// 缓存电梯数据
List<ElevatorDto> list = elevatorServiceImpl.selectExportData(null);
redisUtil.set(BizCommonConstant.OLD_ELEVATOR_REDIS_KEY, JSONObject.toJSONString(list));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment