@ -1,18 +1,23 @@
package com.share.help.service ;
import com.share.help.Util ;
import com.share.help.dao.FriendMapper ;
import com.share.help.dao.UserMapper ;
import com.share.help.entity.UserEntity ;
import com.share.help.entity.custorm.FindUserRes ;
import com.share.help.entity.custorm.Friend ;
import com.share.help.entity.custorm.UserWithName ;
import com.share.help.form.* ;
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 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 ;
@ -34,14 +39,22 @@ public class UserService{
//用户分页配置
@Value ( "${page-size.user.page-size}" )
private int p ageSize;
private int userP ageSize;
@Value ( "${page-size.user.row-size}" )
private int rowSize ;
private int use rR owSize;
@Autowired
private ImageService imageService ;
@Autowired
private FriendMapper friendMapper ;
@Value ( "${page-size.friend}" )
private int friendSize ;
private Logger logger = LoggerFactory . getLogger ( UserService . class ) ;
/ * *
* 注册
* @param userRegisterForm 注册表单
@ -64,6 +77,7 @@ public class UserService{
//保存头像
String imageName = imageService . saveImg ( userRegisterForm . getImgFile ( ) ) ;
if ( imageName = = null ) {
logger . error ( "保存头像失败" ) ;
return new JSONResponse < > ( RegisterRes . fail , Result . FAIL ) ;
}
userEntity . setHeadImg ( imageName ) ;
@ -96,13 +110,13 @@ public class UserService{
* @return 返回志愿者列表
* /
public JSONResponse < FindUserRes . Res , FindUserRes > find ( FindUserForm findUserForm ) {
FindUserRes findUserRes = userMapper . count ( p ageSize, findUserForm . getUserTypes ( ) , findUserForm . getInfo ( ) , findUserForm . getServiceAddress ( ) ) ;
findUserRes . setPageSize ( p ageSize) ;
FindUserRes findUserRes = userMapper . count ( userP ageSize, findUserForm . getUserTypes ( ) , findUserForm . getInfo ( ) , findUserForm . getServiceAddress ( ) ) ;
findUserRes . setPageSize ( userP ageSize) ;
findUserRes . setCurrentPage ( findUserForm . getCurrentPage ( ) ) ;
List < UserEntity > userEntityList = userMapper . getPage ( ( findUserForm . getCurrentPage ( ) - 1 ) * pageSize , p ageSize, findUserForm . getUserTypes ( ) ,
List < UserEntity > userEntityList = userMapper . getPage ( ( findUserForm . getCurrentPage ( ) - 1 ) * userPageSize , userP ageSize , findUserForm . getUserTypes ( ) ,
findUserForm . getInfo ( ) , findUserForm . getServiceAddress ( ) ) ;
if ( ! userEntityList . isEmpty ( ) ) {
findUserRes . setBody ( Util . splitList ( UserEntity . class , userEntityList , rowSize ) ) ;
findUserRes . setBody ( Util . splitList ( UserEntity . class , userEntityList , use rR owSize) ) ;
return new JSONResponse < FindUserRes . Res , FindUserRes > ( FindUserRes . Res . ok , Result . OK ) . setBody ( findUserRes ) ;
} else {
return new JSONResponse < > ( FindUserRes . Res . empty , Result . OK ) ;
@ -111,23 +125,14 @@ public class UserService{
/ * *
* 获取用户个人信息
*
* @param targetUserId 目标用户
* @param userId 用户id
* @return 返回用户信息
* /
public JSONResponse < DefaultRes , QueryRes > find ( String userId ) {
UserEntity userEntity = userMapper . findOne ( userId ) ;
if ( userEntity ! = null ) {
QueryRes queryRes = new QueryRes ( ) ;
queryRes . setUserId ( userEntity . getUserId ( ) ) ;
queryRes . setHeadImg ( userEntity . getHeadImg ( ) ) ;
queryRes . setName ( userEntity . getName ( ) ) ;
queryRes . setAge ( userEntity . getAge ( ) ) ;
queryRes . setMobile ( userEntity . getMobile ( ) ) ;
queryRes . setEmail ( userEntity . getEmail ( ) ) ;
queryRes . setServiceAddress ( userEntity . getServiceAddress ( ) ) ;
queryRes . setInfo ( userEntity . getInfo ( ) ) ;
queryRes . setUserType ( userEntity . getUserType ( ) ) ;
queryRes . setSex ( userEntity . getSex ( ) ) ;
public JSONResponse < DefaultRes , QueryRes > find ( String targetUserId , String userId ) {
QueryRes queryRes = userMapper . findInfo ( targetUserId , userId ) ;
if ( queryRes ! = null ) {
return new JSONResponse < DefaultRes , QueryRes > ( DefaultRes . ok , Result . OK ) . setBody ( queryRes ) ;
} else {
return new JSONResponse < > ( DefaultRes . fail , Result . FAIL ) ;
@ -187,9 +192,40 @@ public class UserService{
* @param queryUserForm 搜索条件
* @return 返回查询结果
* /
public JSONResponse < DefaultRes , List < UserWithName > > queryUser ( QueryUserForm queryUserForm ) {
List < UserWithName > userWithNameList = userMapper . queryUser ( queryUserForm . getUserName ( ) , queryUserForm . getInfo ( ) ) ;
return new JSONResponse < DefaultRes , List < UserWithName > > ( DefaultRes . ok , Result . OK ) . setBody ( userWithNameList ) ;
public JSONResponse < DefaultRes , Page < List < UserWithName > > > queryUser ( QueryUserForm queryUserForm ) {
Page < List < UserWithName > > page = userMapper . countUser ( queryUserForm . getName ( ) , queryUserForm . getInfo ( ) , queryUserForm . getUserId ( ) , userPageSize ) ;
List < UserWithName > userWithNameList = userMapper . queryUser ( queryUserForm . getName ( ) , queryUserForm . getInfo ( ) , queryUserForm . getUserId ( ) ) ;
page . setBody ( userWithNameList ) ;
return new JSONResponse < DefaultRes , Page < List < UserWithName > > > ( DefaultRes . ok , Result . OK ) . setBody ( page ) ;
}
/ * *
* 检索好友表单
* @param searchFrom 检索条件
* @return 返回好友列表
* /
public JSONResponse < DefaultRes , Page < List < Friend > > > searchFriend ( SearchFrom searchFrom ) {
Page < List < Friend > > page = friendMapper . count ( searchFrom . getUserId ( ) , friendSize ) ;
List < Friend > list = friendMapper . getFriend ( searchFrom . getUserId ( ) , ( searchFrom . getCurrentPage ( ) - 1 ) * friendSize , friendSize ) ;
page . setBody ( list ) ;
return new JSONResponse < DefaultRes , Page < List < Friend > > > ( DefaultRes . ok , Result . OK ) . setBody ( page ) ;
}
/ * *
* 刷新聊天状态
* @param chatForm 表单
* @return 返回刷新结果
* /
public JSONResponse < DefaultRes , Void > changeChat ( ChatForm chatForm ) {
UserEntity userEntity = userMapper . findOne ( chatForm . getUserId ( ) ) ;
if ( userEntity = = null ) {
return new JSONResponse < > ( DefaultRes . fail , Result . FAIL ) ;
}
userEntity . setChatStatus ( chatForm . getChatStatus ( ) ) ;
if ( userMapper . update ( userEntity ) ) {
return new JSONResponse < > ( DefaultRes . ok , Result . OK ) ;
} else {
return new JSONResponse < > ( DefaultRes . fail , Result . FAIL ) ;
}
}
}