Merge remote-tracking branch 'origin/master'

This commit is contained in:
liang.chao 2024-12-10 13:39:29 +08:00
commit 7fb5fc3d53
8 changed files with 111 additions and 0 deletions

View File

@ -48,6 +48,8 @@ public class TreeNode {
private String remark;
private List<String> propertyNames;
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeNode> children = new ArrayList<>();
}

View File

@ -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<TreeNode> 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<TreeNode> treeNodes) {
List<MaTypeProperty> maTypeProperties = maTypeMapper.selectMaTypePropertyNames();
Map<Long, List<MaTypeProperty>> maTypePropertiesMap = new HashMap<>();
if (!org.springframework.util.CollectionUtils.isEmpty(maTypeProperties)) {
maTypePropertiesMap = maTypeProperties.stream().collect(Collectors.groupingBy(MaTypeProperty::getTypeId));
}
for (TreeNode treeNode : treeNodes) {
List<MaTypeProperty> 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

View File

@ -87,4 +87,10 @@ public interface MaTypeMapper {
List<Integer> selectParentId(@Param("typeId")Long typeId, @Param("level")Integer level);
Integer updateLeasePrice(@Param("typeIds")List<Integer> typeIds,@Param("leasePrice") BigDecimal leasePrice);
List<MaTypeProperty> selectMaTypePropertyNames();
int deleteMaTypePropertyNames(@Param("typeId")Long typeId);
int insertMaTypePropertyNames(@Param("typeId")Long typeId, @Param("list") List<String> propertyNames);
}

View File

@ -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<String> 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<TreeSelect> getMaTypeList(String typeName, String parentId) {
List<MaType> maTypes = maTypeMapper.selectMaTypeTree(parentId);
//填充自定义属性
fillProperties(maTypes);
List<TreeSelect> treeSelectList = buildDeptTreeSelect(maTypes);
//如果没有查询到那么返回空
return treeSelectList;
}
private void fillProperties(List<MaType> maTypes) {
List<MaTypeProperty> maTypeProperties = maTypeMapper.selectMaTypePropertyNames();
Map<Long, List<MaTypeProperty>> maTypePropertiesMap = new HashMap<>();
if (!CollectionUtils.isEmpty(maTypeProperties)) {
maTypePropertiesMap = maTypeProperties.stream().collect(Collectors.groupingBy(MaTypeProperty::getTypeId));
}
for (MaType maType : maTypes) {
List<MaTypeProperty> tmpPropList = maTypePropertiesMap.get(maType.getTypeId());
if (!CollectionUtils.isEmpty(tmpPropList)) {
maType.setPropertyNames(tmpPropList.stream().map(o -> o.getPropertyName()).collect(Collectors.toList()));
}
}
}
@Override
public List<TreeSelect> getMaTypeSelect(String typeName, String parentId) {
List<MaType> maTypes = maTypeMapper.getMaTypeSelect(parentId);

View File

@ -216,4 +216,6 @@ public class MaType extends BaseEntity {
private String intelligentCode;
private List<Integer> typeIds;
private List<String> propertyNames;
}

View File

@ -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;
}

View File

@ -27,6 +27,8 @@ public class TreeSelect implements Serializable
private String companyId;
private List<String> propertyNames;
/** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelect> 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<String> getPropertyNames() {
return propertyNames;
}
public void setPropertyNames(List<String> propertyNames) {
this.propertyNames = propertyNames;
}
public List<TreeSelect> getChildren()
{
return children;

View File

@ -454,4 +454,27 @@
</foreach>
and del_flag = 0
</update>
<select id="selectMaTypePropertyNames" resultType="com.bonus.material.ma.vo.MaTypeProperty">
select type_id as typeId,
property_name as propertyName
from ma_type_properties
</select>
<delete id="deleteMaTypePropertyNames">
delete from ma_type_properties where type_id = #{typeId}
</delete>
<insert id="insertMaTypePropertyNames">
insert into
ma_type_properties(type_id, property_name, create_time)
values
<foreach collection="list" item="item" index="index" separator=",">
(
#{typeId},
#{item},
now()
)
</foreach>
</insert>
</mapper>