|
@@ -3,29 +3,43 @@ package com.backendsys.modules.cms.template;
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
import com.backendsys.modules.cms.article.dao.ArticleDao;
|
|
|
import com.backendsys.modules.cms.article.entity.Article;
|
|
|
+import com.backendsys.modules.cms.article.entity.ArticleCategory;
|
|
|
+import com.backendsys.modules.cms.article.service.ArticleCategoryService;
|
|
|
import com.backendsys.modules.cms.article.service.ArticleService;
|
|
|
+import com.backendsys.modules.cms.siteinfo.entity.SiteInfo;
|
|
|
import com.backendsys.modules.common.aspect.Pages;
|
|
|
import com.backendsys.modules.common.utils.CookieUtil;
|
|
|
import com.backendsys.utils.response.PageEntity;
|
|
|
import com.backendsys.utils.v2.PageUtils;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.context.MessageSource;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.Model;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
public class ViewArticleController {
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private MessageSource messageSource;
|
|
|
+
|
|
|
@Autowired
|
|
|
private ArticleService articleService;
|
|
|
+ @Autowired
|
|
|
+ private ArticleCategoryService articleCategoryService;
|
|
|
|
|
|
@Pages
|
|
|
+ @Operation(summary = "资讯列表 (视图)")
|
|
|
@GetMapping({"/article/list"})
|
|
|
public String article(Model model,
|
|
|
@RequestParam(value = "page_num", defaultValue = "1") Integer pageNum,
|
|
@@ -36,64 +50,62 @@ public class ViewArticleController {
|
|
|
|
|
|
String lang = Convert.toStr(model.getAttribute("lang"));
|
|
|
|
|
|
- // [Get] 获取资讯列表
|
|
|
+ // [Get] 获取资讯列表 -------------------------------------------------
|
|
|
+ // [Condition] 查询条件
|
|
|
Article article = new Article();
|
|
|
article.setLang(lang);
|
|
|
article.setTitle(title);
|
|
|
article.setCategory_id(categoryId);
|
|
|
- //
|
|
|
- PageUtils.startPage(pageNum, pageSize); // 分页
|
|
|
+ // [Condition] 分页
|
|
|
+ PageUtils.startPage(pageNum, pageSize);
|
|
|
PageEntity articleList = articleService.selectArticleList(article);
|
|
|
model.addAttribute("articleList", articleList);
|
|
|
|
|
|
-//
|
|
|
-// // [Get] 资讯分类
|
|
|
-// List<Map<String, Object>> categoryList = articleCategoryService.queryArticleCategoryActive();
|
|
|
-// String categoryName = null;
|
|
|
-// if ("zh".equals(lang)) {
|
|
|
-// categoryName = (String) categoryList.stream()
|
|
|
-// .filter(cate -> cate.get("id").equals(categoryId))
|
|
|
-// .map(cate -> cate.get("category_name"))
|
|
|
-// .findFirst().orElse(null);
|
|
|
-// }
|
|
|
-// if ("en".equals(lang)) {
|
|
|
-// categoryName = (String) categoryList.stream()
|
|
|
-// .filter(cate -> cate.get("id").equals(categoryId))
|
|
|
-// .map(cate -> cate.get("category_name_en"))
|
|
|
-// .findFirst().orElse(null);
|
|
|
-// }
|
|
|
-//
|
|
|
-//
|
|
|
-// model.addAttribute("isBrand", true);
|
|
|
-// model.addAttribute("articleCategory", categoryList);
|
|
|
-//
|
|
|
-// Map<String, Object> parameters = new LinkedHashMap<>();
|
|
|
-// parameters.put("title", title);
|
|
|
-// parameters.put("category_id", categoryId);
|
|
|
-// parameters.put("category_name", categoryName);
|
|
|
-// model.addAttribute("parameters", parameters);
|
|
|
+ // [Get] 获取资讯分类列表 ---------------------------------------------
|
|
|
+ ArticleCategory articleCategory = new ArticleCategory();
|
|
|
+ articleCategory.setLang(lang);
|
|
|
+ articleCategory.setStatus(1);
|
|
|
+ List<ArticleCategory> articleCategoryList = articleCategoryService.selectArticleCategory(articleCategory);
|
|
|
+ System.out.println(articleCategoryList);
|
|
|
+ model.addAttribute("articleCategoryList", articleCategoryList);
|
|
|
+
|
|
|
+ // 参数暴露
|
|
|
+ Map<String, Object> parameters = new LinkedHashMap<>();
|
|
|
+ parameters.put("title", title);
|
|
|
+ parameters.put("category_id", categoryId);
|
|
|
+ model.addAttribute("parameters", parameters);
|
|
|
|
|
|
// -- Layout ---------------------------------------------
|
|
|
- model.addAttribute("title", "zh".equals(lang) ? "资讯中心": "Aricle");
|
|
|
+ String titleTranslate = messageSource.getMessage("article.title", null, new Locale(lang));
|
|
|
+ model.addAttribute("title", titleTranslate);
|
|
|
+
|
|
|
model.addAttribute("layout", "article");
|
|
|
return "layout/layout";
|
|
|
}
|
|
|
|
|
|
|
|
|
@Pages
|
|
|
+ @Operation(summary = "资讯详情 (视图)")
|
|
|
@GetMapping({"/articleDetail/{uid}"})
|
|
|
public String articleDetail(Model model, @PathVariable("uid") String uid) {
|
|
|
|
|
|
String lang = Convert.toStr(model.getAttribute("lang"));
|
|
|
|
|
|
- // [Get] 获取资讯详情
|
|
|
+ // [Get] 获取资讯详情 ----------------------------------------------
|
|
|
Article articleDetail = articleService.selectArticle(lang, uid);
|
|
|
if (articleDetail == null) return "error";
|
|
|
-
|
|
|
model.addAttribute("articleDetail", articleDetail);
|
|
|
|
|
|
- // -- Layout ---------------------------------------------
|
|
|
- model.addAttribute("title", articleDetail.getTitle() + "- 资讯详情");
|
|
|
+ // -- Layout -----------------------------------------------------
|
|
|
+ String titleTranslate = messageSource.getMessage("articleDetail.title", null, new Locale(lang));
|
|
|
+ model.addAttribute("title", articleDetail.getTitle() + " - " + titleTranslate);
|
|
|
+
|
|
|
+ // 重载页头信息
|
|
|
+ SiteInfo siteInfo = (SiteInfo) model.getAttribute("siteInfo");
|
|
|
+ siteInfo.setMeta_keyword(articleDetail.getMeta_keyword());
|
|
|
+ siteInfo.setMeta_description(articleDetail.getMeta_description());
|
|
|
+ model.addAttribute("siteInfo", siteInfo);
|
|
|
+
|
|
|
model.addAttribute("layout", "articleDetail");
|
|
|
return "layout/layout";
|
|
|
}
|