diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/controller/EquipmentPropertyController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/controller/EquipmentPropertyController.java new file mode 100644 index 0000000..e6f72bb --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/controller/EquipmentPropertyController.java @@ -0,0 +1,103 @@ +package com.bonus.material.devConfig.controller; + +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.devConfig.domain.EquipmentProperty; +import com.bonus.material.devConfig.domain.EquipmentPropertyDTO; +import com.bonus.material.devConfig.service.EquipmentPropertyService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 装备特征值管理 + */ +@RestController +@RequestMapping("/equipment/type/property") +public class EquipmentPropertyController { + + @Autowired + private EquipmentPropertyService equipmentPropertyService; + + /** + * 查询特征值列表 + */ + @GetMapping("/list") + public AjaxResult list() { + List list = equipmentPropertyService.list(); + return AjaxResult.success(list); + } + + /** + * 根据ID查询特征值 + */ + @GetMapping("/{id}") + public AjaxResult getById(@PathVariable Long id) { + EquipmentProperty property = equipmentPropertyService.getById(id); + return AjaxResult.success(property); + } + + /** + * 根据类型ID查询特征值 + */ + @GetMapping("/type/{typeId}") + public AjaxResult getByTypeId(@PathVariable Long typeId) { + List properties = equipmentPropertyService.getByTypeId(typeId); + return AjaxResult.success(properties); + } + + /** + * 根据类型ID查询装备类型及其特征值(扁平化结果) + */ + @GetMapping("/type-with-properties/{typeId}") + public AjaxResult getTypeWithProperties(@PathVariable Long typeId) { + List result = equipmentPropertyService.getTypeWithProperties(typeId); + return AjaxResult.success(result); + } + + /** + * 查询所有装备类型及其特征值(扁平化结果) + */ + @GetMapping("/all-types-with-properties") + public AjaxResult getAllTypesWithProperties() { + List result = equipmentPropertyService.getAllTypesWithProperties(); + return AjaxResult.success(result); + } + + /** + * 查询装备类型详情及其特征值列表(嵌套结构) + */ + @GetMapping("/type-detail-with-properties/{typeId}") + public AjaxResult getTypeDetailWithProperties(@PathVariable Long typeId) { + EquipmentPropertyDTO result = equipmentPropertyService.getTypeDetailWithProperties(typeId); + return AjaxResult.success(result); + } + + /** + * 新增特征值 + */ + @PostMapping + public AjaxResult add(@Validated @RequestBody EquipmentProperty equipmentProperty) { + equipmentPropertyService.add(equipmentProperty); + return AjaxResult.success(); + } + + /** + * 修改特征值 + */ + @PutMapping + public AjaxResult update(@Validated @RequestBody EquipmentProperty equipmentProperty) { + equipmentPropertyService.update(equipmentProperty); + return AjaxResult.success(); + } + + /** + * 删除特征值 + */ + @DeleteMapping("/{id}") + public AjaxResult delete(@PathVariable Integer id) { + equipmentPropertyService.delete(id); + return AjaxResult.success(); + } +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/controller/EquipmentTypeController.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/controller/EquipmentTypeController.java new file mode 100644 index 0000000..7a641de --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/controller/EquipmentTypeController.java @@ -0,0 +1,84 @@ +package com.bonus.material.devConfig.controller; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/11 23:17 + */ + +// EquipmentTypeController.java + + +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.devConfig.domain.PageResult; +import com.bonus.material.devConfig.domain.EquipmentTypeDTO; +import com.bonus.material.devConfig.domain.EquipmentType; +import com.bonus.material.devConfig.domain.EquipmentTypeQuery; +import com.bonus.material.devConfig.service.EquipmentTypeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 装备分类管理 + */ +@RestController +@RequestMapping("/equipment/type") +public class EquipmentTypeController { + + @Autowired + private EquipmentTypeService equipmentTypeService; + + //获取树 + @GetMapping("/tree") + public AjaxResult getEquipmentTree() { + List tree = equipmentTypeService.getEquipmentTypeTree(); + return AjaxResult.success(tree); + } + + //获取层级 + @GetMapping("/cascader") + public AjaxResult getEquipmentCascader() { + List cascaderData = equipmentTypeService.getEquipmentCascader(); + return AjaxResult.success(cascaderData); + } + + //获取列表 + @GetMapping("/list") + public AjaxResult getEquipmentTypeList(EquipmentTypeQuery query) { + PageResult result = equipmentTypeService.getEquipmentTypeList(query); + return AjaxResult.success(result); + } + + //获取详细信息 + @GetMapping("/detail/{id}") + public AjaxResult getEquipmentTypeDetail(@PathVariable Long id) { + EquipmentType detail = equipmentTypeService.getEquipmentTypeDetail(id); + return AjaxResult.success(detail); + } + + //添加 + @PostMapping("/add") + public AjaxResult addEquipmentType(@Validated @RequestBody EquipmentType equipmentType) { + equipmentTypeService.addEquipmentType(equipmentType); + return AjaxResult.success(); + } + + //更新 + @PutMapping("/update") + public AjaxResult updateEquipmentType(@Validated @RequestBody EquipmentType equipmentType) { + equipmentTypeService.updateEquipmentType(equipmentType); + return AjaxResult.success(); + } + + //删除 + @DeleteMapping("/delete/{id}") + public AjaxResult deleteEquipmentType(@PathVariable Long id) { + equipmentTypeService.deleteEquipmentType(id); + return AjaxResult.success(); + } + + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentProperty.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentProperty.java new file mode 100644 index 0000000..3d91d5d --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentProperty.java @@ -0,0 +1,35 @@ +package com.bonus.material.devConfig.domain; + +import lombok.Data; + +import java.util.Date; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/14 16:11 + */ + +@Data +public class EquipmentProperty { + private Long id; + private Long typeId; + private String mustHave; + private Long inputType; + private String propertyName; + private String propertyValue; + private Date createTime; + + @Override + public String toString() { + return "PropertyConfig{" + + "id=" + id + + ", typeId=" + typeId + + ", mustHave='" + mustHave + '\'' + + ", inputType=" + inputType + + ", propertyName='" + propertyName + '\'' + + ", propertyValue='" + propertyValue + '\'' + + ", createTime=" + createTime + + '}'; + } +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentPropertyDTO.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentPropertyDTO.java new file mode 100644 index 0000000..adc3c74 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentPropertyDTO.java @@ -0,0 +1,47 @@ +package com.bonus.material.devConfig.domain; + +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/14 16:41 + */ + +@Data +public class EquipmentPropertyDTO { + + /** + * 装备类型和特征值关联查询结果 + */ + + + // 装备类型信息 + private Long typeId; + private String typeName; + private Long parentId; + private Integer sortOrder; + private String status; + private Integer level; + private Boolean leaf; + + // 特征值信息 + private Integer propertyId; + private String mustHave; + private Integer inputType; + private String propertyName; + private String propertyValue; + private Date propertyCreateTime; + + // 子级特征值列表 + private List properties; + +} + + + + + diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentType.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentType.java new file mode 100644 index 0000000..62fd088 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentType.java @@ -0,0 +1,80 @@ +package com.bonus.material.devConfig.domain; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/11 22:44 + */ + +// EquipmentType.java +import lombok.Data; + +import java.util.Date; +import java.util.List; + +/** + * 装备分类实体 + */ +@Data +public class EquipmentType { + + /** + * 分类ID + */ + private Long typeId; + + /** + * 分类名称 + */ + private String typeName; + + /** + * 父级分类ID + */ + private Long parentId; + + /** + * 排序号 + */ + private Integer sortOrder; + + /** + * 状态(0正常 1停用) + */ + private String status; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 更新时间 + */ + private Date updateTime; + + /** + * 创建人 + */ + private String createBy; + + /** + * 更新人 + */ + private String updateBy; + + /** + * 子分类列表 + */ + private List children; + + /** + * 层级 + */ + private Integer level; + + /** + * 是否叶子节点 + */ + private Boolean leaf; +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentTypeDTO.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentTypeDTO.java new file mode 100644 index 0000000..a47c5e4 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentTypeDTO.java @@ -0,0 +1,27 @@ +package com.bonus.material.devConfig.domain; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/11 22:52 + */ + +// EquipmentTypeDTO.java + +import lombok.Data; + +import java.util.List; + +/** + * 装备分类DTO + */ +@Data +public class EquipmentTypeDTO { + + private Long id; + private String name; + private Long parentId; + private List children; + private Integer level; + private Boolean leaf; +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentTypeQuery.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentTypeQuery.java new file mode 100644 index 0000000..c9fd306 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/EquipmentTypeQuery.java @@ -0,0 +1,25 @@ +package com.bonus.material.devConfig.domain; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/11 22:53 + */ + +// EquipmentTypeQuery.java + + +import lombok.Data; + +/** + * 装备分类查询参数 + */ +@Data +public class EquipmentTypeQuery { + private Long parentId; + private String typeName; + private String status; + private Integer pageNum = 1; + private Integer pageSize = 10; + private Integer offset; +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/PageResult.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/PageResult.java new file mode 100644 index 0000000..8a9969d --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/domain/PageResult.java @@ -0,0 +1,60 @@ +package com.bonus.material.devConfig.domain; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/11 22:55 + */ + +// PageResult.java + +import lombok.Data; + +import java.util.List; + +/** + * 分页结果 + */ +@Data +public class PageResult { + + /** + * 总记录数 + */ + private Long total; + + /** + * 数据列表 + */ + private List rows; + + /** + * 当前页 + */ + private Integer pageNum; + + /** + * 每页大小 + */ + private Integer pageSize; + + /** + * 总页数 + */ + private Integer pages; + + public PageResult() {} + + public PageResult(Long total, List rows) { + this.total = total; + this.rows = rows; + } + + public PageResult(Long total, List rows, Integer pageNum, Integer pageSize) { + this.total = total; + this.rows = rows; + this.pageNum = pageNum; + this.pageSize = pageSize; + this.pages = (int) Math.ceil((double) total / pageSize); + } +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/mapper/EquipmentPropertyMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/mapper/EquipmentPropertyMapper.java new file mode 100644 index 0000000..6dc71c3 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/mapper/EquipmentPropertyMapper.java @@ -0,0 +1,29 @@ +package com.bonus.material.devConfig.mapper; + +import com.bonus.material.devConfig.domain.EquipmentProperty; +import com.bonus.material.devConfig.domain.EquipmentPropertyDTO; + +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface EquipmentPropertyMapper { + void deleteById(Integer id); + + void update(EquipmentProperty equipmentProperty); + + void insert(EquipmentProperty equipmentProperty); + + List selectByTypeId(Long typeId); + + EquipmentProperty selectById(Long id); + + List selectAll(); + + + // 新增关联查询方法 + List selectTypeWithProperties(Long typeId); + List selectAllTypesWithProperties(); + EquipmentPropertyDTO selectTypeDetailWithProperties(Long typeId); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/mapper/EquipmentTypeMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/mapper/EquipmentTypeMapper.java new file mode 100644 index 0000000..4a2c3c0 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/mapper/EquipmentTypeMapper.java @@ -0,0 +1,62 @@ +package com.bonus.material.devConfig.mapper; + +// EquipmentTypeMapper.java + +import com.bonus.material.devConfig.domain.EquipmentType; +import com.bonus.material.devConfig.domain.EquipmentTypeQuery; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 装备分类Mapper + */ +@Mapper +public interface EquipmentTypeMapper { + + /** + * 查询装备分类列表 + */ + List selectEquipmentTypeList(EquipmentTypeQuery query); + + /** + * 查询装备分类数量 + */ + Long countEquipmentTypeList(EquipmentTypeQuery query); + + /** + * 根据父ID查询子分类 + */ + List selectChildrenByParentId(@Param("parentId") Long parentId); + + /** + * 查询所有分类(构建树形结构用) + */ + List selectAllEquipmentTypes(); + + /** + * 根据ID查询分类 + */ + EquipmentType selectEquipmentTypeById(@Param("typeId") Long typeId); + + /** + * 新增装备分类 + */ + int insertEquipmentType(EquipmentType equipmentType); + + /** + * 更新装备分类 + */ + int updateEquipmentType(EquipmentType equipmentType); + + /** + * 删除装备分类 + */ + int deleteEquipmentTypeById(@Param("typeId") Long typeId); + + /** + * 检查是否存在子分类 + */ + Long countChildrenByParentId(@Param("parentId") Long parentId); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/EquipmentPropertyService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/EquipmentPropertyService.java new file mode 100644 index 0000000..6c0dab9 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/EquipmentPropertyService.java @@ -0,0 +1,26 @@ +package com.bonus.material.devConfig.service; + +import com.bonus.material.devConfig.domain.EquipmentProperty; +import com.bonus.material.devConfig.domain.EquipmentPropertyDTO; + +import java.util.List; + +public interface EquipmentPropertyService { + List list(); + + EquipmentProperty getById(Long id); + + List getByTypeId(Long typeId); + + void add(EquipmentProperty equipmentProperty); + + void update(EquipmentProperty equipmentProperty); + + void delete(Integer id); + + List getTypeWithProperties(Long typeId); + + List getAllTypesWithProperties(); + + EquipmentPropertyDTO getTypeDetailWithProperties(Long typeId); +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/EquipmentTypeService.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/EquipmentTypeService.java new file mode 100644 index 0000000..da03f38 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/EquipmentTypeService.java @@ -0,0 +1,31 @@ +package com.bonus.material.devConfig.service; + +// EquipmentTypeService.java + + +import com.bonus.material.devConfig.domain.PageResult; +import com.bonus.material.devConfig.domain.EquipmentTypeDTO; +import com.bonus.material.devConfig.domain.EquipmentType; +import com.bonus.material.devConfig.domain.EquipmentTypeQuery; + +import java.util.List; + +/** + * 装备分类服务 + */ +public interface EquipmentTypeService { + + List getEquipmentTypeTree(); + + List getEquipmentCascader(); + + PageResult getEquipmentTypeList(EquipmentTypeQuery query); + + EquipmentType getEquipmentTypeDetail(Long id); + + void addEquipmentType(EquipmentType equipmentType); + + void updateEquipmentType(EquipmentType equipmentType); + + void deleteEquipmentType(Long id); +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/impl/EquipmentPropertyServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/impl/EquipmentPropertyServiceImpl.java new file mode 100644 index 0000000..5417ed5 --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/impl/EquipmentPropertyServiceImpl.java @@ -0,0 +1,75 @@ +package com.bonus.material.devConfig.service.impl; + +import com.bonus.material.devConfig.domain.EquipmentProperty; +import com.bonus.material.devConfig.domain.EquipmentPropertyDTO; +import com.bonus.material.devConfig.mapper.EquipmentPropertyMapper; +import com.bonus.material.devConfig.service.EquipmentPropertyService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; + +/** + * @author 30791 + * @version 1.0 + * Create by 2025/10/14 16:29 + */ + +@Service +public class EquipmentPropertyServiceImpl implements EquipmentPropertyService { + @Autowired + private EquipmentPropertyMapper equipmentPropertyMapper; + + + @Override + public List list() { + return equipmentPropertyMapper.selectAll(); + } + + @Override + public EquipmentProperty getById(Long id) { + return equipmentPropertyMapper.selectById(id); + } + + @Override + public List getByTypeId(Long typeId) { + return equipmentPropertyMapper.selectByTypeId(typeId); + } + + @Override + public void add(EquipmentProperty equipmentProperty) { + equipmentProperty.setCreateTime(new Date()); + equipmentPropertyMapper.insert(equipmentProperty); + } + + @Override + public void update(EquipmentProperty equipmentProperty) { + equipmentPropertyMapper.update(equipmentProperty); + } + + @Override + public void delete(Integer id) { + equipmentPropertyMapper.deleteById(id); + } + + + + @Override + public List getTypeWithProperties(Long typeId) { + return equipmentPropertyMapper.selectTypeWithProperties(typeId); + } + + @Override + public List getAllTypesWithProperties() { + return equipmentPropertyMapper.selectAllTypesWithProperties(); + } + + @Override + public EquipmentPropertyDTO getTypeDetailWithProperties(Long typeId) { + return equipmentPropertyMapper.selectTypeDetailWithProperties(typeId); + } + + + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/impl/EquipmentTypeServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/impl/EquipmentTypeServiceImpl.java new file mode 100644 index 0000000..d1a299d --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/devConfig/service/impl/EquipmentTypeServiceImpl.java @@ -0,0 +1,160 @@ +package com.bonus.material.devConfig.service.impl; + +import com.bonus.common.core.utils.StringUtils; +import com.bonus.material.devConfig.domain.PageResult; +import com.bonus.material.devConfig.domain.EquipmentTypeDTO; +import com.bonus.material.devConfig.domain.EquipmentType; +import com.bonus.material.devConfig.mapper.EquipmentTypeMapper; +import com.bonus.material.devConfig.domain.EquipmentTypeQuery; +import com.bonus.material.devConfig.service.EquipmentTypeService; +import org.springframework.beans.BeanUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 装备分类服务实现 + */ +@Service +public class EquipmentTypeServiceImpl implements EquipmentTypeService { + + @Autowired + private EquipmentTypeMapper equipmentTypeMapper; + + @Override + public List getEquipmentTypeTree() { + List allTypes = equipmentTypeMapper.selectAllEquipmentTypes(); + List tree = buildTree(allTypes); + return convertToDTOList(tree); + } + + @Override + public List getEquipmentCascader() { + return getEquipmentTypeTree(); + } + + @Override + public PageResult getEquipmentTypeList(EquipmentTypeQuery query) { + // 计算offset,修正分页参数 + if (query.getPageNum() != null && query.getPageSize() != null) { + query.setOffset((query.getPageNum() - 1) * query.getPageSize()); + } + + List list = equipmentTypeMapper.selectEquipmentTypeList(query); + Long total = equipmentTypeMapper.countEquipmentTypeList(query); + return new PageResult<>(total, list, query.getPageNum(), query.getPageSize()); + } + + @Override + public EquipmentType getEquipmentTypeDetail(Long id) { + return equipmentTypeMapper.selectEquipmentTypeById(id); + } + + @Override + @Transactional + public void addEquipmentType(EquipmentType equipmentType) { + // 设置默认值 + + + + // 设置层级,如果没有设置则默认为1 + if (equipmentType.getLevel() == null) { + equipmentType.setLevel(1); + } + + equipmentType.setCreateTime(new Date()); + equipmentType.setUpdateTime(new Date()); + + equipmentTypeMapper.insertEquipmentType(equipmentType); + } + + @Override + @Transactional + public void updateEquipmentType(EquipmentType equipmentType) { + // 1. 校验父ID是否与自身ID相同 + if (equipmentType.getParentId() != null && equipmentType.getParentId().equals(equipmentType.getTypeId())) { + // 抛出异常,阻止更新并回滚事务 + throw new IllegalArgumentException("父分类ID不能与自身ID相同,更新失败。"); + } + + + // 4. 执行正常的更新逻辑 + equipmentType.setUpdateTime(new Date()); + equipmentTypeMapper.updateEquipmentType(equipmentType); + } + + @Override + @Transactional + public void deleteEquipmentType(Long id) { + // 检查是否存在子分类 + Long count = equipmentTypeMapper.countChildrenByParentId(id); + if (count > 0) { + throw new RuntimeException("存在子分类,无法删除"); + } + equipmentTypeMapper.deleteEquipmentTypeById(id); + } + + /** + * 构建树形结构 + */ + private List buildTree(List list) { + List roots = list.stream() + .filter(node -> node.getParentId() == null || node.getParentId() == 0) + .collect(Collectors.toList()); + + for (EquipmentType root : roots) { + buildChildTree(root, list, 1); + } + + return roots; + } + + /** + * 递归构建子树 + */ + private void buildChildTree(EquipmentType parent, List list, int level) { + List children = list.stream() + .filter(node -> parent.getTypeId().equals(node.getParentId())) + .collect(Collectors.toList()); + + parent.setChildren(children); + parent.setLevel(level); + parent.setLeaf(children.isEmpty()); + + for (EquipmentType child : children) { + buildChildTree(child, list, level + 1); + } + } + + /** + * 转换为DTO列表 + */ + private List convertToDTOList(List entities) { + return entities.stream() + .map(this::convertToDTO) + .collect(Collectors.toList()); + } + + /** + * 转换为DTO + */ + private EquipmentTypeDTO convertToDTO(EquipmentType entity) { + EquipmentTypeDTO dto = new EquipmentTypeDTO(); + dto.setId(entity.getTypeId()); + dto.setName(entity.getTypeName()); + dto.setParentId(entity.getParentId()); + dto.setLevel(entity.getLevel()); + dto.setLeaf(entity.getLeaf()); + + if (entity.getChildren() != null && !entity.getChildren().isEmpty()) { + List childDTOs = convertToDTOList(entity.getChildren()); + dto.setChildren(childDTOs); + } + + return dto; + } +} \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devConfig/EquipmentPropertyMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devConfig/EquipmentPropertyMapper.xml new file mode 100644 index 0000000..10e821e --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devConfig/EquipmentPropertyMapper.xml @@ -0,0 +1,197 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + INSERT INTO equipment_property ( + type_id, + must_have, + input_type, + property_name, + property_value, + create_time + ) VALUES ( + #{typeId}, + #{mustHave}, + #{inputType}, + #{propertyName}, + #{propertyValue}, + #{createTime} + ) + + + + + UPDATE equipment_property + + type_id = #{typeId}, + must_have = #{mustHave}, + input_type = #{inputType}, + property_name = #{propertyName}, + property_value = #{propertyValue}, + + WHERE id = #{id} + + + + + DELETE FROM equipment_property + WHERE id = #{id} + + + \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devConfig/EquipmentTypeMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devConfig/EquipmentTypeMapper.xml new file mode 100644 index 0000000..169acfe --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/devConfig/EquipmentTypeMapper.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + type_id, type_name, parent_id, level, create_time, update_time, create_by, update_by + + + + + + + + + + + + + + INSERT INTO ma_type ( + type_name, parent_id, level, create_time, update_time, create_by, update_by + ) VALUES ( + #{typeName}, #{parentId}, #{level}, #{createTime}, #{updateTime}, #{createBy}, #{updateBy} + ) + + + + UPDATE ma_type + + type_name = #{typeName}, + parent_id = #{parentId}, + level = #{level}, + update_time = #{updateTime}, + update_by = #{updateBy} + + WHERE type_id = #{typeId} + + + + DELETE FROM ma_type WHERE type_id = #{typeId} + + + + + \ No newline at end of file