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
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
164 additions
and
277 deletions
+164
-277
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
+106
-95
No files found.
src/main/java/com/zhiwei/manage/bean/Data.java
View file @
6c5a1ee3
...
...
@@ -11,11 +11,6 @@ import org.springframework.stereotype.Component;
@Component
public
class
Data
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Id
@Indexed
(
unique
=
true
)
private
String
dataId
;
...
...
@@ -73,9 +68,6 @@ public class Data implements Serializable{
public
void
setSpyderInfoId
(
String
spyderInfoId
)
{
this
.
spyderInfoId
=
spyderInfoId
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
public
String
toString
()
{
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;
@Component
public
class
EasyNews
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
-
1598171340115069977L
;
private
String
spyderInfoId
;
private
String
title
;
private
String
source
;
...
...
@@ -58,9 +54,6 @@ public class EasyNews implements Serializable {
this
.
pt
=
pt
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
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;
@Document
(
collection
=
"Message"
)
public
class
Message
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Indexed
@Id
...
...
@@ -104,9 +100,6 @@ public class Message implements Serializable {
public
void
setHandler
(
String
handler
)
{
this
.
handler
=
handler
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
public
String
toString
()
{
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;
@Component
public
class
News
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Id
private
String
id
;
private
String
url
;
...
...
@@ -57,9 +53,6 @@ public class News implements Serializable{
public
void
setTime
(
Date
time
)
{
this
.
time
=
time
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
public
String
getSource
()
{
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;
@Document
(
collection
=
"Person"
)
public
class
Person
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Indexed
@Id
...
...
@@ -85,10 +81,6 @@ public class Person implements Serializable {
this
.
lv
=
lv
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
public
String
toString
()
{
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;
@Component
public
class
RunMsg
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
String
templateId
;
private
String
templateName
;
...
...
@@ -114,10 +110,6 @@ public class RunMsg implements Serializable {
this
.
fields
=
fields
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
public
String
toString
()
{
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 {
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
@Indexed
@Id
private
String
templateId
;
...
...
@@ -237,9 +236,6 @@ public class Template implements Serializable {
public
void
setSpyderInfoId
(
String
spyderInfoId
)
{
this
.
spyderInfoId
=
spyderInfoId
;
}
public
static
long
getSerialversionuid
()
{
return
serialVersionUID
;
}
@Override
public
String
toString
()
{
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 {
private
MongoTemplate
mongo
;
@Resource
(
name
=
"newmongoTemplate"
)
private
MongoTemplate
mongo2
;
@Resource
(
name
=
"weibomongoTemplate"
)
private
MongoTemplate
weibo
;
@Override
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
;
import
java.lang.reflect.Field
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
...
...
@@ -11,9 +12,13 @@ import org.apache.commons.logging.Log;
import
org.apache.commons.logging.LogFactory
;
import
org.bson.types.ObjectId
;
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.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.Update
;
import
org.springframework.stereotype.Component
;
import
com.mongodb.BasicDBObject
;
...
...
@@ -32,9 +37,6 @@ public class MessageDaoImpl implements MessageDao {
@Resource
(
name
=
"mongoTemplate"
)
private
MongoTemplate
mongo
;
@Autowired
private
DbDepot
dbDepot
;
@SuppressWarnings
(
"all"
)
@Override
public
String
insert
(
Message
message
)
{
...
...
@@ -52,19 +54,23 @@ public class MessageDaoImpl implements MessageDao {
@Override
public
String
update
(
Message
message
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
return
null
;
Update
update
=
new
Update
();
Field
[]
fields
=
message
.
getClass
().
getDeclaredFields
();
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
fields
[
j
].
setAccessible
(
true
);
try
{
if
(
fields
[
j
].
getName
().
equals
(
"templateId"
))
{
continue
;
}
if
(
fields
[
j
].
get
(
message
)
!=
null
)
update
.
set
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
message
));
// 字段名,字段值
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
DBObject
obj
=
new
BasicDBObject
();
obj
.
put
(
"handle"
,
message
.
isHandle
());
obj
.
put
(
"handleDate"
,
new
Date
());
obj
.
put
(
"handler"
,
message
.
getHandler
());
obj
.
put
(
"handleMsg"
,
message
.
getHandleMsg
());
DBObject
update
=
new
BasicDBObject
();
update
.
put
(
"$set"
,
obj
);
WriteResult
result
=
con
.
update
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
message
.
getMessageId
())),
update
,
false
,
false
);
WriteResult
result
=
mongo
.
updateFirst
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
is
(
message
.
getMessageId
())),
update
,
Message
.
class
);
if
(
result
.
getN
()
==
1
)
{
return
"修改成功"
;
}
else
{
...
...
@@ -74,132 +80,54 @@ public class MessageDaoImpl implements MessageDao {
@Override
public
List
<
Message
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Message
>
msgList
=
new
ArrayList
<
Message
>();
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
return
null
;
}
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
;
return
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
).
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
false
)))
.
skip
((
pageNo
-
1
)
*
pageSize
).
with
(
new
Sort
(
Sort
.
Direction
.
ASC
,
"templateLv"
)).
limit
(
pageSize
),
Message
.
class
);
}
@Override
public
List
<
Message
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Message
>
msgList
=
new
ArrayList
<
Message
>();
DBCollection
con
=
getConnection
(
pt
);
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
;
return
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
)).
skip
((
pageNo
-
1
)
*
pageSize
)
.
limit
(
pageSize
),
Message
.
class
);
}
@Override
public
boolean
delete
(
List
<
String
>
messageId
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
WriteResult
wr
=
mongo
.
remove
(
Query
.
query
(
Criteria
.
where
(
"_id"
).
in
(
messageId
)),
Message
.
class
);
if
(
wr
.
getN
()
==
0
)
{
return
false
;
}
System
.
out
.
println
(
con
);
for
(
String
msg
:
messageId
)
{
WriteResult
wr
=
con
.
remove
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
msg
)));
if
(
wr
.
getN
()
==
0
)
{
return
false
;
}
}
return
true
;
}
@Override
public
int
allCount
(
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
return
0
;
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"handle"
,
false
).
append
(
"pt"
,
pt
));
return
(
int
)
mongo
.
count
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
).
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
false
))),
Message
.
class
);
}
@Override
public
int
findByTmpCount
(
String
templateName
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
return
0
;
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
)).
append
(
"pt"
,
pt
));
return
(
int
)
mongo
.
count
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
))),
Message
.
class
);
}
@Override
public
List
<
Message
>
findByHandle
(
int
pageNo
,
int
pageSize
,
boolean
handle
,
String
tempName
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
return
null
;
}
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
;
}
return
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
tempName
)
.
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
handle
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
))))
.
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
),
Message
.
class
);
}
@Override
public
int
findByHandleCount
(
int
pageNo
,
int
pageSize
,
boolean
handle
,
String
tempName
,
String
pt
)
{
DBCollection
con
=
getConnection
(
pt
);
if
(
con
==
null
)
{
return
0
;
}
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
));
}
return
(
int
)
mongo
.
count
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
tempName
)
.
andOperator
(
Criteria
.
where
(
"handle"
).
is
(
handle
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
)))),
Message
.
class
);
}
}
src/main/java/com/zhiwei/manage/dao/ServerDaoImpl.java
View file @
6c5a1ee3
...
...
@@ -74,22 +74,21 @@ public class ServerDaoImpl implements ServerDao {
@Override
public
void
findPt
(
String
pt
)
{
List
<
ServerBean
>
list
=
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
)),
ServerBean
.
class
);
for
(
ServerBean
sb
:
list
)
{
System
.
out
.
println
(
sb
);
if
(
sb
.
getDbType
().
equals
(
"mongo"
))
{
if
(
sb
.
getDbUsername
()
!=
null
&&
!
sb
.
getDbUsername
().
equals
(
""
))
{
DBCollection
con
=
new
MongoConnect
(
sb
.
getDbHost
(),
sb
.
getDbPort
(),
sb
.
getDbUsername
(),
sb
.
getDbPassword
(),
sb
.
getDbName
()).
getCollection
(
sb
.
getCollection
());
DbDepot
.
dbCons
.
put
(
sb
.
getOther
(),
con
);
}
else
{
DBCollection
con
=
new
MongoConnect
(
sb
.
getDbHost
(),
sb
.
getDbPort
(),
sb
.
getDbName
())
.
getCollection
(
sb
.
getCollection
());
DbDepot
.
dbCons
.
put
(
sb
.
getOther
(),
con
);
}
}
}
DbDepot
.
nowPt
=
pt
;
// List<ServerBean> list = mongo.find(Query.query(Criteria.where("pt").is(pt)), ServerBean.class);
// for (ServerBean sb : list) {
// if (sb.getDbType().equals("mongo")) {
// if (sb.getDbUsername() != null && !sb.getDbUsername().equals("")) {
// DBCollection con = new MongoConnect(sb.getDbHost(), sb.getDbPort(), sb.getDbUsername(),
// sb.getDbPassword(), sb.getDbName()).getCollection(sb.getCollection());
// DbDepot.dbCons.put(sb.getOther(), con);
// } else {
// DBCollection con = new MongoConnect(sb.getDbHost(), sb.getDbPort(), sb.getDbName())
// .getCollection(sb.getCollection());
// DbDepot.dbCons.put(sb.getOther(), con);
// }
// }
// }
// DbDepot.nowPt = pt;
}
@Override
...
...
src/main/java/com/zhiwei/manage/dao/TemplateDaoImpl.java
View file @
6c5a1ee3
...
...
@@ -8,12 +8,14 @@ import java.util.Map;
import
javax.annotation.Resource
;
import
org.bson.types.ObjectId
;
import
org.elasticsearch.common.cache.Cache
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort.Direction
;
import
org.springframework.data.domain.Sort.Order
;
import
org.springframework.data.mongodb.core.MongoTemplate
;
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.Update
;
import
org.springframework.stereotype.Service
;
...
...
@@ -36,37 +38,39 @@ public class TemplateDaoImpl implements TemplateDao {
@Override
public
boolean
insert
(
Template
template
)
{
DBCollection
con
=
getCollection
(
template
.
getPt
());
if
(
con
==
null
)
{
return
false
;
}
DBObject
obj
=
new
BasicDBObject
();
Field
[]
fields
=
template
.
getClass
().
getDeclaredFields
();
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
fields
[
j
].
setAccessible
(
true
);
try
{
if
(
fields
[
j
].
getName
().
equals
(
"id"
))
{
continue
;
}
if
(
fields
[
j
].
get
(
template
)
!=
null
)
// 字段名,字段值
obj
.
put
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
template
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
con
.
insert
(
obj
);
// DBCollection con = getCollection(template.getPt());
// if (con == null) {
// return false;
// }
// DBObject obj = new BasicDBObject();
// Field[] fields = template.getClass().getDeclaredFields();
// for (int j = 0; j < fields.length; j++) {
// fields[j].setAccessible(true);
// try {
// if (fields[j].getName().equals("id")) {
// continue;
// }
// if (fields[j].get(template) != null)
// // 字段名,字段值
// obj.put(fields[j].getName(), fields[j].get(template));
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// con.insert(obj);
mongo
.
insert
(
template
);
return
true
;
}
@Override
public
boolean
update
(
Template
template
)
{
DBCollection
con
=
getCollection
(
template
.
getPt
());
if
(
con
==
null
)
{
return
false
;
}
DBObject
update
=
new
BasicDBObject
();
DBObject
obj
=
new
BasicDBObject
();
// DBCollection con = getCollection(template.getPt());
// if (con == null) {
// return false;
// }
// DBObject update = new BasicDBObject();
// DBObject obj = new BasicDBObject();
Update
update
=
new
Update
();
Field
[]
fields
=
template
.
getClass
().
getDeclaredFields
();
for
(
int
j
=
0
;
j
<
fields
.
length
;
j
++)
{
fields
[
j
].
setAccessible
(
true
);
...
...
@@ -75,109 +79,116 @@ public class TemplateDaoImpl implements TemplateDao {
continue
;
}
if
(
fields
[
j
].
get
(
template
)
!=
null
)
// 字段名,字段值
obj
.
put
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
template
));
update
.
set
(
fields
[
j
].
getName
(),
fields
[
j
].
get
(
template
));
// 字段名,字段值
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
update
.
put
(
"$set"
,
obj
);
DBObject
query
=
new
BasicDBObject
();
query
.
put
(
"_id"
,
new
ObjectId
(
template
.
getTemplateId
()));
WriteResult
result
=
con
.
update
(
query
,
update
,
false
,
false
);
// update.put("$set", obj);
// DBObject query = new BasicDBObject();
// query.put("_id", new ObjectId(template.getTemplateId()));
// 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
;
}
@Override
public
Template
findById
(
String
templateId
,
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
if
(
con
==
null
)
{
return
null
;
}
Map
<
String
,
Object
>
map
=(
Map
<
String
,
Object
>)
con
.
findOne
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
templateId
)).
append
(
"pt"
,
pt
));
Template
temp
=
new
Template
();
temp
=
Change
.
toBean
(
Template
.
class
,
map
);
temp
.
setTemplateId
(
String
.
valueOf
(
map
.
get
(
"_id"
)));
public
Template
findById
(
String
templateId
,
String
pt
)
{
// DBCollection con = getCollection(pt);
// if (con == null) {
// return null;
// }
// Map<String, Object> map = (Map<String, Object>) con
// .findOne(new BasicDBObject("_id", new ObjectId(templateId)).append("pt",
// pt));
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
;
}
@Override
public
List
<
Template
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Template
>
list
=
new
ArrayList
<
Template
>();
DBCollection
con
=
getCollection
(
pt
);
DBObject
query
=
new
BasicDBObject
();
query
.
put
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
));
query
.
put
(
"pt"
,
pt
);
DBCursor
cursor
=
con
.
find
(
query
).
sort
(
new
BasicDBObject
(
"createDate"
,-
1
)).
skip
((
pageNo
-
1
)*
pageSize
).
limit
(
pageSize
);
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
);
}
public
List
<
Template
>
findByTmpName
(
String
templateName
,
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Template
>
list
=
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
))
.
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
).
addCriteria
(
Criteria
.
where
(
"pt"
).
is
(
pt
)),
Template
.
class
);
// List<Template> list = new ArrayList<Template>();
// DBCollection con = getCollection(pt);
// DBObject query = new BasicDBObject();
// query.put("tempName", new BasicDBObject("$regex", templateName));
// query.put("pt", pt);
// DBCursor cursor = con.find(query).sort(new BasicDBObject("createDate",
// -1)).skip((pageNo - 1) * pageSize)
// .limit(pageSize);
// 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
;
}
@Override
public
boolean
delete
(
String
templateId
,
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
if
(
con
==
null
)
{
return
false
;
}
WriteResult
result
=
con
.
remove
(
new
BasicDBObject
(
"_id"
,
new
ObjectId
(
templateId
)));
public
boolean
delete
(
String
templateId
,
String
pt
)
{
// DBCollection con = getCollection(pt);
// if (con == null) {
// return false;
// }
// 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
;
}
@Override
public
List
<
Template
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Template
>
list
=
new
ArrayList
<
Template
>();
DBCollection
con
=
getCollection
(
pt
);
if
(
con
==
null
)
{
return
null
;
}
DBObject
obj
=
new
BasicDBObject
();
obj
.
put
(
"pt"
,
pt
);
DBCursor
currsor
=
con
.
find
(
obj
).
sort
(
new
BasicDBObject
(
"createDate"
,-
1
)).
skip
((
pageNo
-
1
)
*
10
).
limit
(
pageSize
);
while
(
currsor
.
hasNext
()){
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
);
}
public
List
<
Template
>
findAll
(
int
pageNo
,
int
pageSize
,
String
pt
)
{
List
<
Template
>
list
=
mongo
.
find
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
)).
skip
((
pageNo
-
1
)
*
pageSize
).
limit
(
pageSize
),
Template
.
class
);
// List<Template> list = new ArrayList<Template>();
// DBCollection con = getCollection(pt);
// if (con == null) {
// return null;
// }
// DBObject obj = new BasicDBObject();
// obj.put("pt", pt);
// DBCursor currsor = con.find(obj).sort(new BasicDBObject("createDate",
// -1)).skip((pageNo - 1) * 10)
// .limit(pageSize);
// while (currsor.hasNext()) {
// 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
;
}
public
DBCollection
getCollection
(
String
pt
)
{
DBCollection
con
=
null
;
if
(
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
)
!=
null
)
{
con
=
(
DBCollection
)
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
);
if
(
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
)
!=
null
)
{
con
=
(
DBCollection
)
DbDepot
.
dbCons
.
get
(
pt
+
"temp"
);
}
else
{
con
=
dbDepot
.
getDBCollection
(
"temp"
,
pt
);
con
=
dbDepot
.
getDBCollection
(
"temp"
,
pt
);
}
return
con
;
}
@Override
public
int
allCount
(
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
if
(
con
==
null
)
{
return
0
;
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"pt"
,
pt
));
return
(
int
)
mongo
.
count
(
Query
.
query
(
Criteria
.
where
(
"pt"
).
is
(
pt
)),
Template
.
class
);
}
@Override
public
int
findByUserCount
(
String
templateName
,
String
pt
)
{
DBCollection
con
=
getCollection
(
pt
);
if
(
con
==
null
)
{
return
0
;
}
return
(
int
)
con
.
count
(
new
BasicDBObject
(
"tempName"
,
new
BasicDBObject
(
"$regex"
,
templateName
))
.
append
(
"pt"
,
pt
));
public
int
findByUserCount
(
String
templateName
,
String
pt
)
{
return
(
int
)
mongo
.
count
(
Query
.
query
(
Criteria
.
where
(
"tempName"
).
regex
(
templateName
).
andOperator
(
Criteria
.
where
(
"pt"
).
is
(
pt
))),
Template
.
class
);
}
@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