feat: 活动 新增

This commit is contained in:
萌狼蓝天 2024-11-13 10:02:57 +08:00
parent ef1164f04c
commit 2dbafa77ea
7 changed files with 144 additions and 4 deletions

View File

@ -1,4 +1,39 @@
package com.guaiguailang.harmony.controller; 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 { 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));
}
} }

View File

@ -50,15 +50,15 @@ public class UploadController {
* @param file * @param file
* @return * @return
*/ */
@Operation(summary = "活动 头图") @Operation(summary = "文件上传")
@PostMapping("/activate/profile") @PostMapping("/fileOne")
public ResponseResult uploadActivateProfile(@RequestParam("file") MultipartFile file){ public ResponseResult uploadActivateProfile(@RequestParam("file") MultipartFile file){
if(file.isEmpty()){ if(file.isEmpty()){
return ResponseResult.error("图片为空,请重新选择"); return ResponseResult.error("文件为空,请重新上传");
} }
String imgUrl = activateService.uploadActivateProfile(file); String imgUrl = activateService.uploadActivateProfile(file);
if(imgUrl==null){ if(imgUrl==null){
return ResponseResult.error("图片上传失败"); return ResponseResult.error("文件上传失败");
} }
return ResponseResult.success(imgUrl); return ResponseResult.success(imgUrl);
} }

View File

@ -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;
}

View File

@ -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<ActiveBaseInfo> {
}

View File

@ -1,7 +1,15 @@
package com.guaiguailang.harmony.service; 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 org.springframework.web.multipart.MultipartFile;
import java.sql.ResultSet;
public interface ActivateService { public interface ActivateService {
String uploadActivateProfile(MultipartFile file); String uploadActivateProfile(MultipartFile file);
ResponseResult addActivate(ActiveBaseInfo activeBaseInfo);
ResponseResult loadActivate();
} }

View File

@ -1,18 +1,73 @@
package com.guaiguailang.harmony.service.impl; 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.service.ActivateService;
import com.guaiguailang.harmony.utils.FileUpload; import com.guaiguailang.harmony.utils.FileUpload;
import com.guaiguailang.harmony.utils.UtilMD5; import com.guaiguailang.harmony.utils.UtilMD5;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
@Service @Service
public class ActivateServiceImpl implements ActivateService { public class ActivateServiceImpl implements ActivateService {
@Autowired @Autowired
private FileUpload fileUpload; private FileUpload fileUpload;
@Autowired
private UserMapper userMapper;
@Autowired
private ActivateMapper activateMapper;
@Override @Override
public String uploadActivateProfile(MultipartFile file) { public String uploadActivateProfile(MultipartFile file) {
return fileUpload.uploadFile(file,file.getName(),"activate","活动头图"); 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<ActiveBaseInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.orderByDesc("start_time");
List<ActiveBaseInfo> activeList = activateMapper.selectList(queryWrapper);
return ResponseResult.success(activeList);
}
} }

View File

@ -0,0 +1,7 @@
<?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.ActivateMapper">
</mapper>