From a1145dec7d325d7567aca8b24d67d7881e66bc66 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sun, 31 May 2020 22:22:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=AE=A1=E7=90=86=E5=90=8E?= =?UTF-8?q?=E5=8F=B0=E6=8E=A5=E5=8F=A3=201.=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E7=AE=A1=E7=90=86=202.=E5=90=8E=E5=8F=B0=E7=AE=A1=E7=90=86=203?= =?UTF-8?q?.=E6=B4=BB=E5=8A=A8=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/share/help/Constants.java | 22 +++ .../help/controller/ManagerController.java | 147 +++++++++++++++++ .../share/help/controller/UserController.java | 6 +- .../com/share/help/dao/ActivityMapper.java | 8 + .../com/share/help/dao/ManagerMapper.java | 66 ++++++++ .../java/com/share/help/dao/SplitHandler.java | 20 +++ .../java/com/share/help/dao/UserMapper.java | 4 + .../com/share/help/form/ManagerLoginForm.java | 27 +++ .../share/help/form/ManagerRegisterForm.java | 27 +++ .../com/share/help/form/QueryManager.java | 13 ++ .../com/share/help/form/UpdateManager.java | 25 +++ .../help/form/manager/FindActivityForm.java | 13 ++ .../share/help/res/ManagerActivityRes.java | 79 +++++++++ .../java/com/share/help/res/ManagerRes.java | 16 ++ .../help/res/account/ManagerLoginRes.java | 30 ++++ .../{LoginRes.java => UserLoginRes.java} | 6 +- .../share/help/service/ActivityService.java | 1 + .../share/help/service/ManagerService.java | 156 ++++++++++++++++++ .../com/share/help/service/UserService.java | 9 +- src/main/resources/application.yaml | 4 +- src/main/resources/mapping/ActivityMapper.xml | 37 +++++ src/main/resources/mapping/UserMapper.xml | 16 +- .../com/share/help/HelpApplicationTests.java | 48 +++++- 23 files changed, 764 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/share/help/controller/ManagerController.java create mode 100644 src/main/java/com/share/help/dao/ManagerMapper.java create mode 100644 src/main/java/com/share/help/dao/SplitHandler.java create mode 100644 src/main/java/com/share/help/form/ManagerLoginForm.java create mode 100644 src/main/java/com/share/help/form/ManagerRegisterForm.java create mode 100644 src/main/java/com/share/help/form/QueryManager.java create mode 100644 src/main/java/com/share/help/form/UpdateManager.java create mode 100644 src/main/java/com/share/help/form/manager/FindActivityForm.java create mode 100644 src/main/java/com/share/help/res/ManagerActivityRes.java create mode 100644 src/main/java/com/share/help/res/ManagerRes.java create mode 100644 src/main/java/com/share/help/res/account/ManagerLoginRes.java rename src/main/java/com/share/help/res/account/{LoginRes.java => UserLoginRes.java} (90%) create mode 100644 src/main/java/com/share/help/service/ManagerService.java diff --git a/src/main/java/com/share/help/Constants.java b/src/main/java/com/share/help/Constants.java index 5573ece..6d2cedc 100644 --- a/src/main/java/com/share/help/Constants.java +++ b/src/main/java/com/share/help/Constants.java @@ -66,4 +66,26 @@ public class Constants { public static final String USER_INTERFACE_FRIEND_LIST = "/friend/list"; // 刷新聊天室状态 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}"; } diff --git a/src/main/java/com/share/help/controller/ManagerController.java b/src/main/java/com/share/help/controller/ManagerController.java new file mode 100644 index 0000000..acd8d01 --- /dev/null +++ b/src/main/java/com/share/help/controller/ManagerController.java @@ -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 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 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>> 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>> 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 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 delete(@PathVariable String managerId){ + return managerService.delete(managerId); + } + + /** + * 更新用户信息 + * @param updateUserForm 更新用户表单 + * @return 返回更新结果 + */ + @PostMapping(Constants.MANAGER_INTERFACE_UPDATE_USER) + public JSONResponse 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>> 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 deleteActivity(@PathVariable Long activityId){ +// if(activityId!=null){ +// return managerService.deleteActivity(activityId); +// }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 95241ce..e4de816 100644 --- a/src/main/java/com/share/help/controller/UserController.java +++ b/src/main/java/com/share/help/controller/UserController.java @@ -10,10 +10,10 @@ 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.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.res.account.UserLoginRes; import com.share.help.service.LeaveWordService; import com.share.help.service.UserService; import org.apache.commons.lang3.ObjectUtils; @@ -61,11 +61,11 @@ public class UserController { * @return 返回登陆结果 */ @PostMapping(Constants.USER_INTERFACE_LOGIN) - public JSONResponse login(UserLoginForm userLoginForm){ + public JSONResponse login(UserLoginForm userLoginForm){ if(StringUtils.isNoneEmpty(userLoginForm.getUserId(),userLoginForm.getPassword())){ return userService.login(userLoginForm); }else{ - return new JSONResponse<>(LoginRes.Res.form_error,Result.FAIL); + return new JSONResponse<>(UserLoginRes.Res.form_error,Result.FAIL); } } diff --git a/src/main/java/com/share/help/dao/ActivityMapper.java b/src/main/java/com/share/help/dao/ActivityMapper.java index 7f90e7f..4483378 100644 --- a/src/main/java/com/share/help/dao/ActivityMapper.java +++ b/src/main/java/com/share/help/dao/ActivityMapper.java @@ -5,6 +5,8 @@ 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.res.ManagerActivityRes; +import com.share.help.res.Page; import org.apache.ibatis.annotations.Delete; import org.apache.ibatis.annotations.Insert; import org.apache.ibatis.annotations.Options; @@ -59,4 +61,10 @@ public interface ActivityMapper { //求助信息 List seekHelp(@Param("userId") String userId); + + //查找管理员信息 + List queryActivity(@Param("start") Integer start, @Param("count") Integer count); + + //分页信息 + Page> countActivity(@Param("pageSize") Integer pageSize); } diff --git a/src/main/java/com/share/help/dao/ManagerMapper.java b/src/main/java/com/share/help/dao/ManagerMapper.java new file mode 100644 index 0000000..8a11d19 --- /dev/null +++ b/src/main/java/com/share/help/dao/ManagerMapper.java @@ -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> count(@Param("pageSize") int pageSize); + + /** + * 分页查询管理员 + * @param start 起始索引 + * @param pageSize 查询记录数 + * @return 返回管理员集合 + */ + @Select("select manager_id as managerId from manager limit #{start},#{pageSize}") + List 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); +} diff --git a/src/main/java/com/share/help/dao/SplitHandler.java b/src/main/java/com/share/help/dao/SplitHandler.java new file mode 100644 index 0000000..521d7dd --- /dev/null +++ b/src/main/java/com/share/help/dao/SplitHandler.java @@ -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(",")); + } + } +} diff --git a/src/main/java/com/share/help/dao/UserMapper.java b/src/main/java/com/share/help/dao/UserMapper.java index 092519b..956796b 100644 --- a/src/main/java/com/share/help/dao/UserMapper.java +++ b/src/main/java/com/share/help/dao/UserMapper.java @@ -88,11 +88,15 @@ public interface UserMapper { FindUserRes count(@Param("pageSize") Integer pageSize, @Param("userTypes") List userTypes,@Param("info") String info,@Param("serviceAddress") String serviceAddress); + Page> countUserByManager(@Param("pageSize") Integer pageSize, @Param("userTypes") List userTypes,@Param("info") + String info,@Param("serviceAddress") String serviceAddress); + /** * 查找用户 */ List queryUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId); + Page> countUser(@Param("name") String name, @Param("info") String info,@Param("userId") String userId,@Param("pageSize") Integer pageSize); /** diff --git a/src/main/java/com/share/help/form/ManagerLoginForm.java b/src/main/java/com/share/help/form/ManagerLoginForm.java new file mode 100644 index 0000000..e2b2ded --- /dev/null +++ b/src/main/java/com/share/help/form/ManagerLoginForm.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/form/ManagerRegisterForm.java b/src/main/java/com/share/help/form/ManagerRegisterForm.java new file mode 100644 index 0000000..bae4dd5 --- /dev/null +++ b/src/main/java/com/share/help/form/ManagerRegisterForm.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/form/QueryManager.java b/src/main/java/com/share/help/form/QueryManager.java new file mode 100644 index 0000000..f6709d0 --- /dev/null +++ b/src/main/java/com/share/help/form/QueryManager.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/form/UpdateManager.java b/src/main/java/com/share/help/form/UpdateManager.java new file mode 100644 index 0000000..9c34c93 --- /dev/null +++ b/src/main/java/com/share/help/form/UpdateManager.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/form/manager/FindActivityForm.java b/src/main/java/com/share/help/form/manager/FindActivityForm.java new file mode 100644 index 0000000..499745e --- /dev/null +++ b/src/main/java/com/share/help/form/manager/FindActivityForm.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/res/ManagerActivityRes.java b/src/main/java/com/share/help/res/ManagerActivityRes.java new file mode 100644 index 0000000..a197e35 --- /dev/null +++ b/src/main/java/com/share/help/res/ManagerActivityRes.java @@ -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 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 getHelpUser() { + return helpUser; + } + + public void setHelpUser(List helpUser) { + this.helpUser = helpUser; + } +} diff --git a/src/main/java/com/share/help/res/ManagerRes.java b/src/main/java/com/share/help/res/ManagerRes.java new file mode 100644 index 0000000..2dac4f3 --- /dev/null +++ b/src/main/java/com/share/help/res/ManagerRes.java @@ -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; + } +} diff --git a/src/main/java/com/share/help/res/account/ManagerLoginRes.java b/src/main/java/com/share/help/res/account/ManagerLoginRes.java new file mode 100644 index 0000000..18026dd --- /dev/null +++ b/src/main/java/com/share/help/res/account/ManagerLoginRes.java @@ -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 + } +} diff --git a/src/main/java/com/share/help/res/account/LoginRes.java b/src/main/java/com/share/help/res/account/UserLoginRes.java similarity index 90% rename from src/main/java/com/share/help/res/account/LoginRes.java rename to src/main/java/com/share/help/res/account/UserLoginRes.java index e891ccf..e56b741 100644 --- a/src/main/java/com/share/help/res/account/LoginRes.java +++ b/src/main/java/com/share/help/res/account/UserLoginRes.java @@ -3,9 +3,9 @@ package com.share.help.res.account; import com.share.help.entity.UserEntity; /** - * 登陆结果 + * 用户登陆响应数据 */ -public class LoginRes { +public class UserLoginRes { //用户id private String userId; @@ -16,7 +16,7 @@ public class LoginRes { //时间币 private Integer timeScore; - public LoginRes(UserEntity userEntity) { + public UserLoginRes(UserEntity userEntity) { this.userId = userEntity.getUserId(); this.userType = userEntity.getUserType(); this.timeScore = userEntity.getTimeScore(); diff --git a/src/main/java/com/share/help/service/ActivityService.java b/src/main/java/com/share/help/service/ActivityService.java index 98395d9..4e2d067 100644 --- a/src/main/java/com/share/help/service/ActivityService.java +++ b/src/main/java/com/share/help/service/ActivityService.java @@ -112,6 +112,7 @@ public class ActivityService{ * @param sendHelpForm 推荐表单 */ private void autoRecommend(SendHelpForm sendHelpForm) { + //查找参加过我活动的好友 } diff --git a/src/main/java/com/share/help/service/ManagerService.java b/src/main/java/com/share/help/service/ManagerService.java new file mode 100644 index 0000000..d4e33c5 --- /dev/null +++ b/src/main/java/com/share/help/service/ManagerService.java @@ -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 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.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 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>> list(QueryManager queryManager) { + Page> page=managerMapper.count(pageSize); + List list=managerMapper.list((queryManager.getCurrentPage()-1)*pageSize,pageSize); + page.setBody(list); + + return new JSONResponse>>(DefaultRes.ok,Result.OK).setBody(page); + } + + /** + * 更新管理员 + * @param manager 管理员表单 + * @return 返回更新结果 + */ + public JSONResponse 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 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>> find(FindUserForm findUserForm){ + Page> page=userMapper.countUserByManager(userPageSize,findUserForm.getUserTypes(),findUserForm.getInfo(),findUserForm.getServiceAddress()); + List userEntityList=userMapper.getPage((findUserForm.getCurrentPage()-1)* userPageSize, userPageSize,findUserForm.getUserTypes(), + findUserForm.getInfo(),findUserForm.getServiceAddress()); + page.setBody(userEntityList); + return new JSONResponse>>(DefaultRes.ok,Result.OK).setBody(page); + } + + /** + * + * @param findActivityForm 查找活动列表 + * @return 返回活动列表 + */ + public JSONResponse>> findActivity(FindActivityForm findActivityForm) { + Page> page=activityMapper.countActivity(pageSize); + page.setBody(activityMapper.queryActivity((findActivityForm.getCurrentPage()-1),pageSize)); + return new JSONResponse>>(DefaultRes.ok,Result.OK).setBody(page); + } + +// public JSONResponse deleteActivity(Long activityId) { +// if(activityMapper.delete(activityId)){ +// +// }else{ +// +// } +// } +} diff --git a/src/main/java/com/share/help/service/UserService.java b/src/main/java/com/share/help/service/UserService.java index e5044f2..9ccee7d 100644 --- a/src/main/java/com/share/help/service/UserService.java +++ b/src/main/java/com/share/help/service/UserService.java @@ -12,10 +12,10 @@ 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.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.res.account.UserLoginRes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -97,11 +97,11 @@ public class UserService{ * @param userLoginForm 登陆表单 * @return 返回登录结果 */ - public JSONResponse login(UserLoginForm userLoginForm){ + public JSONResponse login(UserLoginForm userLoginForm){ UserEntity userEntity=userMapper.findOneWithPwd(userLoginForm.getUserId(),DigestUtils.md5DigestAsHex(userLoginForm.getPassword().getBytes())); - return userEntity==null?new JSONResponse<>(LoginRes.Res.valid_error,Result.FAIL) - :new JSONResponse(LoginRes.Res.ok,Result.OK).setBody(new LoginRes(userEntity)); + return userEntity==null?new JSONResponse<>(UserLoginRes.Res.valid_error,Result.FAIL) + :new JSONResponse(UserLoginRes.Res.ok,Result.OK).setBody(new UserLoginRes(userEntity)); } /** @@ -123,6 +123,7 @@ public class UserService{ } } + /** * 获取用户个人信息 * diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml index 788ccf6..c5197ed 100644 --- a/src/main/resources/application.yaml +++ b/src/main/resources/application.yaml @@ -46,8 +46,10 @@ page-size: user: # 分页大小 page-size: 6 - # 前端一行显示数量 + # 单行显示数量 row-size: 3 #好友列表 friend: 3 + #管理员列表 + manager: 10 diff --git a/src/main/resources/mapping/ActivityMapper.xml b/src/main/resources/mapping/ActivityMapper.xml index 9ac5ef8..a499530 100644 --- a/src/main/resources/mapping/ActivityMapper.xml +++ b/src/main/resources/mapping/ActivityMapper.xml @@ -39,6 +39,7 @@ where activity_id=#{activityId} + @@ -54,6 +55,41 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mapping/UserMapper.xml b/src/main/resources/mapping/UserMapper.xml index 974bed7..5bf32b9 100644 --- a/src/main/resources/mapping/UserMapper.xml +++ b/src/main/resources/mapping/UserMapper.xml @@ -32,15 +32,14 @@ from user where user_id=#{targetUserId} - - + + + + +