From 853ac636932ff91b53846f3f3a9b4afd210ac361 Mon Sep 17 00:00:00 2001 From: xierz Date: Thu, 24 Dec 2020 10:07:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/mingsoft/cms/upgrade/Upgrade.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/main/java/net/mingsoft/cms/upgrade/Upgrade.java diff --git a/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java b/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java new file mode 100644 index 00000000..6298db79 --- /dev/null +++ b/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java @@ -0,0 +1,60 @@ +package net.mingsoft.cms.upgrade; + +import net.mingsoft.basic.util.SpringUtil; +import net.mingsoft.cms.biz.ICategoryBiz; +import net.mingsoft.cms.entity.CategoryEntity; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @author by 铭飞开源团队 + * @Description + * @date 2020/6/19 15:58 + */ +public class Upgrade { + + /** + * 更新栏目分类的顶级节点和叶子节点 + */ + public void upgrade(){ + ICategoryBiz categoryBiz = SpringUtil.getBean(ICategoryBiz.class); + List list = categoryBiz.queryAll(); + + list.forEach(x->{ + + //将parentId第一行设为顶级节点 + String topId = "0"; + String parentId = x.getParentids(); + if (parentId != null) { + topId = parentId.split(",")[0]; + } + x.setTopId(topId); + + String id = x.getId(); + boolean leaf = true; + //判断是否叶子,循环查找,如果有节点的父节点中包含该节点的id则判断为否跳出循环 + for (int i = 0; i< list.size(); i++) { + String pId = list.get(i).getParentids(); + if (pId == null) { + continue; + } + leaf = !pId.contains(id); + //如果不是叶子就跳出循环,不需要再判断了 + if (!leaf) { + break; + } + } + x.setLeaf(leaf); + //更新 + Map fields = new HashMap<>(); + fields.put("leaf", x.getLeaf()?"1":"0"); + fields.put("top_id", x.getTopId()); + Map where = new HashMap<>(); + where.put("id", x.getId()); + categoryBiz.updateBySQL("cms_category", fields, where); + }); + + } +}