增加管理后台接口

1.管理员管理
2.后台管理
3.活动管理
master
pan 5 years ago
parent bcfe945b1f
commit a1145dec7d
  1. 22
      src/main/java/com/share/help/Constants.java
  2. 147
      src/main/java/com/share/help/controller/ManagerController.java
  3. 6
      src/main/java/com/share/help/controller/UserController.java
  4. 8
      src/main/java/com/share/help/dao/ActivityMapper.java
  5. 66
      src/main/java/com/share/help/dao/ManagerMapper.java
  6. 20
      src/main/java/com/share/help/dao/SplitHandler.java
  7. 4
      src/main/java/com/share/help/dao/UserMapper.java
  8. 27
      src/main/java/com/share/help/form/ManagerLoginForm.java
  9. 27
      src/main/java/com/share/help/form/ManagerRegisterForm.java
  10. 13
      src/main/java/com/share/help/form/QueryManager.java
  11. 25
      src/main/java/com/share/help/form/UpdateManager.java
  12. 13
      src/main/java/com/share/help/form/manager/FindActivityForm.java
  13. 79
      src/main/java/com/share/help/res/ManagerActivityRes.java
  14. 16
      src/main/java/com/share/help/res/ManagerRes.java
  15. 30
      src/main/java/com/share/help/res/account/ManagerLoginRes.java
  16. 6
      src/main/java/com/share/help/res/account/UserLoginRes.java
  17. 1
      src/main/java/com/share/help/service/ActivityService.java
  18. 156
      src/main/java/com/share/help/service/ManagerService.java
  19. 9
      src/main/java/com/share/help/service/UserService.java
  20. 4
      src/main/resources/application.yaml
  21. 37
      src/main/resources/mapping/ActivityMapper.xml
  22. 16
      src/main/resources/mapping/UserMapper.xml
  23. 48
      src/test/java/com/share/help/HelpApplicationTests.java

@ -66,4 +66,26 @@ public class Constants {
public static final String USER_INTERFACE_FRIEND_LIST = "/friend/list"; public static final String USER_INTERFACE_FRIEND_LIST = "/friend/list";
// 刷新聊天室状态 // 刷新聊天室状态
public static final String USER_INTERFACE_CHAT_STATUS = "/chat/status"; public static final String USER_INTERFACE_CHAT_STATUS = "/chat/status";
//管理员接口
public static final String MANAGER_INTERFACE = "/api/manager";
//管理登录接口
public static final String MANAGER_INTERFACE_LOGIN = "/login";
//管理员注册接口
public static final String MANAGER_INTERFACE_REGISTER = "/register";
//管理员列表接口
public static final String MANAGER_INTERFACE_LIST = "/list";
//管理员cookie
public static final String MANAGER_COOKIE = "manager_cookie";
//更新管理员
public static final String MANAGER_INTERFACE_UPDATE = "/update";
//删除管理员
public static final String MANAGER_INTERFACE_DELETE = "/delete/{managerId}";
//管理员找用户
public static final String MANAGER_INTERFACE_USER = "/user";
//更新用户信息
public static final String MANAGER_INTERFACE_UPDATE_USER = "/userUpdate";
//查找活动列表
public static final String MANAGER_INTERFACE_FIND_ACTIVITY ="/find/activity" ;
//删除活动接口
public static final String MANAGER_INTERFACE_DELTE_ACTIVITY = "/delete/{activityId}";
} }

@ -0,0 +1,147 @@
package com.share.help.controller;
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.res.*;
import com.share.help.res.account.ManagerLoginRes;
import com.share.help.res.account.RegisterRes;
import com.share.help.service.ManagerService;
import com.share.help.service.UserService;
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.MANAGER_INTERFACE)
public class ManagerController {
@Autowired
private ManagerService managerService;
@Autowired
private UserService userService;
/**
* 登录
* @param managerLoginForm 管理员登录表单
* @return 返回登录结果
*/
@PostMapping(Constants.MANAGER_INTERFACE_LOGIN)
public JSONResponse<ManagerLoginRes.Res,ManagerLoginRes> login(ManagerLoginForm managerLoginForm){
if(!StringUtils.isAllEmpty(managerLoginForm.getManagerId(), managerLoginForm.getPassword())){
return managerService.login(managerLoginForm);
}else{
return new JSONResponse<>(ManagerLoginRes.Res.form_fail, Result.FAIL);
}
}
/**
* 注册接口
* @param managerRegisterForm 注册表单
* @return 返回注册结果
*/
@PostMapping(Constants.MANAGER_INTERFACE_REGISTER)
public JSONResponse<RegisterRes,Void> register(ManagerRegisterForm managerRegisterForm){
if(!StringUtils.isAllEmpty(managerRegisterForm.getManagerId(),managerRegisterForm.getPassword())){
return managerService.register(managerRegisterForm);
}else{
return new JSONResponse<>(RegisterRes.fail,Result.FAIL);
}
}
/**
* 管理员列表
* @param queryManager 查询表单
* @return 返回管理员列表
*/
@GetMapping(Constants.MANAGER_INTERFACE_LIST)
public JSONResponse<DefaultRes, Page<List<ManagerRes>>> list(QueryManager queryManager){
if(queryManager.getCurrentPage()!=null){
return managerService.list(queryManager);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 查找用户信息
* @param findUserForm 查找表单
* @return 返回用户列表
*/
@GetMapping(Constants.MANAGER_INTERFACE_USER)
public JSONResponse<DefaultRes,Page<List<UserEntity>>> find(FindUserForm findUserForm){
if(findUserForm.getCurrentPage()!=null){
return managerService.find(findUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 更新管理员
* @param updateManager 更新管理员表单
* @param managerId 管理员品证cookie
* @return 返回更新结果
*/
@PostMapping(Constants.MANAGER_INTERFACE_UPDATE)
public JSONResponse<DefaultRes,Void> update(UpdateManager updateManager, @CookieValue(Constants.MANAGER_COOKIE) String managerId){
if(!StringUtils.isAllEmpty(updateManager.getManagerId(),updateManager.getPassword())&&managerId!=null){
return managerService.update(updateManager);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 删除管理员
* @param managerId 管理员id
* @return 返回删除结果
*/
@PostMapping(Constants.MANAGER_INTERFACE_DELETE)
public JSONResponse<DefaultRes,Void> delete(@PathVariable String managerId){
return managerService.delete(managerId);
}
/**
* 更新用户信息
* @param updateUserForm 更新用户表单
* @return 返回更新结果
*/
@PostMapping(Constants.MANAGER_INTERFACE_UPDATE_USER)
public JSONResponse<DefaultRes,Void> update(UpdateUserForm updateUserForm){
if(updateUserForm.getUserId()!=null){
return userService.update(updateUserForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 查询活动列表
* @param findActivityForm 活动表单
* @return 返回活动列表
*/
@GetMapping(Constants.MANAGER_INTERFACE_FIND_ACTIVITY)
public JSONResponse<DefaultRes,Page<List<ManagerActivityRes>>> findActivity(FindActivityForm findActivityForm){
if(findActivityForm.getCurrentPage()!=null){
return managerService.findActivity(findActivityForm);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
// @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);
// }
// }
}

@ -10,10 +10,10 @@ import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Page; import com.share.help.res.Page;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.LoginRes;
import com.share.help.res.account.ModifyPwdRes; import com.share.help.res.account.ModifyPwdRes;
import com.share.help.res.account.QueryRes; import com.share.help.res.account.QueryRes;
import com.share.help.res.account.RegisterRes; import com.share.help.res.account.RegisterRes;
import com.share.help.res.account.UserLoginRes;
import com.share.help.service.LeaveWordService; import com.share.help.service.LeaveWordService;
import com.share.help.service.UserService; import com.share.help.service.UserService;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
@ -61,11 +61,11 @@ public class UserController {
* @return 返回登陆结果 * @return 返回登陆结果
*/ */
@PostMapping(Constants.USER_INTERFACE_LOGIN) @PostMapping(Constants.USER_INTERFACE_LOGIN)
public JSONResponse<LoginRes.Res,LoginRes> login(UserLoginForm userLoginForm){ public JSONResponse<UserLoginRes.Res, UserLoginRes> login(UserLoginForm userLoginForm){
if(StringUtils.isNoneEmpty(userLoginForm.getUserId(),userLoginForm.getPassword())){ if(StringUtils.isNoneEmpty(userLoginForm.getUserId(),userLoginForm.getPassword())){
return userService.login(userLoginForm); return userService.login(userLoginForm);
}else{ }else{
return new JSONResponse<>(LoginRes.Res.form_error,Result.FAIL); return new JSONResponse<>(UserLoginRes.Res.form_error,Result.FAIL);
} }
} }

@ -5,6 +5,8 @@ import com.share.help.entity.custorm.ActivityDetail;
import com.share.help.entity.custorm.ActivitySimple; import com.share.help.entity.custorm.ActivitySimple;
import com.share.help.entity.custorm.FindActivityRes; import com.share.help.entity.custorm.FindActivityRes;
import com.share.help.entity.custorm.SeekHelpSum; import com.share.help.entity.custorm.SeekHelpSum;
import com.share.help.res.ManagerActivityRes;
import com.share.help.res.Page;
import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options; import org.apache.ibatis.annotations.Options;
@ -59,4 +61,10 @@ public interface ActivityMapper {
//求助信息 //求助信息
List<SeekHelpSum> seekHelp(@Param("userId") String userId); List<SeekHelpSum> seekHelp(@Param("userId") String userId);
//查找管理员信息
List<ManagerActivityRes> queryActivity(@Param("start") Integer start, @Param("count") Integer count);
//分页信息
Page<List<ManagerActivityRes>> countActivity(@Param("pageSize") Integer pageSize);
} }

@ -0,0 +1,66 @@
package com.share.help.dao;
import com.share.help.entity.ManagerEntity;
import com.share.help.res.ManagerRes;
import com.share.help.res.Page;
import org.apache.ibatis.annotations.*;
import java.util.List;
/**
* 管理员数据接口
*/
public interface ManagerMapper {
/**
* 根据账号密码查找管理员
* @param managerId 管理员账号
* @return 返回管理员信息
*/
@Select("select manager_id as managerId,password from manager where manager_id=#{managerId}")
ManagerEntity findUser(@Param("managerId") String managerId);
/**
* 添加管理员
* @param managerEntity 管理员实体类
* @return 返回添加结果
*/
@Insert("insert into manager(manager_id,password) value (#{managerId},#{password})")
boolean insert(ManagerEntity managerEntity);
/**
* 判断管理员是否存在
* @param managerId 管理员id
* @return true 存在false 不存在
*/
@Select("select count(*) from manager where manager_id=#{managerId}")
boolean hasUser(@Param("managerId") String managerId);
/**
* 统计管理员分页信息
* @param pageSize 分页大小
* @return 返回分页结果
*/
@Select("select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from manager")
Page<List<ManagerRes>> count(@Param("pageSize") int pageSize);
/**
* 分页查询管理员
* @param start 起始索引
* @param pageSize 查询记录数
* @return 返回管理员集合
*/
@Select("select manager_id as managerId from manager limit #{start},#{pageSize}")
List<ManagerRes> list(@Param("start") int start,@Param("pageSize") int pageSize);
/**
* 更新管理员
* @param managerEntity 管理员实体数据
* @return 返回更新结果
*/
@Update("update manager set password=#{password} where manager_id=#{managerId}")
boolean update(ManagerEntity managerEntity);
@Delete("delete from manager where manager_id=#{managerId}")
boolean delete(@Param("managerId") String managerId);
}

@ -0,0 +1,20 @@
package com.share.help.dao;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.type.ArrayTypeHandler;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
public class SplitHandler extends ArrayTypeHandler {
@Override
public Object getNullableResult(ResultSet rs, String columnName) throws SQLException {
String splitString= rs.getString(columnName);
if(StringUtils.isEmpty(splitString)){
return null;
}else {
return Arrays.asList(splitString.split(","));
}
}
}

@ -88,11 +88,15 @@ public interface UserMapper {
FindUserRes count(@Param("pageSize") Integer pageSize, @Param("userTypes") List<String> userTypes,@Param("info") FindUserRes count(@Param("pageSize") Integer pageSize, @Param("userTypes") List<String> userTypes,@Param("info")
String info,@Param("serviceAddress") String serviceAddress); String info,@Param("serviceAddress") String serviceAddress);
Page<List<UserEntity>> countUserByManager(@Param("pageSize") Integer pageSize, @Param("userTypes") List<String> userTypes,@Param("info")
String info,@Param("serviceAddress") String serviceAddress);
/** /**
* 查找用户 * 查找用户
*/ */
List<UserWithName> queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId); List<UserWithName> queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId);
Page<List<UserWithName>> countUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("pageSize") Integer pageSize); Page<List<UserWithName>> countUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("pageSize") Integer pageSize);
/** /**

@ -0,0 +1,27 @@
package com.share.help.form;
/**
* 管理员登录表单
*/
public class ManagerLoginForm {
//管理员账号
private String managerId;
//密码
private String password;
public String getManagerId() {
return managerId;
}
public void setManagerId(String managerId) {
this.managerId = managerId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -0,0 +1,27 @@
package com.share.help.form;
/**
* 管理员注册表单
*/
public class ManagerRegisterForm {
// 管理员账号
private String managerId;
// 密码
private String password;
public String getManagerId() {
return managerId;
}
public void setManagerId(String managerId) {
this.managerId = managerId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -0,0 +1,13 @@
package com.share.help.form;
public class QueryManager {
private Integer currentPage;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
}

@ -0,0 +1,25 @@
package com.share.help.form;
/**
* 更新管理员表单
*/
public class UpdateManager {
private String managerId;
private String password;
public String getManagerId() {
return managerId;
}
public void setManagerId(String managerId) {
this.managerId = managerId;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

@ -0,0 +1,13 @@
package com.share.help.form.manager;
public class FindActivityForm {
private Integer currentPage;
public Integer getCurrentPage() {
return currentPage;
}
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
}

@ -0,0 +1,79 @@
package com.share.help.res;
import java.sql.Timestamp;
import java.util.List;
public class ManagerActivityRes {
private Long activityId;
private String content;
private String title;
private String activityImg;
private Timestamp activityStartTime;
private Timestamp activityEndTime;
private String seekHelpUser;
private List<String> helpUser;
public Long getActivityId() {
return activityId;
}
public void setActivityId(Long activityId) {
this.activityId = activityId;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getActivityImg() {
return activityImg;
}
public void setActivityImg(String activityImg) {
this.activityImg = activityImg;
}
public Timestamp getActivityStartTime() {
return activityStartTime;
}
public void setActivityStartTime(Timestamp activityStartTime) {
this.activityStartTime = activityStartTime;
}
public Timestamp getActivityEndTime() {
return activityEndTime;
}
public void setActivityEndTime(Timestamp activityEndTime) {
this.activityEndTime = activityEndTime;
}
public String getSeekHelpUser() {
return seekHelpUser;
}
public void setSeekHelpUser(String seekHelpUser) {
this.seekHelpUser = seekHelpUser;
}
public List<String> getHelpUser() {
return helpUser;
}
public void setHelpUser(List<String> helpUser) {
this.helpUser = helpUser;
}
}

@ -0,0 +1,16 @@
package com.share.help.res;
/**
* 管理员返回
*/
public class ManagerRes {
private String managerId;
public String getManagerId() {
return managerId;
}
public void setManagerId(String managerId) {
this.managerId = managerId;
}
}

@ -0,0 +1,30 @@
package com.share.help.res.account;
import com.share.help.entity.ManagerEntity;
/**
* 管理员登录响应
*/
public class ManagerLoginRes {
private String managerId;
public ManagerLoginRes(ManagerEntity managerEntity) {
this.managerId=managerEntity.getManagerId();
}
public String getManagerId() {
return managerId;
}
public void setManagerId(String managerId) {
this.managerId = managerId;
}
public enum Res {
ok,
fail,
form_fail,
valid_fail
}
}

@ -3,9 +3,9 @@ package com.share.help.res.account;
import com.share.help.entity.UserEntity; import com.share.help.entity.UserEntity;
/** /**
* 登陆结果 * 用户登陆响应数据
*/ */
public class LoginRes { public class UserLoginRes {
//用户id //用户id
private String userId; private String userId;
@ -16,7 +16,7 @@ public class LoginRes {
//时间币 //时间币
private Integer timeScore; private Integer timeScore;
public LoginRes(UserEntity userEntity) { public UserLoginRes(UserEntity userEntity) {
this.userId = userEntity.getUserId(); this.userId = userEntity.getUserId();
this.userType = userEntity.getUserType(); this.userType = userEntity.getUserType();
this.timeScore = userEntity.getTimeScore(); this.timeScore = userEntity.getTimeScore();

@ -112,6 +112,7 @@ public class ActivityService{
* @param sendHelpForm 推荐表单 * @param sendHelpForm 推荐表单
*/ */
private void autoRecommend(SendHelpForm sendHelpForm) { private void autoRecommend(SendHelpForm sendHelpForm) {
//查找参加过我活动的好友
} }

@ -0,0 +1,156 @@
package com.share.help.service;
import com.share.help.dao.ActivityMapper;
import com.share.help.dao.ManagerMapper;
import com.share.help.dao.UserMapper;
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.res.*;
import com.share.help.res.account.ManagerLoginRes;
import com.share.help.res.account.RegisterRes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;
import java.util.List;
@Service
public class ManagerService {
@Autowired
private ManagerMapper managerMapper;
private Logger logger= LoggerFactory.getLogger(ManagerService.class);
@Value("${page-size.manager}")
private int pageSize;
//用户分页配置
@Value("${page-size.user.page-size}")
private int userPageSize;
@Autowired
private UserMapper userMapper;
@Autowired
private ActivityMapper activityMapper;
/**
* 登录
* @param managerLoginForm 登录表单
* @return 返回登录结果
*/
public JSONResponse<ManagerLoginRes.Res, ManagerLoginRes> login(ManagerLoginForm managerLoginForm) {
ManagerEntity managerEntity=managerMapper.findUser(managerLoginForm.getManagerId());
if (managerEntity==null){
logger.error("管理员账号:"+ managerLoginForm.getManagerId()+"不存在");
return new JSONResponse<>(ManagerLoginRes.Res.valid_fail, Result.FAIL);
}
String password= DigestUtils.md5DigestAsHex(managerLoginForm.getPassword().getBytes());
if(password.equals(managerEntity.getPassword())){
return new JSONResponse<ManagerLoginRes.Res,
ManagerLoginRes>(ManagerLoginRes.Res.ok,Result.OK).setBody(new ManagerLoginRes(managerEntity));
}else{
logger.error("管理员:"+managerEntity.getManagerId()+"密码验证错误");
return new JSONResponse<>(ManagerLoginRes.Res.valid_fail, Result.FAIL);
}
}
/**
* 注册
* @param managerRegisterForm 注册表单
* @return 返回注册结果
*/
public JSONResponse<RegisterRes, Void> register(ManagerRegisterForm managerRegisterForm) {
if(managerMapper.hasUser(managerRegisterForm.getManagerId())){
return new JSONResponse<>(RegisterRes.user_repeat,Result.FAIL);
}
ManagerEntity managerEntity=new ManagerEntity();
managerEntity.setManagerId(managerRegisterForm.getManagerId());
managerEntity.setPassword(DigestUtils.md5DigestAsHex(managerRegisterForm.getPassword().getBytes()));
if(managerMapper.insert(managerEntity)){
return new JSONResponse<>(RegisterRes.ok,Result.OK);
}else{
return new JSONResponse<>(RegisterRes.fail,Result.FAIL);
}
}
/**
* 管理员列表
* @param queryManager 查询表单
* @return 返回管理员列表
*/
public JSONResponse<DefaultRes, Page<List<ManagerRes>>> list(QueryManager queryManager) {
Page<List<ManagerRes>> page=managerMapper.count(pageSize);
List<ManagerRes> list=managerMapper.list((queryManager.getCurrentPage()-1)*pageSize,pageSize);
page.setBody(list);
return new JSONResponse<DefaultRes, Page<List<ManagerRes>>>(DefaultRes.ok,Result.OK).setBody(page);
}
/**
* 更新管理员
* @param manager 管理员表单
* @return 返回更新结果
*/
public JSONResponse<DefaultRes,Void> update(UpdateManager manager){
ManagerEntity managerEntity=managerMapper.findUser(manager.getManagerId());
managerEntity.setPassword(DigestUtils.md5DigestAsHex(manager.getPassword().getBytes()));
if(managerMapper.update(managerEntity)){
return new JSONResponse<>(DefaultRes.ok,Result.OK);
}else{
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
* 删除管理员
* @param managerId 管理员id
* @return 返回删除结果
*/
public JSONResponse<DefaultRes, Void> delete(String managerId) {
if (managerMapper.delete(managerId)) {
return new JSONResponse<>(DefaultRes.ok, Result.OK);
} else {
return new JSONResponse<>(DefaultRes.fail,Result.FAIL);
}
}
/**
*
* @param findUserForm 查找用户表单
* @return 返回用户列表
*/
public JSONResponse<DefaultRes,Page<List<UserEntity>>> find(FindUserForm findUserForm){
Page<List<UserEntity>> page=userMapper.countUserByManager(userPageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress());
List<UserEntity> userEntityList=userMapper.getPage((findUserForm.getCurrentPage()-1)* userPageSize, userPageSize,findUserForm.getUserTypes(),
findUserForm.getInfo(),findUserForm.getServiceAddress());
page.setBody(userEntityList);
return new JSONResponse<DefaultRes,Page<List<UserEntity>>>(DefaultRes.ok,Result.OK).setBody(page);
}
/**
*
* @param findActivityForm 查找活动列表
* @return 返回活动列表
*/
public JSONResponse<DefaultRes, Page<List<ManagerActivityRes>>> findActivity(FindActivityForm findActivityForm) {
Page<List<ManagerActivityRes>> page=activityMapper.countActivity(pageSize);
page.setBody(activityMapper.queryActivity((findActivityForm.getCurrentPage()-1),pageSize));
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{
//
// }
// }
}

@ -12,10 +12,10 @@ import com.share.help.res.DefaultRes;
import com.share.help.res.JSONResponse; import com.share.help.res.JSONResponse;
import com.share.help.res.Page; import com.share.help.res.Page;
import com.share.help.res.Result; import com.share.help.res.Result;
import com.share.help.res.account.LoginRes;
import com.share.help.res.account.ModifyPwdRes; import com.share.help.res.account.ModifyPwdRes;
import com.share.help.res.account.QueryRes; import com.share.help.res.account.QueryRes;
import com.share.help.res.account.RegisterRes; import com.share.help.res.account.RegisterRes;
import com.share.help.res.account.UserLoginRes;
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;
@ -97,11 +97,11 @@ public class UserService{
* @param userLoginForm 登陆表单 * @param userLoginForm 登陆表单
* @return 返回登录结果 * @return 返回登录结果
*/ */
public JSONResponse<LoginRes.Res,LoginRes> login(UserLoginForm userLoginForm){ public JSONResponse<UserLoginRes.Res, UserLoginRes> login(UserLoginForm userLoginForm){
UserEntity userEntity=userMapper.findOneWithPwd(userLoginForm.getUserId(),DigestUtils.md5DigestAsHex(userLoginForm.getPassword().getBytes())); UserEntity userEntity=userMapper.findOneWithPwd(userLoginForm.getUserId(),DigestUtils.md5DigestAsHex(userLoginForm.getPassword().getBytes()));
return userEntity==null?new JSONResponse<>(LoginRes.Res.valid_error,Result.FAIL) return userEntity==null?new JSONResponse<>(UserLoginRes.Res.valid_error,Result.FAIL)
:new JSONResponse<LoginRes.Res,LoginRes>(LoginRes.Res.ok,Result.OK).setBody(new LoginRes(userEntity)); :new JSONResponse<UserLoginRes.Res, UserLoginRes>(UserLoginRes.Res.ok,Result.OK).setBody(new UserLoginRes(userEntity));
} }
/** /**
@ -123,6 +123,7 @@ public class UserService{
} }
} }
/** /**
* 获取用户个人信息 * 获取用户个人信息
* *

@ -46,8 +46,10 @@ page-size:
user: user:
# 分页大小 # 分页大小
page-size: 6 page-size: 6
# 前端一行显示数量 # 行显示数量
row-size: 3 row-size: 3
#好友列表 #好友列表
friend: 3 friend: 3
#管理员列表
manager: 10

@ -39,6 +39,7 @@
where activity_id=#{activityId} where activity_id=#{activityId}
</select> </select>
<select id="count" resultType="com.share.help.entity.custorm.FindActivityRes"> <select id="count" resultType="com.share.help.entity.custorm.FindActivityRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity
</select> </select>
@ -54,6 +55,41 @@
<result property="complete" column="complete"/> <result property="complete" column="complete"/>
</resultMap> </resultMap>
<!-- 管理员查找活动信息 -->
<resultMap id="managerActivityRes" type="com.share.help.res.ManagerActivityRes">
<result property="helpUser" column="helpUser" javaType="list" typeHandler="com.share.help.dao.SplitHandler"/>
</resultMap>
<select id="countActivity" resultType="com.share.help.res.Page">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from activity
</select>
<!-- 管理员查找活动信息-->
<select id="queryActivity" resultMap="managerActivityRes">
select activity.activity_id as activityId,
activity.content,
activity.title,
activity.activity_img as activityImg,
activity.activity_start_time as activityStartTime,
activity.activity_end_time as activityEndTime,
activity.user_id as seekHelpUser,
group_concat(activity_history.user_id) as helpUser
from activity_history,activity where activity.activity_id=activity_history.activity_id group by activity.activity_id
union all
select activity_id as activityId,
content,
title,
activity_img as activityImg,
activity_start_time as activityStartTime,
activity_end_time as activityEndTime,
user_id as seekHelpUser,
null as helpUser
from activity where activity_id not in(select activity_id from activity_history)
limit #{start},#{count}
</select>
<!-- 查询用户的求助信息--> <!-- 查询用户的求助信息-->
<select id="seekHelp" resultMap="seekHelpMap"> <select id="seekHelp" resultMap="seekHelpMap">
select activity_id,activity_img,seek_help_time,title,content, select activity_id,activity_img,seek_help_time,title,content,
@ -76,4 +112,5 @@ and activity_id not in(select activity_id from activity_history) order by seek_
</select> </select>
</mapper> </mapper>

@ -32,15 +32,14 @@
from user where user_id=#{targetUserId} from user where user_id=#{targetUserId}
</select> </select>
<!-- 统计用户分页数--> <sql id="countSql">
<select id="count" resultType="com.share.help.entity.custorm.FindUserRes">
select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from user select count(*) as count,ceil(count(*)/#{pageSize}) as totalPage from user
<where> <where>
<if test='userTypes.size>0'> <if test='userTypes.size>0'>
and user_type in and user_type in
<foreach collection='userTypes' open='(' item='userType' separator=',' close=')'> <foreach collection='userTypes' open='(' item='userType' separator=',' close=')'>
#{userType} #{userType}
</foreach> </foreach>
</if> </if>
<if test="info!=null and info!=''"> <if test="info!=null and info!=''">
and info like '%${info}%' and info like '%${info}%'
@ -49,8 +48,19 @@
and service_address = #{serviceAddress} and service_address = #{serviceAddress}
</if> </if>
</where> </where>
</sql>
<!-- 统计用户分页数-->
<select id="count" resultType="com.share.help.entity.custorm.FindUserRes">
<include refid="countSql"/>
</select> </select>
<!-- 统计用户分页数-->
<select id="countUserByManager" resultType="com.share.help.res.Page">
<include refid="countSql"/>
</select>
<!-- 分页查询--> <!-- 分页查询-->
<select id="getPage" resultMap="userMap"> <select id="getPage" resultMap="userMap">
select * from user select * from user

@ -2,9 +2,11 @@ package com.share.help;
import com.share.help.dao.*; import com.share.help.dao.*;
import com.share.help.entity.ActivityHistoryEntity; import com.share.help.entity.ActivityHistoryEntity;
import com.share.help.entity.ManagerEntity;
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.ActivityStatus; import com.share.help.form.ActivityStatus;
import com.share.help.res.ManagerActivityRes;
import com.share.help.res.Page; import com.share.help.res.Page;
import com.share.help.res.account.QueryRes; import com.share.help.res.account.QueryRes;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
@ -16,12 +18,15 @@ 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;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers; import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import javax.servlet.http.Cookie; import javax.servlet.http.Cookie;
@ -33,6 +38,7 @@ import java.util.UUID;
@SpringBootTest @SpringBootTest
@MapperScans(@MapperScan("com.share.help.dao")) @MapperScans(@MapperScan("com.share.help.dao"))
@EnableTransactionManagement @EnableTransactionManagement
@Transactional
class HelpApplicationTests { class HelpApplicationTests {
@Autowired @Autowired
@ -55,6 +61,9 @@ class HelpApplicationTests {
@Autowired @Autowired
private FriendMapper friendMapper; private FriendMapper friendMapper;
@Autowired
private ManagerMapper managerMapper;
private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class); private Logger logger = LoggerFactory.getLogger(HelpApplicationTests.class);
@BeforeEach @BeforeEach
@ -257,9 +266,44 @@ class HelpApplicationTests {
activityHistoryEntity.setActivityStatus(ActivityStatus.complete.name()); activityHistoryEntity.setActivityStatus(ActivityStatus.complete.name());
activityHistoryEntity.setActivityId(57L); activityHistoryEntity.setActivityId(57L);
activityHistoryEntity.setUserId("123"); activityHistoryEntity.setUserId("123");
Integer score=activityHistoryMapper.getTimeScore(57L,"123"); Integer score=activityHistoryMapper.getTimeScore(57L,"123");
activityHistoryEntity.setTimeScore(score); activityHistoryEntity.setTimeScore(score);
Assertions.assertTrue(activityHistoryMapper.insert(activityHistoryEntity)); Assertions.assertTrue(activityHistoryMapper.insert(activityHistoryEntity));
} }
/**
* 测试管理员
*/
@Test
@Rollback
public void testManager(){
ManagerEntity managerEntity=new ManagerEntity();
managerEntity.setManagerId("123");
managerEntity.setPassword("123");
Assertions.assertTrue(managerMapper.insert(managerEntity),"账号未注册!!!");
Assertions.assertTrue(managerMapper.hasUser(managerEntity.getManagerId()),"账号未注册!!!");
Assertions.assertTrue(managerMapper.count(10).getCount()>0,"管理员分页查询失败");
Assertions.assertFalse(managerMapper.list(0,10).isEmpty(),"管理员分页查询失败");
String password= DigestUtils.md5DigestAsHex("222".getBytes());
managerEntity.setPassword(password);
Assertions.assertTrue(managerMapper.update(managerEntity));
Assertions.assertTrue(managerMapper.delete("123"));
}
// 测试管理员查询活动
@Test
public void testQueryActivity(){
List<ManagerActivityRes> list=activityMapper.queryActivity(0,20);
Assertions.assertFalse(list.isEmpty(),"管理员分页查询活动失败");
Page<List<ManagerActivityRes>> page=activityMapper.countActivity(10);
Assertions.assertTrue(page.getCount()>0,"管理员分页查询活动失败");
}
} }

Loading…
Cancel
Save