左侧树:聚合列表查询

This commit is contained in:
huangge1199 2025-08-06 14:06:34 +08:00
parent 2a94318c9e
commit 3282eec092
4 changed files with 76 additions and 2 deletions

View File

@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* 目标管控-分类 * 目标管控-分类
@ -59,4 +60,11 @@ public class CategoryController {
categoryService.delCategory(params); categoryService.delCategory(params);
return R.ok(); return R.ok();
} }
@Operation(summary = "聚合列表查询")
@PostMapping("/getTogethList")
public R<List<Map<String, String>>> getTogethList(@RequestBody JSONObject params) {
List<Map<String, String>> result = categoryService.getTogethList(params);
return R.ok(result);
}
} }

View File

@ -5,6 +5,7 @@ import iet.ustb.sf.domain.Category;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author hyy * @author hyy
@ -18,4 +19,6 @@ public interface CategoryService extends IService<Category> {
void addCategory(JSONObject params); void addCategory(JSONObject params);
void delCategory(JSONObject params); void delCategory(JSONObject params);
List<Map<String, String>> getTogethList(JSONObject params);
} }

View File

@ -16,6 +16,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* @author hyy * @author hyy
@ -92,7 +93,7 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
String id = params.getString("id"); String id = params.getString("id");
CheckUtils.checkEmpty(id, "分类ID"); CheckUtils.checkEmpty(id, "分类ID");
Category category = categoryMapper.selectById(id); Category category = categoryMapper.selectById(id);
ThrowUtils.throwIf(category==null,ErrorCode.PARAMS_ERROR,"分类不存在!"); ThrowUtils.throwIf(category == null, ErrorCode.PARAMS_ERROR, "分类不存在!");
Date now = new Date(); Date now = new Date();
@ -108,6 +109,68 @@ public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
categoryMapper.deleteById(id); categoryMapper.deleteById(id);
} }
@Override
public List<Map<String, String>> getTogethList(JSONObject params) {
String topic = params.getString("topic");
String organization = params.getString("organization");
String categoryId = params.getString("categoryId");
String targetId = params.getString("targetId");
List<Category> categoryList = new ArrayList<>();
if (StringUtils.isEmpty(targetId)) {
Category category = Category.builder()
.topic(topic)
.organization(organization)
.parentId(categoryId)
.build();
categoryList = showCategory(category);
}
List<Target> targetList = new ArrayList<>();
if (!StringUtils.isEmpty(topic)) {
QueryWrapper<Target> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("topic", topic);
if (!StringUtils.isEmpty(organization)) {
queryWrapper.like("organization", "%" + organization + "%");
}
if (!StringUtils.isEmpty(targetId)) {
queryWrapper.eq("parent_id", targetId);
} else if (!StringUtils.isEmpty(categoryId)) {
queryWrapper.eq("category_id", categoryId);
} else {
queryWrapper.and(qw -> {
qw.isNull("category_id").or().eq("category_id", "");
});
}
queryWrapper.orderByDesc("update_time");
targetList = targetMapper.selectList(queryWrapper);
}
List<String> idList = targetList.stream().map(Target::getId).distinct().toList();
targetList.removeIf(target -> idList.contains(target.getParent()));
List<Map<String, String>> resultList = new ArrayList<>();
for (Category category : categoryList) {
Map<String, String> map = new HashMap<>();
map.put("topic", category.getTopic());
map.put("organization", category.getOrganization());
map.put("categoryId", category.getId());
String name = Optional.ofNullable(category.getNameCn()).orElse(category.getTopic());
map.put("name", name);
map.put("show", "1");
map.put("key", "0");
resultList.add(map);
}
for (Target target : targetList) {
Map<String, String> map = new HashMap<>();
map.put("topic", target.getTopic());
map.put("organization", target.getOrganization());
map.put("targetId", target.getId());
map.put("name", target.getName());
map.put("show", "0");
map.put("key", String.valueOf(target.getIsKey()));
resultList.add(map);
}
return resultList;
}
} }

View File

@ -35,7 +35,7 @@ public class CheckUtils {
*/ */
public static void checkTableName(String tableName) { public static void checkTableName(String tableName) {
checkEmpty(tableName, "表名"); checkEmpty(tableName, "表名");
String sql = "SELECT COUNT(1) FROM information_schema.tables WHERE table_schema = 'mbgk' AND table_name = '" + tableName + "'"; String sql = "SELECT COUNT(1) FROM information_schema.tables WHERE table_schema = 'dwops_extension' AND table_name = '" + tableName + "'";
long cnt = SqlRunner.db().selectCount(sql); long cnt = SqlRunner.db().selectCount(sql);
ThrowUtils.throwIf(cnt <= 0, new RuntimeException("" + tableName + "不存在!")); ThrowUtils.throwIf(cnt <= 0, new RuntimeException("" + tableName + "不存在!"));
} }