feat(智能机柜): 新增机柜模板枚举类和单元格编号字段
在CabinetTemplateEnum中添加了新的机柜模板类型,并增加了每块主板的单元格数量字段。同时在CabinetDetailDTO.CellInfoDTO中新增了cellNo字段,用于标识单元格编号。这些改动是为了支持更灵活的机柜配置和单元格管理。
This commit is contained in:
parent
b103184a1e
commit
ed6d2748fc
agileboot-domain/src/main/java/com/agileboot/domain/cabinet/smartCabinet
|
@ -1,41 +1,102 @@
|
|||
package com.agileboot.domain.cabinet.smartCabinet;
|
||||
|
||||
/**
|
||||
* 机柜模板枚举类
|
||||
* 定义了系统中支持的各种机柜模板类型
|
||||
*/
|
||||
public enum CabinetTemplateEnum {
|
||||
CABINET_16(1, "cabinet_16.jpg", "16口机柜", 1),
|
||||
CABINET_20(2, "cabinet_20.jpg", "20口机柜", 1),
|
||||
CABINET_22(3, "cabinet_22.jpg", "22口机柜", 1),
|
||||
CABINET_24(4, "cabinet_24.jpg", "24口机柜", 1),
|
||||
CABINET_40(5, "cabinet_40.jpg", "40口机柜", 2),
|
||||
CABINET_48(6, "cabinet_48.jpg", "48口机柜", 2),
|
||||
CABINET_60(7, "cabinet_60.jpg", "60口机柜", 4),
|
||||
CABINET_120(8, "cabinet_120.jpg", "120口机柜", 6),
|
||||
CABINET_4(9, "cabinet_4.jpg","4口机柜", 1);
|
||||
/** 16口机柜模板,1块主板,每块主板16个单元格 */
|
||||
CABINET_16(1, "cabinet_16.jpg", "16口机柜", 1, 16),
|
||||
/** 20口机柜模板,1块主板,每块主板20个单元格 */
|
||||
CABINET_20(2, "cabinet_20.jpg", "20口机柜", 1, 20),
|
||||
/** 22口机柜模板,1块主板,每块主板22个单元格 */
|
||||
CABINET_22(3, "cabinet_22.jpg", "22口机柜", 1, 22),
|
||||
/** 24口机柜模板,1块主板,每块主板24个单元格 */
|
||||
CABINET_24(4, "cabinet_24.jpg", "24口机柜", 1, 24),
|
||||
/** 40口机柜模板,2块主板,每块主板20个单元格 */
|
||||
CABINET_40(5, "cabinet_40.jpg", "40口机柜", 2, 20),
|
||||
/** 48口机柜模板,2块主板,每块主板24个单元格 */
|
||||
CABINET_48(6, "cabinet_48.jpg", "48口机柜", 2, 24),
|
||||
/** 60口机柜模板,2块主板,每块主板30个单元格 */
|
||||
CABINET_60(7, "cabinet_60.jpg", "60口机柜", 2, 30),
|
||||
/** 120口机柜模板(6X20),6块主板,每块主板20个单元格 */
|
||||
CABINET_6X20(8, "cabinet_120_6X20.jpg", "120口机柜6X20", 6, 20),
|
||||
/** 4口机柜模板,1块主板,每块主板4个单元格 */
|
||||
CABINET_4(9, "cabinet_4.jpg","4口机柜", 1, 4),
|
||||
/** 120口机柜模板(4X30),4块主板,每块主板30个单元格 */
|
||||
CABINET_4X30(10, "cabinet_120_4X30.jpg", "120口机柜4X30", 4, 30);
|
||||
|
||||
/** 模板代码 */
|
||||
private final int code;
|
||||
/** 模板图片名称 */
|
||||
private final String img;
|
||||
/** 模板名称 */
|
||||
private final String name;
|
||||
/** 主板数量 */
|
||||
private final int boardCount;
|
||||
/** 每块主板的单元格数量 */
|
||||
private final int cellsPerBoard;
|
||||
|
||||
CabinetTemplateEnum(int code, String img, String name, int boardCount) {
|
||||
CabinetTemplateEnum(int code, String img, String name, int boardCount, int cellsPerBoard) {
|
||||
this.code = code;
|
||||
this.img = img;
|
||||
this.name = name;
|
||||
this.boardCount = boardCount;
|
||||
this.cellsPerBoard = cellsPerBoard;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板代码
|
||||
* @return 模板代码
|
||||
*/
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板图片名称
|
||||
* @return 模板图片名称
|
||||
*/
|
||||
public String getImg() {
|
||||
return img;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取模板名称
|
||||
* @return 模板名称
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主板数量
|
||||
* @return 主板数量
|
||||
*/
|
||||
public int getBoardCount() {
|
||||
return boardCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取每块主板的单元格数量
|
||||
* @return 每块主板的单元格数量
|
||||
*/
|
||||
public int getCellsPerBoard() {
|
||||
return cellsPerBoard;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据模板代码获取枚举实例
|
||||
* @param code 模板代码
|
||||
* @return 对应的枚举实例,如果不存在则返回null
|
||||
*/
|
||||
public static CabinetTemplateEnum getByCode(int code) {
|
||||
for (CabinetTemplateEnum value : values()) {
|
||||
if (value.getCode() == code) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
package com.agileboot.domain.cabinet.smartCabinet;
|
||||
|
||||
import com.agileboot.common.core.page.PageDTO;
|
||||
import com.agileboot.domain.cabinet.cell.command.AddCabinetCellCommand;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellEntity;
|
||||
import com.agileboot.domain.cabinet.cell.db.CabinetCellService;
|
||||
import com.agileboot.domain.cabinet.cell.model.CabinetCellModel;
|
||||
import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory;
|
||||
import com.agileboot.domain.cabinet.mainboard.command.AddCabinetMainboardCommand;
|
||||
import com.agileboot.domain.cabinet.mainboard.model.CabinetMainboardModel;
|
||||
import com.agileboot.domain.cabinet.mainboard.model.CabinetMainboardModelFactory;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.dto.CabinetDetailDTO;
|
||||
import com.agileboot.domain.common.command.BulkOperationCommand;
|
||||
import com.agileboot.domain.cabinet.smartCabinet.command.AddSmartCabinetCommand;
|
||||
|
@ -33,6 +39,8 @@ public class SmartCabinetApplicationService {
|
|||
private final CabinetCellService cabinetCellService;
|
||||
private final ShopGoodsService shopGoodsService;
|
||||
private final ShopService shopService;
|
||||
private final CabinetMainboardModelFactory cabinetMainboardModelFactory;
|
||||
private final CabinetCellModelFactory cabinetCellModelFactory;
|
||||
|
||||
public PageDTO<SmartCabinetDTO> getSmartCabinetList(SearchSmartCabinetQuery<SmartCabinetEntity> query) {
|
||||
List<ShopEntity> shopEntities = shopService.selectAll();
|
||||
|
@ -75,8 +83,17 @@ public class SmartCabinetApplicationService {
|
|||
|
||||
public void addSmartCabinet(AddSmartCabinetCommand command) {
|
||||
SmartCabinetModel model = smartCabinetModelFactory.create();
|
||||
if (command.getLockControlNo() == null) {
|
||||
command.setLockControlNo(1);
|
||||
}
|
||||
if (command.getLocation() == null) {
|
||||
command.setLocation(1);
|
||||
}
|
||||
model.loadAddCommand(command);
|
||||
model.insert();
|
||||
|
||||
List<CabinetMainboardModel> mainboardModels = createCabinetMainboardByTemplate(model);
|
||||
createCabinetCellsByTemplate(model, mainboardModels);
|
||||
}
|
||||
|
||||
public void updateSmartCabinet(UpdateSmartCabinetCommand command) {
|
||||
|
@ -122,6 +139,7 @@ public class SmartCabinetApplicationService {
|
|||
CabinetDetailDTO.CellInfoDTO cellInfo = new CabinetDetailDTO.CellInfoDTO();
|
||||
// 设置单元格基础信息
|
||||
cellInfo.setCellId(cell.getCellId());
|
||||
cellInfo.setCellNo(cell.getCellNo());
|
||||
cellInfo.setPinNo(cell.getPinNo());
|
||||
cellInfo.setStock(cell.getStock());
|
||||
|
||||
|
@ -150,7 +168,54 @@ public class SmartCabinetApplicationService {
|
|||
return result;
|
||||
}
|
||||
|
||||
public void createCabinetMainboardByTemplate(Long cabinetId) {
|
||||
SmartCabinetModel cabinetModel = smartCabinetModelFactory.loadById(cabinetId);
|
||||
public List<CabinetMainboardModel> createCabinetMainboardByTemplate(SmartCabinetModel cabinetModel) {
|
||||
CabinetTemplateEnum template = CabinetTemplateEnum.getByCode(Integer.parseInt(cabinetModel.getTemplateNo()));
|
||||
if (template == null) {
|
||||
throw new IllegalArgumentException("Invalid template code");
|
||||
}
|
||||
|
||||
List<CabinetMainboardModel> result = new ArrayList<>();
|
||||
for (int i = 1; i <= template.getBoardCount(); i++) {
|
||||
CabinetMainboardModel mainboardModel = cabinetMainboardModelFactory.create();
|
||||
AddCabinetMainboardCommand command = new AddCabinetMainboardCommand();
|
||||
command.initBaseEntity();
|
||||
command.setCabinetId(cabinetModel.getCabinetId());
|
||||
command.setLockControlNo(i);
|
||||
mainboardModel.loadAddCommand(command);
|
||||
mainboardModel.insert();
|
||||
result.add(mainboardModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<CabinetCellModel> createCabinetCellsByTemplate(SmartCabinetModel cabinetModel, List<CabinetMainboardModel> mainboards) {
|
||||
CabinetTemplateEnum template = CabinetTemplateEnum.getByCode(Integer.parseInt(cabinetModel.getTemplateNo()));
|
||||
if (template == null) {
|
||||
throw new IllegalArgumentException("Invalid template code");
|
||||
}
|
||||
|
||||
List<CabinetCellModel> result = new ArrayList<>();
|
||||
|
||||
int cell_no = 1;
|
||||
for (CabinetMainboardModel mainboard : mainboards) {
|
||||
for (int i = 1; i <= template.getCellsPerBoard(); i++) {
|
||||
CabinetCellModel cellModel = cabinetCellModelFactory.create();
|
||||
AddCabinetCellCommand command = new AddCabinetCellCommand();
|
||||
command.initBaseEntity();
|
||||
command.setCabinetId(cabinetModel.getCabinetId());
|
||||
command.setMainboardId(mainboard.getMainboardId());
|
||||
command.setCellNo(cell_no);
|
||||
cell_no++;
|
||||
command.setPinNo(i);
|
||||
command.setStock(0);
|
||||
command.setCellType(1);
|
||||
command.setUsageStatus(1);
|
||||
command.setAvailableStatus(1);
|
||||
cellModel.loadAddCommand(command);
|
||||
cellModel.insert();
|
||||
result.add(cellModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ public class CabinetDetailDTO {
|
|||
@Data
|
||||
public static class CellInfoDTO {
|
||||
private Long cellId;
|
||||
private Integer cellNo;
|
||||
private Integer pinNo;
|
||||
private Integer stock;
|
||||
private ProductInfoDTO product;
|
||||
|
|
Loading…
Reference in New Issue