发布活动时推荐指定好友

master
pan 5 years ago
parent 3b788177d8
commit 750c6dbcf7
  1. 11
      src/main/java/com/share/help/controller/ActivityController.java
  2. 5
      src/main/java/com/share/help/dao/ActivityMapper.java
  3. 10
      src/main/java/com/share/help/form/RecommendType.java
  4. 20
      src/main/java/com/share/help/form/SendHelpForm.java
  5. 11
      src/main/java/com/share/help/res/SendHelpRes.java
  6. 45
      src/main/java/com/share/help/service/ActivityService.java
  7. 2
      src/test/java/com/share/help/HelpApplicationTests.java

@ -7,7 +7,10 @@ import com.share.help.entity.custorm.HelpRes;
import com.share.help.entity.custorm.SeekHelpSum; import com.share.help.entity.custorm.SeekHelpSum;
import com.share.help.entity.custorm.UserWithName; import com.share.help.entity.custorm.UserWithName;
import com.share.help.form.*; import com.share.help.form.*;
import com.share.help.res.*; import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
import com.share.help.res.Page;
import com.share.help.res.Result;
import com.share.help.service.ActivityService; import com.share.help.service.ActivityService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -32,14 +35,14 @@ public class ActivityController {
* @return 返回发布结果 * @return 返回发布结果
*/ */
@PutMapping(Constants.ACTIVITY_INTERFACE_SEND_HELP) @PutMapping(Constants.ACTIVITY_INTERFACE_SEND_HELP)
public JSONResponse<SendHelpRes,Void> send(SendHelpForm sendHelpForm,@CookieValue(Constants.USER_COOKIE) String userId){ public JSONResponse<DefaultRes,Void> send(SendHelpForm sendHelpForm,@RequestParam(value = "friendUserId[]",required = false) String []friendUserId,@CookieValue(Constants.USER_COOKIE) String userId){
if(StringUtils.isNoneEmpty(userId,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); sendHelpForm.setUserId(userId);
return activityService.sendHelp(sendHelpForm); return activityService.sendHelp(sendHelpForm,friendUserId);
}else{ }else{
return new JSONResponse<>(SendHelpRes.fail,Result.FAIL); return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
} }
} }

@ -18,8 +18,9 @@ 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,user_id)" + @Insert("insert into activity(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})") "value(#{title},#{content},#{seekHelpTime},#{activityStartTime},#{activityEndTime},#{activityImg},#{serviceAddress},#{userId})")
@Options(useGeneratedKeys=true,keyColumn="activity_id",keyProperty = "activityId")
boolean insert(ActivityEntity activityEntity); boolean insert(ActivityEntity activityEntity);
/** /**

@ -0,0 +1,10 @@
package com.share.help.form;
/**
* 推荐类型
*/
public enum RecommendType {
no,
choose,
auto
}

@ -10,6 +10,22 @@ public class SendHelpForm extends ActivityEntity {
// 求助用户 // 求助用户
private String userId; private String userId;
//推荐类型
private RecommendType recommendType;
/**
* 活动背景图
*/
private MultipartFile activityImgFile;
public RecommendType getRecommendType() {
return recommendType;
}
public void setRecommendType(RecommendType recommendType) {
this.recommendType = recommendType;
}
public String getUserId() { public String getUserId() {
return userId; return userId;
} }
@ -18,10 +34,6 @@ public class SendHelpForm extends ActivityEntity {
this.userId = userId; this.userId = userId;
} }
/**
* 活动背景图
*/
private MultipartFile activityImgFile;
public MultipartFile getActivityImgFile() { public MultipartFile getActivityImgFile() {
return activityImgFile; return activityImgFile;

@ -1,11 +0,0 @@
package com.share.help.res;
/**
* 发布求助信息响应
*/
public enum SendHelpRes {
//发布成功
ok,
//发布失败请联系管理员
fail
}

@ -11,7 +11,11 @@ import com.share.help.entity.LeaveWordEntity;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.*; import com.share.help.entity.custorm.*;
import com.share.help.form.*; import com.share.help.form.*;
import com.share.help.res.*; import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
import com.share.help.res.Page;
import com.share.help.res.Result;
import org.apache.commons.lang3.ArrayUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -58,9 +62,10 @@ public class ActivityService{
/** /**
* 发布求助信息 * 发布求助信息
* @param sendHelpForm 求助信息表单 * @param sendHelpForm 求助信息表单
* @param friendUserId 手动推荐好友
* @return 发布结果 * @return 发布结果
*/ */
public JSONResponse<SendHelpRes,Void> sendHelp(SendHelpForm sendHelpForm){ public JSONResponse<DefaultRes,Void> sendHelp(SendHelpForm sendHelpForm, String[] friendUserId){
ActivityEntity activityEntity=new ActivityEntity(); ActivityEntity activityEntity=new ActivityEntity();
activityEntity.setUserId(sendHelpForm.getUserId()); activityEntity.setUserId(sendHelpForm.getUserId());
activityEntity.setTitle(sendHelpForm.getTitle()); activityEntity.setTitle(sendHelpForm.getTitle());
@ -72,12 +77,44 @@ public class ActivityService{
String imageName=imageService.saveImg(sendHelpForm.getActivityImgFile()); String imageName=imageService.saveImg(sendHelpForm.getActivityImgFile());
if(imageName==null){ if(imageName==null){
logger.error("活动背景图保存失败"); logger.error("活动背景图保存失败");
return new JSONResponse<>(SendHelpRes.fail, Result.FAIL); return new JSONResponse<>(DefaultRes.fail, Result.FAIL);
} }
activityEntity.setActivityImg(imageName); activityEntity.setActivityImg(imageName);
activityEntity.setServiceAddress(sendHelpForm.getServiceAddress()); activityEntity.setServiceAddress(sendHelpForm.getServiceAddress());
return activityMapper.insert(activityEntity)?new JSONResponse<>(SendHelpRes.ok,Result.OK):new JSONResponse<>(SendHelpRes.fail,Result.FAIL);
if(activityMapper.insert(activityEntity)) {
switch (sendHelpForm.getRecommendType()) {
case auto:
autoRecommend(sendHelpForm);
break;
case choose:
if (ArrayUtils.isNotEmpty(friendUserId)) {
for (String userId : friendUserId) {
LeaveWordEntity leaveWordEntity = new LeaveWordEntity();
leaveWordEntity.setType(LeaveWordType.recommend.name());
leaveWordEntity.setSourceUserId(sendHelpForm.getUserId());
leaveWordEntity.setTargetUserId(userId);
leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
leaveWordEntity.setActivityId(activityEntity.getActivityId());
leaveWordMapper.insert(leaveWordEntity);
}
} }
break;
}
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 系统推荐
* @param sendHelpForm 推荐表单
*/
private void autoRecommend(SendHelpForm sendHelpForm) {
}
/** /**
* 分页查询活动信息 * 分页查询活动信息

@ -167,7 +167,7 @@ class HelpApplicationTests {
@Test @Test
public void testAddActivity(){ public void testAddActivity(){
ActivityEntity activityEntity=activityMapper.findOne(46L); ActivityEntity activityEntity=activityMapper.findOne(63L);
activityEntity.setActivityId(null); activityEntity.setActivityId(null);
activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis())); activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis()));

Loading…
Cancel
Save