feat: 活动报名
This commit is contained in:
parent
e292ddceab
commit
c70d123fe5
@ -5,4 +5,5 @@ public class SystemConfigKey {
|
||||
public static final String SYS_CONFIG_URL_FRONT = "front_url";
|
||||
public static final String SYS_FILE_SAVE_PATH = "file_save";
|
||||
|
||||
public static final String ACTIVATE_JOIN = "activate_join";
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.guaiguailang.harmony.controller;
|
||||
|
||||
import com.guaiguailang.harmony.domain.dto.ParamSelect;
|
||||
import com.guaiguailang.harmony.domain.entity.ActivateUser;
|
||||
import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo;
|
||||
import com.guaiguailang.harmony.service.ActivateService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@ -24,6 +26,16 @@ public class ActivateController {
|
||||
// todo 以后可考虑按机构来加载
|
||||
return ResponseEntity.ok(activateService.loadActivate());
|
||||
}
|
||||
@Operation(
|
||||
summary = "活动 列表",
|
||||
description = "有条件的加载活动列表",
|
||||
tags = {"活动相关接口"}
|
||||
)
|
||||
@PostMapping("get")
|
||||
public ResponseEntity laodActivateSelect(@RequestBody ParamSelect paramSelect){
|
||||
// 只加载没被删除的
|
||||
return ResponseEntity.ok(activateService.loadActivateSelect(paramSelect));
|
||||
}
|
||||
@Operation(
|
||||
summary = "活动 新增",
|
||||
description = "新增一个活动",
|
||||
@ -69,4 +81,12 @@ public class ActivateController {
|
||||
public ResponseEntity delActivateNot(@RequestBody ActiveBaseInfo activeBaseInfo){
|
||||
return ResponseEntity.ok(activateService.delActivateNot(activeBaseInfo));
|
||||
}
|
||||
@PostMapping("/join")
|
||||
public ResponseEntity joinActivate(@RequestBody ActivateUser au){
|
||||
return ResponseEntity.ok(activateService.joinActivate(au));
|
||||
}
|
||||
@PostMapping("/detail")
|
||||
public ResponseEntity detailActivate(@RequestBody ActivateUser au){
|
||||
return ResponseEntity.ok(activateService.detailActivate(au));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.guaiguailang.harmony.domain.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ParamSelect {
|
||||
private String paramName;
|
||||
private String paramValue;
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package com.guaiguailang.harmony.domain.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActivateUser {
|
||||
|
||||
private long id;
|
||||
private long uid;
|
||||
private long acid;
|
||||
private long sf;
|
||||
private String about;
|
||||
private int status;
|
||||
|
||||
}
|
@ -18,7 +18,7 @@ public class ActiveBaseInfo {
|
||||
private java.sql.Timestamp startTime;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm")
|
||||
private java.sql.Timestamp endTime;
|
||||
private long status;
|
||||
private int status;
|
||||
private String description;
|
||||
private String imgUrl;
|
||||
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.guaiguailang.harmony.domain.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.guaiguailang.harmony.domain.entity.ActivateUser;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@Data
|
||||
public class ActivateDetailVO {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String creatorName;
|
||||
private Long creatorId;
|
||||
private String titleNext;
|
||||
private String agentId;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.sql.Timestamp createTime;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.sql.Timestamp updateTime;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.sql.Timestamp startTime;
|
||||
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private java.sql.Timestamp endTime;
|
||||
private int status;
|
||||
private String description;
|
||||
private String imgUrl;
|
||||
private List<ActivateUserVO> users;
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.guaiguailang.harmony.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ActivateUserVO {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
private long uid;
|
||||
private long acid;
|
||||
private long sf;
|
||||
private String about;
|
||||
private int status;
|
||||
|
||||
}
|
@ -2,8 +2,16 @@ package com.guaiguailang.harmony.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ActivateMapper extends BaseMapper<ActiveBaseInfo> {
|
||||
@Select("SELECT * FROM active_base_info WHERE ${paramName} != #{paramValue}")
|
||||
List<ActiveBaseInfo> getActivate(@Param("paramName") String paramName, @Param("paramValue") String paramValue);
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
package com.guaiguailang.harmony.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guaiguailang.harmony.domain.entity.ActivateUser;
|
||||
import com.guaiguailang.harmony.domain.vo.ActivateUserVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ActivateUserMapper extends BaseMapper<ActivateUser> {
|
||||
@Select("SELECT * from activate_user join user_info on activate_user.uid=user_info.id where activate_user.acid=#{acid}")
|
||||
List<ActivateUserVO> getActivateUser(long acid);
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
package com.guaiguailang.harmony.service;
|
||||
|
||||
import com.guaiguailang.harmony.domain.dto.ParamSelect;
|
||||
import com.guaiguailang.harmony.domain.entity.ActivateUser;
|
||||
import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo;
|
||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -20,4 +22,10 @@ public interface ActivateService {
|
||||
ResponseResult delActivateReal(ActiveBaseInfo activeBaseInfo);
|
||||
|
||||
ResponseResult delActivateNot(ActiveBaseInfo activeBaseInfo);
|
||||
|
||||
ResponseResult joinActivate(ActivateUser au);
|
||||
|
||||
ResponseResult detailActivate(ActivateUser au);
|
||||
|
||||
ResponseResult loadActivateSelect(ParamSelect paramSelect);
|
||||
}
|
||||
|
@ -1,23 +1,28 @@
|
||||
package com.guaiguailang.harmony.service.impl;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.github.yitter.idgen.YitIdHelper;
|
||||
import com.guaiguailang.harmony.constant.SystemConfigKey;
|
||||
import com.guaiguailang.harmony.domain.dto.ParamSelect;
|
||||
import com.guaiguailang.harmony.domain.entity.ActivateUser;
|
||||
import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo;
|
||||
import com.guaiguailang.harmony.domain.entity.UserInfo;
|
||||
import com.guaiguailang.harmony.domain.vo.ActivateDetailVO;
|
||||
import com.guaiguailang.harmony.domain.vo.ActivateUserVO;
|
||||
import com.guaiguailang.harmony.domain.vo.ResponseResult;
|
||||
import com.guaiguailang.harmony.mapper.ActivateMapper;
|
||||
import com.guaiguailang.harmony.mapper.ActivateUserMapper;
|
||||
import com.guaiguailang.harmony.mapper.ConfigMapper;
|
||||
import com.guaiguailang.harmony.mapper.UserMapper;
|
||||
import com.guaiguailang.harmony.service.ActivateService;
|
||||
import com.guaiguailang.harmony.utils.FileUpload;
|
||||
import com.guaiguailang.harmony.utils.UtilMD5;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@ -28,6 +33,10 @@ public class ActivateServiceImpl implements ActivateService {
|
||||
private UserMapper userMapper;
|
||||
@Autowired
|
||||
private ActivateMapper activateMapper;
|
||||
@Autowired
|
||||
private ActivateUserMapper activateUserMapper;
|
||||
@Autowired
|
||||
private ConfigMapper configMapper;
|
||||
|
||||
@Override
|
||||
public String uploadActivateProfile(MultipartFile file) {
|
||||
@ -112,4 +121,98 @@ public class ActivateServiceImpl implements ActivateService {
|
||||
return ResponseResult.error("恢复删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult joinActivate(ActivateUser au) {
|
||||
// 判断该用户是否已经报名,根据 au.getUid() and au.getAcid() 使用MyBatisPlus查询,如果已经报名,则返回失败信息,已经报名,请勿重新报名
|
||||
LambdaQueryWrapper<ActivateUser> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(ActivateUser::getUid, au.getUid())
|
||||
.eq(ActivateUser::getAcid, au.getAcid());
|
||||
boolean isExist = activateUserMapper.exists(queryWrapper);
|
||||
if (isExist) {
|
||||
return ResponseResult.error("已经报名,请勿重新报名");
|
||||
}
|
||||
// 设置id
|
||||
au.setId(YitIdHelper.nextId());//雪花ID,本项目专属。你们建议直接使用MYSQL自增id,就不用设置id了
|
||||
String r = configMapper.getKeyValue(SystemConfigKey.ACTIVATE_JOIN);
|
||||
if(r==null){return ResponseResult.error("获取配置失败");}
|
||||
|
||||
au.setStatus(Integer.parseInt(r));
|
||||
// 使用Mybatis Plus的插入功能
|
||||
int result = activateUserMapper.insert(au);
|
||||
if(result>0){
|
||||
return ResponseResult.success();
|
||||
}else{
|
||||
return ResponseResult.error("恢复删除失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult detailActivate(ActivateUser au) {
|
||||
// 根据au.id获取活动更的详情信息
|
||||
/**
|
||||
*CREATE TABLE `active_base_info` (
|
||||
* `id` bigint(20) NOT NULL COMMENT 'id(雪花',
|
||||
* `title` varchar(255) DEFAULT NULL COMMENT '活动标题',
|
||||
* `creator_name` varchar(255) DEFAULT NULL COMMENT '创建人名称',
|
||||
* `creator_id` bigint(20) DEFAULT NULL COMMENT '创建人id',
|
||||
* `title_next` varchar(255) DEFAULT NULL COMMENT '小标题',
|
||||
* `agent_id` varchar(20) DEFAULT NULL COMMENT '机构id',
|
||||
* `create_time` datetime DEFAULT NULL COMMENT '活动创建时间',
|
||||
* `update_time` datetime DEFAULT NULL COMMENT '活动更新时间',
|
||||
* `start_time` datetime DEFAULT NULL COMMENT '活动开始时间',
|
||||
* `end_time` datetime DEFAULT NULL COMMENT '活动结束时间',
|
||||
* `status` tinyint(4) DEFAULT NULL COMMENT '状态 0 停止 1 发布 -1 删除',
|
||||
* `description` varchar(255) DEFAULT NULL COMMENT '描述',
|
||||
* `img_url` varchar(255) DEFAULT NULL COMMENT '图片链接',
|
||||
* PRIMARY KEY (`id`)
|
||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
* 还需要加载报名这个活动的人员信息
|
||||
* CREATE TABLE `activate_user` (
|
||||
* `id` bigint(20) NOT NULL COMMENT 'id',
|
||||
* `uid` bigint(20) DEFAULT NULL COMMENT '用户id',
|
||||
* `acid` bigint(20) DEFAULT NULL COMMENT '活动id',
|
||||
* `sf` tinyint(4) DEFAULT NULL COMMENT '身份(1评委 2选手0观众)\r\n',
|
||||
* `about` varchar(255) DEFAULT NULL COMMENT '关于',
|
||||
* `status` tinyint(4) DEFAULT NULL COMMENT '状态(0 审核中 1审核通过 2打回)',
|
||||
* PRIMARY KEY (`id`)
|
||||
* ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
*
|
||||
* 最后编写一个返回值对象(VO)来接受并返回数据给前端
|
||||
* 注意:数据查询采用的MyBatis Plus
|
||||
* 已经导入了
|
||||
* @Autowired
|
||||
* private ActivateUserMapper activateUserMapper;
|
||||
*/
|
||||
// 根据 au.id 获取活动详细信息
|
||||
QueryWrapper<ActiveBaseInfo> baseInfoQuery = new QueryWrapper<>();
|
||||
baseInfoQuery.eq("id", au.getAcid());
|
||||
ActiveBaseInfo baseInfo = activateMapper.selectOne(baseInfoQuery);
|
||||
|
||||
if (baseInfo == null) {
|
||||
return ResponseResult.error("活动不存在");
|
||||
}
|
||||
System.out.println("查询活动信息");
|
||||
System.out.println(baseInfo.toString());
|
||||
System.out.println("查询报名人信息");
|
||||
|
||||
// 根据 au.acid 获取报名该活动的人员信息
|
||||
|
||||
List<ActivateUserVO> users = activateUserMapper.getActivateUser(au.getAcid());
|
||||
System.out.println("根据"+au.getAcid()+"查询到了用户:");
|
||||
System.out.println(users.toString());
|
||||
|
||||
// 封装到返回值对象中
|
||||
ActivateDetailVO detailVO = new ActivateDetailVO();
|
||||
BeanUtils.copyProperties(baseInfo, detailVO);
|
||||
detailVO.setUsers(users);
|
||||
System.out.println(detailVO.toString());
|
||||
// 返回成功结果
|
||||
return ResponseResult.success(detailVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseResult loadActivateSelect(ParamSelect paramSelect) {
|
||||
return ResponseResult.success(activateMapper.getActivate(paramSelect.getParamName(),paramSelect.getParamValue()));
|
||||
}
|
||||
}
|
||||
|
@ -23,11 +23,9 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
|
||||
# MyBatis Setting
|
||||
mybatis.type-aliases-package=com.guaiguailang.harmony.domain
|
||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||
|
||||
|
||||
# 下划线转小驼峰
|
||||
mybatis.configuration.map-underscore-to-camel-case=true
|
||||
|
||||
mybatis-plus.mapper-locations=classpath:mapper/*.xml
|
||||
# Redis Configuration
|
||||
spring.data.redis.host=localhost
|
||||
spring.data.redis.port=6379
|
||||
|
6
src/main/resources/mapper/ActivateUserMapper.xml
Normal file
6
src/main/resources/mapper/ActivateUserMapper.xml
Normal file
@ -0,0 +1,6 @@
|
||||
<?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="com.guaiguailang.harmony.mapper.ActivateUserMapper">
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user