Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
datamanage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenjinzhu
datamanage
Commits
6c5a1ee3
Commit
6c5a1ee3
authored
Jan 16, 2018
by
shenjinzhu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
代码优化,数据库连接减少
parent
f0e1ed56
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
162 additions
and
275 deletions
+162
-275
src/main/java/com/zhiwei/manage/bean/Data.java
+0
-8
src/main/java/com/zhiwei/manage/bean/EasyNews.java
+0
-7
src/main/java/com/zhiwei/manage/bean/Message.java
+0
-7
src/main/java/com/zhiwei/manage/bean/News.java
+0
-7
src/main/java/com/zhiwei/manage/bean/Person.java
+0
-8
src/main/java/com/zhiwei/manage/bean/RunMsg.java
+0
-8
src/main/java/com/zhiwei/manage/bean/Template.java
+0
-4
src/main/java/com/zhiwei/manage/dao/DataDaoImpl.java
+0
-2
src/main/java/com/zhiwei/manage/dao/MessageDaoImpl.java
+43
-115
src/main/java/com/zhiwei/manage/dao/ServerDaoImpl.java
+15
-16
src/main/java/com/zhiwei/manage/dao/TemplateDaoImpl.java
+104
-93
No files found.
src/main/java/com/zhiwei/manage/bean/Data.java
View file @
6c5a1ee3
...
@@ -11,11 +11,6 @@ import org.springframework.stereotype.Component;
...
@@ -11,11 +11,6 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
Data
implements
Serializable
{
public
class
Data
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Id
@Indexed
(
unique
=
true
)
@Indexed
(
unique
=
true
)
private
String
dataId
;
private
String
dataId
;
...
@@ -73,9 +68,6 @@ public class Data implements Serializable{
...
@@ -73,9 +68,6 @@ public class Data implements Serializable{
public
void
setSpyderInfoId
(
String
spyderInfoId
)
{
public
void
setSpyderInfoId
(
String
spyderInfoId
)
{
this
.
spyderInfoId
=
spyderInfoId
;
this
.
spyderInfoId
=
spyderInfoId
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Data [dataId="
+
dataId
+
", pt="
+
pt
+
", tempName="
+
tempName
+
", source="
+
source
+
", count="
return
"Data [dataId="
+
dataId
+
", pt="
+
pt
+
", tempName="
+
tempName
+
", source="
+
source
+
", count="
...
...
src/main/java/com/zhiwei/manage/bean/EasyNews.java
View file @
6c5a1ee3
...
@@ -8,10 +8,6 @@ import org.springframework.stereotype.Component;
...
@@ -8,10 +8,6 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
EasyNews
implements
Serializable
{
public
class
EasyNews
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
1598171340115069977L
;
private
String
spyderInfoId
;
private
String
spyderInfoId
;
private
String
title
;
private
String
title
;
private
String
source
;
private
String
source
;
...
@@ -58,9 +54,6 @@ public class EasyNews implements Serializable {
...
@@ -58,9 +54,6 @@ public class EasyNews implements Serializable {
this
.
pt
=
pt
;
this
.
pt
=
pt
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
...
...
src/main/java/com/zhiwei/manage/bean/Message.java
View file @
6c5a1ee3
...
@@ -11,10 +11,6 @@ import org.springframework.data.mongodb.core.mapping.Field;
...
@@ -11,10 +11,6 @@ import org.springframework.data.mongodb.core.mapping.Field;
@Document
(
collection
=
"Message"
)
@Document
(
collection
=
"Message"
)
public
class
Message
implements
Serializable
{
public
class
Message
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Indexed
@Indexed
@Id
@Id
...
@@ -104,9 +100,6 @@ public class Message implements Serializable {
...
@@ -104,9 +100,6 @@ public class Message implements Serializable {
public
void
setHandler
(
String
handler
)
{
public
void
setHandler
(
String
handler
)
{
this
.
handler
=
handler
;
this
.
handler
=
handler
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Message [messageId="
+
messageId
+
", tempName="
+
tempName
+
", createDate="
+
createDate
return
"Message [messageId="
+
messageId
+
", tempName="
+
tempName
+
", createDate="
+
createDate
...
...
src/main/java/com/zhiwei/manage/bean/News.java
View file @
6c5a1ee3
...
@@ -10,10 +10,6 @@ import org.springframework.stereotype.Component;
...
@@ -10,10 +10,6 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
News
implements
Serializable
{
public
class
News
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Id
private
String
id
;
private
String
id
;
private
String
url
;
private
String
url
;
...
@@ -57,9 +53,6 @@ public class News implements Serializable{
...
@@ -57,9 +53,6 @@ public class News implements Serializable{
public
void
setTime
(
Date
time
)
{
public
void
setTime
(
Date
time
)
{
this
.
time
=
time
;
this
.
time
=
time
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
public
String
getSource
()
{
public
String
getSource
()
{
return
source
;
return
source
;
}
}
...
...
src/main/java/com/zhiwei/manage/bean/Person.java
View file @
6c5a1ee3
...
@@ -11,10 +11,6 @@ import org.springframework.data.mongodb.core.mapping.Field;
...
@@ -11,10 +11,6 @@ import org.springframework.data.mongodb.core.mapping.Field;
@Document
(
collection
=
"Person"
)
@Document
(
collection
=
"Person"
)
public
class
Person
implements
Serializable
{
public
class
Person
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Indexed
@Indexed
@Id
@Id
...
@@ -85,10 +81,6 @@ public class Person implements Serializable {
...
@@ -85,10 +81,6 @@ public class Person implements Serializable {
this
.
lv
=
lv
;
this
.
lv
=
lv
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Person [personId="
+
personId
+
", username="
+
username
+
", password="
+
password
+
", lv="
+
lv
return
"Person [personId="
+
personId
+
", username="
+
username
+
", password="
+
password
+
", lv="
+
lv
...
...
src/main/java/com/zhiwei/manage/bean/RunMsg.java
View file @
6c5a1ee3
...
@@ -9,10 +9,6 @@ import org.springframework.stereotype.Component;
...
@@ -9,10 +9,6 @@ import org.springframework.stereotype.Component;
@Component
@Component
public
class
RunMsg
implements
Serializable
{
public
class
RunMsg
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
String
templateId
;
private
String
templateId
;
private
String
templateName
;
private
String
templateName
;
...
@@ -114,10 +110,6 @@ public class RunMsg implements Serializable {
...
@@ -114,10 +110,6 @@ public class RunMsg implements Serializable {
this
.
fields
=
fields
;
this
.
fields
=
fields
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"RunMsg [templateId="
+
templateId
+
", templateName="
+
templateName
+
", runType="
+
runType
return
"RunMsg [templateId="
+
templateId
+
", templateName="
+
templateName
+
", runType="
+
runType
...
...
src/main/java/com/zhiwei/manage/bean/Template.java
View file @
6c5a1ee3
...
@@ -18,7 +18,6 @@ public class Template implements Serializable {
...
@@ -18,7 +18,6 @@ public class Template implements Serializable {
/**
/**
*
*
*/
*/
private
static
final
long
serialVersionUID
=
1L
;
@Indexed
@Indexed
@Id
@Id
private
String
templateId
;
private
String
templateId
;
...
@@ -237,9 +236,6 @@ public class Template implements Serializable {
...
@@ -237,9 +236,6 @@ public class Template implements Serializable {
public
void
setSpyderInfoId
(
String
spyderInfoId
)
{
public
void
setSpyderInfoId
(
String
spyderInfoId
)
{
this
.
spyderInfoId
=
spyderInfoId
;
this
.
spyderInfoId
=
spyderInfoId
;
}
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"Template [templateId="
+
templateId
+
", tempName="
+
tempName
+
", mail="
+
mail
+
", needPing="
return
"Template [templateId="
+
templateId
+
", tempName="
+
tempName
+
", mail="
+
mail
+
", needPing="
...
...
src/main/java/com/zhiwei/manage/dao/DataDaoImpl.java
View file @
6c5a1ee3
...
@@ -47,8 +47,6 @@ public class DataDaoImpl implements DataDao {
...
@@ -47,8 +47,6 @@ public class DataDaoImpl implements DataDao {
private
MongoTemplate
mongo
;
private
MongoTemplate
mongo
;
@Resource
(
name
=
"newmongoTemplate"
)
@Resource
(
name
=
"newmongoTemplate"
)
private
MongoTemplate
mongo2
;
private
MongoTemplate
mongo2
;
@Resource
(
name
=
"weibomongoTemplate"
)
private
MongoTemplate
weibo
;
@Override
@Override
public
List
<
Data
>
findByPt
(
Date
startTime
,
Date
endTime
,
String
pt
)
{
public
List
<
Data
>
findByPt
(
Date
startTime
,
Date
endTime
,
String
pt
)
{
...
...
src/main/java/com/zhiwei/manage/dao/MessageDaoImpl.java
View file @
6c5a1ee3
package
com
.
zhiwei
.
manage
.
dao
;
package
com
.
zhiwei
.
manage
.
dao
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -11,9 +12,13 @@ import org.apache.commons.logging.Log;
...
@@ -11,9 +12,13 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.apache.commons.logging.LogFactory
;
import
org.bson.types.ObjectId
;
import
org.bson.types.ObjectId
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort.Direction
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.CriteriaDefinition
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
com.mongodb.BasicDBObject
;
import
com.mongodb.BasicDBObject
;
...
@@ -32,9 +37,6 @@ public class MessageDaoImpl implements MessageDao {
...
@@ -32,9 +37,6 @@ public class MessageDaoImpl implements MessageDao {
@Resource
(
name
=
"mongoTemplate"
)
@Resource
(
name
=
"mongoTemplate"
)
private
MongoTemplate
mongo
;
private
MongoTemplate
mongo
;
@Autowired
private
DbDepot
dbDepot
;
@SuppressWarnings
(
"all"
)
@SuppressWarnings
(
"all"
)
@Override
@Override
public
String
insert
(
Message
message
)
{
public
String
insert
(
Message
message
)
{
...
@@ -52,19 +54,23 @@ public class MessageDaoImpl implements MessageDao {
...
@@ -52,19 +54,23 @@ public class MessageDaoImpl implements MessageDao {
@Override
@Override
public
String
update
(
Message
message
,
String
pt
)
{
public
String
update
(
Message
message
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
Update
update
=
new
Update
();
if
(
con
==
null
)
{
Field
[]
fields
=
message
.
getClass
().
getDeclaredFields
();
return
null
;
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
}
fields
[
j
].
setAccessible
(
true
);
DBObject
obj
=
new
BasicDBObject
();
try
{
obj
.
put
(
"handle"
,
message
.
isHandle
());
if
(
fields
[
j
].
getName
().
equals
(
"templateId"
))
{
obj
.
put
(
"handleDate"
,
new
Date
());
continue
;
obj
.
put
(
"handler"
,
message
.
getHandler
());
}
obj
.
put
(
"handleMsg"
,
message
.
getHandleMsg
());
if
(
fields
[
j
].
get
(
message
)
!=
null
)
DBObject
update
=
new
BasicDBObject
();
update
.
set
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
message
));
update
.
put
(
"$set"
,
obj
);
// 字段名,字段值
WriteResult
result
=
con
.
update
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
message
.
getMessageId
())),
update
,
false
,
}
catch
(
Exception
e
)
{
false
);
e
.
printStackTrace
();
}
}
WriteResult
result
=
mongo
.
updateFirst
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
message
.
getMessageId
())),
update
,
Message
.
class
);
if
(
result
.
getN
()
==
1
)
{
if
(
result
.
getN
()
==
1
)
{
return
"修改成功"
;
return
"修改成功"
;
}
else
{
}
else
{
...
@@ -74,132 +80,54 @@ public class MessageDaoImpl implements MessageDao {
...
@@ -74,132 +80,54 @@ public class MessageDaoImpl implements MessageDao {
@Override
@Override
public
List
<
Message
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
public
List
<
Message
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Message
>
msgList
=
new
ArrayList
<
Message
>();
return
mongo
.
find
(
DBCollection
con
=
getConnection
(
pt
);
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
).
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
false
)))
if
(
con
==
null
)
{
.
skip
((
pageNo
-
1
)
*
pageSize
).
with
(
new
Sort
(
Sort
.
Direction
.
ASC
,
"templateLv"
)).
limit
(
pageSize
),
return
null
;
Message
.
class
);
}
DBCursor
cursor
=
con
.
find
(
new
BasicDBObject
(
"pt"
,
pt
).
append
(
"handle"
,
false
)).
skip
((
pageNo
-
1
)
*
pageSize
)
.
limit
(
pageSize
).
sort
(
new
BasicDBObject
(
"templateLv"
,
1
).
append
(
"createDate"
,
-
1
));
while
(
cursor
.
hasNext
())
{
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
cursor
.
next
();
Message
msg
=
Change
.
toBean
(
Message
.
class
,
map
);
msg
.
setMessageId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
msg
.
setTempName
(
String
.
valueOf
(
map
.
get
(
"tempName"
)));
msgList
.
add
(
msg
);
}
return
msgList
;
}
public
DBCollection
getConnection
(
String
pt
)
{
DBCollection
con
=
null
;
if
(
DbDepot
.
dbCons
.
get
(
pt
+
"msg"
)
!=
null
)
{
con
=
(
DBCollection
)
DbDepot
.
dbCons
.
get
(
pt
+
"msg"
);
}
else
{
con
=
dbDepot
.
getDBCollection
(
"msg"
,
pt
);
}
return
con
;
}
}
@Override
@Override
public
List
<
Message
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
public
List
<
Message
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Message
>
msgList
=
new
ArrayList
<
Message
>();
return
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
)).
skip
((
pageNo
-
1
)
*
pageSize
)
DBCollection
con
=
getConnection
(
pt
);
.
limit
(
pageSize
),
Message
.
class
);
if
(
con
==
null
)
{
return
null
;
}
DBCursor
cursor
=
con
.
find
(
new
BasicDBObject
(
"pt"
,
pt
).
append
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
)))
.
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
).
sort
(
new
BasicDBObject
(
"createDate"
,
-
1
));
while
(
cursor
.
hasNext
())
{
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
cursor
.
next
();
Message
msg
=
Change
.
toBean
(
Message
.
class
,
map
);
msg
.
setMessageId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
msg
.
setTempName
(
String
.
valueOf
(
map
.
get
(
"tempName"
)));
msgList
.
add
(
msg
);
}
return
msgList
;
}
}
@Override
@Override
public
boolean
delete
(
List
<
String
>
messageId
,
String
pt
)
{
public
boolean
delete
(
List
<
String
>
messageId
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
WriteResult
wr
=
mongo
.
remove
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
in
(
messageId
)),
Message
.
class
);
if
(
con
==
null
)
{
return
false
;
}
System
.
out
.
println
(
con
);
for
(
String
msg
:
messageId
)
{
WriteResult
wr
=
con
.
remove
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
msg
)));
if
(
wr
.
getN
()
==
0
)
{
if
(
wr
.
getN
()
==
0
)
{
return
false
;
return
false
;
}
}
}
return
true
;
return
true
;
}
}
@Override
@Override
public
int
allCount
(
String
pt
)
{
public
int
allCount
(
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
return
(
int
)
mongo
.
count
(
if
(
con
==
null
)
{
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
).
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
false
))),
return
0
;
Message
.
class
);
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"handle"
,
false
).
append
(
"pt"
,
pt
));
}
}
@Override
@Override
public
int
findByTmpCount
(
String
templateName
,
String
pt
)
{
public
int
findByTmpCount
(
String
templateName
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
return
(
int
)
mongo
.
count
(
if
(
con
==
null
)
{
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
))),
return
0
;
Message
.
class
);
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
)).
append
(
"pt"
,
pt
));
}
}
@Override
@Override
public
List
<
Message
>
findByHandle
(
int
pageNo
,
int
pageSize
,
boolean
handle
,
String
tempName
,
String
pt
)
{
public
List
<
Message
>
findByHandle
(
int
pageNo
,
int
pageSize
,
boolean
handle
,
String
tempName
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
return
mongo
.
find
(
Query
if
(
con
==
null
)
{
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
tempName
)
return
null
;
.
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
handle
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
))))
}
.
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
),
Message
.
class
);
List
<
Message
>
msgList
=
new
ArrayList
<
Message
>();
if
(
tempName
==
null
||
tempName
.
equals
(
""
))
{
DBCursor
cur
=
con
.
find
(
new
BasicDBObject
(
"handle"
,
handle
).
append
(
"pt"
,
pt
))
.
sort
(
new
BasicDBObject
(
"createDate"
,
-
1
)).
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
);
while
(
cur
.
hasNext
())
{
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
cur
.
next
();
Message
msg
=
Change
.
toBean
(
Message
.
class
,
map
);
msg
.
setMessageId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
msgList
.
add
(
msg
);
}
return
msgList
;
}
else
{
DBCursor
cur
=
con
.
find
(
new
BasicDBObject
(
"handle"
,
handle
).
append
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
tempName
))
.
append
(
"pt"
,
pt
))
.
sort
(
new
BasicDBObject
(
"createDate"
,
-
1
)).
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
);
while
(
cur
.
hasNext
())
{
Map
<
String
,
Object
>
map
=
(
Map
<
String
,
Object
>)
cur
.
next
();
Message
msg
=
Change
.
toBean
(
Message
.
class
,
map
);
msg
.
setMessageId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
msgList
.
add
(
msg
);
}
return
msgList
;
}
}
}
@Override
@Override
public
int
findByHandleCount
(
int
pageNo
,
int
pageSize
,
boolean
handle
,
String
tempName
,
String
pt
)
{
public
int
findByHandleCount
(
int
pageNo
,
int
pageSize
,
boolean
handle
,
String
tempName
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
return
(
int
)
mongo
.
count
(
if
(
con
==
null
)
{
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
tempName
)
return
0
;
.
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
handle
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
)))),
}
Message
.
class
);
if
(
tempName
==
null
||
tempName
.
equals
(
""
))
{
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"handle"
,
handle
).
append
(
"pt"
,
pt
));
}
else
{
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"handle"
,
handle
)
.
append
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
tempName
)).
append
(
"pt"
,
pt
));
}
}
}
}
}
src/main/java/com/zhiwei/manage/dao/ServerDaoImpl.java
View file @
6c5a1ee3
...
@@ -74,22 +74,21 @@ public class ServerDaoImpl implements ServerDao {
...
@@ -74,22 +74,21 @@ public class ServerDaoImpl implements ServerDao {
@Override
@Override
public
void
findPt
(
String
pt
)
{
public
void
findPt
(
String
pt
)
{
List
<
ServerBean
>
list
=
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
)),
ServerBean
.
class
);
// List<ServerBean> list = mongo.find(Query.query(Criteria.where("pt").is(pt)), ServerBean.class);
for
(
ServerBean
sb
:
list
)
{
// for (ServerBean sb : list) {
System
.
out
.
println
(
sb
);
// if (sb.getDbType().equals("mongo")) {
if
(
sb
.
getDbType
().
equals
(
"mongo"
))
{
// if (sb.getDbUsername() != null && !sb.getDbUsername().equals("")) {
if
(
sb
.
getDbUsername
()
!=
null
&&
!
sb
.
getDbUsername
().
equals
(
""
))
{
// DBCollection con = new MongoConnect(sb.getDbHost(), sb.getDbPort(), sb.getDbUsername(),
DBCollection
con
=
new
MongoConnect
(
sb
.
getDbHost
(),
sb
.
getDbPort
(),
sb
.
getDbUsername
(),
// sb.getDbPassword(), sb.getDbName()).getCollection(sb.getCollection());
sb
.
getDbPassword
(),
sb
.
getDbName
()).
getCollection
(
sb
.
getCollection
());
// DbDepot.dbCons.put(sb.getOther(), con);
DbDepot
.
dbCons
.
put
(
sb
.
getOther
(),
con
);
// } else {
}
else
{
// DBCollection con = new MongoConnect(sb.getDbHost(), sb.getDbPort(), sb.getDbName())
DBCollection
con
=
new
MongoConnect
(
sb
.
getDbHost
(),
sb
.
getDbPort
(),
sb
.
getDbName
())
// .getCollection(sb.getCollection());
.
getCollection
(
sb
.
getCollection
());
// DbDepot.dbCons.put(sb.getOther(), con);
DbDepot
.
dbCons
.
put
(
sb
.
getOther
(),
con
);
// }
}
// }
}
// }
}
// DbDepot.nowPt = pt;
DbDepot
.
nowPt
=
pt
;
}
}
@Override
@Override
...
...
src/main/java/com/zhiwei/manage/dao/TemplateDaoImpl.java
View file @
6c5a1ee3
...
@@ -8,12 +8,14 @@ import java.util.Map;
...
@@ -8,12 +8,14 @@ import java.util.Map;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
org.bson.types.ObjectId
;
import
org.bson.types.ObjectId
;
import
org.elasticsearch.common.cache.Cache
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort.Direction
;
import
org.springframework.data.domain.Sort.Direction
;
import
org.springframework.data.domain.Sort.Order
;
import
org.springframework.data.domain.Sort.Order
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.Criteria
;
import
org.springframework.data.mongodb.core.query.CriteriaDefinition
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.data.mongodb.core.query.Update
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
...
@@ -36,37 +38,39 @@ public class TemplateDaoImpl implements TemplateDao {
...
@@ -36,37 +38,39 @@ public class TemplateDaoImpl implements TemplateDao {
@Override
@Override
public
boolean
insert
(
Template
template
)
{
public
boolean
insert
(
Template
template
)
{
DBCollection
con
=
getCollection
(
template
.
getPt
());
// DBCollection con = getCollection(template.getPt());
if
(
con
==
null
)
{
// if (con == null) {
return
false
;
// return false;
}
// }
DBObject
obj
=
new
BasicDBObject
();
// DBObject obj = new BasicDBObject();
Field
[]
fields
=
template
.
getClass
().
getDeclaredFields
();
// Field[] fields = template.getClass().getDeclaredFields();
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
// for (int j = 0; j < fields.length; j++) {
fields
[
j
].
setAccessible
(
true
);
// fields[j].setAccessible(true);
try
{
// try {
if
(
fields
[
j
].
getName
().
equals
(
"id"
))
{
// if (fields[j].getName().equals("id")) {
continue
;
// continue;
}
// }
if
(
fields
[
j
].
get
(
template
)
!=
null
)
// if (fields[j].get(template) != null)
// 字段名,字段值
// // 字段名,字段值
obj
.
put
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
template
));
// obj.put(fields[j].getName(), fields[j].get(template));
}
catch
(
Exception
e
)
{
// } catch (Exception e) {
e
.
printStackTrace
();
// e.printStackTrace();
}
// }
}
// }
con
.
insert
(
obj
);
// con.insert(obj);
mongo
.
insert
(
template
);
return
true
;
return
true
;
}
}
@Override
@Override
public
boolean
update
(
Template
template
)
{
public
boolean
update
(
Template
template
)
{
DBCollection
con
=
getCollection
(
template
.
getPt
());
// DBCollection con = getCollection(template.getPt());
if
(
con
==
null
)
{
// if (con == null) {
return
false
;
// return false;
}
// }
DBObject
update
=
new
BasicDBObject
();
// DBObject update = new BasicDBObject();
DBObject
obj
=
new
BasicDBObject
();
// DBObject obj = new BasicDBObject();
Update
update
=
new
Update
();
Field
[]
fields
=
template
.
getClass
().
getDeclaredFields
();
Field
[]
fields
=
template
.
getClass
().
getDeclaredFields
();
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
fields
[
j
].
setAccessible
(
true
);
fields
[
j
].
setAccessible
(
true
);
...
@@ -75,109 +79,116 @@ public class TemplateDaoImpl implements TemplateDao {
...
@@ -75,109 +79,116 @@ public class TemplateDaoImpl implements TemplateDao {
continue
;
continue
;
}
}
if
(
fields
[
j
].
get
(
template
)
!=
null
)
if
(
fields
[
j
].
get
(
template
)
!=
null
)
update
.
set
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
template
));
// 字段名,字段值
// 字段名,字段值
obj
.
put
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
template
));
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
update
.
put
(
"$set"
,
obj
);
// update.put("$set", obj);
DBObject
query
=
new
BasicDBObject
();
// DBObject query = new BasicDBObject();
query
.
put
(
"_id"
,
new
ObjectId
(
template
.
getTemplateId
()));
// query.put("_id", new ObjectId(template.getTemplateId()));
WriteResult
result
=
con
.
update
(
query
,
update
,
false
,
false
);
// WriteResult result = con.update(query, update, false, false);
WriteResult
result
=
mongo
.
updateFirst
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
template
.
getTemplateId
())),
update
,
Template
.
class
);
return
result
.
getN
()
==
1
?
true
:
false
;
return
result
.
getN
()
==
1
?
true
:
false
;
}
}
@Override
@Override
public
Template
findById
(
String
templateId
,
String
pt
)
{
public
Template
findById
(
String
templateId
,
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
// DBCollection con = getCollection(pt);
if
(
con
==
null
)
{
// if (con == null) {
return
null
;
// return null;
}
// }
Map
<
String
,
Object
>
map
=(
Map
<
String
,
Object
>)
con
.
findOne
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
templateId
)).
append
(
"pt"
,
pt
));
// Map<String, Object> map = (Map<String, Object>) con
Template
temp
=
new
Template
();
// .findOne(new BasicDBObject("_id", new ObjectId(templateId)).append("pt",
temp
=
Change
.
toBean
(
Template
.
class
,
map
);
// pt));
temp
.
setTemplateId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
Template
temp
=
mongo
.
findOne
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
templateId
)),
Template
.
class
);
// Template temp = new Template();
// temp = Change.toBean(Template.class, map);
// temp.setTemplateId(String.valueOf(map.get("_id")));
return
temp
;
return
temp
;
}
}
@Override
@Override
public
List
<
Template
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
public
List
<
Template
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Template
>
list
=
new
ArrayList
<
Template
>();
List
<
Template
>
list
=
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
))
DBCollection
con
=
getCollection
(
pt
);
.
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
).
addCriteria
(
Criteria
.
where
(
"pt"
).
is
(
pt
)),
DBObject
query
=
new
BasicDBObject
();
Template
.
class
);
query
.
put
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
));
// List<Template> list = new ArrayList<Template>();
query
.
put
(
"pt"
,
pt
);
// DBCollection con = getCollection(pt);
DBCursor
cursor
=
con
.
find
(
query
).
sort
(
new
BasicDBObject
(
"createDate"
,-
1
)).
skip
((
pageNo
-
1
)*
pageSize
).
limit
(
pageSize
);
// DBObject query = new BasicDBObject();
while
(
cursor
.
hasNext
()){
// query.put("tempName", new BasicDBObject("$regex", templateName));
Map
<
String
,
Object
>
map
=(
Map
<
String
,
Object
>)
cursor
.
next
();
// query.put("pt", pt);
Template
temp
=
new
Template
();
// DBCursor cursor = con.find(query).sort(new BasicDBObject("createDate",
temp
=
Change
.
toBean
(
Template
.
class
,
map
);
// -1)).skip((pageNo - 1) * pageSize)
temp
.
setTemplateId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
// .limit(pageSize);
list
.
add
(
temp
);
// while (cursor.hasNext()) {
}
// Map<String, Object> map = (Map<String, Object>) cursor.next();
// Template temp = new Template();
// temp = Change.toBean(Template.class, map);
// temp.setTemplateId(String.valueOf(map.get("_id")));
// list.add(temp);
// }
return
list
;
return
list
;
}
}
@Override
@Override
public
boolean
delete
(
String
templateId
,
String
pt
)
{
public
boolean
delete
(
String
templateId
,
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
// DBCollection con = getCollection(pt);
if
(
con
==
null
)
{
// if (con == null) {
return
false
;
// return false;
}
// }
WriteResult
result
=
con
.
remove
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
templateId
)));
// WriteResult result = con.remove(new BasicDBObject("_id", new
// ObjectId(templateId)));
WriteResult
result
=
mongo
.
remove
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
templateId
)),
Template
.
class
);
return
result
.
getN
()
==
0
?
true
:
false
;
return
result
.
getN
()
==
0
?
true
:
false
;
}
}
@Override
@Override
public
List
<
Template
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
public
List
<
Template
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Template
>
list
=
new
ArrayList
<
Template
>();
List
<
Template
>
list
=
mongo
.
find
(
DBCollection
con
=
getCollection
(
pt
);
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
)).
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
),
Template
.
class
);
if
(
con
==
null
)
{
// List<Template> list = new ArrayList<Template>();
return
null
;
// DBCollection con = getCollection(pt);
}
// if (con == null) {
DBObject
obj
=
new
BasicDBObject
();
// return null;
obj
.
put
(
"pt"
,
pt
);
// }
DBCursor
currsor
=
con
.
find
(
obj
).
sort
(
new
BasicDBObject
(
"createDate"
,-
1
)).
skip
((
pageNo
-
1
)
*
10
).
limit
(
pageSize
);
// DBObject obj = new BasicDBObject();
while
(
currsor
.
hasNext
()){
// obj.put("pt", pt);
Map
<
String
,
Object
>
map
=(
Map
<
String
,
Object
>)
currsor
.
next
();
// DBCursor currsor = con.find(obj).sort(new BasicDBObject("createDate",
Template
temp
=
new
Template
();
// -1)).skip((pageNo - 1) * 10)
temp
=
Change
.
toBean
(
Template
.
class
,
map
);
// .limit(pageSize);
temp
.
setTemplateId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
// while (currsor.hasNext()) {
list
.
add
(
temp
);
// Map<String, Object> map = (Map<String, Object>) currsor.next();
}
// Template temp = new Template();
// temp = Change.toBean(Template.class, map);
// temp.setTemplateId(String.valueOf(map.get("_id")));
// list.add(temp);
// }
return
list
;
return
list
;
}
}
public
DBCollection
getCollection
(
String
pt
)
{
public
DBCollection
getCollection
(
String
pt
)
{
DBCollection
con
=
null
;
DBCollection
con
=
null
;
if
(
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
)
!=
null
)
{
if
(
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
)
!=
null
)
{
con
=
(
DBCollection
)
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
);
con
=
(
DBCollection
)
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
);
}
else
{
}
else
{
con
=
dbDepot
.
getDBCollection
(
"temp"
,
pt
);
con
=
dbDepot
.
getDBCollection
(
"temp"
,
pt
);
}
}
return
con
;
return
con
;
}
}
@Override
@Override
public
int
allCount
(
String
pt
)
{
public
int
allCount
(
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
return
(
int
)
mongo
.
count
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
)),
Template
.
class
);
if
(
con
==
null
)
{
return
0
;
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"pt"
,
pt
));
}
}
@Override
@Override
public
int
findByUserCount
(
String
templateName
,
String
pt
)
{
public
int
findByUserCount
(
String
templateName
,
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
return
(
int
)
mongo
.
count
(
if
(
con
==
null
)
{
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
))),
return
0
;
Template
.
class
);
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
))
.
append
(
"pt"
,
pt
));
}
}
@Override
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment