From a14b5f4fcabed0ce00a6d6ceccf29816077462b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=AE=87=E5=A5=87?= Date: Fri, 31 Oct 2025 17:16:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=B0=83=E6=95=B4=EF=BC=8C=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=9A=84=E7=AE=80=E5=8D=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/common/CommonController.java | 18 +++++ .../web/controller/common/vo/HtmlVO.java | 26 ++++++++ .../framework/config/SecurityConfig.java | 2 + .../java/com/ruoyi/quartz/task/XktTask.java | 2 +- .../java/com/ruoyi/system/domain/SysHtml.java | 20 ++++++ .../ruoyi/system/mapper/SysHtmlMapper.java | 13 ++++ .../ruoyi/system/service/ISysHtmlService.java | 12 ++++ .../service/impl/SysHtmlServiceImpl.java | 65 +++++++++++++++++++ sql/ry_20240629.sql | 14 ++++ 9 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/vo/HtmlVO.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/domain/SysHtml.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysHtmlMapper.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/ISysHtmlService.java create mode 100644 ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysHtmlServiceImpl.java diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java index 0bf86df9e..5f6ce644e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java @@ -16,6 +16,7 @@ import com.ruoyi.framework.ocr.BusinessLicense; import com.ruoyi.framework.ocr.IdCard; import com.ruoyi.framework.ocr.OcrClientWrapper; import com.ruoyi.framework.oss.OSSClientWrapper; +import com.ruoyi.system.service.ISysHtmlService; import com.ruoyi.web.controller.common.vo.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -24,6 +25,7 @@ import org.apache.commons.codec.binary.Base64; import org.codehaus.jettison.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -60,6 +62,8 @@ public class CommonController { private RedisCache redisCache; @Autowired private OcrClientWrapper ocrClient; + @Autowired + private ISysHtmlService htmlService; @ApiOperation("获取OSS临时访问凭证") @GetMapping("/oss/getCredentials") @@ -219,6 +223,20 @@ public class CommonController { return R.ok(BeanUtil.toBean(dto, BusinessLicenseVO.class)); } + @PreAuthorize("@ss.hasAnyRoles('admin,general_admin')") + @ApiOperation("保存html(需登录管理员用户)") + @PostMapping("/html/save") + public R saveHtmlContent(@Validated @RequestBody HtmlVO vo){ + htmlService.saveHtml(vo.getTitle(),vo.getContent()); + return R.ok(); + } + + @ApiOperation("获取html内容") + @GetMapping("/html/content/{title}") + public R getHtmlContent(@PathVariable("title") String title) { + return R.ok(htmlService.getHtmlContent(title)); + } + /** * 通过指定有效的时长(秒)生成过期时间。 * diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/vo/HtmlVO.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/vo/HtmlVO.java new file mode 100644 index 000000000..fafe64b45 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/vo/HtmlVO.java @@ -0,0 +1,26 @@ +package com.ruoyi.web.controller.common.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; + +/** + * @author liangyq + * @date 2025-06-29 + */ +@ApiModel +@Data +public class HtmlVO { + + @NotEmpty + @ApiModelProperty("title") + private String title; + + @NotNull + @ApiModelProperty("content") + private String content; + +} diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 759aedaae..69680af89 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -122,6 +122,8 @@ public class SecurityConfig .antMatchers("/rest/v1/alipay-callback/**").permitAll() //OSS回调 .antMatchers("/rest/v1/oss-callback/upload").permitAll() + //html + .antMatchers("/rest/v1/common/html/content/**").permitAll() //物流回调 .antMatchers("/rest/v1/express-callback/**").permitAll() // 系统广告及首页 diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java index 5c060fc40..6fb9b9bd8 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/XktTask.java @@ -989,7 +989,7 @@ public class XktTask { public void autoCompleteStoreOrder() { log.info("-------------自动完成订单开始-------------"); Integer batchCount = 20; - Date beforeDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -14); + Date beforeDate = DateUtil.offset(new Date(), DateField.DAY_OF_YEAR, -15); List storeOrderIds = storeOrderService.listNeedAutoCompleteOrder(beforeDate, batchCount); for (Long storeOrderId : storeOrderIds) { log.info("开始处理: {}", storeOrderId); diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysHtml.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysHtml.java new file mode 100644 index 000000000..478ed61a3 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysHtml.java @@ -0,0 +1,20 @@ +package com.ruoyi.system.domain; + +import com.ruoyi.common.core.domain.SimpleEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +/** + * @author liangyq + * @date 2025-10-31 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class SysHtml extends SimpleEntity { + + private String title; + + private String content; +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysHtmlMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysHtmlMapper.java new file mode 100644 index 000000000..c80b84571 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysHtmlMapper.java @@ -0,0 +1,13 @@ +package com.ruoyi.system.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.ruoyi.system.domain.SysHtml; +import org.springframework.stereotype.Repository; + +/** + * @author liangyq + * @date 2025-10-31 + */ +@Repository +public interface SysHtmlMapper extends BaseMapper { +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysHtmlService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysHtmlService.java new file mode 100644 index 000000000..3f1639095 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysHtmlService.java @@ -0,0 +1,12 @@ +package com.ruoyi.system.service; + +/** + * @author liangyq + * @date 2025-10-31 + */ +public interface ISysHtmlService { + + void saveHtml(String title, String content); + + String getHtmlContent(String title); +} diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysHtmlServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysHtmlServiceImpl.java new file mode 100644 index 000000000..a1dfbc436 --- /dev/null +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysHtmlServiceImpl.java @@ -0,0 +1,65 @@ +package com.ruoyi.system.service.impl; + +import cn.hutool.cache.CacheUtil; +import cn.hutool.cache.impl.WeakCache; +import cn.hutool.core.lang.Assert; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.ruoyi.common.constant.Constants; +import com.ruoyi.system.domain.SysHtml; +import com.ruoyi.system.mapper.SysHtmlMapper; +import com.ruoyi.system.service.ISysHtmlService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.HashMap; +import java.util.Map; + +/** + * @author liangyq + * @date 2025-10-31 + */ +@Service +public class SysHtmlServiceImpl implements ISysHtmlService { + +// private WeakCache htmlCache = CacheUtil.newWeakCache(-1L); + private Map htmlCache = new HashMap<>(); + @Autowired + private SysHtmlMapper htmlMapper; + + @Transactional(rollbackFor = Exception.class) + @Override + public void saveHtml(String title, String content) { + Assert.notEmpty(title); + SysHtml html = htmlMapper.selectOne(Wrappers.lambdaQuery(SysHtml.class).eq(SysHtml::getTitle, title)); + if (html == null) { + //新增 + html = new SysHtml(); + html.setTitle(title); + html.setContent(content); + html.setDelFlag(Constants.UNDELETED); + htmlMapper.insert(html); + } else { + //修改 + html.setContent(content); + html.setDelFlag(Constants.UNDELETED); + htmlMapper.updateById(html); + } + htmlCache.put(title, content); + } + + @Override + public String getHtmlContent(String title) { + Assert.notEmpty(title); + String content = htmlCache.get(title); + if (content == null) { + SysHtml html = htmlMapper.selectOne(Wrappers.lambdaQuery(SysHtml.class).eq(SysHtml::getTitle, title)); + if (html != null) { + content = html.getContent(); + htmlCache.put(title, content); + } + } + return content; + } + +} diff --git a/sql/ry_20240629.sql b/sql/ry_20240629.sql index bea0a8ed9..d87e5b505 100644 --- a/sql/ry_20240629.sql +++ b/sql/ry_20240629.sql @@ -4262,6 +4262,20 @@ CREATE TABLE `user_subscriptions` PRIMARY KEY (`id`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户关注u档口' ROW_FORMAT = DYNAMIC; +DROP TABLE IF EXISTS `sys_html`; +CREATE TABLE `sys_html` ( + `id` bigint NOT NULL AUTO_INCREMENT COMMENT 'ID', + `title` varchar(256) NOT NULL COMMENT '标题', + `content` mediumblob DEFAULT NULL COMMENT '内容', + `del_flag` char(1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '删除标志(0代表存在 2代表删除)', + `create_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者', + `create_time` datetime DEFAULT NULL COMMENT '创建时间', + `update_by` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者', + `update_time` datetime DEFAULT NULL COMMENT '更新时间', + PRIMARY KEY (`id`) USING BTREE, + UNIQUE KEY `uk_title` (`title`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci ROW_FORMAT=DYNAMIC COMMENT='网页内容'; + -- 快递费用初始化(测试,上线前根据实际费用调整) INSERT INTO express_fee_config ( express_id, region_code, first_item_amount, next_item_amount ) SELECT 1, region_code, 5, 5 FROM express_region WHERE region_level = 1; From c51f44c568cee9150e178ba1662e4a93dd0257d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E5=AE=87=E5=A5=87?= Date: Fri, 31 Oct 2025 17:57:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=86=85=E5=AE=B9=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E7=AE=80=E5=8D=95=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/web/controller/common/CommonController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java index 5f6ce644e..a28759aa4 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/common/CommonController.java @@ -233,8 +233,8 @@ public class CommonController { @ApiOperation("获取html内容") @GetMapping("/html/content/{title}") - public R getHtmlContent(@PathVariable("title") String title) { - return R.ok(htmlService.getHtmlContent(title)); + public String getHtmlContent(@PathVariable("title") String title) { + return htmlService.getHtmlContent(title); } /**