generated from root/miduo_server
Merge branch 'dh_dev_notice'
commit
59852153b1
|
@ -8,6 +8,7 @@ import com.ljsd.redis.RedisKey;
|
||||||
import com.ljsd.util.BaseGlobal;
|
import com.ljsd.util.BaseGlobal;
|
||||||
import com.ljsd.util.MD5Util;
|
import com.ljsd.util.MD5Util;
|
||||||
import com.ljsd.util.StringUtils;
|
import com.ljsd.util.StringUtils;
|
||||||
|
import com.ljsd.util.TimeUtil;
|
||||||
import com.mongodb.DBObject;
|
import com.mongodb.DBObject;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -26,14 +27,16 @@ public class GetNoticeController extends HttpServlet {
|
||||||
private static Gson gson = new Gson();
|
private static Gson gson = new Gson();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse response){
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setContentType("application/json; charset=utf-8");
|
response.setContentType("application/json; charset=utf-8");
|
||||||
String timestamp = req.getParameter("timestamp");
|
String timestamp = req.getParameter("timestamp");
|
||||||
String sign = req.getParameter("sign");
|
String sign = req.getParameter("sign");
|
||||||
|
String packageName = req.getParameter("packageName");
|
||||||
|
|
||||||
ResMsg resMsg = new ResMsg();
|
ResMsg resMsg = new ResMsg();
|
||||||
resMsg.setCode(1);
|
resMsg.setCode(1);
|
||||||
try (PrintWriter out = response.getWriter();) {
|
try (PrintWriter out = response.getWriter()) {
|
||||||
if (StringUtils.checkIsEmpty(timestamp) || StringUtils.checkIsEmpty(sign)) {
|
if (StringUtils.checkIsEmpty(timestamp) || StringUtils.checkIsEmpty(sign)) {
|
||||||
resMsg.setMsg("参数不能为空");
|
resMsg.setMsg("参数不能为空");
|
||||||
out.print(gson.toJson(resMsg));
|
out.print(gson.toJson(resMsg));
|
||||||
|
@ -45,70 +48,54 @@ public class GetNoticeController extends HttpServlet {
|
||||||
out.print(gson.toJson(resMsg));
|
out.print(gson.toJson(resMsg));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ("".equals(packageName) || packageName == null){
|
||||||
|
resMsg.setMsg("包名不能为空");
|
||||||
|
out.print(gson.toJson(resMsg));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, NoticeInfo> noticeInfoMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.NOTICE, "", NoticeInfo.class, -1, false);
|
Map<String, NoticeInfo> noticeInfoMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.NOTICE, "", NoticeInfo.class, -1, false);
|
||||||
|
|
||||||
NoticeInfo send = noticeInfoMap.get("1");
|
ArrayList<NoticeInfo> list = new ArrayList<>();
|
||||||
|
|
||||||
Comparator<NoticeInfo> comparator = (o1, o2) -> {
|
HashSet<String> remove = new HashSet<>();
|
||||||
if (o1.getStartTime() > o2.getStartTime()) {
|
for (NoticeInfo info : noticeInfoMap.values()) {
|
||||||
return -1;
|
// 获取时间
|
||||||
} else if (o1.getStartTime() == o2.getStartTime()) {
|
long now = TimeUtil.nowInt();
|
||||||
return 0;
|
long start = TimeUtil.timeStrToSecond(info.getStartTime());
|
||||||
} else {
|
long end = TimeUtil.timeStrToSecond(info.getEndTime());
|
||||||
return 1;
|
// 未开启公告
|
||||||
}
|
if (start > now){
|
||||||
};
|
|
||||||
TreeSet<NoticeInfo> normalList = new TreeSet<>(comparator);
|
|
||||||
TreeSet<NoticeInfo> highList = new TreeSet<>(comparator);
|
|
||||||
|
|
||||||
Set<String> remove = new HashSet<>();
|
|
||||||
long localtime = System.currentTimeMillis() / 1000;
|
|
||||||
for (NoticeInfo noticeInfo : noticeInfoMap.values()) {
|
|
||||||
if (noticeInfo.getLeve() == 0)
|
|
||||||
continue;
|
|
||||||
try {
|
|
||||||
|
|
||||||
long start = noticeInfo.getStartTime() / 1000;
|
|
||||||
long end = noticeInfo.getEndTime() / 1000;
|
|
||||||
if (start > localtime) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//移除当前时间以前的
|
// 已过期公告
|
||||||
if (end < localtime) {
|
if (now > end){
|
||||||
remove.add(noticeInfo.get_id());
|
remove.add(String.valueOf(info.getId()));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
// 包名不包含
|
||||||
|
if (!info.getPackageName().contains(packageName)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 最多展示十条
|
||||||
|
if (list.size() > 10){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// 需要展示得公告列表
|
||||||
|
list.add(info);
|
||||||
|
}
|
||||||
|
|
||||||
int leve =noticeInfo.getLeve();
|
// 删除过期公告
|
||||||
if (leve == 1)
|
for (String k : remove) {
|
||||||
normalList.add(noticeInfo);
|
BaseGlobal.getInstance().redisApp.hdel(RedisKey.NOTICE, "", k, false);
|
||||||
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.setList(list);
|
||||||
resMsg.setMsg("");
|
System.out.println("1==="+gson.toJson(resMsg));
|
||||||
|
|
||||||
if (send != null) {
|
|
||||||
Map<String, String> parms = new HashMap<>();
|
|
||||||
parms.put("title", send.getTitle());
|
|
||||||
parms.put("content", send.getContent());
|
|
||||||
resMsg.setParms(parms);
|
|
||||||
}
|
|
||||||
out.print(gson.toJson(resMsg));
|
out.print(gson.toJson(resMsg));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
System.out.println("2==="+e.getMessage());
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
package com.ljsd.pojo;
|
package com.ljsd.pojo;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import com.mongodb.DBObject;
|
|
||||||
import org.bson.BSONObject;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -15,13 +10,33 @@ import java.util.Set;
|
||||||
|
|
||||||
public class NoticeInfo {
|
public class NoticeInfo {
|
||||||
|
|
||||||
|
private long id;
|
||||||
|
|
||||||
private String _id;
|
|
||||||
private String content;
|
private String content;
|
||||||
|
|
||||||
private String title;
|
private String title;
|
||||||
private int leve;
|
|
||||||
private long startTime;
|
private String packageName;
|
||||||
private long endTime;
|
|
||||||
|
/**
|
||||||
|
* 1 紧急
|
||||||
|
* 2 最新
|
||||||
|
* 3 最热
|
||||||
|
* 4 常规
|
||||||
|
*/
|
||||||
|
private int type;
|
||||||
|
|
||||||
|
private String startTime;
|
||||||
|
|
||||||
|
private String endTime;
|
||||||
|
|
||||||
|
public long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public String getContent() {
|
public String getContent() {
|
||||||
return content;
|
return content;
|
||||||
|
@ -39,36 +54,48 @@ public class NoticeInfo {
|
||||||
this.title = title;
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String get_id() {
|
public String getPackageName() {
|
||||||
return _id;
|
return packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set_id(String _id) {
|
public void setPackageName(String packageName) {
|
||||||
this._id = _id;
|
this.packageName = packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeve() {
|
public int getType() {
|
||||||
return leve;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLeve(int leve) {
|
public void setType(int type) {
|
||||||
this.leve = leve;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartTime() {
|
public String getStartTime() {
|
||||||
return startTime;
|
return startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartTime(long startTime) {
|
public void setStartTime(String startTime) {
|
||||||
this.startTime = startTime;
|
this.startTime = startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getEndTime() {
|
public String getEndTime() {
|
||||||
return endTime;
|
return endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEndTime(long endTime) {
|
public void setEndTime(String endTime) {
|
||||||
this.endTime = endTime;
|
this.endTime = endTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
NoticeInfo that = (NoticeInfo) o;
|
||||||
|
return Objects.equals(id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(id, content, title, packageName, type, startTime, endTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.ljsd.pojo;
|
package com.ljsd.pojo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ResMsg {
|
public class ResMsg {
|
||||||
|
@ -10,6 +11,11 @@ public class ResMsg {
|
||||||
|
|
||||||
private Map<String,String> parms;
|
private Map<String,String> parms;
|
||||||
|
|
||||||
|
private List<NoticeInfo> list;
|
||||||
|
|
||||||
|
public ResMsg() {
|
||||||
|
}
|
||||||
|
|
||||||
public int getCode() {
|
public int getCode() {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -33,4 +39,12 @@ public class ResMsg {
|
||||||
public void setParms(Map<String, String> parms) {
|
public void setParms(Map<String, String> parms) {
|
||||||
this.parms = parms;
|
this.parms = parms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<NoticeInfo> getList() {
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setList(List<NoticeInfo> list) {
|
||||||
|
this.list = list;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ public interface RedisKey {
|
||||||
/**
|
/**
|
||||||
* 公告列表
|
* 公告列表
|
||||||
*/
|
*/
|
||||||
String NOTICE = "NOTICE";
|
String NOTICE = "NOTICE_INFO";
|
||||||
String GLOBAL_SYS_PRO= "GLOBAL_SYS_PRO";
|
String GLOBAL_SYS_PRO= "GLOBAL_SYS_PRO";
|
||||||
/**
|
/**
|
||||||
* 根据openId 封号
|
* 根据openId 封号
|
||||||
|
|
|
@ -74,4 +74,27 @@ public class TimeUtil {
|
||||||
int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
int week = calendar.get(Calendar.DAY_OF_WEEK) - 1;
|
||||||
return (week == 0) ? 7 : week;
|
return (week == 0) ? 7 : week;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字符串 时间格式 转秒时间戳
|
||||||
|
* @param date
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long timeStrToSecond(String date){
|
||||||
|
try {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
return sdf.parse(date).getTime()/1000;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前时间,秒
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static long nowInt(){
|
||||||
|
return System.currentTimeMillis()/1000;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||||
version="3.1">
|
version="3.1">
|
||||||
|
<!-- 本地路劲需要加 jl_loginserver -->
|
||||||
|
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>logbackConfigLocation</param-name>
|
<param-name>logbackConfigLocation</param-name>
|
||||||
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>getNotice</servlet-name>
|
<servlet-name>getNotice</servlet-name>
|
||||||
<url-pattern>/getNotice</url-pattern>
|
<url-pattern>/jl_loginserver/getNotice</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<servlet>
|
<servlet>
|
||||||
|
|
Loading…
Reference in New Issue