|
@@ -1,7 +1,9 @@
|
|
|
package com.bz.smart_city.service.importfile;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.bz.smart_city.commom.exception.ServiceException;
|
|
|
import com.bz.smart_city.commom.util.FileUtil;
|
|
|
+import com.bz.smart_city.commom.util.UserUtil;
|
|
|
import com.bz.smart_city.commom.util.Util;
|
|
|
import com.bz.smart_city.dao.*;
|
|
|
import com.bz.smart_city.dao.pay.PayBaseAccountMapper;
|
|
@@ -16,6 +18,7 @@ import com.bz.smart_city.entity.pay.archives.PayBaseCustomerandmeterrela;
|
|
|
import com.bz.smart_city.excel.HandleExcelService;
|
|
|
import com.bz.smart_city.excel.ResolverExcelTemplate;
|
|
|
import com.bz.smart_city.excel.resolver.*;
|
|
|
+import com.bz.smart_city.rabbitmq.model.RabbitCommandParamData;
|
|
|
import com.bz.smart_city.service.*;
|
|
|
import com.bz.smart_city.service.pay.PayBaseAccountService;
|
|
|
import com.bz.smart_city.service.pay.PaySysDictService;
|
|
@@ -24,6 +27,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.springframework.amqp.rabbit.connection.SimpleResourceHolder;
|
|
|
+import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
@@ -96,6 +101,13 @@ public class AsyncTaskImportService {
|
|
|
@Value("${service.domain}")
|
|
|
private String domain;
|
|
|
|
|
|
+ @Value("${spring.rabbitmq.exchange}")
|
|
|
+ private String exchange;
|
|
|
+ @Value("${spring.rabbitmq.command-task-queue}")
|
|
|
+ private String queue;
|
|
|
+ @Autowired
|
|
|
+ private RabbitTemplate rabbitTemplate;
|
|
|
+
|
|
|
protected String getFilePath() {
|
|
|
String name = Util.createUUIDId();
|
|
|
String fullPath = filesPath + "/import/" + name + ".xlsm";
|
|
@@ -107,10 +119,10 @@ public class AsyncTaskImportService {
|
|
|
log.info("begin executeAsyncInstallTask!");
|
|
|
if(sysId == 55){
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(installRemoteMeterResolverExcelService,handleExcelService);
|
|
|
- template.resolver(null,null,record,"新装水表管理-批量添加水表");
|
|
|
+ template.resolver(null,null,record, null,"新装水表管理-批量添加水表");
|
|
|
}else {
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(installResolverExcelService,handleExcelService);
|
|
|
- template.resolver(null,null,record,"新装水表管理-批量添加水表");
|
|
|
+ template.resolver(null,null,record,null, "新装水表管理-批量添加水表");
|
|
|
}
|
|
|
log.info("begin executeAsyncInstallTask!");
|
|
|
}
|
|
@@ -122,15 +134,15 @@ public class AsyncTaskImportService {
|
|
|
Channel channel = channelMapper.findById(sysId);
|
|
|
if(StringUtils.equals("photoelectricMeter",channel.getChannelCode())){
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(gdDeviceResolverExcelService,handleExcelService);
|
|
|
- template.resolver(sysId,null,record,"设备列表-批量添加");
|
|
|
+ template.resolver(sysId,null,record,null,"设备列表-批量添加");
|
|
|
}else {
|
|
|
//判断是否是水表场景
|
|
|
if (wMeterType != null) {
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(waterDeviceResolverExcelService,handleExcelService);
|
|
|
- template.resolver(sysId,null,record,"设备列表-批量添加");
|
|
|
+ template.resolver(sysId,null,record,null,"设备列表-批量添加");
|
|
|
} else {
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(generalDeviceResolverExcelService,handleExcelService);
|
|
|
- template.resolver(sysId,null,record,"设备列表-批量添加");
|
|
|
+ template.resolver(sysId,null,record,null,"设备列表-批量添加");
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -141,12 +153,12 @@ public class AsyncTaskImportService {
|
|
|
@Async
|
|
|
public void executeAsyncBuildingTask(Import record, Integer customerId, MultipartFile file){
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(buildingResolverExcelService,handleExcelService);
|
|
|
- template.resolver(null,customerId,record,"建筑列表-批量添加");
|
|
|
+ template.resolver(null,customerId,record,null,"建筑列表-批量添加");
|
|
|
}
|
|
|
@Async
|
|
|
public void executeAsyncInstallPlanTask(Import record){
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(installPlanResolverExcelService,handleExcelService);
|
|
|
- template.resolver(null,null,record,"装表计划-批量添加");
|
|
|
+ template.resolver(null,null,record,null,"装表计划-批量添加");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -578,17 +590,30 @@ public class AsyncTaskImportService {
|
|
|
@Async
|
|
|
public void executeAsyncConcentratorTask(Import record) {
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(concentratorResolveExcelService,handleExcelService);
|
|
|
- template.resolver(null,null,record,"集中器列表-批量添加");
|
|
|
+ template.resolver(null,null,record,null,"集中器列表-批量添加");
|
|
|
}
|
|
|
|
|
|
@Async
|
|
|
public void executeAsyncCollectorTask(Import record) {
|
|
|
ResolverExcelTemplate template = new ResolverExcelTemplate(collectorResolveExcelService,handleExcelService);
|
|
|
- template.resolver(null,null,record,"采集器列表-批量添加");
|
|
|
+ template.resolver(null,null,record,null,"采集器列表-批量添加");
|
|
|
}
|
|
|
|
|
|
public void executeAsyncCommandTask(Import record) {
|
|
|
- ResolverExcelTemplate template = new ResolverExcelTemplate(commandResolverExcelService,handleExcelService);
|
|
|
- template.resolver(null,null,record,"批量指令下发-指令导入");
|
|
|
+
|
|
|
+ RabbitCommandParamData data = new RabbitCommandParamData();
|
|
|
+ data.setRecordId(record.getId());
|
|
|
+ data.setUsername(UserUtil.getUsername()!=null?UserUtil.getUsername():"系统操作");
|
|
|
+ data.setCustomerIds(UserUtil.getCustomerIds());
|
|
|
+
|
|
|
+
|
|
|
+ String message = JSON.toJSONString(data);
|
|
|
+
|
|
|
+ //设置当前线程lookupKey,内部由ThreadLocal实现
|
|
|
+ SimpleResourceHolder.bind(rabbitTemplate.getConnectionFactory(), "platform");
|
|
|
+ //业务操作会根据线程中的lookupKey从routeConnectionFactory的targetConnectionFactories中选择对应的connectionFactory
|
|
|
+ rabbitTemplate.convertAndSend(exchange,queue, message);
|
|
|
+ //操作完以后记得解绑。不影响线程的后序其他工厂操作
|
|
|
+ SimpleResourceHolder.unbind(rabbitTemplate.getConnectionFactory());
|
|
|
}
|
|
|
}
|