Przeglądaj źródła

修改优先使用本地application,删除对unit的名称限制

zhourui 5 lat temu
rodzic
commit
3e7c0b53f1

+ 27 - 13
o2server/x_base_core_project/src/main/java/com/x/base/core/project/Applications.java

@@ -13,9 +13,7 @@ import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import java.util.zip.CRC32;
 
-import org.apache.commons.lang3.BooleanUtils;
-import org.apache.commons.lang3.StringUtils;
-
+import com.x.base.core.project.config.Config;
 import com.x.base.core.project.connection.ActionResponse;
 import com.x.base.core.project.connection.CipherConnectionAction;
 import com.x.base.core.project.connection.HttpConnection;
@@ -25,6 +23,8 @@ import com.x.base.core.project.tools.DefaultCharset;
 import com.x.base.core.project.tools.ListTools;
 import com.x.base.core.project.tools.StringTools;
 
+import org.apache.commons.lang3.StringUtils;
+
 public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList<Application>> {
 
 	private static Logger logger = LoggerFactory.getLogger(Applications.class);
@@ -112,7 +112,11 @@ public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList
 		}
 		Application application = null;
 		if (StringUtils.isEmpty(seed)) {
-			application = this.randomWithWeight(name);
+			// 如果随机种子是空,那么优先使用本机
+			application = this.findApplicationWithNode(name, Config.node());
+			if (null == application) {
+				application = this.randomWithWeight(name);
+			}
 		} else {
 			application = this.randomWithSeed(name, seed);
 		}
@@ -161,7 +165,11 @@ public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList
 		}
 		Application application = null;
 		if (StringUtils.isEmpty(seed)) {
-			application = this.randomWithWeight(name);
+			// 如果随机种子是空,那么优先使用本机
+			application = this.findApplicationWithNode(name, Config.node());
+			if (null == application) {
+				application = this.randomWithWeight(name);
+			}
 		} else {
 			application = this.randomWithSeed(name, seed);
 		}
@@ -213,7 +221,11 @@ public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList
 		}
 		Application application = null;
 		if (StringUtils.isEmpty(seed)) {
-			application = this.randomWithWeight(name);
+			// 如果随机种子是空,那么优先使用本机
+			application = this.findApplicationWithNode(name, Config.node());
+			if (null == application) {
+				application = this.randomWithWeight(name);
+			}
 		} else {
 			application = this.randomWithSeed(name, seed);
 		}
@@ -265,7 +277,11 @@ public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList
 		}
 		Application application = null;
 		if (StringUtils.isEmpty(seed)) {
-			application = this.randomWithWeight(name);
+			// 如果随机种子是空,那么优先使用本机
+			application = this.findApplicationWithNode(name, Config.node());
+			if (null == application) {
+				application = this.randomWithWeight(name);
+			}
 		} else {
 			application = this.randomWithSeed(name, seed);
 		}
@@ -282,12 +298,10 @@ public class Applications extends ConcurrentHashMap<String, CopyOnWriteArrayList
 		return null;
 	}
 
-	public Application findOneAppByNode(String node) throws Exception {
-		for(List<Application> apps : this.values()){
-			for (Application app : apps){
-				if(app.getNode().equals(node)){
-					return app;
-				}
+	public Application findApplicationWithNode(String className, String node) throws Exception {
+		for (Application o : this.get(className)) {
+			if (o.getNode().equals(node)) {
+				return o;
 			}
 		}
 		return null;

+ 0 - 1
o2server/x_console/src/main/java/com/x/server/console/action/EraseContentLog.java

@@ -25,7 +25,6 @@ public class EraseContentLog extends EraseContentProcessPlatform {
 		addClass(FormVersion.class);
 		addClass(ScriptVersion.class);
 		this.run();
-		this.run();
 		return true;
 	}
 }

+ 3 - 3
o2server/x_console/src/main/java/com/x/server/console/action/EraseContentMessage.java

@@ -1,14 +1,13 @@
 package com.x.server.console.action;
 
-import javax.measure.quantity.Mass;
-
-import com.google.protobuf.Message;
 import com.x.base.core.project.logger.Logger;
 import com.x.base.core.project.logger.LoggerFactory;
 import com.x.message.core.entity.IMConversation;
 import com.x.message.core.entity.IMConversationExt;
 import com.x.message.core.entity.IMMsg;
 import com.x.message.core.entity.Instant;
+import com.x.message.core.entity.Mass;
+import com.x.message.core.entity.Message;
 import com.x.message.core.entity.Org;
 
 public class EraseContentMessage extends EraseContentProcessPlatform {
@@ -16,6 +15,7 @@ public class EraseContentMessage extends EraseContentProcessPlatform {
 	private static Logger logger = LoggerFactory.getLogger(EraseContentMessage.class);
 	@Override
 	public boolean execute() throws Exception {
+		this.init("message", null);
 		addClass(IMConversation.class);
 		addClass(IMConversationExt.class);
 		addClass(IMMsg.class);

+ 1 - 1
o2server/x_organization_core_entity/src/main/java/com/x/organization/core/entity/Unit.java

@@ -92,7 +92,7 @@ public class Unit extends SliceJpaObject {
 	@FieldDescribe("名称,可以重名.")
 	@Column(length = length_255B, name = ColumnNamePrefix + name_FIELDNAME)
 	@Index(name = TABLE + IndexNameMiddle + name_FIELDNAME)
-	@CheckPersist(allowEmpty = false, simplyString = true)
+	@CheckPersist(allowEmpty = false)
 	private String name;
 
 	public static final String unique_FIELDNAME = "unique";

+ 1 - 0
o2server/x_processplatform_assemble_surface/src/main/java/com/x/processplatform/assemble/surface/jaxrs/attachment/ActionUpload.java

@@ -73,6 +73,7 @@ class ActionUpload extends BaseAction {
 				logger.debug("filename:{}, file type:{}, text:{}.", attachment.getName(), attachment.getType(),
 						attachment.getText());
 			}
+			
 			emc.beginTransaction(Attachment.class);
 			emc.persist(attachment, CheckPersistType.all);
 			emc.commit();

+ 26 - 11
o2server/x_program_center/src/main/java/com/x/program/center/ThisApplication.java

@@ -1,16 +1,31 @@
 package com.x.program.center;
 
-import com.google.gson.internal.LinkedTreeMap;
-import com.x.base.core.project.cache.ApplicationCache;
-import com.x.base.core.project.config.Config;
-import com.x.base.core.project.logger.LoggerFactory;
-import com.x.program.center.schedule.*;
-
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import com.google.gson.internal.LinkedTreeMap;
+import com.x.base.core.project.config.Config;
+import com.x.base.core.project.logger.LoggerFactory;
+import com.x.program.center.schedule.Area;
+import com.x.program.center.schedule.CleanupCode;
+import com.x.program.center.schedule.CleanupPromptErrorLog;
+import com.x.program.center.schedule.CleanupScheduleLog;
+import com.x.program.center.schedule.CleanupUnexpectedErrorLog;
+import com.x.program.center.schedule.CleanupWarnLog;
+import com.x.program.center.schedule.CollectLog;
+import com.x.program.center.schedule.CollectPerson;
+import com.x.program.center.schedule.DingdingSyncOrganization;
+import com.x.program.center.schedule.DingdingSyncOrganizationTrigger;
+import com.x.program.center.schedule.FireSchedule;
+import com.x.program.center.schedule.QiyeweixinSyncOrganization;
+import com.x.program.center.schedule.QiyeweixinSyncOrganizationTrigger;
+import com.x.program.center.schedule.RefreshApplications;
+import com.x.program.center.schedule.TriggerAgent;
+import com.x.program.center.schedule.ZhengwuDingdingSyncOrganization;
+import com.x.program.center.schedule.ZhengwuDingdingSyncOrganizationTrigger;
+
 public class ThisApplication {
 
 	protected static Context context;
@@ -23,8 +38,6 @@ public class ThisApplication {
 
 	public static LogQueue logQueue;
 
-	// public static CodeTransferQueue codeTransferQueue;
-
 	public static List<Object> dingdingSyncOrganizationCallbackRequest = new ArrayList<>();
 
 	public static List<Object> zhengwuDingdingSyncOrganizationCallbackRequest = new ArrayList<>();
@@ -66,7 +79,8 @@ public class ThisApplication {
 			}
 			context().scheduleLocal(RefreshApplications.class, CenterQueue.REFRESHAPPLICATIONSINTERVAL,
 					CenterQueue.REFRESHAPPLICATIONSINTERVAL);
-			context().scheduleLocal(FireSchedule.class, 180, 300);
+			// 运行间隔由300秒缩减到120秒
+			context().scheduleLocal(FireSchedule.class, 180, 120);
 			context().scheduleLocal(CleanupScheduleLog.class, 10, 80);
 			context().scheduleLocal(CleanupCode.class, 10, 60 * 30);
 			context().scheduleLocal(CleanupPromptErrorLog.class, 10, 60 * 30);
@@ -74,9 +88,10 @@ public class ThisApplication {
 			context().scheduleLocal(CleanupWarnLog.class, 10, 60 * 30);
 			context().scheduleLocal(CollectPerson.class, 10, 60 * 30);
 			context().scheduleLocal(CollectLog.class, 10, 60 * 30);
-			context().scheduleLocal(TriggerAgent.class, 150, 60);
+			// 运行间隔由60秒缩减到30秒
+			context().scheduleLocal(TriggerAgent.class, 150, 30);
 			/* 行政区域每周更新一次 */
-			context().scheduleLocal(Area.class, 300, 60 * 60 * 24);
+			context().scheduleLocal(Area.class, 300, 60 * 60 * 24 * 7);
 		} catch (Exception e) {
 			e.printStackTrace();
 		}

+ 3 - 4
o2server/x_program_center/src/main/java/com/x/program/center/schedule/FireSchedule.java

@@ -10,10 +10,6 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
-import org.apache.commons.lang3.StringUtils;
-import org.quartz.JobExecutionContext;
-import org.quartz.JobExecutionException;
-
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.factory.EntityManagerContainerFactory;
 import com.x.base.core.project.Application;
@@ -27,6 +23,9 @@ import com.x.program.center.ThisApplication;
 import com.x.program.center.core.entity.ScheduleLog;
 import com.x.program.center.core.entity.ScheduleLog_;
 
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+
 public class FireSchedule extends BaseAction {
 
 	private static Logger logger = LoggerFactory.getLogger(FireSchedule.class);

+ 16 - 16
o2server/x_program_center/src/main/java/com/x/program/center/schedule/TriggerAgent.java

@@ -77,24 +77,24 @@ public class TriggerAgent extends BaseAction {
 			if (date.before(new Date())) {
 				if (LOCK.contains(pair.getId())) {
 					throw new ExceptionAgentLastNotEnd(pair);
-				} else {
-					Agent agent = null;
-					try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
-						agent = emc.find(pair.getId(), Agent.class);
-						if (null != agent) {
-							emc.beginTransaction(Agent.class);
-							agent.setLastStartTime(new Date());
-							emc.commit();
-						}
-					}
-					if (null != agent && agent.getEnable()) {
-						logger.info("trigger agent : {}, name :{}, cron: {}, last start time: {}.", pair.getId(),
-								pair.getName(), pair.getCron(),
-								(pair.getLastStartTime() == null ? "" : DateTools.format(pair.getLastStartTime())));
-						ExecuteThread thread = new ExecuteThread(agent);
-						thread.start();
+				}
+				Agent agent = null;
+				try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
+					agent = emc.find(pair.getId(), Agent.class);
+					if (null != agent) {
+						emc.beginTransaction(Agent.class);
+						agent.setLastStartTime(new Date());
+						emc.commit();
 					}
 				}
+				if (null != agent && agent.getEnable()) {
+					logger.info("trigger agent : {}, name :{}, cron: {}, last start time: {}.", pair.getId(),
+							pair.getName(), pair.getCron(),
+							(pair.getLastStartTime() == null ? "" : DateTools.format(pair.getLastStartTime())));
+					ExecuteThread thread = new ExecuteThread(agent);
+					thread.start();
+				}
+
 			}
 		} catch (Exception e) {
 			logger.error(e);