Sfoglia il codice sorgente

feat(business): 添加运动申明相关功能

- 新增运动申明相关的数据模型、业务对象、控制器、服务实现和映射文件
- 实现运动申明的查询、分页查询、导出、新增、修改和删除功能- 添加获取默认运动申明的功能
- 在安全配置中排除相关接口的登录验证
fugui001 3 mesi fa
parent
commit
ef53753889

+ 3 - 1
ruoyi-common/ruoyi-common-security/src/main/java/org/dromara/common/security/config/SecurityConfig.java

@@ -53,7 +53,9 @@ public class SecurityConfig implements WebMvcConfigurer {
                     // 获取所有的
                     .match(allUrlHandler.getUrls())
                     // 排除不需要登录的接口路径
-                    .notMatch("/business/policy/selectPrivacyPolicyListMax","/business/ofService/selectTermsServiceListMax") // 替换为你的开放接口路径
+                    .notMatch("/business/policy/selectPrivacyPolicyListMax",
+                        "/business/ofService/selectTermsServiceListMax",
+                        "/business/terms/getSportTermsListMax") // 替换为你的开放接口路径
                     // 对未排除的路径进行检查
                     .check(() -> {
                         HttpServletRequest request = ServletUtils.getRequest();

+ 111 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/controller/SportTermsController.java

@@ -0,0 +1,111 @@
+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.SportTermsBo;
+import org.dromara.business.domain.vo.SportTermsVo;
+import org.dromara.business.service.ISportTermsService;
+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-09-10
+ */
+@Validated
+@RequiredArgsConstructor
+@RestController
+@RequestMapping("/business/terms")
+public class SportTermsController extends BaseController {
+
+    private final ISportTermsService sportTermsService;
+
+    /**
+     * 查询运动申明列表
+     */
+    @SaCheckPermission("business:terms:list")
+    @GetMapping("/list")
+    public TableDataInfo<SportTermsVo> list(SportTermsBo bo, PageQuery pageQuery) {
+        return sportTermsService.queryPageList(bo, pageQuery);
+    }
+
+    /**
+     * 导出运动申明列表
+     */
+    @SaCheckPermission("business:terms:export")
+    @Log(title = "运动申明", businessType = BusinessType.EXPORT)
+    @PostMapping("/export")
+    public void export(SportTermsBo bo, HttpServletResponse response) {
+        List<SportTermsVo> list = sportTermsService.queryList(bo);
+        ExcelUtil.exportExcel(list, "运动申明", SportTermsVo.class, response);
+    }
+
+    /**
+     * 获取运动申明详细信息
+     *
+     * @param id 主键
+     */
+    @SaCheckPermission("business:terms:query")
+    @GetMapping("/{id}")
+    public R<SportTermsVo> getInfo(@NotNull(message = "主键不能为空")
+                                     @PathVariable Long id) {
+        return R.ok(sportTermsService.queryById(id));
+    }
+
+    /**
+     * 新增运动申明
+     */
+    @SaCheckPermission("business:terms:add")
+    @Log(title = "运动申明", businessType = BusinessType.INSERT)
+    @RepeatSubmit()
+    @PostMapping()
+    public R<Void> add(@Validated(AddGroup.class) @RequestBody SportTermsBo bo) {
+        return toAjax(sportTermsService.insertByBo(bo));
+    }
+
+    /**
+     * 修改运动申明
+     */
+    @SaCheckPermission("business:terms:edit")
+    @Log(title = "运动申明", businessType = BusinessType.UPDATE)
+    @RepeatSubmit()
+    @PutMapping()
+    public R<Void> edit(@Validated(EditGroup.class) @RequestBody SportTermsBo bo) {
+        return toAjax(sportTermsService.updateByBo(bo));
+    }
+
+    /**
+     * 删除运动申明
+     *
+     * @param ids 主键串
+     */
+    @SaCheckPermission("business:terms:remove")
+    @Log(title = "运动申明", businessType = BusinessType.DELETE)
+    @DeleteMapping("/{ids}")
+    public R<Void> remove(@NotEmpty(message = "主键不能为空")
+                          @PathVariable Long[] ids) {
+        return toAjax(sportTermsService.deleteWithValidByIds(List.of(ids), true));
+    }
+
+    @GetMapping("/getSportTermsListMax")
+    public R<SportTermsVo> selectSportTermsListMax() {
+        return R.ok(sportTermsService.selectSportTermsListMax());
+    }
+
+}

+ 53 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/domain/SportTerms.java

@@ -0,0 +1,53 @@
+package org.dromara.business.domain;
+
+import com.baomidou.mybatisplus.annotation.*;
+import lombok.Data;
+import java.io.Serial;
+
+/**
+ * 运动申明对象 sport_terms
+ *
+ * @author Lion Li
+ * @date 2025-09-10
+ */
+@Data
+@TableName("sport_terms")
+public class SportTerms{
+
+    @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/SportTermsBo.java

@@ -0,0 +1,52 @@
+package org.dromara.business.domain.bo;
+
+import org.dromara.business.domain.SportTerms;
+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.*;
+
+/**
+ * 运动申明业务对象 sport_terms
+ *
+ * @author Lion Li
+ * @date 2025-09-10
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@AutoMapper(target = SportTerms.class, reverseConvertGenerate = false)
+public class SportTermsBo 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;
+
+
+}

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

@@ -0,0 +1,64 @@
+package org.dromara.business.domain.vo;
+
+import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
+import cn.idev.excel.annotation.ExcelProperty;
+import org.dromara.business.domain.SportTerms;
+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;
+
+
+
+/**
+ * 运动申明视图对象 sport_terms
+ *
+ * @author Lion Li
+ * @date 2025-09-10
+ */
+@Data
+@ExcelIgnoreUnannotated
+@AutoMapper(target = SportTerms.class)
+public class SportTermsVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 主键
+     */
+    @ExcelProperty(value = "主键")
+    private Long id;
+
+    /**
+     * 声明标题
+     */
+    @ExcelProperty(value = "声明标题")
+    private String title;
+
+    /**
+     * 声明内容(HTML格式)
+     */
+    @ExcelProperty(value = "声明内容", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "H=TML格式")
+    private String content;
+
+    /**
+     * 语言代码(如 zh-CN, en-US)
+     */
+    @ExcelProperty(value = "语言代码", converter = ExcelDictConvert.class)
+    @ExcelDictFormat(readConverterExp = "如=,z=h-CN,,e=n-US")
+    private String language;
+
+    /**
+     * 是否为默认版本
+     */
+    @ExcelProperty(value = "是否为默认版本")
+    private Long isDefault;
+
+    @ExcelProperty(value = "消息内容text")
+    private String contentText;
+}

+ 52 - 0
ruoyi-modules/ruoyi-system/src/main/java/org/dromara/business/mapper/SportTermsMapper.java

@@ -0,0 +1,52 @@
+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.SportTerms;
+import org.dromara.business.domain.vo.SportTermsVo;
+import org.dromara.common.mybatis.core.mapper.BaseMapperPlus;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * 运动申明Mapper接口
+ *
+ * @author Lion Li
+ * @date 2025-09-10
+ */
+@DS("mysql2")
+public interface SportTermsMapper extends BaseMapperPlus<SportTerms, SportTermsVo> {
+
+    @InterceptorIgnore(tenantLine = "true")
+    Page<SportTermsVo> selectVoPage2(@Param("page") Page<SportTerms> page, @Param("ew") Wrapper<SportTerms> wrapper);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int insertSportTerms(SportTerms rewardClaims);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int updateSportTermsById(SportTerms rewardClaims);
+
+    @InterceptorIgnore(tenantLine = "true")
+    int deleteSportTermsById(@Param("ids") Collection<Long> ids);
+
+    @InterceptorIgnore(tenantLine = "true")
+    SportTermsVo selectVoInfoById(Long id);
+
+    @InterceptorIgnore(tenantLine = "true")
+    List<SportTermsVo> selectSportTermsList(@Param("ew") Wrapper<SportTerms> wrapper);
+
+    @InterceptorIgnore(tenantLine = "true")
+    SportTermsVo selectSportTermsMax();
+
+    @InterceptorIgnore(tenantLine = "true")
+    int updateSportTermsOtherFalse();
+
+
+
+
+
+}

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

@@ -0,0 +1,74 @@
+package org.dromara.business.service;
+
+import org.dromara.business.domain.bo.SportTermsBo;
+import org.dromara.business.domain.vo.SportTermsVo;
+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-09-10
+ */
+public interface ISportTermsService {
+
+    /**
+     * 查询运动申明
+     *
+     * @param id 主键
+     * @return 运动申明
+     */
+    SportTermsVo queryById(Long id);
+
+    /**
+     * 分页查询运动申明列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 运动申明分页列表
+     */
+    TableDataInfo<SportTermsVo> queryPageList(SportTermsBo bo, PageQuery pageQuery);
+
+    /**
+     * 查询符合条件的运动申明列表
+     *
+     * @param bo 查询条件
+     * @return 运动申明列表
+     */
+    List<SportTermsVo> queryList(SportTermsBo bo);
+
+    /**
+     * 新增运动申明
+     *
+     * @param bo 运动申明
+     * @return 是否新增成功
+     */
+    Boolean insertByBo(SportTermsBo bo);
+
+    /**
+     * 修改运动申明
+     *
+     * @param bo 运动申明
+     * @return 是否修改成功
+     */
+    Boolean updateByBo(SportTermsBo bo);
+
+    /**
+     * 校验并批量删除运动申明信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
+
+    /**
+     * 查询默认的那一条数据
+     * @return
+     */
+    SportTermsVo selectSportTermsListMax();
+}

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

@@ -0,0 +1,163 @@
+package org.dromara.business.service.impl;
+
+import org.dromara.business.domain.SportTerms;
+import org.dromara.business.domain.bo.SportTermsBo;
+import org.dromara.business.domain.vo.SportTermsVo;
+import org.dromara.business.domain.vo.TermsOfServiceVo;
+import org.dromara.business.mapper.SportTermsMapper;
+import org.dromara.business.service.ISportTermsService;
+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-09-10
+ */
+@Slf4j
+@RequiredArgsConstructor
+@Service
+public class SportTermsServiceImpl implements ISportTermsService {
+
+    private final SportTermsMapper baseMapper;
+
+    /**
+     * 查询运动申明
+     *
+     * @param id 主键
+     * @return 运动申明
+     */
+    @Override
+    public SportTermsVo queryById(Long id){
+        return baseMapper.selectVoInfoById(id);
+    }
+
+    /**
+     * 分页查询运动申明列表
+     *
+     * @param bo        查询条件
+     * @param pageQuery 分页参数
+     * @return 运动申明分页列表
+     */
+    @Override
+    public TableDataInfo<SportTermsVo> queryPageList(SportTermsBo bo, PageQuery pageQuery) {
+        LambdaQueryWrapper<SportTerms> lqw = buildQueryWrapper(bo);
+        Page<SportTermsVo> result = baseMapper.selectVoPage2(pageQuery.build(), lqw);
+        List<SportTermsVo> records = result.getRecords();
+        for (SportTermsVo record : records) {
+            String contentText=replaceHtml(record.getContent());
+            record.setContentText(contentText);
+        }
+        return TableDataInfo.build(result);
+    }
+
+    /**
+     * 查询符合条件的运动申明列表
+     *
+     * @param bo 查询条件
+     * @return 运动申明列表
+     */
+    @Override
+    public List<SportTermsVo> queryList(SportTermsBo bo) {
+        LambdaQueryWrapper<SportTerms> lqw = buildQueryWrapper(bo);
+        return baseMapper.selectSportTermsList(lqw);
+    }
+
+    private LambdaQueryWrapper<SportTerms> buildQueryWrapper(SportTermsBo bo) {
+        Map<String, Object> params = bo.getParams();
+        LambdaQueryWrapper<SportTerms> lqw = Wrappers.lambdaQuery();
+        lqw.orderByAsc(SportTerms::getId);
+        lqw.eq(StringUtils.isNotBlank(bo.getTitle()), SportTerms::getTitle, bo.getTitle());
+        lqw.eq(StringUtils.isNotBlank(bo.getContent()), SportTerms::getContent, bo.getContent());
+        lqw.eq(StringUtils.isNotBlank(bo.getLanguage()), SportTerms::getLanguage, bo.getLanguage());
+        lqw.eq(bo.getIsDefault() != null, SportTerms::getIsDefault, bo.getIsDefault());
+        return lqw;
+    }
+
+    /**
+     * 新增运动申明
+     *
+     * @param bo 运动申明
+     * @return 是否新增成功
+     */
+    @Override
+    public Boolean insertByBo(SportTermsBo bo) {
+        SportTerms add = MapstructUtils.convert(bo, SportTerms.class);
+        validEntityBeforeSave(add);
+        if(bo.getIsDefault()==1L){
+            //如果这个是默认的,其他的则都变成不是默认的
+            baseMapper.updateSportTermsOtherFalse();
+        }
+        boolean flag = baseMapper.insertSportTerms(add) > 0;
+        if (flag) {
+            bo.setId(add.getId());
+        }
+        return flag;
+    }
+
+    /**
+     * 修改运动申明
+     *
+     * @param bo 运动申明
+     * @return 是否修改成功
+     */
+    @Override
+    public Boolean updateByBo(SportTermsBo bo) {
+        SportTerms update = MapstructUtils.convert(bo, SportTerms.class);
+        validEntityBeforeSave(update);
+        if(bo.getIsDefault()==1L){
+            //如果这个是默认的,其他的则都变成不是默认的
+            baseMapper.updateSportTermsOtherFalse();
+        }
+        return baseMapper.updateSportTermsById(update) > 0;
+    }
+
+    /**
+     * 保存前的数据校验
+     */
+    private void validEntityBeforeSave(SportTerms entity){
+        //TODO 做一些数据校验,如唯一约束
+    }
+
+    /**
+     * 校验并批量删除运动申明信息
+     *
+     * @param ids     待删除的主键集合
+     * @param isValid 是否进行有效性校验
+     * @return 是否删除成功
+     */
+    @Override
+    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
+        if(isValid){
+            //TODO 做一些业务上的校验,判断是否需要校验
+        }
+        return baseMapper.deleteSportTermsById(ids) > 0;
+    }
+
+    @Override
+    public SportTermsVo selectSportTermsListMax() {
+        return baseMapper.selectSportTermsMax();
+    }
+
+    public static String replaceHtml(String html) {
+        if (html == null || html.isEmpty()) {
+            return "";
+        }
+        // 正则表达式移除所有的HTML标签
+        return html.replaceAll("<[^>]*>", "");
+    }
+
+}

+ 111 - 0
ruoyi-modules/ruoyi-system/src/main/resources/mapper/business/SportTermsMapper.xml

@@ -0,0 +1,111 @@
+<?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.SportTermsMapper">
+
+    <select id="selectVoPage2" resultType="org.dromara.business.domain.vo.SportTermsVo">
+        SELECT
+            id,
+            title,
+            content,
+            version,
+            language,
+            is_default,
+            create_time,
+            update_time
+        FROM sport_terms ${ew.customSqlSegment}
+    </select>
+
+
+    <select id="selectSportTermsList" resultType="org.dromara.business.domain.vo.SportTermsVo">
+        SELECT
+            id,
+            title,
+            content,
+            version,
+            language,
+            is_default,
+            create_time,
+            update_time
+        FROM sport_terms  ${ew.customSqlSegment}
+    </select>
+
+    <select id="selectVoInfoById" resultType="org.dromara.business.domain.vo.SportTermsVo">
+        SELECT
+            id,
+            title,
+            content,
+            version,
+            language,
+            is_default,
+            create_time,
+            update_time
+        FROM sport_terms   WHERE id =  #{id}
+    </select>
+
+    <update id="updateSportTermsById" parameterType="org.dromara.business.domain.SportTerms">
+        UPDATE sport_terms
+        <set>
+            <if test="title != null">title = #{title},</if>
+            <if test="content != null">content = #{content},</if>
+            <if test="version != null">version = #{version},</if>
+            <if test="language != null">language = #{language},</if>
+            <if test="isDefault != null">is_default = #{isDefault},</if>
+        </set>
+        WHERE id = #{id}
+    </update>
+
+    <!-- 插入 -->
+    <insert id="insertSportTerms" parameterType="org.dromara.business.domain.SportTerms">
+        INSERT INTO sport_terms
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="title != null">title,</if>
+            <if test="content != null">content,</if>
+            <if test="version != null">version,</if>
+            <if test="language != null">language,</if>
+            <if test="isDefault != null">is_default,</if>
+        </trim>
+        VALUES
+        <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="title != null">#{title},</if>
+            <if test="content != null">#{content},</if>
+            <if test="version != null">#{version},</if>
+            <if test="language != null">#{language},</if>
+            <if test="isDefault != null">#{isDefault},</if>
+        </trim>
+    </insert>
+
+    <delete id="deleteSportTermsById">
+        DELETE FROM sport_terms
+        <where>
+            id IN
+            <foreach item="id" collection="ids" open="(" separator="," close=")">
+                <if test="id > 0">
+                    #{id}
+                </if>
+            </foreach>
+        </where>
+    </delete>
+
+    <select id="selectSportTermsMax" resultType="org.dromara.business.domain.vo.SportTermsVo">
+        SELECT
+            id,
+            title,
+            content,
+            version,
+            language,
+            is_default,
+            create_time,
+            update_time
+        FROM sport_terms
+        where is_default = true  limit 1
+    </select>
+
+
+    <update id="updateSportTermsOtherFalse">
+        UPDATE sport_terms  set is_default = false
+    </update>
+
+
+</mapper>