Commit 515b4bc9 by admin

添加注释

parent 22d33948
......@@ -8,8 +8,14 @@ import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection="Channel")
public class Channel implements Serializable{
/**
* 渠道字段对应
*
* @author admin
*
*/
@Document(collection = "Channel")
public class Channel implements Serializable {
@Indexed
@Id
......@@ -18,34 +24,42 @@ public class Channel implements Serializable{
private String value;
@Transient
private List<Data> list;
public List<Data> getList() {
return list;
}
public void setList(List<Data> list) {
this.list = list;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPt() {
return pt;
}
public void setPt(String pt) {
this.pt = pt;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
@Override
public String toString() {
return "Channel [id=" + id + ", pt=" + pt + ", value=" + value + "]";
}
}
......@@ -6,7 +6,6 @@ import java.util.Map;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@Document(collection = "spyderInfo")
public class CrawTemplate {
......@@ -14,13 +13,13 @@ public class CrawTemplate {
private String configName;
@Field("staticFieldList")
private List<Map<String,Object>> staticFieldList;
private List<Map<String, Object>> staticFieldList;
@Field("_id")
private String id;
private String pt;
public List<Map<String, Object>> getStaticFieldList() {
return staticFieldList;
}
......@@ -59,5 +58,4 @@ public class CrawTemplate {
+ ", pt=" + pt + "]";
}
}
......@@ -8,72 +8,90 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.stereotype.Component;
/**
* 数据量
*
* @author admin
*
*/
@Component
@Document(collection="Data")
public class Data implements Serializable{
@Document(collection = "Data")
public class Data implements Serializable {
@Id
@Indexed(unique=true)
@Indexed(unique = true)
private String dataId;
private String pt;
@Indexed(background=true)
@Indexed(background = true)
private String tempName;
@Indexed(background=true)
@Indexed(background = true)
private String source;
private long count;
@Indexed(background=true)
@Indexed(background = true)
private Date time;
@Indexed(background=true)
@Indexed(background = true)
private String spyderInfoId;
public String getDataId() {
return dataId;
}
public void setDataId(String dataId) {
this.dataId = dataId;
}
public String getPt() {
return pt;
}
public void setPt(String pt) {
this.pt = pt;
}
public String getTempName() {
return tempName;
}
public void setTempName(String tempName) {
this.tempName = tempName;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public long getCount() {
return count;
}
public void setCount(long count) {
this.count = count;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getSpyderInfoId() {
return spyderInfoId;
}
public void setSpyderInfoId(String spyderInfoId) {
this.spyderInfoId = spyderInfoId;
}
@Override
public String toString() {
return "Data [dataId=" + dataId + ", pt=" + pt + ", tempName=" + tempName + ", source=" + source + ", count="
+ count + ", time=" + time + "]";
}
}
......@@ -5,6 +5,11 @@ import java.util.Date;
import org.springframework.stereotype.Component;
/**
*
* @author admin
*
*/
@Component
public class EasyNews implements Serializable {
......@@ -54,7 +59,6 @@ public class EasyNews implements Serializable {
this.pt = pt;
}
@Override
public String toString() {
return "EasyNews [title=" + title + ", source=" + source + ", time=" + time + ", pt=" + pt + "]";
......
......@@ -2,113 +2,145 @@ package com.zhiwei.manage.bean;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.springframework.stereotype.Component;
/**
* 字段缺失类
*
* @author admin
*
*/
@Component
public class FieldIntegerity implements Serializable{
public class FieldIntegerity implements Serializable {
private String templateId;
private String tempName;// 模板名
private String field;//检测的字段
private String field;// 检测的字段
private double fieldIntegrityRate;// 字段缺失率
private int fieldInterval;// 字段缺失率统计间隔
private int testCount;// 测试需要多少条数据
private String pt;//渠道
private String host;//地址
private int port;//端口
private String collection;//表名
private String dBName;//数据库名
private String pt;// 渠道
private String host;// 地址
private int port;// 端口
private String collection;// 表名
private String dBName;// 数据库名
private boolean startNow;
private Date nextRun;
private String spyderInfoId;
public String getSpyderInfoId() {
return spyderInfoId;
}
public void setSpyderInfoId(String spyderInfoId) {
this.spyderInfoId = spyderInfoId;
}
public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}
public String getTempName() {
return tempName;
}
public void setTempName(String tempName) {
this.tempName = tempName;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public double getFieldIntegrityRate() {
return fieldIntegrityRate;
}
public void setFieldIntegrityRate(double fieldIntegrityRate) {
this.fieldIntegrityRate = fieldIntegrityRate;
}
public int getFieldInterval() {
return fieldInterval;
}
public void setFieldInterval(int fieldInterval) {
this.fieldInterval = fieldInterval;
}
public String getPt() {
return pt;
}
public void setPt(String pt) {
this.pt = pt;
}
public String getHost() {
return host;
}
public void setHost(String host) {
this.host = host;
}
public int getPort() {
return port;
}
public void setPort(int port) {
this.port = port;
}
public String getCollection() {
return collection;
}
public void setCollection(String collection) {
this.collection = collection;
}
public String getdBName() {
return dBName;
}
public void setdBName(String dBName) {
this.dBName = dBName;
}
public boolean isStartNow() {
return startNow;
}
public void setStartNow(boolean startNow) {
this.startNow = startNow;
}
public Date getNextRun() {
return nextRun;
}
public void setNextRun(Date nextRun) {
this.nextRun = nextRun;
}
public int getTestCount() {
return testCount;
}
public void setTestCount(int testCount) {
this.testCount = testCount;
}
@Override
public String toString() {
return "FieldIntegerity [templateId=" + templateId + ", tempName=" + tempName + ", field=" + field
......@@ -116,7 +148,5 @@ public class FieldIntegerity implements Serializable{
+ testCount + ", pt=" + pt + ", host=" + host + ", port=" + port + ", collection=" + collection
+ ", dBName=" + dBName + ", startNow=" + startNow + ", nextRun=" + nextRun + "]";
}
}
......@@ -8,10 +8,15 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
/**
* 反馈信息类
*
* @author admin
*
*/
@Document(collection = "Message")
public class Message implements Serializable {
@Indexed
@Id
private String messageId;
......@@ -27,79 +32,103 @@ public class Message implements Serializable {
private String pt;
private String handleMsg;
private String errorType;
public String getErrorType() {
return errorType;
}
public void setErrorType(String errorType) {
this.errorType = errorType;
}
public String getHandleMsg() {
return handleMsg;
}
public void setHandleMsg(String handleMsg) {
this.handleMsg = handleMsg;
}
public String getPt() {
return pt;
}
public void setPt(String pt) {
this.pt = pt;
}
public String getMessageId() {
return messageId;
}
public void setMessageId(String messageId) {
this.messageId = messageId;
}
public String getTempName() {
return tempName;
}
public void setTempName(String tempName) {
this.tempName = tempName;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public String getErrorMsg() {
return errorMsg;
}
public void setErrorMsg(String errorMsg) {
this.errorMsg = errorMsg;
}
public int getTemplateLv() {
return templateLv;
}
public void setTemplateLv(int templateLv) {
this.templateLv = templateLv;
}
public String getTemplateCreator() {
return templateCreator;
}
public void setTemplateCreator(String templateCreator) {
this.templateCreator = templateCreator;
}
public boolean isHandle() {
return handle;
}
public void setHandle(boolean handle) {
this.handle = handle;
}
public Date getHandleDate() {
return handleDate;
}
public void setHandleDate(Date handleDate) {
this.handleDate = handleDate;
}
public String getHandler() {
return handler;
}
public void setHandler(String handler) {
this.handler = handler;
}
@Override
public String toString() {
return "Message [messageId=" + messageId + ", tempName=" + tempName + ", createDate=" + createDate
......
......@@ -4,11 +4,16 @@ import java.io.Serializable;
import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.stereotype.Component;
/**
* 新闻类
*
* @author admin
*
*/
@Component
public class News implements Serializable{
public class News implements Serializable {
@Id
private String id;
......@@ -22,80 +27,100 @@ public class News implements Serializable{
private long savetime;
private String spyderInfoId;
private String rsid;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public Date getTime() {
return time;
}
public void setTime(Date time) {
this.time = time;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPt() {
return pt;
}
public void setPt(String pt) {
this.pt = pt;
}
public long getSavetime() {
return savetime;
}
public void setSavetime(long savetime) {
this.savetime = savetime;
}
public String getSpyderInfoId() {
return spyderInfoId;
}
public void setSpyderInfoId(String spyderInfoId) {
this.spyderInfoId = spyderInfoId;
}
public String getRsid() {
return rsid;
}
public void setRsid(String rsid) {
this.rsid = rsid;
}
@Override
public String toString() {
return "News [id=" + id + ", url=" + url + ", title=" + title + ", content=" + content + ", time=" + time
+ ", source=" + source + ", type=" + type + ", pt=" + pt + ", savetime=" + savetime + ", spyderInfoId="
+ spyderInfoId + ", rsid=" + rsid + "]";
}
}
......@@ -3,48 +3,63 @@ package com.zhiwei.manage.bean;
import java.io.Serializable;
import java.util.List;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.stereotype.Component;
/**
* 分页类
*
* @author admin
*
*/
@Component
public class PageEty implements Serializable{
public class PageEty implements Serializable {
private int pageNo;
private int pageSize;
private List data;
private int dataCount;
private int pageCount;
public int getPageCount() {
return pageCount;
}
public void setPageCount(int pageCount) {
this.pageCount = pageCount;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
public int getDataCount() {
return dataCount;
}
public void setDataCount(int dataCount) {
this.dataCount = dataCount;
}
@Override
public String toString() {
return "PageEty [pageNo=" + pageNo + ", pageSize=" + pageSize + ", data=" + data + ", dataCount=" + dataCount
......@@ -53,7 +68,5 @@ public class PageEty implements Serializable{
+ ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString()
+ "]";
}
}
......@@ -8,10 +8,15 @@ import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
/**
* 用户类
*
* @author admin
*
*/
@Document(collection = "Person")
public class Person implements Serializable {
@Indexed
@Id
private String personId;
......
......@@ -5,6 +5,12 @@ import java.util.Date;
import org.springframework.stereotype.Component;
/**
* 网站连通测试
*
* @author admin
*
*/
@Component
public class PingUrl implements Serializable {
......
......@@ -6,10 +6,15 @@ import java.util.List;
import org.springframework.stereotype.Component;
/**
* 运行信息
*
* @author admin
*
*/
@Component
public class RunMsg implements Serializable {
private String templateId;
private String templateName;
private String runType;// 运行类型
......@@ -17,7 +22,7 @@ public class RunMsg implements Serializable {
private String errorMsg;
private Date nextRun;
private boolean runNow;
private String field;//查询字段
private String field;// 查询字段
private String value;
private double rate;
private List<String> fields;
......@@ -117,5 +122,4 @@ public class RunMsg implements Serializable {
+ ", field=" + field + ", value=" + value + ", rate=" + rate + ", fields=" + fields + "]";
}
}
......@@ -2,15 +2,18 @@ package com.zhiwei.manage.bean;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import org.springframework.context.annotation.ComponentScan.Filter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.stereotype.Component;
/**
* 检测模板
*
* @author admin
*
*/
@Component
@Document(collection = "Template")
public class Template implements Serializable {
......
......@@ -6,8 +6,15 @@ import java.util.Date;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.stereotype.Component;
/**
* 微博类
*
* @author admin
*
*/
@Component
public class Weibo implements Serializable{
public class Weibo implements Serializable {
@Id
private String id;
......@@ -26,7 +33,7 @@ public class Weibo implements Serializable{
@Field("weibo_img")
private String weiboImg;
private int vtype;
private int fensi;
private int fensi;
private int guanzhu;
private int weibo;
private String description;
......@@ -37,147 +44,189 @@ public class Weibo implements Serializable{
private Date ins;
private int isForward;
private int rstime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public int getMonth() {
return month;
}
public void setMonth(int month) {
this.month = month;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public int getRetweet_count() {
return retweet_count;
}
public void setRetweet_count(int retweet_count) {
this.retweet_count = retweet_count;
}
public int getReply_count() {
return reply_count;
}
public void setReply_count(int reply_count) {
this.reply_count = reply_count;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getImageUrl() {
return imageUrl;
}
public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}
public String getWeiboImg() {
return weiboImg;
}
public void setWeiboImg(String weiboImg) {
this.weiboImg = weiboImg;
}
public int getVtype() {
return vtype;
}
public void setVtype(int vtype) {
this.vtype = vtype;
}
public int getFensi() {
return fensi;
}
public void setFensi(int fensi) {
this.fensi = fensi;
}
public int getGuanzhu() {
return guanzhu;
}
public void setGuanzhu(int guanzhu) {
this.guanzhu = guanzhu;
}
public int getWeibo() {
return weibo;
}
public void setWeibo(int weibo) {
this.weibo = weibo;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPicUrls() {
return picUrls;
}
public void setPicUrls(String picUrls) {
this.picUrls = picUrls;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public Date getIns() {
return ins;
}
public void setIns(Date ins) {
this.ins = ins;
}
public int getIsForward() {
return isForward;
}
public void setIsForward(int isForward) {
this.isForward = isForward;
}
public int getRstime() {
return rstime;
}
public void setRstime(int rstime) {
this.rstime = rstime;
}
}
......@@ -8,22 +8,22 @@ public interface MessageDao {
public String insert(Message message);
public String update(Message message,String pt);
public String update(Message message, String pt);
public List<Message> findAll(int pageNo,int pageSize,String pt);
public List<Message> findAll(int pageNo, int pageSize, String pt);
public List<Message> findByTmpName(String templateName,int pageNo,int pageSize,String pt);
public List<Message> findByTmpName(String templateName, int pageNo, int pageSize, String pt);
public boolean delete(List<String> MessageId, String pt);
public boolean delete(List<String> MessageId,String pt);
public int allCount(String pt);
public int findByTmpCount(String templateName,String pt);
public List<Message> findByHandle(int pageNo,int pageSize,boolean handle,String tempName,String pt);
public int findByHandleCount(int pageNo,int pageSize,boolean handle,String tempName,String pt);
public Message findMsg(String tempName,String errorType);
public int findByTmpCount(String templateName, String pt);
public List<Message> findByHandle(int pageNo, int pageSize, boolean handle, String tempName, String pt);
public int findByHandleCount(int pageNo, int pageSize, boolean handle, String tempName, String pt);
public Message findMsg(String tempName, String errorType);
}
......@@ -2,7 +2,9 @@ package com.zhiwei.manage.handle;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.annotation.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
......@@ -10,6 +12,12 @@ import org.springframework.stereotype.Service;
import com.zhiwei.manage.bean.ServerBean;
/**
* 初始化
*
* @author admin
*
*/
@Service("firstRun")
public class DbDepot {
......@@ -24,6 +32,5 @@ public class DbDepot {
log.info("数据连接map初始化");
esClients = new ConcurrentHashMap<String, Object>();
serverBeans = new ConcurrentHashMap<String, ServerBean>();
System.out.println("连接初始化成功");
}
}
......@@ -15,19 +15,25 @@ import org.springframework.stereotype.Component;
import com.zhiwei.manage.bean.NewsDelayed;
import com.zhiwei.manage.util.Tools;
/**
* 延时检测线程
*
* @author admin
*
*/
@Component
public class DelayedThread extends Thread {
private static final Log log=LogFactory.getLog(DelayedThread.class);
private static final Log log = LogFactory.getLog(DelayedThread.class);
private static boolean isrun = true;
public static Map<String, NewsDelayed> runMap = new ConcurrentHashMap<String, NewsDelayed>();
public static Queue<NewsDelayed> queue=new LinkedBlockingQueue<NewsDelayed>(500);
public static Queue<NewsDelayed> queue = new LinkedBlockingQueue<NewsDelayed>(500);
public DelayedThread(){
public DelayedThread() {
this.start();
}
public void stopMe() {
isrun = false;
}
......@@ -41,7 +47,7 @@ public class DelayedThread extends Thread {
String key = it.next();
NewsDelayed run = runMap.get(key);
Calendar cal = Calendar.getInstance();
if (run.getNextRun().before(cal.getTime())&&!run.isStartNow()) {
if (run.getNextRun().before(cal.getTime()) && !run.isStartNow()) {
queue.offer(run);
cal.add(Calendar.HOUR, run.getDelayedInterval());
run.setNextRun(cal.getTime());
......
......@@ -17,6 +17,12 @@ import org.springframework.stereotype.Component;
import com.zhiwei.manage.bean.FieldIntegerity;
import com.zhiwei.manage.util.Tools;
/**
* 字段检测线程
*
* @author admin
*
*/
@Component
public class FieldThread extends Thread {
......@@ -26,10 +32,10 @@ public class FieldThread extends Thread {
private static final Log log = LogFactory.getLog(FieldThread.class);
private static Lock fieldLock = new ReentrantLock();
public FieldThread(){
public FieldThread() {
this.start();
}
public void stopMe() {
isrun = false;
}
......
package com.zhiwei.manage.handle;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
......@@ -34,6 +35,12 @@ import com.zhiwei.manage.util.ESUtil;
import com.zhiwei.manage.util.SendMailUtil;
import com.zhiwei.manage.util.TimeUtil;
/**
* 主要执行线程
*
* @author admin
*
*/
@Component
public class MainThread extends Thread {
......@@ -197,21 +204,24 @@ public class MainThread extends Thread {
dataService.insert(data);
log.info(sdf.format(start.getTime()) + "|" + chan.getPt() + "|入库");
count = es.getCountByPt(inTime.getTime(), end.getTime(), chan.getPt(), chan.getValue(), ser);// 小时的数据量
if (counts.get(chan.getPt()) != null)
if (count < counts.get(chan.getPt())) {
Messages m = new Messages();
m.setTitle("渠道低数据量预警{" + chan.getPt() + "}");
m.setContent("1小时内的数据量为:" + count);
m.setDate(sdf.format(start.getTime()));
for (String mail : Config.getVal("count_mail").split(",")) {
SendMailUtil.sendMessage(mail, m);
if (start.get(Calendar.HOUR_OF_DAY) > 6)
if (counts.get(chan.getPt()) != null)
if (count < counts.get(chan.getPt())) {
Messages m = new Messages();
m.setTitle("渠道低数据量预警{" + chan.getPt() + "}");
m.setContent("1小时内的数据量为:" + count);
m.setDate(sdf.format(start.getTime()));
for (String mail : Config.getVal("count_mail").split(",")) {
SendMailUtil.sendMessage(mail, m);
}
}
}
} catch (Exception e) {
log.error(chan.getPt() + "入库出错,错误信息{}", e);
}
}
Set<String> keys = allTmp.keySet();
List<Message> needRemoveWm = new ArrayList<>();
List<Message> needRemovePm = new ArrayList<>();
for (Iterator<String> it = keys.iterator(); it.hasNext();) {
String key = it.next();
Template tmp = allTmp.get(key);
......@@ -239,6 +249,15 @@ public class MainThread extends Thread {
msg.setPt(pt);
msg.setTemplateLv(1);
messageService.insert(msg);
} else {
Message msg = messageService.findMsg(tmp.getTempName(), null);
if (msg != null) {
if (msg.getPt().equals("网媒")) {
needRemoveWm.add(msg);
} else {
needRemovePm.add(msg);
}
}
}
}
} catch (Exception e) {
......
......@@ -17,6 +17,12 @@ import org.springframework.stereotype.Component;
import com.zhiwei.manage.bean.PingUrl;
import com.zhiwei.manage.util.Tools;
/**
* 连通性线程
*
* @author admin
*
*/
@Component
public class PingThread extends Thread {
......
......@@ -7,10 +7,16 @@ import org.springframework.stereotype.Component;
import com.zhiwei.manage.util.ThreadPool;
import com.zhiwei.manage.util.Tools;
/**
* 队列线程
*
* @author admin
*
*/
@Component
public class QueueTask extends Thread {
private static final Log log=LogFactory.getLog(QueueTask.class);
private static final Log log = LogFactory.getLog(QueueTask.class);
private ThreadPool t = ThreadPool.getThreadPool(30);
private static boolean isRun = true;
......@@ -26,17 +32,17 @@ public class QueueTask extends Thread {
public void run() {
log.info("队列线程启动");
while (isRun) {
if (FieldThread.queue.size() > 0 ) {
if (FieldThread.queue.size() > 0) {
t.execute(new Task(FieldThread.queue.poll()));
} else {
Tools.sleep(1000);
}
if (PingThread.queue.size() > 0 ) {
if (PingThread.queue.size() > 0) {
t.execute(new Task(PingThread.queue.poll()));
} else {
Tools.sleep(1000);
}
if (DelayedThread.queue.size() > 0 ) {
if (DelayedThread.queue.size() > 0) {
t.execute(new Task(DelayedThread.queue.poll()));
} else {
Tools.sleep(1000);
......
......@@ -23,7 +23,7 @@ import com.zhiwei.manage.service.MessageService;
import com.zhiwei.manage.service.NewsService;
/**
* 任务执行
* 任务执行线程
*
* @author admin
*
......@@ -207,7 +207,7 @@ public class Task implements Runnable {
List<Map<String, Object>> list = newsService.findNews(delayed.getHost(), delayed.getPort(),
delayed.getdBName(), delayed.getCollection(), delayed.getTestCount(), delayed.getSpyderInfoId(),
delayed.getPt());
log.info("size"+list.size());
log.info("size" + list.size());
long sum = 0;
if (list.size() == 0) {
Template tp = MainThread.mainMap.get(delayed.getTemplateId());
......
......@@ -9,15 +9,15 @@ public interface MessageService {
public void insert(Message message);
public String update(Message message,String pt);
public String update(Message message, String pt);
public PageEty findAll(int pageNo,int pageSize,String pt);
public PageEty findAll(int pageNo, int pageSize, String pt);
public PageEty findByTmpName(String templateName,int pageNo,int pageSize,String pt);
public PageEty findByTmpName(String templateName, int pageNo, int pageSize, String pt);
public boolean delete(List<String> MessageId,String pt);
public PageEty findByHandle(int pageNo,int pageSize,boolean handle,String tempName,String pt);
public Message findMsg(String tempName,String errorType);
public boolean delete(List<String> MessageId, String pt);
public PageEty findByHandle(int pageNo, int pageSize, boolean handle, String tempName, String pt);
public Message findMsg(String tempName, String errorType);
}
......@@ -27,6 +27,12 @@ import com.zhiwei.manage.service.DataService;
import com.zhiwei.manage.service.ServerService;
import com.zhiwei.manage.util.Tools;
/**
* 数据控制
*
* @author admin
*
*/
@Controller
public class DataController {
......@@ -37,6 +43,13 @@ public class DataController {
@Autowired
private ServerService serverService;
/**
* 获取数据
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/getData", produces = "application/json;charset=utf-8")
@ResponseBody
public String getData(HttpServletRequest request, HttpServletResponse response) {
......@@ -46,6 +59,14 @@ public class DataController {
return JSON.toJSONString(list);
}
/**
* 根据;来源获取数据
*
* @param request
* @param response
* @param map
* @return
*/
@RequestMapping(value = "/getDataBySource", produces = "application/json;charset=utf-8")
@ResponseBody
public String getDataBySource(HttpServletRequest request, HttpServletResponse response,
......@@ -61,6 +82,15 @@ public class DataController {
return JSON.toJSONString(list);
}
/**
* 根据对应字段获取数据
*
* @param request
* @param response
* @param map
* @return
* @throws UnsupportedEncodingException
*/
@RequestMapping(value = "/getDataByTempName", produces = "application/json;charset=utf-8")
@ResponseBody
public String getDataByTempName(HttpServletRequest request, HttpServletResponse response,
......@@ -114,6 +144,12 @@ public class DataController {
}
}
/**
* 获取所有的数据
*
* @param map
* @return
*/
@RequestMapping(value = "/getDataAll", produces = "application/json;charset=utf-8")
@ResponseBody
public String getAllData(@RequestBody Map<String, Object> map) {
......@@ -153,12 +189,18 @@ public class DataController {
return JSON.toJSONString(result);
}
} catch (Exception e) {
log.error("处理错误,错误信息{}",e);
log.error("处理错误,错误信息{}", e);
JsonResult result = new JsonResult(false, 500, e.getMessage(), "");
return JSON.toJSONString(result);
}
}
/**
* 根据来源获取数据
*
* @param map
* @return
*/
@RequestMapping(value = "/getDayDataByChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String getDayDataByChannel(@RequestBody Map<String, Object> map) {
......@@ -179,12 +221,19 @@ public class DataController {
JsonResult result = new JsonResult(true, 200, "请求成功", datas);
return JSON.toJSONString(result);
} catch (Exception e) {
log.error("处理错误,错误信息{}",e);
log.error("处理错误,错误信息{}", e);
JsonResult result = new JsonResult(false, 500, e.getMessage(), "");
return JSON.toJSONString(result);
}
}
/**
* 根据来源名获取
*
* @param map
* @param req
* @return
*/
@RequestMapping(value = "/getSource", produces = "application/json;charset=utf-8")
@ResponseBody
public String getSource(@RequestBody Map<String, Object> map, HttpServletRequest req) {
......
......@@ -15,6 +15,12 @@ import com.zhiwei.manage.bean.JsonResult;
import com.zhiwei.manage.bean.PageEty;
import com.zhiwei.manage.service.FieldBeanService;
/**
* 字段
*
* @author admin
*
*/
@Controller
public class FieldController {
......@@ -37,6 +43,12 @@ public class FieldController {
return JSON.toJSONString(result);
}
/**
* 更新字段表信息
*
* @param fieldBean
* @return
*/
@RequestMapping(value = "/updateFields", produces = "application/json;charset=utf-8")
@ResponseBody
public String updateField(@RequestBody FieldBean fieldBean) {
......@@ -45,16 +57,28 @@ public class FieldController {
return JSON.toJSONString(result);
}
/**
* 删除字段表
*
* @param map
* @return
*/
@RequestMapping(value = "/deleteFields", produces = "application/json;charset=utf-8")
@ResponseBody
public String deleteFields(@RequestBody Map<String, Object> map) {
List<String> id=(List<String>) map.get("id");
List<String> id = (List<String>) map.get("id");
System.out.println(id);
boolean b = fs.delete(id);
JsonResult result = new JsonResult(b, 200, b ? "删除成功" : "删除失败");
return JSON.toJSONString(result);
}
/**
* 新增字段信息
*
* @param fieldbean
* @return
*/
@RequestMapping(value = "/insertFields", produces = "application/json;charset=utf-8")
@ResponseBody
public String insertField(@RequestBody FieldBean fieldbean) {
......@@ -63,10 +87,16 @@ public class FieldController {
return JSON.toJSONString(result);
}
/**
* 获取所有的字段信息
*
* @param map
* @return
*/
@RequestMapping(value = "/getAllFields", produces = "application/json;charset=utf-8")
@ResponseBody
public String getAllFields(@RequestBody Map<String, Object> map) {
String pt=(String) map.get("pt");
String pt = (String) map.get("pt");
FieldBean field = fs.getFieldsByPt(pt);
String fields[] = null;
if (field != null) {
......
......@@ -16,12 +16,24 @@ import com.zhiwei.manage.bean.Message;
import com.zhiwei.manage.bean.PageEty;
import com.zhiwei.manage.service.MessageService;
/**
* 信息处理器
*
* @author admin
*
*/
@Controller
public class MessageConteoller {
@Autowired
private MessageService msgService;
/**
* 获取所有的信息
*
* @param map
* @return
*/
@RequestMapping(value = "/findAllMsg", produces = "application/json;charset=utf-8")
@ResponseBody
public String getAllMessage(@RequestBody Map<String, Object> map) {
......@@ -40,6 +52,12 @@ public class MessageConteoller {
}
}
/**
* 处理信息
*
* @param map
* @return
*/
@RequestMapping(value = "/handle", produces = "application/json;charset=utf-8")
@ResponseBody
public String handle(@RequestBody Map<String, Object> map) {
......@@ -55,6 +73,12 @@ public class MessageConteoller {
return JSON.toJSONString(result);
}
/**
* 删除信息
*
* @param map
* @return
*/
@RequestMapping(value = "/deleteMsg", produces = "application/json;charset=utf-8")
@ResponseBody
public String delete(@RequestBody Map<String, Object> map) {
......@@ -65,6 +89,12 @@ public class MessageConteoller {
return JSON.toJSONString(result);
}
/**
* 获取处理过的信息
*
* @param map
* @return
*/
@RequestMapping(value = "/findHandleMsg", produces = "application/json;charset=utf-8")
@ResponseBody
public String getNewMsg(@RequestBody Map<String, Object> map) {
......
......@@ -2,7 +2,6 @@ package com.zhiwei.manage.servlet;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
......@@ -14,7 +13,6 @@ import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
......@@ -23,12 +21,26 @@ import com.zhiwei.manage.bean.PageEty;
import com.zhiwei.manage.bean.Person;
import com.zhiwei.manage.service.PersonService;
/**
* 个人控制
*
* @author admin
*
*/
@Controller
public class PersonController {
@Resource
private PersonService personService;
/**
* 登录
*
* @param req
* @param res
* @param map
* @return
*/
@RequestMapping(value = "/login", produces = "application/json;charset=utf-8")
@ResponseBody
public String login(HttpServletRequest req, HttpServletResponse res, @RequestBody Map<String, Object> map) {
......@@ -38,7 +50,7 @@ public class PersonController {
if (p != null) {
Cookie cookie;
try {
username=URLEncoder.encode(username, "utf-8");
username = URLEncoder.encode(username, "utf-8");
cookie = new Cookie("username", username);
res.addCookie(cookie);
cookie.setMaxAge(1000 * 60 * 60);
......@@ -59,6 +71,14 @@ public class PersonController {
}
}
/**
* 登出
*
* @param req
* @param res
* @param map
* @return
*/
@RequestMapping(value = "/leave", produces = "application/json;charset=utf-8")
@ResponseBody
public String leave(HttpServletRequest req, HttpServletResponse res, @RequestBody Map<String, Object> map) {
......@@ -74,6 +94,13 @@ public class PersonController {
return JSON.toJSONString(result);
}
/**
* cookie获取
*
* @param req
* @param res
* @return
*/
@RequestMapping(value = "/getcookie", produces = "application/json;charset=utf-8")
@ResponseBody
public String getCookie(HttpServletRequest req, HttpServletResponse res) {
......@@ -85,6 +112,14 @@ public class PersonController {
return JSON.toJSONString(result);
}
/**
* 获取用户信息
*
* @param res
* @param req
* @param map
* @return
*/
@RequestMapping(value = "/getPerson", produces = "application/json;charset=utf-8")
@ResponseBody
public String getPersonByUser(HttpServletResponse res, HttpServletRequest req,
......@@ -104,6 +139,12 @@ public class PersonController {
}
}
/**
* 更新用户信息
*
* @param person
* @return
*/
@RequestMapping(value = "/updatePerson", produces = "application/json;charset=utf-8")
@ResponseBody
public String updatePerson(@RequestBody Person person) {
......@@ -112,6 +153,12 @@ public class PersonController {
return JSON.toJSONString(result);
}
/**
* 删除用户信息
*
* @param map
* @return
*/
@RequestMapping(value = "/deletePerson", produces = "application/json;charset=utf-8")
@ResponseBody
public String deletePerson(@RequestBody Map<String, Object> map) {
......@@ -121,6 +168,13 @@ public class PersonController {
return JSON.toJSONString(result);
}
/**
* 存储用户信息
*
* @param req
* @param person
* @return
*/
@RequestMapping(value = "/savePerson", produces = "application/json;charset=utf-8")
@ResponseBody
public String savePerson(HttpServletRequest req, @RequestBody Person person) {
......
......@@ -8,7 +8,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
......@@ -18,23 +17,41 @@ import com.zhiwei.manage.bean.PageEty;
import com.zhiwei.manage.bean.ServerBean;
import com.zhiwei.manage.service.ServerService;
/**
* 数据库等参数
*
* @author admin
*
*/
@Controller
public class ServerController {
@Autowired
private ServerService ss;
/**
* 分页获取所有库信息
*
* @param map
* @return
*/
@RequestMapping(value = "/getServer", produces = "application/json;charset=utf-8")
@ResponseBody
public String getServer(@RequestBody Map<String, Object> map) {
int pageNo=(int) map.get("pageNo");
int pageSize=(int) map.get("pageSize");
String dbName=(String) map.get("dbName");
int pageNo = (int) map.get("pageNo");
int pageSize = (int) map.get("pageSize");
String dbName = (String) map.get("dbName");
PageEty page = ss.findDb(pageNo, pageSize, dbName);
JsonResult result = new JsonResult(true, 200, "获取成功", page);
return JSON.toJSONString(result);
}
/**
* 更新库信息
*
* @param serverBean
* @return
*/
@RequestMapping(value = "/updateServer", produces = "application/json;charset=utf-8")
@ResponseBody
public String updateServer(@RequestBody ServerBean serverBean) {
......@@ -43,16 +60,27 @@ public class ServerController {
return JSON.toJSONString(result);
}
/**
* 删除库信息
*
* @param map
* @return
*/
@RequestMapping(value = "/deleteServer", produces = "application/json;charset=utf-8")
@ResponseBody
public String deleteServer(@RequestBody Map<String, Object> map) {
List<String> serverid=(List<String>) map.get("serverid");
List<String> serverid = (List<String>) map.get("serverid");
boolean b = ss.delete(serverid);
JsonResult result = new JsonResult(true, 200, serverid+(b ? "删除成功" : "删除失败"));
JsonResult result = new JsonResult(true, 200, serverid + (b ? "删除成功" : "删除失败"));
return JSON.toJSONString(result);
}
/**
* 插入库信息
*
* @param serverBean
* @return
*/
@RequestMapping(value = "/insertServer", produces = "application/json;charset=utf-8")
@ResponseBody
public String insertServer(@RequestBody ServerBean serverBean) {
......@@ -63,96 +91,125 @@ public class ServerController {
/**
* 获取所有的渠道信息
*
* @return
*/
@RequestMapping(value = "/getChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String getChannel(@RequestBody Map<String, Object> map){
int pageNo=(int) map.get("pageNo");
int pageSize=(int) map.get("pageSize");
PageEty page=ss.findChannel(pageNo, pageSize);
JsonResult result=new JsonResult(true, 200, "获取成功",page);
public String getChannel(@RequestBody Map<String, Object> map) {
int pageNo = (int) map.get("pageNo");
int pageSize = (int) map.get("pageSize");
PageEty page = ss.findChannel(pageNo, pageSize);
JsonResult result = new JsonResult(true, 200, "获取成功", page);
return JSON.toJSONString(result);
}
/**
* 更改平台
*
* @param map
* @return
*/
@RequestMapping(value = "/changePt", produces = "application/json;charset=utf-8")
@ResponseBody
public String changePt(@RequestBody Map<String, Object> map) {
String pt=(String) map.get("pt");
String pt = (String) map.get("pt");
ss.findPt(pt);
JsonResult result = new JsonResult(true, 200, "源改变成功");
return JSON.toJSONString(result);
}
/**
* 插入渠道信息
*
* @param channel
* @return
*/
@RequestMapping(value = "/insertChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String insertChannel(@RequestBody Channel channel){
public String insertChannel(@RequestBody Channel channel) {
ss.insertChannels(channel);
JsonResult result=new JsonResult(true, 200, "添加成功");
JsonResult result = new JsonResult(true, 200, "添加成功");
return JSON.toJSONString(result);
}
/**
* 更新渠道信息
*
* @param channel
* @return
*/
@RequestMapping(value = "/updateChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String updateChannel(@RequestBody Channel channel){
boolean b=ss.updateChannel(channel);
JsonResult result=new JsonResult(b, 200, b?"修改成功":"修改失败");
public String updateChannel(@RequestBody Channel channel) {
boolean b = ss.updateChannel(channel);
JsonResult result = new JsonResult(b, 200, b ? "修改成功" : "修改失败");
return JSON.toJSONString(result);
}
/**
* 删除渠道信息
*
* @param map
* @return
*/
@RequestMapping(value = "/deleteChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String deleteChannel(@RequestBody Map<String, Object> map) {
List<String> id=(List<String>) map.get("id");
boolean b=ss.deleteChannel(id);
JsonResult result=new JsonResult(b, 200, id+(b?"删除成功":"删除失败"));
List<String> id = (List<String>) map.get("id");
boolean b = ss.deleteChannel(id);
JsonResult result = new JsonResult(b, 200, id + (b ? "删除成功" : "删除失败"));
return JSON.toJSONString(result);
}
/**
* 用于展示渠道
*
* @return
*/
@RequestMapping(value="/getShowChannel",produces="application/json;charset=utf-8")
@RequestMapping(value = "/getShowChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String findAllChannel(){
List<Channel> list=ss.findDisChannel();
if(list==null||list.size()==0){
Channel c=new Channel();
public String findAllChannel() {
List<Channel> list = ss.findDisChannel();
if (list == null || list.size() == 0) {
Channel c = new Channel();
c.setId("1");
c.setPt("网媒");
c.setValue("wangmei");
list.add(c);
}
JsonResult result=new JsonResult(true, 200, "获取成功",list);
JsonResult result = new JsonResult(true, 200, "获取成功", list);
System.out.println(result);
return JSON.toJSONString(result);
}
/**
* 用于给用户选择渠道
*
* @return
*/
@RequestMapping(value="/getDisChannel",produces="application/json;charset=utf-8")
@RequestMapping(value = "/getDisChannel", produces = "application/json;charset=utf-8")
@ResponseBody
public String findDisChannel(){
List<String> list=ss.findDisChan();
JsonResult result=new JsonResult(true, 200, "获取成功",list);
public String findDisChannel() {
List<String> list = ss.findDisChan();
JsonResult result = new JsonResult(true, 200, "获取成功", list);
return JSON.toJSONString(result);
}
@RequestMapping(value="/getParam",produces="application/json;charset=utf-8")
/**
* 获取参数
*
* @return
*/
@RequestMapping(value = "/getParam", produces = "application/json;charset=utf-8")
@ResponseBody
public String getParam(){
List<String> list=new ArrayList<>();
public String getParam() {
List<String> list = new ArrayList<>();
list.add("msg");
list.add("temp");
list.add("data");
JsonResult result=new JsonResult(true, 200, "获取成功",list);
JsonResult result = new JsonResult(true, 200, "获取成功", list);
return JSON.toJSONString(result);
}
}
......@@ -2,7 +2,6 @@ package com.zhiwei.manage.servlet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
......@@ -11,11 +10,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.mysql.jdbc.log.LogFactory;
import com.zhiwei.manage.bean.FieldBean;
import com.zhiwei.manage.bean.JsonResult;
import com.zhiwei.manage.bean.PageEty;
......@@ -24,25 +21,42 @@ import com.zhiwei.manage.handle.MainThread;
import com.zhiwei.manage.service.FieldBeanService;
import com.zhiwei.manage.service.TemplateService;
/**
* 模板控制
*
* @author admin
*
*/
@Controller
public class TemplateController {
private static final Log log=org.apache.commons.logging.LogFactory.getLog(TemplateController.class);
private static final Log log = org.apache.commons.logging.LogFactory.getLog(TemplateController.class);
@Autowired
private TemplateService ts;
@Autowired
private FieldBeanService fb;
/**
* 一键启动
*
* @return
*/
@RequestMapping(value = "/startAll", produces = "application/json;charset=utf-8")
@ResponseBody
public String startAll() {
List<Template> tpList=ts.findAll();
for(Template t:tpList) {
List<Template> tpList = ts.findAll();
for (Template t : tpList) {
MainThread.pushMap(t.getTemplateId());
}
JsonResult result = new JsonResult(true, 200, "启动成功");
return JSON.toJSONString(result);
}
/**
* 一键停止
*
* @return
*/
@RequestMapping(value = "/stopAll", produces = "application/json;charset=utf-8")
@ResponseBody
public String stopAll() {
......@@ -50,7 +64,13 @@ public class TemplateController {
JsonResult result = new JsonResult(true, 200, "停止成功");
return JSON.toJSONString(result);
}
/**
* 保存模板
*
* @param template
* @return
*/
@RequestMapping(value = "/saveTmp", produces = "application/json;charset=utf-8")
@ResponseBody
public String saveTmp(@RequestBody Template template) {
......@@ -64,12 +84,19 @@ public class TemplateController {
return JSON.toJSONString(result);
}
/**
* 更新模板
*
* @param template
* @param request
* @return
*/
@RequestMapping(value = "/updateTmp", produces = "application/json;charset=utf-8")
@ResponseBody
public String updateTmp(@RequestBody Template template, HttpServletRequest request) {
JsonResult result = null;
if (MainThread.mainMap.get(template.getTemplateId()) != null) {
result=new JsonResult(true, 200, "修改失败");
result = new JsonResult(true, 200, "修改失败");
} else {
if (ts.update(template)) {
result = new JsonResult(true, 200, "修改成功");
......@@ -80,6 +107,12 @@ public class TemplateController {
return JSON.toJSONString(result);
}
/**
* 删除模板
*
* @param map
* @return
*/
@RequestMapping(value = "/deleteTmp", produces = "application/json;charset=utf-8")
@ResponseBody
public String deleteTmp(@RequestBody Map<String, Object> map) {
......@@ -96,6 +129,12 @@ public class TemplateController {
return JSON.toJSONString(result);
}
/**
* 获取所有的模板信息
*
* @param map
* @return
*/
@RequestMapping(value = "/findAllTmp", produces = "application/json;charset=utf-8")
@ResponseBody
public String findAll(@RequestBody Map<String, Object> map) {
......@@ -119,6 +158,12 @@ public class TemplateController {
}
}
/**
* 开启模板根据id
*
* @param map
* @return
*/
@RequestMapping(value = "/startTmp", produces = "application/json;charset=utf-8")
@ResponseBody
public String startTmp(@RequestBody Map<String, Object> map) {
......@@ -133,6 +178,12 @@ public class TemplateController {
}
}
/**
* 停止模板
*
* @param map
* @return
*/
@RequestMapping(value = "/stopTmp", produces = "application/json;charset=utf-8")
@ResponseBody
public String stopTmp(@RequestBody Map<String, Object> map) {
......@@ -147,6 +198,12 @@ public class TemplateController {
}
}
/**
* 获取字段信息
*
* @param map
* @return
*/
@RequestMapping(value = "/getField", produces = "application/json;charset=utf-8")
@ResponseBody
public String getField(@RequestBody Map<String, Object> map) {
......
package com.zhiwei.manage.util;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
/**
* aes加密解析
*
* @author
* @version V1.0
* @Description
* @date 2017-12-28 14:26
**/
public class AESUtils {
private AESUtils() {
}
private AESUtils() {
}
/**
* 加密
*
* @param secret 密钥
* @param value 待加密的字符串
* @return 加密后的字符串
*/
public static String encrypt(String secret, String value) {
SecretKeySpec keySpec = getKey(secret);
IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes());
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes("UTF-8"));
return parseByte2HexStr(encrypted);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 加密
*
* @param secret
* 密钥
* @param value
* 待加密的字符串
* @return 加密后的字符串
*/
public static String encrypt(String secret, String value) {
SecretKeySpec keySpec = getKey(secret);
IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes());
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, keySpec, iv);
byte[] encrypted = cipher.doFinal(value.getBytes("UTF-8"));
return parseByte2HexStr(encrypted);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
AESUtils ac = new AESUtils();
String jsm = AESUtils.encrypt("wechat", "shenjinzhu");
System.out.println(jsm);
String jm = AESUtils.decrypt("wechat", jsm);
System.out.println(jm);
}
public static void main(String[] args) {
AESUtils ac=new AESUtils();
String jsm=AESUtils.encrypt("wechat", "shenjinzhu");
System.out.println(jsm);
String jm=AESUtils.decrypt("wechat", jsm);
System.out.println(jm);
/**
* 解密
*
* @param secret
* 密钥
* @param value
* 待解密字符串
* @return 解密后的字符串
*/
public static String decrypt(String secret, String value) {
SecretKeySpec keySpec = getKey(secret);
IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes());
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec, iv);
byte[] encrypted1 = parseHexStr2Byte(value);
byte[] original = cipher.doFinal(encrypted1);
return new String(original, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 解密
*
* @param secret 密钥
* @param value 待解密字符串
* @return 解密后的字符串
*/
public static String decrypt(String secret, String value) {
SecretKeySpec keySpec = getKey(secret);
IvParameterSpec iv = new IvParameterSpec("0102030405060708".getBytes());
try {
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, keySpec, iv);
byte[] encrypted1 = parseHexStr2Byte(value);
byte[] original = cipher.doFinal(encrypted1);
return new String(original, "UTF-8");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* 生成加密的密钥,保证长度为16位
*
* @param secret 用户的密钥
* @return 生成的密钥
*/
private static SecretKeySpec getKey(String secret) {
byte[] bytes;
try {
bytes = secret.getBytes("UTF-8");
return new SecretKeySpec(Arrays.copyOf(bytes, 16), "AES");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
/**
* 生成加密的密钥,保证长度为16位
*
* @param secret
* 用户的密钥
* @return 生成的密钥
*/
private static SecretKeySpec getKey(String secret) {
byte[] bytes;
try {
bytes = secret.getBytes("UTF-8");
return new SecretKeySpec(Arrays.copyOf(bytes, 16), "AES");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
/**
* 将二进制转换成16进制
*
* @param buf
* @return
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 将二进制转换成16进制
*
* @param buf
* @return
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 将16进制转换为二进制
*
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2),
16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
/**
* 将16进制转换为二进制
*
* @param hexStr
* @return
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
}
......@@ -4,20 +4,27 @@ import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Properties;
/**
* 配置读取
*
* @author admin
*
*/
public class Config {
public static Properties p=new Properties();
public static Properties p = new Properties();
static {
String fileurl = Config.class.getClassLoader().getResource("mongo.properties").getPath();
p = new Properties();
try {
InputStreamReader in = new InputStreamReader(new FileInputStream(fileurl),"utf-8");
InputStreamReader in = new InputStreamReader(new FileInputStream(fileurl), "utf-8");
p.load(in); /// 加载属性列表
in.close();
}catch(Exception e){
} catch (Exception e) {
}
}
public static String getVal(String key){
public static String getVal(String key) {
return p.getProperty(key);
}
}
......@@ -8,19 +8,25 @@ import org.apache.commons.logging.LogFactory;
import com.mysql.jdbc.Connection;
/**
* mysql链接
*
* @author admin
*
*/
public class MysqlConnection {
private static final Log log=LogFactory.getLog(MysqlConnection.class);
private static final Log log = LogFactory.getLog(MysqlConnection.class);
private String host;
private int port;
private String dbName;
public MysqlConnection(String host,Integer port,String dbName){
this.host=host;
this.port=port;
this.dbName=dbName;
public MysqlConnection(String host, Integer port, String dbName) {
this.host = host;
this.port = port;
this.dbName = dbName;
}
/**
* 需要登录的mysql连接
*
......@@ -41,6 +47,7 @@ public class MysqlConnection {
}
return con;
}
/**
* 无需登录的mysql连接
*
......
......@@ -3,139 +3,143 @@ package com.zhiwei.manage.util;
import java.util.LinkedList;
import java.util.List;
/**
* 自定义线程池
*
* @author admin
*
*/
public class ThreadPool {
// 线程池中默认线程的个数为30
private static int worker_num = 30;
private WorkThread[] workThrads;
private static volatile int finished_task = 0;
private List<Runnable> taskQueue = new LinkedList<Runnable>();
private static ThreadPool threadPool;
// 创建具有默认线程个数的线程池
private ThreadPool() {
this(30);
}
private ThreadPool(int worker_num) {
ThreadPool.worker_num = worker_num;
workThrads = new WorkThread[worker_num];
for (int i = 0; i < worker_num; i++) {
workThrads[i] = new WorkThread();
workThrads[i].start();// 开启线程池中的线程
}
}
//获得一个默认线程个数的线程池
public static ThreadPool getThreadPool() {
return getThreadPool(ThreadPool.worker_num);
}
// worker_num<=0创建默认的工作线程个数
public static ThreadPool getThreadPool(int worker_num1) {
if (worker_num1 <= 0)
worker_num1 = ThreadPool.worker_num;
if (threadPool == null)
threadPool = new ThreadPool(worker_num1);
return threadPool;
}
// 执行任务
public void execute(Runnable task) {
synchronized (taskQueue) {
taskQueue.add(task);
taskQueue.notify();
}
}
// 批量执行任务
public void execute(List<Runnable> task) {
synchronized (taskQueue) {
for (Runnable t : task)
taskQueue.add(t);
taskQueue.notify();
}
}
// 销毁线程池
public void destroy() {
while (!taskQueue.isEmpty()) {// 如果还有任务没执行完成,就先睡会吧
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
//工作线程停止工作,且置为null
for (int i = 0; i < worker_num; i++) {
workThrads[i].stopWorker();
workThrads[i] = null;
}
threadPool=null;
taskQueue.clear();// 清空任务队列
}
// 返回工作线程的个数
public int getWorkThreadNumber() {
return worker_num;
}
// 返回已完成任务的个数,这里的已完成是只出了任务队列的任务个数,可能该任务并没有实际执行完成
public int getFinishedTasknumber() {
return finished_task;
}
// 返回任务队列的长度,即还没处理的任务个数
public int getWaitTasknumber() {
return taskQueue.size();
}
// 覆盖toString方法,返回线程池信息:工作线程个数和已完成任务个数
@Override
public String toString() {
return "WorkThread number:" + worker_num + " finished task number:"
+ finished_task + " wait task number:" + getWaitTasknumber();
}
/**
* 内部类,工作线程
*/
private class WorkThread extends Thread {
// 该工作线程是否有效,用于结束该工作线程
private boolean isRunning = true;
/*
* 关键所在啊,如果任务队列不空,则取出任务执行,若任务队列空,则等待
*/
@Override
public void run() {
Runnable r = null;
while (isRunning) {// 注意,若线程无效则自然结束run方法,该线程就没用了
synchronized (taskQueue) {
while (isRunning && taskQueue.isEmpty()) {// 队列为空
try {
taskQueue.wait(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (!taskQueue.isEmpty())
r = taskQueue.remove(0);// 取出任务
}
if (r != null) {
r.run();// 执行任务
}
finished_task++;
r = null;
}
}
// 停止工作,让该线程自然执行完run方法,自然结束
public void stopWorker() {
isRunning = false;
}
}
// 线程池中默认线程的个数为30
private static int worker_num = 30;
private WorkThread[] workThrads;
private static volatile int finished_task = 0;
private List<Runnable> taskQueue = new LinkedList<Runnable>();
private static ThreadPool threadPool;
// 创建具有默认线程个数的线程池
private ThreadPool() {
this(30);
}
private ThreadPool(int worker_num) {
ThreadPool.worker_num = worker_num;
workThrads = new WorkThread[worker_num];
for (int i = 0; i < worker_num; i++) {
workThrads[i] = new WorkThread();
workThrads[i].start();// 开启线程池中的线程
}
}
// 获得一个默认线程个数的线程池
public static ThreadPool getThreadPool() {
return getThreadPool(ThreadPool.worker_num);
}
// worker_num<=0创建默认的工作线程个数
public static ThreadPool getThreadPool(int worker_num1) {
if (worker_num1 <= 0)
worker_num1 = ThreadPool.worker_num;
if (threadPool == null)
threadPool = new ThreadPool(worker_num1);
return threadPool;
}
// 执行任务
public void execute(Runnable task) {
synchronized (taskQueue) {
taskQueue.add(task);
taskQueue.notify();
}
}
// 批量执行任务
public void execute(List<Runnable> task) {
synchronized (taskQueue) {
for (Runnable t : task)
taskQueue.add(t);
taskQueue.notify();
}
}
// 销毁线程池
public void destroy() {
while (!taskQueue.isEmpty()) {// 如果还有任务没执行完成,就先睡会吧
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// 工作线程停止工作,且置为null
for (int i = 0; i < worker_num; i++) {
workThrads[i].stopWorker();
workThrads[i] = null;
}
threadPool = null;
taskQueue.clear();// 清空任务队列
}
// 返回工作线程的个数
public int getWorkThreadNumber() {
return worker_num;
}
// 返回已完成任务的个数,这里的已完成是只出了任务队列的任务个数,可能该任务并没有实际执行完成
public int getFinishedTasknumber() {
return finished_task;
}
// 返回任务队列的长度,即还没处理的任务个数
public int getWaitTasknumber() {
return taskQueue.size();
}
// 覆盖toString方法,返回线程池信息:工作线程个数和已完成任务个数
@Override
public String toString() {
return "WorkThread number:" + worker_num + " finished task number:" + finished_task + " wait task number:"
+ getWaitTasknumber();
}
/**
* 内部类,工作线程
*/
private class WorkThread extends Thread {
// 该工作线程是否有效,用于结束该工作线程
private boolean isRunning = true;
/*
* 关键所在啊,如果任务队列不空,则取出任务执行,若任务队列空,则等待
*/
@Override
public void run() {
Runnable r = null;
while (isRunning) {// 注意,若线程无效则自然结束run方法,该线程就没用了
synchronized (taskQueue) {
while (isRunning && taskQueue.isEmpty()) {// 队列为空
try {
taskQueue.wait(20);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
if (!taskQueue.isEmpty())
r = taskQueue.remove(0);// 取出任务
}
if (r != null) {
r.run();// 执行任务
}
finished_task++;
r = null;
}
}
// 停止工作,让该线程自然执行完run方法,自然结束
public void stopWorker() {
isRunning = false;
}
}
}
package com.zhiwei.manage.util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -21,11 +12,19 @@ import weixin.popular.bean.message.templatemessage.TemplateMessage;
import weixin.popular.bean.message.templatemessage.TemplateMessageItem;
import weixin.popular.bean.message.templatemessage.TemplateMessageResult;
/**
* 微信推送部分
*
* @author admin
*
*/
public class WechatPush {
private static final Logger log = LoggerFactory.getLogger(WechatPush.class);
/**
* 指定分组的的指定用户进行模板发送
*
* @param idNum
* 分组编号
* @param temp_id
......
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