Commit 4515351c authored by suhuiguang's avatar suhuiguang

1.电梯导出多线程

parent 832141da
...@@ -22,5 +22,10 @@ ...@@ -22,5 +22,10 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.16</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -11,4 +11,9 @@ public interface BizCommonConstant { ...@@ -11,4 +11,9 @@ public interface BizCommonConstant {
* 所有平台企业数据redisKey * 所有平台企业数据redisKey
*/ */
String COMPANY_TREE_REDIS_KEY = "REGULATOR_UNIT_TREE"; 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; ...@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils; 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.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.ElevatorDto;
import com.yeejoin.amos.boot.module.elevator.api.dto.ExportDto; import com.yeejoin.amos.boot.module.elevator.api.dto.ExportDto;
import com.yeejoin.amos.boot.module.elevator.api.entity.TemplateExport; import com.yeejoin.amos.boot.module.elevator.api.entity.TemplateExport;
...@@ -15,7 +16,10 @@ import com.yeejoin.amos.boot.module.elevator.api.service.IRescueStationService; ...@@ -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.api.service.IUseUnitService;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.ElevatorServiceImpl; 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.service.impl.VoiceRecordFileServiceImpl;
import com.yeejoin.amos.boot.module.elevator.biz.utils.RedisUtil;
import org.apache.commons.lang3.StringUtils; 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 org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -25,6 +29,7 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController; ...@@ -25,6 +29,7 @@ import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.Executor;
import com.yeejoin.amos.boot.module.elevator.biz.service.impl.TemplateExportServiceImpl; import com.yeejoin.amos.boot.module.elevator.biz.service.impl.TemplateExportServiceImpl;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
...@@ -69,6 +74,12 @@ public class TemplateExportController extends BaseController { ...@@ -69,6 +74,12 @@ public class TemplateExportController extends BaseController {
@Autowired @Autowired
VoiceRecordFileServiceImpl voiceRecordFileServiceImpl; VoiceRecordFileServiceImpl voiceRecordFileServiceImpl;
@Autowired
RedisUtil redisUtil;
@Autowired
Executor customExecutor;
/** /**
* 新增模板表 * 新增模板表
* *
...@@ -177,7 +188,7 @@ public class TemplateExportController extends BaseController { ...@@ -177,7 +188,7 @@ public class TemplateExportController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@ApiOperation(httpMethod = "POST", value = "根据字段类型导出", notes = "根据字段类型导出") @ApiOperation(httpMethod = "POST", value = "根据字段类型导出", notes = "根据字段类型导出")
@PostMapping("/exportByTypeParams") @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()) if (ValidationUtil.isEmpty(exportDto.getExportArray())
|| ValidationUtil.isEmpty(exportDto.getDataType()) || ValidationUtil.isEmpty(exportDto.getDataType())
|| ValidationUtil.isEmpty(exportDto.getFileName()) || ValidationUtil.isEmpty(exportDto.getFileName())
...@@ -206,9 +217,16 @@ public class TemplateExportController extends BaseController { ...@@ -206,9 +217,16 @@ public class TemplateExportController extends BaseController {
heads.add(tempList); heads.add(tempList);
} }
String fileName = exportDto.getFileName(); String fileName = exportDto.getFileName();
if("ELEVATOR".equals(exportDto.getExportType())) { // 查询电梯数据 // 查询电梯数据
list = elevatorServiceImpl.selectExportData(exportDto.getExportId()); if("ELEVATOR".equals(exportDto.getExportType())) {
sheetName = "电梯信息"; 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())) { // 查询维保单位数据 } else if("MAINTENANCE_COMPANY".equals(exportDto.getExportType())) { // 查询维保单位数据
list = iMaintenanceUnitService.selectExportData(exportDto.getExportId()); list = iMaintenanceUnitService.selectExportData(exportDto.getExportId());
sheetName = "维保单位"; sheetName = "维保单位";
...@@ -222,7 +240,6 @@ public class TemplateExportController extends BaseController { ...@@ -222,7 +240,6 @@ public class TemplateExportController extends BaseController {
sheetName = "通话录音"; sheetName = "通话录音";
list = voiceRecordFileServiceImpl.selectExportData(exportDto.getExportId()); 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; package com.yeejoin.amos.boot.module.elevator.biz.core.threadpool;
import org.slf4j.Logger; import org.springframework.context.annotation.Bean;
import org.slf4j.LoggerFactory; import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
/** /**
* 线程池 * 线程池
*/ */
@Configuration
public class AmosThreadPool { public class AmosThreadPool {
/**
* 日志记录器
*/
private static final Logger log = LoggerFactory.getLogger(AmosThreadPool.class);
/** @Bean
* 单例 public Executor customExecutor() {
*/ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
private static AmosThreadPool instance; // 初始核心线程数
executor.setCorePoolSize(10);
/** // 最大线程数
* 执行服务 executor.setMaxPoolSize(20);
*/ // 任务队列容量
private static ExecutorService executorService; executor.setQueueCapacity(50);
// 线程名前缀
/** executor.setThreadNamePrefix("CustomExecutor-");
* 获取单例 executor.initialize();
* return executor;
* @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);
} }
} }
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