Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_42566577
o2oa
提交
e2e15a38
o2oa
项目概览
weixin_42566577
/
o2oa
与 Fork 源项目一致
Fork自
浙江兰德纵横网络技术股份有限公司 / o2oa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
o2oa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e2e15a38
编写于
4月 10, 2022
作者:
O
o2null
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add jdbcConsumeQueue tableConsumeQueue
上级
acc42076
变更
20
隐藏空白更改
内联
并排
Showing
20 changed file
with
1368 addition
and
634 deletion
+1368
-634
o2server/person.json
o2server/person.json
+27
-0
o2server/pom.xml
o2server/pom.xml
+6
-5
o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java
...ava/com/x/base/core/project/build/CreateConfigSample.java
+2
-0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java
.../src/main/java/com/x/base/core/project/config/Config.java
+14
-0
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/MessageJdbc.java
...main/java/com/x/base/core/project/config/MessageJdbc.java
+24
-33
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/MessageTable.java
...ain/java/com/x/base/core/project/config/MessageTable.java
+36
-0
o2server/x_message_assemble_communicate/pom.xml
o2server/x_message_assemble_communicate/pom.xml
+17
-32
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/ExceptionTableReturn.java
.../x/message/assemble/communicate/ExceptionTableReturn.java
+12
-0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/JdbcConsumeQueue.java
.../com/x/message/assemble/communicate/JdbcConsumeQueue.java
+531
-43
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/TableConsumeQueue.java
...com/x/message/assemble/communicate/TableConsumeQueue.java
+133
-0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/ThisApplication.java
...a/com/x/message/assemble/communicate/ThisApplication.java
+6
-0
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/connector/ActionCreate.java
...ge/assemble/communicate/jaxrs/connector/ActionCreate.java
+4
-1
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/schedule/TriggerMessageConsumeQueue.java
...mble/communicate/schedule/TriggerMessageConsumeQueue.java
+4
-1
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/ActionInsert.java
.../x/query/service/processing/jaxrs/table/ActionInsert.java
+60
-0
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/ActionUpdate.java
.../x/query/service/processing/jaxrs/table/ActionUpdate.java
+0
-466
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/ActionUpdateWithBundle.java
...ervice/processing/jaxrs/table/ActionUpdateWithBundle.java
+72
-0
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/BaseAction.java
...om/x/query/service/processing/jaxrs/table/BaseAction.java
+398
-0
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/TableAction.java
...m/x/query/service/processing/jaxrs/table/TableAction.java
+22
-6
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/touch/ActionTest.java
...om/x/query/service/processing/jaxrs/touch/ActionTest.java
+0
-28
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/touch/TouchAction.java
...m/x/query/service/processing/jaxrs/touch/TouchAction.java
+0
-19
未找到文件。
o2server/person.json
0 → 100644
浏览文件 @
e2e15a38
{
"MAX_PASSWORDPERIOD"
:
3650
,
"captchaLogin"
:
false
,
"codeLogin"
:
true
,
"bindLogin"
:
true
,
"faceLogin"
:
true
,
"password"
:
"(var v
\\
u003d person.getMobile();
\\
u000a return v.substring(v.length - 6))"
,
"passwordPeriod"
:
0
,
"passwordRegex"
:
"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,}$"
,
"passwordRegexHint"
:
"6位以上,包含数字和字母."
,
"register"
:
"disable"
,
"superPermission"
:
true
,
"mobileRegex"
:
"(^(
\\
+)?0{0,2}852
\\
d{8}$)|(^(
\\
+)?0{0,2}853
\\
d{8}$)|(^(
\\
+)?0{0,2}886
\\
d{9}$)|(^1(3|4|5|6|7|8|9)
\\
d{9}$)"
,
"loginPage"
:
{
"enable"
:
true
,
"portal"
:
"f4fbfb29-98ae-45c5-a9ac-a4d141049d78"
,
"page"
:
""
},
"failureInterval"
:
10
,
"failureCount"
:
5
,
"tokenExpiredMinutes"
:
21600
,
"tokenCookieHttpOnly"
:
false
,
"tokenName"
:
"x-token"
,
"personUnitOrderByAsc"
:
true
,
"language"
:
"zh-CN"
,
"captchaFont"
:
""
}
\ No newline at end of file
o2server/pom.xml
浏览文件 @
e2e15a38
...
...
@@ -75,6 +75,12 @@
<dependency>
<groupId>
org.apache.openjpa
</groupId>
<artifactId>
openjpa
</artifactId>
<exclusions>
<exclusion>
<groupId>
org.apache.geronimo.specs
</groupId>
<artifactId>
geronimo-jms_1.1_spec
</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
...
...
@@ -875,11 +881,6 @@
<artifactId>
jedis
</artifactId>
<version>
3.3.0
</version>
</dependency>
<dependency>
<groupId>
com.sun.mail
</groupId>
<artifactId>
javax.mail
</artifactId>
<version>
1.5.6
</version>
</dependency>
<dependency>
<groupId>
org.apache.commons
</groupId>
<artifactId>
commons-email
</artifactId>
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/build/CreateConfigSample.java
浏览文件 @
e2e15a38
...
...
@@ -35,6 +35,7 @@ import com.x.base.core.project.config.LogLevel;
import
com.x.base.core.project.config.MPweixin
;
import
com.x.base.core.project.config.Meeting
;
import
com.x.base.core.project.config.MessageApi
;
import
com.x.base.core.project.config.MessageJdbc
;
import
com.x.base.core.project.config.MessageMail
;
import
com.x.base.core.project.config.MessageMq
;
import
com.x.base.core.project.config.MessageRestful
;
...
...
@@ -91,6 +92,7 @@ public class CreateConfigSample {
classes
.
add
(
MessageMail
.
class
);
classes
.
add
(
MessageMq
.
class
);
classes
.
add
(
MessageApi
.
class
);
classes
.
add
(
MessageJdbc
.
class
);
classes
.
add
(
Mock
.
class
);
classes
.
add
(
MPweixin
.
class
);
classes
.
add
(
Node
.
class
);
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java
浏览文件 @
e2e15a38
...
...
@@ -79,6 +79,7 @@ public class Config {
public
static
final
String
PATH_CONFIG_MESSAGEMAIL
=
"config/messageMail.json"
;
public
static
final
String
PATH_CONFIG_MESSAGEAPI
=
"config/messageApi.json"
;
public
static
final
String
PATH_CONFIG_MESSAGEJDBC
=
"config/messageJdbc.json"
;
public
static
final
String
PATH_CONFIG_MESSAGETABLE
=
"config/messageTable.json"
;
public
static
final
String
PATH_CONFIG_SSLKEYSTORE
=
"config/keystore"
;
public
static
final
String
PATH_CONFIG_SSLKEYSTORESAMPLE
=
"config/sample/keystore"
;
public
static
final
String
PATH_CONFIG_STARTIMAGE
=
"config/startImage.png"
;
...
...
@@ -1000,6 +1001,19 @@ public class Config {
return
instance
().
messageJdbc
;
}
private
MessageTable
messageTable
;
public
static
synchronized
MessageTable
messageTable
()
throws
Exception
{
if
(
null
==
instance
().
messageTable
)
{
MessageTable
obj
=
BaseTools
.
readConfigObject
(
PATH_CONFIG_MESSAGETABLE
,
MessageTable
.
class
);
if
(
null
==
obj
)
{
obj
=
MessageTable
.
defaultInstance
();
}
instance
().
messageTable
=
obj
;
}
return
instance
().
messageTable
;
}
private
String
messageSendRuleScript
;
public
static
synchronized
String
messageSendRuleScript
()
throws
Exception
{
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/MessageJdbc.java
浏览文件 @
e2e15a38
...
...
@@ -2,8 +2,6 @@ package com.x.base.core.project.config;
import
java.util.LinkedHashMap
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.project.annotation.FieldDescribe
;
public
class
MessageJdbc
extends
LinkedHashMap
<
String
,
MessageJdbc
.
Item
>
{
...
...
@@ -11,63 +9,56 @@ public class MessageJdbc extends LinkedHashMap<String, MessageJdbc.Item> {
private
static
final
long
serialVersionUID
=
2536141863287117519L
;
public
static
MessageJdbc
defaultInstance
()
{
MessageJdbc
message
Mq
=
new
MessageJdbc
();
message
Mq
.
put
(
"o2oa"
,
new
Item
());
return
message
Mq
;
MessageJdbc
message
Jdbc
=
new
MessageJdbc
();
message
Jdbc
.
put
(
"o2oa"
,
new
Item
());
return
message
Jdbc
;
}
public
static
class
Item
{
public
Item
()
{
this
.
driverClass
=
DEFAULT_DRIVERCLASS
;
this
.
url
=
DEFAULT_URL
;
this
.
username
=
DEFAULT_USERNAME
;
this
.
password
=
DEFAULT_PASSWORD
;
this
.
catalog
=
DEFAULT_CATALOG
;
this
.
schema
=
DEFAULT_SCHEMA
;
this
.
table
=
DEFAULT_TABLE
;
}
public
static
final
String
TYPE_KAFKA
=
"kafka"
;
public
static
final
String
TYPE_ACTIVEMQ
=
"activeMQ"
;
public
static
final
String
DEFAULT_TYPE
=
TYPE_KAFKA
;
public
static
final
String
DEFAULT_KAFKABOOTSTRAPSERVERS
=
""
;
public
static
final
String
DEFAULT_KAFKATOPIC
=
""
;
public
static
final
String
DEFAULT_KAFKAACKS
=
""
;
public
static
final
Integer
DEFAULT_KAFKARETRIES
=
3
;
public
static
final
String
DEFAULT_DRIVERCLASS
=
"com.mysql.cj.jdbc.Driver"
;
public
static
final
String
DEFAULT_
KAFKABATCHSIZE
=
"
"
;
public
static
final
String
DEFAULT_
URL
=
"jdbc:mysql://127.0.0.1:3306/TEST?autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8
"
;
public
static
final
Integer
DEFAULT_KAFKALINGERMS
=
5000
;
public
static
final
String
DEFAULT_USERNAME
=
"root"
;
public
static
final
String
DEFAULT_
KAFKABUFFERMEMORY
=
"
"
;
public
static
final
String
DEFAULT_
PASSWORD
=
"password
"
;
public
static
final
String
DEFAULT_
ACTIVEMQUSERNAME
=
""
;
public
static
final
String
DEFAULT_
CATALOG
=
""
;
public
static
final
String
DEFAULT_
ACTIVEMQPASSWORD
=
""
;
public
static
final
String
DEFAULT_
SCHEMA
=
""
;
public
static
final
String
DEFAULT_
ACTIVEMQURL
=
"
"
;
public
static
final
String
DEFAULT_
TABLE
=
"NEWTABLE
"
;
public
static
final
String
DEFAULT_ACTIVEMQQUEUENAME
=
""
;
@FieldDescribe
(
"类型,kafka或者activeMQ"
)
@FieldDescribe
(
"驱动类"
)
private
String
driverClass
;
@FieldDescribe
(
"
服务器
地址"
)
@FieldDescribe
(
"地址"
)
private
String
url
;
@FieldDescribe
(
"
主题
"
)
@FieldDescribe
(
"
用户名
"
)
private
String
username
;
@FieldDescribe
(
"
用户名
"
)
@FieldDescribe
(
"
密码
"
)
private
String
password
;
@FieldDescribe
(
"
密码
"
)
@FieldDescribe
(
"
catalog
"
)
private
String
catalog
;
@FieldDescribe
(
"
服务器地址
"
)
@FieldDescribe
(
"
schema
"
)
private
String
schema
;
@FieldDescribe
(
"
消息队列
名"
)
@FieldDescribe
(
"
表
名"
)
private
String
table
;
public
String
getDriverClass
()
{
...
...
o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/MessageTable.java
0 → 100644
浏览文件 @
e2e15a38
package
com.x.base.core.project.config
;
import
java.util.LinkedHashMap
;
import
org.apache.commons.lang3.StringUtils
;
import
com.x.base.core.project.annotation.FieldDescribe
;
public
class
MessageTable
extends
LinkedHashMap
<
String
,
MessageTable
.
Item
>
{
private
static
final
long
serialVersionUID
=
2536141863287117519L
;
public
static
MessageTable
defaultInstance
()
{
MessageTable
messageTable
=
new
MessageTable
();
messageTable
.
put
(
"o2oa"
,
new
Item
());
return
messageTable
;
}
public
static
class
Item
{
private
static
final
String
DEFAULT_TABLE
=
""
;
public
Item
()
{
this
.
table
=
DEFAULT_TABLE
;
}
@FieldDescribe
(
"自建表"
)
private
String
table
;
public
String
getTable
()
{
return
StringUtils
.
isBlank
(
this
.
table
)
?
DEFAULT_TABLE
:
this
.
table
;
}
}
}
o2server/x_message_assemble_communicate/pom.xml
浏览文件 @
e2e15a38
<?xml version="1.0"?>
<project
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<project
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<groupId>
o2oa
</groupId>
...
...
@@ -30,36 +27,24 @@
</dependency>
<dependency>
<groupId>
org.apache.kafka
</groupId>
<artifactId>
kafka-clients
</artifactId>
<version>
2.6.0
</version>
</dependency>
<!--
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.14.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency>
-->
<dependency>
<groupId>
org.apache.activemq
</groupId>
<artifactId>
activemq-client
</artifactId>
<version>
5.14.5
</version>
<groupId>
org.apache.kafka
</groupId>
<artifactId>
kafka-clients
</artifactId>
<version>
2.6.0
</version>
</dependency>
<dependency>
<groupId>
org.apache.activemq
</groupId>
<artifactId>
activemq-client
</artifactId>
<version>
5.14.5
</version>
<exclusions>
<exclusion>
<groupId>
org.apache.geronimo.specs
</groupId>
<artifactId>
geronimo-jms_1.1_spec
</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugins>
<plugin>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
exec-maven-plugin
</artifactId>
...
...
@@ -161,4 +146,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
\ No newline at end of file
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/ExceptionTableReturn.java
0 → 100644
浏览文件 @
e2e15a38
package
com.x.message.assemble.communicate
;
import
com.x.base.core.project.exception.PromptException
;
class
ExceptionTableReturn
extends
PromptException
{
private
static
final
long
serialVersionUID
=
6235890108470383271L
;
ExceptionTableReturn
(
String
id
,
String
title
,
String
table
)
{
super
(
"execute table message return is not true, message:{}, title:{}, table:{}."
,
id
,
title
,
table
);
}
}
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/JdbcConsumeQueue.java
浏览文件 @
e2e15a38
package
com.x.message.assemble.communicate
;
import
java.math.BigDecimal
;
import
java.sql.Connection
;
import
java.sql.DatabaseMetaData
;
import
java.sql.DriverManager
;
...
...
@@ -8,14 +9,24 @@ import java.sql.ResultSet;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Optional
;
import
org.apache.commons.collections4.ListUtils
;
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.apache.commons.lang3.BooleanUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.math.NumberUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
com.google.gson.Gson
;
import
com.google.gson.JsonElement
;
...
...
@@ -23,13 +34,17 @@ import com.google.gson.JsonObject;
import
com.google.gson.JsonPrimitive
;
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.project.config.Config
;
import
com.x.base.core.project.config.MessageJdbc
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.message.MessageConnector
;
import
com.x.base.core.project.queue.AbstractQueue
;
import
com.x.base.core.project.tools.DateTools
;
import
com.x.message.core.entity.Message
;
import
com.x.message.core.entity.Message_
;
public
class
JdbcConsumeQueue
extends
AbstractQueue
<
Message
>
{
...
...
@@ -68,78 +83,551 @@ public class JdbcConsumeQueue extends AbstractQueue<Message> {
private
void
update
(
Message
message
)
{
try
{
MessageJdbc
.
Item
item
=
Config
.
messageJdbc
().
get
(
message
.
getItem
());
String
catalog
=
""
;
String
schema
=
""
;
String
table
=
""
;
Class
.
forName
(
""
);
Class
.
forName
(
item
.
getDriverClass
());
try
(
Connection
connection
=
DriverManager
.
getConnection
(
item
.
getUrl
(),
item
.
getUsername
(),
item
.
getPassword
());
Statement
statement
=
connection
.
createStatement
())
{
List
<
String
>
columns
=
this
.
columnNames
(
connection
,
item
);
Map
<
String
,
JsonElement
>
map
=
values
(
columns
,
null
);
List
<
String
>
params
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
map
.
keySet
().
size
();
i
++)
{
params
.
add
(
"?"
);
}
String
sql
=
"INSERT INTO XXXXX ("
+
StringUtils
.
join
(
map
.
keySet
(),
","
)
+
") VALUES ("
+
StringUtils
.
join
(
params
,
","
)
+
")"
;
List
<
Column
>
columns
=
this
.
columns
(
connection
,
item
);
Map
<
String
,
Object
>
map
=
values
(
columns
,
gson
.
fromJson
(
message
.
getBody
(),
JsonObject
.
class
));
String
sql
=
createSql
(
item
.
getSchema
(),
item
.
getTable
(),
map
);
PreparedStatement
preparedStatement
=
connection
.
prepareStatement
(
sql
);
int
idx
=
1
;
for
(
Entry
<
String
,
JsonElemen
t
>
en
:
map
.
entrySet
())
{
preparedStatement
.
setObject
(
idx
++,
getObject
(
en
.
getValue
()
));
for
(
Entry
<
String
,
Objec
t
>
en
:
map
.
entrySet
())
{
preparedStatement
.
setObject
(
idx
++,
en
.
getValue
(
));
}
preparedStatement
.
executeUpdate
();
}
success
(
message
.
getId
());
}
catch
(
Exception
e
)
{
failure
(
message
.
getId
(),
e
);
LOGGER
.
error
(
e
);
}
}
private
String
createSql
(
String
schema
,
String
table
,
Map
<
String
,
Object
>
map
)
{
List
<
String
>
aux
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
map
.
keySet
().
size
();
i
++)
{
aux
.
add
(
"?"
);
}
return
"INSERT INTO "
+
(
StringUtils
.
isEmpty
(
schema
)
?
table
:
(
schema
+
"."
+
table
))
+
" ("
+
StringUtils
.
join
(
map
.
keySet
(),
","
)
+
") VALUES ("
+
StringUtils
.
join
(
aux
,
","
)
+
")"
;
}
private
void
success
(
String
id
)
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Message
message
=
emc
.
find
(
id
,
Message
.
class
);
if
(
null
!=
message
)
{
emc
.
beginTransaction
(
Message
.
class
);
message
.
setConsumed
(
true
);
emc
.
commit
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
private
void
failure
(
String
id
,
Exception
exception
)
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Message
message
=
emc
.
find
(
id
,
Message
.
class
);
if
(
null
!=
message
)
{
emc
.
beginTransaction
(
Message
.
class
);
Integer
failure
=
message
.
getProperties
().
getFailure
();
failure
=
(
null
==
failure
)
?
1
:
failure
+
1
;
message
.
getProperties
().
setFailure
(
failure
);
message
.
getProperties
().
setError
(
exception
.
getMessage
());
emc
.
commit
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
private
Map
<
String
,
Object
>
values
(
List
<
Column
>
columns
,
JsonObject
jsonObject
)
{
Map
<
String
,
String
>
auxLowerCase
=
new
HashMap
<>();
jsonObject
.
entrySet
().
forEach
(
en
->
{
auxLowerCase
.
put
(
StringUtils
.
lowerCase
(
en
.
getKey
()),
en
.
getKey
());
});
Map
<
String
,
Object
>
map
=
new
LinkedHashMap
<>();
String
key
;
for
(
Column
column
:
columns
)
{
key
=
auxLowerCase
.
get
(
StringUtils
.
lowerCase
(
column
.
getName
()));
if
(
StringUtils
.
isNotEmpty
(
key
))
{
map
.
put
(
column
.
getName
(),
getValue
(
column
,
jsonObject
.
get
(
key
)));
}
}
return
map
;
}
private
Object
get
Object
(
JsonElement
jsonElement
)
{
private
Object
get
Value
(
Column
column
,
JsonElement
jsonElement
)
{
if
(
null
==
jsonElement
||
jsonElement
.
isJsonNull
())
{
return
null
;
}
switch
(
column
.
getDataType
())
{
case
java
.
sql
.
Types
.
ARRAY
:
return
toARRAY
();
case
java
.
sql
.
Types
.
BIGINT
:
return
toBIGINT
(
jsonElement
);
case
java
.
sql
.
Types
.
BINARY
:
return
toBINARY
();
case
java
.
sql
.
Types
.
BIT
:
return
toBIT
(
jsonElement
);
case
java
.
sql
.
Types
.
BLOB
:
return
toBLOB
();
case
java
.
sql
.
Types
.
BOOLEAN
:
return
toBOOLEAN
(
jsonElement
);
case
java
.
sql
.
Types
.
CHAR
:
return
toCHAR
(
jsonElement
);
case
java
.
sql
.
Types
.
CLOB
:
return
toCLOB
(
jsonElement
);
case
java
.
sql
.
Types
.
DATALINK
:
return
toDATALINK
();
case
java
.
sql
.
Types
.
DATE
:
return
toDATE
(
jsonElement
);
case
java
.
sql
.
Types
.
DECIMAL
:
return
toDECIMAL
(
jsonElement
);
case
java
.
sql
.
Types
.
DISTINCT
:
return
toDISTINCT
();
case
java
.
sql
.
Types
.
DOUBLE
:
return
toDOUBLE
(
jsonElement
);
case
java
.
sql
.
Types
.
FLOAT
:
return
toFLOAT
(
jsonElement
);
case
java
.
sql
.
Types
.
INTEGER
:
return
toINTEGER
(
jsonElement
);
case
java
.
sql
.
Types
.
JAVA_OBJECT
:
return
toJAVA_OBJECT
();
case
java
.
sql
.
Types
.
LONGNVARCHAR
:
return
toLONGNVARCHAR
(
jsonElement
);
case
java
.
sql
.
Types
.
LONGVARBINARY
:
return
toLONGVARBINARY
();
case
java
.
sql
.
Types
.
LONGVARCHAR
:
return
toLONGVARCHAR
(
jsonElement
);
case
java
.
sql
.
Types
.
NCHAR
:
return
toNCHAR
(
jsonElement
);
case
java
.
sql
.
Types
.
NCLOB
:
return
toNCLOB
(
jsonElement
);
case
java
.
sql
.
Types
.
NULL
:
return
toNULL
();
case
java
.
sql
.
Types
.
NUMERIC
:
return
toNUMERIC
(
jsonElement
);
case
java
.
sql
.
Types
.
NVARCHAR
:
return
toNVARCHAR
(
jsonElement
);
case
java
.
sql
.
Types
.
OTHER
:
return
toOTHER
();
case
java
.
sql
.
Types
.
REAL
:
return
toREAL
();
case
java
.
sql
.
Types
.
REF
:
return
toREF
();
case
java
.
sql
.
Types
.
REF_CURSOR
:
return
toREF_CURSOR
();
case
java
.
sql
.
Types
.
ROWID
:
return
toROWID
();
case
java
.
sql
.
Types
.
SMALLINT
:
return
toSMALLINT
(
jsonElement
);
case
java
.
sql
.
Types
.
SQLXML
:
return
toSQLXML
(
jsonElement
);
case
java
.
sql
.
Types
.
STRUCT
:
return
toSTRUCT
();
case
java
.
sql
.
Types
.
TIME
:
return
toTIME
(
jsonElement
);
case
java
.
sql
.
Types
.
TIME_WITH_TIMEZONE
:
return
toTIME_WITH_TIMEZONE
();
case
java
.
sql
.
Types
.
TIMESTAMP
:
return
toTIMESTAMP
(
jsonElement
);
case
java
.
sql
.
Types
.
TIMESTAMP_WITH_TIMEZONE
:
return
toTIMESTAMP_WITH_TIMEZONE
();
case
java
.
sql
.
Types
.
TINYINT
:
return
toTINYINT
(
jsonElement
);
case
java
.
sql
.
Types
.
VARBINARY
:
return
toVARBINARY
();
case
java
.
sql
.
Types
.
VARCHAR
:
return
toVARCHAR
(
jsonElement
);
default
:
return
null
;
}
}
private
Object
toARRAY
()
{
return
null
;
}
private
Object
toBIGINT
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isBoolean
())
{
return
jsonPrimitive
.
getAsBoolean
();
}
else
if
(
jsonPrimitive
.
isString
())
{
return
jsonPrimitive
.
getAsString
();
}
else
if
(
jsonPrimitive
.
isNumber
())
{
return
jsonPrimitive
.
getAsNumber
();
try
{
return
Integer
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
intValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Map
<
String
,
JsonElement
>
values
(
List
<
String
>
columns
,
JsonObject
jsonObject
)
{
Map
<
String
,
JsonElement
>
map
=
new
LinkedHashMap
<>();
jsonObject
.
entrySet
().
forEach
(
en
->
{
int
idx
=
ListUtils
.
indexOf
(
columns
,
o
->
{
return
StringUtils
.
equalsIgnoreCase
(
en
.
getKey
(),
o
);
});
if
(
idx
>
0
)
{
map
.
put
(
columns
.
get
(
idx
),
en
.
getValue
());
private
Object
toBINARY
()
{
return
null
;
}
private
Object
toBIT
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isBoolean
())
{
return
Integer
.
valueOf
(
jsonPrimitive
.
getAsBoolean
()
?
1
:
0
);
}
else
if
(
jsonPrimitive
.
isNumber
())
{
return
Integer
.
valueOf
((
jsonPrimitive
.
getAsInt
()
>
0
)
?
1
:
0
);
}
else
if
(
jsonPrimitive
.
isString
())
{
String
str
=
jsonPrimitive
.
getAsString
();
if
(
NumberUtils
.
isCreatable
(
str
))
{
return
Integer
.
valueOf
((
NumberUtils
.
toInt
(
str
)
>
0
)
?
1
:
0
);
}
else
{
return
Integer
.
valueOf
(
BooleanUtils
.
toBoolean
(
str
)
?
1
:
0
);
}
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
});
return
map
;
}
return
null
;
}
private
Object
toBLOB
()
{
return
null
;
}
private
Object
toBOOLEAN
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isBoolean
())
{
return
jsonElement
.
getAsBoolean
();
}
else
if
(
jsonPrimitive
.
isNumber
())
{
return
Boolean
.
valueOf
((
jsonPrimitive
.
getAsNumber
().
intValue
()
>
0
)
?
true
:
false
);
}
else
if
(
jsonPrimitive
.
isString
())
{
String
str
=
jsonPrimitive
.
getAsString
();
if
(
NumberUtils
.
isCreatable
(
str
))
{
return
Boolean
.
valueOf
((
NumberUtils
.
toInt
(
str
)
>
0
)
?
true
:
false
);
}
else
{
return
BooleanUtils
.
toBooleanObject
(
str
);
}
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toCHAR
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsCharacter
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toCLOB
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toDATALINK
()
{
return
null
;
}
private
Object
toDATE
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
DateTools
.
parse
(
jsonElement
.
getAsJsonPrimitive
().
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toDECIMAL
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
BigDecimal
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
doubleValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toDISTINCT
()
{
return
null
;
}
private
Object
toDOUBLE
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
Double
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
doubleValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toFLOAT
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
Float
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
floatValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toINTEGER
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
Integer
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
intValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toJAVA_OBJECT
()
{
return
null
;
}
private
Object
toLONGNVARCHAR
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toLONGVARBINARY
()
{
return
null
;
}
private
Object
toLONGVARCHAR
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toNCHAR
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toNCLOB
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toNULL
()
{
return
null
;
}
private
Object
toNUMERIC
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsBigDecimal
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toNVARCHAR
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toOTHER
()
{
return
null
;
}
private
Object
toREAL
()
{
return
null
;
}
private
Object
toREF
()
{
return
null
;
}
private
Object
toREF_CURSOR
()
{
return
null
;
}
private
Object
toROWID
()
{
return
null
;
}
private
Object
toSMALLINT
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
Short
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
shortValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
List
<
String
>
columnNames
(
Connection
connection
,
MessageJdbc
.
Item
item
)
throws
SQLException
{
private
Object
toSQLXML
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toSTRUCT
()
{
return
null
;
}
private
Object
toTIME
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
DateTools
.
parse
(
jsonElement
.
getAsJsonPrimitive
().
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toTIME_WITH_TIMEZONE
()
{
return
null
;
}
private
Object
toTIMESTAMP
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
DateTools
.
parse
(
jsonElement
.
getAsJsonPrimitive
().
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toTIMESTAMP_WITH_TIMEZONE
()
{
return
null
;
}
private
Object
toTINYINT
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
Short
.
valueOf
(
jsonElement
.
getAsJsonPrimitive
().
getAsNumber
().
shortValue
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
Object
toVARBINARY
()
{
return
null
;
}
private
Object
toVARCHAR
(
JsonElement
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
try
{
return
jsonElement
.
getAsJsonPrimitive
().
getAsString
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
return
null
;
}
private
List
<
Column
>
columns
(
Connection
connection
,
MessageJdbc
.
Item
item
)
throws
SQLException
{
DatabaseMetaData
databaseMetaData
=
connection
.
getMetaData
();
String
catalog
=
""
;
String
schema
=
""
;
String
table
=
""
;
List
<
String
>
list
=
new
ArrayList
<>();
String
catalog
=
StringUtils
.
isEmpty
(
item
.
getCatalog
())
?
null
:
item
.
getCatalog
()
;
String
schema
=
StringUtils
.
isEmpty
(
item
.
getSchema
())
?
"%"
:
item
.
getSchema
()
;
String
table
=
item
.
getTable
()
;
List
<
Column
>
list
=
new
ArrayList
<>();
try
(
ResultSet
resultSet
=
databaseMetaData
.
getColumns
(
catalog
,
schema
,
table
,
"%"
))
{
while
(
resultSet
.
next
())
{
list
.
add
(
resultSet
.
getString
(
"COLUMN_NAME"
));
list
.
add
(
new
Column
(
resultSet
.
getString
(
"COLUMN_NAME"
),
resultSet
.
getInt
(
"DATA_TYPE"
)
));
}
}
return
list
;
}
private
List
<
String
>
listOverStay
()
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
EntityManager
em
=
emc
.
get
(
Message
.
class
);
CriteriaBuilder
cb
=
em
.
getCriteriaBuilder
();
CriteriaQuery
<
String
>
cq
=
cb
.
createQuery
(
String
.
class
);
Root
<
Message
>
root
=
cq
.
from
(
Message
.
class
);
Predicate
p
=
cb
.
equal
(
root
.
get
(
Message_
.
consumer
),
MessageConnector
.
CONSUME_JDBC
);
p
=
cb
.
and
(
p
,
cb
.
notEqual
(
root
.
get
(
Message_
.
consumed
),
true
));
p
=
cb
.
and
(
p
,
cb
.
lessThan
(
root
.
get
(
JpaObject_
.
updateTime
),
DateUtils
.
addMinutes
(
new
Date
(),
-
20
)));
cq
.
select
(
root
.
get
(
Message_
.
id
)).
where
(
p
);
return
em
.
createQuery
(
cq
).
setMaxResults
(
20
).
getResultList
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
return
new
ArrayList
<>();
}
public
static
class
Column
{
public
Column
(
String
name
,
int
dataType
)
{
this
.
name
=
name
;
this
.
dataType
=
dataType
;
}
private
String
name
;
private
int
dataType
;
public
String
getName
()
{
return
name
;
}
public
int
getDataType
()
{
return
dataType
;
}
}
}
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/TableConsumeQueue.java
0 → 100644
浏览文件 @
e2e15a38
package
com.x.message.assemble.communicate
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Optional
;
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.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.time.DateUtils
;
import
com.google.gson.Gson
;
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.project.Applications
;
import
com.x.base.core.project.x_query_service_processing
;
import
com.x.base.core.project.config.Config
;
import
com.x.base.core.project.config.MessageTable
;
import
com.x.base.core.project.gson.XGsonBuilder
;
import
com.x.base.core.project.jaxrs.WrapBoolean
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.message.MessageConnector
;
import
com.x.base.core.project.queue.AbstractQueue
;
import
com.x.message.core.entity.Message
;
import
com.x.message.core.entity.Message_
;
public
class
TableConsumeQueue
extends
AbstractQueue
<
Message
>
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
TableConsumeQueue
.
class
);
private
static
final
Gson
gson
=
XGsonBuilder
.
instance
();
protected
void
execute
(
Message
message
)
throws
Exception
{
if
(
null
!=
message
&&
StringUtils
.
isNotEmpty
(
message
.
getItem
()))
{
update
(
message
);
}
List
<
String
>
ids
=
listOverStay
();
if
(!
ids
.
isEmpty
())
{
LOGGER
.
info
(
"滞留 table 消息数量:{}."
,
ids
.
size
());
for
(
String
id
:
ids
)
{
Optional
<
Message
>
optional
=
find
(
id
);
if
(
optional
.
isPresent
())
{
message
=
optional
.
get
();
if
(
StringUtils
.
isNotEmpty
(
message
.
getItem
()))
{
update
(
message
);
}
}
}
}
}
private
Optional
<
Message
>
find
(
String
id
)
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
return
Optional
.
of
(
emc
.
find
(
id
,
Message
.
class
));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
return
Optional
.
empty
();
}
private
void
update
(
Message
message
)
{
try
{
MessageTable
.
Item
item
=
Config
.
messageTable
().
get
(
message
.
getItem
());
JsonElement
jsonElement
=
gson
.
fromJson
(
message
.
getBody
(),
JsonElement
.
class
);
WrapBoolean
resp
=
ThisApplication
.
context
().
applications
()
.
postQuery
(
x_query_service_processing
.
class
,
Applications
.
joinQueryUri
(
"table"
,
item
.
getTable
(),
"insert"
),
jsonElement
)
.
getData
(
WrapBoolean
.
class
);
if
(!
resp
.
getValue
())
{
throw
new
ExceptionTableReturn
(
message
.
getId
(),
message
.
getTitle
(),
item
.
getTable
());
}
success
(
message
.
getId
());
}
catch
(
Exception
e
)
{
failure
(
message
.
getId
(),
e
);
LOGGER
.
error
(
e
);
}
}
private
void
success
(
String
id
)
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Message
message
=
emc
.
find
(
id
,
Message
.
class
);
if
(
null
!=
message
)
{
emc
.
beginTransaction
(
Message
.
class
);
message
.
setConsumed
(
true
);
emc
.
commit
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
private
void
failure
(
String
id
,
Exception
exception
)
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
Message
message
=
emc
.
find
(
id
,
Message
.
class
);
if
(
null
!=
message
)
{
emc
.
beginTransaction
(
Message
.
class
);
Integer
failure
=
message
.
getProperties
().
getFailure
();
failure
=
(
null
==
failure
)
?
1
:
failure
+
1
;
message
.
getProperties
().
setFailure
(
failure
);
message
.
getProperties
().
setError
(
exception
.
getMessage
());
emc
.
commit
();
}
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
private
List
<
String
>
listOverStay
()
{
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
EntityManager
em
=
emc
.
get
(
Message
.
class
);
CriteriaBuilder
cb
=
em
.
getCriteriaBuilder
();
CriteriaQuery
<
String
>
cq
=
cb
.
createQuery
(
String
.
class
);
Root
<
Message
>
root
=
cq
.
from
(
Message
.
class
);
Predicate
p
=
cb
.
equal
(
root
.
get
(
Message_
.
consumer
),
MessageConnector
.
CONSUME_RESTFUL
);
p
=
cb
.
and
(
p
,
cb
.
notEqual
(
root
.
get
(
Message_
.
consumed
),
true
));
p
=
cb
.
and
(
p
,
cb
.
lessThan
(
root
.
get
(
JpaObject_
.
updateTime
),
DateUtils
.
addMinutes
(
new
Date
(),
-
20
)));
cq
.
select
(
root
.
get
(
Message_
.
id
)).
where
(
p
);
return
em
.
createQuery
(
cq
).
setMaxResults
(
20
).
getResultList
();
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
return
new
ArrayList
<>();
}
}
\ No newline at end of file
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/ThisApplication.java
浏览文件 @
e2e15a38
...
...
@@ -43,6 +43,10 @@ public class ThisApplication {
public
static
final
ApiConsumeQueue
apiConsumeQueue
=
new
ApiConsumeQueue
();
public
static
final
JdbcConsumeQueue
jdbcConsumeQueue
=
new
JdbcConsumeQueue
();
public
static
final
TableConsumeQueue
tableConsumeQueue
=
new
TableConsumeQueue
();
public
static
Context
context
()
{
return
context
;
}
...
...
@@ -70,6 +74,8 @@ public class ThisApplication {
context
().
startQueue
(
apiConsumeQueue
);
context
().
startQueue
(
mailConsumeQueue
);
context
().
startQueue
(
mqConsumeQueue
);
context
().
startQueue
(
jdbcConsumeQueue
);
context
().
startQueue
(
tableConsumeQueue
);
if
(
BooleanUtils
.
isTrue
(
Config
.
qiyeweixin
().
getEnable
())
&&
BooleanUtils
.
isTrue
(
Config
.
qiyeweixin
().
getMessageEnable
()))
{
context
().
startQueue
(
qiyeweixinConsumeQueue
);
...
...
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/jaxrs/connector/ActionCreate.java
浏览文件 @
e2e15a38
...
...
@@ -566,7 +566,7 @@ class ActionCreate extends BaseAction {
case
MessageConnector
.
CONSUME_CALENDAR
:
message
=
this
.
v3CalendarMessage
(
wi
,
consumer
);
break
;
// restful, mq, api, mail, custom_消息没有其他判断条件
// restful, mq, api, mail,
jdbc,
custom_消息没有其他判断条件
default
:
message
=
this
.
v3Message
(
wi
,
consumer
);
break
;
...
...
@@ -817,6 +817,9 @@ class ActionCreate extends BaseAction {
case
MessageConnector
.
CONSUME_API
:
ThisApplication
.
apiConsumeQueue
.
send
(
message
);
break
;
case
MessageConnector
.
CONSUME_JDBC
:
ThisApplication
.
jdbcConsumeQueue
.
send
(
message
);
break
;
default
:
break
;
}
...
...
o2server/x_message_assemble_communicate/src/main/java/com/x/message/assemble/communicate/schedule/TriggerMessageConsumeQueue.java
浏览文件 @
e2e15a38
...
...
@@ -13,11 +13,14 @@ public class TriggerMessageConsumeQueue extends AbstractJob {
@Override
public
void
schedule
(
JobExecutionContext
jobExecutionContext
)
throws
Exception
{
LOGGER
.
debug
(
"schedule trigger restfulConsumeQueue, mqConsumeQueue, mailConsumeQueue, apiConsumeQueue."
);
LOGGER
.
debug
(
"schedule trigger restfulConsumeQueue, mqConsumeQueue, mailConsumeQueue, apiConsumeQueue, jdbcConsumeQueue, tableConsumeQueue."
);
ThisApplication
.
restfulConsumeQueue
.
send
(
null
);
ThisApplication
.
mqConsumeQueue
.
send
(
null
);
ThisApplication
.
mailConsumeQueue
.
send
(
null
);
ThisApplication
.
apiConsumeQueue
.
send
(
null
);
ThisApplication
.
jdbcConsumeQueue
.
send
(
null
);
ThisApplication
.
tableConsumeQueue
.
send
(
null
);
}
}
\ No newline at end of file
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/ActionInsert.java
0 → 100644
浏览文件 @
e2e15a38
package
com.x.query.service.processing.jaxrs.table
;
import
org.apache.commons.beanutils.PropertyUtilsBean
;
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.entity.dynamic.DynamicEntity
;
import
com.x.base.core.project.exception.ExceptionEntityNotExist
;
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.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.query.core.entity.schema.Table
;
import
com.x.query.service.processing.Business
;
class
ActionInsert
extends
BaseAction
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ActionInsert
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
flag
,
JsonElement
jsonElement
)
throws
Exception
{
LOGGER
.
debug
(
"execute:{}, flag:{}."
,
effectivePerson:
:
getDistinguishedName
,
()
->
flag
);
ClassLoader
classLoader
=
Business
.
getDynamicEntityClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
classLoader
);
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
LOGGER
.
debug
(
"execute:{}, flag:{}."
,
effectivePerson:
:
getDistinguishedName
,
()
->
flag
);
Table
table
=
emc
.
flag
(
flag
,
Table
.
class
);
if
(
null
==
table
)
{
throw
new
ExceptionEntityNotExist
(
flag
,
Table
.
class
);
}
DynamicEntity
dynamicEntity
=
new
DynamicEntity
(
table
.
getName
());
@SuppressWarnings
(
"unchecked"
)
Class
<?
extends
JpaObject
>
cls
=
(
Class
<?
extends
JpaObject
>)
classLoader
.
loadClass
(
dynamicEntity
.
className
());
JpaObject
o
=
update
(
jsonElement
,
cls
);
emc
.
beginTransaction
(
cls
);
emc
.
persist
(
o
);
emc
.
check
(
o
,
CheckPersistType
.
all
);
emc
.
commit
();
Wo
wo
=
new
Wo
();
wo
.
setValue
(
true
);
result
.
setData
(
wo
);
}
return
result
;
}
public
static
class
Wo
extends
WrapBoolean
{
private
static
final
long
serialVersionUID
=
7570720614789228246L
;
}
}
\ No newline at end of file
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/ActionUpdate.java
已删除
100644 → 0
浏览文件 @
acc42076
package
com.x.query.service.processing.jaxrs.table
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
javax.persistence.Column
;
import
org.apache.commons.beanutils.PropertyUtilsBean
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.reflect.FieldUtils
;
import
org.apache.openjpa.persistence.jdbc.ElementColumn
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonPrimitive
;
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.entity.dynamic.DynamicEntity
;
import
com.x.base.core.entity.tools.JpaObjectTools
;
import
com.x.base.core.project.exception.ExceptionEntityNotExist
;
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.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.DateTools
;
import
com.x.base.core.project.tools.StringTools
;
import
com.x.query.core.entity.schema.Table
;
import
com.x.query.service.processing.Business
;
class
ActionUpdate
extends
BaseAction
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ActionUpdate
.
class
);
private
PropertyUtilsBean
propertyUtilsBean
=
new
PropertyUtilsBean
();
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
flag
,
String
bundle
,
JsonElement
jsonElement
)
throws
Exception
{
LOGGER
.
debug
(
"execute:{}, flag:{}, bundle:{}."
,
effectivePerson:
:
getDistinguishedName
,
()
->
flag
,
()
->
bundle
);
ClassLoader
classLoader
=
Business
.
getDynamicEntityClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
classLoader
);
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
if
(
StringUtils
.
isEmpty
(
bundle
))
{
throw
new
ExceptionBundleEmpty
();
}
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
LOGGER
.
debug
(
"execute:{}, flag:{}."
,
effectivePerson:
:
getDistinguishedName
,
()
->
flag
);
Table
table
=
emc
.
flag
(
flag
,
Table
.
class
);
if
(
null
==
table
)
{
throw
new
ExceptionEntityNotExist
(
flag
,
Table
.
class
);
}
DynamicEntity
dynamicEntity
=
new
DynamicEntity
(
table
.
getName
());
@SuppressWarnings
(
"unchecked"
)
Class
<?
extends
JpaObject
>
cls
=
(
Class
<?
extends
JpaObject
>)
classLoader
.
loadClass
(
dynamicEntity
.
className
());
JpaObject
o
=
update
(
jsonElement
,
cls
);
JpaObject
obj
=
emc
.
find
(
bundle
,
cls
);
emc
.
beginTransaction
(
cls
);
if
(
null
!=
obj
)
{
o
.
copyTo
(
obj
,
JpaObject
.
FieldsUnmodify
);
emc
.
check
(
obj
,
CheckPersistType
.
all
);
}
else
{
emc
.
persist
(
o
);
emc
.
check
(
o
,
CheckPersistType
.
all
);
}
emc
.
commit
();
Wo
wo
=
new
Wo
();
wo
.
setValue
(
true
);
result
.
setData
(
wo
);
}
return
result
;
}
private
<
T
extends
JpaObject
>
T
update
(
JsonElement
jsonElement
,
Class
<
T
>
cls
)
throws
IllegalAccessException
,
InvocationTargetException
,
NoSuchMethodException
,
InstantiationException
,
IllegalArgumentException
,
SecurityException
{
List
<
Field
>
fields
=
FieldUtils
.
getFieldsListWithAnnotation
(
cls
,
Column
.
class
);
T
t
=
cls
.
getConstructor
().
newInstance
();
JsonObject
jsonObject
=
null
;
if
((
jsonElement
!=
null
)
&&
jsonElement
.
isJsonObject
())
{
jsonObject
=
jsonElement
.
getAsJsonObject
();
}
for
(
Field
field
:
fields
)
{
switch
(
JpaObjectTools
.
type
(
field
))
{
case
JpaObject
.
TYPE_STRING
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractStringOrDistinguishedName
(
getJsonElement
(
jsonObject
,
field
),
getColumnDefinedStringLength
(
field
)));
break
;
case
JpaObject
.
TYPE_INTEGER
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractInteger
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_LONG
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractLong
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_FLOAT
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractFloat
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DOUBLE
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDouble
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DATETIME
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDateTime
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DATE
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDate
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_BOOLEAN
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractBoolean
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_STRINGLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractStringOrDistinguishedNameList
(
getJsonElement
(
jsonObject
,
field
),
getElementColumnDefinedStringLength
(
field
)));
break
;
case
JpaObject
.
TYPE_INTEGERLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractIntegerList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_LONGLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractLongList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_FLOATLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractFloatList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DOUBLELIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDoubleList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DATETIMELIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDateTimeList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_BOOLEANLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractBooleanList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
default
:
break
;
}
}
return
t
;
}
private
int
getColumnDefinedStringLength
(
Field
field
)
{
Column
column
=
field
.
getAnnotation
(
Column
.
class
);
return
(
null
!=
column
)
?
column
.
length
()
:
JpaObject
.
length_255B
;
}
private
int
getElementColumnDefinedStringLength
(
Field
field
)
{
ElementColumn
elementColumn
=
field
.
getAnnotation
(
ElementColumn
.
class
);
return
(
null
!=
elementColumn
)
?
elementColumn
.
length
()
:
JpaObject
.
length_255B
;
}
private
JsonElement
getJsonElement
(
JsonObject
jsonObject
,
Field
field
)
{
JsonElement
element
=
null
;
if
((
null
!=
jsonObject
)
&&
jsonObject
.
has
(
field
.
getName
()))
{
element
=
jsonObject
.
get
(
field
.
getName
());
}
return
element
;
}
private
String
extractStringOrDistinguishedName
(
JsonElement
jsonElement
,
int
maxLength
)
{
String
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
value
=
jsonElement
.
getAsString
();
}
else
if
(
jsonElement
.
isJsonObject
())
{
JsonObject
o
=
jsonElement
.
getAsJsonObject
();
if
(
o
.
has
(
JpaObject
.
DISTINGUISHEDNAME
))
{
value
=
o
.
get
(
JpaObject
.
DISTINGUISHEDNAME
).
getAsString
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractStringOrDistinguishedName
(
os
.
get
(
0
),
maxLength
);
}
}
}
return
StringTools
.
utf8SubString
(
value
,
maxLength
);
}
private
List
<
String
>
extractStringOrDistinguishedNameList
(
JsonElement
jsonElement
,
int
maxLength
)
{
List
<
String
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
values
.
add
(
StringTools
.
utf8SubString
(
jsonElement
.
getAsString
(),
maxLength
));
}
else
if
(
jsonElement
.
isJsonObject
())
{
JsonObject
o
=
jsonElement
.
getAsJsonObject
();
if
(
o
.
has
(
JpaObject
.
DISTINGUISHEDNAME
))
{
values
.
add
(
StringTools
.
utf8SubString
(
o
.
get
(
JpaObject
.
DISTINGUISHEDNAME
).
getAsString
(),
maxLength
));
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractStringOrDistinguishedName
(
o
,
maxLength
));
}
}
}
return
values
;
}
private
Integer
extractInteger
(
JsonElement
jsonElement
)
{
Integer
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsInt
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractInteger
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Integer
>
extractIntegerList
(
JsonElement
jsonElement
)
{
List
<
Integer
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsInt
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractInteger
(
o
));
}
}
}
return
values
;
}
private
Long
extractLong
(
JsonElement
jsonElement
)
{
Long
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsLong
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractLong
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Long
>
extractLongList
(
JsonElement
jsonElement
)
{
List
<
Long
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsLong
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractLong
(
o
));
}
}
}
return
values
;
}
private
Float
extractFloat
(
JsonElement
jsonElement
)
{
Float
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsFloat
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractFloat
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Float
>
extractFloatList
(
JsonElement
jsonElement
)
{
List
<
Float
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsFloat
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractFloat
(
o
));
}
}
}
return
values
;
}
private
Double
extractDouble
(
JsonElement
jsonElement
)
{
Double
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsDouble
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractDouble
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Double
>
extractDoubleList
(
JsonElement
jsonElement
)
{
List
<
Double
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsDouble
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractDouble
(
o
));
}
}
}
return
values
;
}
private
Date
extractDateTime
(
JsonElement
jsonElement
)
{
Date
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isString
())
{
try
{
value
=
DateTools
.
parseDateTime
(
jsonPrimitive
.
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractDateTime
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Date
>
extractDateTimeList
(
JsonElement
jsonElement
)
{
List
<
Date
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isString
())
{
try
{
values
.
add
(
DateTools
.
parseDateTime
(
jsonPrimitive
.
getAsString
()));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractDateTime
(
o
));
}
}
}
return
values
;
}
private
Date
extractDate
(
JsonElement
jsonElement
)
{
Date
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isString
())
{
try
{
value
=
DateTools
.
parseDate
(
jsonPrimitive
.
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractDate
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
Boolean
extractBoolean
(
JsonElement
jsonElement
)
{
Boolean
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsBoolean
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractBoolean
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Boolean
>
extractBooleanList
(
JsonElement
jsonElement
)
{
List
<
Boolean
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsBoolean
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractBoolean
(
o
));
}
}
}
return
values
;
}
public
static
class
Wo
extends
WrapBoolean
{
private
static
final
long
serialVersionUID
=
7570720614789228246L
;
}
}
\ No newline at end of file
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/ActionUpdateWithBundle.java
0 → 100644
浏览文件 @
e2e15a38
package
com.x.query.service.processing.jaxrs.table
;
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.entity.dynamic.DynamicEntity
;
import
com.x.base.core.project.exception.ExceptionEntityNotExist
;
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.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.query.core.entity.schema.Table
;
import
com.x.query.service.processing.Business
;
class
ActionUpdateWithBundle
extends
BaseAction
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
ActionUpdateWithBundle
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
String
flag
,
String
bundle
,
JsonElement
jsonElement
)
throws
Exception
{
LOGGER
.
debug
(
"execute:{}, flag:{}, bundle:{}."
,
effectivePerson:
:
getDistinguishedName
,
()
->
flag
,
()
->
bundle
);
ClassLoader
classLoader
=
Business
.
getDynamicEntityClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
classLoader
);
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
if
(
StringUtils
.
isEmpty
(
bundle
))
{
throw
new
ExceptionBundleEmpty
();
}
try
(
EntityManagerContainer
emc
=
EntityManagerContainerFactory
.
instance
().
create
())
{
LOGGER
.
debug
(
"execute:{}, flag:{}."
,
effectivePerson:
:
getDistinguishedName
,
()
->
flag
);
Table
table
=
emc
.
flag
(
flag
,
Table
.
class
);
if
(
null
==
table
)
{
throw
new
ExceptionEntityNotExist
(
flag
,
Table
.
class
);
}
DynamicEntity
dynamicEntity
=
new
DynamicEntity
(
table
.
getName
());
@SuppressWarnings
(
"unchecked"
)
Class
<?
extends
JpaObject
>
cls
=
(
Class
<?
extends
JpaObject
>)
classLoader
.
loadClass
(
dynamicEntity
.
className
());
JpaObject
o
=
update
(
jsonElement
,
cls
);
JpaObject
obj
=
emc
.
find
(
bundle
,
cls
);
emc
.
beginTransaction
(
cls
);
if
(
null
!=
obj
)
{
o
.
copyTo
(
obj
,
JpaObject
.
FieldsUnmodify
);
emc
.
check
(
obj
,
CheckPersistType
.
all
);
}
else
{
emc
.
persist
(
o
);
emc
.
check
(
o
,
CheckPersistType
.
all
);
}
emc
.
commit
();
Wo
wo
=
new
Wo
();
wo
.
setValue
(
true
);
result
.
setData
(
wo
);
}
return
result
;
}
public
static
class
Wo
extends
WrapBoolean
{
private
static
final
long
serialVersionUID
=
7570720614789228246L
;
}
}
\ No newline at end of file
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/BaseAction.java
浏览文件 @
e2e15a38
package
com.x.query.service.processing.jaxrs.table
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
javax.persistence.Column
;
import
org.apache.commons.beanutils.PropertyUtilsBean
;
import
org.apache.commons.lang3.reflect.FieldUtils
;
import
org.apache.openjpa.persistence.jdbc.ElementColumn
;
import
com.google.gson.JsonArray
;
import
com.google.gson.JsonElement
;
import
com.google.gson.JsonObject
;
import
com.google.gson.JsonPrimitive
;
import
com.x.base.core.entity.JpaObject
;
import
com.x.base.core.entity.tools.JpaObjectTools
;
import
com.x.base.core.project.jaxrs.StandardJaxrsAction
;
import
com.x.base.core.project.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
import
com.x.base.core.project.tools.DateTools
;
import
com.x.base.core.project.tools.StringTools
;
abstract
class
BaseAction
extends
StandardJaxrsAction
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
BaseAction
.
class
);
private
PropertyUtilsBean
propertyUtilsBean
=
new
PropertyUtilsBean
();
protected
<
T
extends
JpaObject
>
T
update
(
JsonElement
jsonElement
,
Class
<
T
>
cls
)
throws
IllegalAccessException
,
InvocationTargetException
,
NoSuchMethodException
,
InstantiationException
,
IllegalArgumentException
,
SecurityException
{
List
<
Field
>
fields
=
FieldUtils
.
getFieldsListWithAnnotation
(
cls
,
Column
.
class
);
T
t
=
cls
.
getConstructor
().
newInstance
();
JsonObject
jsonObject
=
null
;
if
((
jsonElement
!=
null
)
&&
jsonElement
.
isJsonObject
())
{
jsonObject
=
jsonElement
.
getAsJsonObject
();
}
for
(
Field
field
:
fields
)
{
switch
(
JpaObjectTools
.
type
(
field
))
{
case
JpaObject
.
TYPE_STRING
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractStringOrDistinguishedName
(
getJsonElement
(
jsonObject
,
field
),
getColumnDefinedStringLength
(
field
)));
break
;
case
JpaObject
.
TYPE_INTEGER
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractInteger
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_LONG
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractLong
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_FLOAT
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractFloat
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DOUBLE
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDouble
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DATETIME
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDateTime
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DATE
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDate
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_BOOLEAN
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractBoolean
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_STRINGLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractStringOrDistinguishedNameList
(
getJsonElement
(
jsonObject
,
field
),
getElementColumnDefinedStringLength
(
field
)));
break
;
case
JpaObject
.
TYPE_INTEGERLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractIntegerList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_LONGLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractLongList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_FLOATLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractFloatList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DOUBLELIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDoubleList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_DATETIMELIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractDateTimeList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
case
JpaObject
.
TYPE_BOOLEANLIST
:
propertyUtilsBean
.
setProperty
(
t
,
field
.
getName
(),
extractBooleanList
(
getJsonElement
(
jsonObject
,
field
)));
break
;
default
:
break
;
}
}
return
t
;
}
private
JsonElement
getJsonElement
(
JsonObject
jsonObject
,
Field
field
)
{
JsonElement
element
=
null
;
if
((
null
!=
jsonObject
)
&&
jsonObject
.
has
(
field
.
getName
()))
{
element
=
jsonObject
.
get
(
field
.
getName
());
}
return
element
;
}
private
int
getColumnDefinedStringLength
(
Field
field
)
{
Column
column
=
field
.
getAnnotation
(
Column
.
class
);
return
(
null
!=
column
)
?
column
.
length
()
:
JpaObject
.
length_255B
;
}
private
int
getElementColumnDefinedStringLength
(
Field
field
)
{
ElementColumn
elementColumn
=
field
.
getAnnotation
(
ElementColumn
.
class
);
return
(
null
!=
elementColumn
)
?
elementColumn
.
length
()
:
JpaObject
.
length_255B
;
}
private
String
extractStringOrDistinguishedName
(
JsonElement
jsonElement
,
int
maxLength
)
{
String
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
value
=
jsonElement
.
getAsString
();
}
else
if
(
jsonElement
.
isJsonObject
())
{
JsonObject
o
=
jsonElement
.
getAsJsonObject
();
if
(
o
.
has
(
JpaObject
.
DISTINGUISHEDNAME
))
{
value
=
o
.
get
(
JpaObject
.
DISTINGUISHEDNAME
).
getAsString
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractStringOrDistinguishedName
(
os
.
get
(
0
),
maxLength
);
}
}
}
return
StringTools
.
utf8SubString
(
value
,
maxLength
);
}
private
List
<
String
>
extractStringOrDistinguishedNameList
(
JsonElement
jsonElement
,
int
maxLength
)
{
List
<
String
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
values
.
add
(
StringTools
.
utf8SubString
(
jsonElement
.
getAsString
(),
maxLength
));
}
else
if
(
jsonElement
.
isJsonObject
())
{
JsonObject
o
=
jsonElement
.
getAsJsonObject
();
if
(
o
.
has
(
JpaObject
.
DISTINGUISHEDNAME
))
{
values
.
add
(
StringTools
.
utf8SubString
(
o
.
get
(
JpaObject
.
DISTINGUISHEDNAME
).
getAsString
(),
maxLength
));
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractStringOrDistinguishedName
(
o
,
maxLength
));
}
}
}
return
values
;
}
private
Integer
extractInteger
(
JsonElement
jsonElement
)
{
Integer
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsInt
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractInteger
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Integer
>
extractIntegerList
(
JsonElement
jsonElement
)
{
List
<
Integer
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsInt
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractInteger
(
o
));
}
}
}
return
values
;
}
private
Long
extractLong
(
JsonElement
jsonElement
)
{
Long
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsLong
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractLong
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Long
>
extractLongList
(
JsonElement
jsonElement
)
{
List
<
Long
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsLong
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractLong
(
o
));
}
}
}
return
values
;
}
private
Float
extractFloat
(
JsonElement
jsonElement
)
{
Float
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsFloat
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractFloat
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Float
>
extractFloatList
(
JsonElement
jsonElement
)
{
List
<
Float
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsFloat
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractFloat
(
o
));
}
}
}
return
values
;
}
private
Double
extractDouble
(
JsonElement
jsonElement
)
{
Double
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsDouble
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractDouble
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Double
>
extractDoubleList
(
JsonElement
jsonElement
)
{
List
<
Double
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsDouble
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractDouble
(
o
));
}
}
}
return
values
;
}
private
Date
extractDateTime
(
JsonElement
jsonElement
)
{
Date
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isString
())
{
try
{
value
=
DateTools
.
parseDateTime
(
jsonPrimitive
.
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractDateTime
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Date
>
extractDateTimeList
(
JsonElement
jsonElement
)
{
List
<
Date
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isString
())
{
try
{
values
.
add
(
DateTools
.
parseDateTime
(
jsonPrimitive
.
getAsString
()));
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractDateTime
(
o
));
}
}
}
return
values
;
}
private
Date
extractDate
(
JsonElement
jsonElement
)
{
Date
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isString
())
{
try
{
value
=
DateTools
.
parseDate
(
jsonPrimitive
.
getAsString
());
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
);
}
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractDate
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
Boolean
extractBoolean
(
JsonElement
jsonElement
)
{
Boolean
value
=
null
;
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
value
=
jsonPrimitive
.
getAsBoolean
();
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
if
(
os
.
size
()
>
0
)
{
value
=
extractBoolean
(
os
.
get
(
0
));
}
}
}
return
value
;
}
private
List
<
Boolean
>
extractBooleanList
(
JsonElement
jsonElement
)
{
List
<
Boolean
>
values
=
new
ArrayList
<>();
if
(
null
!=
jsonElement
)
{
if
(
jsonElement
.
isJsonPrimitive
())
{
JsonPrimitive
jsonPrimitive
=
jsonElement
.
getAsJsonPrimitive
();
if
(
jsonPrimitive
.
isNumber
())
{
values
.
add
(
jsonPrimitive
.
getAsBoolean
());
}
}
else
if
(
jsonElement
.
isJsonArray
())
{
JsonArray
os
=
jsonElement
.
getAsJsonArray
();
for
(
JsonElement
o
:
os
)
{
values
.
add
(
extractBoolean
(
o
));
}
}
}
return
values
;
}
}
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/table/TableAction.java
浏览文件 @
e2e15a38
package
com.x.query.service.processing.jaxrs.table
;
import
java.util.List
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.GET
;
...
...
@@ -32,18 +30,36 @@ public class TableAction extends StandardJaxrsAction {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
TableAction
.
class
);
@JaxrsMethodDescribe
(
value
=
"更新指定表中的行."
,
action
=
ActionUpdate
.
class
)
@JaxrsMethodDescribe
(
value
=
"更新指定表中的行."
,
action
=
ActionUpdate
WithBundle
.
class
)
@POST
@Path
(
"{flag}/update/{bundle}"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
void
listNext
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
public
void
updateWithBundle
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@JaxrsParameterDescribe
(
"标识"
)
@PathParam
(
"flag"
)
String
flag
,
@JaxrsParameterDescribe
(
"数据行标识"
)
@PathParam
(
"bundle"
)
String
bundle
,
JsonElement
jsonElement
)
{
ActionResult
<
ActionUpdate
.
Wo
>
result
=
new
ActionResult
<>();
ActionResult
<
ActionUpdateWithBundle
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionUpdateWithBundle
().
execute
(
effectivePerson
,
flag
,
bundle
,
jsonElement
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
,
effectivePerson
,
request
,
jsonElement
);
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
@JaxrsMethodDescribe
(
value
=
"指定表中插入行."
,
action
=
ActionInsert
.
class
)
@POST
@Path
(
"{flag}/insert"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
void
insert
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
@JaxrsParameterDescribe
(
"标识"
)
@PathParam
(
"flag"
)
String
flag
,
JsonElement
jsonElement
)
{
ActionResult
<
ActionInsert
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
Action
Update
().
execute
(
effectivePerson
,
flag
,
bundle
,
jsonElement
);
result
=
new
Action
Insert
().
execute
(
effectivePerson
,
flag
,
jsonElement
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
,
effectivePerson
,
request
,
jsonElement
);
result
.
error
(
e
);
...
...
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/touch/ActionTest.java
已删除
100644 → 0
浏览文件 @
acc42076
package
com.x.query.service.processing.jaxrs.touch
;
import
com.google.gson.JsonElement
;
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.logger.Logger
;
import
com.x.base.core.project.logger.LoggerFactory
;
class
ActionTest
extends
BaseAction
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
ActionTest
.
class
);
ActionResult
<
Wo
>
execute
(
EffectivePerson
effectivePerson
,
JsonElement
jsonElement
)
throws
Exception
{
ActionResult
<
Wo
>
result
=
new
ActionResult
<>();
System
.
out
.
println
(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
);
System
.
out
.
println
(
jsonElement
);
System
.
out
.
println
(
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
);
Wo
wo
=
new
Wo
();
result
.
setData
(
wo
);
return
result
;
}
public
static
class
Wo
extends
WrapBoolean
{
}
}
\ No newline at end of file
o2server/x_query_service_processing/src/main/java/com/x/query/service/processing/jaxrs/touch/TouchAction.java
浏览文件 @
e2e15a38
...
...
@@ -79,23 +79,4 @@ public class TouchAction extends StandardJaxrsAction {
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
@JaxrsMethodDescribe
(
value
=
"文字转换."
,
action
=
ActionTest
.
class
)
@POST
@Path
(
"test"
)
@Produces
(
HttpMediaType
.
APPLICATION_JSON_UTF_8
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
public
void
extract
(
@Suspended
final
AsyncResponse
asyncResponse
,
@Context
HttpServletRequest
request
,
JsonElement
jsonElement
)
{
ActionResult
<
ActionTest
.
Wo
>
result
=
new
ActionResult
<>();
EffectivePerson
effectivePerson
=
this
.
effectivePerson
(
request
);
try
{
result
=
new
ActionTest
().
execute
(
effectivePerson
,
jsonElement
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
e
,
effectivePerson
,
request
,
null
);
result
.
error
(
e
);
}
asyncResponse
.
resume
(
ResponseFactory
.
getEntityTagActionResultResponse
(
request
,
result
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录