From c70d123fe52904508490000600e59e55f8268a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E7=8B=BC=E8=93=9D=E5=A4=A9?= Date: Sat, 16 Nov 2024 02:32:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B4=BB=E5=8A=A8=E6=8A=A5=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../harmony/constant/SystemConfigKey.java | 1 + .../controller/ActivateController.java | 20 ++++ .../harmony/domain/dto/ParamSelect.java | 9 ++ .../harmony/domain/entity/ActivateUser.java | 15 +++ .../harmony/domain/entity/ActiveBaseInfo.java | 2 +- .../harmony/domain/vo/ActivateDetailVO.java | 29 +++++ .../harmony/domain/vo/ActivateUserVO.java | 16 +++ .../harmony/mapper/ActivateMapper.java | 8 ++ .../harmony/mapper/ActivateUserMapper.java | 15 +++ .../harmony/service/ActivateService.java | 8 ++ .../service/impl/ActivateServiceImpl.java | 111 +++++++++++++++++- src/main/resources/application.properties | 4 +- .../resources/mapper/ActivateUserMapper.xml | 6 + 13 files changed, 236 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/guaiguailang/harmony/domain/dto/ParamSelect.java create mode 100644 src/main/java/com/guaiguailang/harmony/domain/entity/ActivateUser.java create mode 100644 src/main/java/com/guaiguailang/harmony/domain/vo/ActivateDetailVO.java create mode 100644 src/main/java/com/guaiguailang/harmony/domain/vo/ActivateUserVO.java create mode 100644 src/main/java/com/guaiguailang/harmony/mapper/ActivateUserMapper.java create mode 100644 src/main/resources/mapper/ActivateUserMapper.xml diff --git a/src/main/java/com/guaiguailang/harmony/constant/SystemConfigKey.java b/src/main/java/com/guaiguailang/harmony/constant/SystemConfigKey.java index e6c85c0..8952152 100644 --- a/src/main/java/com/guaiguailang/harmony/constant/SystemConfigKey.java +++ b/src/main/java/com/guaiguailang/harmony/constant/SystemConfigKey.java @@ -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"; } diff --git a/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java b/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java index 07c80e1..5c3d5c8 100644 --- a/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java +++ b/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java @@ -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)); + } } diff --git a/src/main/java/com/guaiguailang/harmony/domain/dto/ParamSelect.java b/src/main/java/com/guaiguailang/harmony/domain/dto/ParamSelect.java new file mode 100644 index 0000000..b78a35f --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/dto/ParamSelect.java @@ -0,0 +1,9 @@ +package com.guaiguailang.harmony.domain.dto; + +import lombok.Data; + +@Data +public class ParamSelect { + private String paramName; + private String paramValue; +} diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/ActivateUser.java b/src/main/java/com/guaiguailang/harmony/domain/entity/ActivateUser.java new file mode 100644 index 0000000..c3e520f --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/ActivateUser.java @@ -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; + +} diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java b/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java index 60a6bc7..23b4968 100644 --- a/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java @@ -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; diff --git a/src/main/java/com/guaiguailang/harmony/domain/vo/ActivateDetailVO.java b/src/main/java/com/guaiguailang/harmony/domain/vo/ActivateDetailVO.java new file mode 100644 index 0000000..0b28c69 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/vo/ActivateDetailVO.java @@ -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 users; + +} \ No newline at end of file diff --git a/src/main/java/com/guaiguailang/harmony/domain/vo/ActivateUserVO.java b/src/main/java/com/guaiguailang/harmony/domain/vo/ActivateUserVO.java new file mode 100644 index 0000000..bad93ff --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/vo/ActivateUserVO.java @@ -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; + +} diff --git a/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java index 9b0cddc..47ff8a7 100644 --- a/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java +++ b/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java @@ -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 { + @Select("SELECT * FROM active_base_info WHERE ${paramName} != #{paramValue}") + List getActivate(@Param("paramName") String paramName, @Param("paramValue") String paramValue); + } diff --git a/src/main/java/com/guaiguailang/harmony/mapper/ActivateUserMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/ActivateUserMapper.java new file mode 100644 index 0000000..dda5fbd --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/mapper/ActivateUserMapper.java @@ -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 { + @Select("SELECT * from activate_user join user_info on activate_user.uid=user_info.id where activate_user.acid=#{acid}") + List getActivateUser(long acid); +} diff --git a/src/main/java/com/guaiguailang/harmony/service/ActivateService.java b/src/main/java/com/guaiguailang/harmony/service/ActivateService.java index 8473e3f..14db23a 100644 --- a/src/main/java/com/guaiguailang/harmony/service/ActivateService.java +++ b/src/main/java/com/guaiguailang/harmony/service/ActivateService.java @@ -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); } diff --git a/src/main/java/com/guaiguailang/harmony/service/impl/ActivateServiceImpl.java b/src/main/java/com/guaiguailang/harmony/service/impl/ActivateServiceImpl.java index 5a08dc4..e137334 100644 --- a/src/main/java/com/guaiguailang/harmony/service/impl/ActivateServiceImpl.java +++ b/src/main/java/com/guaiguailang/harmony/service/impl/ActivateServiceImpl.java @@ -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 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 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 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())); + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 6a50e09..0fc6cb4 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -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 diff --git a/src/main/resources/mapper/ActivateUserMapper.xml b/src/main/resources/mapper/ActivateUserMapper.xml new file mode 100644 index 0000000..1c30cf4 --- /dev/null +++ b/src/main/resources/mapper/ActivateUserMapper.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file