膳逸:用户分页查询功能开发文档

概述

本开发文档详细描述了MIS系统中的分页查询活动接口的设计与实现。通过该接口,用户可以根据各种条件查询活动信息,返回符合条件的活动列表,并支持分页显示。

功能需求

  1. 分页查询活动:用户可以通过提交查询条件来分页获取活动信息,包括活动名称、状态、开始时间、结束时间等。
  2. 权限控制:确保只有具有特定权限的用户可以访问此接口。

接口详情

分页查询活动接口

接口路径
/mis_user/searchActivityByPage
请求方法

POST

Body 请求参数

{
  "page": 1,
  "length": 10,
  "id": null,
  "activityName": "",
  "startTime": "",
  "endTime": "",
  "status": null
}

请求参数

名称位置类型必选说明
Tokenheaderstringnone
bodybodyobjectnone
» pagebodyintegernone
» lengthbodyintegernone
» idbodyintegernone
» activityNamebodystringnone
» startTimebodystringnone
» endTimebodystringnone
» statusbodyinteger活动状态(0未开始,1进行中,2已结束)

返回示例

成功

{
  "msg": "success",
  "result": {
    "totalCount": 7,
    "pageSize": 10,
    "totalPage": 1,
    "pageIndex": 1,
    "list": [
      {
        "reward": "大白兔礼包",
        "start_time": "2024-06-01",
        "requirements": "连续打卡1天",
        "participants_count": 103,
        "name": "六一活动",
        "end_time": "2024-08-07",
        "description": "儿童节活动",
        "count_day": 1,
        "id": 1,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406221703940.png",
        "status": 1
      },
      {
        "reward": "劳动礼包",
        "start_time": "2024-05-01",
        "requirements": "连续打卡5天",
        "participants_count": 502,
        "name": "五一活动",
        "end_time": "2024-08-30",
        "description": "劳动节活动",
        "count_day": 5,
        "id": 2,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406221704667.png",
        "status": 1
      },
      {
        "reward": "春节大礼包",
        "start_time": "2024-02-01",
        "requirements": "连续打卡10天",
        "participants_count": 1000,
        "name": "春节活动",
        "end_time": "2024-03-01",
        "description": "春节活动",
        "count_day": 10,
        "id": 3,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406221705143.png",
        "status": 1
      },
      {
        "reward": "有机会获得健康饮食礼包或运动器材",
        "start_time": "2024-06-14",
        "requirements": "用户每天上传一张照片,这张照片可以是与父亲一起共进餐,或者为父亲准备的美食照片。可以只包含食物,不一定要包含父亲。即图片要求满足下面之一即可:1.有食物;2.有人物和食物;",
        "participants_count": 1003,
        "name": "\"父爱如山,食在心间\"父亲节特别活动",
        "end_time": "2024-06-23",
        "description": "上传与父亲的进餐瞬间",
        "count_day": 5,
        "id": 8,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406161248411.jpg",
        "status": 1
      },
      {
        "reward": "欢度元旦大礼包",
        "start_time": "2023-12-31",
        "requirements": "连续打卡1天",
        "participants_count": 0,
        "name": "元旦活动",
        "end_time": "2023-12-31",
        "description": "欢度元旦",
        "count_day": 1,
        "id": 9,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406221929172.png",
        "status": 1
      },
      {
        "reward": "情人节大礼包",
        "start_time": "2024-02-14",
        "requirements": "打卡一天",
        "participants_count": 0,
        "name": "情人节活动",
        "end_time": "2024-02-14",
        "description": "情人节",
        "count_day": 1,
        "id": 10,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406221932526.png",
        "status": 1
      },
      {
        "reward": "5积分",
        "start_time": "2024-06-20",
        "requirements": "发布一张光盘图片",
        "participants_count": 0,
        "name": "七一活动",
        "end_time": "2024-06-27",
        "description": "学习建党精神,珍惜粮食资源",
        "count_day": 0,
        "id": 12,
        "picture": "https://lhplanet-1316168555.cos.ap-beijing.myqcloud.com/shanyi/development-documentation/development-documentation-v3.0.assets/202406232003814.jpg",
        "status": 1
      }
    ]
  },
  "code": 200
}

返回结果

状态码状态码含义说明数据模型
200OK成功Inline

返回数据结构

状态码 200

名称类型必选约束中文名说明
» codeintegertruenonenone
» msgstringtruenonenone
» resultobjecttruenonenone
»» totalCountintegertruenonenone
»» pageSizeintegertruenonenone
»» totalPageintegertruenonenone
»» pageIndexintegertruenonenone
»» list[object]truenonenone
»»» rewardstringtruenonenone
»»» start_timestringtruenonenone
»»» requirementsstringtruenonenone
»»» participants_countintegertruenonenone
»»» namestringtruenonenone
»»» end_timestringtruenonenone
»»» descriptionstringtruenonenone
»»» idintegertruenonenone
»»» picturestringtruenonenone
»»» statusintegertruenonenone
»»» count_dayintegertruenonenone

实现细节

控制器代码

@PostMapping("/searchActivityByPage")
    @SaCheckLogin
    @SaCheckPermission(value = {"ROOT", "ACTIVITY:SELECT"}, mode = SaMode.OR)
    public R searchActivityByPage(@RequestBody @Valid searchActivityByPageForm form) {
        Map param = BeanUtil.beanToMap(form);
        int page = form.getPage();
        int length = form.getLength();
        int start = (page - 1) * length;
        param.put("start", start);
        PageUtils pageUtils = misUserService.searchActivityByPage(param);
        return R.ok().put("result", pageUtils);
    }

表单验证类

@Data
public class searchActivityByPageForm {
    @NotNull(message = "page不能为空")
    @Min(value = 1, message = "page最小值为1")
    private Integer page;

    @NotNull(message = "length不能为空")
    @Range(min = 10, max = 50, message = "length每页长度不正确,最小10,最大50")
    private Integer length;

    @Min(value = 1, message = "id最小值为1")
    private Integer id;

//    @NotNull(message = "活动名称不能为空")
    private String activityName;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private DateTime startTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private DateTime endTime;

    @Range(min = 0, max = 2, message = "status状态码不正确,0未开始,1进行中,2已结束")
    private Byte status;
}

MisUserDao.xml

 <select id="searchActivityByPage" parameterType="Map" resultType="java.util.HashMap">
        SELECT a.id,
        a.name,
        a.description,
        a.requirements,
        a.start_time,
        a.end_time,
        a.participants_count,
        a.reward,
        a.status,
        a.picture,
        a.count_day
        FROM activity a
        WHERE 1 = 1
        <if test="id != null and id != ''">
            AND a.id = #{id}
        </if>
        <if test="activityName != null and activityName != ''">
            AND a.name LIKE CONCAT('%', #{activityName}, '%')
        </if>
        <if test="status != null and description != ''">
            AND a.status = #{status}
        </if>
        <if test="startTime != null">
            AND a.start_time &gt;= #{startTime}
        </if>
        <if test="endTime != null">
            AND a.end_time &lt;= #{endTime}
        </if>
        LIMIT #{length} OFFSET #{start}
    </select>

通过上述文档,实现了分页查询活动功能

  • 16
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值