generated from root/miduo_server
限时优先级公告
parent
69abb67c93
commit
bf8b754487
|
@ -1,6 +1,7 @@
|
||||||
package com.ljsd.controller;
|
package com.ljsd.controller;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import com.ljsd.pojo.NoticeInfo;
|
||||||
import com.ljsd.pojo.ResMsg;
|
import com.ljsd.pojo.ResMsg;
|
||||||
import com.ljsd.util.BaseGlobal;
|
import com.ljsd.util.BaseGlobal;
|
||||||
import com.ljsd.util.MD5Util;
|
import com.ljsd.util.MD5Util;
|
||||||
|
@ -13,9 +14,12 @@ import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 常驻 中 高优先级 同等优先级按最新发布的
|
||||||
|
*/
|
||||||
public class GetNoticeController extends HttpServlet {
|
public class GetNoticeController extends HttpServlet {
|
||||||
private static Gson gson = new Gson();
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
|
@ -39,16 +43,86 @@ public class GetNoticeController extends HttpServlet {
|
||||||
out.print(gson.toJson(resMsg));
|
out.print(gson.toJson(resMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
List<DBObject> notices = BaseGlobal.getInstance().mongoDBPool.findAll("notice_info");
|
||||||
|
|
||||||
|
|
||||||
|
NoticeInfo send = new NoticeInfo();
|
||||||
DBObject notice = BaseGlobal.getInstance().mongoDBPool.findOne("notice_info", "1");
|
DBObject notice = BaseGlobal.getInstance().mongoDBPool.findOne("notice_info", "1");
|
||||||
|
if(notice!=null){
|
||||||
|
Object content = notice.get("content");
|
||||||
|
Object title = notice.get("title");
|
||||||
|
send.setContent(content.toString());
|
||||||
|
send.setTitle(title.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Comparator<NoticeInfo> comparator = (o1, o2) -> {
|
||||||
|
if (o1.getStartTime() > o2.getStartTime()) {
|
||||||
|
return -1;
|
||||||
|
} else if (o1.getStartTime()==o2.getStartTime()) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
TreeSet<NoticeInfo> normalList = new TreeSet<>(comparator);
|
||||||
|
TreeSet<NoticeInfo> highList = new TreeSet<>(comparator);
|
||||||
|
|
||||||
|
Set<String> remove = new HashSet<>();
|
||||||
|
long localtime = System.currentTimeMillis() / 1000;
|
||||||
|
for (DBObject dbObject:notices) {
|
||||||
|
String id = dbObject.get("_id").toString();
|
||||||
|
if(id.equals("1"))
|
||||||
|
continue;
|
||||||
|
try {
|
||||||
|
NoticeInfo noticeInfo = new NoticeInfo();
|
||||||
|
noticeInfo.set_id(id);
|
||||||
|
Object content = dbObject.get("content");
|
||||||
|
Object title = dbObject.get("title");
|
||||||
|
Object start_time = dbObject.get("start_time");
|
||||||
|
Object end_time = dbObject.get("end_time");
|
||||||
|
noticeInfo.setContent(content.toString());
|
||||||
|
noticeInfo.setTitle(title.toString());
|
||||||
|
|
||||||
|
|
||||||
|
long start = (long)start_time/1000;
|
||||||
|
long end = (long)end_time/1000;
|
||||||
|
if (start > localtime) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
//移除当前时间以前的
|
||||||
|
if (end < localtime) {
|
||||||
|
remove.add(id);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int leve = (int)dbObject.get("leve");
|
||||||
|
if(leve==1)
|
||||||
|
normalList.add(noticeInfo);
|
||||||
|
else if(leve==2){
|
||||||
|
highList.add(noticeInfo);
|
||||||
|
}
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(highList.size()!=0){
|
||||||
|
send = highList.last();
|
||||||
|
}else {
|
||||||
|
if(normalList.size()!=0){
|
||||||
|
send = normalList.last();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
resMsg.setCode(0);
|
resMsg.setCode(0);
|
||||||
resMsg.setCode(0);
|
resMsg.setCode(0);
|
||||||
resMsg.setMsg("");
|
resMsg.setMsg("");
|
||||||
if(notice!=null){
|
|
||||||
|
if(send!=null){
|
||||||
Map<String,String> parms = new HashMap<>();
|
Map<String,String> parms = new HashMap<>();
|
||||||
Object content = notice.get("content");
|
parms.put("title",send.getTitle());
|
||||||
Object title = notice.get("title");
|
parms.put("content",send.getContent());
|
||||||
parms.put("title",title.toString());
|
|
||||||
parms.put("content",content.toString());
|
|
||||||
resMsg.setParms(parms);
|
resMsg.setParms(parms);
|
||||||
}
|
}
|
||||||
out.print(gson.toJson(resMsg));
|
out.print(gson.toJson(resMsg));
|
||||||
|
@ -56,4 +130,7 @@ public class GetNoticeController extends HttpServlet {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,6 +59,10 @@ public class GetUserController extends HttpServlet {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String admin = request.getParameter("admin"); //平台类型
|
String admin = request.getParameter("admin"); //平台类型
|
||||||
|
|
||||||
|
String gid = request.getParameter("gid"); //gid
|
||||||
|
String pid = request.getParameter("pid"); //pid
|
||||||
|
|
||||||
/*if (StringUtils.checkIsEmpty(admin)) {
|
/*if (StringUtils.checkIsEmpty(admin)) {
|
||||||
response.sendError(400, "platform is empety");
|
response.sendError(400, "platform is empety");
|
||||||
return;
|
return;
|
||||||
|
@ -86,6 +90,14 @@ public class GetUserController extends HttpServlet {
|
||||||
dbObject.put("openId", openId);
|
dbObject.put("openId", openId);
|
||||||
dbObject.put("serverId", serverId);
|
dbObject.put("serverId", serverId);
|
||||||
dbObject.put("platform", platform);
|
dbObject.put("platform", platform);
|
||||||
|
if (gid != null && !gid.isEmpty()) {
|
||||||
|
dbObject.put("gid", gid);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pid != null && !pid.isEmpty()) {
|
||||||
|
dbObject.put("pid", pid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int uid = 0;
|
int uid = 0;
|
||||||
List<DBObject> userInfos = BaseGlobal.getInstance().mongoDBPool.find(_COLLECTION_NAME, dbObject);
|
List<DBObject> userInfos = BaseGlobal.getInstance().mongoDBPool.find(_COLLECTION_NAME, dbObject);
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.ljsd.pojo;
|
||||||
|
|
||||||
|
|
||||||
|
import com.mongodb.DBObject;
|
||||||
|
import org.bson.BSONObject;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Administrator
|
||||||
|
* @date 2015/8/13
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class NoticeInfo {
|
||||||
|
|
||||||
|
|
||||||
|
private String _id;
|
||||||
|
private String content;
|
||||||
|
private String title;
|
||||||
|
private int leve;
|
||||||
|
private long startTime;
|
||||||
|
private long endTime;
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String get_id() {
|
||||||
|
return _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set_id(String _id) {
|
||||||
|
this._id = _id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLeve() {
|
||||||
|
return leve;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeve(int leve) {
|
||||||
|
this.leve = leve;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getStartTime() {
|
||||||
|
return startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStartTime(long startTime) {
|
||||||
|
this.startTime = startTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getEndTime() {
|
||||||
|
return endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEndTime(long endTime) {
|
||||||
|
this.endTime = endTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -41,6 +41,18 @@ public class MyMongoDBPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<DBObject> findAll(String collectionName) throws Exception {
|
||||||
|
DBCollection coll = db.getCollection(collectionName);
|
||||||
|
DBCursor cursor = coll.find();
|
||||||
|
List<DBObject> docs = new ArrayList<>();
|
||||||
|
|
||||||
|
while (cursor.hasNext()) {
|
||||||
|
DBObject doc = cursor.next();
|
||||||
|
docs.add(doc);
|
||||||
|
}
|
||||||
|
return docs;
|
||||||
|
}
|
||||||
|
|
||||||
public DBObject findOne(String collectionName, String id) throws Exception {
|
public DBObject findOne(String collectionName, String id) throws Exception {
|
||||||
return findOne2(collectionName, id);
|
return findOne2(collectionName, id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue