USVT-116 更新博客表的字段,添加一个新的Discourse Id 字段

This commit is contained in:
YuCheng Hu 2022-12-22 09:39:15 -05:00
parent a5f4b67381
commit 6d43e5e730
3 changed files with 68 additions and 20 deletions

View File

@ -1,16 +1,20 @@
package com.northtecom.visatrack.api.controller.api;
import com.northtecom.visatrack.api.controller.vo.VisaCaseSearch;
import com.northtecom.visatrack.api.service.impl.BlogService;
import com.northtecom.visatrack.api.service.impl.VisaCaseService;
import com.redfin.sitemapgenerator.ChangeFreq;
import com.redfin.sitemapgenerator.WebSitemapGenerator;
import com.redfin.sitemapgenerator.WebSitemapUrl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.io.FileUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
import java.net.MalformedURLException;
import java.util.Date;
/**
* The API related to website content.
@ -32,9 +36,12 @@ public class ContentController {
private final BlogService blogService;
private final VisaCaseService visaCaseService;
public ContentController(BlogService blogService) {
public ContentController(BlogService blogService, VisaCaseService visaCaseService) {
this.blogService = blogService;
this.visaCaseService = visaCaseService;
}
@ -43,27 +50,34 @@ public class ContentController {
*
* @return a File with Spring MVC
*/
@GetMapping("/sitemap")
@GetMapping("/blog")
@Operation(summary = "Get Sitemap xml file", description = "This API will get sitemap xml file")
public String querySitemap() {
public String querySitemap() throws MalformedURLException {
byte[] bt = null;
String btx = null;
VisaCaseSearch search = new VisaCaseSearch();
// search.setCheckStartDate(new Date().mi);
// 38553
WebSitemapGenerator wsg = new WebSitemapGenerator("https://www.usvisatrack.com/", new File("D:\\home\\"));
for (int i = 0; i < 39553; i++) {
WebSitemapUrl url = new WebSitemapUrl.Options("https://www.usvisatrack.com/visa/detail?id=" + i)
.lastMod(new Date()).priority(1.0).changeFreq(ChangeFreq.HOURLY).build();
wsg.addUrl(url);
}
wsg.write();
// bt = FileUtils.readFileToByteArray(new File("D:\\home\\sitemap.xml"));
btx = "<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n" +
"<sitemap>\n" +
"<loc>https://www.ossez.com/sitemap_recent.xml</loc>\n" +
"<lastmod>2022-12-15T05:44:41Z</lastmod>\n" +
"</sitemap>\n" +
"<sitemap>\n" +
"<loc>https://www.ossez.com/sitemap_1.xml</loc>\n" +
"<lastmod>2022-12-15T05:44:41Z</lastmod>\n" +
"</sitemap>\n" +
"<sitemap>\n" +
"<loc>https://www.ossez.com/sitemap_2.xml</loc>\n" +
"<lastmod>2022-12-12T15:49:36Z</lastmod>\n" +
"</sitemap>\n" +
"</sitemapindex>";
btx = "";
// return Base64.getEncoder().withoutPadding().encodeToString(bt);

View File

@ -61,6 +61,38 @@ public class CrawlController {
this.objectMapper = new ObjectMapper();
}
@PostMapping("/blog/sync")
@Operation(summary = "Sync ", description = "同步所有数据")
public Boolean syncBlogByDateRange(@RequestBody CheckeeSyncRequest checkeeSyncRequest) {
LocalDate startDate = LocalDate.now();
LocalDate endDate = LocalDate.now();
try {
String action = checkeeSyncRequest.getAction();
// Get Start and End Date by action
switch (action) {
case "date":
if (StringUtils.isNotBlank(checkeeSyncRequest.getStartDate()) && StringUtils.isNotBlank(checkeeSyncRequest.getEndDate())) {
startDate = LocalDate.parse(checkeeSyncRequest.getStartDate());
endDate = LocalDate.parse(checkeeSyncRequest.getEndDate());
}
break;
default:
Period p = Period.parse(StringUtils.trimToEmpty(checkeeSyncRequest.getRange()));
startDate = endDate.minus(p);
}
this.visaReportCheckeeService.syncDataAndReport(startDate,endDate);
} catch (Exception e) {
throw new BaseException(Status.BAD_REQUEST, "Cannot Process Request");
}
return true;
}
@PostMapping("/checkee/sync")
@Operation(summary = "Sync ", description = "同步所有数据")
public Boolean syncByDateRange(@RequestBody CheckeeSyncRequest checkeeSyncRequest) {

View File

@ -31,6 +31,8 @@ public class Blog extends BaseEntity<Long> {
private String authorName;
@Column(name = "category", columnDefinition = "varchar(50) COMMENT 'Category'")
private String category;
@Column(name = "discourse_id", columnDefinition = "bigint COMMENT 'Discourse Id'")
private Long discourseId = 0L;
@Column(name = "title", columnDefinition = "varchar(300) COMMENT 'Title'")
private String blogTitle;
@Column(name = "content", columnDefinition = "LONGTEXT COMMENT 'Content'")