From b879d7e7d7eeda56dab389dce9b7d47cf86dfbae Mon Sep 17 00:00:00 2001
From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com>
Date: Thu, 21 Nov 2019 11:23:22 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E6=B9=96=E5=8D=97=E7=9C=81?=
=?UTF-8?q?=E6=94=BF=E5=BA=9C=E9=87=87=E8=B4=AD=E7=BD=91=20rss=20(#3436)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
docs/government.md | 4 ++
lib/router.js | 1 +
lib/routes/gov/hunan/notice.js | 80 ++++++++++++++++++++++++++++++++++
3 files changed, 85 insertions(+)
create mode 100644 lib/routes/gov/hunan/notice.js
diff --git a/docs/government.md b/docs/government.md
index 696eb402be..00619b0d33 100644
--- a/docs/government.md
+++ b/docs/government.md
@@ -89,6 +89,10 @@ pageClass: routes
+### 湖南省政府采购网-公告
+
+
+
### 江苏省人民政府
diff --git a/lib/router.js b/lib/router.js
index b4de907bec..66a648ef13 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -1075,6 +1075,7 @@ router.get('/gov/news/:uid', require('./routes/gov/news'));
router.get('/gov/suzhou/news/:uid', require('./routes/gov/suzhou/news'));
router.get('/gov/suzhou/doc', require('./routes/gov/suzhou/doc'));
router.get('/gov/shanxi/rst/:category', require('./routes/gov/shanxi/rst'));
+router.get('/gov/hunan/notice/:type', require('./routes/gov/hunan/notice'));
// 中华人民共和国-海关总署
router.get('/gov/customs/list/:gchannel', require('./routes/gov/customs/list'));
diff --git a/lib/routes/gov/hunan/notice.js b/lib/routes/gov/hunan/notice.js
new file mode 100644
index 0000000000..77d554c2c7
--- /dev/null
+++ b/lib/routes/gov/hunan/notice.js
@@ -0,0 +1,80 @@
+const got = require('@/utils/got');
+
+module.exports = async (ctx) => {
+ const type = ctx.params.type || 'all';
+ const rssData = {
+ isType: ctx.params.type ? true : false,
+ Title: `湖南省政府采购网`,
+ Desc: `湖南省政府采购网`,
+ Link: `http://www.ccgp-hunan.gov.cn/page/notice/more.jsp`,
+ Category: new Map([
+ ['all', { name: '全部', id: '' }],
+ ['cg', { name: '采购公告', id: 'prcmNotices' }],
+ ['zb', { name: '中标(成交)公告', id: 'dealNotices' }],
+ ['fb', { name: '废标公告', id: 'invalidNotices' }],
+ ['ht', { name: '合同公告', id: 'contractNotices' }],
+ ['gz', { name: '更正公告', id: 'modfiyNotices' }],
+ ['zz', { name: '终止公告', id: 'endNotices' }],
+ ['qt', { name: '其他公告', id: 'otherNotices' }],
+ ]),
+ typeName: function(type) {
+ return rssData.Category.get(type).name;
+ },
+ typeid: function(type) {
+ return rssData.Category.get(type).id;
+ },
+ ProcessFeed: async (id) => {
+ const response = await got({
+ method: 'get',
+ url: `http://www.ccgp-hunan.gov.cn/mvc/viewNoticeContent.do?noticeId=` + id,
+ headers: {
+ Referer: rssData.itemUrl + id,
+ },
+ });
+ const htmlContent = response.data;
+ return htmlContent;
+ },
+ ItemsSingle: async function(item) {
+ const cache = await ctx.cache.get(rssData.itemUrl);
+ if (cache) {
+ return Promise.resolve(JSON.parse(cache));
+ }
+
+ const single = {
+ title: item.NOTICE_TITLE,
+ link: rssData.itemUrl + item.NOTICE_ID,
+ author: item.NOTICE_NAME,
+ description: await rssData.ProcessFeed(item.NOTICE_ID),
+ guid: item.NOTICE_ID,
+ category: item.NOTICE_NAME,
+ pubDate: new Date(`${item.NEWWORK_DATE} GMT`).toUTCString(),
+ };
+ ctx.cache.set(rssData.itemUrl, JSON.stringify(single));
+ return Promise.resolve(single);
+ },
+ referUrl: `http://www.ccgp-hunan.gov.cn/page/notice/more.jsp`,
+ apiUrl: `http://www.ccgp-hunan.gov.cn/mvc/getNoticeList4Web.do`,
+ itemUrl: `http://www.ccgp-hunan.gov.cn/page/notice/notice.jsp?noticeId=`,
+ };
+ // 结束rssData定义
+ // 配置api日期参数
+ const now = new Date();
+ const startDate = now.getFullYear() + '-' + now.getMonth() + '-01';
+ const endDate = now.toLocaleDateString().replace(/\//g, '-');
+ rssData.apiResponse = await got({
+ method: 'post',
+ url: `http://www.ccgp-hunan.gov.cn/mvc/getNoticeList4Web.do?nType=${rssData.typeid(type)}&startDate=${startDate}&endDate=${endDate}&page=1&pageSize=18`,
+ responseType: 'buffer',
+ headers: {
+ Referer: rssData.referUrl,
+ },
+ });
+ rssData.apiData = rssData.apiResponse.data.rows;
+ rssData.Items = await Promise.all(rssData.apiData.map((item) => rssData.ItemsSingle(item)));
+ ctx.state.data = {
+ title: rssData.Title,
+ link: rssData.Link,
+ description: rssData.Desc,
+ item: rssData.Items,
+ };
+};