feat: 新增智能柜详情接口及MQTT连接复用逻辑
- 新增智能柜详情接口,支持通过ID获取智能柜详细信息 - 添加MQTT连接复用逻辑,避免重复创建相同连接的客户端实例 - 新增CabinetTemplateEnum枚举类,定义智能柜模板类型
This commit is contained in:
parent
3fe5778ea0
commit
e4235e197b
|
@ -5,6 +5,7 @@ import com.agileboot.common.core.base.BaseController;
|
||||||
import com.agileboot.common.core.dto.ResponseDTO;
|
import com.agileboot.common.core.dto.ResponseDTO;
|
||||||
import com.agileboot.common.core.page.PageDTO;
|
import com.agileboot.common.core.page.PageDTO;
|
||||||
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
import com.agileboot.common.enums.common.BusinessTypeEnum;
|
||||||
|
import com.agileboot.domain.ab98.user.dto.Ab98UserDetailDTO;
|
||||||
import com.agileboot.domain.cabinet.cell.CabinetCellApplicationService;
|
import com.agileboot.domain.cabinet.cell.CabinetCellApplicationService;
|
||||||
import com.agileboot.domain.cabinet.cell.dto.CabinetCellDTO;
|
import com.agileboot.domain.cabinet.cell.dto.CabinetCellDTO;
|
||||||
import com.agileboot.domain.cabinet.smartCabinet.dto.AllCabinetDataDTO;
|
import com.agileboot.domain.cabinet.smartCabinet.dto.AllCabinetDataDTO;
|
||||||
|
@ -46,6 +47,13 @@ public class SmartCabinetController extends BaseController {
|
||||||
return ResponseDTO.ok(page);
|
return ResponseDTO.ok(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "智能柜详情")
|
||||||
|
@GetMapping("/detail/{cabinetId}")
|
||||||
|
public ResponseDTO<SmartCabinetDTO> detail(@PathVariable Long cabinetId) {
|
||||||
|
SmartCabinetDTO smartCabinetDTO = smartCabinetApplicationService.getSmartCabinetById(cabinetId);
|
||||||
|
return ResponseDTO.ok(smartCabinetDTO);
|
||||||
|
}
|
||||||
|
|
||||||
@Operation(summary = "新增智能柜")
|
@Operation(summary = "新增智能柜")
|
||||||
@AccessLog(title = "智能柜管理", businessType = BusinessTypeEnum.ADD)
|
@AccessLog(title = "智能柜管理", businessType = BusinessTypeEnum.ADD)
|
||||||
@PostMapping
|
@PostMapping
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.agileboot.domain.cabinet.smartCabinet;
|
||||||
|
|
||||||
|
public enum CabinetTemplateEnum {
|
||||||
|
CABINET_16(1, "cabinet_16.jpg", "16口机柜"),
|
||||||
|
CABINET_20(2, "cabinet_20.jpg", "20口机柜"),
|
||||||
|
CABINET_22(3, "cabinet_22.jpg", "22口机柜"),
|
||||||
|
CABINET_24(4, "cabinet_24.jpg", "24口机柜"),
|
||||||
|
CABINET_40(5, "cabinet_40.jpg", "40口机柜"),
|
||||||
|
CABINET_48(6, "cabinet_48.jpg", "48口机柜"),
|
||||||
|
CABINET_60(7, "cabinet_60.jpg", "60口机柜"),
|
||||||
|
CABINET_120(8, "cabinet_120.jpg", "120口机柜");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String img;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
CabinetTemplateEnum(int code, String img, String name) {
|
||||||
|
this.code = code;
|
||||||
|
this.img = img;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImg() {
|
||||||
|
return img;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -53,6 +53,26 @@ public class SmartCabinetApplicationService {
|
||||||
return new PageDTO<>(dtoList, page.getTotal());
|
return new PageDTO<>(dtoList, page.getTotal());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SmartCabinetDTO getSmartCabinetById(Long cabinetId) {
|
||||||
|
SmartCabinetEntity cabinet = smartCabinetService.getById(cabinetId);
|
||||||
|
SmartCabinetDTO dto = new SmartCabinetDTO(cabinet);
|
||||||
|
|
||||||
|
List<ShopEntity> shopEntities = shopService.selectAll();
|
||||||
|
dto.setShopName(
|
||||||
|
shopEntities.stream()
|
||||||
|
.filter(shop -> shop.getShopId().equals(dto.getShopId()))
|
||||||
|
.findFirst()
|
||||||
|
.map(ShopEntity::getShopName)
|
||||||
|
.orElse("")
|
||||||
|
);
|
||||||
|
|
||||||
|
SmartCabinetEntity mainCabinet = smartCabinetService.getByCabinetId(cabinet.getMainCabinet());
|
||||||
|
if (mainCabinet!= null) {
|
||||||
|
dto.setMainCabinetName(mainCabinet.getCabinetName());
|
||||||
|
}
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
public void addSmartCabinet(AddSmartCabinetCommand command) {
|
public void addSmartCabinet(AddSmartCabinetCommand command) {
|
||||||
SmartCabinetModel model = smartCabinetModelFactory.create();
|
SmartCabinetModel model = smartCabinetModelFactory.create();
|
||||||
model.loadAddCommand(command);
|
model.loadAddCommand(command);
|
||||||
|
|
|
@ -25,6 +25,12 @@ public class MqttService implements MqttCallback {
|
||||||
private static class ClientConfig {
|
private static class ClientConfig {
|
||||||
private final MqttClient client;
|
private final MqttClient client;
|
||||||
private final MqttServerEntity config;
|
private final MqttServerEntity config;
|
||||||
|
|
||||||
|
public boolean isSameConnection(MqttServerEntity other) {
|
||||||
|
return config.getServerUrl().equals(other.getServerUrl())
|
||||||
|
&& config.getUsername().equals(other.getUsername())
|
||||||
|
&& config.getPassword().equals(other.getPassword());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -51,6 +57,18 @@ public class MqttService implements MqttCallback {
|
||||||
|
|
||||||
public void connect() throws MqttException {
|
public void connect() throws MqttException {
|
||||||
for (MqttServerEntity config : mqttServerService.selectAll()) {
|
for (MqttServerEntity config : mqttServerService.selectAll()) {
|
||||||
|
// 检查是否已有相同连接的client实例
|
||||||
|
ClientConfig existingConfig = clientConfigs.stream()
|
||||||
|
.filter(cc -> cc.isSameConnection(config))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (existingConfig != null) {
|
||||||
|
log.info("复用已有MQTT连接:{} 账号:{}", config.getServerUrl(), config.getUsername());
|
||||||
|
clientConfigs.add(new ClientConfig(existingConfig.client, config));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
MqttClient client = new MqttClient(config.getServerUrl(), MqttClient.generateClientId(), new MemoryPersistence());
|
MqttClient client = new MqttClient(config.getServerUrl(), MqttClient.generateClientId(), new MemoryPersistence());
|
||||||
MqttConnectOptions options = new MqttConnectOptions();
|
MqttConnectOptions options = new MqttConnectOptions();
|
||||||
options.setUserName(config.getUsername());
|
options.setUserName(config.getUsername());
|
||||||
|
|
Loading…
Reference in New Issue