diff --git a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeNode.java b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeNode.java index 9d1e102..07f2ba3 100644 --- a/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeNode.java +++ b/bonus-common-biz/src/main/java/com/bonus/common/biz/domain/TreeNode.java @@ -48,6 +48,8 @@ public class TreeNode { private String remark; + private List propertyNames; + @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children = new ArrayList<>(); } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java index fe2e48a..264e631 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/home/service/impl/MaTypeInfoServiceImpl.java @@ -8,13 +8,19 @@ import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.device.domain.vo.DevInfoVo; import com.bonus.material.home.mapper.MaTypeInfoMapper; import com.bonus.material.home.service.MaTypeInfoSevice; +import com.bonus.material.ma.mapper.MaTypeMapper; +import com.bonus.material.ma.vo.MaType; +import com.bonus.material.ma.vo.MaTypeProperty; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; @Service @Slf4j @@ -23,6 +29,9 @@ public class MaTypeInfoServiceImpl implements MaTypeInfoSevice { @Resource private MaTypeInfoMapper maTypeInfoMapper; + @Resource + private MaTypeMapper maTypeMapper; + /** * 首页查询分类树 * @return @@ -33,6 +42,8 @@ public class MaTypeInfoServiceImpl implements MaTypeInfoSevice { List list = new ArrayList<>(); try { list = maTypeInfoMapper.getMaTypeInfoList(typeInfo); + //填充自定义属性 + fillProperties(list); if (CollectionUtils.isNotEmpty(list)) { // 创建树形结构(数据集合作为参数) TreeBuild treeBuild = new TreeBuild(list); @@ -45,6 +56,20 @@ public class MaTypeInfoServiceImpl implements MaTypeInfoSevice { return AjaxResult.success(groupList); } + private void fillProperties(List treeNodes) { + List maTypeProperties = maTypeMapper.selectMaTypePropertyNames(); + Map> maTypePropertiesMap = new HashMap<>(); + if (!org.springframework.util.CollectionUtils.isEmpty(maTypeProperties)) { + maTypePropertiesMap = maTypeProperties.stream().collect(Collectors.groupingBy(MaTypeProperty::getTypeId)); + } + for (TreeNode treeNode : treeNodes) { + List tmpPropList = maTypePropertiesMap.get(treeNode.getId()); + if (!org.springframework.util.CollectionUtils.isEmpty(tmpPropList)) { + treeNode.setPropertyNames(tmpPropList.stream().map(o -> o.getPropertyName()).collect(Collectors.toList())); + } + } + } + /** * 首页搜索热搜装备 * @param devInfoVo diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java index 0f9b478..b018b70 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/mapper/MaTypeMapper.java @@ -87,4 +87,10 @@ public interface MaTypeMapper { List selectParentId(@Param("typeId")Long typeId, @Param("level")Integer level); Integer updateLeasePrice(@Param("typeIds")List typeIds,@Param("leasePrice") BigDecimal leasePrice); + + List selectMaTypePropertyNames(); + + int deleteMaTypePropertyNames(@Param("typeId")Long typeId); + + int insertMaTypePropertyNames(@Param("typeId")Long typeId, @Param("list") List propertyNames); } \ No newline at end of file diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/service/impl/MaTypeServiceImpl.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/service/impl/MaTypeServiceImpl.java index b084c8f..9abeca9 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/service/impl/MaTypeServiceImpl.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/service/impl/MaTypeServiceImpl.java @@ -8,6 +8,8 @@ import com.bonus.material.ma.service.ITypeService; import com.bonus.material.ma.vo.*; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; + import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -128,6 +130,13 @@ public class MaTypeServiceImpl implements ITypeService { Long typeId = maType.getTypeId(); maType.setUpdateTime(DateUtils.getNowDate()); int i = maTypeMapper.updateType(maType); + //保存配置属性 + if (!CollectionUtils.isEmpty(maType.getPropertyNames())) { + maTypeMapper.deleteMaTypePropertyNames(maType.getTypeId()); + List maTypeProperties = maType.getPropertyNames(); + maTypeProperties.removeIf(String::isEmpty); + maTypeMapper.insertMaTypePropertyNames(maType.getTypeId(), maTypeProperties); + } // 图片路径保存 if (StringUtils.isNotEmpty(maType.getPhotoName()) && StringUtils.isNotEmpty(maType.getPhotoUrl())) { typeFileMapper.deleteMaTypeFileByTypeId(typeId, "1"); @@ -202,11 +211,27 @@ public class MaTypeServiceImpl implements ITypeService { @Override public List getMaTypeList(String typeName, String parentId) { List maTypes = maTypeMapper.selectMaTypeTree(parentId); + //填充自定义属性 + fillProperties(maTypes); List treeSelectList = buildDeptTreeSelect(maTypes); //如果没有查询到那么返回空 return treeSelectList; } + private void fillProperties(List maTypes) { + List maTypeProperties = maTypeMapper.selectMaTypePropertyNames(); + Map> maTypePropertiesMap = new HashMap<>(); + if (!CollectionUtils.isEmpty(maTypeProperties)) { + maTypePropertiesMap = maTypeProperties.stream().collect(Collectors.groupingBy(MaTypeProperty::getTypeId)); + } + for (MaType maType : maTypes) { + List tmpPropList = maTypePropertiesMap.get(maType.getTypeId()); + if (!CollectionUtils.isEmpty(tmpPropList)) { + maType.setPropertyNames(tmpPropList.stream().map(o -> o.getPropertyName()).collect(Collectors.toList())); + } + } + } + @Override public List getMaTypeSelect(String typeName, String parentId) { List maTypes = maTypeMapper.getMaTypeSelect(parentId); diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaType.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaType.java index b27456f..2b634bb 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaType.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaType.java @@ -216,4 +216,6 @@ public class MaType extends BaseEntity { private String intelligentCode; private List typeIds; + + private List propertyNames; } diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaTypeProperty.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaTypeProperty.java new file mode 100644 index 0000000..7cf356e --- /dev/null +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/MaTypeProperty.java @@ -0,0 +1,17 @@ +package com.bonus.material.ma.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +@Data +public class MaTypeProperty { + + /** 类型ID */ + @ApiModelProperty(value = "类型ID") + private Long typeId; + + /** 类型ID */ + @ApiModelProperty(value = "属性名称") + private String propertyName; + +} diff --git a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/TreeSelect.java b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/TreeSelect.java index bf65755..cbdd00b 100644 --- a/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/TreeSelect.java +++ b/bonus-modules/bonus-material-mall/src/main/java/com/bonus/material/ma/vo/TreeSelect.java @@ -27,6 +27,8 @@ public class TreeSelect implements Serializable private String companyId; + private List propertyNames; + /** 子节点 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) private List children; @@ -51,6 +53,7 @@ public class TreeSelect implements Serializable this.id = maType.getTypeId(); this.label = maType.getTypeName(); this.companyId = maType.getCompanyId(); + this.propertyNames = maType.getPropertyNames(); this.children = maType.getChildren().stream().map(TreeSelect::new).collect(Collectors.toList()); } // public TreeSelect(SysDept dept) @@ -106,6 +109,14 @@ public class TreeSelect implements Serializable this.companyId = companyId; } + public List getPropertyNames() { + return propertyNames; + } + + public void setPropertyNames(List propertyNames) { + this.propertyNames = propertyNames; + } + public List getChildren() { return children; diff --git a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml index 2992843..ba379e4 100644 --- a/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml +++ b/bonus-modules/bonus-material-mall/src/main/resources/mapper/material/ma/MaMachineTypeMapper.xml @@ -454,4 +454,27 @@ and del_flag = 0 + + + + + delete from ma_type_properties where type_id = #{typeId} + + + + insert into + ma_type_properties(type_id, property_name, create_time) + values + + ( + #{typeId}, + #{item}, + now() + ) + + \ No newline at end of file