Commit f4ca8002 authored by tianbo's avatar tianbo

bugfix:

1、管道品种级联筛选
parent 62be67c6
package com.yeejoin.amos.boot.module.jg.api.dto;
import com.yeejoin.amos.boot.module.ymt.api.dto.EquipmentCategoryDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
/**
* 装备分类
*
* @author system_generator
* @date 2021-10-20
*/
@Data
@ApiModel(value="EquipmentClassifyDto", description="装备分类")
public class EquipmentClassifyDto extends EquipmentCategoryDto implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "children")
private List<EquipmentClassifyDto> children;
}
......@@ -7,9 +7,11 @@ import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.module.common.api.dto.DPFilterParamDto;
import com.yeejoin.amos.boot.module.jg.api.bo.JgBizCountDataBO;
import com.yeejoin.amos.boot.module.jg.api.dto.DynamicColumnDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipmentClassifyDto;
import com.yeejoin.amos.boot.module.jg.api.dto.ReportAnalysisSearchDTO;
import com.yeejoin.amos.boot.module.ymt.api.entity.EquipmentCategory;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;
......@@ -230,5 +232,32 @@ public interface CommonMapper extends BaseMapper<EquipmentCategory> {
@Param("record") String record);
void updateEnterpriseSafetyStatus(@Param("useUnitCodeList") Set<String> useUnitCodeList);
@Select("WITH RECURSIVE category_tree AS (\n" +
" SELECT \n" +
" tt.id,\n" +
" tt.code,\n" +
" tt.name,\n" +
" ifnull((SELECT code FROM tz_equipment_category WHERE id = tt.parent_id), 0) parent_id,\n" +
" 1 AS level -- 定义当前级别为1\n" +
" FROM \n" +
" tz_equipment_category tt\n" +
" WHERE \n" +
" code = #{parentCode}\n" +
" UNION ALL\n" +
" -- 递归成员:从子节点继续查找\n" +
" SELECT \n" +
" child.id,\n" +
" child.code,\n" +
" child.name,\n" +
" (SELECT code FROM tz_equipment_category WHERE id = child.parent_id) parent_id,\n" +
" parent.level + 1 \n" +
" FROM \n" +
" tz_equipment_category child\n" +
" INNER JOIN \n" +
" category_tree parent ON child.parent_id = parent.id\n" +
")\n" +
"SELECT * FROM category_tree ORDER BY level;")
List<EquipmentClassifyDto> getEquClassifyByCode(String parentCode);
}
......@@ -9,6 +9,7 @@ import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.jg.api.dto.CodeGenerateDto;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipmentClassifyDto;
import com.yeejoin.amos.boot.module.jg.api.dto.UseFlagParamDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgRegistrationHistory;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationManage;
......@@ -689,9 +690,9 @@ public class CommonController extends BaseController {
* @return list
*/
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/getSubEquCategoryByParent")
@GetMapping(value = "/getEquClassifyByCode")
@ApiOperation(httpMethod = "GET", value = "根据父级code查询子设备分类", notes = "根据父级code查询子设备分类")
public ResponseModel<List<EquipmentCategoryDto>> getSubEquCategoryByParent(@RequestParam(value = "parentCode") String parentCode) {
return ResponseHelper.buildResponse(commonService.getSubEquCategoryByParentCode(parentCode));
public ResponseModel<List<EquipmentClassifyDto>> getEquClassifyByCode(@RequestParam(value = "parentCode") String parentCode) {
return ResponseHelper.buildResponse(commonService.getEquClassifyByCode(parentCode));
}
}
......@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.CompanyBo;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.module.jg.api.dto.EquipmentClassifyDto;
import com.yeejoin.amos.boot.module.jg.api.dto.InstanceRuntimeData;
import com.yeejoin.amos.boot.module.jg.api.dto.UseFlagParamDto;
import com.yeejoin.amos.boot.module.jg.api.entity.JgUseRegistrationManage;
......@@ -242,5 +243,5 @@ public interface ICommonService {
List<EquipmentCategoryDto> getEquDefineByParentId(String parentId);
List<EquipmentCategoryDto> getSubEquCategoryByParentCode(String parentCode);
List<EquipmentClassifyDto> getEquClassifyByCode(String parentCode);
}
......@@ -2123,9 +2123,37 @@ public class CommonServiceImpl implements ICommonService {
}
@Override
public List<EquipmentCategoryDto> getSubEquCategoryByParentCode(String parentCode) {
return equipmentCategoryMapper.getSubEquCategoryByParentCode(parentCode);
}
public List<EquipmentClassifyDto> getEquClassifyByCode(String parentCode) {
List<EquipmentClassifyDto> equipmentCategoryDtos = commonMapper.getEquClassifyByCode(parentCode);
if (ValidationUtil.isEmpty(equipmentCategoryDtos)) {
return new ArrayList<>();
}
Map<String, EquipmentClassifyDto> idToDtoMap = equipmentCategoryDtos.stream()
.collect(Collectors.toMap(EquipmentClassifyDto::getCode, dto -> dto));
List<EquipmentClassifyDto> rootNodes = equipmentCategoryDtos.stream()
.filter(dto -> dto.getParentId().equals("0"))
.collect(Collectors.toList());
equipmentCategoryDtos.forEach(dto -> {
String parentId = dto.getParentId();
if (!ValidationUtil.isEmpty(parentId)) {
EquipmentClassifyDto parent = idToDtoMap.get(parentId);
if (parent != null) {
if (parent.getChildren() == null) {
parent.setChildren(new ArrayList<>());
}
parent.getChildren().add(dto);
}
}
});
return rootNodes.stream()
.flatMap(root -> root.getChildren().stream())
.collect(Collectors.toList());
}
/**
* 排序 :页面列表排序功能支持,将 "字段,ascend" 或 "字段,descend" 转化为对应JSONObject
......
......@@ -101,7 +101,5 @@ public interface EquipmentCategoryMapper extends BaseMapper<EquipmentCategory> {
@Select("SELECT * FROM tz_equipment_category WHERE parent_id = #{parentId}")
List<EquipmentCategoryDto> getEquDefineByParentId(String parentId);
@Select("SELECT * FROM tz_equipment_category WHERE parent_id = ( SELECT ID FROM tz_equipment_category WHERE code = #{parentCode} )")
List<EquipmentCategoryDto> getSubEquCategoryByParentCode(String parentCode);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment