Jelajahi Sumber

添加components

Zhou Rui 5 tahun lalu
induk
melakukan
7a5bbd9a65

+ 203 - 0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Components.java

@@ -0,0 +1,203 @@
+package com.x.base.core.project.config;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import com.x.base.core.project.annotation.FieldDescribe;
+import com.x.base.core.project.gson.XGsonBuilder;
+import com.x.base.core.project.tools.DefaultCharset;
+import com.x.base.core.project.tools.ListTools;
+
+import org.apache.commons.io.FileUtils;
+
+public class Components extends ConfigObject {
+
+	public static final String NAME_SETTINGS = "Settings";
+	public static final String NAME_ORG = "Org";
+	public static final String NAME_PROFILE = "Profile";
+	public static final String NAME_APPMARKET = "AppMarket";
+	public static final String NAME_FILE = "File";
+	public static final String NAME_BAM = "BAM";
+	public static final String NAME_NOTE = "Note";
+	public static final String NAME_MEETING = "Meeting";
+	public static final String NAME_ATTENDANCE = "Attendance";
+	public static final String NAME_FORUM = "Forum";
+	public static final String NAME_HOTARTICLE = "HotArticle";
+	public static final String NAME_ONLINEMEETING = "OnlineMeeting";
+	public static final String NAME_ANN = "ANN";
+	public static final String NAME_MINDER = "Minder";
+	public static final String NAME_CALENDAR = "Calendar";
+	public static final String NAME_SEARCH = "Search";
+	public static final String NAME_HOMEPAGE = "Homepage";
+
+	
+
+	public static List<String> SYSTEM_NAME_NAMES = ListTools.toList(NAME_SETTINGS, NAME_ORG,
+			NAME_PROFILE, NAME_APPMARKET, NAME_FILE, NAME_BAM, NAME_NOTE, NAME_MEETING,
+			NAME_ATTENDANCE, NAME_FORUM, NAME_HOTARTICLE, NAME_ONLINEMEETING, NAME_ANN,
+			NAME_MINDER, NAME_CALENDAR, NAME_SEARCH, NAME_HOMEPAGE);
+
+	public static final String APPICON_PNG = "appicon.png";
+
+	public static Components defaultInstance() {
+		Components o = new Components();
+		o.systems.add(
+				new Component(NAME_SETTINGS, NAME_SETTINGS, "系统设置", APPICON_PNG, 1, Component.TYPE_SYSTEM));
+		o.systems.add(
+				new Component(NAME_APPMARKET, NAME_APPMARKET, "应用市场", APPICON_PNG, 2, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_ANN, NAME_ANN, "神经网络", APPICON_PNG, 3, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_ORG, NAME_ORG, "组织管理", APPICON_PNG, 4, Component.TYPE_SYSTEM));
+		o.systems.add(
+				new Component(NAME_PROFILE, NAME_PROFILE, "个人设置", APPICON_PNG, 5, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_BAM, NAME_BAM, "流程监控", APPICON_PNG, 6, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_FILE, NAME_FILE, "云文件", APPICON_PNG, 7, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_NOTE, NAME_NOTE, "便签", APPICON_PNG, 8, Component.TYPE_SYSTEM));
+		o.systems.add(
+				new Component(NAME_MEETING, NAME_MEETING, "会议管理", APPICON_PNG, 9, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_ATTENDANCE, NAME_ATTENDANCE, "考勤管理", APPICON_PNG, 10,
+				Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_FORUM, NAME_FORUM, "论坛", APPICON_PNG, 11, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_HOTARTICLE, NAME_HOTARTICLE, "热点", APPICON_PNG, 12,
+				Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_ONLINEMEETING, NAME_ONLINEMEETING, "网络会议", APPICON_PNG, 13,
+				Component.TYPE_SYSTEM));
+		o.systems.add(
+				new Component(NAME_MINDER, NAME_MINDER, "脑图编辑器", APPICON_PNG, 14, Component.TYPE_SYSTEM));
+		o.systems.add(
+				new Component(NAME_CALENDAR, NAME_CALENDAR, "日程安排", APPICON_PNG, 15, Component.TYPE_SYSTEM));
+		o.systems.add(new Component(NAME_SEARCH, NAME_SEARCH, "搜索", APPICON_PNG, 16, Component.TYPE_SYSTEM));
+		o.systems.add(
+				new Component(NAME_HOMEPAGE, NAME_HOMEPAGE, "首页", APPICON_PNG, 17, Component.TYPE_SYSTEM));
+		return o;
+	}
+
+	@FieldDescribe("默认模块")
+	private List<Component> systems = new ArrayList<>();
+
+	public Components() {
+		// nothing
+	}
+
+	public void save() throws Exception {
+		File file = new File(Config.base(), Config.PATH_CONFIG_PORTAL);
+		FileUtils.write(file, XGsonBuilder.toJson(this), DefaultCharset.charset);
+	}
+
+	public static class Component {
+
+		public static final String TYPE_SYSTEM = "system";
+		public static final String TYPE_CUSTOM = "custom";
+
+		public Component() {
+
+		}
+
+		public Component(String name, String path, String title, String iconPath, Integer order, String type) {
+			this.name = name;
+			this.path = path;
+			this.title = title;
+			this.iconPath = iconPath;
+			this.order = order;
+			this.type = type;
+		}
+
+		@FieldDescribe("名称")
+		private String name;
+
+		@FieldDescribe("路径")
+		private String path;
+
+		@FieldDescribe("标题")
+		private String title;
+
+		@FieldDescribe("iconPath")
+		private String iconPath;
+
+		@FieldDescribe("排序号")
+		private Integer order;
+
+		@FieldDescribe("类型")
+		private String type;
+
+		@FieldDescribe("允许列表,可以混用person,role")
+		private List<String> allowList = new ArrayList<>();
+
+		@FieldDescribe("禁止列表,可以混用person,role")
+		private List<String> dentyList = new ArrayList<>();
+
+		public String getName() {
+			return name;
+		}
+
+		public void setName(String name) {
+			this.name = name;
+		}
+
+		public String getPath() {
+			return path;
+		}
+
+		public void setPath(String path) {
+			this.path = path;
+		}
+
+		public String getTitle() {
+			return title;
+		}
+
+		public void setTitle(String title) {
+			this.title = title;
+		}
+
+		public String getIconPath() {
+			return iconPath;
+		}
+
+		public void setIconPath(String iconPath) {
+			this.iconPath = iconPath;
+		}
+
+		public List<String> getAllowList() {
+			return allowList;
+		}
+
+		public void setAllowList(List<String> allowList) {
+			this.allowList = allowList;
+		}
+
+		public List<String> getDentyList() {
+			return dentyList;
+		}
+
+		public void setDentyList(List<String> dentyList) {
+			this.dentyList = dentyList;
+		}
+
+		public Integer getOrder() {
+			return order;
+		}
+
+		public void setOrder(Integer order) {
+			this.order = order;
+		}
+
+		public String getType() {
+			return type;
+		}
+
+		public void setType(String type) {
+			this.type = type;
+		}
+
+	}
+
+	public List<Component> getSystems() {
+		return systems;
+	}
+
+	public void setSystems(List<Component> systems) {
+		this.systems = systems;
+	}
+
+}

+ 18 - 2
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java

@@ -74,6 +74,7 @@ public class Config {
 	public static final String PATH_CONFIG_COMMUNICATE = "config/communicate.json";
 	public static final String PATH_CONFIG_EXMAIL = "config/exmail.json";
 	public static final String PATH_CONFIG_PORTAL = "config/portal.json";
+	public static final String PATH_CONFIG_COMPONENTS = "config/components.json";
 
 	public static final String DIR_COMMONS = "commons";
 	public static final String DIR_COMMONS_TESS4J_TESSDATA = "commons/tess4j/tessdata";
@@ -124,8 +125,6 @@ public class Config {
 
 	public static final String SCRIPTING_ENGINE_NAME = "JavaScript";
 
-	// public static final String RESOUCE_CONFIG = "config";
-
 	public static final String RESOURCE_NODE_PREFIX = "node/";
 	public static final String RESOURCE_NODE_EVENTQUEUE = RESOURCE_NODE_PREFIX + "eventQueue";
 	public static final String RESOURCE_NODE_EVENTQUEUEEXECUTOR = RESOURCE_NODE_PREFIX + "eventQueueExecutor";
@@ -1227,6 +1226,23 @@ public class Config {
 		return instance().portal;
 	}
 
+	private Components components = null;
+
+	public static Components components() throws Exception {
+		if (null == instance().components) {
+			synchronized (Config.class) {
+				if (null == instance().components) {
+					Components obj = BaseTools.readConfigObject(PATH_CONFIG_COMPONENTS, Components.class);
+					if (null == obj) {
+						obj = Components.defaultInstance();
+					}
+					instance().components = obj;
+				}
+			}
+		}
+		return instance().components;
+	}
+
 	public static Object resource(String name) throws Exception {
 		return initialContext().lookup(name);
 	}

+ 15 - 2
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/ThisApplication.java

@@ -1,26 +1,39 @@
 package com.x.component.assemble.control;
 
 import com.x.base.core.project.Context;
+import com.x.base.core.project.config.Config;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.component.assemble.control.schedule.InitComponents;
 
 public class ThisApplication {
 
+	private ThisApplication() {
+		// nothing
+	}
+
 	protected static Context context;
 
+	private static Logger logger = LoggerFactory.getLogger(ThisApplication.class);
+
 	public static Context context() {
 		return context;
 	}
 
 	public static void init() {
 		try {
+			LoggerFactory.setLevel(Config.logLevel().x_component_assemble_control());
+			context.scheduleLocal(InitComponents.class, 1);
 		} catch (Exception e) {
-			e.printStackTrace();
+			logger.error(e);
 		}
 	}
 
 	public static void destroy() {
 		try {
+			//nothing
 		} catch (Exception e) {
-			e.printStackTrace();
+			logger.error(e);
 		}
 	}
 

+ 0 - 3
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/jaxrs/component/ActionListAll.java

@@ -5,8 +5,6 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import org.apache.commons.collections4.ListUtils;
-
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.JpaObject;
@@ -16,7 +14,6 @@ import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.cache.ApplicationCache;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
-import com.x.base.core.project.tools.ListTools;
 import com.x.component.core.entity.Component;
 
 import net.sf.ehcache.Element;

+ 64 - 0
o2server/x_component_assemble_control/src/main/java/com/x/component/assemble/control/schedule/InitComponents.java

@@ -0,0 +1,64 @@
+package com.x.component.assemble.control.schedule;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import com.x.base.core.container.EntityManagerContainer;
+import com.x.base.core.container.factory.EntityManagerContainerFactory;
+import com.x.base.core.entity.annotation.CheckPersistType;
+import com.x.base.core.project.config.Config;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.base.core.project.schedule.AbstractJob;
+import com.x.base.core.project.tools.ListTools;
+import com.x.component.core.entity.Component;
+
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
+public class InitComponents extends AbstractJob {
+
+	private static Logger logger = LoggerFactory.getLogger(InitComponents.class);
+
+	@Override
+	public void schedule(JobExecutionContext jobExecutionContext) throws Exception {
+		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+			emc.beginTransaction(Component.class);
+			this.init(emc);
+			emc.commit();
+		} catch (Exception e) {
+			logger.error(e);
+			throw new JobExecutionException(e);
+		}
+	}
+
+	private void init(EntityManagerContainer emc) throws Exception {
+		List<String> names = ListTools.extractProperty(Config.components().getSystems(), "name", String.class, true,
+				true);
+		List<Component> os = emc.listEqual(Component.class, Component.type_FIELDNAME, Component.TYPE_SYSTEM);
+		for (Component o : os) {
+			names.remove(o.getName());
+		}
+		for (com.x.base.core.project.config.Components.Component o : Config.components().getSystems()) {
+			if (names.contains(o.getName())) {
+				Component component = new Component();
+				component.setName(o.getName());
+				component.setPath(o.getPath());
+				component.setTitle(o.getTitle());
+				component.setIconPath(o.getIconPath());
+				component.setOrder(o.getOrder());
+				component.setVisible(true);
+				emc.persist(component, CheckPersistType.all);
+			}
+		}
+		Iterator<Component> iterator = os.iterator();
+		while (iterator.hasNext()) {
+			Component o = iterator.next();
+			if (!names.contains(o.getName())) {
+				iterator.remove();
+			}
+		}
+	}
+
+}

+ 16 - 4
o2server/x_component_assemble_control/src/main/webapp/describe/describe.json

@@ -116,7 +116,7 @@
               "isBaseType": true
             },
             {
-              "name": "orderNumber",
+              "name": "order",
               "type": "Integer",
               "isCollection": false,
               "description": "排序号,升序排列,为空在最后",
@@ -254,7 +254,7 @@
               "isBaseType": true
             },
             {
-              "name": "orderNumber",
+              "name": "order",
               "type": "Integer",
               "isCollection": false,
               "description": "排序号,升序排列,为空在最后",
@@ -344,7 +344,7 @@
               "description": "是否是可见的应用."
             },
             {
-              "name": "orderNumber",
+              "name": "order",
               "type": "Integer",
               "isCollection": false,
               "description": "排序号,升序排列,为空在最后"
@@ -373,6 +373,12 @@
               "isCollection": true,
               "description": "拒绝访问人员."
             },
+            {
+              "name": "type",
+              "type": "String",
+              "isCollection": false,
+              "description": "类型:system|custom"
+            },
             {
               "name": "createTime",
               "type": "Date",
@@ -427,7 +433,7 @@
               "description": "是否是可见的应用."
             },
             {
-              "name": "orderNumber",
+              "name": "order",
               "type": "Integer",
               "isCollection": false,
               "description": "排序号,升序排列,为空在最后"
@@ -456,6 +462,12 @@
               "isCollection": true,
               "description": "拒绝访问人员."
             },
+            {
+              "name": "type",
+              "type": "String",
+              "isCollection": false,
+              "description": "类型:system|custom"
+            },
             {
               "name": "createTime",
               "type": "Date",

+ 15 - 2
o2server/x_component_assemble_control/src/main/webapp/describe/sources/com/x/component/assemble/control/ThisApplication.java

@@ -1,26 +1,39 @@
 package com.x.component.assemble.control;
 
 import com.x.base.core.project.Context;
+import com.x.base.core.project.config.Config;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.component.assemble.control.schedule.InitComponents;
 
 public class ThisApplication {
 
+	private ThisApplication() {
+		// nothing
+	}
+
 	protected static Context context;
 
+	private static Logger logger = LoggerFactory.getLogger(ThisApplication.class);
+
 	public static Context context() {
 		return context;
 	}
 
 	public static void init() {
 		try {
+			LoggerFactory.setLevel(Config.logLevel().x_component_assemble_control());
+			context.scheduleLocal(InitComponents.class, 1);
 		} catch (Exception e) {
-			e.printStackTrace();
+			logger.error(e);
 		}
 	}
 
 	public static void destroy() {
 		try {
+			//nothing
 		} catch (Exception e) {
-			e.printStackTrace();
+			logger.error(e);
 		}
 	}
 

+ 0 - 3
o2server/x_component_assemble_control/src/main/webapp/describe/sources/com/x/component/assemble/control/jaxrs/component/ActionListAll.java

@@ -5,8 +5,6 @@ import java.util.Comparator;
 import java.util.List;
 import java.util.stream.Collectors;
 
-import org.apache.commons.collections4.ListUtils;
-
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.entity.JpaObject;
@@ -16,7 +14,6 @@ import com.x.base.core.project.bean.WrapCopierFactory;
 import com.x.base.core.project.cache.ApplicationCache;
 import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
-import com.x.base.core.project.tools.ListTools;
 import com.x.component.core.entity.Component;
 
 import net.sf.ehcache.Element;

+ 24 - 31
o2server/x_component_core_entity/src/main/java/com/x/component/core/entity/Component.java

@@ -1,7 +1,6 @@
 package com.x.component.core.entity;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import javax.persistence.Column;
@@ -14,12 +13,6 @@ import javax.persistence.OrderColumn;
 import javax.persistence.Table;
 import javax.persistence.UniqueConstraint;
 
-import org.apache.openjpa.persistence.PersistentCollection;
-import org.apache.openjpa.persistence.jdbc.ContainerTable;
-import org.apache.openjpa.persistence.jdbc.ElementColumn;
-import org.apache.openjpa.persistence.jdbc.ElementIndex;
-import org.apache.openjpa.persistence.jdbc.Index;
-
 import com.x.base.core.entity.JpaObject;
 import com.x.base.core.entity.SliceJpaObject;
 import com.x.base.core.entity.annotation.CheckPersist;
@@ -28,6 +21,12 @@ import com.x.base.core.entity.annotation.ContainerEntity;
 import com.x.base.core.entity.annotation.Flag;
 import com.x.base.core.project.annotation.FieldDescribe;
 
+import org.apache.openjpa.persistence.PersistentCollection;
+import org.apache.openjpa.persistence.jdbc.ContainerTable;
+import org.apache.openjpa.persistence.jdbc.ElementColumn;
+import org.apache.openjpa.persistence.jdbc.ElementIndex;
+import org.apache.openjpa.persistence.jdbc.Index;
+
 @ContainerEntity
 @Entity
 @Table(name = PersistenceProperties.Component.table, uniqueConstraints = {
@@ -41,6 +40,10 @@ public class Component extends SliceJpaObject {
 
 	private static final String TABLE = PersistenceProperties.Component.table;
 
+	public static final String TYPE_SYSTEM = "system";
+
+	public static final String TYPE_CUSTOM = "custom";
+
 	public String getId() {
 		return id;
 	}
@@ -57,6 +60,7 @@ public class Component extends SliceJpaObject {
 	/* 以上为 JpaObject 默认字段 */
 
 	public void onPersist() throws Exception {
+		// nothing
 	}
 
 	/* 更新运行方法 */
@@ -83,11 +87,11 @@ public class Component extends SliceJpaObject {
 	@CheckPersist(allowEmpty = true)
 	private Boolean visible;
 
-	public static final String orderNumber_FIELDNAME = "orderNumber";
+	public static final String order_FIELDNAME = "order";
 	@FieldDescribe("排序号,升序排列,为空在最后")
-	@Column(name = ColumnNamePrefix + orderNumber_FIELDNAME)
-	@Index(name = TABLE + IndexNameMiddle + orderNumber_FIELDNAME)
-	private Integer orderNumber;
+	@Column(name = ColumnNamePrefix + order_FIELDNAME)
+	@Index(name = TABLE + IndexNameMiddle + order_FIELDNAME)
+	private Integer order;
 
 	public static final String path_FIELDNAME = "path";
 	@FieldDescribe("应用路径.")
@@ -123,22 +127,11 @@ public class Component extends SliceJpaObject {
 	@CheckPersist(allowEmpty = true)
 	private List<String> denyList = new ArrayList<String>();
 
-	/** flag标志位 */
-
-	// public static String[] FLA GS = new String[] { JpaObject.id_FIELDNAME,
-	// name_FIELDNAME };
-	// @FieldDescribe("管理人员.")
-	// public static final String title_FIELDNAME = "title";
-	// @PersistentCollection(fetch = FetchType.EAGER)
-	// @OrderColumn(name = ORDERCOLUMNCOLUMN)
-	// @ContainerTable(name = TABLE + "_controllerList", joinIndex = @Index(name =
-	// TABLE + "_controllerList_join"))
-	// @ElementColumn(length =
-	// AbstractPersistenceProperties.organization_name_length, name =
-	// "xcontrollerList")
-	// @ElementIndex(name = TABLE + "_controllerList_element")
-	// @CheckPersist(allowEmpty = true)
-	// private List<String> controllerList = new ArrayList<String>();
+	public static final String type_FIELDNAME = "type";
+	@FieldDescribe("类型:system|custom")
+	@Column(length = JpaObject.length_16B, name = ColumnNamePrefix + type_FIELDNAME)
+	@CheckPersist(allowEmpty = false)
+	private String type;
 
 	public String getName() {
 		return name;
@@ -196,12 +189,12 @@ public class Component extends SliceJpaObject {
 		this.iconPath = iconPath;
 	}
 
-	public Integer getOrderNumber() {
-		return orderNumber;
+	public Integer getOrder() {
+		return order;
 	}
 
-	public void setOrderNumber(Integer orderNumber) {
-		this.orderNumber = orderNumber;
+	public void setOrder(Integer order) {
+		this.order = order;
 	}
 
 }