From 347c9e6bf3f379bfdc161bbc39d9c4904050b9c0 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Thu, 28 May 2020 08:13:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3=201.?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=BF=A1=E6=81=AF-=E6=88=91=E7=9A=84?= =?UTF-8?q?=E6=B1=82=E5=8A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/share/help/Constants.java | 4 + .../help/controller/ActivityController.java | 29 +++++- .../share/help/controller/UserController.java | 6 +- .../share/help/dao/ActivityHistoryMapper.java | 5 ++ .../com/share/help/dao/ActivityMapper.java | 8 +- .../java/com/share/help/dao/UserMapper.java | 2 +- .../custorm}/ActivitySimple.java | 2 +- .../custorm}/FindActivityRes.java | 2 +- .../custorm}/FindUserRes.java | 2 +- .../help/entity/custorm/SeekHelpSum.java | 89 +++++++++++++++++++ .../help/entity/custorm/UserWithName.java | 23 +++++ .../share/help/form/ApplyActivityForm.java | 1 - .../com/share/help/form/FindUserHelp.java | 26 ++++++ .../share/help/service/ActivityService.java | 29 ++++-- .../com/share/help/service/UserService.java | 6 +- .../mapping/ActivityHistoryMapper.xml | 11 +++ src/main/resources/mapping/ActivityMapper.xml | 33 ++++++- .../com/share/help/HelpApplicationTests.java | 28 +++++- 18 files changed, 285 insertions(+), 21 deletions(-) rename src/main/java/com/share/help/{res/activity => entity/custorm}/ActivitySimple.java (96%) rename src/main/java/com/share/help/{res/activity => entity/custorm}/FindActivityRes.java (88%) rename src/main/java/com/share/help/{res/account => entity/custorm}/FindUserRes.java (87%) create mode 100644 src/main/java/com/share/help/entity/custorm/SeekHelpSum.java create mode 100644 src/main/java/com/share/help/entity/custorm/UserWithName.java create mode 100644 src/main/java/com/share/help/form/FindUserHelp.java create mode 100644 src/main/resources/mapping/ActivityHistoryMapper.xml diff --git a/src/main/java/com/share/help/Constants.java b/src/main/java/com/share/help/Constants.java index ac7625f..40ee1e7 100644 --- a/src/main/java/com/share/help/Constants.java +++ b/src/main/java/com/share/help/Constants.java @@ -41,4 +41,8 @@ public class Constants { public static final String USER_INTERFACE_UPDATE = "/update"; //更新密码接口 public static final String USER_INTERFACE_PWD = "/updatePwd"; + //求助信息统计 + public static final String ACTIVITY_INTERFACE_SEEK_HELP = "/seekHelp"; + //获取求助信息志愿者 + public static final String ACTIVITY_INTERFACE_SEEK_HELP_USER = "/seekHelpUser"; } diff --git a/src/main/java/com/share/help/controller/ActivityController.java b/src/main/java/com/share/help/controller/ActivityController.java index db4151a..0d8d59e 100644 --- a/src/main/java/com/share/help/controller/ActivityController.java +++ b/src/main/java/com/share/help/controller/ActivityController.java @@ -2,20 +2,25 @@ package com.share.help.controller; import com.share.help.Constants; import com.share.help.entity.ActivityEntity; +import com.share.help.entity.custorm.FindActivityRes; +import com.share.help.entity.custorm.SeekHelpSum; +import com.share.help.entity.custorm.UserWithName; import com.share.help.form.ApplyActivityForm; import com.share.help.form.FindActivityForm; +import com.share.help.form.FindUserHelp; import com.share.help.form.SendHelpForm; import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; import com.share.help.res.SendHelpRes; -import com.share.help.res.activity.FindActivityRes; import com.share.help.service.ActivityService; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; + @RestController @RequestMapping(Constants.ACTIVITY_INTERFACE) public class ActivityController { @@ -82,4 +87,26 @@ public class ActivityController { return new JSONResponse<>(DefaultRes.fail,Result.FAIL); } } + + /** + * 统计求助信息数据 + * @return 返回统计结果 + */ + @GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP) + public JSONResponse> seekHelp(@CookieValue(Constants.USER_COOKIE) String userId){ + if(userId==null){ + return new JSONResponse<>(DefaultRes.fail,Result.FAIL); + }else{ + return activityService.seekHelpCount(userId); + } + } + + @GetMapping(Constants.ACTIVITY_INTERFACE_SEEK_HELP_USER) + public JSONResponse> seekHelpUser(FindUserHelp findUserHelp){ + if(ObjectUtils.allNotNull(findUserHelp.getActivityId(),findUserHelp.getActivityStatus())){ + return activityService.seekHelpList(findUserHelp); + }else{ + 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 5545677..2f50de1 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -1,11 +1,15 @@ package com.share.help.controller; import com.share.help.Constants; +import com.share.help.entity.custorm.FindUserRes; import com.share.help.form.*; import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; -import com.share.help.res.account.*; +import com.share.help.res.account.LoginRes; +import com.share.help.res.account.ModifyPwdRes; +import com.share.help.res.account.QueryRes; +import com.share.help.res.account.RegisterRes; import com.share.help.service.UserService; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; diff --git a/src/main/java/com/share/help/dao/ActivityHistoryMapper.java b/src/main/java/com/share/help/dao/ActivityHistoryMapper.java index 67f2ae6..e0e7df8 100644 --- a/src/main/java/com/share/help/dao/ActivityHistoryMapper.java +++ b/src/main/java/com/share/help/dao/ActivityHistoryMapper.java @@ -1,7 +1,11 @@ package com.share.help.dao; import com.share.help.entity.ActivityHistoryEntity; +import com.share.help.entity.custorm.UserWithName; import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Param; + +import java.util.List; /** * 活动历史记录 @@ -18,4 +22,5 @@ public interface ActivityHistoryMapper { boolean insert(ActivityHistoryEntity activityHistoryEntity); + List queryUser(@Param("activityStatus") String activityStatus, @Param("activityId") Long activityId); } diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index 3d928be..3c5b4a2 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -1,8 +1,9 @@ package com.share.help.dao; import com.share.help.entity.ActivityEntity; -import com.share.help.res.activity.ActivitySimple; -import com.share.help.res.activity.FindActivityRes; +import com.share.help.entity.custorm.ActivitySimple; +import com.share.help.entity.custorm.FindActivityRes; +import com.share.help.entity.custorm.SeekHelpSum; import org.apache.ibatis.annotations.*; import java.util.List; @@ -52,4 +53,7 @@ public interface ActivityMapper { * @return 返回分页信息 */ FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId); + + //求助信息 + List seekHelp(@Param("userId") String userId); } diff --git a/src/main/java/com/share/help/dao/UserMapper.java b/src/main/java/com/share/help/dao/UserMapper.java index be9463e..ba9d331 100644 --- a/src/main/java/com/share/help/dao/UserMapper.java +++ b/src/main/java/com/share/help/dao/UserMapper.java @@ -1,7 +1,7 @@ package com.share.help.dao; import com.share.help.entity.UserEntity; -import com.share.help.res.account.FindUserRes; +import com.share.help.entity.custorm.FindUserRes; import org.apache.ibatis.annotations.*; import java.util.List; diff --git a/src/main/java/com/share/help/res/activity/ActivitySimple.java b/src/main/java/com/share/help/entity/custorm/ActivitySimple.java similarity index 96% rename from src/main/java/com/share/help/res/activity/ActivitySimple.java rename to src/main/java/com/share/help/entity/custorm/ActivitySimple.java index f7064f0..642ca09 100644 --- a/src/main/java/com/share/help/res/activity/ActivitySimple.java +++ b/src/main/java/com/share/help/entity/custorm/ActivitySimple.java @@ -1,4 +1,4 @@ -package com.share.help.res.activity; +package com.share.help.entity.custorm; /** * 活动列表实体 diff --git a/src/main/java/com/share/help/res/activity/FindActivityRes.java b/src/main/java/com/share/help/entity/custorm/FindActivityRes.java similarity index 88% rename from src/main/java/com/share/help/res/activity/FindActivityRes.java rename to src/main/java/com/share/help/entity/custorm/FindActivityRes.java index 147d2fd..2c0ca7b 100644 --- a/src/main/java/com/share/help/res/activity/FindActivityRes.java +++ b/src/main/java/com/share/help/entity/custorm/FindActivityRes.java @@ -1,4 +1,4 @@ -package com.share.help.res.activity; +package com.share.help.entity.custorm; import com.share.help.res.Page; diff --git a/src/main/java/com/share/help/res/account/FindUserRes.java b/src/main/java/com/share/help/entity/custorm/FindUserRes.java similarity index 87% rename from src/main/java/com/share/help/res/account/FindUserRes.java rename to src/main/java/com/share/help/entity/custorm/FindUserRes.java index 1560f80..7f39de9 100644 --- a/src/main/java/com/share/help/res/account/FindUserRes.java +++ b/src/main/java/com/share/help/entity/custorm/FindUserRes.java @@ -1,4 +1,4 @@ -package com.share.help.res.account; +package com.share.help.entity.custorm; import com.share.help.entity.UserEntity; import com.share.help.res.Page; diff --git a/src/main/java/com/share/help/entity/custorm/SeekHelpSum.java b/src/main/java/com/share/help/entity/custorm/SeekHelpSum.java new file mode 100644 index 0000000..d6188c1 --- /dev/null +++ b/src/main/java/com/share/help/entity/custorm/SeekHelpSum.java @@ -0,0 +1,89 @@ +package com.share.help.entity.custorm; + +import java.sql.Timestamp; + +/** + * 统计用户求助信息 + */ +public class SeekHelpSum { + //活动id + private Long activityId; + //活动背景图 + private String activityImg; + //求助时间 + private Timestamp seekHelpTime; + //活动标题 + private String title; + //活动内容 + private String content; + //报名人数 + private Integer apply; + //参与人数 + private Integer join; + //完成人数 + private Integer complete; + + public Long getActivityId() { + return activityId; + } + + public void setActivityId(Long activityId) { + this.activityId = activityId; + } + + public String getActivityImg() { + return activityImg; + } + + public void setActivityImg(String activityImg) { + this.activityImg = activityImg; + } + + public Timestamp getSeekHelpTime() { + return seekHelpTime; + } + + public void setSeekHelpTime(Timestamp seekHelpTime) { + this.seekHelpTime = seekHelpTime; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public Integer getApply() { + return apply; + } + + public void setApply(Integer apply) { + this.apply = apply; + } + + public Integer getJoin() { + return join; + } + + public void setJoin(Integer join) { + this.join = join; + } + + public Integer getComplete() { + return complete; + } + + public void setComplete(Integer complete) { + this.complete = complete; + } +} diff --git a/src/main/java/com/share/help/entity/custorm/UserWithName.java b/src/main/java/com/share/help/entity/custorm/UserWithName.java new file mode 100644 index 0000000..da3b830 --- /dev/null +++ b/src/main/java/com/share/help/entity/custorm/UserWithName.java @@ -0,0 +1,23 @@ +package com.share.help.entity.custorm; + +public class UserWithName { + private String userId; + + private String name; + + public String getUserId() { + return userId; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/com/share/help/form/ApplyActivityForm.java b/src/main/java/com/share/help/form/ApplyActivityForm.java index b9e433b..effb4f2 100644 --- a/src/main/java/com/share/help/form/ApplyActivityForm.java +++ b/src/main/java/com/share/help/form/ApplyActivityForm.java @@ -5,6 +5,5 @@ package com.share.help.form; */ public class ApplyActivityForm extends UpdateActivityForm{ - } diff --git a/src/main/java/com/share/help/form/FindUserHelp.java b/src/main/java/com/share/help/form/FindUserHelp.java new file mode 100644 index 0000000..46c6d6c --- /dev/null +++ b/src/main/java/com/share/help/form/FindUserHelp.java @@ -0,0 +1,26 @@ +package com.share.help.form; + +/** + * 获取志愿者列表信息 + */ +public class FindUserHelp { + private Long activityId; + + private ActivityStatus activityStatus; + + public ActivityStatus getActivityStatus() { + return activityStatus; + } + + public void setActivityStatus(ActivityStatus activityStatus) { + this.activityStatus = activityStatus; + } + + public Long getActivityId() { + return activityId; + } + + public void setActivityId(Long activityId) { + this.activityId = activityId; + } +} diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index c2fc3a6..dd9c474 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -7,16 +7,15 @@ import com.share.help.dao.LeaveWordMapper; 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.LeaveWordType; -import com.share.help.form.SendHelpForm; +import com.share.help.entity.custorm.ActivitySimple; +import com.share.help.entity.custorm.FindActivityRes; +import com.share.help.entity.custorm.SeekHelpSum; +import com.share.help.entity.custorm.UserWithName; +import com.share.help.form.*; import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; import com.share.help.res.SendHelpRes; -import com.share.help.res.activity.ActivitySimple; -import com.share.help.res.activity.FindActivityRes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -148,4 +147,22 @@ public class ActivityService{ return new JSONResponse<>(DefaultRes.ok,Result.OK); } + /** + * 求助信息统计 + * @return 返回统计结果 + */ + public JSONResponse> seekHelpCount(String userId){ + List seekHelpSums=activityMapper.seekHelp(userId); + return new JSONResponse>(DefaultRes.ok,Result.OK).setBody(seekHelpSums); + } + + /** + * 求助信息志愿者列表 + * @param findUserHelp 查询条件 + * @return 返回搜索结果 + */ + public JSONResponse> seekHelpList(FindUserHelp findUserHelp){ + List userList=activityHistoryMapper.queryUser(findUserHelp.getActivityStatus().name(),findUserHelp.getActivityId()); + return new JSONResponse>(DefaultRes.ok,Result.OK).setBody(userList); + } } diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index bdba854..22a2a34 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -3,11 +3,15 @@ package com.share.help.service; import com.share.help.Util; import com.share.help.dao.UserMapper; import com.share.help.entity.UserEntity; +import com.share.help.entity.custorm.FindUserRes; import com.share.help.form.*; import com.share.help.res.DefaultRes; import com.share.help.res.JSONResponse; import com.share.help.res.Result; -import com.share.help.res.account.*; +import com.share.help.res.account.LoginRes; +import com.share.help.res.account.ModifyPwdRes; +import com.share.help.res.account.QueryRes; +import com.share.help.res.account.RegisterRes; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/src/main/resources/mapping/ActivityHistoryMapper.xml b/src/main/resources/mapping/ActivityHistoryMapper.xml new file mode 100644 index 0000000..30d4a89 --- /dev/null +++ b/src/main/resources/mapping/ActivityHistoryMapper.xml @@ -0,0 +1,11 @@ + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapping/ActivityMapper.xml b/src/main/resources/mapping/ActivityMapper.xml index dfa42ab..5676c92 100644 --- a/src/main/resources/mapping/ActivityMapper.xml +++ b/src/main/resources/mapping/ActivityMapper.xml @@ -15,7 +15,7 @@ - + @@ -35,8 +35,37 @@ limit #{start},#{count} - select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/share/help/HelpApplicationTests.java b/src/test/java/com/share/help/HelpApplicationTests.java index 27c9b63..7d633bd 100644 --- a/src/test/java/com/share/help/HelpApplicationTests.java +++ b/src/test/java/com/share/help/HelpApplicationTests.java @@ -1,11 +1,15 @@ package com.share.help; +import com.share.help.dao.ActivityHistoryMapper; import com.share.help.dao.ActivityMapper; import com.share.help.dao.UserMapper; import com.share.help.entity.ActivityEntity; import com.share.help.entity.UserEntity; -import com.share.help.res.account.FindUserRes; -import com.share.help.res.activity.ActivitySimple; +import com.share.help.entity.custorm.ActivitySimple; +import com.share.help.entity.custorm.FindUserRes; +import com.share.help.entity.custorm.SeekHelpSum; +import com.share.help.entity.custorm.UserWithName; +import com.share.help.form.ActivityStatus; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,6 +48,9 @@ class HelpApplicationTests { @Autowired private ActivityMapper activityMapper; + @Autowired + private ActivityHistoryMapper activityHistoryMapper; + private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); @BeforeEach @@ -153,11 +160,26 @@ class HelpApplicationTests { @Test public void testAddActivity(){ - ActivityEntity activityEntity=activityMapper.findOne(25L); + ActivityEntity activityEntity=activityMapper.findOne(46L); activityEntity.setActivityId(null); activityEntity.setSeekHelpTime(new Timestamp(System.currentTimeMillis())); activityMapper.insert(activityEntity); } + +// 求助信息统计 + @Test + public void testSeekHelpCount(){ + List seekHelpSums=activityMapper.seekHelp("777"); + Assertions.assertFalse(seekHelpSums.isEmpty()); + } + + + //求助信息用户 + @Test + public void testSeekHelpUser(){ + List userWithNames=activityHistoryMapper.queryUser(ActivityStatus.join.name(),47L); + Assertions.assertFalse(userWithNames.isEmpty()); + } }