@ -3,14 +3,11 @@ package com.share.help.service;
import com.share.help.Util ;
import com.share.help.Util ;
import com.share.help.dao.UserMapper ;
import com.share.help.dao.UserMapper ;
import com.share.help.entity.UserEntity ;
import com.share.help.entity.UserEntity ;
import com.share.help.form.FindUserForm ;
import com.share.help.form.* ;
import com.share.help.form.UserLoginForm ;
import com.share.help.res.DefaultRes ;
import com.share.help.form.UserRegisterForm ;
import com.share.help.res.JSONResponse ;
import com.share.help.res.JSONResponse ;
import com.share.help.res.Result ;
import com.share.help.res.Result ;
import com.share.help.res.account.FindUserRes ;
import com.share.help.res.account.* ;
import com.share.help.res.account.LoginRes ;
import com.share.help.res.account.RegisterRes ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
@ -57,6 +54,7 @@ public class UserService{
String newPassword = DigestUtils . md5DigestAsHex ( userRegisterForm . getPassword ( ) . getBytes ( ) ) ;
String newPassword = DigestUtils . md5DigestAsHex ( userRegisterForm . getPassword ( ) . getBytes ( ) ) ;
userEntity . setPassword ( newPassword ) ;
userEntity . setPassword ( newPassword ) ;
userEntity . setName ( userRegisterForm . getName ( ) ) ;
userEntity . setName ( userRegisterForm . getName ( ) ) ;
userEntity . setAge ( userRegisterForm . getAge ( ) ) ;
userEntity . setSex ( userRegisterForm . getSex ( ) ) ;
userEntity . setSex ( userRegisterForm . getSex ( ) ) ;
//保存头像
//保存头像
String imageName = imageService . saveImg ( userRegisterForm . getImgFile ( ) ) ;
String imageName = imageService . saveImg ( userRegisterForm . getImgFile ( ) ) ;
@ -87,6 +85,11 @@ public class UserService{
: new JSONResponse < LoginRes . Res , LoginRes > ( LoginRes . Res . ok , Result . OK ) . setBody ( new LoginRes ( userEntity ) ) ;
: new JSONResponse < LoginRes . Res , LoginRes > ( LoginRes . Res . ok , Result . OK ) . setBody ( new LoginRes ( userEntity ) ) ;
}
}
/ * *
* 获取志愿者信息
* @param findUserForm 搜索条件表单
* @return 返回志愿者列表
* /
public JSONResponse < FindUserRes . Res , FindUserRes > find ( FindUserForm findUserForm ) {
public JSONResponse < FindUserRes . Res , FindUserRes > find ( FindUserForm findUserForm ) {
FindUserRes findUserRes = userMapper . count ( pageSize , findUserForm . getUserTypes ( ) , findUserForm . getInfo ( ) , findUserForm . getServiceAddress ( ) ) ;
FindUserRes findUserRes = userMapper . count ( pageSize , findUserForm . getUserTypes ( ) , findUserForm . getInfo ( ) , findUserForm . getServiceAddress ( ) ) ;
findUserRes . setPageSize ( pageSize ) ;
findUserRes . setPageSize ( pageSize ) ;
@ -100,4 +103,77 @@ public class UserService{
return new JSONResponse < > ( FindUserRes . Res . empty , Result . FAIL ) ;
return new JSONResponse < > ( FindUserRes . Res . empty , Result . FAIL ) ;
}
}
}
}
/ * *
* 获取用户个人信息
* @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 ( ) ) ;
return new JSONResponse < DefaultRes , QueryRes > ( DefaultRes . ok , Result . OK ) . setBody ( queryRes ) ;
} else {
return new JSONResponse < > ( DefaultRes . fail , Result . FAIL ) ;
}
}
/ * *
* 更新用户信息
* @param updateUserForm 用户id
* @return 返回更新结果
* /
public JSONResponse < DefaultRes , Void > update ( UpdateUserForm updateUserForm ) {
UserEntity userEntity = new UserEntity ( ) ;
userEntity . setUserId ( updateUserForm . getUserId ( ) ) ;
userEntity . setName ( updateUserForm . getName ( ) ) ;
userEntity . setHeadImg ( updateUserForm . getHeadImg ( ) ) ;
userEntity . setAddress ( updateUserForm . getAddress ( ) ) ;
userEntity . setServiceAddress ( updateUserForm . getServiceAddress ( ) ) ;
userEntity . setUserType ( updateUserForm . getUserType ( ) ) ;
userEntity . setMobile ( updateUserForm . getMobile ( ) ) ;
userEntity . setEmail ( updateUserForm . getEmail ( ) ) ;
userEntity . setInfo ( updateUserForm . getInfo ( ) ) ;
userEntity . setAge ( updateUserForm . getAge ( ) ) ;
userEntity . setSex ( updateUserForm . getSex ( ) ) ;
if ( userMapper . update ( userEntity ) ) {
return new JSONResponse < > ( DefaultRes . ok , Result . OK ) ;
} else {
return new JSONResponse < > ( DefaultRes . fail , Result . FAIL ) ;
}
}
/ * *
* 更新用户密码
* @param modifyPwdForm 更新密码表单
* @return 返回更新结果
* /
public JSONResponse < ModifyPwdRes , Void > update ( ModifyPwdForm modifyPwdForm ) {
UserEntity userEntity = userMapper . findOne ( modifyPwdForm . getUserId ( ) ) ;
if ( userEntity = = null ) {
return new JSONResponse < > ( ModifyPwdRes . fail , Result . FAIL ) ;
}
if ( DigestUtils . md5DigestAsHex ( modifyPwdForm . getOldPassword ( ) . getBytes ( ) ) . equals ( userEntity . getPassword ( ) ) ) {
userEntity . setPassword ( DigestUtils . md5DigestAsHex ( modifyPwdForm . getNewPassword ( ) . getBytes ( ) ) ) ;
if ( userMapper . update ( userEntity ) ) {
return new JSONResponse < > ( ModifyPwdRes . ok , Result . OK ) ;
} else {
return new JSONResponse < > ( ModifyPwdRes . fail , Result . FAIL ) ;
}
} else {
return new JSONResponse < > ( ModifyPwdRes . pwd_fail , Result . FAIL ) ;
}
}
}
}