添加用户目录

This commit is contained in:
cyk
2023-12-24 15:49:35 +08:00
parent f4438eb1c7
commit 3a036c10e4

View File

@@ -521,4 +521,88 @@ public class UrlAndCateController {
}
@RequestMapping("/returnCateByUserId")
public String returnCateByUserId(String userId)
{
HashMap<String, Object> result = new HashMap<>();
result.put("code", 500);
result.put("msg", "下载失败");
List<UrlCateList> urlCateLists = urlCateListService.selectUrListByUserId(Integer.valueOf(userId));
result.put("data", urlCateLists);
return JSONObject.toJSONString(result);
}
@RequestMapping("/disposeBookmarkToJsonByUserId")
public String disposeBookmarkToJsonByUserId(String userId)
{
List<UrlCateList> urlCateListList = urlCateListService.selectUrListByUserId(Integer.valueOf(userId));
List<CateAndUrl> cateAndUrlList = new ArrayList<>();
for( int i = 0 ; i < urlCateListList.size() ; i++)
{
UrlCateList urlCateList = urlCateListList.get(i);
CateAndUrl cateAndUrl = new CateAndUrl();
cateAndUrl.setFloder("true");
cateAndUrl.setName(urlCateList.getName());
cateAndUrl.setParentId(urlCateList.getRootCateId());
cateAndUrl.setCateId(urlCateList.getId());
cateAndUrlList.add(cateAndUrl);
}
System.out.println(cateAndUrlList);
List<CateAndUrl> parentsList = new ArrayList<>();
//声明返回集合
List<CateAndUrl> resultList = new ArrayList<>();
//对全部数据进行遍历
for (CateAndUrl disease : cateAndUrlList) {
//判断是否是第一梯队,或者说是树的根节点,如果是根节点就加入到父类集合与返回集合
if (disease.getParentId() == 0) {
parentsList.add(disease);
resultList.add(disease);
} else {
//对于不是第一梯队的数据进行遍历
for (CateAndUrl parent : parentsList) {
//对数据的pid与父类集合中的父节点进行配对如果配对成功就把数据加入到父节点中的子节点集合
if (parent.getFloder().equals("true") ) {
if( parent.getCateId() == disease.getParentId())
{
parent.getChildUC().add(disease);
//当前数据有可能是别的数据的父节点,加到父类容器
parentsList.add(disease);
break;
}
}
if (parent.getFloder().equals("false") ) {
if(parent.getUrlId() == disease.getParentId())
{
parent.getChildUC().add(disease);
//当前数据有可能是别的数据的父节点,加到父类容器
parentsList.add(disease);
break;
}
}
}
}
}
ObjectMapper mapper = new ObjectMapper();
String Json;
HashMap<String, Object> result = new HashMap<>();
// java对象转换为json字符换
try {
Json = mapper.writeValueAsString(resultList);
result.put("code", 200);
result.put("msg", "处理成功");
result.put("data", resultList);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
return JSONObject.toJSONString(result);
}
}