发布活动时推荐指定好友

master
pan 5 years ago
parent 3b788177d8
commit 750c6dbcf7
  1. 11
      src/main/java/com/share/help/controller/ActivityController.java
  2. 2
      src/main/java/com/share/help/controller/UserController.java
  3. 5
      src/main/java/com/share/help/dao/ActivityMapper.java
  4. 10
      src/main/java/com/share/help/form/RecommendType.java
  5. 20
      src/main/java/com/share/help/form/SendHelpForm.java
  6. 11
      src/main/java/com/share/help/res/SendHelpRes.java
  7. 45
      src/main/java/com/share/help/service/ActivityService.java
  8. 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.UserWithName;
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 org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
@ -32,14 +35,14 @@ public class ActivityController {
* @return 返回发布结果
*/
@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())&&
ObjectUtils.allNotNull(sendHelpForm.getActivityStartTime(),sendHelpForm.getActivityEndTime()
,sendHelpForm.getActivityImgFile())){
sendHelpForm.setUserId(userId);
return activityService.sendHelp(sendHelpForm);
return activityService.sendHelp(sendHelpForm,friendUserId);
}else{
return new JSONResponse<>(SendHelpRes.fail,Result.FAIL);
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}

@ -210,7 +210,7 @@ public class UserController {
* @return 返回检索结果
*/
@GetMapping(Constants.USER_INTERFACE_FRIEND_LIST)
public JSONResponse<DefaultRes,Page<List<Friend>>> searchFriend(SearchFrom searchFrom, @CookieValue(Constants.USER_COOKIE) String userId){
public JSONResponse<DefaultRes,Page<List<Friend>>> searchFriend(SearchFrom searchFrom,@CookieValue(Constants.USER_COOKIE) String userId){
if(ObjectUtils.isNotEmpty(searchFrom.getCurrentPage())&&StringUtils.isNotEmpty(userId)){
searchFrom.setUserId(userId);
return userService.searchFriend(searchFrom);

@ -18,8 +18,9 @@ public interface ActivityMapper {
* @param activityEntity 活动实体
* @return 返回保存结果
*/
@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})")
@Insert("insert into activity(title,content,seek_help_time,activity_start_time,activity_end_time,activity_img,service_address,user_id)" +
"value(#{title},#{content},#{seekHelpTime},#{activityStartTime},#{activityEndTime},#{activityImg},#{serviceAddress},#{userId})")
@Options(useGeneratedKeys=true,keyColumn="activity_id",keyProperty = "activityId")
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 RecommendType recommendType;
/**
* 活动背景图
*/
private MultipartFile activityImgFile;
public RecommendType getRecommendType() {
return recommendType;
}
public void setRecommendType(RecommendType recommendType) {
this.recommendType = recommendType;
}
public String getUserId() {
return userId;
}
@ -18,10 +34,6 @@ public class SendHelpForm extends ActivityEntity {
this.userId = userId;
}
/**
* 活动背景图
*/
private MultipartFile activityImgFile;
public MultipartFile getActivityImgFile() {
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.custorm.*;
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.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -58,9 +62,10 @@ public class ActivityService{
/**
* 发布求助信息
* @param sendHelpForm 求助信息表单
* @param friendUserId 手动推荐好友
* @return 发布结果
*/
public JSONResponse<SendHelpRes,Void> sendHelp(SendHelpForm sendHelpForm){
public JSONResponse<DefaultRes,Void> sendHelp(SendHelpForm sendHelpForm, String[] friendUserId){
ActivityEntity activityEntity=new ActivityEntity();
activityEntity.setUserId(sendHelpForm.getUserId());
activityEntity.setTitle(sendHelpForm.getTitle());
@ -72,13 +77,45 @@ public class ActivityService{
String imageName=imageService.saveImg(sendHelpForm.getActivityImgFile());
if(imageName==null){
logger.error("活动背景图保存失败");
return new JSONResponse<>(SendHelpRes.fail, Result.FAIL);
return new JSONResponse<>(DefaultRes.fail, Result.FAIL);
}
activityEntity.setActivityImg(imageName);
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) {
}
/**
* 分页查询活动信息
* @param findActivityForm 查询活动信息

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

Loading…
Cancel
Save