Просмотр исходного кода

feat(business): 添加使用条款管理功能

- 新增 TermsOfService 实体类
- 新增 TermsOfServiceBo、TermsOfServiceVo 数据传输对象
- 实现 ITermsOfServiceService 接口
- 编写 TermsOfServiceController 控制器
- 创建 TermsOfServiceMapper XML 映射文件
- 开发 TermsOfServiceServiceImpl 服务实现类
fugui001 5 месяцев назад
Родитель
Сommit
706fe0fc09

+ 117 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/TermsOfServiceController.java

@@ -0,0 +1,117 @@
+package org.dromara.business.controller;
+
+import java.util.List;
+
+import lombok.RequiredArgsConstructor;
+import jakarta.servlet.http.HttpServletResponse;
+import jakarta.validation.constraints.*;
+import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.dromara.business.domain.bo.TermsOfServiceBo;
+import org.dromara.business.domain.vo.TermsOfServiceVo;
+import org.dromara.business.service.ITermsOfServiceService;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.validation.annotation.Validated;
+import org.dromara.common.idempotent.annotation.RepeatSubmit;
+import org.dromara.common.log.annotation.Log;
+import org.dromara.common.web.core.BaseController;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import org.dromara.common.core.domain.R;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import org.dromara.common.log.enums.BusinessType;
+import org.dromara.common.excel.utils.ExcelUtil;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+
+/**
+ * 使用条款管理
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/business/ofService")
+public class TermsOfServiceController extends BaseController {
+
+    private final ITermsOfServiceService termsOfServiceService;
+
+    /**
+     * 查询使用条款管理列表
+     */
+    @SaCheckPermission("business:ofService:list")
+    @GetMapping("/list")
+    public TableDataInfo<TermsOfServiceVo> list(TermsOfServiceBo bo, PageQuery pageQuery) {
+        return termsOfServiceService.queryPageList(bo, pageQuery);
+    }
+
+    /**
+     * 导出使用条款管理列表
+     */
+    @SaCheckPermission("business:ofService:export")
+    @Log(title = "使用条款管理", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(TermsOfServiceBo bo, HttpServletResponse response) {
+        List<TermsOfServiceVo> list = termsOfServiceService.queryList(bo);
+        ExcelUtil.exportExcel(list, "使用条款管理", TermsOfServiceVo.class, response);
+    }
+
+    /**
+     * 获取使用条款管理详细信息
+     *
+     * @param id 主键
+     */
+    @SaCheckPermission("business:ofService:query")
+    @GetMapping("/{id}")
+    public R<TermsOfServiceVo> getInfo(@NotNull(message = "主键不能为空")
+                                     @PathVariable Long id) {
+        return R.ok(termsOfServiceService.queryById(id));
+    }
+
+    /**
+     * 新增使用条款管理
+     */
+    @SaCheckPermission("business:ofService:add")
+    @Log(title = "使用条款管理", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping()
+    public R<Void> add(@Validated(AddGroup.class) @RequestBody TermsOfServiceBo bo) {
+        return toAjax(termsOfServiceService.insertByBo(bo));
+    }
+
+    /**
+     * 修改使用条款管理
+     */
+    @SaCheckPermission("business:ofService:edit")
+    @Log(title = "使用条款管理", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping()
+    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TermsOfServiceBo bo) {
+        return toAjax(termsOfServiceService.updateByBo(bo));
+    }
+
+    /**
+     * 删除使用条款管理
+     *
+     * @param ids 主键串
+     */
+    @SaCheckPermission("business:ofService:remove")
+    @Log(title = "使用条款管理", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public R<Void> remove(@NotEmpty(message = "主键不能为空")
+                          @PathVariable Long[] ids) {
+        return toAjax(termsOfServiceService.deleteWithValidByIds(List.of(ids), true));
+    }
+
+
+    /**
+     * 查询默认的数据
+     * @return
+     */
+    @SaCheckPermission("business:ofService:selectTermsServiceListMax")
+    @GetMapping("/selectTermsServiceListMax")
+    public R<TermsOfServiceVo> selectTermsServiceListMax() {
+        return R.ok(termsOfServiceService.selectTermsServiceListMax());
+    }
+
+}

+ 57 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/TermsOfService.java

@@ -0,0 +1,57 @@
+package org.dromara.business.domain;
+
+import org.dromara.common.mybatis.core.domain.BaseEntity;
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.io.Serial;
+
+/**
+ * 使用条款管理对象 terms_of_service
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@TableName("terms_of_service")
+public class TermsOfService extends BaseEntity {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @TableId(value = "id")
+    private Long id;
+
+    /**
+     * 条款标题(如:使用条款、隐私协议等)
+     */
+    private String title;
+
+    /**
+     * 条款内容(HTML格式)
+     */
+    private String content;
+
+    /**
+     * 版本号,如 v1.0.0
+     */
+    @Version
+    private String version;
+
+    /**
+     * 语言代码,如 zh-CN, en-US
+     */
+    private String language;
+
+    /**
+     * 是否为默认版本
+     */
+    private Long isDefault;
+
+
+}

+ 52 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/bo/TermsOfServiceBo.java

@@ -0,0 +1,52 @@
+package org.dromara.business.domain.bo;
+
+import org.dromara.business.domain.TermsOfService;
+import org.dromara.common.mybatis.core.domain.BaseEntity;
+import org.dromara.common.core.validate.AddGroup;
+import org.dromara.common.core.validate.EditGroup;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import jakarta.validation.constraints.*;
+
+/**
+ * 使用条款管理业务对象 terms_of_service
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = TermsOfService.class, reverseConvertGenerate = false)
+public class TermsOfServiceBo extends BaseEntity {
+
+    /**
+     * 主键
+     */
+    @NotNull(message = "主键不能为空", groups = { EditGroup.class })
+    private Long id;
+
+    /**
+     * 条款标题(如:使用条款、隐私协议等)
+     */
+    @NotBlank(message = "条款标题(如:使用条款、隐私协议等)不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String title;
+
+    /**
+     * 条款内容(HTML格式)
+     */
+    @NotBlank(message = "条款内容(HTML格式)不能为空", groups = { AddGroup.class, EditGroup.class })
+    private String content;
+
+    /**
+     * 语言代码,如 zh-CN, en-US
+     */
+    private String language;
+
+    /**
+     * 是否为默认版本
+     */
+    private Long isDefault;
+
+
+}

+ 66 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/vo/TermsOfServiceVo.java

@@ -0,0 +1,66 @@
+package org.dromara.business.domain.vo;
+
+import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
+import cn.idev.excel.annotation.ExcelProperty;
+import org.dromara.business.domain.TermsOfService;
+import org.dromara.common.excel.annotation.ExcelDictFormat;
+import org.dromara.common.excel.convert.ExcelDictConvert;
+import io.github.linpeilie.annotations.AutoMapper;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+
+
+/**
+ * 使用条款管理视图对象 terms_of_service
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+@Data
+@ExcelIgnoreUnannotated
+@AutoMapper(target = TermsOfService.class)
+public class TermsOfServiceVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @ExcelProperty(value = "主键")
+    private Long id;
+
+    /**
+     * 条款标题(如:使用条款、隐私协议等)
+     */
+    @ExcelProperty(value = "条款标题", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "如=:使用条款、隐私协议等")
+    private String title;
+
+    /**
+     * 条款内容(HTML格式)
+     */
+    @ExcelProperty(value = "条款内容", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "H=TML格式")
+    private String content;
+
+    /**
+     * 语言代码,如 zh-CN, en-US
+     */
+    @ExcelProperty(value = "语言代码,如 zh-CN, en-US")
+    private String language;
+
+    /**
+     * 是否为默认版本
+     */
+    @ExcelProperty(value = "是否为默认版本")
+    private Long isDefault;
+
+
+    @ExcelProperty(value = "消息内容text")
+    private String contentText;
+
+}

+ 51 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/TermsOfServiceMapper.java

@@ -0,0 +1,51 @@
+package org.dromara.business.mapper;
+
+import com.baomidou.dynamic.datasource.annotation.DS;
+import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import org.apache.ibatis.annotations.Param;
+import org.dromara.business.domain.RewardClaims;
+import org.dromara.business.domain.TermsOfService;
+import org.dromara.business.domain.vo.RewardClaimsVo;
+import org.dromara.business.domain.vo.TermsOfServiceVo;
+import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 使用条款管理Mapper接口
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+@DS("mysql2")
+public interface TermsOfServiceMapper extends BaseMapperPlus<TermsOfService, TermsOfServiceVo> {
+
+
+    @InterceptorIgnore(tenantLine = "true")
+    Page<TermsOfServiceVo> selectVoPage2(@Param("page") Page<TermsOfService> page, @Param("ew") Wrapper<TermsOfService> wrapper);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int insertTermsService(TermsOfService rewardClaims);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int updateTermsServiceById(TermsOfService rewardClaims);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteTermsServiceById(@Param("ids") Collection<Long> ids);
+
+    @InterceptorIgnore(tenantLine = "true")
+    TermsOfServiceVo selectVoInfoById(Long id);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<TermsOfServiceVo> selectTermsServiceList(@Param("ew") Wrapper<TermsOfService> wrapper);
+
+    @InterceptorIgnore(tenantLine = "true")
+    TermsOfServiceVo selectTermsServiceListMax();
+
+    @InterceptorIgnore(tenantLine = "true")
+    int updateTermsServiceOtherFalse();
+
+}

+ 74 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/ITermsOfServiceService.java

@@ -0,0 +1,74 @@
+package org.dromara.business.service;
+
+import org.dromara.business.domain.bo.TermsOfServiceBo;
+import org.dromara.business.domain.vo.TermsOfServiceVo;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.mybatis.core.page.PageQuery;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 使用条款管理Service接口
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+public interface ITermsOfServiceService {
+
+    /**
+     * 查询使用条款管理
+     *
+     * @param id 主键
+     * @return 使用条款管理
+     */
+    TermsOfServiceVo queryById(Long id);
+
+    /**
+     * 分页查询使用条款管理列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 使用条款管理分页列表
+     */
+    TableDataInfo<TermsOfServiceVo> queryPageList(TermsOfServiceBo bo, PageQuery pageQuery);
+
+    /**
+     * 查询符合条件的使用条款管理列表
+     *
+     * @param bo 查询条件
+     * @return 使用条款管理列表
+     */
+    List<TermsOfServiceVo> queryList(TermsOfServiceBo bo);
+
+    /**
+     * 新增使用条款管理
+     *
+     * @param bo 使用条款管理
+     * @return 是否新增成功
+     */
+    Boolean insertByBo(TermsOfServiceBo bo);
+
+    /**
+     * 修改使用条款管理
+     *
+     * @param bo 使用条款管理
+     * @return 是否修改成功
+     */
+    Boolean updateByBo(TermsOfServiceBo bo);
+
+    /**
+     * 校验并批量删除使用条款管理信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+    /**
+     * 查询使用条款管理 默认的那一条数据
+     * @return
+     */
+    TermsOfServiceVo selectTermsServiceListMax();
+}

+ 165 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/service/impl/TermsOfServiceServiceImpl.java

@@ -0,0 +1,165 @@
+package org.dromara.business.service.impl;
+
+import org.dromara.business.domain.TermsOfService;
+import org.dromara.business.domain.bo.TermsOfServiceBo;
+import org.dromara.business.domain.vo.TermsOfServiceVo;
+import org.dromara.business.mapper.TermsOfServiceMapper;
+import org.dromara.business.service.ITermsOfServiceService;
+import org.dromara.common.core.utils.MapstructUtils;
+import org.dromara.common.core.utils.StringUtils;
+import org.dromara.common.mybatis.core.page.TableDataInfo;
+import org.dromara.common.mybatis.core.page.PageQuery;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+
+import java.util.List;
+import java.util.Map;
+import java.util.Collection;
+
+/**
+ * 使用条款管理Service业务层处理
+ *
+ * @author Lion Li
+ * @date 2025-07-21
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class TermsOfServiceServiceImpl implements ITermsOfServiceService {
+
+    private final TermsOfServiceMapper baseMapper;
+
+    /**
+     * 查询使用条款管理
+     *
+     * @param id 主键
+     * @return 使用条款管理
+     */
+    @Override
+    public TermsOfServiceVo queryById(Long id){
+        return baseMapper.selectVoInfoById(id);
+    }
+
+    /**
+     * 分页查询使用条款管理列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 使用条款管理分页列表
+     */
+    @Override
+    public TableDataInfo<TermsOfServiceVo> queryPageList(TermsOfServiceBo bo, PageQuery pageQuery) {
+        LambdaQueryWrapper<TermsOfService> lqw = buildQueryWrapper(bo);
+        Page<TermsOfServiceVo> result = baseMapper.selectVoPage2(pageQuery.build(), lqw);
+        List<TermsOfServiceVo> records = result.getRecords();
+        for (TermsOfServiceVo record : records) {
+            String contentText=replaceHtml(record.getContent());
+            record.setContentText(contentText);
+        }
+        return TableDataInfo.build(result);
+    }
+
+    /**
+     * 查询符合条件的使用条款管理列表
+     *
+     * @param bo 查询条件
+     * @return 使用条款管理列表
+     */
+    @Override
+    public List<TermsOfServiceVo> queryList(TermsOfServiceBo bo) {
+        LambdaQueryWrapper<TermsOfService> lqw = buildQueryWrapper(bo);
+        return baseMapper.selectTermsServiceList(lqw);
+    }
+
+    private LambdaQueryWrapper<TermsOfService> buildQueryWrapper(TermsOfServiceBo bo) {
+        Map<String, Object> params = bo.getParams();
+        LambdaQueryWrapper<TermsOfService> lqw = Wrappers.lambdaQuery();
+        lqw.orderByAsc(TermsOfService::getId);
+        lqw.eq(StringUtils.isNotBlank(bo.getTitle()), TermsOfService::getTitle, bo.getTitle());
+        lqw.eq(StringUtils.isNotBlank(bo.getContent()), TermsOfService::getContent, bo.getContent());
+        lqw.eq(StringUtils.isNotBlank(bo.getLanguage()), TermsOfService::getLanguage, bo.getLanguage());
+        lqw.eq(bo.getIsDefault() != null, TermsOfService::getIsDefault, bo.getIsDefault());
+        return lqw;
+    }
+
+    /**
+     * 新增使用条款管理
+     *
+     * @param bo 使用条款管理
+     * @return 是否新增成功
+     */
+    @Override
+    public Boolean insertByBo(TermsOfServiceBo bo) {
+        TermsOfService add = MapstructUtils.convert(bo, TermsOfService.class);
+        validEntityBeforeSave(add);
+        Long isDefault = bo.getIsDefault();
+        if(isDefault==1L){
+            //如果这个是默认的,其他的则都变成不是默认的
+            baseMapper.updateTermsServiceOtherFalse();
+        }
+
+        boolean flag = baseMapper.insertTermsService(add) > 0;
+        if (flag) {
+            bo.setId(add.getId());
+        }
+        return flag;
+    }
+
+    /**
+     * 修改使用条款管理
+     *
+     * @param bo 使用条款管理
+     * @return 是否修改成功
+     */
+    @Override
+    public Boolean updateByBo(TermsOfServiceBo bo) {
+        TermsOfService update = MapstructUtils.convert(bo, TermsOfService.class);
+        validEntityBeforeSave(update);
+        if(bo.getIsDefault()==1L){
+            //如果这个是默认的,其他的则都变成不是默认的
+            baseMapper.updateTermsServiceOtherFalse();
+        }
+
+        return baseMapper.updateTermsServiceById(update) > 0;
+    }
+
+    /**
+     * 保存前的数据校验
+     */
+    private void validEntityBeforeSave(TermsOfService entity){
+        //TODO 做一些数据校验,如唯一约束
+    }
+
+    /**
+     * 校验并批量删除使用条款管理信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if(isValid){
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return baseMapper.deleteTermsServiceById(ids) > 0;
+    }
+
+    @Override
+    public TermsOfServiceVo selectTermsServiceListMax() {
+        return baseMapper.selectTermsServiceListMax();
+    }
+
+    public static String replaceHtml(String html) {
+        if (html == null || html.isEmpty()) {
+            return "";
+        }
+        // 正则表达式移除所有的HTML标签
+        return html.replaceAll("<[^>]*>", "");
+    }
+}

+ 88 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/TermsOfServiceMapper.xml

@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.dromara.business.mapper.TermsOfServiceMapper">
+
+
+    <select id="selectVoPage2" resultType="org.dromara.business.domain.vo.TermsOfServiceVo">
+        SELECT id, title, content, version, language, is_default, create_time, update_time
+        FROM terms_of_service ${ew.customSqlSegment}
+    </select>
+
+
+    <select id="selectTermsServiceList" resultType="org.dromara.business.domain.vo.TermsOfServiceVo">
+        SELECT id, title, content, version, language, is_default, create_time, update_time
+        FROM terms_of_service  ${ew.customSqlSegment}
+    </select>
+
+    <select id="selectVoInfoById" resultType="org.dromara.business.domain.vo.TermsOfServiceVo">
+        SELECT id, title, content, version, language, is_default, create_time, update_time
+        FROM terms_of_service   WHERE id =  #{id}
+    </select>
+
+    <update id="updateTermsServiceById">
+        UPDATE terms_of_service
+        <set>
+            <if test="title != null and title != ''">
+                title = #{title},
+            </if>
+            <if test="content != null and content != ''">
+                content = #{content},
+            </if>
+            <if test="version != null and version != ''">
+                version = #{version},
+            </if>
+            <if test="language != null and language != ''">
+                language = #{language},
+            </if>
+            <if test="isDefault != null">
+                is_default = #{isDefault},
+            </if>
+            update_time = NOW()
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <insert id="insertTermsService">
+        INSERT INTO terms_of_service
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="title != null and title != ''">title,</if>
+            <if test="content != null and content != ''">content,</if>
+            <if test="version != null and version != ''">version,</if>
+            <if test="language != null and language != ''">language,</if>
+            <if test="isDefault != null">is_default,</if>
+        </trim>
+        VALUES
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="title != null and title != ''">#{title},</if>
+            <if test="content != null and content != ''">#{content},</if>
+            <if test="version != null and version != ''">#{version},</if>
+            <if test="language != null and language != ''">#{language},</if>
+            <if test="isDefault != null">#{isDefault},</if>
+        </trim>
+    </insert>
+
+    <delete id="deleteTermsServiceById">
+        DELETE FROM terms_of_service
+        <where>
+            id IN
+            <foreach item="id" collection="ids" open="(" separator="," close=")">
+                <if test="id > 0">
+                    #{id}
+                </if>
+            </foreach>
+        </where>
+    </delete>
+
+    <select id="selectTermsServiceListMax" resultType="org.dromara.business.domain.vo.TermsOfServiceVo">
+        SELECT id, title, content, version, language, is_default, create_time, update_time
+        FROM terms_of_service where is_default = true  limit 1
+    </select>
+
+    <update id="updateTermsServiceOtherFalse">
+        UPDATE terms_of_service  set is_default = false
+    </update>
+
+
+</mapper>