概述
本开发文档详细描述了MIS系统中的添加活动接口的设计与实现。通过该接口,用户可以提交活动信息,系统将保存这些信息以创建新的活动。
功能需求
- 添加活动:用户可以通过提交活动信息来创建新的活动。
- 权限控制:确保只有具有特定权限的用户可以访问此接口并添加活动。
接口详情
添加活动接口
接口路径
/mis_user/addActivity
请求方法
POST
前端返回要新增的活动信息,后端插入新的活动
Body 请求参数
{
"name": "测试活动",
"description": "测试活动",
"requirements": "测试需要",
"startTime": "2000-01-01",
"endTime": "2025-01-01",
"reward": "棒棒糖",
"picture": "http://dummyimage.com/400x400",
"status": 0,
"countDay": 1
}
请求参数
| 名称 | 位置 | 类型 | 必选 | 说明 |
|---|---|---|---|---|
| Token | header | string | 否 | none |
| body | body | object | 否 | none |
| » name | body | string | 是 | none |
| » description | body | string | 是 | none |
| » requirements | body | string | 是 | none |
| » startTime | body | string | 是 | none |
| » endTime | body | string | 是 | none |
| » reward | body | string | 是 | none |
| » picture | body | string | 是 | none |
| » status | body | integer | 是 | none |
| » countDay | body | integer | 是 | none |
返回示例
成功
{
"msg": "success",
"code": 200
}
返回结果
| 状态码 | 状态码含义 | 说明 | 数据模型 |
|---|---|---|---|
| 200 | OK | 成功 | Inline |
返回数据结构
状态码 200
| 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
|---|---|---|---|---|---|
| » code | integer | true | none | none | |
| » msg | string | true | none | none |
实现细节
控制器代码
@PostMapping("/addActivity")
@SaCheckLogin
@SaCheckPermission(value = {"ROOT", "ACTIVITY:INSERT"}, mode = SaMode.OR)
public R addActivity(@RequestBody @Valid InsertOrUpdateActivityForm form) {
Map param = BeanUtil.beanToMap(form);
boolean flag = misUserService.addActivity(param);
if (flag){
return R.ok();
}else {
return R.error("添加活动出错");
}
}
表单验证类
@Data
public class InsertOrUpdateActivityForm {
private Integer id;
@NotNull(message = "活动名称不能为空")
@Size(max = 20, message = "活动名称长度不能超过20个字符")
private String name;
@NotNull(message = "描述不能为空")
@Size(max = 200, message = "描述长度不能超过200个字符")
private String description;
@NotNull(message = "要求不能为空")
@Size(max = 255, message = "要求长度不能超过255个字符")
private String requirements;
@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;
@NotNull(message = "奖励不能为空")
@Size(max = 255, message = "奖励长度不能超过255个字符")
private String reward;
@NotNull(message = "图片不能为空")
private String picture;
@NotNull(message = "status状态码不能为空")
@Range(min = 0, max = 2, message = "status状态码不正确,0未开始,1进行中,2已结束")
private Byte status;
@NotNull(message = "countDay状态码不能为空")
private Integer countDay;
}
MisUserDao XML
<insert id="addActivity" parameterType="Map">
INSERT INTO activity (name, description, requirements, start_time, end_time, reward, picture ,status, count_day)
VALUES ( #{name}, #{description}, #{requirements}, #{startTime}, #{endTime}, #{reward}, #{picture}, #{status}, #{countDay});
</insert>
通过上述文档,可以实现增加活动的具体功能。

被折叠的 条评论
为什么被折叠?



