refactor(cms): 重构网站信息获取功能
- 新增 CmsWebsiteVO 和 CmsNavigationVO 类用于前端展示 - 重构 getSiteInfo 方法,优化缓存逻辑和数据处理 - 新增 clearSiteInfoCache 方法用于清除缓存 - 优化网站状态、配置和导航信息的处理逻辑
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
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.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 网站信息记录表控制器
|
||||
*
|
||||
* @author 科技小王子
|
||||
* @since 2024-09-10 20:36:14
|
||||
*/
|
||||
@Slf4j
|
||||
@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() {
|
||||
try {
|
||||
Integer tenantId = getTenantId();
|
||||
if (ObjectUtil.isEmpty(tenantId)) {
|
||||
return fail("租户ID不能为空", null);
|
||||
}
|
||||
|
||||
CmsWebsiteVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||
return success(websiteVO);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return fail(e.getMessage(), null);
|
||||
} catch (RuntimeException e) {
|
||||
return fail(e.getMessage(), null);
|
||||
} catch (Exception e) {
|
||||
log.error("获取网站信息失败", e);
|
||||
return fail("获取网站信息失败", null);
|
||||
}
|
||||
}
|
||||
|
||||
@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("清除成功");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,37 +1,24 @@
|
||||
package com.gxwebsoft.cms.controller;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.cms.entity.*;
|
||||
import com.gxwebsoft.cms.param.CmsNavigationParam;
|
||||
import com.gxwebsoft.cms.service.CmsNavigationService;
|
||||
import com.gxwebsoft.cms.service.CmsWebsiteFieldService;
|
||||
import com.gxwebsoft.cms.service.CmsWebsiteSettingService;
|
||||
import com.gxwebsoft.common.core.utils.CommonUtil;
|
||||
import com.gxwebsoft.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.cms.service.CmsWebsiteService;
|
||||
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.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.core.web.BatchParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 网站信息记录表控制器
|
||||
@@ -44,298 +31,168 @@ import java.util.concurrent.TimeUnit;
|
||||
@RestController
|
||||
@RequestMapping("/api/cms/cms-website")
|
||||
public class CmsWebsiteController extends BaseController {
|
||||
@Resource
|
||||
private CmsWebsiteService cmsWebsiteService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private CmsWebsiteFieldService cmsWebsiteFieldService;
|
||||
@Resource
|
||||
private CmsNavigationService cmsNavigationService;
|
||||
@Resource
|
||||
private CmsWebsiteSettingService cmsWebsiteSettingService;
|
||||
@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";
|
||||
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 = "分页查询网站信息记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<CmsWebsite>> page(CmsWebsiteParam param) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.pageRel(param));
|
||||
}
|
||||
|
||||
@Operation(summary = "查询全部网站信息记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<CmsWebsite>> list(CmsWebsiteParam param) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.listRel(param));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询网站信息记录表")
|
||||
@GetMapping("/pageAll")
|
||||
public ApiResult<PageResult<CmsWebsite>> pageAll(CmsWebsiteParam param) {
|
||||
return success(cmsWebsiteService.pageRelAll(param));
|
||||
}
|
||||
|
||||
@Operation(summary = "根据id查询网站信息记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<CmsWebsite> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.getByIdRel(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "根据id查询网站信息记录表")
|
||||
@GetMapping("/getAll/{id}")
|
||||
public ApiResult<CmsWebsite> getAll(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.getByIdRelAll(id));
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:save')")
|
||||
@Operation(summary = "添加网站信息记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody CmsWebsite cmsWebsite) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
cmsWebsite.setLoginUser(loginUser);
|
||||
return success("创建成功", cmsWebsiteService.create(cmsWebsite));
|
||||
}
|
||||
return fail("创建失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:update')")
|
||||
@Operation(summary = "修改网站信息记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody CmsWebsite cmsWebsite) {
|
||||
if (cmsWebsiteService.updateById(cmsWebsite)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:update')")
|
||||
@Operation(summary = "修改网站信息记录表")
|
||||
@PutMapping("/updateAll")
|
||||
public ApiResult<?> updateAll(@RequestBody CmsWebsite cmsWebsite) {
|
||||
if (cmsWebsiteService.updateByIdAll(cmsWebsite)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:remove')")
|
||||
@Operation(summary = "删除网站信息记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (cmsWebsiteService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:remove')")
|
||||
@Operation(summary = "删除网站信息记录表")
|
||||
@DeleteMapping("/removeAll/{id}")
|
||||
public ApiResult<?> removeAll(@PathVariable("id") Integer id) {
|
||||
if (cmsWebsiteService.removeByIdAll(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:save')")
|
||||
@Operation(summary = "批量添加网站信息记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<CmsWebsite> list) {
|
||||
if (cmsWebsiteService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:update')")
|
||||
@Operation(summary = "批量修改网站信息记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<CmsWebsite> batchParam) {
|
||||
if (batchParam.update(cmsWebsiteService, "website_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:remove')")
|
||||
@Operation(summary = "批量删除网站信息记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (cmsWebsiteService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "网站基本信息")
|
||||
@GetMapping("/getSiteInfo")
|
||||
public ApiResult<CmsWebsite> getSiteInfo() {
|
||||
if (ObjectUtil.isEmpty(getTenantId())) {
|
||||
return fail("参数不正确", null);
|
||||
@Operation(summary = "分页查询网站信息记录表")
|
||||
@GetMapping("/page")
|
||||
public ApiResult<PageResult<CmsWebsite>> page(CmsWebsiteParam param) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.pageRel(param));
|
||||
}
|
||||
|
||||
String key = SITE_INFO_KEY_PREFIX + getTenantId();
|
||||
final String siteInfo = redisUtil.get(key);
|
||||
if (StrUtil.isNotBlank(siteInfo)) {
|
||||
log.info("从缓存获取网站信息: = {}", key);
|
||||
// return success(JSONUtil.parseObject(siteInfo, CmsWebsite.class));
|
||||
@Operation(summary = "查询全部网站信息记录表")
|
||||
@GetMapping()
|
||||
public ApiResult<List<CmsWebsite>> list(CmsWebsiteParam param) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.listRel(param));
|
||||
}
|
||||
|
||||
// 获取站点信息
|
||||
CmsWebsite website = cmsWebsiteService.getOne(new LambdaQueryWrapper<CmsWebsite>().eq(CmsWebsite::getDeleted, 0).last("limit 1"));
|
||||
|
||||
// 创建默认站点
|
||||
if (ObjectUtil.isEmpty(website)) {
|
||||
return success("请先创建站点...", null);
|
||||
@Operation(summary = "分页查询网站信息记录表")
|
||||
@GetMapping("/pageAll")
|
||||
public ApiResult<PageResult<CmsWebsite>> pageAll(CmsWebsiteParam param) {
|
||||
return success(cmsWebsiteService.pageRelAll(param));
|
||||
}
|
||||
|
||||
// 站点异常状态
|
||||
setWebsiteStatus(website);
|
||||
|
||||
// 站点配置参数
|
||||
HashMap<String, Object> config = buildWebsiteConfig(website);
|
||||
website.setConfig(config);
|
||||
|
||||
// 网站导航
|
||||
setWebsiteNavigation(website);
|
||||
|
||||
// 网站设置信息
|
||||
setWebsiteSetting(website);
|
||||
|
||||
// 服务器时间
|
||||
HashMap<String, Object> serverTime = buildServerTime();
|
||||
website.setServerTime(serverTime);
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 即将过期(一周内过期的)
|
||||
website.setSoon(website.getExpirationTime().minusDays(30).compareTo(now));
|
||||
// 是否过期 -1已过期 大于0 未过期
|
||||
website.setExpired(website.getExpirationTime().compareTo(now));
|
||||
// 剩余天数
|
||||
website.setExpiredDays(java.time.temporal.ChronoUnit.DAYS.between(now, website.getExpirationTime()));
|
||||
|
||||
redisUtil.set(key, website, 1L, TimeUnit.DAYS);
|
||||
return success(website);
|
||||
}
|
||||
|
||||
private void setWebsiteStatus(CmsWebsite website) {
|
||||
if (!website.getRunning().equals(1)) {
|
||||
// 未开通
|
||||
if (website.getRunning().equals(0)) {
|
||||
website.setStatusIcon("error");
|
||||
website.setStatusText("该站点未开通");
|
||||
}
|
||||
// 维护中
|
||||
if (website.getRunning().equals(2)) {
|
||||
website.setStatusIcon("warning");
|
||||
}
|
||||
// 已关闭
|
||||
if (website.getRunning().equals(3)) {
|
||||
website.setStatusIcon("error");
|
||||
website.setStatusText("已关闭");
|
||||
}
|
||||
// 已欠费停机
|
||||
if (website.getRunning().equals(4)) {
|
||||
website.setStatusIcon("error");
|
||||
website.setStatusText("已欠费停机");
|
||||
}
|
||||
// 违规关停
|
||||
if (website.getRunning().equals(5)) {
|
||||
website.setStatusIcon("error");
|
||||
website.setStatusText("违规关停");
|
||||
}
|
||||
@Operation(summary = "根据id查询网站信息记录表")
|
||||
@GetMapping("/{id}")
|
||||
public ApiResult<CmsWebsite> get(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.getByIdRel(id));
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Object> buildWebsiteConfig(CmsWebsite website) {
|
||||
HashMap<String, Object> config = new HashMap<>();
|
||||
LambdaQueryWrapper<CmsWebsiteField> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CmsWebsiteField::getDeleted, 0);
|
||||
final List<CmsWebsiteField> fields = cmsWebsiteFieldService.list(wrapper);
|
||||
fields.forEach(d -> {
|
||||
config.put(d.getName(), d.getValue());
|
||||
});
|
||||
config.put("SysDomain", getSysDomain(website));
|
||||
config.put("Domain", getDomain(website));
|
||||
return config;
|
||||
}
|
||||
|
||||
private String getSysDomain(CmsWebsite website) {
|
||||
return StrUtil.isNotBlank(website.getWebsiteCode()) ? website.getWebsiteCode() + SYS_DOMAIN_SUFFIX : website.getTenantId() + SYS_DOMAIN_SUFFIX;
|
||||
}
|
||||
|
||||
private String getDomain(CmsWebsite website) {
|
||||
return StrUtil.isNotBlank(website.getDomain()) ? website.getDomain() : website.getWebsiteCode() + DOMAIN_SUFFIX;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
private void setWebsiteSetting(CmsWebsite website) {
|
||||
final CmsWebsiteSetting setting = cmsWebsiteSettingService.getOne(new LambdaQueryWrapper<CmsWebsiteSetting>().eq(CmsWebsiteSetting::getWebsiteId, website.getWebsiteId()));
|
||||
if (ObjectUtil.isNotEmpty(setting)) {
|
||||
website.setSetting(setting);
|
||||
@Operation(summary = "根据id查询网站信息记录表")
|
||||
@GetMapping("/getAll/{id}")
|
||||
public ApiResult<CmsWebsite> getAll(@PathVariable("id") Integer id) {
|
||||
// 使用关联查询
|
||||
return success(cmsWebsiteService.getByIdRelAll(id));
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, Object> buildServerTime() {
|
||||
HashMap<String, Object> serverTime = new HashMap<>();
|
||||
// 今天日期
|
||||
DateTime date = DateUtil.date();
|
||||
String today = DateUtil.today();
|
||||
// 明天日期
|
||||
final DateTime dateTime = DateUtil.tomorrow();
|
||||
String tomorrow = DateUtil.format(dateTime, "yyyy-MM-dd");
|
||||
// 后天日期
|
||||
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);
|
||||
serverTime.put("week", week);
|
||||
serverTime.put("nextWeek", nextWeek);
|
||||
return serverTime;
|
||||
}
|
||||
@PreAuthorize("hasAuthority('cms:website:save')")
|
||||
@Operation(summary = "添加网站信息记录表")
|
||||
@PostMapping()
|
||||
public ApiResult<?> save(@RequestBody CmsWebsite cmsWebsite) {
|
||||
// 记录当前登录用户id
|
||||
User loginUser = getLoginUser();
|
||||
if (loginUser != null) {
|
||||
cmsWebsite.setLoginUser(loginUser);
|
||||
return success("创建成功", cmsWebsiteService.create(cmsWebsite));
|
||||
}
|
||||
return fail("创建失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "清除缓存")
|
||||
@DeleteMapping("/clearSiteInfo/{key}")
|
||||
public ApiResult<?> clearSiteInfo(@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("清除成功");
|
||||
}
|
||||
@PreAuthorize("hasAuthority('cms:website:update')")
|
||||
@Operation(summary = "修改网站信息记录表")
|
||||
@PutMapping()
|
||||
public ApiResult<?> update(@RequestBody CmsWebsite cmsWebsite) {
|
||||
if (cmsWebsiteService.updateById(cmsWebsite)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:update')")
|
||||
@Operation(summary = "修改网站信息记录表")
|
||||
@PutMapping("/updateAll")
|
||||
public ApiResult<?> updateAll(@RequestBody CmsWebsite cmsWebsite) {
|
||||
if (cmsWebsiteService.updateByIdAll(cmsWebsite)) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:remove')")
|
||||
@Operation(summary = "删除网站信息记录表")
|
||||
@DeleteMapping("/{id}")
|
||||
public ApiResult<?> remove(@PathVariable("id") Integer id) {
|
||||
if (cmsWebsiteService.removeById(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:remove')")
|
||||
@Operation(summary = "删除网站信息记录表")
|
||||
@DeleteMapping("/removeAll/{id}")
|
||||
public ApiResult<?> removeAll(@PathVariable("id") Integer id) {
|
||||
if (cmsWebsiteService.removeByIdAll(id)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:save')")
|
||||
@Operation(summary = "批量添加网站信息记录表")
|
||||
@PostMapping("/batch")
|
||||
public ApiResult<?> saveBatch(@RequestBody List<CmsWebsite> list) {
|
||||
if (cmsWebsiteService.saveBatch(list)) {
|
||||
return success("添加成功");
|
||||
}
|
||||
return fail("添加失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:update')")
|
||||
@Operation(summary = "批量修改网站信息记录表")
|
||||
@PutMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody BatchParam<CmsWebsite> batchParam) {
|
||||
if (batchParam.update(cmsWebsiteService, "website_id")) {
|
||||
return success("修改成功");
|
||||
}
|
||||
return fail("修改失败");
|
||||
}
|
||||
|
||||
@PreAuthorize("hasAuthority('cms:website:remove')")
|
||||
@Operation(summary = "批量删除网站信息记录表")
|
||||
@DeleteMapping("/batch")
|
||||
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
|
||||
if (cmsWebsiteService.removeByIds(ids)) {
|
||||
return success("删除成功");
|
||||
}
|
||||
return fail("删除失败");
|
||||
}
|
||||
|
||||
@Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等")
|
||||
@GetMapping("/getSiteInfo")
|
||||
public ApiResult<CmsWebsiteVO> getSiteInfo() {
|
||||
try {
|
||||
Integer tenantId = getTenantId();
|
||||
if (ObjectUtil.isEmpty(tenantId)) {
|
||||
return fail("租户ID不能为空", null);
|
||||
}
|
||||
|
||||
CmsWebsiteVO websiteVO = cmsWebsiteService.getSiteInfo(tenantId);
|
||||
return success(websiteVO);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return fail(e.getMessage(), null);
|
||||
} catch (RuntimeException e) {
|
||||
return fail(e.getMessage(), null);
|
||||
} catch (Exception e) {
|
||||
log.error("获取网站信息失败", e);
|
||||
return fail("获取网站信息失败", null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Operation(summary = "清除缓存")
|
||||
@DeleteMapping("/clearSiteInfo/{key}")
|
||||
public ApiResult<?> clearSiteInfo(@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("清除成功");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.time.LocalDateTime;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
@@ -169,7 +170,7 @@ public class CmsNavigation implements Serializable {
|
||||
private Integer tenantId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonIgnore // 导航的创建时间前端不需要
|
||||
private LocalDateTime createTime;
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +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 java.util.List;
|
||||
@@ -52,4 +53,19 @@ public interface CmsWebsiteService extends IService<CmsWebsite> {
|
||||
boolean removeByIdAll(Integer id);
|
||||
|
||||
CmsWebsite getByTenantId(Integer tenantId);
|
||||
|
||||
/**
|
||||
* 获取网站基本信息(VO格式)
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
* @return 网站信息VO
|
||||
*/
|
||||
CmsWebsiteVO getSiteInfo(Integer tenantId);
|
||||
|
||||
/**
|
||||
* 清除网站信息缓存
|
||||
*
|
||||
* @param tenantId 租户ID
|
||||
*/
|
||||
void clearSiteInfoCache(Integer tenantId);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.gxwebsoft.cms.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
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.common.core.utils.JSONUtil;
|
||||
import com.gxwebsoft.common.core.utils.RedisUtil;
|
||||
import com.gxwebsoft.common.core.web.PageParam;
|
||||
import com.gxwebsoft.common.core.web.PageResult;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
@@ -18,6 +20,11 @@ import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 网站信息记录表Service实现
|
||||
@@ -25,8 +32,11 @@ import java.util.List;
|
||||
* @author 科技小王子
|
||||
* @since 2024-09-10 20:36:14
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebsite> implements CmsWebsiteService {
|
||||
|
||||
private static final String SITE_INFO_KEY_PREFIX = "cms:site:info:";
|
||||
@Resource
|
||||
private CmsWebsiteFieldMapper cmsWebsiteFieldMapper;
|
||||
@Resource
|
||||
@@ -62,6 +72,8 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
||||
@Resource
|
||||
private ProjectService projectService;
|
||||
@Resource
|
||||
private RedisUtil redisUtil;
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private CompanyService companyService;
|
||||
@@ -302,4 +314,103 @@ public class CmsWebsiteServiceImpl extends ServiceImpl<CmsWebsiteMapper, CmsWebs
|
||||
return baseMapper.getByTenantId(tenantId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CmsWebsiteVO getSiteInfo(Integer tenantId) {
|
||||
// 参数验证
|
||||
if (ObjectUtil.isEmpty(tenantId)) {
|
||||
throw new IllegalArgumentException("租户ID不能为空");
|
||||
}
|
||||
|
||||
// 尝试从缓存获取
|
||||
String cacheKey = SITE_INFO_KEY_PREFIX + tenantId;
|
||||
String siteInfo = redisUtil.get(cacheKey);
|
||||
if (StrUtil.isNotBlank(siteInfo)) {
|
||||
log.info("从缓存获取网站信息,租户ID: {}", tenantId);
|
||||
try {
|
||||
return JSONUtil.parseObject(siteInfo, CmsWebsiteVO.class);
|
||||
} catch (Exception e) {
|
||||
log.warn("缓存解析失败,从数据库重新获取: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// 从数据库获取站点信息
|
||||
CmsWebsite website = getWebsiteFromDatabase(tenantId);
|
||||
if (website == null) {
|
||||
throw new RuntimeException("请先创建站点");
|
||||
}
|
||||
|
||||
// 构建完整的网站信息
|
||||
buildCompleteWebsiteInfo(website);
|
||||
|
||||
// 处理过期时间
|
||||
CmsWebsiteServiceImplHelper.processExpirationTime(website);
|
||||
|
||||
// 转换为VO对象
|
||||
CmsWebsiteVO websiteVO = CmsWebsiteServiceImplHelper.convertToVO(website);
|
||||
|
||||
// 缓存结果
|
||||
try {
|
||||
redisUtil.set(cacheKey, websiteVO, 1L, TimeUnit.DAYS);
|
||||
} catch (Exception e) {
|
||||
log.warn("缓存网站信息失败: {}", e.getMessage());
|
||||
}
|
||||
|
||||
log.info("获取网站信息成功,网站ID: {}, 租户ID: {}", website.getWebsiteId(), tenantId);
|
||||
return websiteVO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearSiteInfoCache(Integer tenantId) {
|
||||
if (tenantId != null) {
|
||||
String cacheKey = SITE_INFO_KEY_PREFIX + tenantId;
|
||||
redisUtil.delete(cacheKey);
|
||||
log.info("清除网站信息缓存成功,租户ID: {}", tenantId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从数据库获取网站信息
|
||||
*/
|
||||
private CmsWebsite getWebsiteFromDatabase(Integer tenantId) {
|
||||
return getByTenantId(tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建完整的网站信息
|
||||
*/
|
||||
private void buildCompleteWebsiteInfo(CmsWebsite website) {
|
||||
// 设置网站状态
|
||||
CmsWebsiteServiceImplHelper.setWebsiteStatus(website);
|
||||
|
||||
// 设置网站配置
|
||||
CmsWebsiteServiceImplHelper.setWebsiteConfig(website);
|
||||
|
||||
// 设置网站导航
|
||||
setWebsiteNavigation(website);
|
||||
|
||||
// 设置网站设置信息
|
||||
CmsWebsiteServiceImplHelper.setWebsiteSetting(website);
|
||||
|
||||
// 设置服务器时间信息
|
||||
CmsWebsiteServiceImplHelper.setServerTimeInfo(website);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置网站导航
|
||||
*/
|
||||
private void setWebsiteNavigation(CmsWebsite website) {
|
||||
// 获取顶部导航
|
||||
CmsNavigationParam navigationParam = new CmsNavigationParam();
|
||||
navigationParam.setHide(0);
|
||||
navigationParam.setTop(0);
|
||||
navigationParam.setBottom(null);
|
||||
List<CmsNavigation> topNavs = cmsNavigationService.listRel(navigationParam);
|
||||
website.setTopNavs(topNavs);
|
||||
|
||||
// 获取底部导航
|
||||
navigationParam.setTop(null);
|
||||
navigationParam.setBottom(0);
|
||||
List<CmsNavigation> bottomNavs = cmsNavigationService.listRel(navigationParam);
|
||||
website.setBottomNavs(bottomNavs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
package com.gxwebsoft.cms.service.impl;
|
||||
|
||||
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 java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* CmsWebsiteServiceImpl 辅助方法
|
||||
* 包含转换和处理逻辑
|
||||
*/
|
||||
public class CmsWebsiteServiceImplHelper {
|
||||
|
||||
/**
|
||||
* 处理过期时间,只处理真正需要的字段
|
||||
*/
|
||||
public static void processExpirationTime(CmsWebsite website) {
|
||||
if (website.getExpirationTime() != null) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime expirationTime = website.getExpirationTime();
|
||||
|
||||
// 计算是否即将过期(30天内过期)
|
||||
LocalDateTime thirtyDaysLater = now.plusDays(30);
|
||||
website.setSoon(expirationTime.isBefore(thirtyDaysLater) ? 1 : 0);
|
||||
|
||||
// 计算是否已过期
|
||||
website.setExpired(expirationTime.isBefore(now) ? -1 : 1);
|
||||
|
||||
// 计算剩余天数
|
||||
long daysBetween = ChronoUnit.DAYS.between(now, expirationTime);
|
||||
website.setExpiredDays(daysBetween);
|
||||
} else {
|
||||
// 没有过期时间的默认值
|
||||
website.setSoon(0);
|
||||
website.setExpired(1);
|
||||
website.setExpiredDays(0L);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将实体对象转换为VO对象
|
||||
*/
|
||||
public static CmsWebsiteVO convertToVO(CmsWebsite website) {
|
||||
CmsWebsiteVO vo = new CmsWebsiteVO();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
// 基本信息
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换导航列表为VO
|
||||
*/
|
||||
public static List<CmsNavigationVO> convertNavigationToVO(List<CmsNavigation> navigations) {
|
||||
if (navigations == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return navigations.stream().map(nav -> {
|
||||
CmsNavigationVO navVO = new CmsNavigationVO();
|
||||
navVO.setNavigationId(nav.getNavigationId());
|
||||
navVO.setNavigationName(nav.getTitle()); // 修复:使用 title 字段
|
||||
navVO.setNavigationUrl(nav.getPath()); // 修复:使用 path 字段
|
||||
navVO.setNavigationIcon(nav.getIcon()); // 修复:使用 icon 字段
|
||||
navVO.setNavigationColor(nav.getColor()); // 修复:使用 color 字段
|
||||
navVO.setParentId(nav.getParentId());
|
||||
navVO.setSort(nav.getSortNumber()); // 修复:使用 sortNumber 字段
|
||||
navVO.setHide(nav.getHide());
|
||||
navVO.setTop(nav.getTop());
|
||||
navVO.setTarget(Integer.valueOf(nav.getTarget()));
|
||||
navVO.setNavigationType(nav.getModel()); // 修复:使用 model 字段
|
||||
|
||||
// 递归处理子导航
|
||||
if (nav.getChildren() != null) {
|
||||
navVO.setChildren(convertNavigationToVO(nav.getChildren()));
|
||||
}
|
||||
|
||||
return navVO;
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置网站状态
|
||||
*/
|
||||
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("未知状态");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置网站配置
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
55
src/main/java/com/gxwebsoft/cms/vo/CmsNavigationVO.java
Normal file
55
src/main/java/com/gxwebsoft/cms/vo/CmsNavigationVO.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package com.gxwebsoft.cms.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 导航信息视图对象
|
||||
* 专门用于前端展示,只包含前端需要的字段
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2025-01-12
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "导航信息视图对象")
|
||||
public class CmsNavigationVO implements Serializable {
|
||||
|
||||
@Schema(description = "导航ID")
|
||||
private Integer navigationId;
|
||||
|
||||
@Schema(description = "导航名称")
|
||||
private String navigationName;
|
||||
|
||||
@Schema(description = "导航链接")
|
||||
private String navigationUrl;
|
||||
|
||||
@Schema(description = "导航图标")
|
||||
private String navigationIcon;
|
||||
|
||||
@Schema(description = "导航颜色")
|
||||
private String navigationColor;
|
||||
|
||||
@Schema(description = "父级ID")
|
||||
private Integer parentId;
|
||||
|
||||
@Schema(description = "排序")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "是否隐藏 0显示 1隐藏")
|
||||
private Integer hide;
|
||||
|
||||
@Schema(description = "位置 0顶部 1底部")
|
||||
private Integer top;
|
||||
|
||||
@Schema(description = "打开方式 0当前窗口 1新窗口")
|
||||
private Integer target;
|
||||
|
||||
@Schema(description = "导航类型")
|
||||
private String navigationType;
|
||||
|
||||
@Schema(description = "子导航")
|
||||
private List<CmsNavigationVO> children;
|
||||
}
|
||||
86
src/main/java/com/gxwebsoft/cms/vo/CmsWebsiteVO.java
Normal file
86
src/main/java/com/gxwebsoft/cms/vo/CmsWebsiteVO.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package com.gxwebsoft.cms.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 网站信息视图对象
|
||||
* 专门用于前端展示,只包含前端需要的字段
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2025-01-12
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "网站信息视图对象")
|
||||
public class CmsWebsiteVO implements Serializable {
|
||||
|
||||
@Schema(description = "网站ID")
|
||||
private Integer websiteId;
|
||||
|
||||
@Schema(description = "网站名称")
|
||||
private String websiteName;
|
||||
|
||||
@Schema(description = "网站代码")
|
||||
private String websiteCode;
|
||||
|
||||
@Schema(description = "网站标题")
|
||||
private String websiteTitle;
|
||||
|
||||
@Schema(description = "网站关键词")
|
||||
private String websiteKeywords;
|
||||
|
||||
@Schema(description = "网站描述")
|
||||
private String websiteDescription;
|
||||
|
||||
@Schema(description = "网站LOGO")
|
||||
private String websiteLogo;
|
||||
|
||||
@Schema(description = "网站图标")
|
||||
private String websiteIcon;
|
||||
|
||||
@Schema(description = "域名")
|
||||
private String domain;
|
||||
|
||||
@Schema(description = "运行状态 0未开通 1正常 2维护中 3违规关停")
|
||||
private Integer running;
|
||||
|
||||
@Schema(description = "应用版本 10免费版 20授权版 30永久授权")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "服务到期时间")
|
||||
private String expirationTime;
|
||||
|
||||
@Schema(description = "是否到期 -1已过期 1未过期")
|
||||
private Integer expired;
|
||||
|
||||
@Schema(description = "剩余天数")
|
||||
private Long expiredDays;
|
||||
|
||||
@Schema(description = "即将过期 0否 1是")
|
||||
private Integer soon;
|
||||
|
||||
@Schema(description = "状态图标")
|
||||
private String statusIcon;
|
||||
|
||||
@Schema(description = "状态文本")
|
||||
private String statusText;
|
||||
|
||||
@Schema(description = "网站配置")
|
||||
private Object config;
|
||||
|
||||
@Schema(description = "服务器时间信息")
|
||||
private HashMap<String, Object> serverTime;
|
||||
|
||||
@Schema(description = "顶部导航")
|
||||
private List<CmsNavigationVO> topNavs;
|
||||
|
||||
@Schema(description = "底部导航")
|
||||
private List<CmsNavigationVO> bottomNavs;
|
||||
|
||||
@Schema(description = "网站设置")
|
||||
private Object setting;
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.gxwebsoft.common.core.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.gxwebsoft.common.core.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* LocalDateTime自定义反序列化器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2025-01-12
|
||||
*/
|
||||
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
|
||||
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
|
||||
String value = p.getValueAsString();
|
||||
if (value != null && !value.isEmpty()) {
|
||||
return LocalDateTime.parse(value, FORMATTER);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.gxwebsoft.common.core.config;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* LocalDateTime自定义序列化器
|
||||
*
|
||||
* @author WebSoft
|
||||
* @since 2025-01-12
|
||||
*/
|
||||
public class LocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
|
||||
|
||||
private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
|
||||
if (value != null) {
|
||||
gen.writeString(value.format(FORMATTER));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,10 +24,6 @@ spring:
|
||||
date-format: yyyy-MM-dd HH:mm:ss
|
||||
serialization:
|
||||
write-dates-as-timestamps: false
|
||||
deserialization:
|
||||
fail-on-unknown-properties: false
|
||||
mapper:
|
||||
default-property-inclusion: non_null
|
||||
|
||||
# 连接池配置
|
||||
datasource:
|
||||
|
||||
Reference in New Issue
Block a user