This commit is contained in:
@jyuhsin
2026-01-15 08:56:42 +08:00
parent 105c955abd
commit 0a479ae299
6 changed files with 82 additions and 125 deletions
+1 -1
View File
@@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging> <packaging>jar</packaging>
<groupId>com.budwk</groupId> <groupId>com.budwk</groupId>
<artifactId>zhgh-whcp</artifactId> <artifactId>zhgh_cug_v4</artifactId>
<version>5.6.0-plus</version> <version>5.6.0-plus</version>
<properties> <properties>
<nutzboot.version>2.6.0-SNAPSHOT</nutzboot.version> <nutzboot.version>2.6.0-SNAPSHOT</nutzboot.version>
@@ -27,6 +27,7 @@ import org.nutz.dao.util.Daos;
import org.nutz.integration.jedis.RedisService; import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.loader.annotation.Inject; import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean; import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.lang.Lang; import org.nutz.lang.Lang;
import org.nutz.lang.Strings; import org.nutz.lang.Strings;
import org.nutz.lang.util.NutMap; import org.nutz.lang.util.NutMap;
@@ -38,10 +39,9 @@ import org.nutz.mvc.annotation.Param;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import java.util.ArrayList; import java.io.IOException;
import java.util.Comparator; import java.util.*;
import java.util.Date; import java.util.stream.Collectors;
import java.util.List;
@IocBean @IocBean
@@ -263,76 +263,31 @@ public class SysHomeController {
// @CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "web_news", isHash = true) // @CacheDefaults(cacheName = RedisConstant.PLATFORM_REDIS_WKCACHE_PREFIX + "web_news", isHash = true)
// @CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24) // @CacheResult(cacheKey = "news", ignoreNull = true, cacheLiveTime = 60 * 60 * 24)
public Result getNews() { public Result getNews() {
// 定义要爬取的URL
String domain = "https://gh.whcp.edu.cn";
try { try {
// 使用Jsoup连接到URL并获取页面内容 String url = "https://xgh.cug.edu.cn/";
Document doc = Jsoup.connect(domain).get(); Document document = Jsoup.connect(url).get();
Elements homeElements = document.select(".gh,.jc,.fc,.jg");
JSONObject root = new JSONObject(); List<Map<String, Object>> news = homeElements.stream().map(homeElement -> {
//获取板块名称
// 1. 新闻快讯(来自 .list1 String name = homeElement.selectFirst(".title").text();
/* List<JSONObject> newsArray = new ArrayList<>(); Elements liElements = homeElement.select("li");
Elements newsItems = doc.select(".ml .main_page2 .news_list li"); List<NutMap> ele = liElements.stream().map(liElement -> {
for (Element item : newsItems) { NutMap row = NutMap.NEW();
String date = item.select(".date").text().trim(); String href = liElement.selectFirst("a").attr("href");
Element link = item.select("a.text").first(); String time = liElement.selectFirst("span").text();
String title = link.select(".title").text().trim(); String title = liElement.selectFirst("a").attr("title");
String url = link.attr("href").trim(); row.put("href", href);
row.put("time", time);
JSONObject node = new JSONObject(); row.put("text", title);
node.set("title", title); return row;
node.set("date", date); }).toList();
node.set("url", domain + url); return Map.of("label", name, "value", ele);
newsArray.add(node); }).collect(Collectors.toList());
} redisService.setex("gonghui_news", 60 * 60 * 24, Json.toJson(news));
root.set("news", newsArray);*/ return Result.success(news);
} catch (IOException e) {
// 2. 通知公告(来自 .list2 throw new RuntimeException(e);
List<JSONObject> noticesArray = new ArrayList<>();
Elements noticeItems = doc.select(".tu_text .news_list li");
for (Element item : noticeItems) {
String date = item.select(".news_meta").text().trim();
Element link = item.select(".news_title a").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();
} }
} }
} }
+4 -4
View File
@@ -1,6 +1,6 @@
nutz: nutz:
application: application:
name: zhgh_whcp name: zhgh_cug_v4
mvc: mvc:
ignore: ^(.+[.])(jsp|png|gif|jpg|js|css|jspx|jpeg|html|mp3|mp4|ico|svg|vue)$ ignore: ^(.+[.])(jsp|png|gif|jpg|js|css|jspx|jpeg|html|mp3|mp4|ico|svg|vue)$
exclusions: /favicon/*,/assets/*,/druid/*,/upload/*,/components/* exclusions: /favicon/*,/assets/*,/druid/*,/upload/*,/components/*
@@ -21,7 +21,7 @@ jetty:
#结合ftp使用,或用nginx代理ftp路径 #结合ftp使用,或用nginx代理ftp路径
#staticPath: /Users/wizzer/temp/files #staticPath: /Users/wizzer/temp/files
#开发模式静态资源 #开发模式静态资源
staticPathLocal: D:/project/zhgh_whcp_new/src/main/resources/static staticPathLocal: D:/project/zhgh_cug_v4/src/main/resources/static
security: security:
tokenName: saToken tokenName: saToken
@@ -71,7 +71,7 @@ redis:
#nodes=192.168.6.31:6377,192.168.6.31:6378,192.168.6.28:6377,192.168.6.28:6378,192.168.6.34:6377,192.168.6.34:6378 #nodes=192.168.6.31:6377,192.168.6.31:6378,192.168.6.28:6377,192.168.6.28:6378,192.168.6.34:6377,192.168.6.34:6378
jdbc: jdbc:
url: jdbc:mysql://192.168.21.203:3306/zhgh_whcp_new?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true url: jdbc:mysql://192.168.21.215:3306/zhgh_cug_v4?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
username: root username: root
password: root password: root
validationQuery: select 1 validationQuery: select 1
@@ -87,7 +87,7 @@ xsssql:
beetl: beetl:
RESOURCE: RESOURCE:
#本地路径,开发时设置本地路径,便于调试 #本地路径,开发时设置本地路径,便于调试
rootLocal: D:/project/zhgh_whcp_new/src/main/resources/views/ rootLocal: D:/project/zhgh_cug_v4/src/main/resources/views/
root: views/ root: views/
DELIMITER_STATEMENT_START: "<!--#" DELIMITER_STATEMENT_START: "<!--#"
DELIMITER_STATEMENT_END: "#-->" DELIMITER_STATEMENT_END: "#-->"
@@ -85,7 +85,7 @@ layout("/layouts/v4/baseLayout.html"){
</div> </div>
</div> </div>
<jcdt :list="websiteNews.notices"></jcdt> <jcdt :list="websiteNews"></jcdt>
</div> </div>
</div> </div>
@@ -102,9 +102,7 @@ layout("/layouts/v4/baseLayout.html"){
el: '#v4-home-app', el: '#v4-home-app',
data(){ data(){
return{ return{
websiteNews:{ websiteNews: []
notices:[],
}
} }
}, },
components: { components: {
@@ -2,29 +2,30 @@ const jcdt = {
template: /*language=HTML*/ ` template: /*language=HTML*/ `
<div class="jcdt-wrapper"> <div class="jcdt-wrapper">
<div class="jcdt-container"> <div class="jcdt-container">
<el-carousel height="360px" :interval="30000" indicator-position="none">
<el-carousel-item v-for="item,index in list" :key="index">
<div class="jcdt-title"> <div class="jcdt-title">
<span>综合新闻</span> <span>{{ item.label }}</span>
</div> </div>
<div class="jcdt-content"> <div class="jcdt-content">
<div class="jcdt-list"> <div class="jcdt-list">
<div class="jcdt-item" v-for="item in list" :key="item.title" @click="onLink(item)"> <div class="jcdt-item" v-for="o,i in item.value" :key="i" @click="onLink(o)">
<div class="date" v-if="item.date">{{item.date}}</div> <div class="date" v-if="o.time">
<i class="el-icon-alarm-clock"></i>
<span>{{o.time}}</span>
</div>
<div style="display: flex; align-items: center"> <div style="display: flex; align-items: center">
<div > <div>
<el-image style="width: 30px" src="/assets/platform/img/v4/xw.png" ></el-image>
</div>
<div class="title">{{item.title}}</div>
</div>
<!--<div class="image"> </div>
<img v-if="item.image" :src="item.image" alt=""> <div class="title">{{o.text}}</div>
<img v-else src="/assets/platform/img/v4/not-image.png" alt="">
</div>-->
<!-- <div class="summary">{{item.summary}}</div>-->
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</el-carousel-item>
</el-carousel>
</div>
</div> </div>
`, `,
data() { data() {
@@ -38,9 +39,12 @@ const jcdt = {
}, },
methods: { methods: {
onLink(item) { onLink(item) {
if(!item.url) return const url = this.isHttpOrHttps(item.href) ? item.href : "https://xgh.cug.edu.cn/" + item.href
window.open(item.url) window.open(url)
}, },
isHttpOrHttps(url) {
return /^(http:\/\/|https:\/\/)/i.test(url)
}
}, },
style: /*language=CSS*/ ` style: /*language=CSS*/ `
.jcdt-wrapper { .jcdt-wrapper {
@@ -53,16 +57,14 @@ const jcdt = {
.jcdt-container { .jcdt-container {
width: 80%; width: 80%;
max-width: 80%; max-width: 80%;
margin: 0 auto; margin: 0 auto 10px;
background-color: #FFFFFF; background-color: #FFFFFF;
border-radius: 12px; border-radius: 12px;
padding: 20px; padding: 20px;
margin-bottom: 10px;
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
} }
.jcdt-title{ /deep/ .jcdt-title{
font-size: 30px; font-size: 30px;
color: #000000; color: #000000;
display: block; display: block;
@@ -94,13 +96,13 @@ const jcdt = {
vertical-align: middle; vertical-align: middle;
} }
.jcdt-list { /deep/ .jcdt-list {
display: grid; display: grid;
grid-template-columns: repeat(4, 1fr); grid-template-columns: repeat(4, 1fr);
gap: 20px; gap: 20px;
} }
.jcdt-item { /deep/ .jcdt-item {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
padding: 16px; padding: 16px;
@@ -109,18 +111,17 @@ const jcdt = {
transition: all 0.3s ease; transition: all 0.3s ease;
cursor: pointer; cursor: pointer;
height: auto; height: auto;
border-radius: 12px; border-radius: 12px;
} box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
.jcdt-item:hover{
background: #ffffff;
border-bottom-color: var(--color-primary); border-bottom-color: var(--color-primary);
transform: translateY(-4px); background: #ffffff;
box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
} }
.jcdt-item .date { /deep/ .jcdt-item:hover{
transform: translateY(-4px);
}
/deep/ .jcdt-item .date {
font-size: 20px; font-size: 20px;
font-weight: bold; font-weight: bold;
white-space: nowrap; white-space: nowrap;
@@ -129,7 +130,7 @@ const jcdt = {
transition: opacity 0.3s ease; transition: opacity 0.3s ease;
} }
.jcdt-item .title { /deep/ .jcdt-item .title {
font-size: 16px; font-size: 16px;
font-weight: 600; font-weight: 600;
/*margin-bottom: 12px;*/ /*margin-bottom: 12px;*/
@@ -141,7 +142,7 @@ const jcdt = {
/*height: 45px;*/ /*height: 45px;*/
} }
.jcdt-item .image { /deep/ .jcdt-item .image {
width: 100%; width: 100%;
height: 180px; height: 180px;
margin: 0 0 16px 0; margin: 0 0 16px 0;
@@ -155,14 +156,14 @@ const jcdt = {
transition: transform 0.3s ease; transition: transform 0.3s ease;
} }
.jcdt-item .image img { /deep/ .jcdt-item .image img {
width: 100%; width: 100%;
height: 100%; height: 100%;
object-fit: cover; object-fit: cover;
transition: transform 0.3s ease; transition: transform 0.3s ease;
} }
.jcdt-item .summary { /deep/ .jcdt-item .summary {
font-size: 14px; font-size: 14px;
color: #666; color: #666;
line-height: 1.6; line-height: 1.6;
@@ -174,5 +175,8 @@ const jcdt = {
margin-bottom: 12px; margin-bottom: 12px;
} }
/deep/ .jcdt-item i {
color: #007aff;
}
` `
}; };
@@ -608,7 +608,7 @@ layout("/layouts/platform_h5.html"){
</van-collapse-item> </van-collapse-item>
<!-- <van-cell title="发放方式" :value="getProvideModeName(projectInfo.provideMode)"></van-cell>--> <!-- <van-cell title="发放方式" :value="getProvideModeName(projectInfo.provideMode)"></van-cell>-->
<!-- <van-cell title="签字方式" :value="getSignModeName(projectInfo.signMode)"></van-cell>--> <!-- <van-cell title="签字方式" :value="getSignModeName(projectInfo.signMode)"></van-cell>-->
</van-collapse>
</div> </div>
<div class="section-divider"></div> <div class="section-divider"></div>