diff --git a/src/main/java/com/gxwebsoft/cms/controller/CmsMainController.java b/src/main/java/com/gxwebsoft/cms/controller/CmsMainController.java index d91a6df..403ba2f 100644 --- a/src/main/java/com/gxwebsoft/cms/controller/CmsMainController.java +++ b/src/main/java/com/gxwebsoft/cms/controller/CmsMainController.java @@ -26,25 +26,4 @@ public class CmsMainController extends BaseController { @Resource private CmsWebsiteService cmsWebsiteService; - @Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等") - @GetMapping("/getSiteInfo") - public ApiResult getSiteInfo() { - try { - Integer tenantId = getTenantId(); - if (ObjectUtil.isEmpty(tenantId)) { - return fail("租户ID不能为空", null); - } - - CmsVO 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); - } - } - } diff --git a/src/main/java/com/gxwebsoft/cms/controller/CmsWebsiteController.java b/src/main/java/com/gxwebsoft/cms/controller/CmsWebsiteController.java index 73d7bd6..667348b 100644 --- a/src/main/java/com/gxwebsoft/cms/controller/CmsWebsiteController.java +++ b/src/main/java/com/gxwebsoft/cms/controller/CmsWebsiteController.java @@ -1,40 +1,60 @@ -package com.gxwebsoft.cms.controller; - -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.CmsVO; -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.BatchParam; -import com.gxwebsoft.common.core.web.PageResult; -import com.gxwebsoft.common.system.entity.User; -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.util.List; - -/** - * 网站信息记录表控制器 - * - * @author 科技小王子 - * @since 2024-09-10 20:36:14 - */ -@Slf4j -@Tag(name = "网站信息记录表管理") -@RestController -@RequestMapping("/api/cms/cms-website") -public class CmsWebsiteController extends BaseController { + 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.CmsNavigation; + import com.gxwebsoft.cms.entity.CmsWebsite; + import com.gxwebsoft.cms.entity.CmsWebsiteField; + import com.gxwebsoft.cms.entity.CmsWebsiteSetting; + import com.gxwebsoft.cms.param.CmsNavigationParam; + import com.gxwebsoft.cms.param.CmsWebsiteParam; + import com.gxwebsoft.cms.service.CmsNavigationService; + import com.gxwebsoft.cms.service.CmsWebsiteFieldService; + import com.gxwebsoft.cms.service.CmsWebsiteService; + 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.RedisUtil; + import com.gxwebsoft.common.core.web.ApiResult; + 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.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.util.HashMap; + import java.util.List; + import java.util.concurrent.TimeUnit; + + /** + * 网站信息记录表控制器 + * + * @author 科技小王子 + * @since 2024-09-10 20:36:14 + */ + @Slf4j + @Tag(name = "网站信息记录表管理") + @RestController + @RequestMapping("/api/cms/cms-website") + public class CmsWebsiteController extends BaseController { @Resource private CmsWebsiteService cmsWebsiteService; @Resource private RedisUtil redisUtil; + @Resource + private CmsNavigationService cmsNavigationService; + @Resource + private CmsWebsiteSettingService cmsWebsiteSettingService; + @Resource + private CmsWebsiteFieldService cmsWebsiteFieldService; private static final String SITE_INFO_KEY_PREFIX = "SiteInfo:"; private static final String MP_INFO_KEY_PREFIX = "MpInfo:"; @@ -45,155 +65,277 @@ public class CmsWebsiteController extends BaseController { @Operation(summary = "分页查询网站信息记录表") @GetMapping("/page") public ApiResult> page(CmsWebsiteParam param) { - // 使用关联查询 - return success(cmsWebsiteService.pageRel(param)); + // 使用关联查询 + return success(cmsWebsiteService.pageRel(param)); } @Operation(summary = "查询全部网站信息记录表") @GetMapping() public ApiResult> list(CmsWebsiteParam param) { - // 使用关联查询 - return success(cmsWebsiteService.listRel(param)); + // 使用关联查询 + return success(cmsWebsiteService.listRel(param)); } @Operation(summary = "分页查询网站信息记录表") @GetMapping("/pageAll") public ApiResult> pageAll(CmsWebsiteParam param) { - return success(cmsWebsiteService.pageRelAll(param)); + return success(cmsWebsiteService.pageRelAll(param)); } @Operation(summary = "根据id查询网站信息记录表") @GetMapping("/{id}") public ApiResult get(@PathVariable("id") Integer id) { - // 使用关联查询 - return success(cmsWebsiteService.getByIdRel(id)); + // 使用关联查询 + return success(cmsWebsiteService.getByIdRel(id)); } @Operation(summary = "根据id查询网站信息记录表") @GetMapping("/getAll/{id}") public ApiResult getAll(@PathVariable("id") Integer id) { - // 使用关联查询 - return success(cmsWebsiteService.getByIdRelAll(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("创建失败"); + // 记录当前登录用户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("修改失败"); + 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("修改失败"); + 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("删除失败"); + 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("删除失败"); + if (cmsWebsiteService.removeByIdAll(id)) { + return success("删除成功"); + } + return fail("删除失败"); } @PreAuthorize("hasAuthority('cms:website:save')") @Operation(summary = "批量添加网站信息记录表") @PostMapping("/batch") public ApiResult saveBatch(@RequestBody List list) { - if (cmsWebsiteService.saveBatch(list)) { - return success("添加成功"); - } - return fail("添加失败"); + if (cmsWebsiteService.saveBatch(list)) { + return success("添加成功"); + } + return fail("添加失败"); } @PreAuthorize("hasAuthority('cms:website:update')") @Operation(summary = "批量修改网站信息记录表") @PutMapping("/batch") public ApiResult removeBatch(@RequestBody BatchParam batchParam) { - if (batchParam.update(cmsWebsiteService, "website_id")) { - return success("修改成功"); - } - return fail("修改失败"); + if (batchParam.update(cmsWebsiteService, "website_id")) { + return success("修改成功"); + } + return fail("修改失败"); } @PreAuthorize("hasAuthority('cms:website:remove')") @Operation(summary = "批量删除网站信息记录表") @DeleteMapping("/batch") public ApiResult removeBatch(@RequestBody List ids) { - if (cmsWebsiteService.removeByIds(ids)) { - return success("删除成功"); - } - return fail("删除失败"); + if (cmsWebsiteService.removeByIds(ids)) { + return success("删除成功"); + } + return fail("删除失败"); } - @Operation(summary = "网站基本信息", description = "获取网站的基本信息,包括配置、导航、设置和过期状态等") + @Operation(summary = "网站基本信息") @GetMapping("/getSiteInfo") - public ApiResult getSiteInfo() { - try { - Integer tenantId = getTenantId(); - if (ObjectUtil.isEmpty(tenantId)) { - return fail("租户ID不能为空", null); - } - - CmsVO 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); + public ApiResult getSiteInfo() { + if (ObjectUtil.isEmpty(getTenantId())) { + return fail("参数不正确", null); + } + + 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)); + } + + // 获取站点信息 + CmsWebsite website = cmsWebsiteService.getOne(new LambdaQueryWrapper().eq(CmsWebsite::getDeleted, 0).last("limit 1")); + + // 创建默认站点 + if (ObjectUtil.isEmpty(website)) { + return success("请先创建站点...", null); + } + + // 站点异常状态 + setWebsiteStatus(website); + + // 站点配置参数 + HashMap config = buildWebsiteConfig(website); + website.setConfig(config); + + // 网站导航 + setWebsiteNavigation(website); + + // 网站设置信息 + setWebsiteSetting(website); + + // 服务器时间 + HashMap serverTime = buildServerTime(); + 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); + } + + 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("违规关停"); + } + } } + private HashMap buildWebsiteConfig(CmsWebsite website) { + HashMap config = new HashMap<>(); + LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); + wrapper.eq(CmsWebsiteField::getDeleted, 0); + final List 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 topNavs = cmsNavigationService.listRel(navigationParam); + // 顶部菜单 + website.setTopNavs(CommonUtil.toTreeData(topNavs, 0, CmsNavigation::getParentId, CmsNavigation::getNavigationId, CmsNavigation::setChildren)); + navigationParam.setTop(null); + navigationParam.setBottom(0); + final List 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().eq(CmsWebsiteSetting::getWebsiteId, website.getWebsiteId())); + if (ObjectUtil.isNotEmpty(setting)) { + website.setSetting(setting); + } + } + + private HashMap buildServerTime() { + HashMap 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; + } @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("清除成功"); - } - -} + // 清除指定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("清除成功"); + } + + } diff --git a/src/main/java/com/gxwebsoft/cms/service/CmsWebsiteService.java b/src/main/java/com/gxwebsoft/cms/service/CmsWebsiteService.java index afb420d..08c5a37 100644 --- a/src/main/java/com/gxwebsoft/cms/service/CmsWebsiteService.java +++ b/src/main/java/com/gxwebsoft/cms/service/CmsWebsiteService.java @@ -5,6 +5,7 @@ import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.cms.entity.CmsWebsite; import com.gxwebsoft.cms.param.CmsWebsiteParam; import com.gxwebsoft.cms.vo.CmsVO; +import com.gxwebsoft.shop.vo.ShopVo; import java.util.List; @@ -59,7 +60,7 @@ public interface CmsWebsiteService extends IService { * @param tenantId 租户ID * @return 网站信息VO */ - CmsVO getSiteInfo(Integer tenantId); + ShopVo getSiteInfo(Integer tenantId); /** * 清除网站信息缓存 diff --git a/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java b/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java index 2aaf8a7..38ca917 100644 --- a/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java +++ b/src/main/java/com/gxwebsoft/cms/service/impl/CmsWebsiteServiceImpl.java @@ -15,6 +15,7 @@ import com.gxwebsoft.common.system.service.CompanyService; import com.gxwebsoft.common.system.service.UserService; import com.gxwebsoft.project.entity.Project; import com.gxwebsoft.project.service.ProjectService; +import com.gxwebsoft.shop.vo.ShopVo; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -313,7 +314,7 @@ public class CmsWebsiteServiceImpl extends ServiceImpl> testDateTime() { - Map result = new HashMap<>(); - result.put("currentTime", LocalDateTime.now()); - result.put("message", "LocalDateTime序列化测试"); - return success(result); - } -} diff --git a/src/main/java/com/gxwebsoft/common/core/controller/WechatCertTestController.java b/src/main/java/com/gxwebsoft/common/core/controller/WechatCertTestController.java deleted file mode 100644 index 6ea9c4e..0000000 --- a/src/main/java/com/gxwebsoft/common/core/controller/WechatCertTestController.java +++ /dev/null @@ -1,211 +0,0 @@ -package com.gxwebsoft.common.core.controller; - -import com.gxwebsoft.common.core.utils.WechatCertAutoConfig; -import com.gxwebsoft.common.core.web.ApiResult; -import com.gxwebsoft.common.core.web.BaseController; -import com.wechat.pay.java.core.Config; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; - -import java.util.HashMap; -import java.util.Map; - -/** - * 微信支付证书自动配置测试控制器 - * - * @author 科技小王子 - * @since 2024-07-26 - */ -@Slf4j -@RestController -@RequestMapping("/api/wechat-cert-test") -@Tag(name = "微信支付证书自动配置测试") -public class WechatCertTestController extends BaseController { - - @Autowired - private WechatCertAutoConfig wechatCertAutoConfig; - - @Operation(summary = "测试默认开发环境证书配置") - @PostMapping("/test-default") - public ApiResult> testDefaultConfig() { - Map result = new HashMap<>(); - - try { - log.info("开始测试默认开发环境证书配置..."); - - // 创建自动证书配置 - Config config = wechatCertAutoConfig.createDefaultDevConfig(); - - // 测试配置 - boolean testResult = wechatCertAutoConfig.testConfig(config); - - result.put("success", true); - result.put("configCreated", config != null); - result.put("testPassed", testResult); - result.put("message", "默认证书配置测试完成"); - result.put("instructions", wechatCertAutoConfig.getUsageInstructions()); - - log.info("✅ 默认证书配置测试成功"); - return success("测试成功", result); - - } catch (Exception e) { - log.error("❌ 默认证书配置测试失败: {}", e.getMessage(), e); - - result.put("success", false); - result.put("error", e.getMessage()); - result.put("message", "证书配置测试失败"); - result.put("troubleshooting", getTroubleshootingInfo()); - - return fail("测试失败: " + e.getMessage(), result); - } - } - - @Operation(summary = "测试自定义证书配置") - @PostMapping("/test-custom") - public ApiResult> testCustomConfig( - @Parameter(description = "商户号") @RequestParam String merchantId, - @Parameter(description = "私钥文件路径") @RequestParam String privateKeyPath, - @Parameter(description = "证书序列号") @RequestParam String merchantSerialNumber, - @Parameter(description = "APIv3密钥") @RequestParam String apiV3Key) { - - Map result = new HashMap<>(); - - try { - log.info("开始测试自定义证书配置..."); - log.info("商户号: {}", merchantId); - log.info("私钥路径: {}", privateKeyPath); - - // 创建自动证书配置 - Config config = wechatCertAutoConfig.createAutoConfig( - merchantId, privateKeyPath, merchantSerialNumber, apiV3Key); - - // 测试配置 - boolean testResult = wechatCertAutoConfig.testConfig(config); - - result.put("success", true); - result.put("configCreated", config != null); - result.put("testPassed", testResult); - result.put("message", "自定义证书配置测试完成"); - result.put("merchantId", merchantId); - result.put("privateKeyPath", privateKeyPath); - - log.info("✅ 自定义证书配置测试成功"); - return success("测试成功", result); - - } catch (Exception e) { - log.error("❌ 自定义证书配置测试失败: {}", e.getMessage(), e); - - result.put("success", false); - result.put("error", e.getMessage()); - result.put("message", "证书配置测试失败"); - result.put("troubleshooting", getTroubleshootingInfo()); - - return fail("测试失败: " + e.getMessage(), result); - } - } - - @Operation(summary = "获取使用说明") - @GetMapping("/instructions") - public ApiResult getInstructions() { - String instructions = wechatCertAutoConfig.getUsageInstructions(); - return success("获取使用说明成功", instructions); - } - - @Operation(summary = "获取故障排除信息") - @GetMapping("/troubleshooting") - public ApiResult> getTroubleshooting() { - Map troubleshooting = getTroubleshootingInfo(); - return success("获取故障排除信息成功", troubleshooting); - } - - /** - * 获取故障排除信息 - */ - private Map getTroubleshootingInfo() { - Map info = new HashMap<>(); - - info.put("commonIssues", Map.of( - "404错误", "商户平台未开启API安全功能或未申请使用微信支付公钥", - "证书序列号错误", "请检查商户平台中的证书序列号是否正确", - "APIv3密钥错误", "请确认APIv3密钥是否正确设置", - "私钥文件不存在", "请检查私钥文件路径是否正确", - "网络连接问题", "请检查网络连接是否正常" - )); - - info.put("solutions", Map.of( - "开启API安全", "登录微信商户平台 -> 账户中心 -> API安全 -> 申请使用微信支付公钥", - "获取证书序列号", "在API安全页面查看或重新下载证书", - "设置APIv3密钥", "在API安全页面设置APIv3密钥", - "检查私钥文件", "确保apiclient_key.pem文件存在且路径正确" - )); - - info.put("advantages", Map.of( - "自动下载", "RSAAutoCertificateConfig会自动下载平台证书", - "自动更新", "证书过期时会自动更新", - "简化管理", "无需手动管理wechatpay_cert.pem文件", - "官方推荐", "微信支付官方推荐的证书管理方式" - )); - - info.put("documentation", "https://pay.weixin.qq.com/doc/v3/merchant/4012153196"); - - return info; - } - - @Operation(summary = "检查商户平台配置状态") - @PostMapping("/check-merchant-config") - public ApiResult> checkMerchantConfig( - @RequestParam String merchantId, - @RequestParam String privateKeyPath, - @RequestParam String merchantSerialNumber, - @RequestParam String apiV3Key) { - - Map result = new HashMap<>(); - - try { - log.info("开始检查商户平台配置状态..."); - log.info("商户号: {}", merchantId); - - // 尝试创建自动证书配置 - Config config = wechatCertAutoConfig.createAutoConfig( - merchantId, privateKeyPath, merchantSerialNumber, apiV3Key); - - result.put("success", true); - result.put("configCreated", true); - result.put("message", "商户平台配置正常,自动证书配置创建成功"); - result.put("merchantId", merchantId); - result.put("recommendation", "配置正常,可以正常使用微信支付功能"); - - log.info("✅ 商户平台配置检查成功"); - return success("配置检查成功", result); - - } catch (Exception e) { - log.error("❌ 商户平台配置检查失败: {}", e.getMessage(), e); - - result.put("success", false); - result.put("configCreated", false); - result.put("error", e.getMessage()); - result.put("merchantId", merchantId); - - // 分析错误类型并提供解决方案 - if (e.getMessage().contains("404") || e.getMessage().contains("RESOURCE_NOT_EXISTS")) { - result.put("errorType", "商户平台配置问题"); - result.put("solution", "请在微信支付商户平台完成以下配置:\n" + - "1. 登录商户平台:https://pay.weixin.qq.com/\n" + - "2. 进入:产品中心 → 开发配置 → API安全\n" + - "3. 申请API证书\n" + - "4. 申请使用微信支付公钥\n" + - "5. 确保API证书和微信支付公钥状态为\"已生效\""); - result.put("documentUrl", "https://pay.weixin.qq.com/doc/v3/merchant/4012153196"); - } else { - result.put("errorType", "其他配置问题"); - result.put("solution", "请检查商户号、证书序列号、API密钥等配置是否正确"); - } - - return success("配置检查完成(发现问题)", result); - } - } -} diff --git a/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java b/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java index 63d4f4b..d87d09e 100644 --- a/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java +++ b/src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java @@ -74,8 +74,8 @@ public class SecurityConfig { "/api/shop/merchant-account/getMerchantAccountByPhone", "/api/hjm/hjm-car/**", "/api/chat/**", - "/api/shop/shop-order/test", - "/api/cms/getSiteInfo" + "/api/shop/getShopInfo", + "/api/shop/shop-order/test" ) .permitAll() .anyRequest() diff --git a/src/main/java/com/gxwebsoft/common/task/AddUserTaskController.java b/src/main/java/com/gxwebsoft/common/task/AddUserTaskController.java deleted file mode 100644 index f69267e..0000000 --- a/src/main/java/com/gxwebsoft/common/task/AddUserTaskController.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.gxwebsoft.common.task; - -import com.gxwebsoft.common.core.utils.RequestUtil; -import com.gxwebsoft.common.core.web.BaseController; -import com.gxwebsoft.common.system.entity.User; -import com.gxwebsoft.common.system.service.UserRoleService; -import com.gxwebsoft.common.system.service.UserService; -import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import javax.annotation.Resource; - -/** - * 定时任务 - * - * @author 科技小王子 - * @since 2022-12-15 19:11:07 - */ -@Tag(name = "定时任务") -@RestController -@RequestMapping("/api/love/scheduling") -public class AddUserTaskController extends BaseController { - @Resource - private RequestUtil requestUtil; - @Resource - private UserRoleService userRoleService; - - /** - * 模拟注册用户 - * @Scheduled(fixedDelay = 1000, initialDelay = 1000) - */ - @Scheduled(fixedDelay = 1000, initialDelay = 1000) - public void addUserProfile() { -// final User userId = requestUtil.getCoreUserInfoByUserId(27344); - } - -} diff --git a/src/main/java/com/gxwebsoft/shop/controller/ShopMainController.java b/src/main/java/com/gxwebsoft/shop/controller/ShopMainController.java new file mode 100644 index 0000000..358c10e --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/controller/ShopMainController.java @@ -0,0 +1,54 @@ +package com.gxwebsoft.shop.controller; + +import cn.hutool.core.util.ObjectUtil; +import com.gxwebsoft.cms.service.CmsWebsiteService; +import com.gxwebsoft.cms.vo.CmsVO; +import com.gxwebsoft.common.core.web.ApiResult; +import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.shop.vo.ShopVo; +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.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * 商城主入口 + * + * @author 科技小王子 + * @since 2024-09-10 20:36:14 + */ +@Slf4j +@Tag(name = "商城") +@RestController +@RequestMapping("/api/shop") +public class ShopMainController extends BaseController { + @Resource + private CmsWebsiteService cmsWebsiteService; + + @Operation(summary = "商城基本信息", description = "获取商城的基本信息,包括配置、导航、设置和过期状态等") + @GetMapping("/getShopInfo") + public ApiResult getSiteInfo() { + Integer tenantId = getTenantId(); + + if (ObjectUtil.isEmpty(tenantId)) { + return fail("租户ID不能为空", null); + } + + try { + ShopVo vo = cmsWebsiteService.getSiteInfo(tenantId); + return success(vo); + } 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); + } + } + +} diff --git a/src/main/java/com/gxwebsoft/shop/controller/ShopUserCouponController.java b/src/main/java/com/gxwebsoft/shop/controller/ShopUserCouponController.java index 1750038..2bbb1f7 100644 --- a/src/main/java/com/gxwebsoft/shop/controller/ShopUserCouponController.java +++ b/src/main/java/com/gxwebsoft/shop/controller/ShopUserCouponController.java @@ -122,7 +122,6 @@ public class ShopUserCouponController extends BaseController { return success("领取成功"); } - @PreAuthorize("hasAuthority('shop:shopUserCoupon:list')") @Operation(summary = "分页查询用户优惠券") @GetMapping("/page") public ApiResult> page(ShopUserCouponParam param) { diff --git a/src/main/java/com/gxwebsoft/shop/vo/MenuVo.java b/src/main/java/com/gxwebsoft/shop/vo/MenuVo.java new file mode 100644 index 0000000..894ed4b --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/vo/MenuVo.java @@ -0,0 +1,55 @@ +package com.gxwebsoft.shop.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 MenuVo 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 children; +} diff --git a/src/main/java/com/gxwebsoft/shop/vo/ShopVo.java b/src/main/java/com/gxwebsoft/shop/vo/ShopVo.java new file mode 100644 index 0000000..b95ca2b --- /dev/null +++ b/src/main/java/com/gxwebsoft/shop/vo/ShopVo.java @@ -0,0 +1,92 @@ +package com.gxwebsoft.shop.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 ShopVo implements Serializable { + + @Schema(description = "应用ID") + private Integer appId; + + @Schema(description = "应用名称") + private String appName; + + @Schema(description = "应用介绍") + private String description; + + @Schema(description = "网站关键词") + private String keywords; + + @Schema(description = "应用编号") + private String appCode; + + @Schema(description = "小程序二维码") + private String mpQrCode; + + @Schema(description = "标题") + private String title; + + @Schema(description = "LOGO") + private String logo; + + @Schema(description = "图标") + private String icon; + + @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 = "创建时间") + private String createTime; + + @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 serverTime; + + @Schema(description = "顶部导航") + private List topNavs; + + @Schema(description = "底部导航") + private List bottomNavs; + + @Schema(description = "网站设置") + private Object setting; +}