From 2dbafa77ea2b062075f15ad64776e85db463b11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=90=8C=E7=8B=BC=E8=93=9D=E5=A4=A9?= Date: Wed, 13 Nov 2024 10:02:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B4=BB=E5=8A=A8=20=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ActivateController.java | 35 ++++++++++++ .../harmony/controller/UploadController.java | 8 +-- .../harmony/domain/entity/ActiveBaseInfo.java | 26 +++++++++ .../harmony/mapper/ActivateMapper.java | 9 +++ .../harmony/service/ActivateService.java | 8 +++ .../service/impl/ActivateServiceImpl.java | 55 +++++++++++++++++++ src/main/resources/mapper/ActivateMapper.xml | 7 +++ 7 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java create mode 100644 src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java create mode 100644 src/main/resources/mapper/ActivateMapper.xml diff --git a/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java b/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java index bf5f768..1c6bc10 100644 --- a/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java +++ b/src/main/java/com/guaiguailang/harmony/controller/ActivateController.java @@ -1,4 +1,39 @@ package com.guaiguailang.harmony.controller; +import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo; +import com.guaiguailang.harmony.service.ActivateService; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +@RestController +@Tag(name="活动相关接口") +@RequestMapping("/activate") public class ActivateController { + @Autowired + ActivateService activateService; + @Operation( + summary = "活动 列表", + description = "加载活动列表", + tags = {"活动相关接口"} + ) + @GetMapping + public ResponseEntity laodActivate(){ + // todo 以后可考虑按机构来加载 + return ResponseEntity.ok(activateService.loadActivate()); + } + + + @Operation( + summary = "活动 新增", + description = "新增一个活动", + tags = {"活动相关接口"} + ) + @PostMapping("/add") + public ResponseEntity addActivate(@RequestBody ActiveBaseInfo activeBaseInfo){ + return ResponseEntity.ok(activateService.addActivate(activeBaseInfo)); + } + } diff --git a/src/main/java/com/guaiguailang/harmony/controller/UploadController.java b/src/main/java/com/guaiguailang/harmony/controller/UploadController.java index b440318..59e13ee 100644 --- a/src/main/java/com/guaiguailang/harmony/controller/UploadController.java +++ b/src/main/java/com/guaiguailang/harmony/controller/UploadController.java @@ -50,15 +50,15 @@ public class UploadController { * @param file * @return */ - @Operation(summary = "活动 头图") - @PostMapping("/activate/profile") + @Operation(summary = "文件上传") + @PostMapping("/fileOne") public ResponseResult uploadActivateProfile(@RequestParam("file") MultipartFile file){ if(file.isEmpty()){ - return ResponseResult.error("图片为空,请重新选择"); + return ResponseResult.error("文件为空,请重新上传"); } String imgUrl = activateService.uploadActivateProfile(file); if(imgUrl==null){ - return ResponseResult.error("图片上传失败"); + return ResponseResult.error("文件上传失败"); } return ResponseResult.success(imgUrl); } diff --git a/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java b/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java new file mode 100644 index 0000000..60a6bc7 --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/domain/entity/ActiveBaseInfo.java @@ -0,0 +1,26 @@ +package com.guaiguailang.harmony.domain.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; + +@Data +public class ActiveBaseInfo { + + private long id; + private String title; + private String creatorName; + private long creatorId; + private String titleNext; + private String agentId; + private java.sql.Timestamp createTime; + private java.sql.Timestamp updateTime; + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm") + 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 String description; + private String imgUrl; + + +} diff --git a/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java b/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java new file mode 100644 index 0000000..9b0cddc --- /dev/null +++ b/src/main/java/com/guaiguailang/harmony/mapper/ActivateMapper.java @@ -0,0 +1,9 @@ +package com.guaiguailang.harmony.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface ActivateMapper extends BaseMapper { +} diff --git a/src/main/java/com/guaiguailang/harmony/service/ActivateService.java b/src/main/java/com/guaiguailang/harmony/service/ActivateService.java index 7aa2c10..5436e9a 100644 --- a/src/main/java/com/guaiguailang/harmony/service/ActivateService.java +++ b/src/main/java/com/guaiguailang/harmony/service/ActivateService.java @@ -1,7 +1,15 @@ package com.guaiguailang.harmony.service; +import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo; +import com.guaiguailang.harmony.domain.vo.ResponseResult; import org.springframework.web.multipart.MultipartFile; +import java.sql.ResultSet; + public interface ActivateService { String uploadActivateProfile(MultipartFile file); + + ResponseResult addActivate(ActiveBaseInfo activeBaseInfo); + + ResponseResult loadActivate(); } 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 d3d2a46..8043b12 100644 --- a/src/main/java/com/guaiguailang/harmony/service/impl/ActivateServiceImpl.java +++ b/src/main/java/com/guaiguailang/harmony/service/impl/ActivateServiceImpl.java @@ -1,18 +1,73 @@ package com.guaiguailang.harmony.service.impl; +import cn.dev33.satoken.stp.StpUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.github.yitter.idgen.YitIdHelper; +import com.guaiguailang.harmony.domain.entity.ActiveBaseInfo; +import com.guaiguailang.harmony.domain.entity.UserInfo; +import com.guaiguailang.harmony.domain.vo.ResponseResult; +import com.guaiguailang.harmony.mapper.ActivateMapper; +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.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 public class ActivateServiceImpl implements ActivateService { @Autowired private FileUpload fileUpload; + @Autowired + private UserMapper userMapper; + @Autowired + private ActivateMapper activateMapper; @Override public String uploadActivateProfile(MultipartFile file) { return fileUpload.uploadFile(file,file.getName(),"activate","活动头图"); } + + @Override + public ResponseResult addActivate(ActiveBaseInfo activeBaseInfo) { + // 检查关键信息 + if(StringUtils.isAnyBlank(activeBaseInfo.getTitle())){ + return ResponseResult.error("请输入活动名称"); + } + // 补充数据 + ////获取创建人的机构信息 + Long uid = Long.parseLong(StpUtil.getLoginId().toString()); + //// 获取用户信息 + UserInfo userInfo = userMapper.getUserById(uid); + // 设置机构 + activeBaseInfo.setAgentId(userInfo.getMerchantCode()); + // 设置创建人、创建人的id、创建时间 + activeBaseInfo.setCreatorName(userInfo.getName()); + activeBaseInfo.setCreatorId(uid); + activeBaseInfo.setCreateTime(new Timestamp(System.currentTimeMillis())); + // 设置数据id + activeBaseInfo.setId(YitIdHelper.nextId()); + // 保存数据 + int result = activateMapper.insert(activeBaseInfo); + if(result > 0) { + return ResponseResult.success(activeBaseInfo); + }else{ + return ResponseResult.error("新增失败"); + } + } + + @Override + public ResponseResult loadActivate() { + // 使用 MyBatis Plus 的 Wrapper 来构建查询条件 + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.orderByDesc("start_time"); + List activeList = activateMapper.selectList(queryWrapper); + return ResponseResult.success(activeList); + } } diff --git a/src/main/resources/mapper/ActivateMapper.xml b/src/main/resources/mapper/ActivateMapper.xml new file mode 100644 index 0000000..c63e369 --- /dev/null +++ b/src/main/resources/mapper/ActivateMapper.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file