|
@ -5,23 +5,19 @@ |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import cn.hutool.core.util.StrUtil; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
import com.gxwebsoft.cms.entity.CmsNavigation; |
|
|
|
|
|
import com.gxwebsoft.cms.entity.CmsWebsite; |
|
|
|
|
|
import com.gxwebsoft.cms.entity.CmsWebsiteField; |
|
|
|
|
|
import com.gxwebsoft.cms.entity.CmsWebsiteSetting; |
|
|
|
|
|
|
|
|
import com.gxwebsoft.cms.entity.*; |
|
|
import com.gxwebsoft.cms.param.CmsNavigationParam; |
|
|
import com.gxwebsoft.cms.param.CmsNavigationParam; |
|
|
import com.gxwebsoft.cms.param.CmsWebsiteParam; |
|
|
|
|
|
import com.gxwebsoft.cms.service.CmsNavigationService; |
|
|
import com.gxwebsoft.cms.service.CmsNavigationService; |
|
|
import com.gxwebsoft.cms.service.CmsWebsiteFieldService; |
|
|
import com.gxwebsoft.cms.service.CmsWebsiteFieldService; |
|
|
import com.gxwebsoft.cms.service.CmsWebsiteService; |
|
|
|
|
|
import com.gxwebsoft.cms.service.CmsWebsiteSettingService; |
|
|
import com.gxwebsoft.cms.service.CmsWebsiteSettingService; |
|
|
import com.gxwebsoft.cms.vo.CmsVO; |
|
|
|
|
|
import com.gxwebsoft.common.core.utils.CommonUtil; |
|
|
import com.gxwebsoft.common.core.utils.CommonUtil; |
|
|
import com.gxwebsoft.common.core.utils.RedisUtil; |
|
|
import com.gxwebsoft.common.core.utils.RedisUtil; |
|
|
import com.gxwebsoft.common.core.web.ApiResult; |
|
|
|
|
|
import com.gxwebsoft.common.core.web.BaseController; |
|
|
import com.gxwebsoft.common.core.web.BaseController; |
|
|
import com.gxwebsoft.common.core.web.BatchParam; |
|
|
|
|
|
|
|
|
import com.gxwebsoft.cms.service.CmsWebsiteService; |
|
|
|
|
|
import com.gxwebsoft.cms.param.CmsWebsiteParam; |
|
|
|
|
|
import com.gxwebsoft.common.core.web.ApiResult; |
|
|
import com.gxwebsoft.common.core.web.PageResult; |
|
|
import com.gxwebsoft.common.core.web.PageResult; |
|
|
|
|
|
import com.gxwebsoft.common.core.web.BatchParam; |
|
|
import com.gxwebsoft.common.system.entity.User; |
|
|
import com.gxwebsoft.common.system.entity.User; |
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
import io.swagger.v3.oas.annotations.Operation; |
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
|
import io.swagger.v3.oas.annotations.tags.Tag; |
|
@ -30,8 +26,8 @@ |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.util.HashMap; |
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -50,11 +46,11 @@ |
|
|
@Resource |
|
|
@Resource |
|
|
private RedisUtil redisUtil; |
|
|
private RedisUtil redisUtil; |
|
|
@Resource |
|
|
@Resource |
|
|
|
|
|
private CmsWebsiteFieldService cmsWebsiteFieldService; |
|
|
|
|
|
@Resource |
|
|
private CmsNavigationService cmsNavigationService; |
|
|
private CmsNavigationService cmsNavigationService; |
|
|
@Resource |
|
|
@Resource |
|
|
private CmsWebsiteSettingService cmsWebsiteSettingService; |
|
|
private CmsWebsiteSettingService cmsWebsiteSettingService; |
|
|
@Resource |
|
|
|
|
|
private CmsWebsiteFieldService cmsWebsiteFieldService; |
|
|
|
|
|
|
|
|
|
|
|
private static final String SITE_INFO_KEY_PREFIX = "SiteInfo:"; |
|
|
private static final String SITE_INFO_KEY_PREFIX = "SiteInfo:"; |
|
|
private static final String MP_INFO_KEY_PREFIX = "MpInfo:"; |
|
|
private static final String MP_INFO_KEY_PREFIX = "MpInfo:"; |
|
@ -182,51 +178,119 @@ |
|
|
@Operation(summary = "网站基本信息") |
|
|
@Operation(summary = "网站基本信息") |
|
|
@GetMapping("/getSiteInfo") |
|
|
@GetMapping("/getSiteInfo") |
|
|
public ApiResult<CmsWebsite> getSiteInfo() { |
|
|
public ApiResult<CmsWebsite> getSiteInfo() { |
|
|
if (ObjectUtil.isEmpty(getTenantId())) { |
|
|
|
|
|
return fail("参数不正确", null); |
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
Integer tenantId = getTenantId(); |
|
|
|
|
|
if (ObjectUtil.isEmpty(tenantId)) { |
|
|
|
|
|
return fail("租户ID不能为空", null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
String key = SITE_INFO_KEY_PREFIX + getTenantId(); |
|
|
|
|
|
|
|
|
String key = SITE_INFO_KEY_PREFIX + tenantId; |
|
|
|
|
|
|
|
|
|
|
|
// 尝试从缓存获取
|
|
|
|
|
|
try { |
|
|
final String siteInfo = redisUtil.get(key); |
|
|
final String siteInfo = redisUtil.get(key); |
|
|
if (StrUtil.isNotBlank(siteInfo)) { |
|
|
if (StrUtil.isNotBlank(siteInfo)) { |
|
|
log.info("从缓存获取网站信息: = {}", key); |
|
|
log.info("从缓存获取网站信息: = {}", key); |
|
|
|
|
|
// 可以启用缓存返回,但先注释掉确保数据最新
|
|
|
// return success(JSONUtil.parseObject(siteInfo, CmsWebsite.class));
|
|
|
// return success(JSONUtil.parseObject(siteInfo, CmsWebsite.class));
|
|
|
} |
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("获取缓存失败: {}", e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 获取站点信息
|
|
|
// 获取站点信息
|
|
|
CmsWebsite website = cmsWebsiteService.getOne(new LambdaQueryWrapper<CmsWebsite>().eq(CmsWebsite::getDeleted, 0).last("limit 1")); |
|
|
|
|
|
|
|
|
CmsWebsite website = null; |
|
|
|
|
|
try { |
|
|
|
|
|
website = cmsWebsiteService.getOne(new LambdaQueryWrapper<CmsWebsite>() |
|
|
|
|
|
.eq(CmsWebsite::getTenantId, tenantId) |
|
|
|
|
|
.eq(CmsWebsite::getDeleted, 0) |
|
|
|
|
|
.last("limit 1")); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("查询站点信息失败: {}", e.getMessage(), e); |
|
|
|
|
|
return fail("查询站点信息失败", null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 创建默认站点
|
|
|
// 创建默认站点
|
|
|
if (ObjectUtil.isEmpty(website)) { |
|
|
if (ObjectUtil.isEmpty(website)) { |
|
|
return success("请先创建站点...", null); |
|
|
return success("请先创建站点...", null); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 站点异常状态
|
|
|
|
|
|
|
|
|
// 安全地构建网站信息
|
|
|
|
|
|
try { |
|
|
|
|
|
buildSafeWebsiteInfo(website); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("构建网站信息失败: {}", e.getMessage(), e); |
|
|
|
|
|
return fail("构建网站信息失败", null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 缓存结果
|
|
|
|
|
|
try { |
|
|
|
|
|
redisUtil.set(key, website, 1L, TimeUnit.DAYS); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("缓存网站信息失败: {}", e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return success(website); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("获取网站信息异常: {}", e.getMessage(), e); |
|
|
|
|
|
return fail("获取网站信息失败: " + e.getMessage(), null); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 安全地构建网站信息 |
|
|
|
|
|
*/ |
|
|
|
|
|
private void buildSafeWebsiteInfo(CmsWebsite website) { |
|
|
|
|
|
if (website == null) { |
|
|
|
|
|
throw new IllegalArgumentException("网站对象不能为空"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 1. 设置网站状态
|
|
|
|
|
|
try { |
|
|
setWebsiteStatus(website); |
|
|
setWebsiteStatus(website); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("设置网站状态失败: {}", e.getMessage()); |
|
|
|
|
|
website.setStatus(0); // 默认状态
|
|
|
|
|
|
website.setStatusText("状态未知"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 站点配置参数
|
|
|
|
|
|
HashMap<String, Object> config = buildWebsiteConfig(website); |
|
|
|
|
|
|
|
|
// 2. 构建配置信息
|
|
|
|
|
|
try { |
|
|
|
|
|
HashMap<String, Object> config = buildSafeWebsiteConfig(website); |
|
|
website.setConfig(config); |
|
|
website.setConfig(config); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("构建网站配置失败: {}", e.getMessage()); |
|
|
|
|
|
website.setConfig(new HashMap<>()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 网站导航
|
|
|
|
|
|
setWebsiteNavigation(website); |
|
|
|
|
|
|
|
|
// 3. 设置导航信息
|
|
|
|
|
|
try { |
|
|
|
|
|
setSafeWebsiteNavigation(website); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("设置网站导航失败: {}", e.getMessage()); |
|
|
|
|
|
website.setTopNavs(new ArrayList<>()); |
|
|
|
|
|
website.setBottomNavs(new ArrayList<>()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 网站设置信息
|
|
|
|
|
|
|
|
|
// 4. 设置网站设置信息
|
|
|
|
|
|
try { |
|
|
setWebsiteSetting(website); |
|
|
setWebsiteSetting(website); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("设置网站设置失败: {}", e.getMessage()); |
|
|
|
|
|
// 设置为null,让前端知道没有设置信息
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 服务器时间
|
|
|
|
|
|
HashMap<String, Object> serverTime = buildServerTime(); |
|
|
|
|
|
|
|
|
// 5. 构建服务器时间(使用LocalDateTime)
|
|
|
|
|
|
try { |
|
|
|
|
|
HashMap<String, Object> serverTime = buildSafeServerTime(); |
|
|
website.setServerTime(serverTime); |
|
|
website.setServerTime(serverTime); |
|
|
|
|
|
|
|
|
// 即将过期(一周内过期的)
|
|
|
|
|
|
website.setSoon(DateUtil.offsetDay(website.getExpirationTime(), -30).compareTo(DateUtil.date())); |
|
|
|
|
|
// 是否过期 -1已过期 大于0 未过期
|
|
|
|
|
|
website.setExpired(website.getExpirationTime().compareTo(DateUtil.date())); |
|
|
|
|
|
// 剩余天数
|
|
|
|
|
|
website.setExpiredDays(DateUtil.betweenDay(website.getExpirationTime(), DateUtil.date(), false)); |
|
|
|
|
|
|
|
|
|
|
|
redisUtil.set(key, website, 1L, TimeUnit.DAYS); |
|
|
|
|
|
return success(website); |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("构建服务器时间失败: {}", e.getMessage()); |
|
|
|
|
|
HashMap<String, Object> defaultTime = new HashMap<>(); |
|
|
|
|
|
defaultTime.put("now", java.time.LocalDateTime.now().toString()); |
|
|
|
|
|
website.setServerTime(defaultTime); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void setWebsiteStatus(CmsWebsite website) { |
|
|
private void setWebsiteStatus(CmsWebsite website) { |
|
@ -259,39 +323,133 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private HashMap<String, Object> buildWebsiteConfig(CmsWebsite website) { |
|
|
private HashMap<String, Object> buildWebsiteConfig(CmsWebsite website) { |
|
|
|
|
|
return buildSafeWebsiteConfig(website); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private HashMap<String, Object> buildSafeWebsiteConfig(CmsWebsite website) { |
|
|
HashMap<String, Object> config = new HashMap<>(); |
|
|
HashMap<String, Object> config = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 获取网站字段配置
|
|
|
LambdaQueryWrapper<CmsWebsiteField> wrapper = new LambdaQueryWrapper<>(); |
|
|
LambdaQueryWrapper<CmsWebsiteField> wrapper = new LambdaQueryWrapper<>(); |
|
|
wrapper.eq(CmsWebsiteField::getDeleted, 0); |
|
|
wrapper.eq(CmsWebsiteField::getDeleted, 0); |
|
|
final List<CmsWebsiteField> fields = cmsWebsiteFieldService.list(wrapper); |
|
|
final List<CmsWebsiteField> fields = cmsWebsiteFieldService.list(wrapper); |
|
|
fields.forEach(d -> { |
|
|
|
|
|
config.put(d.getName(), d.getValue()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fields != null && !fields.isEmpty()) { |
|
|
|
|
|
fields.forEach(field -> { |
|
|
|
|
|
if (field != null && StrUtil.isNotBlank(field.getName())) { |
|
|
|
|
|
config.put(field.getName(), field.getValue() != null ? field.getValue() : ""); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
config.put("SysDomain", getSysDomain(website)); |
|
|
|
|
|
config.put("Domain", getDomain(website)); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("获取网站字段配置失败: {}", e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 安全地设置域名信息
|
|
|
|
|
|
try { |
|
|
|
|
|
config.put("SysDomain", getSafeSysDomain(website)); |
|
|
|
|
|
config.put("Domain", getSafeDomain(website)); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("设置域名信息失败: {}", e.getMessage()); |
|
|
|
|
|
config.put("SysDomain", website.getTenantId() + ".websoft.top"); |
|
|
|
|
|
config.put("Domain", website.getTenantId() + ".wsdns.cn"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return config; |
|
|
return config; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String getSysDomain(CmsWebsite website) { |
|
|
private String getSysDomain(CmsWebsite website) { |
|
|
return StrUtil.isNotBlank(website.getWebsiteCode()) ? website.getWebsiteCode() + SYS_DOMAIN_SUFFIX : website.getTenantId() + SYS_DOMAIN_SUFFIX; |
|
|
|
|
|
|
|
|
return getSafeSysDomain(website); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String getDomain(CmsWebsite website) { |
|
|
private String getDomain(CmsWebsite website) { |
|
|
return StrUtil.isNotBlank(website.getDomain()) ? website.getDomain() : website.getWebsiteCode() + DOMAIN_SUFFIX; |
|
|
|
|
|
|
|
|
return getSafeDomain(website); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getSafeSysDomain(CmsWebsite website) { |
|
|
|
|
|
if (website == null || website.getTenantId() == null) { |
|
|
|
|
|
return "unknown.websoft.top"; |
|
|
|
|
|
} |
|
|
|
|
|
return StrUtil.isNotBlank(website.getWebsiteCode()) ? |
|
|
|
|
|
website.getWebsiteCode() + SYS_DOMAIN_SUFFIX : |
|
|
|
|
|
website.getTenantId() + SYS_DOMAIN_SUFFIX; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String getSafeDomain(CmsWebsite website) { |
|
|
|
|
|
if (website == null || website.getTenantId() == null) { |
|
|
|
|
|
return "unknown.wsdns.cn"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (StrUtil.isNotBlank(website.getDomain())) { |
|
|
|
|
|
return website.getDomain(); |
|
|
|
|
|
} |
|
|
|
|
|
if (StrUtil.isNotBlank(website.getWebsiteCode())) { |
|
|
|
|
|
return website.getWebsiteCode() + DOMAIN_SUFFIX; |
|
|
|
|
|
} |
|
|
|
|
|
return website.getTenantId() + DOMAIN_SUFFIX; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void setWebsiteNavigation(CmsWebsite website) { |
|
|
private void setWebsiteNavigation(CmsWebsite website) { |
|
|
final CmsNavigationParam navigationParam = new CmsNavigationParam(); |
|
|
|
|
|
navigationParam.setHide(0); |
|
|
|
|
|
navigationParam.setTop(0); |
|
|
|
|
|
navigationParam.setBottom(null); |
|
|
|
|
|
final List<CmsNavigation> topNavs = cmsNavigationService.listRel(navigationParam); |
|
|
|
|
|
// 顶部菜单
|
|
|
|
|
|
website.setTopNavs(CommonUtil.toTreeData(topNavs, 0, CmsNavigation::getParentId, CmsNavigation::getNavigationId, CmsNavigation::setChildren)); |
|
|
|
|
|
navigationParam.setTop(null); |
|
|
|
|
|
navigationParam.setBottom(0); |
|
|
|
|
|
final List<CmsNavigation> bottomNavs = cmsNavigationService.listRel(navigationParam); |
|
|
|
|
|
// 底部菜单
|
|
|
|
|
|
website.setBottomNavs(CommonUtil.toTreeData(bottomNavs, 0, CmsNavigation::getParentId, CmsNavigation::getNavigationId, CmsNavigation::setChildren)); |
|
|
|
|
|
|
|
|
setSafeWebsiteNavigation(website); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setSafeWebsiteNavigation(CmsWebsite website) { |
|
|
|
|
|
if (website == null) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置顶部导航
|
|
|
|
|
|
try { |
|
|
|
|
|
final CmsNavigationParam topParam = new CmsNavigationParam(); |
|
|
|
|
|
topParam.setHide(0); |
|
|
|
|
|
topParam.setTop(0); |
|
|
|
|
|
topParam.setBottom(null); |
|
|
|
|
|
final List<CmsNavigation> topNavs = cmsNavigationService.listRel(topParam); |
|
|
|
|
|
|
|
|
|
|
|
if (topNavs != null && !topNavs.isEmpty()) { |
|
|
|
|
|
try { |
|
|
|
|
|
website.setTopNavs(CommonUtil.toTreeData(topNavs, 0, |
|
|
|
|
|
CmsNavigation::getParentId, |
|
|
|
|
|
CmsNavigation::getNavigationId, |
|
|
|
|
|
CmsNavigation::setChildren)); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("构建顶部导航树失败: {}", e.getMessage()); |
|
|
|
|
|
website.setTopNavs(new ArrayList<>(topNavs)); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
website.setTopNavs(new ArrayList<>()); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("获取顶部导航失败: {}", e.getMessage()); |
|
|
|
|
|
website.setTopNavs(new ArrayList<>()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 设置底部导航
|
|
|
|
|
|
try { |
|
|
|
|
|
final CmsNavigationParam bottomParam = new CmsNavigationParam(); |
|
|
|
|
|
bottomParam.setHide(0); |
|
|
|
|
|
bottomParam.setTop(null); |
|
|
|
|
|
bottomParam.setBottom(0); |
|
|
|
|
|
final List<CmsNavigation> bottomNavs = cmsNavigationService.listRel(bottomParam); |
|
|
|
|
|
|
|
|
|
|
|
if (bottomNavs != null && !bottomNavs.isEmpty()) { |
|
|
|
|
|
try { |
|
|
|
|
|
website.setBottomNavs(CommonUtil.toTreeData(bottomNavs, 0, |
|
|
|
|
|
CmsNavigation::getParentId, |
|
|
|
|
|
CmsNavigation::getNavigationId, |
|
|
|
|
|
CmsNavigation::setChildren)); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("构建底部导航树失败: {}", e.getMessage()); |
|
|
|
|
|
website.setBottomNavs(new ArrayList<>(bottomNavs)); |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
website.setBottomNavs(new ArrayList<>()); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.warn("获取底部导航失败: {}", e.getMessage()); |
|
|
|
|
|
website.setBottomNavs(new ArrayList<>()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void setWebsiteSetting(CmsWebsite website) { |
|
|
private void setWebsiteSetting(CmsWebsite website) { |
|
@ -302,25 +460,50 @@ |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private HashMap<String, Object> buildServerTime() { |
|
|
private HashMap<String, Object> buildServerTime() { |
|
|
|
|
|
return buildSafeServerTime(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private HashMap<String, Object> buildSafeServerTime() { |
|
|
HashMap<String, Object> serverTime = new HashMap<>(); |
|
|
HashMap<String, Object> serverTime = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
// 使用 LocalDateTime 替代 DateTime
|
|
|
|
|
|
java.time.LocalDateTime now = java.time.LocalDateTime.now(); |
|
|
|
|
|
java.time.LocalDate today = java.time.LocalDate.now(); |
|
|
|
|
|
|
|
|
|
|
|
// 当前时间
|
|
|
|
|
|
serverTime.put("now", now.toString()); |
|
|
|
|
|
|
|
|
// 今天日期
|
|
|
// 今天日期
|
|
|
DateTime date = DateUtil.date(); |
|
|
|
|
|
String today = DateUtil.today(); |
|
|
|
|
|
|
|
|
serverTime.put("today", today.toString()); |
|
|
|
|
|
|
|
|
// 明天日期
|
|
|
// 明天日期
|
|
|
final DateTime dateTime = DateUtil.tomorrow(); |
|
|
|
|
|
String tomorrow = DateUtil.format(dateTime, "yyyy-MM-dd"); |
|
|
|
|
|
|
|
|
java.time.LocalDate tomorrow = today.plusDays(1); |
|
|
|
|
|
serverTime.put("tomorrow", tomorrow.toString()); |
|
|
|
|
|
|
|
|
// 后天日期
|
|
|
// 后天日期
|
|
|
final DateTime dateTime2 = DateUtil.offsetDay(date, 2); |
|
|
|
|
|
final String afterDay = DateUtil.format(dateTime2, "yyyy-MM-dd"); |
|
|
|
|
|
// 今天星期几
|
|
|
|
|
|
final int week = DateUtil.thisDayOfWeek(); |
|
|
|
|
|
final DateTime nextWeek = DateUtil.nextWeek(); |
|
|
|
|
|
serverTime.put("now", DateUtil.now()); |
|
|
|
|
|
serverTime.put("today", today); |
|
|
|
|
|
serverTime.put("tomorrow", tomorrow); |
|
|
|
|
|
serverTime.put("afterDay", afterDay); |
|
|
|
|
|
|
|
|
java.time.LocalDate afterDay = today.plusDays(2); |
|
|
|
|
|
serverTime.put("afterDay", afterDay.toString()); |
|
|
|
|
|
|
|
|
|
|
|
// 今天星期几 (1=Monday, 7=Sunday)
|
|
|
|
|
|
int week = today.getDayOfWeek().getValue(); |
|
|
serverTime.put("week", week); |
|
|
serverTime.put("week", week); |
|
|
serverTime.put("nextWeek", nextWeek); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 下周同一天
|
|
|
|
|
|
java.time.LocalDate nextWeek = today.plusWeeks(1); |
|
|
|
|
|
serverTime.put("nextWeek", nextWeek.toString()); |
|
|
|
|
|
|
|
|
|
|
|
// 时间戳
|
|
|
|
|
|
serverTime.put("timestamp", System.currentTimeMillis()); |
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("构建服务器时间失败: {}", e.getMessage(), e); |
|
|
|
|
|
// 提供最基本的时间信息
|
|
|
|
|
|
serverTime.put("now", java.time.LocalDateTime.now().toString()); |
|
|
|
|
|
serverTime.put("today", java.time.LocalDate.now().toString()); |
|
|
|
|
|
serverTime.put("timestamp", System.currentTimeMillis()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return serverTime; |
|
|
return serverTime; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|