1.完善系统推荐

2.增加修改活动信息接口
master
pan 4 years ago
parent a1145dec7d
commit 1fc0b98ae9
  1. 2
      src/main/java/com/share/help/Constants.java
  2. 41
      src/main/java/com/share/help/config/CrosConfig.java
  3. 33
      src/main/java/com/share/help/config/CrosConfiguration.java
  4. 24
      src/main/java/com/share/help/controller/ManagerController.java
  5. 13
      src/main/java/com/share/help/dao/ActivityMapper.java
  6. 6
      src/main/java/com/share/help/dao/FriendMapper.java
  7. 10
      src/main/java/com/share/help/form/SearchFrom.java
  8. 5
      src/main/java/com/share/help/form/UpdateUserForm.java
  9. 22
      src/main/java/com/share/help/form/manager/ActiveUserRes.java
  10. 36
      src/main/java/com/share/help/form/manager/UpdateActivityForm.java
  11. 28
      src/main/java/com/share/help/service/ActivityService.java
  12. 20
      src/main/java/com/share/help/service/ManagerService.java
  13. 4
      src/main/java/com/share/help/service/UserService.java
  14. 9
      src/main/resources/application.yaml
  15. 37
      src/main/resources/mapping/ActivityMapper.xml
  16. 56
      src/main/resources/mapping/FriendMapper.xml
  17. 26
      src/test/java/com/share/help/HelpApplicationTests.java

@ -88,4 +88,6 @@ public class Constants {
public static final String MANAGER_INTERFACE_FIND_ACTIVITY ="/find/activity" ;
//删除活动接口
public static final String MANAGER_INTERFACE_DELTE_ACTIVITY = "/delete/{activityId}";
//更新活动接口
public static final String MANAGER_INTERFACE_UPDATE_ACTIVITY = "/update/{activityId}";
}

@ -0,0 +1,41 @@
package com.share.help.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
@Component
@PropertySource("classpath:application.yaml")
@ConfigurationProperties(prefix = "cros")
public class CrosConfig {
private String pathPattern;
private String allowedOrigins[];
private String allowedMethods[];
public String[] getAllowedOrigins() {
return allowedOrigins;
}
public void setAllowedOrigins(String[] allowedOrigins) {
this.allowedOrigins = allowedOrigins;
}
public String[] getAllowedMethods() {
return allowedMethods;
}
public void setAllowedMethods(String[] allowedMethods) {
this.allowedMethods = allowedMethods;
}
public String getPathPattern() {
return pathPattern;
}
public void setPathPattern(String pathPattern) {
this.pathPattern = pathPattern;
}
}

@ -1,30 +1,21 @@
package com.share.help.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class CrosConfiguration {
public class CrosConfiguration implements WebMvcConfigurer {
@Value("${cros.allow-origin}")
private String allowOrigin;
@Autowired
private CrosConfig crosConfig;
@Bean
public FilterRegistrationBean<CorsFilter> corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin(allowOrigin);
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/api/**", config);
FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>(new CorsFilter(source));
bean.setOrder(0);
return bean;
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping(crosConfig.getPathPattern()).
allowedOrigins(crosConfig.getAllowedOrigins()).
allowedMethods(crosConfig.getAllowedMethods()).
allowCredentials(true);
}
}

@ -4,6 +4,7 @@ import com.share.help.Constants;
import com.share.help.entity.UserEntity;
import com.share.help.form.*;
import com.share.help.form.manager.FindActivityForm;
import com.share.help.form.manager.UpdateActivityForm;
import com.share.help.res.*;
import com.share.help.res.account.ManagerLoginRes;
import com.share.help.res.account.RegisterRes;
@ -136,12 +137,19 @@ public class ManagerController {
}
}
// @GetMapping(Constants.MANAGER_INTERFACE_DELTE_ACTIVITY)
// public JSONResponse<DefaultRes,Void> deleteActivity(@PathVariable Long activityId){
// if(activityId!=null){
// return managerService.deleteActivity(activityId);
// }else{
// return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
// }
// }
/**
* 更新活动信息
* @param updateActivityForm 活动表单
* @param activityId 活动id
* @return 返回更新结果
*/
@PostMapping(Constants.MANAGER_INTERFACE_UPDATE_ACTIVITY)
public JSONResponse<DefaultRes,Void> updateActivity(UpdateActivityForm updateActivityForm,@PathVariable Long activityId){
if(activityId!=null){
updateActivityForm.setActivityId(activityId);
return managerService.updateActivity(updateActivityForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -5,6 +5,7 @@ import com.share.help.entity.custorm.ActivityDetail;
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.form.manager.ActiveUserRes;
import com.share.help.res.ManagerActivityRes;
import com.share.help.res.Page;
import org.apache.ibatis.annotations.Delete;
@ -48,16 +49,18 @@ public interface ActivityMapper {
* 分页查询活动
* @param start 起始索引
* @param count 查询个数
* @param userId 用户id判断该用户是否报名活动
* @return 返回活动列表
*/
List<ActivitySimple> getPage(@Param("start") Integer start, @Param("count") Integer count,@Param("userId") String userId);
List<ActivitySimple> getPage(@Param("start") Integer start, @Param("count") Integer count,@Param("userId") String userId,@Param("title") String title);
/**
* 获取活动列表分页数
* @param pageSize 分页大小
* @param userId 用户id判断该用户是否报名活动
* @return 返回分页信息
*/
FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId);
FindActivityRes count(@Param("pageSize") Integer pageSize,@Param("userId") String userId,@Param("title") String title);
//求助信息
List<SeekHelpSum> seekHelp(@Param("userId") String userId);
@ -67,4 +70,10 @@ public interface ActivityMapper {
//分页信息
Page<List<ManagerActivityRes>> countActivity(@Param("pageSize") Integer pageSize);
//修改活动信息
boolean updateActivity(@Param("activityId") Long activityId,@Param("title") String title,@Param("content") String content);
//查询活跃用户
List<ActiveUserRes> queryActiveUser(@Param("userId") String userId,@Param("serviceAddress") String serviceAddress);
}

@ -24,14 +24,16 @@ public interface FriendMapper {
/**
* 获取好友邀请
* @param userId 目标用户
* @param serviceAddress 服务地点
* @return 返回好友id
*/
List<Friend> getFriend(@Param("userId") String userId, @Param("name") String name,@Param("start") long start, @Param("count") long count);
List<Friend> getFriend(@Param("userId") String userId, @Param("name") String name, String serviceAddress, @Param("start") long start, @Param("count") long count);
/**
* 统计好友分页数
* @param userId 目标用户
* @param serviceAddress 服务地点
* @return 返回分页数
*/
Page<List<Friend>> count(@Param("userId") String userId, @Param("name") String name,@Param("pageSize") Integer pageSize);
Page<List<Friend>> count(@Param("userId") String userId, @Param("name") String name, String serviceAddress, @Param("pageSize") Integer pageSize);
}

@ -8,6 +8,8 @@ public class SearchFrom {
private String userId;
//用户名
private String name;
//服务地点
private String serviceAddress;
//分页数
private Integer currentPage;
@ -34,4 +36,12 @@ public class SearchFrom {
public void setUserId(String userId) {
this.userId = userId;
}
public String getServiceAddress() {
return serviceAddress;
}
public void setServiceAddress(String serviceAddress) {
this.serviceAddress = serviceAddress;
}
}

@ -3,6 +3,8 @@ package com.share.help.form;
public class UpdateUserForm {
private String userId;
private String name;
private Integer age;
private String sex;
private String headImg;
private String address;
private String serviceAddress;
@ -10,8 +12,7 @@ public class UpdateUserForm {
private Long mobile;
private String email;
private String info;
private Integer age;
private String sex;
public String getUserId() {
return userId;

@ -0,0 +1,22 @@
package com.share.help.form.manager;
public class ActiveUserRes {
private String userId;
private Integer count;
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
}

@ -0,0 +1,36 @@
package com.share.help.form.manager;
/**
* 管理员修改活动信息表单
*/
public class UpdateActivityForm {
private Long activityId;
private String title;
private String content;
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
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;
}
}

@ -11,6 +11,7 @@ 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.form.manager.ActiveUserRes;
import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse;
import com.share.help.res.Page;
@ -85,7 +86,7 @@ public class ActivityService{
if(activityMapper.insert(activityEntity)) {
switch (sendHelpForm.getRecommendType()) {
case auto:
autoRecommend(sendHelpForm);
autoRecommend(activityEntity);
break;
case choose:
if (ArrayUtils.isNotEmpty(friendUserId)) {
@ -107,13 +108,26 @@ public class ActivityService{
}
}
/**
* 系统推荐
* @param sendHelpForm 推荐表单
* @param activityEntity 推荐表单
*/
private void autoRecommend(SendHelpForm sendHelpForm) {
//查找参加过我活动的好友
private void autoRecommend(ActivityEntity activityEntity) {
//查找参加过我活动的活跃好友
List<ActiveUserRes> activeUserRes=activityMapper.queryActiveUser(activityEntity.getUserId(),activityEntity.getServiceAddress());
for(ActiveUserRes res:activeUserRes){
LeaveWordEntity leaveWordEntity = new LeaveWordEntity();
leaveWordEntity.setType(LeaveWordType.recommend.name());
leaveWordEntity.setSourceUserId(activityEntity.getUserId());
leaveWordEntity.setTargetUserId(res.getUserId());
leaveWordEntity.setCreateTime(new Timestamp(System.currentTimeMillis()));
leaveWordEntity.setActivityId(activityEntity.getActivityId());
if(leaveWordMapper.insert(leaveWordEntity)){
logger.info("成功把活动id="+activityEntity.getActivityId()+"推荐给好友id="+res.getUserId());
}
}
}
@ -123,10 +137,10 @@ public class ActivityService{
* @return 返回活动信息
*/
public JSONResponse<FindActivityRes.Res,FindActivityRes> find(FindActivityForm findActivityForm){
FindActivityRes findActivityRes=activityMapper.count(activityPageSize,findActivityForm.getUserId());
FindActivityRes findActivityRes=activityMapper.count(activityPageSize,findActivityForm.getUserId(),findActivityForm.getTitle());
findActivityRes.setPageSize(activityPageSize);
findActivityRes.setCurrentPage(findActivityForm.getCurrentPage());
List<ActivitySimple> activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)* activityPageSize, activityPageSize,findActivityForm.getUserId());
List<ActivitySimple> activitySimpleList=activityMapper.getPage((findActivityForm.getCurrentPage()-1)* activityPageSize, activityPageSize,findActivityForm.getUserId(),findActivityForm.getTitle());
if(!activitySimpleList.isEmpty()){
findActivityRes.setBody(Util.splitList(ActivitySimple.class,activitySimpleList, activityRowSize));
return new JSONResponse<FindActivityRes.Res,FindActivityRes>(FindActivityRes.Res.ok,Result.OK).setBody(findActivityRes);

@ -7,6 +7,7 @@ import com.share.help.entity.ManagerEntity;
import com.share.help.entity.UserEntity;
import com.share.help.form.*;
import com.share.help.form.manager.FindActivityForm;
import com.share.help.form.manager.UpdateActivityForm;
import com.share.help.res.*;
import com.share.help.res.account.ManagerLoginRes;
import com.share.help.res.account.RegisterRes;
@ -146,11 +147,16 @@ public class ManagerService {
return new JSONResponse<DefaultRes, Page<List<ManagerActivityRes>>>(DefaultRes.ok,Result.OK).setBody(page);
}
// public JSONResponse<DefaultRes, Void> deleteActivity(Long activityId) {
// if(activityMapper.delete(activityId)){
//
// }else{
//
// }
// }
/**
* 更新活动信息
* @param updateActivityForm 更新表单
* @return 返回更新结果
*/
public JSONResponse<DefaultRes, Void> updateActivity(UpdateActivityForm updateActivityForm) {
if(activityMapper.updateActivity(updateActivityForm.getActivityId(),updateActivityForm.getTitle(),updateActivityForm.getContent())){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
}

@ -206,8 +206,8 @@ public class UserService{
* @return 返回好友列表
*/
public JSONResponse<DefaultRes, Page<List<Friend>>> searchFriend(SearchFrom searchFrom) {
Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),friendSize);
List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize);
Page<List<Friend>> page=friendMapper.count(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),friendSize);
List<Friend> list=friendMapper.getFriend(searchFrom.getUserId(),searchFrom.getName(),searchFrom.getServiceAddress(),(searchFrom.getCurrentPage()-1)*friendSize,friendSize);
page.setBody(list);
return new JSONResponse<DefaultRes,Page<List<Friend>>>(DefaultRes.ok,Result.OK).setBody(page);
}

@ -22,7 +22,14 @@ logging:
root: info
#跨域配置
cros:
allow-origin: 'http://localhost:3000'
allowedOrigins:
- http://localhost:3000
- http://localhost:3001
pathPattern: /api/**
allowedMethods:
- PUT
- GET
- POST
#用户
user:
#注册

@ -28,7 +28,13 @@
<!-- 获取活动列表-->
<select id="getPage" resultMap="activitySimpleMap">
select activity_id,user_id,title,content,activity_img,(activity_id in(select distinct activity_id from activity_history
where activity_history.user_id=#{userId})) as hasApply,now()>activity_start_time as hasStart from activity order by seek_help_time desc
where activity_history.user_id=#{userId})) as hasApply,now()>activity_start_time as hasStart from activity
<where>
<if test="title !=null and title!=''">
title like '%${title}%'
</if>
</where>
order by seek_help_time desc
limit #{start},#{count}
</select>
@ -110,7 +116,32 @@ and activity_id not in(select activity_id from activity_history) order by seek_
select user_id as userId,name from user where user_id in (select user_id from activity_history where
activity_id=#{activityId} and activity_status=#{activityStatus};
</select>
<!--更新活动信息-->
<update id="updateActivity">
update activity
<set>
<if test="title!=null and title!=''">
title=#{title},
</if>
<if test="content!=null and content!=''">
content=#{content}
</if>
</set>
where activity_id=#{activityId}
</update>
<!-- 获取活跃用户 -->
<select id="queryActiveUser" resultType="com.share.help.form.manager.ActiveUserRes">
select user.user_id as userId, count(user.user_id) as count
from activity_history,
user
where activity_id in (select activity_id from activity where user_id = #{userId})
and activity_status = 'complete'
and activity_history.user_id = user.user_id
and service_address = #{serviceAddress}
group by user.user_id
order by count desc
limit 0,3
</select>
</mapper>

@ -6,32 +6,46 @@
<!-- 获取好友列表-->
<select id="getFriend" resultType="com.share.help.entity.custorm.Friend">
select user_id as userId,name,chat_status as chatStatus from user where user_id in (
select source_user_id as userId from friend where source_user_id!=#{userId} and target_user_id=#{userId}
union all
select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId})
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
select user_id as userId,name,chat_status as chatStatus from user
<where>
user_id in (
select source_user_id as userId from friend where source_user_id!=#{userId} and target_user_id=#{userId}
union all
select target_user_id as userId from friend where target_user_id!=#{userId} and source_user_id=#{userId})
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
and service_address like '%${serviceAddress}%'
</if>
</where>
limit #{start},#{count}
</select>
<select id="count" resultType="com.share.help.res.Page">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage
from user
where user_id in (
select source_user_id as userId
from friend
where source_user_id != #{userId}
and target_user_id = #{userId}
union all
select target_user_id as userId
from friend
where target_user_id != #{userId}
and source_user_id = #{userId}
)
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
<where>
user_id in (
select source_user_id as userId
from friend
where source_user_id != #{userId}
and target_user_id = #{userId}
union all
select target_user_id as userId
from friend
where target_user_id != #{userId}
and source_user_id = #{userId}
)
<if test="name!=null and name!=''">
and name like '%${name}%'
</if>
<if test="serviceAddress!=null and serviceAddress!=''">
and service_address like '%${serviceAddress}%'
</if>
</where>
</select>
</mapper>

@ -6,6 +6,7 @@ import com.share.help.entity.ManagerEntity;
import com.share.help.entity.UserEntity;
import com.share.help.entity.custorm.*;
import com.share.help.form.ActivityStatus;
import com.share.help.form.manager.ActiveUserRes;
import com.share.help.res.ManagerActivityRes;
import com.share.help.res.Page;
import com.share.help.res.account.QueryRes;
@ -164,12 +165,11 @@ class HelpApplicationTests {
*/
@Test
public void testActivity(){
List<ActivitySimple> activityEntityList=activityMapper.getPage(0,10,"123");
Assertions.assertTrue(activityEntityList.isEmpty());
activityEntityList=activityMapper.getPage(0,10,"666");
List<ActivitySimple> activityEntityList=activityMapper.getPage(0,10,"123","");
Assertions.assertFalse(activityEntityList.isEmpty());
activityEntityList=activityMapper.getPage(0,10,"123","赛亚人");
Assertions.assertFalse(activityEntityList.isEmpty());
Assertions.assertNotNull(activityMapper.count(10,"123"));
}
@ -229,10 +229,12 @@ class HelpApplicationTests {
*/
@Test
public void queryFriend(){
Page<List<Friend>> page=friendMapper.count("123","6",3);
Page<List<Friend>> page=friendMapper.count("123","6", "", 3);
Assertions.assertEquals(1, (long) page.getCount());
List<Friend> user=friendMapper.getFriend("123","6",0,3);
List<Friend> user=friendMapper.getFriend("123","6", "上海", 0,3);
Assertions.assertEquals(1,user.size());
user=friendMapper.getFriend("123","6", "广州", 0,3);
Assertions.assertTrue(user.isEmpty());
}
/**
@ -306,4 +308,16 @@ class HelpApplicationTests {
Page<List<ManagerActivityRes>> page=activityMapper.countActivity(10);
Assertions.assertTrue(page.getCount()>0,"管理员分页查询活动失败");
}
//更新活动信息
@Test
public void testUpdateActivity(){
Assertions.assertTrue(activityMapper.updateActivity(66L,"44",""));
}
@Test
public void testQueryActiveUser(){
List<ActiveUserRes> activeUserRes= activityMapper.queryActiveUser("123","广州");
Assertions.assertEquals(2, activeUserRes.get(0).getCount());
}
}

Loading…
Cancel
Save