commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package io.v.nutz.sys.controllers.platform.sys;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
public class SSLContextTrustAnyHostname {
|
||||
public static void trustAllHosts() {
|
||||
TrustManager[] trustAllCerts = new TrustManager[]{
|
||||
new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
public void checkServerTrusted(X509Certificate[] certs, String authType) {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SSLContext sc = null;
|
||||
try {
|
||||
sc = SSLContext.getInstance("SSL");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
sc.init(null, trustAllCerts, new SecureRandom());
|
||||
} catch (KeyManagementException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
|
||||
|
||||
// Create all-trusting host name verifier
|
||||
HostnameVerifier allHostsValid = new HostnameVerifier() {
|
||||
public boolean verify(String hostname, SSLSession session) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
|
||||
}
|
||||
}
|
||||
@@ -4,26 +4,41 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.wizzer.framework.base.Result;
|
||||
import io.v.nutz.base.enums.Env;
|
||||
import io.v.nutz.base.service.BaseService;
|
||||
import io.v.nutz.sys.models.Sys_home_activity;
|
||||
import io.v.nutz.sys.models.Sys_menu;
|
||||
import io.v.nutz.sys.services.SysMenuService;
|
||||
import io.v.nutz.sys.services.SysUserService;
|
||||
import io.v.nutz.web.commons.base.Globals;
|
||||
import io.v.nutz.web.commons.utils.ShiroUtil;
|
||||
import io.v.nutz.zhgh.activity.models.ActivityUserScope;
|
||||
import org.apache.shiro.authz.annotation.RequiresAuthentication;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.FieldFilter;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.dao.util.Daos;
|
||||
import org.nutz.integration.jedis.RedisService;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/6/23.
|
||||
@@ -40,8 +55,14 @@ public class SysHomeController {
|
||||
@Inject
|
||||
private BaseService baseService;
|
||||
|
||||
@Inject
|
||||
private Dao dao;
|
||||
|
||||
@Inject
|
||||
private RedisService redisService;
|
||||
|
||||
@At("")
|
||||
@Ok("beetl:/platform/sys/home2.html")
|
||||
@Ok("beetl:/platform/sys/home/index.html")
|
||||
@RequiresAuthentication
|
||||
public void home(HttpSession session, HttpServletRequest request) {
|
||||
|
||||
@@ -182,6 +203,44 @@ public class SysHomeController {
|
||||
return Result.success(baseService.listMap(sql));
|
||||
}
|
||||
|
||||
@At
|
||||
@Ok("json:full")
|
||||
@RequiresAuthentication
|
||||
public Result listHomeActivity() {
|
||||
FieldFilter fieldFilter = FieldFilter.locked(Sys_home_activity.class, "classPath");
|
||||
List<Sys_home_activity> list = Daos.ext(dao, fieldFilter).query(Sys_home_activity.class, Cnd.where("enable", "=", 1).desc("top"));
|
||||
String userId = ShiroUtil.getUserId();
|
||||
|
||||
List<Sys_home_activity> allowActivityList = new ArrayList<>();
|
||||
|
||||
for (Sys_home_activity activity : list) {
|
||||
Integer allowUserGroupId = activity.getAllowUserGroupId();
|
||||
String allowUserSql = activity.getAllowUserSql();
|
||||
activity.setAllowUserSql(null);
|
||||
if (allowUserGroupId == null && StrUtil.isBlank(allowUserSql)) {
|
||||
allowActivityList.add(activity);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (allowUserGroupId != null) {
|
||||
int count = dao.count(ActivityUserScope.class, Cnd.where("groupId", "=", allowUserGroupId).and("userId", "=", userId));
|
||||
if (count > 0) {
|
||||
allowActivityList.add(activity);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(allowUserSql)) {
|
||||
Sql sql = Sqls.create(allowUserSql).setParam("userId", userId);
|
||||
NutMap nutMap = (NutMap) Daos.query(dao, sql.toString(), Sqls.callback.map());
|
||||
if (Lang.isNotEmpty(nutMap)) {
|
||||
allowActivityList.add(activity);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.success(allowActivityList);
|
||||
}
|
||||
|
||||
|
||||
@At("/403")
|
||||
@Ok("re")
|
||||
@@ -231,5 +290,77 @@ public class SysHomeController {
|
||||
return ">>:/error/AuthenticationError.html";
|
||||
}
|
||||
|
||||
/**
|
||||
* 工会网站新闻
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@At
|
||||
@RequiresAuthentication
|
||||
@Ok("json")
|
||||
public Result getNews() {
|
||||
try {
|
||||
// String gonghuiNews = redisService.get("gonghui_news");
|
||||
// if(Strings.isNotBlank(gonghuiNews)){
|
||||
// List<HashMap> news = Json.fromJsonAsList(HashMap.class, gonghuiNews);
|
||||
// return Result.success(news);
|
||||
// }
|
||||
SSLContextTrustAnyHostname.trustAllHosts();
|
||||
String url = "https://gh.zufe.edu.cn/";
|
||||
Document document = null;
|
||||
document = Jsoup.connect(url).get();
|
||||
Elements homeElements1 = document.select(".index .section1 .w12>div");
|
||||
Elements homeElements2 = document.select(".index .section2 .w12>div");
|
||||
|
||||
|
||||
List<Map<String, Object>> news1 = homeElements1.stream().map(homeElement -> {
|
||||
//获取板块名称
|
||||
String name = homeElement.selectFirst("div.tit>h2").text();
|
||||
if (name.equals("新闻速递")) {
|
||||
Elements liElements = homeElement.select(".s1-r ul li");
|
||||
List<NutMap> notices = liElements.stream().map(liElement -> {
|
||||
NutMap row = NutMap.NEW();
|
||||
String href = liElement.selectFirst("a").attr("href");
|
||||
String time = liElement.selectFirst("a span").text();
|
||||
String title = liElement.selectFirst("a p").text();
|
||||
row.put("href", href);
|
||||
row.put("time", time);
|
||||
row.put("text", title);
|
||||
return row;
|
||||
}).collect(Collectors.toList());
|
||||
return Map.of("label", name, "value", notices);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
List<Map<String, Object>> news2 = homeElements2.stream().map(homeElement -> {
|
||||
//获取板块名称
|
||||
String name = homeElement.selectFirst("div.tit>h2").text();
|
||||
if (name.equals("通知公告")) {
|
||||
Elements liElements = homeElement.select(".s2-l ul li");
|
||||
List<NutMap> notices = liElements.stream().map(liElement -> {
|
||||
NutMap row = NutMap.NEW();
|
||||
String href = liElement.selectFirst("a").attr("href");
|
||||
String time1 = liElement.selectFirst("a .date b").text();
|
||||
String time2 = liElement.selectFirst("a .date span").text();
|
||||
String title = liElement.selectFirst("a .info h3").text();
|
||||
row.put("href", href);
|
||||
row.put("time", time2 + "-" + time1);
|
||||
row.put("text", title);
|
||||
return row;
|
||||
}).collect(Collectors.toList());
|
||||
return Map.of("label", name, "value", notices);
|
||||
}
|
||||
return null;
|
||||
}).collect(Collectors.toList());
|
||||
if (Lang.isNotEmpty(news2)) {
|
||||
news1.addAll(news2);
|
||||
}
|
||||
redisService.setex("gonghui_news", 60 * 60 * 24, Json.toJson(news1));
|
||||
return Result.success(news1);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user