|
@@ -1,8 +1,13 @@
|
|
|
package com.backendsys.modules.common.aspect;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.backendsys.modules.cms.navigation.entity.Navigation;
|
|
|
+import com.backendsys.modules.cms.navigation.service.NavigationService;
|
|
|
import com.backendsys.modules.common.config.security.utils.HttpRequestUtil;
|
|
|
+import com.backendsys.modules.common.utils.CookieUtil;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.aspectj.lang.reflect.MethodSignature;
|
|
|
import org.springframework.ui.Model;
|
|
|
import com.backendsys.modules.cms.siteinfo.entity.SiteInfo;
|
|
@@ -12,9 +17,12 @@ import org.aspectj.lang.annotation.Aspect;
|
|
|
import org.aspectj.lang.annotation.Before;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
import org.springframework.web.method.HandlerMethod;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 视图自动添加:站点信息、导航
|
|
@@ -25,9 +33,12 @@ public class PagesAspect {
|
|
|
|
|
|
@Autowired
|
|
|
private HttpRequestUtil httpRequestUtil;
|
|
|
-
|
|
|
@Autowired
|
|
|
private SiteInfoService siteInfoService;
|
|
|
+ @Autowired
|
|
|
+ private NavigationService navigationService;
|
|
|
+
|
|
|
+
|
|
|
|
|
|
@Before("@annotation(org.springframework.web.bind.annotation.GetMapping) && @annotation(pages)")
|
|
|
public void beforeGet(JoinPoint joinPoint, Pages pages) {
|
|
@@ -45,8 +56,19 @@ public class PagesAspect {
|
|
|
if (arg instanceof Model) {
|
|
|
Model model = (Model) arg;
|
|
|
|
|
|
+ // [Cookie] 获得语种 (默认是:中文)
|
|
|
+ String default_lang = "zh";
|
|
|
+ String lang = CookieUtil.getCookie("lang", request);
|
|
|
+ if (StrUtil.isEmpty(lang)) {
|
|
|
+ lang = default_lang;
|
|
|
+ CookieUtil.setCookie("lang", lang);
|
|
|
+ }
|
|
|
+ System.out.println("(PagesAspect) lang = " + lang);
|
|
|
+
|
|
|
// [Get] 获取站点信息
|
|
|
model.addAttribute("siteInfo", siteInfoService.selectSiteInfo());
|
|
|
+ // [Get] 获取导航
|
|
|
+ model.addAttribute("navigation", navigationService.selectNavigationTemplate(lang));
|
|
|
|
|
|
// 其他信息
|
|
|
model.addAttribute("timestamp", DateUtil.current()); // 当前时间戳
|