diff --git a/o2server/configSample/messages.json b/o2server/configSample/messages.json index d72c424ff192ecd2f7b25ecb2573c63ada4f7720..323d2b51f1cf0798633ad3dab68af4c244e27466 100644 --- a/o2server/configSample/messages.json +++ b/o2server/configSample/messages.json @@ -12,6 +12,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -22,6 +23,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -32,6 +34,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -42,6 +45,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -52,6 +56,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -76,6 +81,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -92,6 +98,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -102,6 +109,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -134,6 +142,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -156,6 +165,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } @@ -170,6 +180,7 @@ "pms": "", "zhengwuDingding": "", "qiyeweixin": "", + "welink": "", "ws": "", "dingding": "" } diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/container/EntityManagerContainer.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/container/EntityManagerContainer.java index fb25210e67121c282625e6e570f4229d61d40ec8..15378ed1e3b0ec391c372ea9110247f60e0e2925 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/container/EntityManagerContainer.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/container/EntityManagerContainer.java @@ -83,70 +83,70 @@ public class EntityManagerContainer extends EntityManagerContainerBasic { // Object object = jpa.get(field.getName()); Object object = FieldUtils.readField(field, jpa, true); switch (fieldType) { - case stringValue: - this.persistChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa, - checkPersist, checkPersistType); - break; - case stringValueList: - this.persistChecker.stringValueList.check(field, null == object ? null : (List) object, jpa, - checkPersist, checkPersistType); - break; - case dateValue: - this.persistChecker.dateValue.check(field, (null == object ? null : (Date) object), jpa, - checkPersist, checkPersistType); - break; - case dateValueList: - this.persistChecker.dateValueList.check(field, (null == object ? null : (List) object), jpa, - checkPersist, checkPersistType); - break; - case booleanValue: - this.persistChecker.booleanValue.check(field, (null == object ? null : (Boolean) object), jpa, - checkPersist, checkPersistType); - break; - case booleanValueList: - this.persistChecker.booleanValueList.check(field, (null == object ? null : (List) object), - jpa, checkPersist, checkPersistType); - break; - case integerValue: - this.persistChecker.integerValue.check(field, (null == object ? null : (Integer) object), jpa, - checkPersist, checkPersistType); - break; - case integerValueList: - this.persistChecker.integerValueList.check(field, (null == object ? null : (List) object), - jpa, checkPersist, checkPersistType); - break; - case doubleValue: - this.persistChecker.doubleValue.check(field, (null == object ? null : (Double) object), jpa, - checkPersist, checkPersistType); - break; - case doubleValueList: - this.persistChecker.doubleValueList.check(field, (null == object ? null : (List) object), - jpa, checkPersist, checkPersistType); - break; - case longValue: - this.persistChecker.longValue.check(field, (null == object ? null : (Long) object), jpa, - checkPersist, checkPersistType); - break; - case longValueList: - this.persistChecker.longValueList.check(field, (null == object ? null : (List) object), jpa, - checkPersist, checkPersistType); - break; - case floatValue: - this.persistChecker.floatValue.check(field, (null == object ? null : (Float) object), jpa, - checkPersist, checkPersistType); - break; - case floatValueList: - this.persistChecker.floatValueList.check(field, (null == object ? null : (List) object), jpa, - checkPersist, checkPersistType); - break; - case byteValueArray: - this.persistChecker.byteValueArray.check(field, (null == object ? null : (byte[]) object), jpa, - checkPersist, checkPersistType); - break; - case enumValue: - break; - default: - break; + case stringValue: + this.persistChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa, + checkPersist, checkPersistType); + break; + case stringValueList: + this.persistChecker.stringValueList.check(field, null == object ? null : (List) object, jpa, + checkPersist, checkPersistType); + break; + case dateValue: + this.persistChecker.dateValue.check(field, (null == object ? null : (Date) object), jpa, checkPersist, + checkPersistType); + break; + case dateValueList: + this.persistChecker.dateValueList.check(field, (null == object ? null : (List) object), jpa, + checkPersist, checkPersistType); + break; + case booleanValue: + this.persistChecker.booleanValue.check(field, (null == object ? null : (Boolean) object), jpa, + checkPersist, checkPersistType); + break; + case booleanValueList: + this.persistChecker.booleanValueList.check(field, (null == object ? null : (List) object), jpa, + checkPersist, checkPersistType); + break; + case integerValue: + this.persistChecker.integerValue.check(field, (null == object ? null : (Integer) object), jpa, + checkPersist, checkPersistType); + break; + case integerValueList: + this.persistChecker.integerValueList.check(field, (null == object ? null : (List) object), jpa, + checkPersist, checkPersistType); + break; + case doubleValue: + this.persistChecker.doubleValue.check(field, (null == object ? null : (Double) object), jpa, + checkPersist, checkPersistType); + break; + case doubleValueList: + this.persistChecker.doubleValueList.check(field, (null == object ? null : (List) object), jpa, + checkPersist, checkPersistType); + break; + case longValue: + this.persistChecker.longValue.check(field, (null == object ? null : (Long) object), jpa, checkPersist, + checkPersistType); + break; + case longValueList: + this.persistChecker.longValueList.check(field, (null == object ? null : (List) object), jpa, + checkPersist, checkPersistType); + break; + case floatValue: + this.persistChecker.floatValue.check(field, (null == object ? null : (Float) object), jpa, checkPersist, + checkPersistType); + break; + case floatValueList: + this.persistChecker.floatValueList.check(field, (null == object ? null : (List) object), jpa, + checkPersist, checkPersistType); + break; + case byteValueArray: + this.persistChecker.byteValueArray.check(field, (null == object ? null : (byte[]) object), jpa, + checkPersist, checkPersistType); + break; + case enumValue: + break; + default: + break; } } } @@ -161,16 +161,16 @@ public class EntityManagerContainer extends EntityManagerContainerBasic { // Object object = jpa.get(field.getName()); Object object = FieldUtils.readField(field, jpa, true); switch (fieldType) { - case stringValue: - this.removeChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa, - checkRemove, checkRemoveType); - break; - case stringValueList: - this.removeChecker.stringValueList.check(field, null == object ? null : (List) object, jpa, - checkRemove, checkRemoveType); - break; - default: - break; + case stringValue: + this.removeChecker.stringValue.check(field, null == object ? null : Objects.toString(object), jpa, + checkRemove, checkRemoveType); + break; + case stringValueList: + this.removeChecker.stringValueList.check(field, null == object ? null : (List) object, jpa, + checkRemove, checkRemoveType); + break; + default: + break; } } } @@ -208,19 +208,18 @@ public class EntityManagerContainer extends EntityManagerContainerBasic { t = em.find(cls, id); } switch (exceptionWhen) { - case not_found: - if (null == t) { - throw new Exception("can not find entity id: " + id + ", class: " + cls.getCanonicalName() + "."); - } - break; - case found: - if (null != t) { - throw new Exception( - "entity already existed, id: " + id + ", class: " + cls.getCanonicalName() + "."); - } - break; - default: - break; + case not_found: + if (null == t) { + throw new Exception("can not find entity id: " + id + ", class: " + cls.getCanonicalName() + "."); + } + break; + case found: + if (null != t) { + throw new Exception("entity already existed, id: " + id + ", class: " + cls.getCanonicalName() + "."); + } + break; + default: + break; } return t; } @@ -245,14 +244,14 @@ public class EntityManagerContainer extends EntityManagerContainerBasic { Predicate p = cb.equal(root.get(field.getName()), flag); List list = em.createQuery(cq.select(root).where(p).distinct(true)).setMaxResults(2).getResultList(); switch (list.size()) { - case 0: - break; - case 1: - t = list.get(0); - break out; - case 2: - throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName() - + ", attribute:" + field.getName() + "."); + case 0: + break; + case 1: + t = list.get(0); + break out; + case 2: + throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName() + + ", attribute:" + field.getName() + "."); } } return t; @@ -310,15 +309,15 @@ public class EntityManagerContainer extends EntityManagerContainerBasic { cq.select(root).where(p); List list = em.createQuery(cq).setMaxResults(2).getResultList(); switch (list.size()) { - case 0: - break; - case 1: - t = list.get(0); - break out; - default: - throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName() - + ", attribute:" + field.getName() + ", restrict attrubte:" + singularAttribute - + ", restrict value:" + restrictValue + "."); + case 0: + break; + case 1: + t = list.get(0); + break out; + default: + throw new Exception("flag get multiple entity flag:" + flag + ", class:" + cls.getName() + + ", attribute:" + field.getName() + ", restrict attrubte:" + singularAttribute + + ", restrict value:" + restrictValue + "."); } } return t; @@ -940,6 +939,19 @@ public class EntityManagerContainer extends EntityManagerContainerBasic { return new ArrayList<>(os); } + public List idsLessThanMax(Class cls, String attribute, Comparable value, + Integer count) throws Exception { + EntityManager em = this.get(cls); + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(String.class); + Root root = cq.from(cls); + Predicate p = cb.lessThan(root.get(attribute), (Comparable) value); + List os = em.createQuery(cq.select(root.get(JpaObject.id_FIELDNAME)).where(p)).setMaxResults(count) + .getResultList(); + List list = new ArrayList<>(os); + return list; + } + public List idsGreaterThan(Class cls, String attribute, Object value) throws Exception { EntityManager em = this.get(cls); diff --git a/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java b/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java index 4292c7eb33bc6fe215c36fbb926d38ea34accbc1..da3903e2e3e6fb407d2d9e8ceb7234c21c1e7c16 100644 --- a/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java +++ b/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java @@ -135,9 +135,9 @@ public class ResourceFactory { private static void internal_driud_c3p0() throws Exception { for (Entry entry : Config.nodes().dataServers().entrySet()) { DruidDataSourceC3P0Adapter dataSource = new DruidDataSourceC3P0Adapter(); - String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort() + "/X;JMX=" - + (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE=" - + (entry.getValue().getCacheSize() * 1024); + String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort() + + "/X;DEFAULT_LOCK_TIMEOUT=99999999;JMX=" + (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + + ";CACHE_SIZE=" + (entry.getValue().getCacheSize() * 1024); dataSource.setJdbcUrl(url); dataSource.setDriverClass(SlicePropertiesBuilder.driver_h2); dataSource.setPreferredTestQuery(SlicePropertiesBuilder.validationQueryOfUrl(url)); @@ -164,9 +164,9 @@ public class ResourceFactory { BasicDataSource dataSource = new BasicDataSource(); - String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort() + "/X;JMX=" - + (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE=" - + (entry.getValue().getCacheSize() * 1024); + String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort() + + "/X;DEFAULT_LOCK_TIMEOUT=99999999;JMX=" + (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + + ";CACHE_SIZE=" + (entry.getValue().getCacheSize() * 1024); dataSource.setDriverClassName(SlicePropertiesBuilder.driver_h2); dataSource.setUrl(url); dataSource.setInitialSize(0); @@ -188,9 +188,9 @@ public class ResourceFactory { private static void internal_driud() throws Exception { for (Entry entry : Config.nodes().dataServers().entrySet()) { DruidDataSource dataSource = new DruidDataSource(); - String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort() + "/X;JMX=" - + (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + ";CACHE_SIZE=" - + (entry.getValue().getCacheSize() * 1024); + String url = "jdbc:h2:tcp://" + entry.getKey() + ":" + entry.getValue().getTcpPort() + + "/X;DEFAULT_LOCK_TIMEOUT=99999999;JMX=" + (entry.getValue().getJmxEnable() ? "TRUE" : "FALSE") + + ";CACHE_SIZE=" + (entry.getValue().getCacheSize() * 1024); dataSource.setDriverClassName(SlicePropertiesBuilder.driver_h2); dataSource.setUrl(url); dataSource.setInitialSize(0); @@ -247,10 +247,10 @@ public class ResourceFactory { private static void processPlatformExecutors() throws Exception { ExecutorService[] services = new ExecutorService[Config.processPlatform().getExecutorCount()]; for (int i = 0; i < Config.processPlatform().getExecutorCount(); i++) { - //services[i] = Executors.newSingleThreadExecutor(); + // services[i] = Executors.newSingleThreadExecutor(); services[i] = Executors.newFixedThreadPool(1); } - + new Resource(Config.RESOURCE_NODE_PROCESSPLATFORMEXECUTORS, services); } diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/LogMessage.java b/o2server/x_program_center/src/main/java/com/x/program/center/LogMessage.java deleted file mode 100644 index 19b0b63a5c7492364e9885316102e29cdd5b6d0b..0000000000000000000000000000000000000000 --- a/o2server/x_program_center/src/main/java/com/x/program/center/LogMessage.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.x.program.center; - -import java.util.Date; - -public class LogMessage { - - private String remoteAddress; - private String text; - private Date dateTime; - - public String getRemoteAddress() { - return remoteAddress; - } - - public void setRemoteAddress(String remoteAddress) { - this.remoteAddress = remoteAddress; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public Date getDateTime() { - return dateTime; - } - - public void setDateTime(Date dateTime) { - this.dateTime = dateTime; - } - -} diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/LogQueue.java b/o2server/x_program_center/src/main/java/com/x/program/center/LogQueue.java index 7657f0c36a3dc7961cc3cea6f377286edd05388e..1a06a6b8e7bd042153416682d1f681c661a25924 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/LogQueue.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/LogQueue.java @@ -1,13 +1,19 @@ package com.x.program.center; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + import org.apache.commons.lang3.StringUtils; import com.x.base.core.container.EntityManagerContainer; import com.x.base.core.container.factory.EntityManagerContainerFactory; +import com.x.base.core.entity.JpaObject; import com.x.base.core.entity.annotation.CheckPersistType; import com.x.base.core.project.bean.NameValuePair; import com.x.base.core.project.queue.AbstractQueue; import com.x.program.center.core.entity.PromptErrorLog; +import com.x.program.center.core.entity.ScheduleLog; import com.x.program.center.core.entity.UnexpectedErrorLog; import com.x.program.center.core.entity.WarnLog; @@ -16,39 +22,61 @@ public class LogQueue extends AbstractQueue { protected void execute(NameValuePair pair) { try { if (StringUtils.equals(pair.getName(), PromptErrorLog.class.getName())) { - this.concretePromptErrorLog(pair.getValue(PromptErrorLog.class)); + PromptErrorLog o = pair.getValue(PromptErrorLog.class); + if (null != o) { + this.concrete(PromptErrorLog.class, o); + } else { + this.clean(PromptErrorLog.class); + } } else if (StringUtils.equals(pair.getName(), UnexpectedErrorLog.class.getName())) { - this.concreteUnexpectedErrorLog(pair.getValue(UnexpectedErrorLog.class)); + UnexpectedErrorLog o = pair.getValue(UnexpectedErrorLog.class); + if (null != o) { + this.concrete(UnexpectedErrorLog.class, o); + } else { + this.clean(UnexpectedErrorLog.class); + } } else if (StringUtils.equals(pair.getName(), WarnLog.class.getName())) { - this.concreteWarnLog(pair.getValue(WarnLog.class)); + WarnLog o = pair.getValue(WarnLog.class); + if (null != o) { + this.concrete(WarnLog.class, o); + } else { + this.clean(WarnLog.class); + } + } else if (StringUtils.equals(pair.getName(), ScheduleLog.class.getName())) { + ScheduleLog o = pair.getValue(ScheduleLog.class); + if (null != o) { + this.concrete(ScheduleLog.class, o); + } else { + this.clean(ScheduleLog.class); + } } } catch (Exception e) { e.printStackTrace(); } } - private void concretePromptErrorLog(PromptErrorLog o) throws Exception { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - emc.beginTransaction(PromptErrorLog.class); - emc.persist(o, CheckPersistType.all); - emc.commit(); - } - } - - private void concreteUnexpectedErrorLog(UnexpectedErrorLog o) throws Exception { + private void concrete(Class cls, T o) throws Exception { try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - emc.beginTransaction(UnexpectedErrorLog.class); + emc.beginTransaction(cls); emc.persist(o, CheckPersistType.all); emc.commit(); } } - private void concreteWarnLog(WarnLog o) throws Exception { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - emc.beginTransaction(WarnLog.class); - emc.persist(o, CheckPersistType.all); - emc.commit(); - } + private void clean(Class cls) throws Exception { + List ids = new ArrayList<>(); + do { + try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { + Calendar threshold = Calendar.getInstance(); + threshold.add(Calendar.DATE, -5); + ids = emc.idsLessThanMax(cls, JpaObject.createTime_FIELDNAME, threshold.getTime(), 500); + if (!ids.isEmpty()) { + emc.beginTransaction(cls); + emc.delete(cls, ids); + emc.commit(); + } + } + } while (!ids.isEmpty()); } } diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/ThisApplication.java b/o2server/x_program_center/src/main/java/com/x/program/center/ThisApplication.java index d4f1c8351066e8bcc697db74d4f7b419b0c03cce..eec8793521a4a559b43e775f1f4f66438acc5167 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/ThisApplication.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/ThisApplication.java @@ -8,7 +8,23 @@ 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.*; +import com.x.program.center.schedule.Area; +import com.x.program.center.schedule.Cleanup; +import com.x.program.center.schedule.CleanupCode; +import com.x.program.center.schedule.CollectLog; +import com.x.program.center.schedule.CollectMarket; +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.WeLinkSyncOrganization; +import com.x.program.center.schedule.WeLinkSyncOrganizationTrigger; +import com.x.program.center.schedule.ZhengwuDingdingSyncOrganization; +import com.x.program.center.schedule.ZhengwuDingdingSyncOrganizationTrigger; public class ThisApplication { @@ -20,7 +36,7 @@ public class ThisApplication { public static CenterQueue centerQueue = new CenterQueue(); - public static LogQueue logQueue; + public static LogQueue logQueue = new LogQueue(); public static List dingdingSyncOrganizationCallbackRequest = new ArrayList<>(); @@ -37,7 +53,6 @@ public class ThisApplication { LoggerFactory.setLevel(Config.logLevel().x_program_center()); /* 20190927新报告机制 */ context().startQueue(centerQueue); - logQueue = new LogQueue(); context().startQueue(logQueue); /* 政务钉钉拉入同步 */ @@ -75,11 +90,8 @@ public class ThisApplication { CenterQueue.REFRESHAPPLICATIONSINTERVAL); // 运行间隔由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); - context().scheduleLocal(CleanupUnexpectedErrorLog.class, 10, 60 * 30); - context().scheduleLocal(CleanupWarnLog.class, 10, 60 * 30); + context().scheduleLocal(Cleanup.class, 10, 60 * 30); context().scheduleLocal(CollectPerson.class, 10, 60 * 30); context().scheduleLocal(CollectMarket.class, 10, 60 * 60 * 6); context().scheduleLocal(CollectLog.class, 10, 60 * 30); diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/schedule/ActionReport.java b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/schedule/ActionReport.java index 7bda66d9bdb6f945b1a6164836c2cf59e0e84474..21fd48c5860148b48847c74c412d8f705a18a88a 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/schedule/ActionReport.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/schedule/ActionReport.java @@ -1,36 +1,37 @@ package com.x.program.center.jaxrs.schedule; +import org.apache.commons.lang3.StringUtils; + import com.google.gson.JsonElement; -import com.x.base.core.container.EntityManagerContainer; -import com.x.base.core.container.factory.EntityManagerContainerFactory; import com.x.base.core.entity.JpaObject; -import com.x.base.core.entity.annotation.CheckPersistType; +import com.x.base.core.project.bean.NameValuePair; import com.x.base.core.project.bean.WrapCopier; import com.x.base.core.project.bean.WrapCopierFactory; -import com.x.base.core.project.exception.ExceptionAccessDenied; import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.jaxrs.WrapBoolean; +import com.x.base.core.project.tools.StringTools; +import com.x.program.center.ThisApplication; import com.x.program.center.core.entity.ScheduleLog; class ActionReport extends BaseAction { ActionResult execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - Wi wi = this.convertToWrapIn(jsonElement, Wi.class); - if (effectivePerson.isNotManager()) { - throw new ExceptionAccessDenied(effectivePerson); - } - ActionResult result = new ActionResult<>(); - emc.beginTransaction(ScheduleLog.class); - ScheduleLog log = Wi.copier.copy(wi); - emc.persist(log, CheckPersistType.all); - emc.commit(); - Wo wo = new Wo(); - wo.setValue(true); - result.setData(wo); - return result; + ActionResult result = new ActionResult<>(); + Wi wi = gson.fromJson(jsonElement, Wi.class); + ScheduleLog o = Wi.copier.copy(wi); + /** 默认使用传递过来的id,如果不存在那么重新赋值 */ + if (StringUtils.isEmpty(o.getId())) { + o.setId(StringTools.uniqueToken()); } + NameValuePair pair = new NameValuePair(); + pair.setName(ScheduleLog.class.getName()); + pair.setValue(o); + ThisApplication.logQueue.send(pair); + Wo wo = new Wo(); + wo.setValue(true); + result.setData(wo); + return result; } public static class Wi extends ScheduleLog { diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/test/ActionTest1.java b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/test/ActionTest1.java index 7a0b93eec2b0d79d9b83eabed05dba85afd5f5b4..f27b5b76f6c055cacccfb39f87cf73bec73f6b4a 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/test/ActionTest1.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/jaxrs/test/ActionTest1.java @@ -1,14 +1,5 @@ package com.x.program.center.jaxrs.test; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; - -import com.x.base.core.project.Applications; -import com.x.base.core.project.config.CenterServer; -import com.x.base.core.project.config.CenterServers; -import com.x.base.core.project.config.Config; -import com.x.base.core.project.exception.ExceptionAccessDenied; import com.x.base.core.project.gson.GsonPropertyObject; import com.x.base.core.project.http.ActionResult; import com.x.base.core.project.http.EffectivePerson; @@ -19,38 +10,10 @@ class ActionTest1 extends BaseAction { ActionResult result = new ActionResult<>(); - if (!effectivePerson.isManager()) { - throw new ExceptionAccessDenied(effectivePerson); - } - - Wo wo = new Wo(); - - wo.applications = gson.fromJson(Config.resource_node_applications(), Applications.class); - wo.resource_node_centersPirmaryNode = Config.resource_node_centersPirmaryNode(); - wo.resource_node_centersPirmaryPort = Config.resource_node_centersPirmaryPort(); - wo.resource_node_centersPirmarySslEnable = Config.resource_node_centersPirmarySslEnable(); - for (Entry en : Config.nodes().centerServers().orderedEntry()) { - wo.nodes_centerServers_ordered.add(en.getValue()); - } - wo.centerServers = Config.nodes().centerServers(); - result.setData(wo); - return result; } public static class Wo extends GsonPropertyObject { - private Applications applications; - - private String resource_node_centersPirmaryNode; - - private Integer resource_node_centersPirmaryPort; - - private Boolean resource_node_centersPirmarySslEnable; - - private List nodes_centerServers_ordered = new ArrayList<>(); - - private CenterServers centerServers; - } } \ No newline at end of file diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/Cleanup.java b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/Cleanup.java new file mode 100644 index 0000000000000000000000000000000000000000..bf74b3a9ddcceaec87fd1ffd53644035b5dfd973 --- /dev/null +++ b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/Cleanup.java @@ -0,0 +1,45 @@ +package com.x.program.center.schedule; + +import java.util.ArrayList; +import java.util.List; + +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; + +import com.x.base.core.entity.JpaObject; +import com.x.base.core.project.bean.NameValuePair; +import com.x.base.core.project.logger.Logger; +import com.x.base.core.project.logger.LoggerFactory; +import com.x.program.center.ThisApplication; +import com.x.program.center.core.entity.PromptErrorLog; +import com.x.program.center.core.entity.ScheduleLog; +import com.x.program.center.core.entity.UnexpectedErrorLog; +import com.x.program.center.core.entity.WarnLog; + +public class Cleanup extends BaseAction { + + private static Logger logger = LoggerFactory.getLogger(Cleanup.class); + + private List> list = new ArrayList<>(); + + private int tag = 0; + + public Cleanup() { + list.add(ScheduleLog.class); + list.add(PromptErrorLog.class); + list.add(UnexpectedErrorLog.class); + list.add(WarnLog.class); + } + + @Override + public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { + try { + if (pirmaryCenter()) { + ThisApplication.logQueue.send(new NameValuePair(list.get((tag++) % list.size()).getName(), null)); + } + } catch (Exception e) { + logger.error(e); + throw new JobExecutionException(e); + } + } +} \ No newline at end of file diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupPromptErrorLog.java b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupPromptErrorLog.java index a461b6b6bf7f6791e4cc78b5ef5fa54a2dc2be33..69df6ebc3d94b9716e03dcf9ed8f3d6eef75b7d5 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupPromptErrorLog.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupPromptErrorLog.java @@ -1,23 +1,13 @@ package com.x.program.center.schedule; -import java.util.Calendar; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - 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.bean.NameValuePair; import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; +import com.x.program.center.ThisApplication; import com.x.program.center.core.entity.PromptErrorLog; -import com.x.program.center.core.entity.PromptErrorLog_; public class CleanupPromptErrorLog extends BaseAction { @@ -27,36 +17,11 @@ public class CleanupPromptErrorLog extends BaseAction { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { try { if (pirmaryCenter()) { - cleanupPromptErrorLog(); + ThisApplication.logQueue.send(new NameValuePair(PromptErrorLog.class.getName(), null)); } } catch (Exception e) { logger.error(e); throw new JobExecutionException(e); } } - - private void cleanupPromptErrorLog() throws Exception { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - EntityManager em = emc.get(PromptErrorLog.class); - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(String.class); - Root root = cq.from(PromptErrorLog.class); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DAY_OF_MONTH, -7); - Predicate p = cb.not(cb.greaterThan(root.get(PromptErrorLog_.createTime), cal.getTime())); - cq.select(root.get(PromptErrorLog_.id)).where(p); - List list = em.createQuery(cq).getResultList(); - for (int i = 0; i < list.size(); i++) { - if (i % 100 == 0) { - emc.beginTransaction(PromptErrorLog.class); - } - PromptErrorLog o = emc.find(list.get(i), PromptErrorLog.class); - emc.remove(o); - if ((i % 100 == 99) || (i == (list.size() - 1))) { - emc.commit(); - } - } - } - } - } diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupScheduleLog.java b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupScheduleLog.java deleted file mode 100644 index 6871929a71817604b34db5079fb533024420b9b5..0000000000000000000000000000000000000000 --- a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupScheduleLog.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.x.program.center.schedule; - -import java.util.ArrayList; -import java.util.Calendar; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - -import org.quartz.Job; -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.entity.annotation.CheckRemoveType; -import com.x.base.core.project.logger.Logger; -import com.x.base.core.project.logger.LoggerFactory; -import com.x.program.center.Business; -import com.x.program.center.core.entity.ScheduleLog; -import com.x.program.center.core.entity.ScheduleLog_; - -public class CleanupScheduleLog implements Job { - - private static Logger logger = LoggerFactory.getLogger(CleanupScheduleLog.class); - - @Override - public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { - try { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - Business business = new Business(emc); - this.clearScheduleLog(business); - } - } catch (Exception e) { - e.printStackTrace(); - throw new JobExecutionException(e); - } - - } - - private void clearScheduleLog(Business business) throws Exception { - List list = new ArrayList<>(); - do { - EntityManagerContainer emc = business.entityManagerContainer(); - EntityManager em = emc.get(ScheduleLog.class); - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(ScheduleLog.class); - Root root = cq.from(ScheduleLog.class); - Calendar threshold = Calendar.getInstance(); - threshold.add(Calendar.DATE, -7); - Predicate p = cb.lessThan(root.get(ScheduleLog_.createTime), threshold.getTime()); - list = em.createQuery(cq.select(root).where(p)).setMaxResults(2000).getResultList(); - if (!list.isEmpty()) { - emc.beginTransaction(ScheduleLog.class); - list.stream().forEach(o -> { - try { - emc.remove(o, CheckRemoveType.all); - } catch (Exception e) { - logger.error(e); - } - }); - emc.commit(); - } - } while (!list.isEmpty()); - } - -} \ No newline at end of file diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupUnexpectedErrorLog.java b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupUnexpectedErrorLog.java index 163a62d9cf472a2651efd919305aa2b846bd1b39..7fac53f6061869ff1b9db6f0a531e18ed344529d 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupUnexpectedErrorLog.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupUnexpectedErrorLog.java @@ -1,23 +1,13 @@ package com.x.program.center.schedule; -import java.util.Calendar; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - 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.bean.NameValuePair; import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; +import com.x.program.center.ThisApplication; import com.x.program.center.core.entity.UnexpectedErrorLog; -import com.x.program.center.core.entity.UnexpectedErrorLog_; public class CleanupUnexpectedErrorLog extends BaseAction { @@ -27,7 +17,7 @@ public class CleanupUnexpectedErrorLog extends BaseAction { public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { try { if (pirmaryCenter()) { - cleanupUnexpectedErrorLog(); + ThisApplication.logQueue.send(new NameValuePair(UnexpectedErrorLog.class.getName(), null)); } } catch (Exception e) { logger.error(e); @@ -35,27 +25,4 @@ public class CleanupUnexpectedErrorLog extends BaseAction { } } - private void cleanupUnexpectedErrorLog() throws Exception { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - EntityManager em = emc.get(UnexpectedErrorLog.class); - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(String.class); - Root root = cq.from(UnexpectedErrorLog.class); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DAY_OF_MONTH, -7); - Predicate p = cb.not(cb.greaterThan(root.get(UnexpectedErrorLog_.createTime), cal.getTime())); - cq.select(root.get(UnexpectedErrorLog_.id)).where(p); - List list = em.createQuery(cq).getResultList(); - for (int i = 0; i < list.size(); i++) { - if (i % 100 == 0) { - emc.beginTransaction(UnexpectedErrorLog.class); - } - UnexpectedErrorLog o = emc.find(list.get(i), UnexpectedErrorLog.class); - emc.remove(o); - if ((i % 100 == 99) || (i == (list.size() - 1))) { - emc.commit(); - } - } - } - } } diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupWarnLog.java b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupWarnLog.java index adae4fbe588f3013362c3434d342a70d39f164fb..a56834150df1012d89789af9d128005acf49ebd5 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupWarnLog.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CleanupWarnLog.java @@ -1,23 +1,13 @@ package com.x.program.center.schedule; -import java.util.Calendar; -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Predicate; -import javax.persistence.criteria.Root; - 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.bean.NameValuePair; import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; +import com.x.program.center.ThisApplication; import com.x.program.center.core.entity.WarnLog; -import com.x.program.center.core.entity.WarnLog_; public class CleanupWarnLog extends BaseAction { @@ -27,35 +17,11 @@ public class CleanupWarnLog extends BaseAction { public void execute(JobExecutionContext arg0) throws JobExecutionException { try { if (pirmaryCenter()) { - cleanupWarnLog(); + ThisApplication.logQueue.send(new NameValuePair(WarnLog.class.getName(), null)); } } catch (Exception e) { logger.error(e); throw new JobExecutionException(e); } } - - private void cleanupWarnLog() throws Exception { - try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) { - EntityManager em = emc.get(WarnLog.class); - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(String.class); - Root root = cq.from(WarnLog.class); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DAY_OF_MONTH, -7); - Predicate p = cb.not(cb.greaterThan(root.get(WarnLog_.createTime), cal.getTime())); - cq.select(root.get(WarnLog_.id)).where(p); - List list = em.createQuery(cq).getResultList(); - for (int i = 0; i < list.size(); i++) { - if (i % 100 == 0) { - emc.beginTransaction(WarnLog.class); - } - WarnLog o = emc.find(list.get(i), WarnLog.class); - emc.remove(o); - if ((i % 100 == 99) || (i == (list.size() - 1))) { - emc.commit(); - } - } - } - } } diff --git a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CollectMarket.java b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CollectMarket.java index 32b28f8a457f018dc1b869f3270b2a9ea0e4dd86..1882ae2180ac3fba5cda01f7c849e7464f622dd4 100644 --- a/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CollectMarket.java +++ b/o2server/x_program_center/src/main/java/com/x/program/center/schedule/CollectMarket.java @@ -1,40 +1,32 @@ package com.x.program.center.schedule; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.BooleanUtils; +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.entity.JpaObject; import com.x.base.core.entity.annotation.CheckPersistType; -import com.x.base.core.project.annotation.FieldDescribe; import com.x.base.core.project.bean.NameValuePair; import com.x.base.core.project.bean.WrapCopier; import com.x.base.core.project.bean.WrapCopierFactory; -import com.x.base.core.project.config.CenterServer; import com.x.base.core.project.config.Collect; import com.x.base.core.project.config.Config; import com.x.base.core.project.connection.ActionResponse; import com.x.base.core.project.connection.ConnectionAction; -import com.x.base.core.project.gson.GsonPropertyObject; -import com.x.base.core.project.http.HttpToken; -import com.x.base.core.project.http.WrapOutBoolean; -import com.x.base.core.project.jaxrs.WrapString; import com.x.base.core.project.logger.Logger; import com.x.base.core.project.logger.LoggerFactory; -import com.x.base.core.project.tools.Host; import com.x.base.core.project.tools.ListTools; -import com.x.organization.core.entity.Person; import com.x.program.center.Business; import com.x.program.center.core.entity.Application; import com.x.program.center.core.entity.Attachment; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.eclipse.jetty.deploy.App; -import org.quartz.JobExecutionContext; -import org.quartz.JobExecutionException; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; public class CollectMarket extends BaseAction { diff --git a/o2server/x_program_center_core_entity/src/main/java/com/x/program/center/core/entity/PersistenceProperties.java b/o2server/x_program_center_core_entity/src/main/java/com/x/program/center/core/entity/PersistenceProperties.java index 79c418b060eada57d295fb628a971a87685b1c1b..0ed11e6380d981142a2132d0f22778fb576ecef4 100644 --- a/o2server/x_program_center_core_entity/src/main/java/com/x/program/center/core/entity/PersistenceProperties.java +++ b/o2server/x_program_center_core_entity/src/main/java/com/x/program/center/core/entity/PersistenceProperties.java @@ -16,21 +16,21 @@ public final class PersistenceProperties extends AbstractPersistenceProperties { public static final String table = "CTE_SCHEDULELOG"; } - public static class ClockTimer { - public static final String table = "CTE_CLOCKTIMER"; - } - - public static class ClockTimerLog { - public static final String table = "CTE_CLOCKTIMERLOG"; - } - - public static class ClockSchedule { - public static final String table = "CTE_CLOCKSCHEDULE"; - } - - public static class ClockScheduleLog { - public static final String table = "CTE_CLOCKSCHEDULELOG"; - } +// public static class ClockTimer { +// public static final String table = "CTE_CLOCKTIMER"; +// } +// +// public static class ClockTimerLog { +// public static final String table = "CTE_CLOCKTIMERLOG"; +// } +// +// public static class ClockSchedule { +// public static final String table = "CTE_CLOCKSCHEDULE"; +// } +// +// public static class ClockScheduleLog { +// public static final String table = "CTE_CLOCKSCHEDULELOG"; +// } public static class PromptErrorLog { public static final String table = "CTE_PROMPTERRORLOG";