parent
bcfe945b1f
commit
a1145dec7d
@ -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);
|
||||
// }
|
||||
// }
|
||||
} |
@ -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(",")); |
||||
} |
||||
} |
||||
} |
@ -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 |
||||
} |
||||
} |
@ -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{
|
||||
//
|
||||
// }
|
||||
// }
|
||||
} |
Loading…
Reference in new issue