refactor(cms): 重构网站信息相关代码
- 移除了不必要的系统输出语句 -优化了网站信息的获取和处理逻辑 - 重构了 CmsWebsiteService 接口和实现类 - 更新了相关的 VO 类和 Mapper XML 文件 - 添加了租户名称字段和相关处理逻辑
This commit is contained in:
@@ -108,7 +108,6 @@ public class BszxPayRankingController extends BaseController {
|
|||||||
return success(list);
|
return success(list);
|
||||||
}
|
}
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
System.out.println("item = " + item);
|
|
||||||
wrapper.clear();
|
wrapper.clear();
|
||||||
wrapper.eq(BszxPay::getGradeName,item.getGradeName());
|
wrapper.eq(BszxPay::getGradeName,item.getGradeName());
|
||||||
wrapper.eq(BszxPay::getClassName, item.getName());
|
wrapper.eq(BszxPay::getClassName, item.getName());
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ public class BszxBmServiceImpl extends ServiceImpl<BszxBmMapper, BszxBm> impleme
|
|||||||
final List<BszxClass> bszxClasses = bszxClassService.listRel(classParam);
|
final List<BszxClass> bszxClasses = bszxClassService.listRel(classParam);
|
||||||
if (!CollectionUtils.isEmpty(bszxClasses)) {
|
if (!CollectionUtils.isEmpty(bszxClasses)) {
|
||||||
BszxClass bszxClass = bszxClasses.get(0);
|
BszxClass bszxClass = bszxClasses.get(0);
|
||||||
System.out.println("bszxClass = " + bszxClass);
|
|
||||||
d.setClassId(bszxClass.getId());
|
d.setClassId(bszxClass.getId());
|
||||||
d.setBranchId(bszxClass.getBranch());
|
d.setBranchId(bszxClass.getBranch());
|
||||||
updateById(d);
|
updateById(d);
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ package com.gxwebsoft.cms.controller;
|
|||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.gxwebsoft.cms.service.CmsWebsiteService;
|
import com.gxwebsoft.cms.service.CmsWebsiteService;
|
||||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
import com.gxwebsoft.cms.vo.CmsVO;
|
||||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
|
||||||
import com.gxwebsoft.common.core.web.ApiResult;
|
import com.gxwebsoft.common.core.web.ApiResult;
|
||||||
import com.gxwebsoft.common.core.web.BaseController;
|
import com.gxwebsoft.common.core.web.BaseController;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
@@ -14,37 +13,29 @@ import org.springframework.web.bind.annotation.*;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网站信息记录表控制器
|
* 网站应用主入口
|
||||||
*
|
*
|
||||||
* @author 科技小王子
|
* @author 科技小王子
|
||||||
* @since 2024-09-10 20:36:14
|
* @since 2024-09-10 20:36:14
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Tag(name = "网站信息记录表管理")
|
@Tag(name = "网站应用")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api/cms")
|
@RequestMapping("/api/cms")
|
||||||
public class CmsMainController extends BaseController {
|
public class CmsMainController extends BaseController {
|
||||||
@Resource
|
@Resource
|
||||||
private CmsWebsiteService cmsWebsiteService;
|
private CmsWebsiteService cmsWebsiteService;
|
||||||
@Resource
|
|
||||||
private RedisUtil redisUtil;
|
|
||||||
|
|
||||||
private static final String SITE_INFO_KEY_PREFIX = "SiteInfo:";
|
|
||||||
private static final String MP_INFO_KEY_PREFIX = "MpInfo:";
|
|
||||||
private static final String SELECT_PAYMENT_KEY_PREFIX = "SelectPayment:";
|
|
||||||
private static final String SYS_DOMAIN_SUFFIX = ".websoft.top";
|
|
||||||
private static final String DOMAIN_SUFFIX = ".wsdns.cn";
|
|
||||||
|
|
||||||
@Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
@Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
||||||
@GetMapping("/getSiteInfo")
|
@GetMapping("/getSiteInfo")
|
||||||
public ApiResult<CmsWebsiteVO> getSiteInfo() {
|
public ApiResult<CmsVO> getSiteInfo() {
|
||||||
try {
|
try {
|
||||||
Integer tenantId = getTenantId();
|
Integer tenantId = getTenantId();
|
||||||
if (ObjectUtil.isEmpty(tenantId)) {
|
if (ObjectUtil.isEmpty(tenantId)) {
|
||||||
return fail("租户ID不能为空", null);
|
return fail("租户ID不能为空", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
CmsWebsiteVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
CmsVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||||
return success(websiteVO);
|
return success(websiteVO);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
return fail(e.getMessage(), null);
|
return fail(e.getMessage(), null);
|
||||||
@@ -56,18 +47,4 @@ public class CmsMainController extends BaseController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "清除缓存")
|
|
||||||
@DeleteMapping("/removeRedisByKey/{key}")
|
|
||||||
public ApiResult<?> removeRedisByKey(@PathVariable("key") String key) {
|
|
||||||
// 清除指定key
|
|
||||||
redisUtil.delete(key);
|
|
||||||
// 清除缓存
|
|
||||||
redisUtil.delete(SITE_INFO_KEY_PREFIX.concat(getTenantId().toString()));
|
|
||||||
// 清除小程序缓存
|
|
||||||
redisUtil.delete(MP_INFO_KEY_PREFIX.concat(getTenantId().toString()));
|
|
||||||
// 选择支付方式
|
|
||||||
redisUtil.delete(SELECT_PAYMENT_KEY_PREFIX.concat(getTenantId().toString()));
|
|
||||||
return success("清除成功");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import cn.hutool.core.util.ObjectUtil;
|
|||||||
import com.gxwebsoft.cms.entity.CmsWebsite;
|
import com.gxwebsoft.cms.entity.CmsWebsite;
|
||||||
import com.gxwebsoft.cms.param.CmsWebsiteParam;
|
import com.gxwebsoft.cms.param.CmsWebsiteParam;
|
||||||
import com.gxwebsoft.cms.service.CmsWebsiteService;
|
import com.gxwebsoft.cms.service.CmsWebsiteService;
|
||||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
import com.gxwebsoft.cms.vo.CmsVO;
|
||||||
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.ApiResult;
|
||||||
import com.gxwebsoft.common.core.web.BaseController;
|
import com.gxwebsoft.common.core.web.BaseController;
|
||||||
@@ -161,14 +161,14 @@ public class CmsWebsiteController extends BaseController {
|
|||||||
|
|
||||||
@Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
@Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
||||||
@GetMapping("/getSiteInfo")
|
@GetMapping("/getSiteInfo")
|
||||||
public ApiResult<CmsWebsiteVO> getSiteInfo() {
|
public ApiResult<CmsVO> getSiteInfo() {
|
||||||
try {
|
try {
|
||||||
Integer tenantId = getTenantId();
|
Integer tenantId = getTenantId();
|
||||||
if (ObjectUtil.isEmpty(tenantId)) {
|
if (ObjectUtil.isEmpty(tenantId)) {
|
||||||
return fail("租户ID不能为空", null);
|
return fail("租户ID不能为空", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
CmsWebsiteVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
CmsVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||||
|
|
||||||
return success(websiteVO);
|
return success(websiteVO);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
|
|||||||
@@ -244,6 +244,10 @@ public class CmsWebsite implements Serializable {
|
|||||||
@Schema(description = "租户id")
|
@Schema(description = "租户id")
|
||||||
private Integer tenantId;
|
private Integer tenantId;
|
||||||
|
|
||||||
|
@Schema(description = "租户名称")
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String tenantName;
|
||||||
|
|
||||||
@Schema(description = "创建时间")
|
@Schema(description = "创建时间")
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private LocalDateTime createTime;
|
private LocalDateTime createTime;
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
<!-- 关联查询sql -->
|
<!-- 关联查询sql -->
|
||||||
<sql id="selectSql">
|
<sql id="selectSql">
|
||||||
SELECT a.*
|
SELECT a.*, b.tenant_name as tenantName
|
||||||
FROM cms_website a
|
FROM cms_website a
|
||||||
|
LEFT JOIN gxwebsoft_core.sys_tenant b ON a.tenant_id = b.tenant_id
|
||||||
<where>
|
<where>
|
||||||
<if test="param.websiteId != null">
|
<if test="param.websiteId != null">
|
||||||
AND a.website_id = #{param.websiteId}
|
AND a.website_id = #{param.websiteId}
|
||||||
@@ -177,8 +178,9 @@
|
|||||||
|
|
||||||
|
|
||||||
<select id="getByTenantId" resultType="com.gxwebsoft.cms.entity.CmsWebsite">
|
<select id="getByTenantId" resultType="com.gxwebsoft.cms.entity.CmsWebsite">
|
||||||
SELECT a.*
|
SELECT a.*, b.tenant_name as tenantName
|
||||||
FROM cms_website a
|
FROM cms_website a
|
||||||
|
LEFT JOIN gxwebsoft_core.sys_tenant b ON a.tenant_id = b.tenant_id
|
||||||
<where>
|
<where>
|
||||||
<if test="tenantId != null">
|
<if test="tenantId != null">
|
||||||
AND a.tenant_id = #{tenantId}
|
AND a.tenant_id = #{tenantId}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import com.gxwebsoft.common.core.web.PageResult;
|
import com.gxwebsoft.common.core.web.PageResult;
|
||||||
import com.gxwebsoft.cms.entity.CmsWebsite;
|
import com.gxwebsoft.cms.entity.CmsWebsite;
|
||||||
import com.gxwebsoft.cms.param.CmsWebsiteParam;
|
import com.gxwebsoft.cms.param.CmsWebsiteParam;
|
||||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
import com.gxwebsoft.cms.vo.CmsVO;
|
||||||
import com.gxwebsoft.common.system.entity.User;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -60,7 +59,7 @@ public interface CmsWebsiteService extends IService<CmsWebsite> {
|
|||||||
* @param tenantId 租户ID
|
* @param tenantId 租户ID
|
||||||
* @return 网站信息VO
|
* @return 网站信息VO
|
||||||
*/
|
*/
|
||||||
CmsWebsiteVO getSiteInfo(Integer tenantId);
|
CmsVO getSiteInfo(Integer tenantId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除网站信息缓存
|
* 清除网站信息缓存
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import com.gxwebsoft.cms.entity.*;
|
|||||||
import com.gxwebsoft.cms.mapper.*;
|
import com.gxwebsoft.cms.mapper.*;
|
||||||
import com.gxwebsoft.cms.param.*;
|
import com.gxwebsoft.cms.param.*;
|
||||||
import com.gxwebsoft.cms.service.*;
|
import com.gxwebsoft.cms.service.*;
|
||||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
import com.gxwebsoft.cms.vo.CmsVO;
|
||||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||||
import com.gxwebsoft.common.core.web.PageParam;
|
import com.gxwebsoft.common.core.web.PageParam;
|
||||||
@@ -36,7 +36,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Service
|
@Service
|
||||||
public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebsite> implements CmsWebsiteService {
|
public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebsite> implements CmsWebsiteService {
|
||||||
|
|
||||||
private static final String SITE_INFO_KEY_PREFIX = "cms:site:info:";
|
private static final String SITE_INFO_KEY_PREFIX = "SiteInfo:";
|
||||||
@Resource
|
@Resource
|
||||||
private CmsWebsiteFieldMapper cmsWebsiteFieldMapper;
|
private CmsWebsiteFieldMapper cmsWebsiteFieldMapper;
|
||||||
@Resource
|
@Resource
|
||||||
@@ -313,7 +313,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CmsWebsiteVO getSiteInfo(Integer tenantId) {
|
public CmsVO getSiteInfo(Integer tenantId) {
|
||||||
// 参数验证
|
// 参数验证
|
||||||
if (ObjectUtil.isEmpty(tenantId)) {
|
if (ObjectUtil.isEmpty(tenantId)) {
|
||||||
throw new IllegalArgumentException("租户ID不能为空");
|
throw new IllegalArgumentException("租户ID不能为空");
|
||||||
@@ -325,7 +325,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
|||||||
if (StrUtil.isNotBlank(siteInfo)) {
|
if (StrUtil.isNotBlank(siteInfo)) {
|
||||||
log.info("从缓存获取网站信息,租户ID: {}", tenantId);
|
log.info("从缓存获取网站信息,租户ID: {}", tenantId);
|
||||||
try {
|
try {
|
||||||
return JSONUtil.parseObject(siteInfo, CmsWebsiteVO.class);
|
return JSONUtil.parseObject(siteInfo, CmsVO.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("缓存解析失败,从数据库重新获取: {}", e.getMessage());
|
log.warn("缓存解析失败,从数据库重新获取: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -333,6 +333,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
|||||||
|
|
||||||
// 从数据库获取站点信息
|
// 从数据库获取站点信息
|
||||||
CmsWebsite website = getWebsiteFromDatabase(tenantId);
|
CmsWebsite website = getWebsiteFromDatabase(tenantId);
|
||||||
|
|
||||||
if (website == null) {
|
if (website == null) {
|
||||||
throw new RuntimeException("请先创建站点");
|
throw new RuntimeException("请先创建站点");
|
||||||
}
|
}
|
||||||
@@ -341,10 +342,10 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
|||||||
buildCompleteWebsiteInfo(website);
|
buildCompleteWebsiteInfo(website);
|
||||||
|
|
||||||
// 处理过期时间
|
// 处理过期时间
|
||||||
// CmsWebsiteServiceImplHelper.processExpirationTime(website);
|
CmsWebsiteServiceImplHelper.processExpirationTime(website);
|
||||||
|
|
||||||
// 转换为VO对象
|
// 转换为VO对象
|
||||||
CmsWebsiteVO websiteVO = CmsWebsiteServiceImplHelper.convertToVO(website);
|
CmsVO websiteVO = CmsWebsiteServiceImplHelper.convertToVO(website);
|
||||||
|
|
||||||
// 缓存结果
|
// 缓存结果
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,15 +1,17 @@
|
|||||||
package com.gxwebsoft.cms.service.impl;
|
package com.gxwebsoft.cms.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.gxwebsoft.cms.entity.CmsNavigation;
|
import com.gxwebsoft.cms.entity.CmsNavigation;
|
||||||
import com.gxwebsoft.cms.entity.CmsWebsite;
|
import com.gxwebsoft.cms.entity.CmsWebsite;
|
||||||
import com.gxwebsoft.cms.vo.CmsNavigationVO;
|
import com.gxwebsoft.cms.vo.CmsNavigationVO;
|
||||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
import com.gxwebsoft.cms.vo.CmsVO;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,193 +28,195 @@ public class CmsWebsiteServiceImplHelper {
|
|||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
LocalDateTime expirationTime = website.getExpirationTime();
|
LocalDateTime expirationTime = website.getExpirationTime();
|
||||||
|
|
||||||
// 计算是否即将过期(30天内过期)
|
// 计算是否即将过期(30天内过期)
|
||||||
LocalDateTime thirtyDaysLater = now.plusDays(30);
|
LocalDateTime thirtyDaysLater = now.plusDays(30);
|
||||||
website.setSoon(expirationTime.isBefore(thirtyDaysLater) ? 1 : 0);
|
website.setSoon(expirationTime.isBefore(thirtyDaysLater) ? 1 : 0);
|
||||||
|
|
||||||
// 计算是否已过期
|
// 计算是否已过期
|
||||||
website.setExpired(expirationTime.isBefore(now) ? -1 : 1);
|
website.setExpired(expirationTime.isBefore(now) ? -1 : 1);
|
||||||
|
|
||||||
// 计算剩余天数
|
// 计算剩余天数
|
||||||
long daysBetween = ChronoUnit.DAYS.between(now, expirationTime);
|
long daysBetween = ChronoUnit.DAYS.between(now, expirationTime);
|
||||||
website.setExpiredDays(daysBetween);
|
website.setExpiredDays(daysBetween);
|
||||||
} else {
|
} else {
|
||||||
// 没有过期时间的默认值
|
// 没有过期时间的默认值
|
||||||
website.setSoon(0);
|
website.setSoon(0);
|
||||||
website.setExpired(1);
|
website.setExpired(1);
|
||||||
website.setExpiredDays(0L);
|
website.setExpiredDays(0L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将实体对象转换为VO对象
|
||||||
|
*/
|
||||||
|
public static CmsVO convertToVO(CmsWebsite website) {
|
||||||
|
CmsVO vo = new CmsVO();
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
|
System.out.println("website_tenantName = " + website.getTenantName());
|
||||||
|
// 基本信息
|
||||||
|
vo.setAppId(website.getTenantId());
|
||||||
|
vo.setAppName(website.getTenantName());
|
||||||
|
vo.setTitle(website.getWebsiteName());
|
||||||
|
vo.setKeywords(website.getKeywords());
|
||||||
|
vo.setDescription(website.getComments());
|
||||||
|
vo.setLogo(website.getWebsiteLogo());
|
||||||
|
vo.setMpQrCode(website.getWebsiteDarkLogo());
|
||||||
|
vo.setDomain(website.getDomain());
|
||||||
|
vo.setRunning(website.getRunning());
|
||||||
|
vo.setVersion(website.getVersion());
|
||||||
|
vo.setCreateTime(website.getCreateTime());
|
||||||
|
|
||||||
|
// 时间字段 - 格式化为字符串
|
||||||
|
if (website.getExpirationTime() != null) {
|
||||||
|
vo.setExpirationTime(website.getExpirationTime().format(formatter));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 过期相关信息
|
||||||
|
vo.setExpired(website.getExpired());
|
||||||
|
vo.setExpiredDays(website.getExpiredDays());
|
||||||
|
vo.setSoon(website.getSoon());
|
||||||
|
|
||||||
|
// 状态信息
|
||||||
|
vo.setStatusIcon(website.getStatusIcon());
|
||||||
|
vo.setStatusText(website.getStatusText());
|
||||||
|
|
||||||
|
// 复杂对象
|
||||||
|
vo.setConfig(website.getConfig());
|
||||||
|
vo.setServerTime(website.getServerTime());
|
||||||
|
vo.setSetting(website.getSetting()); // CmsWebsiteSetting对象可以直接设置给Object类型
|
||||||
|
|
||||||
|
// 导航信息
|
||||||
|
vo.setTopNavs(convertNavigationToVO(website.getTopNavs()));
|
||||||
|
vo.setBottomNavs(convertNavigationToVO(website.getBottomNavs()));
|
||||||
|
|
||||||
|
return vo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全转换 target 字段为整数
|
||||||
|
*
|
||||||
|
* @param target 字符串类型的 target 值
|
||||||
|
* @return 对应的整数值
|
||||||
|
*/
|
||||||
|
private static Integer convertTargetToInteger(String target) {
|
||||||
|
if (target == null) {
|
||||||
|
return 0; // 默认值:当前窗口
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (target.toLowerCase()) {
|
||||||
|
case "_self":
|
||||||
|
return 0; // 当前窗口
|
||||||
|
case "_blank":
|
||||||
|
return 1; // 新窗口
|
||||||
|
default:
|
||||||
|
// 如果是数字字符串,尝试直接转换
|
||||||
|
try {
|
||||||
|
return Integer.valueOf(target);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 转换失败时返回默认值
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将实体对象转换为VO对象
|
* 转换导航列表为VO
|
||||||
*/
|
*/
|
||||||
public static CmsWebsiteVO convertToVO(CmsWebsite website) {
|
public static List<CmsNavigationVO> convertNavigationToVO(List<CmsNavigation> navigations) {
|
||||||
CmsWebsiteVO vo = new CmsWebsiteVO();
|
if (navigations == null) {
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
return null;
|
||||||
|
|
||||||
// 基本信息
|
|
||||||
vo.setWebsiteId(website.getWebsiteId());
|
|
||||||
vo.setWebsiteName(website.getWebsiteName());
|
|
||||||
vo.setWebsiteCode(website.getWebsiteCode());
|
|
||||||
vo.setWebsiteTitle(website.getWebsiteName());
|
|
||||||
vo.setWebsiteKeywords(website.getKeywords());
|
|
||||||
vo.setWebsiteDescription(website.getContent()); // 使用 content 字段作为描述
|
|
||||||
vo.setWebsiteLogo(website.getWebsiteLogo());
|
|
||||||
vo.setWebsiteIcon(website.getWebsiteIcon());
|
|
||||||
vo.setDomain(website.getDomain());
|
|
||||||
vo.setRunning(website.getRunning());
|
|
||||||
vo.setVersion(website.getVersion());
|
|
||||||
|
|
||||||
// 时间字段 - 格式化为字符串
|
|
||||||
if (website.getExpirationTime() != null) {
|
|
||||||
vo.setExpirationTime(website.getExpirationTime().format(formatter));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 过期相关信息
|
|
||||||
vo.setExpired(website.getExpired());
|
|
||||||
vo.setExpiredDays(website.getExpiredDays());
|
|
||||||
vo.setSoon(website.getSoon());
|
|
||||||
|
|
||||||
// 状态信息
|
|
||||||
vo.setStatusIcon(website.getStatusIcon());
|
|
||||||
vo.setStatusText(website.getStatusText());
|
|
||||||
|
|
||||||
// 复杂对象
|
|
||||||
vo.setConfig(website.getConfig());
|
|
||||||
vo.setServerTime(website.getServerTime());
|
|
||||||
vo.setSetting(website.getSetting()); // CmsWebsiteSetting对象可以直接设置给Object类型
|
|
||||||
|
|
||||||
// 导航信息
|
|
||||||
vo.setTopNavs(convertNavigationToVO(website.getTopNavs()));
|
|
||||||
vo.setBottomNavs(convertNavigationToVO(website.getBottomNavs()));
|
|
||||||
|
|
||||||
return vo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
return navigations.stream().map(nav -> {
|
||||||
* 安全转换 target 字段为整数
|
CmsNavigationVO navVO = new CmsNavigationVO();
|
||||||
* @param target 字符串类型的 target 值
|
navVO.setNavigationId(nav.getNavigationId());
|
||||||
* @return 对应的整数值
|
navVO.setNavigationName(nav.getTitle()); // 修复:使用 title 字段
|
||||||
*/
|
navVO.setNavigationUrl(nav.getPath()); // 修复:使用 path 字段
|
||||||
private static Integer convertTargetToInteger(String target) {
|
navVO.setNavigationIcon(nav.getIcon()); // 修复:使用 icon 字段
|
||||||
if (target == null) {
|
navVO.setNavigationColor(nav.getColor()); // 修复:使用 color 字段
|
||||||
return 0; // 默认值:当前窗口
|
navVO.setParentId(nav.getParentId());
|
||||||
}
|
navVO.setSort(nav.getSortNumber()); // 修复:使用 sortNumber 字段
|
||||||
|
navVO.setHide(nav.getHide());
|
||||||
|
navVO.setTop(nav.getTop());
|
||||||
|
// 安全转换 target 字段:将字符串值映射为整数
|
||||||
|
navVO.setTarget(convertTargetToInteger(nav.getTarget()));
|
||||||
|
navVO.setNavigationType(nav.getModel()); // 修复:使用 model 字段
|
||||||
|
|
||||||
switch (target.toLowerCase()) {
|
// 递归处理子导航
|
||||||
case "_self":
|
if (nav.getChildren() != null) {
|
||||||
return 0; // 当前窗口
|
navVO.setChildren(convertNavigationToVO(nav.getChildren()));
|
||||||
case "_blank":
|
}
|
||||||
return 1; // 新窗口
|
|
||||||
default:
|
return navVO;
|
||||||
// 如果是数字字符串,尝试直接转换
|
}).collect(Collectors.toList());
|
||||||
try {
|
}
|
||||||
return Integer.valueOf(target);
|
|
||||||
} catch (NumberFormatException e) {
|
/**
|
||||||
// 转换失败时返回默认值
|
* 设置网站状态
|
||||||
return 0;
|
*/
|
||||||
}
|
public static void setWebsiteStatus(CmsWebsite website) {
|
||||||
}
|
if (website.getRunning() != null) {
|
||||||
|
switch (website.getRunning()) {
|
||||||
|
case 0:
|
||||||
|
website.setStatusIcon("🔴");
|
||||||
|
website.setStatusText("未开通");
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
website.setStatusIcon("🟢");
|
||||||
|
website.setStatusText("正常运行");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
website.setStatusIcon("🟡");
|
||||||
|
website.setStatusText("维护中");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
website.setStatusIcon("🔴");
|
||||||
|
website.setStatusText("违规关停");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
website.setStatusIcon("❓");
|
||||||
|
website.setStatusText("未知状态");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转换导航列表为VO
|
* 设置网站配置
|
||||||
*/
|
*/
|
||||||
public static List<CmsNavigationVO> convertNavigationToVO(List<CmsNavigation> navigations) {
|
public static void setWebsiteConfig(CmsWebsite website) {
|
||||||
if (navigations == null) {
|
HashMap<String, Object> config = new HashMap<>();
|
||||||
return null;
|
config.put("websiteName", website.getWebsiteName());
|
||||||
}
|
config.put("websiteComments", website.getComments());
|
||||||
|
config.put("websiteTitle", website.getWebsiteName());
|
||||||
|
config.put("websiteKeywords", website.getKeywords());
|
||||||
|
config.put("websiteDescription", website.getContent()); // 使用 content 字段作为描述
|
||||||
|
config.put("websiteLogo", website.getWebsiteLogo());
|
||||||
|
config.put("websiteIcon", website.getWebsiteIcon());
|
||||||
|
config.put("domain", website.getDomain());
|
||||||
|
website.setConfig(config);
|
||||||
|
}
|
||||||
|
|
||||||
return navigations.stream().map(nav -> {
|
/**
|
||||||
CmsNavigationVO navVO = new CmsNavigationVO();
|
* 设置服务器时间信息
|
||||||
navVO.setNavigationId(nav.getNavigationId());
|
*/
|
||||||
navVO.setNavigationName(nav.getTitle()); // 修复:使用 title 字段
|
public static void setServerTimeInfo(CmsWebsite website) {
|
||||||
navVO.setNavigationUrl(nav.getPath()); // 修复:使用 path 字段
|
HashMap<String, Object> serverTime = new HashMap<>();
|
||||||
navVO.setNavigationIcon(nav.getIcon()); // 修复:使用 icon 字段
|
LocalDateTime now = LocalDateTime.now();
|
||||||
navVO.setNavigationColor(nav.getColor()); // 修复:使用 color 字段
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||||
navVO.setParentId(nav.getParentId());
|
|
||||||
navVO.setSort(nav.getSortNumber()); // 修复:使用 sortNumber 字段
|
|
||||||
navVO.setHide(nav.getHide());
|
|
||||||
navVO.setTop(nav.getTop());
|
|
||||||
// 安全转换 target 字段:将字符串值映射为整数
|
|
||||||
navVO.setTarget(convertTargetToInteger(nav.getTarget()));
|
|
||||||
navVO.setNavigationType(nav.getModel()); // 修复:使用 model 字段
|
|
||||||
|
|
||||||
// 递归处理子导航
|
serverTime.put("currentTime", now.format(formatter));
|
||||||
if (nav.getChildren() != null) {
|
serverTime.put("timestamp", System.currentTimeMillis());
|
||||||
navVO.setChildren(convertNavigationToVO(nav.getChildren()));
|
serverTime.put("timezone", "Asia/Shanghai");
|
||||||
}
|
|
||||||
|
|
||||||
return navVO;
|
website.setServerTime(serverTime);
|
||||||
}).collect(Collectors.toList());
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置网站状态
|
* 设置网站设置信息
|
||||||
*/
|
*/
|
||||||
public static void setWebsiteStatus(CmsWebsite website) {
|
public static void setWebsiteSetting(CmsWebsite website) {
|
||||||
if (website.getRunning() != null) {
|
// 这里可以根据需要设置网站的其他设置信息
|
||||||
switch (website.getRunning()) {
|
// 暂时设置为null,因为setting字段类型是CmsWebsiteSetting而不是HashMap
|
||||||
case 0:
|
website.setSetting(null);
|
||||||
website.setStatusIcon("🔴");
|
}
|
||||||
website.setStatusText("未开通");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
website.setStatusIcon("🟢");
|
|
||||||
website.setStatusText("正常运行");
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
website.setStatusIcon("🟡");
|
|
||||||
website.setStatusText("维护中");
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
website.setStatusIcon("🔴");
|
|
||||||
website.setStatusText("违规关停");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
website.setStatusIcon("❓");
|
|
||||||
website.setStatusText("未知状态");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置网站配置
|
|
||||||
*/
|
|
||||||
public static void setWebsiteConfig(CmsWebsite website) {
|
|
||||||
HashMap<String, Object> config = new HashMap<>();
|
|
||||||
config.put("websiteName", website.getWebsiteName());
|
|
||||||
config.put("websiteTitle", website.getWebsiteName());
|
|
||||||
config.put("websiteKeywords", website.getKeywords());
|
|
||||||
config.put("websiteDescription", website.getContent()); // 使用 content 字段作为描述
|
|
||||||
config.put("websiteLogo", website.getWebsiteLogo());
|
|
||||||
config.put("websiteIcon", website.getWebsiteIcon());
|
|
||||||
config.put("domain", website.getDomain());
|
|
||||||
website.setConfig(config);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置服务器时间信息
|
|
||||||
*/
|
|
||||||
public static void setServerTimeInfo(CmsWebsite website) {
|
|
||||||
HashMap<String, Object> serverTime = new HashMap<>();
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
|
|
||||||
serverTime.put("currentTime", now.format(formatter));
|
|
||||||
serverTime.put("timestamp", System.currentTimeMillis());
|
|
||||||
serverTime.put("timezone", "Asia/Shanghai");
|
|
||||||
|
|
||||||
website.setServerTime(serverTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置网站设置信息
|
|
||||||
*/
|
|
||||||
public static void setWebsiteSetting(CmsWebsite website) {
|
|
||||||
// 这里可以根据需要设置网站的其他设置信息
|
|
||||||
// 暂时设置为null,因为setting字段类型是CmsWebsiteSetting而不是HashMap
|
|
||||||
website.setSetting(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,43 +4,47 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 网站信息视图对象
|
* 应用信息
|
||||||
* 专门用于前端展示,只包含前端需要的字段
|
* 专门用于前端展示,只包含前端需要的字段
|
||||||
*
|
*
|
||||||
* @author WebSoft
|
* @author WebSoft
|
||||||
* @since 2025-01-12
|
* @since 2025-01-12
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Schema(description = "网站信息视图对象")
|
@Schema(description = "应用信息视图对象")
|
||||||
public class CmsWebsiteVO implements Serializable {
|
public class CmsVO implements Serializable {
|
||||||
|
|
||||||
@Schema(description = "网站ID")
|
@Schema(description = "应用ID")
|
||||||
private Integer websiteId;
|
private Integer appId;
|
||||||
|
|
||||||
@Schema(description = "网站名称")
|
@Schema(description = "应用名称")
|
||||||
private String websiteName;
|
private String appName;
|
||||||
|
|
||||||
@Schema(description = "网站代码")
|
@Schema(description = "应用介绍")
|
||||||
private String websiteCode;
|
private String description;
|
||||||
|
|
||||||
@Schema(description = "网站标题")
|
|
||||||
private String websiteTitle;
|
|
||||||
|
|
||||||
@Schema(description = "网站关键词")
|
@Schema(description = "网站关键词")
|
||||||
private String websiteKeywords;
|
private String keywords;
|
||||||
|
|
||||||
@Schema(description = "网站描述")
|
@Schema(description = "应用编号")
|
||||||
private String websiteDescription;
|
private String appCode;
|
||||||
|
|
||||||
@Schema(description = "网站LOGO")
|
@Schema(description = "小程序二维码")
|
||||||
private String websiteLogo;
|
private String mpQrCode;
|
||||||
|
|
||||||
@Schema(description = "网站图标")
|
@Schema(description = "标题")
|
||||||
private String websiteIcon;
|
private String title;
|
||||||
|
|
||||||
|
@Schema(description = "LOGO")
|
||||||
|
private String logo;
|
||||||
|
|
||||||
|
@Schema(description = "图标")
|
||||||
|
private String icon;
|
||||||
|
|
||||||
@Schema(description = "域名")
|
@Schema(description = "域名")
|
||||||
private String domain;
|
private String domain;
|
||||||
@@ -54,6 +58,9 @@ public class CmsWebsiteVO implements Serializable {
|
|||||||
@Schema(description = "服务到期时间")
|
@Schema(description = "服务到期时间")
|
||||||
private String expirationTime;
|
private String expirationTime;
|
||||||
|
|
||||||
|
@Schema(description = "创建时间")
|
||||||
|
private LocalDateTime createTime;
|
||||||
|
|
||||||
@Schema(description = "是否到期 -1已过期 1未过期")
|
@Schema(description = "是否到期 -1已过期 1未过期")
|
||||||
private Integer expired;
|
private Integer expired;
|
||||||
|
|
||||||
@@ -74,7 +74,8 @@ public class SecurityConfig {
|
|||||||
"/api/shop/merchant-account/getMerchantAccountByPhone",
|
"/api/shop/merchant-account/getMerchantAccountByPhone",
|
||||||
"/api/hjm/hjm-car/**",
|
"/api/hjm/hjm-car/**",
|
||||||
"/api/chat/**",
|
"/api/chat/**",
|
||||||
"/api/shop/shop-order/test"
|
"/api/shop/shop-order/test",
|
||||||
|
"/api/cms/getSiteInfo"
|
||||||
)
|
)
|
||||||
.permitAll()
|
.permitAll()
|
||||||
.anyRequest()
|
.anyRequest()
|
||||||
|
|||||||
@@ -136,7 +136,6 @@ public class HjmBxLogController extends BaseController {
|
|||||||
@Operation(summary = "上传文件")
|
@Operation(summary = "上传文件")
|
||||||
@PostMapping("/upload")
|
@PostMapping("/upload")
|
||||||
public ApiResult<FileRecord> upload(@RequestParam MultipartFile file, HttpServletRequest request) {
|
public ApiResult<FileRecord> upload(@RequestParam MultipartFile file, HttpServletRequest request) {
|
||||||
System.out.println("request = " + request);
|
|
||||||
FileRecord result = null;
|
FileRecord result = null;
|
||||||
try {
|
try {
|
||||||
String dir = getUploadDir();
|
String dir = getUploadDir();
|
||||||
|
|||||||
Reference in New Issue
Block a user