..
This commit is contained in:
@@ -5,7 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.useragent.UserAgent;
|
||||
import cn.hutool.http.useragent.UserAgentUtil;
|
||||
import com.budwk.app.base.constant.RedisConstant;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.budwk.app.base.result.Result;
|
||||
import com.budwk.app.sys.models.Sys_home_activity;
|
||||
import com.budwk.app.sys.models.Sys_menu;
|
||||
@@ -35,8 +35,6 @@ import org.nutz.log.Logs;
|
||||
import org.nutz.mvc.annotation.At;
|
||||
import org.nutz.mvc.annotation.Ok;
|
||||
import org.nutz.mvc.annotation.Param;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheResult;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
@@ -172,6 +170,22 @@ public class SysHomeController {
|
||||
return Result.success(sysMenus);
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@ApiOperation("获取收藏应用")
|
||||
@Ok("json")
|
||||
public Result listFavorite(@Param(value = "platform", df = "PC") String platform) {
|
||||
List<Sys_menu> list = sysMenuService.query(Cnd.where(Sys_menu::getId, "in", Sqls.create("select appId from sys_user_favorite_app where userId = @userId").setParam("userId", SecurityUtil.getUserId()))
|
||||
.and(Sys_menu::getDisabled, "=", 0)
|
||||
.and(Sys_menu::getShowit, "=", 1)
|
||||
.and(Sys_menu::getPlatform, "=", platform)
|
||||
);
|
||||
List<Sys_menu> menus = sysUserService.getMenus(SecurityUtil.getUserId());
|
||||
List<String> allMenuIds = menus.stream().map(Sys_menu::getId).toList();
|
||||
List<Sys_menu> sysMenus = list.stream().filter(m -> allMenuIds.contains(m.getId())).sorted(Comparator.comparingInt(Sys_menu::getLocation)).toList();
|
||||
return Result.success(sysMenus);
|
||||
}
|
||||
|
||||
|
||||
@At
|
||||
@SaCheckLogin
|
||||
@@ -240,43 +254,76 @@ public class SysHomeController {
|
||||
@SaCheckLogin
|
||||
@ApiOperation("获取新闻")
|
||||
@Ok("json")
|
||||
@CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "web_news", isHash = true)
|
||||
@CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24)
|
||||
// @CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "web_news", isHash = true)
|
||||
// @CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24)
|
||||
public Result getNews() {
|
||||
// 定义要爬取的URL
|
||||
String domain = "http://nsdgh.njnu.edu.cn";
|
||||
String domain = "https://cdgh.ncu.edu.cn/";
|
||||
try {
|
||||
// 使用Jsoup连接到URL并获取页面内容
|
||||
Document document = Jsoup.connect(domain).get();
|
||||
List<NutMap> results = new ArrayList<>();
|
||||
Document doc = Jsoup.connect(domain).get();
|
||||
|
||||
// 最新新闻
|
||||
Element newsElement = document.getElementById("news");
|
||||
// 获取所有li元素下的a标签
|
||||
Elements links = newsElement.select("li a");
|
||||
List<NutMap> list = links.stream().map(a -> {
|
||||
NutMap map = new NutMap();
|
||||
map.put("href", domain + "/" + a.attr("href"));
|
||||
map.put("text", a.text());
|
||||
return map;
|
||||
}).toList();
|
||||
results.add(NutMap.NEW().addv("label", "最新新闻").addv("value", list));
|
||||
JSONObject root = new JSONObject();
|
||||
|
||||
// 通知公告
|
||||
Elements newsSections = document.select("div.news1");
|
||||
for (Element section : newsSections) {
|
||||
String category = section.selectFirst("h6").ownText(); // 获取"通知公告"或"分工会"
|
||||
Elements items = section.select("li a");
|
||||
List<NutMap> list1 = items.stream().map(a -> {
|
||||
NutMap map = new NutMap();
|
||||
map.put("href", domain + "/" + a.attr("href"));
|
||||
map.put("text", a.text());
|
||||
return map;
|
||||
}).toList();
|
||||
results.add(NutMap.NEW().addv("label", category).addv("value", list1));
|
||||
// 1. 新闻快讯(来自 .list1)
|
||||
List<JSONObject> newsArray = new ArrayList<>();
|
||||
Elements newsItems = doc.select(".group1 .list1 li");
|
||||
for (Element item : newsItems) {
|
||||
String date = item.select(".date").text().trim();
|
||||
Element link = item.select("a.text").first();
|
||||
String title = link.select(".title").text().trim();
|
||||
String url = link.attr("href").trim();
|
||||
|
||||
JSONObject node = new JSONObject();
|
||||
node.set("title", title);
|
||||
node.set("date", date);
|
||||
node.set("url", domain + url);
|
||||
newsArray.add(node);
|
||||
}
|
||||
root.set("news", newsArray);
|
||||
|
||||
return Result.success(results);
|
||||
// 2. 通知公告(来自 .list2)
|
||||
List<JSONObject> noticesArray = new ArrayList<>();
|
||||
Elements noticeItems = doc.select(".group2 .list2 li");
|
||||
for (Element item : noticeItems) {
|
||||
String date = item.select(".date").text().trim();
|
||||
Element link = item.select("a.title").first();
|
||||
String title = link.text().trim();
|
||||
String url = link.attr("href").trim();
|
||||
JSONObject node = new JSONObject();
|
||||
node.set("title", title);
|
||||
node.set("date", date);
|
||||
node.set("url", domain + url);
|
||||
noticesArray.add(node);
|
||||
}
|
||||
root.set("notices", noticesArray);
|
||||
|
||||
// 3. 基层风采(来自 .pic-list1)
|
||||
List<JSONObject> grassrootsArray = new ArrayList<>();
|
||||
Elements grassrootsItems = doc.select(".group3 .pic-list1 li");
|
||||
for (Element item : grassrootsItems) {
|
||||
Element link = item.select("a.img-scale").first();
|
||||
String date = link.select(".date").text().trim();
|
||||
String title = link.select(".title").text().trim();
|
||||
String url = link.attr("href").trim();
|
||||
String summary = link.select(".info").text().trim();
|
||||
|
||||
String imageUrl = "";
|
||||
Element img = link.select("img").first();
|
||||
if (img != null) {
|
||||
imageUrl = img.attr("src").trim();
|
||||
}
|
||||
|
||||
JSONObject node = new JSONObject();
|
||||
node.set("title", title);
|
||||
node.set("date", date);
|
||||
node.set("url", domain + url);
|
||||
node.set("summary", summary);
|
||||
node.set("image", domain + imageUrl);
|
||||
grassrootsArray.add(node);
|
||||
}
|
||||
root.set("grassroots", grassrootsArray);
|
||||
return Result.success(root);
|
||||
} catch (Exception e) {
|
||||
log.error(e);
|
||||
return Result.success();
|
||||
|
||||
@@ -114,6 +114,11 @@ public interface SysRoleService extends BaseService<Sys_role> {
|
||||
*/
|
||||
Sys_role getByCode(String code);
|
||||
|
||||
/**
|
||||
* 通过枚举获取角色
|
||||
* @param roleConstant
|
||||
* @return
|
||||
*/
|
||||
Sys_role getByCode(RoleConstant roleConstant);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user