查询用户分页
This commit is contained in:
parent
eea01eab93
commit
00103fdff5
|
|
@ -50,8 +50,8 @@ public class UserController {
|
|||
}
|
||||
|
||||
@ApiOperation(value = "查询用户信息", notes = "")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
public ElectromagneticResult<?> searchUser(SearchUserRequest searchUserRequest) {
|
||||
@RequestMapping(value = "/list", method = RequestMethod.POST)
|
||||
public ElectromagneticResult<?> searchUser(@RequestBody SearchUserRequest searchUserRequest) {
|
||||
return userFacade.searchUser(searchUserRequest);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
response.setStatus(401);
|
||||
return false;
|
||||
} else {
|
||||
token = token.substring(7);
|
||||
//token = token.substring(7);
|
||||
}
|
||||
boolean result = tokenService.isTokenValid(token.substring(7));
|
||||
if (!result) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ public class SearchKeyWords {
|
|||
/**
|
||||
* 用户发布状态
|
||||
*/
|
||||
private int isPublished;
|
||||
private String isPublished;
|
||||
|
||||
/**
|
||||
* 排序方式: "asc" 或 "desc" 或 “”
|
||||
|
|
@ -33,4 +33,14 @@ public class SearchKeyWords {
|
|||
* 排序方式: "asc" 或 "desc" 或 “”
|
||||
*/
|
||||
private String internEndDate;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
private int pageIndex;
|
||||
|
||||
/**
|
||||
* 单页条目数量
|
||||
*/
|
||||
private int pageSize;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,13 @@ public interface UserRepository {
|
|||
*/
|
||||
List<User> search(SearchKeyWords searchKeyWords);
|
||||
|
||||
/**
|
||||
* 查询数据总条目数
|
||||
* @param searchKeywords
|
||||
* @return
|
||||
*/
|
||||
int getTotalCount (SearchKeyWords searchKeywords);
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param userId
|
||||
|
|
|
|||
|
|
@ -58,6 +58,13 @@ public interface UserService {
|
|||
*/
|
||||
List<User> searchUser(SearchKeyWords searchKeyWords);
|
||||
|
||||
/**
|
||||
* 查询数据总条目数
|
||||
* @param searchKeywords
|
||||
* @return
|
||||
*/
|
||||
int getTotalCount (SearchKeyWords searchKeywords);
|
||||
|
||||
/**
|
||||
* 根据userId逻辑删除用户
|
||||
* @param userId
|
||||
|
|
|
|||
|
|
@ -89,6 +89,16 @@ public class UserServiceImpl implements UserService {
|
|||
@Override
|
||||
public List<User> searchUser(SearchKeyWords searchKeyWords) { return userRepository.search(searchKeyWords); }
|
||||
|
||||
/**
|
||||
* 查询数据总条目数
|
||||
* @param searchKeywords
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getTotalCount (SearchKeyWords searchKeywords) {
|
||||
return userRepository.getTotalCount(searchKeywords);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据userId逻辑删除用户
|
||||
*
|
||||
|
|
|
|||
|
|
@ -22,19 +22,10 @@ public class SearchUserRequest extends BaseRequest implements Serializable {
|
|||
private String userStatus;
|
||||
|
||||
/**
|
||||
* 用户发布状态
|
||||
* 用户发布状态,1已发布,0未发布
|
||||
*/
|
||||
private int isPublished;
|
||||
private String isPublished;
|
||||
|
||||
// /**
|
||||
// * 排序字段: "gmtCreate", "joinTime", "internEndDate"
|
||||
// */
|
||||
// private String sortBy;
|
||||
//
|
||||
// /**
|
||||
// * 排序方式: "asc" 或 "desc"
|
||||
// */
|
||||
// private String sortOrder;
|
||||
/**
|
||||
* 排序方式: "asc" 或 "desc" 或 “”
|
||||
*/
|
||||
|
|
@ -49,4 +40,14 @@ public class SearchUserRequest extends BaseRequest implements Serializable {
|
|||
* 排序方式: "asc" 或 "desc" 或 “”
|
||||
*/
|
||||
private String internEndDate;
|
||||
|
||||
/**
|
||||
* 页码
|
||||
*/
|
||||
private int pageIndex;
|
||||
|
||||
/**
|
||||
* 单页条目数量
|
||||
*/
|
||||
private int pageSize;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,6 @@ public class UserModiRequest extends BaseRequest implements Serializable {
|
|||
*/
|
||||
private String userName;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 工号
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,13 +1,8 @@
|
|||
package com.electromagnetic.industry.software.data.manage.response.user;
|
||||
|
||||
import com.electromagnetic.industry.software.data.manage.response.indicator.IndicatorCardResponse;
|
||||
import com.electromagnetic.industry.software.data.manage.response.indicator.IndicatorResponse;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class SingleUserResponse {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
package com.electromagnetic.industry.software.data.manage.response.user;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class UserLoginResponse implements Serializable {
|
||||
|
||||
private String token;
|
||||
|
||||
private String userId;
|
||||
}
|
||||
|
|
@ -22,5 +22,10 @@ public class UserSearchResponse implements Serializable {
|
|||
* 用户列表
|
||||
*/
|
||||
private List<SingleUserResponse> userList;
|
||||
//private List<User> userList;
|
||||
|
||||
|
||||
/**
|
||||
* 总数据数
|
||||
*/
|
||||
private long totalCount;
|
||||
}
|
||||
|
|
@ -50,6 +50,13 @@ public interface UserMapper {
|
|||
*/
|
||||
List<User> search(SearchKeyWords searchKeywords);
|
||||
|
||||
/**
|
||||
* 查询数据总条目数
|
||||
* @param searchKeywords
|
||||
* @return
|
||||
*/
|
||||
int getTotalCount (SearchKeyWords searchKeywords);
|
||||
|
||||
/**
|
||||
* 通过用户ID删除用户
|
||||
* @param userId
|
||||
|
|
|
|||
|
|
@ -81,6 +81,14 @@ public class UserRepositoryImpl implements UserRepository {
|
|||
return userMapper.search(searchKeywords);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据总条目数
|
||||
* @param searchKeywords
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public int getTotalCount (SearchKeyWords searchKeywords) {return userMapper.getTotalCount(searchKeywords);}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param userId
|
||||
|
|
|
|||
|
|
@ -116,6 +116,49 @@
|
|||
</choose>
|
||||
</if>
|
||||
|
||||
<!-- 条件 3:按发布状态搜索 -->
|
||||
<if test="isPublished != null and isPublished != ''">
|
||||
<choose>
|
||||
<when test="isPublished != 'all'">
|
||||
AND is_published = CAST(#{isPublished} AS INT)
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
</where>
|
||||
|
||||
<!-- 动态排序条件 -->
|
||||
<choose>
|
||||
<when test="gmtCreate == 'asc' or gmtCreate == 'desc'">
|
||||
ORDER BY gmt_create ${gmtCreate}
|
||||
</when>
|
||||
<when test="joinTime == 'asc' or joinTime == 'desc'">
|
||||
ORDER BY join_time ${joinTime}
|
||||
</when>
|
||||
<when test="internEndDate == 'asc' or internEndDate == 'desc'">
|
||||
ORDER BY internship_end_date ${internEndDate}
|
||||
</when>
|
||||
</choose>
|
||||
LIMIT #{pageSize} OFFSET #{pageIndex}
|
||||
</select>
|
||||
|
||||
<select id="getTotalCount" parameterType="com.electromagnetic.industry.software.data.manage.domain.boardservice.user.params.SearchKeyWords" resultType="Integer">
|
||||
SELECT COUNT(*)
|
||||
FROM ed_users
|
||||
<where>
|
||||
<!-- 条件 1:按用户名或工号搜索 -->
|
||||
<if test="keyWord != null and keyWord != ''">
|
||||
(user_name LIKE CONCAT('%', #{keyWord}, '%') OR work_number LIKE CONCAT('%', #{keyWord}, '%'))
|
||||
</if>
|
||||
|
||||
<!-- 条件 2:按用户状态搜索 -->
|
||||
<if test="userStatus != null and userStatus != ''">
|
||||
<choose>
|
||||
<when test="userStatus != 'all'">
|
||||
AND user_status = #{userStatus}
|
||||
</when>
|
||||
</choose>
|
||||
</if>
|
||||
|
||||
<!-- 条件 3:按发布状态搜索 -->
|
||||
<if test="isPublished != null and isPublished != ''">
|
||||
<choose>
|
||||
|
|
@ -140,7 +183,6 @@
|
|||
</choose>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectUserByWorkNumber" parameterType="String" resultMap="UserResultMap">
|
||||
<include refid="selectUserVo" />
|
||||
where work_number = #{workNumber}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.electromagnetic.industry.software.data.manage.service.facade.user;
|
|||
import com.electromagnetic.industry.software.data.manage.common.ElectromagneticErrorEnum;
|
||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.model.User;
|
||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.model.UserLoginInfo;
|
||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.params.SearchKeyWords;
|
||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.TokenService;
|
||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.service.UserService;
|
||||
import com.electromagnetic.industry.software.data.manage.domain.boardservice.user.util.UserConstant;
|
||||
|
|
@ -13,8 +14,10 @@ import com.electromagnetic.industry.software.data.manage.request.user.UserPublis
|
|||
import com.electromagnetic.industry.software.data.manage.request.user.UserLoginRequest;
|
||||
import com.electromagnetic.industry.software.data.manage.request.user.UserRequest;
|
||||
import com.electromagnetic.industry.software.data.manage.response.user.SingleUserResponse;
|
||||
import com.electromagnetic.industry.software.data.manage.response.user.UserLoginResponse;
|
||||
import com.electromagnetic.industry.software.data.manage.response.user.UserSearchResponse;
|
||||
import com.electromagnetic.industry.software.data.manage.service.mappers.UserMappers;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import electromagnetic.data.framework.share.id.IdWorker;
|
||||
import electromagnetic.data.framework.share.model.ElectromagneticResult;
|
||||
import electromagnetic.data.framework.share.model.ElectromagneticResultUtil;
|
||||
|
|
@ -40,14 +43,17 @@ public class UserFacadeImpl implements UserFacade {
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public ElectromagneticResult<String> login(UserLoginRequest loginRequest) {
|
||||
public ElectromagneticResult<UserLoginResponse> login(UserLoginRequest loginRequest) {
|
||||
UserLoginInfo info = UserMappers.INSTANCE.getUserLoginRequestToModel(loginRequest);
|
||||
String decodePwd = AESUtils.decrypt(info.getUserPwd(), UserConstant.SECRET_KEY);
|
||||
User user = userService.getUserByWorkNumber(info.getWorkNumber());
|
||||
if ( user!=null && userService.matchPassword(user, decodePwd)) {
|
||||
String tokenStr = tokenService.createToken(info);
|
||||
tokenService.createUserToken(user, tokenStr);
|
||||
return ElectromagneticResultUtil.success(tokenStr);
|
||||
UserLoginResponse userLoginResponse = new UserLoginResponse();
|
||||
userLoginResponse.setToken(tokenStr);
|
||||
userLoginResponse.setUserId(user.getUserId());
|
||||
return ElectromagneticResultUtil.success(userLoginResponse);
|
||||
}
|
||||
return ElectromagneticResultUtil.fail("500","用户不存在/密码错误");
|
||||
}
|
||||
|
|
@ -126,10 +132,14 @@ public class UserFacadeImpl implements UserFacade {
|
|||
*/
|
||||
@Override
|
||||
public ElectromagneticResult<UserSearchResponse> searchUser(SearchUserRequest searchUserRequest){
|
||||
List<User> userList = userService.searchUser(UserMappers.INSTANCE.getSearchKeywordsRequestToModel(searchUserRequest));
|
||||
searchUserRequest.setPageIndex((searchUserRequest.getPageIndex()-1)*searchUserRequest.getPageSize());
|
||||
SearchKeyWords model = UserMappers.INSTANCE.getSearchKeywordsRequestToModel(searchUserRequest);
|
||||
List<User> userList = userService.searchUser(model);
|
||||
int totalCount = userService.getTotalCount(model);
|
||||
List<SingleUserResponse> singleUserResponseList = UserMappers.INSTANCE.userListToResponseList(userList);
|
||||
UserSearchResponse userSearchResponse = new UserSearchResponse();
|
||||
userSearchResponse.setUserList(singleUserResponseList);
|
||||
userSearchResponse.setTotalCount(totalCount);
|
||||
return ElectromagneticResultUtil.success(userSearchResponse);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue