From 750c6dbcf7d23310c01c456fa3f88e72962d79d0 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 30 May 2020 05:57:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E5=B8=83=E6=B4=BB=E5=8A=A8=E6=97=B6?= =?UTF-8?q?=E6=8E=A8=E8=8D=90=E6=8C=87=E5=AE=9A=E5=A5=BD=E5=8F=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../help/controller/ActivityController.java | 11 +++-- .../share/help/controller/UserController.java | 2 +- .../com/share/help/dao/ActivityMapper.java | 5 ++- .../com/share/help/form/RecommendType.java | 10 +++++ .../com/share/help/form/SendHelpForm.java | 20 +++++++-- .../java/com/share/help/res/SendHelpRes.java | 11 ----- .../share/help/service/ActivityService.java | 45 +++++++++++++++++-- .../com/share/help/HelpApplicationTests.java | 2 +- 8 files changed, 79 insertions(+), 27 deletions(-) create mode 100644 src/main/java/com/share/help/form/RecommendType.java delete mode 100644 src/main/java/com/share/help/res/SendHelpRes.java diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index 2a4cef1..141369a 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.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 send(SendHelpForm sendHelpForm,@CookieValue(Constants.USER_COOKIE) String userId){ + public JSONResponse 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); } } diff --git a/src/main/java/com/share/help/controller/UserController.java b/src/main/java/com/share/help/controller/UserController.java index 39bcc0f..95241ce 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -210,7 +210,7 @@ public class UserController { * @return 返回检索结果 */ @GetMapping(Constants.USER_INTERFACE_FRIEND_LIST) - public JSONResponse>> searchFriend(SearchFrom searchFrom, @CookieValue(Constants.USER_COOKIE) String userId){ + public JSONResponse>> searchFriend(SearchFrom searchFrom,@CookieValue(Constants.USER_COOKIE) String userId){ if(ObjectUtils.isNotEmpty(searchFrom.getCurrentPage())&&StringUtils.isNotEmpty(userId)){ searchFrom.setUserId(userId); return userService.searchFriend(searchFrom); diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index 3c5b4a2..0306c1c 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -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); /** diff --git a/src/main/java/com/share/help/form/RecommendType.java b/src/main/java/com/share/help/form/RecommendType.java new file mode 100644 index 0000000..34aeffd --- /dev/null +++ b/src/main/java/com/share/help/form/RecommendType.java @@ -0,0 +1,10 @@ +package com.share.help.form; + +/** + * 推荐类型 + */ +public enum RecommendType { + no, + choose, + auto +} diff --git a/src/main/java/com/share/help/form/SendHelpForm.java b/src/main/java/com/share/help/form/SendHelpForm.java index 16c0be8..2cf8ef9 100644 --- a/src/main/java/com/share/help/form/SendHelpForm.java +++ b/src/main/java/com/share/help/form/SendHelpForm.java @@ -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; diff --git a/src/main/java/com/share/help/res/SendHelpRes.java b/src/main/java/com/share/help/res/SendHelpRes.java deleted file mode 100644 index 63d1aad..0000000 --- a/src/main/java/com/share/help/res/SendHelpRes.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.share.help.res; - -/** - * 发布求助信息响应 - */ -public enum SendHelpRes { - //发布成功 - ok, - //发布失败请联系管理员 - fail -} diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index dffda7b..c92d4c8 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -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 sendHelp(SendHelpForm sendHelpForm){ + public JSONResponse 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 查询活动信息 diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 84cd967..148b099 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -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()));