/**
* 分類首頁
*
* @param modelMap
* @param req
* @param res
* @return
* @auth nibili 2019年4月28日 196888813@qq.com
*/
@RequestMapping
public String list(ModelMap modelMap, HttpServletRequest req, HttpServletResponse res) {app
MerchantStoreInfoEntity merchantStoreInfoEntity = this.getNowMerchantStore(req);
if (merchantStoreInfoEntity == null) {
modelMap.addAttribute("errorMsg", "當前用戶沒有店鋪");
} else {
PageRequest pageRequest = new PageRequest();
pageRequest.setOrderBy("orderby");
pageRequest.setOrderDir("desc");
List<MerchantCateEntity> list = merchantCateDao.findByStoreId(merchantStoreInfoEntity.getId(), PageRequestUtils.buildSpringDataPageRequest(pageRequest));
//
Table<Long, Long, MerchantCateEntity> table = HashBasedTable.create();
for (MerchantCateEntity merchantCateEntity : list) {
table.put(merchantCateEntity.getId(), merchantCateEntity.getParentId(), merchantCateEntity);
}
// 根節點集合
list = Lists.newArrayList(table.column(-1l).values());
List<MerchantCateEntity> allList = Lists.newArrayList();
this.addChildren(list, allList, table);
//
modelMap.addAttribute("list", allList);ui
}
return "/admin/merchant/merchant_store_cate";
}this
/**
* 遍歷級裝節點
*
* @param nowList
* @param allLlist
* @param table
* @auth nibili 2019年4月28日 196888813@qq.com
*/
private void addChildren(final List<MerchantCateEntity> nowList, final List<MerchantCateEntity> allLlist, Table<Long, Long, MerchantCateEntity> table) {
List<MerchantCateEntity> chidrenList = null;
if (CollectionUtils.isNotEmpty(nowList) == true) {
for (MerchantCateEntity merchantCateEntity : nowList) {
// 修改name
String temp = "|";
for (int i = 0; i < merchantCateEntity.getLevel() - 1; i++) {
temp = temp + " - ";
}
merchantCateEntity.setName(temp + merchantCateEntity.getName());
allLlist.add(merchantCateEntity);
//
Collection<MerchantCateEntity> collection = table.column(merchantCateEntity.getId()).values();
if (CollectionUtils.isEmpty(collection) == true) {
// 子集爲空跳過
continue;
}
chidrenList = new ArrayList<MerchantCateEntity>(collection);
this.addChildren(chidrenList, allLlist, table);.net
}
}
return;
}get