增加活动报名接口

master
pan 5 years ago
parent 75751c846a
commit a099d3bd89
  1. 5
      src/main/java/com/share/help/Constants.java
  2. 2
      src/main/java/com/share/help/HelpApplication.java
  3. 21
      src/main/java/com/share/help/controller/ActivityController.java
  4. 21
      src/main/java/com/share/help/dao/ActivityHistoryMapper.java
  5. 3
      src/main/java/com/share/help/dao/ActivityMapper.java
  6. 14
      src/main/java/com/share/help/dao/LeaveWordMapper.java
  7. 18
      src/main/java/com/share/help/entity/ActivityEntity.java
  8. 13
      src/main/java/com/share/help/form/ActivityStatus.java
  9. 10
      src/main/java/com/share/help/form/ApplyActivityForm.java
  10. 17
      src/main/java/com/share/help/form/LeaveWordType.java
  11. 10
      src/main/java/com/share/help/form/SendHelpForm.java
  12. 37
      src/main/java/com/share/help/form/UpdateActivityForm.java
  13. 9
      src/main/java/com/share/help/res/activity/ActivitySimple.java
  14. 9
      src/main/java/com/share/help/res/activity/ApplyActivityRes.java
  15. 56
      src/main/java/com/share/help/service/ActivityService.java
  16. 5
      src/main/java/com/share/help/service/ImageService.java
  17. 2
      src/main/resources/mapping/ActivityMapper.xml

@ -28,4 +28,9 @@ public class Constants {
//查找活动接口 //查找活动接口
public static final String ACTIVITY_INTERFACE_FIND_ID =ACTIVITY_INTERFACE_FIND+"/{activityId}" ; public static final String ACTIVITY_INTERFACE_FIND_ID =ACTIVITY_INTERFACE_FIND+"/{activityId}" ;
public static final String USER_COOKIE="user_cookie";
//活动报名接口
public static final String ACTIVITY_INTERFACE_APPLY = "/apply";
} }

@ -4,8 +4,10 @@ import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.annotation.MapperScans; import org.mybatis.spring.annotation.MapperScans;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@SpringBootApplication @SpringBootApplication
@EnableTransactionManagement
@MapperScans(@MapperScan("com.share.help.dao")) @MapperScans(@MapperScan("com.share.help.dao"))
public class HelpApplication { public class HelpApplication {

@ -2,12 +2,14 @@ package com.share.help.controller;
import com.share.help.Constants; import com.share.help.Constants;
import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityEntity;
import com.share.help.form.ApplyActivityForm;
import com.share.help.form.FindActivityForm; import com.share.help.form.FindActivityForm;
import com.share.help.form.SendHelpForm; import com.share.help.form.SendHelpForm;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.SendHelpRes; import com.share.help.res.SendHelpRes;
import com.share.help.res.activity.ActivityDetailRes; import com.share.help.res.activity.ActivityDetailRes;
import com.share.help.res.activity.ApplyActivityRes;
import com.share.help.res.activity.FindActivityRes; import com.share.help.res.activity.FindActivityRes;
import com.share.help.service.ActivityService; import com.share.help.service.ActivityService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
@ -28,10 +30,11 @@ public class ActivityController {
* @return 返回发布结果 * @return 返回发布结果
*/ */
@PutMapping(Constants.ACTIVITY_INTERFACE_SEND_HELP) @PutMapping(Constants.ACTIVITY_INTERFACE_SEND_HELP)
public JSONResponse<SendHelpRes,Void> send(SendHelpForm sendHelpForm){ public JSONResponse<SendHelpRes,Void> send(SendHelpForm sendHelpForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(StringUtils.isNoneEmpty(sendHelpForm.getTitle(),sendHelpForm.getContent(),sendHelpForm.getServiceAddress())&& if(StringUtils.isNoneEmpty(userId,sendHelpForm.getTitle(),sendHelpForm.getContent(),sendHelpForm.getServiceAddress())&&
ObjectUtils.allNotNull(sendHelpForm.getActivityStartTime(),sendHelpForm.getActivityEndTime() ObjectUtils.allNotNull(sendHelpForm.getActivityStartTime(),sendHelpForm.getActivityEndTime()
,sendHelpForm.getActivityImgFile())){ ,sendHelpForm.getActivityImgFile())){
sendHelpForm.setUserId(userId);
return activityService.sendHelp(sendHelpForm); return activityService.sendHelp(sendHelpForm);
}else{ }else{
return new JSONResponse<>(SendHelpRes.fail,Result.FAIL); return new JSONResponse<>(SendHelpRes.fail,Result.FAIL);
@ -65,4 +68,18 @@ public class ActivityController {
return activityService.find(activityId); return activityService.find(activityId);
} }
} }
/**
* 报名活动
* @return 返回报名结果
*/
@PostMapping(Constants.ACTIVITY_INTERFACE_APPLY)
public JSONResponse<ApplyActivityRes,Void> apply(ApplyActivityForm activityForm,@CookieValue(Constants.USER_COOKIE) String userId){
if(StringUtils.isNotEmpty(userId)&&ObjectUtils.allNotNull(activityForm.getActivityId(),activityForm.getActivityStatus())){
activityForm.setUserId(userId);
return activityService.apply(activityForm);
}else{
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL);
}
}
} }

@ -0,0 +1,21 @@
package com.share.help.dao;
import com.share.help.entity.ActivityHistoryEntity;
import org.apache.ibatis.annotations.Insert;
/**
* 活动历史记录
*/
public interface ActivityHistoryMapper {
/**
* 添加活动历史记录
* @param activityHistoryEntity 活动历史实体
* @return 返回添加结果
*/
@Insert("insert into activity_history(activity_id,user_id,activity_status,create_time,activity_score,time_score)value" +
"(#{activityId},#{userId},#{activityStatus},#{createTime},#{activityScore},#{timeScore})")
boolean insert(ActivityHistoryEntity activityHistoryEntity);
}

@ -17,7 +17,8 @@ public interface ActivityMapper {
* @param activityEntity 活动实体 * @param activityEntity 活动实体
* @return 返回保存结果 * @return 返回保存结果
*/ */
@Insert("insert into activity(activity_id,title,content,seek_help_time,activity_start_time,activity_end_time,activity_img,service_address)value(#{activityId},#{title},#{content},#{seekHelpTime},#{activityStartTime},#{activityEndTime},#{activityImg},#{serviceAddress})") @Insert("insert into activity(activity_id,title,content,seek_help_time,activity_start_time,activity_end_time,activity_img,service_address,user_id)" +
"value(#{activityId},#{title},#{content},#{seekHelpTime},#{activityStartTime},#{activityEndTime},#{activityImg},#{serviceAddress},#{userId})")
boolean insert(ActivityEntity activityEntity); boolean insert(ActivityEntity activityEntity);
/** /**

@ -0,0 +1,14 @@
package com.share.help.dao;
import com.share.help.entity.LeaveWordEntity;
import org.apache.ibatis.annotations.Insert;
/**
* 留言信息数据接口
*/
public interface LeaveWordMapper {
@Insert("insert into leave_word(leave_word_id,type,source_user_id,target_user_id,activity_id,create_time)" +
"value(#{leaveWordId},#{type},#{sourceUserId},#{targetUserId},#{activityId},#{createTime})")
boolean insert(LeaveWordEntity leaveWordEntity);
}

@ -5,7 +5,6 @@ import java.util.Collection;
import java.util.Objects; import java.util.Objects;
public class ActivityEntity { public class ActivityEntity {
private Long activityId; private Long activityId;
private String title; private String title;
@ -15,6 +14,7 @@ public class ActivityEntity {
private Timestamp activityEndTime; private Timestamp activityEndTime;
private String activityImg; private String activityImg;
private String serviceAddress; private String serviceAddress;
private String userId;
private Collection<ActivityHistoryEntity> activityHistoriesByActivityId; private Collection<ActivityHistoryEntity> activityHistoriesByActivityId;
private Collection<LeaveWordEntity> leaveWordsByActivityId; private Collection<LeaveWordEntity> leaveWordsByActivityId;
@ -98,6 +98,14 @@ public class ActivityEntity {
this.serviceAddress = serviceAddress; this.serviceAddress = serviceAddress;
} }
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
@Override @Override
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
@ -110,15 +118,17 @@ public class ActivityEntity {
Objects.equals(activityStartTime, that.activityStartTime) && Objects.equals(activityStartTime, that.activityStartTime) &&
Objects.equals(activityEndTime, that.activityEndTime) && Objects.equals(activityEndTime, that.activityEndTime) &&
Objects.equals(activityImg, that.activityImg) && Objects.equals(activityImg, that.activityImg) &&
Objects.equals(serviceAddress, that.serviceAddress); Objects.equals(serviceAddress, that.serviceAddress) &&
Objects.equals(userId, that.userId) &&
Objects.equals(activityHistoriesByActivityId, that.activityHistoriesByActivityId) &&
Objects.equals(leaveWordsByActivityId, that.leaveWordsByActivityId);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(activityId, title, content, seekHelpTime, activityStartTime, activityEndTime, activityImg, serviceAddress); return Objects.hash(activityId, title, content, seekHelpTime, activityStartTime, activityEndTime, activityImg, serviceAddress, userId, activityHistoriesByActivityId, leaveWordsByActivityId);
} }
public Collection<ActivityHistoryEntity> getActivityHistoriesByActivityId() { public Collection<ActivityHistoryEntity> getActivityHistoriesByActivityId() {
return activityHistoriesByActivityId; return activityHistoriesByActivityId;
} }

@ -0,0 +1,13 @@
package com.share.help.form;
/**
* 活动状态
*/
public enum ActivityStatus {
// 报名
apply,
// 参与
join,
// 完成
complete
}

@ -0,0 +1,10 @@
package com.share.help.form;
/**
* 报名活动表单
*/
public class ApplyActivityForm extends UpdateActivityForm{
}

@ -0,0 +1,17 @@
package com.share.help.form;
/**
* 留言类型
*/
public enum LeaveWordType {
//推荐
recommend,
//报名
apply,
//参与
join,
//完成
complete,
//好友验证
friend
}

@ -7,6 +7,16 @@ import org.springframework.web.multipart.MultipartFile;
* 发布求助信息表单 * 发布求助信息表单
*/ */
public class SendHelpForm extends ActivityEntity { public class SendHelpForm extends ActivityEntity {
// 求助用户
private String userId;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
/** /**
* 活动背景图 * 活动背景图

@ -0,0 +1,37 @@
package com.share.help.form;
/**
* 改变活动状态
*/
public abstract class UpdateActivityForm {
//活动id
private Long activityId;
//用户id
private String userId;
//刷新状态
private ActivityStatus activityStatus;
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public ActivityStatus getActivityStatus() {
return activityStatus;
}
public void setActivityStatus(ActivityStatus activityStatus) {
this.activityStatus = activityStatus;
}
}

@ -5,10 +5,19 @@ package com.share.help.res.activity;
*/ */
public class ActivitySimple { public class ActivitySimple {
private Long activityId; private Long activityId;
private String userId;
private String title; private String title;
private String content; private String content;
private String activityImg; private String activityImg;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Long getActivityId() { public Long getActivityId() {
return activityId; return activityId;
} }

@ -0,0 +1,9 @@
package com.share.help.res.activity;
/**
* 报名活动操作反馈
*/
public enum ApplyActivityRes {
ok,
fail
}

@ -1,19 +1,29 @@
package com.share.help.service; package com.share.help.service;
import com.share.help.Util; import com.share.help.Util;
import com.share.help.dao.ActivityHistoryMapper;
import com.share.help.dao.ActivityMapper; import com.share.help.dao.ActivityMapper;
import com.share.help.dao.LeaveWordMapper;
import com.share.help.entity.ActivityEntity; import com.share.help.entity.ActivityEntity;
import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.LeaveWordEntity;
import com.share.help.form.ApplyActivityForm;
import com.share.help.form.FindActivityForm; import com.share.help.form.FindActivityForm;
import com.share.help.form.LeaveWordType;
import com.share.help.form.SendHelpForm; import com.share.help.form.SendHelpForm;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.SendHelpRes; import com.share.help.res.SendHelpRes;
import com.share.help.res.activity.ActivityDetailRes; import com.share.help.res.activity.ActivityDetailRes;
import com.share.help.res.activity.ActivitySimple; import com.share.help.res.activity.ActivitySimple;
import com.share.help.res.activity.ApplyActivityRes;
import com.share.help.res.activity.FindActivityRes; import com.share.help.res.activity.FindActivityRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List; import java.util.List;
@ -27,6 +37,12 @@ public class ActivityService{
@Autowired @Autowired
private ActivityMapper activityMapper; private ActivityMapper activityMapper;
@Autowired
private ActivityHistoryMapper activityHistoryMapper;
@Autowired
private LeaveWordMapper leaveWordMapper;
@Autowired @Autowired
private ImageService imageService; private ImageService imageService;
@ -38,7 +54,7 @@ public class ActivityService{
private int rowSize; private int rowSize;
private Logger logger = LoggerFactory.getLogger(ActivityService.class);
/** /**
* 发布求助信息 * 发布求助信息
@ -47,6 +63,7 @@ public class ActivityService{
*/ */
public JSONResponse<SendHelpRes,Void> sendHelp(SendHelpForm sendHelpForm){ public JSONResponse<SendHelpRes,Void> sendHelp(SendHelpForm sendHelpForm){
ActivityEntity activityEntity=new ActivityEntity(); ActivityEntity activityEntity=new ActivityEntity();
activityEntity.setUserId(sendHelpForm.getUserId());
activityEntity.setTitle(sendHelpForm.getTitle()); activityEntity.setTitle(sendHelpForm.getTitle());
activityEntity.setContent(sendHelpForm.getContent()); activityEntity.setContent(sendHelpForm.getContent());
activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis())); activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis()));
@ -55,6 +72,7 @@ public class ActivityService{
//保存活动背景图 //保存活动背景图
String imageName=imageService.saveImg(sendHelpForm.getActivityImgFile()); String imageName=imageService.saveImg(sendHelpForm.getActivityImgFile());
if(imageName==null){ if(imageName==null){
logger.error("活动背景图保存失败");
return new JSONResponse<>(SendHelpRes.fail, Result.FAIL); return new JSONResponse<>(SendHelpRes.fail, Result.FAIL);
} }
activityEntity.setActivityImg(imageName); activityEntity.setActivityImg(imageName);
@ -94,4 +112,40 @@ public class ActivityService{
} }
} }
/**
* 报名活动
* @param activityForm 报名名单
* @return 返回报名结果
*/
@Transactional
public JSONResponse<ApplyActivityRes,Void> apply(ApplyActivityForm activityForm){
// 保存到活动历史记录
ActivityHistoryEntity activityEntity=new ActivityHistoryEntity();
activityEntity.setActivityId(activityForm.getActivityId());
activityEntity.setUserId(activityForm.getUserId());
activityEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
activityEntity.setActivityStatus(activityForm.getActivityStatus().name());
if(!activityHistoryMapper.insert(activityEntity)){
logger.error("保存活动历史记录失败");
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL);
}
// 给求助用户发送留言
LeaveWordEntity leaveWordEntity=new LeaveWordEntity();
leaveWordEntity.setType(LeaveWordType.apply.name());
leaveWordEntity.setSourceUserId(activityForm.getUserId());
ActivityEntity activity=activityMapper.findOne(activityForm.getActivityId());
if(activity==null){
logger.error("查询活动记录失败");
return new JSONResponse<>(ApplyActivityRes.fail,Result.FAIL);
}
leaveWordEntity.setTargetUserId(activity.getUserId());
leaveWordEntity.setActivityId(activityForm.getActivityId());
leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
if(leaveWordMapper.insert(leaveWordEntity)){
logger.error("保存留言信息失败");
}
return new JSONResponse<>(ApplyActivityRes.ok,Result.OK);
}
} }

@ -31,6 +31,7 @@ public class ImageService {
String fileName; String fileName;
//判断图片类型 //判断图片类型
if(file.getContentType()==null){ if(file.getContentType()==null){
logger.error("获取不到图片的格式");
return null; return null;
}else if(file.getContentType().contains(ImageType.jpg.name())){ }else if(file.getContentType().contains(ImageType.jpg.name())){
fileName= UUID.randomUUID()+"."+ImageType.jpg.name(); fileName= UUID.randomUUID()+"."+ImageType.jpg.name();
@ -39,16 +40,18 @@ public class ImageService {
}else if (file.getContentType().contains(ImageType.png.name())) { }else if (file.getContentType().contains(ImageType.png.name())) {
fileName= UUID.randomUUID()+"."+ImageType.png.name(); fileName= UUID.randomUUID()+"."+ImageType.png.name();
} else { } else {
logger.error("图片文件格式不正确");
return null; return null;
} }
File loadFile = new File(getClass().getResource("/").getFile() + imgPath.replace("classpath:/", ""), fileName); File loadFile = new File(getClass().getResource("/").getFile() + imgPath.replace("classpath:/", ""), fileName);
try { try {
file.transferTo(loadFile); file.transferTo(loadFile);
logger.debug("图片保存到"+loadFile.getAbsolutePath());
return fileName; return fileName;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
logger.error(String.valueOf(e)); logger.error("保存图片文件异常信息:"+e);
return null; return null;
} }
} }

@ -12,10 +12,12 @@
<result property="activityEndTime" column="activity_end_time"/> <result property="activityEndTime" column="activity_end_time"/>
<result property="activityImg" column="activity_img"/> <result property="activityImg" column="activity_img"/>
<result property="serviceAddress" column="service_address"/> <result property="serviceAddress" column="service_address"/>
<result property="userId" column="user_id"/>
</resultMap> </resultMap>
<resultMap id="activitySimpleMap" type="com.share.help.res.activity.ActivitySimple"> <resultMap id="activitySimpleMap" type="com.share.help.res.activity.ActivitySimple">
<id property="activityId" column="activity_id"/> <id property="activityId" column="activity_id"/>
<result property="userId" column="user_id"/>
<result property="title" column="title"/> <result property="title" column="title"/>
<result property="content" column="content"/> <result property="content" column="content"/>
<result property="activityImg" column="activity_img"/> <result property="activityImg" column="activity_img"/>

Loading…
Cancel
Save