refactor(cms): 重构网站信息相关代码
- 移除了不必要的系统输出语句 -优化了网站信息的获取和处理逻辑 - 重构了 CmsWebsiteService 接口和实现类 - 更新了相关的 VO 类和 Mapper XML 文件 - 添加了租户名称字段和相关处理逻辑
This commit is contained in:
@@ -108,7 +108,6 @@ public class BszxPayRankingController extends BaseController {
|
||||
return success(list);
|
||||
}
|
||||
list.forEach(item -> {
|
||||
System.out.println("item = " + item);
|
||||
wrapper.clear();
|
||||
wrapper.eq(BszxPay::getGradeName,item.getGradeName());
|
||||
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);
|
||||
if (!CollectionUtils.isEmpty(bszxClasses)) {
|
||||
BszxClass bszxClass = bszxClasses.get(0);
|
||||
System.out.println("bszxClass = " + bszxClass);
|
||||
d.setClassId(bszxClass.getId());
|
||||
d.setBranchId(bszxClass.getBranch());
|
||||
updateById(d);
|
||||
|
||||
@@ -2,8 +2,7 @@ package com.gxwebsoft.cms.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.gxwebsoft.cms.service.CmsWebsiteService;
|
||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.cms.vo.CmsVO;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -14,37 +13,29 @@ import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 网站信息记录表控制器
|
||||
* 网站应用主入口
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-09-10 20:36:14
|
||||
*/
|
||||
@Slf4j
|
||||
@Tag(name = "网站信息记录表管理")
|
||||
@Tag(name = "网站应用")
|
||||
@RestController
|
||||
@RequestMapping("/api/cms")
|
||||
public class CmsMainController extends BaseController {
|
||||
@Resource
|
||||
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 = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
||||
@GetMapping("/getSiteInfo")
|
||||
public ApiResult<CmsWebsiteVO> getSiteInfo() {
|
||||
public ApiResult<CmsVO> getSiteInfo() {
|
||||
try {
|
||||
Integer tenantId = getTenantId();
|
||||
if (ObjectUtil.isEmpty(tenantId)) {
|
||||
return fail("租户ID不能为空", null);
|
||||
}
|
||||
|
||||
CmsWebsiteVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||
CmsVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||
return success(websiteVO);
|
||||
} catch (IllegalArgumentException e) {
|
||||
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.param.CmsWebsiteParam;
|
||||
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.BaseController;
|
||||
@@ -161,14 +161,14 @@ public class CmsWebsiteController extends BaseController {
|
||||
|
||||
@Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
||||
@GetMapping("/getSiteInfo")
|
||||
public ApiResult<CmsWebsiteVO> getSiteInfo() {
|
||||
public ApiResult<CmsVO> getSiteInfo() {
|
||||
try {
|
||||
Integer tenantId = getTenantId();
|
||||
if (ObjectUtil.isEmpty(tenantId)) {
|
||||
return fail("租户ID不能为空", null);
|
||||
}
|
||||
|
||||
CmsWebsiteVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||
CmsVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||
|
||||
return success(websiteVO);
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
@@ -244,6 +244,10 @@ public class CmsWebsite implements Serializable {
|
||||
@Schema(description = "租户id")
|
||||
private Integer tenantId;
|
||||
|
||||
@Schema(description = "租户名称")
|
||||
@TableField(exist = false)
|
||||
private String tenantName;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@@ -4,8 +4,9 @@
|
||||
|
||||
<!-- 关联查询sql -->
|
||||
<sql id="selectSql">
|
||||
SELECT a.*
|
||||
SELECT a.*, b.tenant_name as tenantName
|
||||
FROM cms_website a
|
||||
LEFT JOIN gxwebsoft_core.sys_tenant b ON a.tenant_id = b.tenant_id
|
||||
<where>
|
||||
<if test="param.websiteId != null">
|
||||
AND a.website_id = #{param.websiteId}
|
||||
@@ -177,8 +178,9 @@
|
||||
|
||||
|
||||
<select id="getByTenantId" resultType="com.gxwebsoft.cms.entity.CmsWebsite">
|
||||
SELECT a.*
|
||||
SELECT a.*, b.tenant_name as tenantName
|
||||
FROM cms_website a
|
||||
LEFT JOIN gxwebsoft_core.sys_tenant b ON a.tenant_id = b.tenant_id
|
||||
<where>
|
||||
<if test="tenantId != null">
|
||||
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.cms.entity.CmsWebsite;
|
||||
import com.gxwebsoft.cms.param.CmsWebsiteParam;
|
||||
import com.gxwebsoft.cms.vo.CmsWebsiteVO;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.cms.vo.CmsVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -60,7 +59,7 @@ public interface CmsWebsiteService extends IService<CmsWebsite> {
|
||||
* @param tenantId 租户ID
|
||||
* @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.param.*;
|
||||
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.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
@@ -36,7 +36,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
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
|
||||
private CmsWebsiteFieldMapper cmsWebsiteFieldMapper;
|
||||
@Resource
|
||||
@@ -313,7 +313,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
||||
}
|
||||
|
||||
@Override
|
||||
public CmsWebsiteVO getSiteInfo(Integer tenantId) {
|
||||
public CmsVO getSiteInfo(Integer tenantId) {
|
||||
// 参数验证
|
||||
if (ObjectUtil.isEmpty(tenantId)) {
|
||||
throw new IllegalArgumentException("租户ID不能为空");
|
||||
@@ -325,7 +325,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
||||
if (StrUtil.isNotBlank(siteInfo)) {
|
||||
log.info("从缓存获取网站信息,租户ID: {}", tenantId);
|
||||
try {
|
||||
return JSONUtil.parseObject(siteInfo, CmsWebsiteVO.class);
|
||||
return JSONUtil.parseObject(siteInfo, CmsVO.class);
|
||||
} catch (Exception e) {
|
||||
log.warn("缓存解析失败,从数据库重新获取: {}", e.getMessage());
|
||||
}
|
||||
@@ -333,6 +333,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
||||
|
||||
// 从数据库获取站点信息
|
||||
CmsWebsite website = getWebsiteFromDatabase(tenantId);
|
||||
|
||||
if (website == null) {
|
||||
throw new RuntimeException("请先创建站点");
|
||||
}
|
||||
@@ -341,10 +342,10 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
||||
buildCompleteWebsiteInfo(website);
|
||||
|
||||
// 处理过期时间
|
||||
// CmsWebsiteServiceImplHelper.processExpirationTime(website);
|
||||
CmsWebsiteServiceImplHelper.processExpirationTime(website);
|
||||
|
||||
// 转换为VO对象
|
||||
CmsWebsiteVO websiteVO = CmsWebsiteServiceImplHelper.convertToVO(website);
|
||||
CmsVO websiteVO = CmsWebsiteServiceImplHelper.convertToVO(website);
|
||||
|
||||
// 缓存结果
|
||||
try {
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package com.gxwebsoft.cms.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.gxwebsoft.cms.entity.CmsNavigation;
|
||||
import com.gxwebsoft.cms.entity.CmsWebsite;
|
||||
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.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -47,22 +49,22 @@ public class CmsWebsiteServiceImplHelper {
|
||||
/**
|
||||
* 将实体对象转换为VO对象
|
||||
*/
|
||||
public static CmsWebsiteVO convertToVO(CmsWebsite website) {
|
||||
CmsWebsiteVO vo = new CmsWebsiteVO();
|
||||
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.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.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) {
|
||||
@@ -92,6 +94,7 @@ public class CmsWebsiteServiceImplHelper {
|
||||
|
||||
/**
|
||||
* 安全转换 target 字段为整数
|
||||
*
|
||||
* @param target 字符串类型的 target 值
|
||||
* @return 对应的整数值
|
||||
*/
|
||||
@@ -183,6 +186,7 @@ public class CmsWebsiteServiceImplHelper {
|
||||
public static void setWebsiteConfig(CmsWebsite website) {
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
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 字段作为描述
|
||||
|
||||
@@ -4,43 +4,47 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 网站信息视图对象
|
||||
* 应用信息
|
||||
* 专门用于前端展示,只包含前端需要的字段
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2025-01-12
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "网站信息视图对象")
|
||||
public class CmsWebsiteVO implements Serializable {
|
||||
@Schema(description = "应用信息视图对象")
|
||||
public class CmsVO implements Serializable {
|
||||
|
||||
@Schema(description = "网站ID")
|
||||
private Integer websiteId;
|
||||
@Schema(description = "应用ID")
|
||||
private Integer appId;
|
||||
|
||||
@Schema(description = "网站名称")
|
||||
private String websiteName;
|
||||
@Schema(description = "应用名称")
|
||||
private String appName;
|
||||
|
||||
@Schema(description = "网站代码")
|
||||
private String websiteCode;
|
||||
|
||||
@Schema(description = "网站标题")
|
||||
private String websiteTitle;
|
||||
@Schema(description = "应用介绍")
|
||||
private String description;
|
||||
|
||||
@Schema(description = "网站关键词")
|
||||
private String websiteKeywords;
|
||||
private String keywords;
|
||||
|
||||
@Schema(description = "网站描述")
|
||||
private String websiteDescription;
|
||||
@Schema(description = "应用编号")
|
||||
private String appCode;
|
||||
|
||||
@Schema(description = "网站LOGO")
|
||||
private String websiteLogo;
|
||||
@Schema(description = "小程序二维码")
|
||||
private String mpQrCode;
|
||||
|
||||
@Schema(description = "网站图标")
|
||||
private String websiteIcon;
|
||||
@Schema(description = "标题")
|
||||
private String title;
|
||||
|
||||
@Schema(description = "LOGO")
|
||||
private String logo;
|
||||
|
||||
@Schema(description = "图标")
|
||||
private String icon;
|
||||
|
||||
@Schema(description = "域名")
|
||||
private String domain;
|
||||
@@ -54,6 +58,9 @@ public class CmsWebsiteVO implements Serializable {
|
||||
@Schema(description = "服务到期时间")
|
||||
private String expirationTime;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@Schema(description = "是否到期 -1已过期 1未过期")
|
||||
private Integer expired;
|
||||
|
||||
@@ -74,7 +74,8 @@ public class SecurityConfig {
|
||||
"/api/shop/merchant-account/getMerchantAccountByPhone",
|
||||
"/api/hjm/hjm-car/**",
|
||||
"/api/chat/**",
|
||||
"/api/shop/shop-order/test"
|
||||
"/api/shop/shop-order/test",
|
||||
"/api/cms/getSiteInfo"
|
||||
)
|
||||
.permitAll()
|
||||
.anyRequest()
|
||||
|
||||
@@ -136,7 +136,6 @@ public class HjmBxLogController extends BaseController {
|
||||
@Operation(summary = "上传文件")
|
||||
@PostMapping("/upload")
|
||||
public ApiResult<FileRecord> upload(@RequestParam MultipartFile file, HttpServletRequest request) {
|
||||
System.out.println("request = " + request);
|
||||
FileRecord result = null;
|
||||
try {
|
||||
String dir = getUploadDir();
|
||||
|
||||
Reference in New Issue
Block a user