Commit dc4969cd by shenjinzhu

一键启动和一键停止的添加

parent 6d5dc256
...@@ -12,6 +12,7 @@ import org.springframework.data.mongodb.core.mapping.Field; ...@@ -12,6 +12,7 @@ import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Component @Component
@Document(collection = "Template")
public class Template implements Serializable { public class Template implements Serializable {
/** /**
......
...@@ -10,6 +10,8 @@ import javax.annotation.Resource; ...@@ -10,6 +10,8 @@ import javax.annotation.Resource;
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.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.Query;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.mongodb.BasicDBObject; import com.mongodb.BasicDBObject;
...@@ -32,21 +34,28 @@ public class MessageDaoImpl implements MessageDao { ...@@ -32,21 +34,28 @@ public class MessageDaoImpl implements MessageDao {
@Override @Override
public String insert(Message message) { public String insert(Message message) {
mongo.insert(message); Message msg = mongo.findOne(Query.query(
return "添加成功"; Criteria.where("tempName").is(message.getTempName()).andOperator(Criteria.where("handle").is(false))
.andOperator(Criteria.where("errorMsg").is(message.getErrorMsg()))),
Message.class);
if (msg == null) {
mongo.insert(message);
return "添加成功";
}
return "未添加";
} }
@Override @Override
public String update(Message message,String pt) { public String update(Message message, String pt) {
DBCollection con = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return null; return null;
} }
DBObject obj = new BasicDBObject(); DBObject obj = new BasicDBObject();
obj.put("handle", message.isHandle()); obj.put("handle", message.isHandle());
obj.put("handleDate", new Date()); obj.put("handleDate", new Date());
...@@ -64,19 +73,19 @@ public class MessageDaoImpl implements MessageDao { ...@@ -64,19 +73,19 @@ 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>(); List<Message> msgList = new ArrayList<Message>();
DBCollection con = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return null; return null;
} }
DBCursor cursor = con.find(new BasicDBObject("pt", pt).append("handle", false)) DBCursor cursor = con.find(new BasicDBObject("pt", pt).append("handle", false)).skip((pageNo - 1) * pageSize)
.skip((pageNo - 1) * pageSize).limit(pageSize).sort(new BasicDBObject("createDate", -1)); .limit(pageSize).sort(new BasicDBObject("createDate", -1));
while (cursor.hasNext()) { while (cursor.hasNext()) {
Map<String, Object> map = (Map<String, Object>) cursor.next(); Map<String, Object> map = (Map<String, Object>) cursor.next();
Message msg = Change.toBean(Message.class, map); Message msg = Change.toBean(Message.class, map);
...@@ -88,20 +97,19 @@ public class MessageDaoImpl implements MessageDao { ...@@ -88,20 +97,19 @@ public class MessageDaoImpl implements MessageDao {
} }
@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>(); List<Message> msgList = new ArrayList<Message>();
DBCollection con = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return null; return null;
} }
DBCursor cursor = con DBCursor cursor = con
.find(new BasicDBObject("pt", pt).append("tempName", .find(new BasicDBObject("pt", pt).append("tempName", new BasicDBObject("$regex", templateName)))
new BasicDBObject("$regex", templateName)))
.skip((pageNo - 1) * pageSize).limit(pageSize).sort(new BasicDBObject("createDate", -1)); .skip((pageNo - 1) * pageSize).limit(pageSize).sort(new BasicDBObject("createDate", -1));
while (cursor.hasNext()) { while (cursor.hasNext()) {
Map<String, Object> map = (Map<String, Object>) cursor.next(); Map<String, Object> map = (Map<String, Object>) cursor.next();
...@@ -114,12 +122,12 @@ public class MessageDaoImpl implements MessageDao { ...@@ -114,12 +122,12 @@ public class MessageDaoImpl implements MessageDao {
} }
@Override @Override
public boolean delete(List<String> messageId,String pt) { public boolean delete(List<String> messageId, String pt) {
DBCollection con = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return false; return false;
...@@ -127,7 +135,7 @@ public class MessageDaoImpl implements MessageDao { ...@@ -127,7 +135,7 @@ public class MessageDaoImpl implements MessageDao {
System.out.println(con); System.out.println(con);
for (String msg : messageId) { for (String msg : messageId) {
WriteResult wr = con.remove(new BasicDBObject("_id", new ObjectId(msg))); WriteResult wr = con.remove(new BasicDBObject("_id", new ObjectId(msg)));
if(wr.getN()==0) { if (wr.getN() == 0) {
return false; return false;
} }
} }
...@@ -137,46 +145,47 @@ public class MessageDaoImpl implements MessageDao { ...@@ -137,46 +145,47 @@ public class MessageDaoImpl implements MessageDao {
@Override @Override
public int allCount(String pt) { public int allCount(String pt) {
DBCollection con = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return 0; return 0;
} }
return (int) con.count(new BasicDBObject("handle", false).append("pt",pt )); 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 = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return 0; return 0;
} }
return (int) con.count(new BasicDBObject("tempName", new BasicDBObject("$regex", templateName)).append("pt",pt )); 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 = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return null; return null;
} }
List<Message> msgList = new ArrayList<Message>(); List<Message> msgList = new ArrayList<Message>();
if (tempName == null || tempName.equals("")) { if (tempName == null || tempName.equals("")) {
DBCursor cur = con.find(new BasicDBObject("handle", handle).append("pt",pt )).sort(new BasicDBObject("createDate", -1)) DBCursor cur = con.find(new BasicDBObject("handle", handle).append("pt", pt))
.skip((pageNo - 1) * pageSize).limit(pageSize); .sort(new BasicDBObject("createDate", -1)).skip((pageNo - 1) * pageSize).limit(pageSize);
while (cur.hasNext()) { while (cur.hasNext()) {
Map<String, Object> map = (Map<String, Object>) cur.next(); Map<String, Object> map = (Map<String, Object>) cur.next();
Message msg = Change.toBean(Message.class, map); Message msg = Change.toBean(Message.class, map);
...@@ -186,8 +195,8 @@ public class MessageDaoImpl implements MessageDao { ...@@ -186,8 +195,8 @@ public class MessageDaoImpl implements MessageDao {
return msgList; return msgList;
} else { } else {
DBCursor cur = con DBCursor cur = con
.find(new BasicDBObject("handle", handle).append("tempName", .find(new BasicDBObject("handle", handle).append("tempName", new BasicDBObject("$regex", tempName))
new BasicDBObject("$regex", tempName)).append("pt",pt)) .append("pt", pt))
.sort(new BasicDBObject("createDate", -1)).skip((pageNo - 1) * pageSize).limit(pageSize); .sort(new BasicDBObject("createDate", -1)).skip((pageNo - 1) * pageSize).limit(pageSize);
while (cur.hasNext()) { while (cur.hasNext()) {
Map<String, Object> map = (Map<String, Object>) cur.next(); Map<String, Object> map = (Map<String, Object>) cur.next();
...@@ -201,21 +210,21 @@ public class MessageDaoImpl implements MessageDao { ...@@ -201,21 +210,21 @@ public class MessageDaoImpl implements MessageDao {
} }
@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 = null; DBCollection con = null;
if (DbDepot.dbCons.get(pt+"msg") != null) { if (DbDepot.dbCons.get(pt + "msg") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"msg"); con = (DBCollection) DbDepot.dbCons.get(pt + "msg");
} else { } else {
con = dbDepot.getDBCollection("msg",pt); con = dbDepot.getDBCollection("msg", pt);
} }
if (con == null) { if (con == null) {
return 0; return 0;
} }
if (tempName == null || tempName.equals("")) { if (tempName == null || tempName.equals("")) {
return (int) con.count(new BasicDBObject("handle", handle).append("pt",pt)); return (int) con.count(new BasicDBObject("handle", handle).append("pt", pt));
} else { } else {
return (int) con.count(new BasicDBObject("handle", handle) return (int) con.count(new BasicDBObject("handle", handle)
.append("tempName", new BasicDBObject("$regex",tempName)).append("pt",pt)); .append("tempName", new BasicDBObject("$regex", tempName)).append("pt", pt));
} }
} }
} }
...@@ -13,6 +13,8 @@ public interface TemplateDao { ...@@ -13,6 +13,8 @@ public interface TemplateDao {
public boolean update(Template template); public boolean update(Template template);
public List<Template> findAll(int pageNo,int pageSize,String pt); public List<Template> findAll(int pageNo,int pageSize,String pt);
public List<Template> findAll();
public Template findById(String templateId,String pt); public Template findById(String templateId,String pt);
......
...@@ -36,12 +36,7 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -36,12 +36,7 @@ public class TemplateDaoImpl implements TemplateDao {
@Override @Override
public boolean insert(Template template) { public boolean insert(Template template) {
DBCollection con = null; DBCollection con = getCollection(template.getPt());
if (DbDepot.dbCons.get(template.getPt()+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(template.getPt()+"temp");
} else {
con = dbDepot.getDBCollection("msg",template.getPt());
}
if (con == null) { if (con == null) {
return false; return false;
} }
...@@ -66,13 +61,7 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -66,13 +61,7 @@ public class TemplateDaoImpl implements TemplateDao {
@Override @Override
public boolean update(Template template) { public boolean update(Template template) {
System.out.println(template); DBCollection con = getCollection(template.getPt());
DBCollection con = null;
if (DbDepot.dbCons.get(template.getPt()+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(template.getPt()+"temp");
} else {
con = dbDepot.getDBCollection("temp",template.getPt());
}
if (con == null) { if (con == null) {
return false; return false;
} }
...@@ -96,18 +85,12 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -96,18 +85,12 @@ public class TemplateDaoImpl implements TemplateDao {
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);
System.out.println(result.getN());
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 = null; DBCollection con = getCollection(pt);
if (DbDepot.dbCons.get(pt+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"temp");
} else {
con = dbDepot.getDBCollection("temp",pt);
}
if (con == null) { if (con == null) {
return null; return null;
} }
...@@ -116,23 +99,12 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -116,23 +99,12 @@ public class TemplateDaoImpl implements TemplateDao {
temp=Change.toBean(Template.class, map); temp=Change.toBean(Template.class, map);
temp.setTemplateId(String.valueOf(map.get("_id"))); temp.setTemplateId(String.valueOf(map.get("_id")));
return temp; return temp;
// return mongo.findOne(Query.query(Criteria.where("_id").is(templateId)
// .andOperator(Criteria.where("pt").is(DbDepot.nowPt)))
// .with(new Sort(new Order(Direction.DESC, "createDate"))), Template.class);
} }
@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=new ArrayList<Template>();
DBCollection con = null; DBCollection con = getCollection(pt);
if (DbDepot.dbCons.get(pt+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"temp");
} else {
con = dbDepot.getDBCollection("temp",pt);
}
if (con == null) {
return null;
}
DBObject query=new BasicDBObject(); DBObject query=new BasicDBObject();
query.put("tempName", new BasicDBObject("$regex",templateName)); query.put("tempName", new BasicDBObject("$regex",templateName));
query.put("pt", pt); query.put("pt", pt);
...@@ -149,12 +121,7 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -149,12 +121,7 @@ public class TemplateDaoImpl implements TemplateDao {
@Override @Override
public boolean delete(String templateId,String pt) { public boolean delete(String templateId,String pt) {
DBCollection con = null; DBCollection con = getCollection(pt);
if (DbDepot.dbCons.get(pt+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"temp");
} else {
con = dbDepot.getDBCollection("temp",pt);
}
if (con == null) { if (con == null) {
return false; return false;
} }
...@@ -162,15 +129,12 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -162,15 +129,12 @@ public class TemplateDaoImpl implements TemplateDao {
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=new ArrayList<Template>();
DBCollection con = null; DBCollection con = getCollection(pt);
if (DbDepot.dbCons.get(pt+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"temp");
} else {
con = dbDepot.getDBCollection("temp",pt);
}
if (con == null) { if (con == null) {
return null; return null;
} }
...@@ -187,14 +151,19 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -187,14 +151,19 @@ public class TemplateDaoImpl implements TemplateDao {
return list; return list;
} }
@Override public DBCollection getCollection(String pt) {
public int allCount(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;
}
@Override
public int allCount(String pt) {
DBCollection con = getCollection(pt);
if (con == null) { if (con == null) {
return 0; return 0;
} }
...@@ -203,12 +172,7 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -203,12 +172,7 @@ public class TemplateDaoImpl implements TemplateDao {
@Override @Override
public int findByUserCount(String templateName,String pt) { public int findByUserCount(String templateName,String pt) {
DBCollection con = null; DBCollection con = getCollection(pt);
if (DbDepot.dbCons.get(pt+"temp") != null) {
con = (DBCollection) DbDepot.dbCons.get(pt+"temp");
} else {
con = dbDepot.getDBCollection("temp",pt);
}
if (con == null) { if (con == null) {
return 0; return 0;
} }
...@@ -216,4 +180,9 @@ public class TemplateDaoImpl implements TemplateDao { ...@@ -216,4 +180,9 @@ public class TemplateDaoImpl implements TemplateDao {
.append("pt", pt)); .append("pt", pt));
} }
@Override
public List<Template> findAll() {
return mongo.find(null, Template.class);
}
} }
...@@ -176,7 +176,7 @@ public class MainThread extends Thread { ...@@ -176,7 +176,7 @@ public class MainThread extends Thread {
System.out.println(list.size()); System.out.println(list.size());
for (CrawTemplate cr : list) { for (CrawTemplate cr : list) {
count = (int) dataService.finCountByDayData(start.getTime(), end.getTime(), count = (int) dataService.finCountByDayData(start.getTime(), end.getTime(),
chan.getPt(), cr.getId()); cr.getPt(), cr.getId());
Data data = new Data(); Data data = new Data();
data.setCount(count); data.setCount(count);
data.setTempName(cr.getConfigName()); data.setTempName(cr.getConfigName());
...@@ -185,7 +185,7 @@ public class MainThread extends Thread { ...@@ -185,7 +185,7 @@ public class MainThread extends Thread {
dataService.insert(data); dataService.insert(data);
if (count == 0) { if (count == 0) {
int testCount = (int) dataService.finCountByDayData(countTest.getTime(), int testCount = (int) dataService.finCountByDayData(countTest.getTime(),
end.getTime(), chan.getPt(), cr.getId()); end.getTime(), cr.getPt(), cr.getId());
if (testCount == 0) { if (testCount == 0) {
Message m = new Message(); Message m = new Message();
m.setHandle(false); m.setHandle(false);
...@@ -193,7 +193,7 @@ public class MainThread extends Thread { ...@@ -193,7 +193,7 @@ public class MainThread extends Thread {
m.setTemplateLv(1); m.setTemplateLv(1);
m.setTempName(cr.getConfigName()); m.setTempName(cr.getConfigName());
m.setPt(cr.getPt()); m.setPt(cr.getPt());
m.setErrorMsg("数据为0检测:" + cr.getConfigName() + "," + chan.getId() + "数据为0"); m.setErrorMsg("数据为0检测:" + cr.getConfigName() + "," + cr.getId() + "数据为0");
msgService.insert(m); msgService.insert(m);
} }
} }
......
package com.zhiwei.manage.service; package com.zhiwei.manage.service;
import java.util.List;
import com.zhiwei.manage.bean.PageEty; import com.zhiwei.manage.bean.PageEty;
import com.zhiwei.manage.bean.Template; import com.zhiwei.manage.bean.Template;
...@@ -10,6 +12,8 @@ public interface TemplateService { ...@@ -10,6 +12,8 @@ public interface TemplateService {
public boolean update(Template template); public boolean update(Template template);
public PageEty findAll(int pageNo,int pageSize,String pt); public PageEty findAll(int pageNo,int pageSize,String pt);
public List<Template> findAll();
public Template findById(String templateId,String pt); public Template findById(String templateId,String pt);
......
...@@ -45,18 +45,18 @@ public class TemplateServiceImpl implements TemplateService { ...@@ -45,18 +45,18 @@ public class TemplateServiceImpl implements TemplateService {
} }
@Override @Override
public PageEty findAll(int pageNo,int pageSize,String pt) { public PageEty findAll(int pageNo, int pageSize, String pt) {
int count=tempDao.allCount(pt); int count = tempDao.allCount(pt);
List<Template> data=tempDao.findAll(pageNo, pageSize,pt); List<Template> data = tempDao.findAll(pageNo, pageSize, pt);
for(Template tp:data){ for (Template tp : data) {
if(MainThread.allTmp.get(tp.getTemplateId())==null){ if (MainThread.allTmp.get(tp.getTemplateId()) == null) {
MainThread.allTmp.put(tp.getTemplateId(), tp); MainThread.allTmp.put(tp.getTemplateId(), tp);
} }
if(MainThread.mainMap.get(tp.getTemplateId())!=null){ if (MainThread.mainMap.get(tp.getTemplateId()) != null) {
tp.setOpen(true); tp.setOpen(true);
} }
} }
PageEty page=new PageEty(); PageEty page = new PageEty();
page.setData(data); page.setData(data);
page.setDataCount(count); page.setDataCount(count);
page.setPageNo(pageNo); page.setPageNo(pageNo);
...@@ -69,27 +69,27 @@ public class TemplateServiceImpl implements TemplateService { ...@@ -69,27 +69,27 @@ public class TemplateServiceImpl implements TemplateService {
} }
@Override @Override
public Template findById(String templateId,String pt) { public Template findById(String templateId, String pt) {
return tempDao.findById(templateId,pt); return tempDao.findById(templateId, pt);
} }
@Override @Override
public PageEty findByTmpName(String templateName,int pageNo,int pageSize,String pt) { public PageEty findByTmpName(String templateName, int pageNo, int pageSize, String pt) {
try { try {
int count=tempDao.findByUserCount(templateName,pt); int count = tempDao.findByUserCount(templateName, pt);
List<Template> data=tempDao.findByTmpName(templateName, pageNo, pageSize,pt); List<Template> data = tempDao.findByTmpName(templateName, pageNo, pageSize, pt);
for(Template tp:data){ for (Template tp : data) {
if(MainThread.allTmp.get(tp.getTemplateId())==null){ if (MainThread.allTmp.get(tp.getTemplateId()) == null) {
MainThread.allTmp.put(tp.getTemplateId(), tp); MainThread.allTmp.put(tp.getTemplateId(), tp);
} }
if(MainThread.mainMap.get(tp.getTemplateId())!=null){ if (MainThread.mainMap.get(tp.getTemplateId()) != null) {
tp.setOpen(true); tp.setOpen(true);
} }
} }
PageEty page=new PageEty(); PageEty page = new PageEty();
if(data.size()==0){ if (data.size() == 0) {
page.setData(new ArrayList<>()); page.setData(new ArrayList<>());
}else{ } else {
page.setData(data); page.setData(data);
} }
page.setPageNo(pageNo); page.setPageNo(pageNo);
...@@ -107,13 +107,27 @@ public class TemplateServiceImpl implements TemplateService { ...@@ -107,13 +107,27 @@ public class TemplateServiceImpl implements TemplateService {
} }
@Override @Override
public boolean delete(String templateId,String pt) { public boolean delete(String templateId, String pt) {
try { try {
return tempDao.delete(templateId,pt); return tempDao.delete(templateId, pt);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
} }
} }
@Override
public List<Template> findAll() {
List<Template> list = tempDao.findAll();
for (Template tp : list) {
if (MainThread.allTmp.get(tp.getTemplateId()) == null) {
MainThread.allTmp.put(tp.getTemplateId(), tp);
}
if (MainThread.mainMap.get(tp.getTemplateId()) != null) {
tp.setOpen(true);
}
}
return list;
}
} }
...@@ -2,9 +2,11 @@ package com.zhiwei.manage.servlet; ...@@ -2,9 +2,11 @@ package com.zhiwei.manage.servlet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -13,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.mysql.jdbc.log.LogFactory;
import com.zhiwei.manage.bean.FieldBean; import com.zhiwei.manage.bean.FieldBean;
import com.zhiwei.manage.bean.JsonResult; import com.zhiwei.manage.bean.JsonResult;
import com.zhiwei.manage.bean.PageEty; import com.zhiwei.manage.bean.PageEty;
...@@ -24,11 +27,37 @@ import com.zhiwei.manage.service.TemplateService; ...@@ -24,11 +27,37 @@ import com.zhiwei.manage.service.TemplateService;
@Controller @Controller
public class TemplateController { public class TemplateController {
private static final Log log=org.apache.commons.logging.LogFactory.getLog(TemplateController.class);
@Autowired @Autowired
private TemplateService ts; private TemplateService ts;
@Autowired @Autowired
private FieldBeanService fb; private FieldBeanService fb;
@RequestMapping(value = "/startAll", produces = "application/json;charset=utf-8")
@ResponseBody
public String startAll() {
List<Template> tpList=ts.findAll();
for(Template t:tpList) {
MainThread.pushMap(t.getTemplateId());
}
JsonResult result = new JsonResult(true, 200, "启动成功");
return JSON.toJSONString(result);
}
@RequestMapping(value = "/stopAll", produces = "application/json;charset=utf-8")
@ResponseBody
public String stopAll() {
Set<String> ids=MainThread.mainMap.keySet();
for(String id:ids) {
try {
MainThread.removeMap(id);
}catch(Exception e) {
log.error("停止失败{}",e);
}
}
JsonResult result = new JsonResult(true, 200, "停止成功");
return JSON.toJSONString(result);
}
@RequestMapping(value = "/saveTmp", produces = "application/json;charset=utf-8") @RequestMapping(value = "/saveTmp", produces = "application/json;charset=utf-8")
@ResponseBody @ResponseBody
public String saveTmp(@RequestBody Template template) { public String saveTmp(@RequestBody Template template) {
...@@ -38,7 +67,7 @@ public class TemplateController { ...@@ -38,7 +67,7 @@ public class TemplateController {
return JSON.toJSONString(result); return JSON.toJSONString(result);
} }
} }
JsonResult result = new JsonResult(false, 200, "保存失败"); JsonResult result = new JsonResult(true, 200, "保存失败");
return JSON.toJSONString(result); return JSON.toJSONString(result);
} }
......
<!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>数据管理系统</title><link rel=stylesheet href=./static/css/style.ini.css><link rel=stylesheet href=./static/datepicker/css/datepicker.css><link rel=stylesheet href=./static/datepicker/css/layout.css><link href=./static/css/app.921ce7ebf497e3e3e68ca86ac4ac8b7d.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.742ad85c13f695db2ef0.js></script><script type=text/javascript src=./static/js/vendor.c00def797876150978d2.js></script><script type=text/javascript src=./static/js/app.f00c0ff73ad487a928f0.js></script></body><script src=./static/js/jquery-1.12.4.min.js></script><script src=./static/js/jquery.easing-master/jquery.easing.min.js></script><script src=./static/js/jquery.transit.js></script><script src=./static/datepicker/js/datepicker.js></script><script src=./static/datepicker/js/eye.js></script><script src=./static/datepicker/js/utils.js></script></html> <!DOCTYPE html><html><head><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1"><title>数据管理系统</title><link rel=stylesheet href=./static/css/style.ini.css><link rel=stylesheet href=./static/datepicker/css/datepicker.css><link rel=stylesheet href=./static/datepicker/css/layout.css><link href=./static/css/app.92bad3cc55dab6eb58d4f6d580131955.css rel=stylesheet></head><body><div id=app></div><script type=text/javascript src=./static/js/manifest.1f643cf06e5671b25020.js></script><script type=text/javascript src=./static/js/vendor.c00def797876150978d2.js></script><script type=text/javascript src=./static/js/app.508ffe1db26d2a077b87.js></script></body><script src=./static/js/jquery-1.12.4.min.js></script><script src=./static/js/jquery.easing-master/jquery.easing.min.js></script><script src=./static/js/jquery.transit.js></script><script src=./static/datepicker/js/datepicker.js></script><script src=./static/datepicker/js/eye.js></script><script src=./static/datepicker/js/utils.js></script></html>
\ No newline at end of file \ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
!function(e){function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}var r=window.webpackJsonp;window.webpackJsonp=function(t,c,a){for(var i,u,f,s=0,l=[];s<t.length;s++)u=t[s],o[u]&&l.push(o[u][0]),o[u]=0;for(i in c)Object.prototype.hasOwnProperty.call(c,i)&&(e[i]=c[i]);for(r&&r(t,c,a);l.length;)l.shift()();if(a)for(s=0;s<a.length;s++)f=n(n.s=a[s]);return f};var t={},o={2:0};n.e=function(e){function r(){i.onerror=i.onload=null,clearTimeout(u);var n=o[e];0!==n&&(n&&n[1](new Error("Loading chunk "+e+" failed.")),o[e]=void 0)}var t=o[e];if(0===t)return new Promise(function(e){e()});if(t)return t[2];var c=new Promise(function(n,r){t=o[e]=[n,r]});t[2]=c;var a=document.getElementsByTagName("head")[0],i=document.createElement("script");i.type="text/javascript",i.charset="utf-8",i.async=!0,i.timeout=12e4,n.nc&&i.setAttribute("nonce",n.nc),i.src=n.p+"static/js/"+e+"."+{0:"c00def797876150978d2",1:"f00c0ff73ad487a928f0"}[e]+".js";var u=setTimeout(r,12e4);return i.onerror=i.onload=r,a.appendChild(i),c},n.m=e,n.c=t,n.d=function(e,r,t){n.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:t})},n.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(r,"a",r),r},n.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},n.p="./",n.oe=function(e){throw console.error(e),e}}([]);
//# sourceMappingURL=manifest.742ad85c13f695db2ef0.js.map
\ No newline at end of file
...@@ -157,7 +157,7 @@ export default { ...@@ -157,7 +157,7 @@ export default {
}, },
filters: { filters: {
format1 (timestemp) { format1 (timestemp) {
return moment(timestemp).format('YYYY-MM-DD hh:mm') return moment(timestemp).format('YYYY-MM-DD HH:mm')
} }
} }
} }
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
<div class="title"> <div class="title">
<input type="text" name="" value="" class="searchInput" spellcheck="false" placeholder="模板名" v-model="tempName" @keydown.enter="findAllTmp()"> <input type="text" name="" value="" class="searchInput" spellcheck="false" placeholder="模板名" v-model="tempName" @keydown.enter="findAllTmp()">
<div class="right"> <div class="right">
<button type="button" class="btn1" @click="allToggle(true)" v-if="userInfo.lv>=2">一键开启</button>
<button type="button" class="btn1" @click="allToggle(false)" v-if="userInfo.lv>=2">一键停止</button>
<button type="button" class="btn1" @click="popup.checkTemplateAdd = true" v-if="userInfo.lv>=2">新建模板</button> <button type="button" class="btn1" @click="popup.checkTemplateAdd = true" v-if="userInfo.lv>=2">新建模板</button>
<button type="button" class="btn1" @click="del()" v-if="userInfo.lv>=2">删除模板</button> <button type="button" class="btn1" @click="del()" v-if="userInfo.lv>=2">删除模板</button>
</div> </div>
...@@ -97,7 +99,7 @@ ...@@ -97,7 +99,7 @@
import checkTemplateDetails from '@/components/module/checkTemplateDetails' import checkTemplateDetails from '@/components/module/checkTemplateDetails'
import checkTemplateDelete from '@/components/module/checkTemplateDelete' import checkTemplateDelete from '@/components/module/checkTemplateDelete'
import checkTemplateAdd from '@/components/module/checkTemplateAdd' import checkTemplateAdd from '@/components/module/checkTemplateAdd'
import { bus, requestFindAllTmp, requestStartTmp, requestStopTmp } from '@/vuex/request.js' import { bus, requestFindAllTmp, requestStartTmp, requestStopTmp, requestStartAll, requestStopAll } from '@/vuex/request.js'
import { getPageList } from '@/assets/js/get-page-list.js' import { getPageList } from '@/assets/js/get-page-list.js'
export default { export default {
...@@ -131,6 +133,34 @@ export default { ...@@ -131,6 +133,34 @@ export default {
this.page = 1 this.page = 1
}, },
methods: { methods: {
// 一键开关
allToggle (flag) {
if (flag) {
requestStartAll({}, {}, (response) => {
if (response.data) {
if (response.data.state) {
this.findAllTmp()
} else {
bus.$emit('alert', response.data.message)
}
} else {
bus.$emit('alert', response + '.')
}
})
} else {
requestStopAll({}, {}, (response) => {
if (response.data) {
if (response.data.state) {
this.findAllTmp()
} else {
bus.$emit('alert', response.data.message)
}
} else {
bus.$emit('alert', response + '.')
}
})
}
},
clearCheckbox () { clearCheckbox () {
this.checkbox = [false, false, false, false, false, false, false, false, false, false] this.checkbox = [false, false, false, false, false, false, false, false, false, false]
}, },
......
...@@ -166,7 +166,7 @@ export default { ...@@ -166,7 +166,7 @@ export default {
}, },
filters: { filters: {
format1 (timestemp) { format1 (timestemp) {
return moment(timestemp).format('YYYY-MM-DD hh:mm') return moment(timestemp).format('YYYY-MM-DD HH:mm')
} }
} }
} }
......
...@@ -17,7 +17,8 @@ export const dataUrl = '/datamanage/' ...@@ -17,7 +17,8 @@ export const dataUrl = '/datamanage/'
// -------------------- 自动判断请求方式 // -------------------- 自动判断请求方式
const requestMethodAuto = (params, data) => { const requestMethodAuto = (params, data) => {
for (let i in data) { return 'post' } for (let i in data) { return 'post' }
for (let i in params) { return 'get' } // for (let i in params) { return 'get' }
return 'get'
} }
// -------------------- 数据管理系统 - 用户登录 ------------------ login // -------------------- 数据管理系统 - 用户登录 ------------------ login
...@@ -482,3 +483,29 @@ export let requestGetAllFields = (params, data, callback) => { ...@@ -482,3 +483,29 @@ export let requestGetAllFields = (params, data, callback) => {
callback(response) callback(response)
}) })
} }
// -------------------- 数据管理系统 - 检测模板 - 一键停止 ------------------ stopAll
export let requestStopAll = (params, data, callback) => {
axios({
url: dataUrl + 'stopAll',
method: requestMethodAuto(params, data),
params: params,
data: data
}).then((response) => {
callback(response)
}).catch((response) => {
callback(response)
})
}
// -------------------- 数据管理系统 - 检测模板 - 一键开启 ------------------ startAll
export let requestStartAll = (params, data, callback) => {
axios({
url: dataUrl + 'startAll',
method: requestMethodAuto(params, data),
params: params,
data: data
}).then((response) => {
callback(response)
}).catch((response) => {
callback(response)
})
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment