feat: bug-242 用户端登录添加管理端用户登录的支持
优先查询用户端的用户,如果不是用户端的用户,则查询管理端用户
This commit is contained in:
parent
b4ecf2f8f0
commit
fef078f783
|
|
@ -10,7 +10,9 @@ import com.nflg.mobilebroken.common.pojo.ApiResult;
|
||||||
import com.nflg.mobilebroken.common.pojo.vo.AppLoginVO;
|
import com.nflg.mobilebroken.common.pojo.vo.AppLoginVO;
|
||||||
import com.nflg.mobilebroken.common.util.SaTokenAppUtil;
|
import com.nflg.mobilebroken.common.util.SaTokenAppUtil;
|
||||||
import com.nflg.mobilebroken.common.util.VUtils;
|
import com.nflg.mobilebroken.common.util.VUtils;
|
||||||
|
import com.nflg.mobilebroken.repository.entity.AdminUser;
|
||||||
import com.nflg.mobilebroken.repository.entity.AppUser;
|
import com.nflg.mobilebroken.repository.entity.AppUser;
|
||||||
|
import com.nflg.mobilebroken.repository.service.IAdminUserService;
|
||||||
import com.nflg.mobilebroken.repository.service.IAppUserService;
|
import com.nflg.mobilebroken.repository.service.IAppUserService;
|
||||||
import com.nflg.mobilebroken.repository.service.IDictionaryItemTranslateService;
|
import com.nflg.mobilebroken.repository.service.IDictionaryItemTranslateService;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
|
@ -34,6 +36,9 @@ public class AppController extends ControllerBase {
|
||||||
@Resource
|
@Resource
|
||||||
private IAppUserService appUserService;
|
private IAppUserService appUserService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private IAdminUserService adminUserService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IDictionaryItemTranslateService dictionaryItemTranslateService;
|
private IDictionaryItemTranslateService dictionaryItemTranslateService;
|
||||||
|
|
||||||
|
|
@ -46,30 +51,50 @@ public class AppController extends ControllerBase {
|
||||||
@GetMapping("login")
|
@GetMapping("login")
|
||||||
public ApiResult<AppLoginVO> login(String userName, String password) {
|
public ApiResult<AppLoginVO> login(String userName, String password) {
|
||||||
AppUser user=appUserService.getUser(userName,password);
|
AppUser user=appUserService.getUser(userName,password);
|
||||||
VUtils.trueThrow(Objects.isNull(user))
|
if (Objects.nonNull(user)) {
|
||||||
.throwMessage(STATE.PassportErr,dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR,Constant.DICTIONARY_ITEM_INCORRECTUSERNAMEORPASSWORD,Constant.DEFAULT_LANGUAGE_CODE));
|
VUtils.trueThrow(Objects.equals(user.getState(), UserState.Disabled.getState()))
|
||||||
VUtils.trueThrow(Objects.equals(user.getState(), UserState.Disabled.getState()))
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_ACCOUNT_DISABLED, user.getLanguageCode()));
|
||||||
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR,Constant.DICTIONARY_ITEM_ACCOUNT_DISABLED,user.getLanguageCode()));
|
VUtils.trueThrow(Objects.equals(user.getState(), UserState.ToBeActivated.getState()))
|
||||||
VUtils.trueThrow(Objects.equals(user.getState(), UserState.ToBeActivated.getState()))
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_ACCOUNT_NOT_ACTIVATED, user.getLanguageCode()));
|
||||||
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR,Constant.DICTIONARY_ITEM_ACCOUNT_NOT_ACTIVATED,user.getLanguageCode()));
|
VUtils.trueThrow(user.getExpireTime().isBefore(ChronoLocalDate.from(LocalDateTime.now())) && user.getIsPrimary())
|
||||||
VUtils.trueThrow(user.getExpireTime().isBefore(ChronoLocalDate.from(LocalDateTime.now())) && user.getIsPrimary())
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_ACCOUNT_HAS_EXPIRED_PRIMARY, user.getLanguageCode()));
|
||||||
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR,Constant.DICTIONARY_ITEM_ACCOUNT_HAS_EXPIRED_PRIMARY,user.getLanguageCode()));
|
VUtils.trueThrow(user.getExpireTime().isBefore(ChronoLocalDate.from(LocalDateTime.now())) && !user.getIsPrimary())
|
||||||
VUtils.trueThrow(user.getExpireTime().isBefore(ChronoLocalDate.from(LocalDateTime.now())) && !user.getIsPrimary())
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_ACCOUNT_HAS_EXPIRED, user.getLanguageCode()));
|
||||||
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR,Constant.DICTIONARY_ITEM_ACCOUNT_HAS_EXPIRED,user.getLanguageCode()));
|
SaTokenAppUtil.login(user.getId(), SaLoginConfig
|
||||||
SaTokenAppUtil.login(user.getId(), SaLoginConfig
|
.setExtra("from", "app")
|
||||||
.setExtra("from", "app")
|
.setExtra("name", user.getName())
|
||||||
.setExtra("name", user.getName())
|
.setExtra("email", user.getEmail())
|
||||||
.setExtra("email", user.getEmail())
|
.setExtra("companyIds", StrUtil.split(user.getCompanyId(), ",").stream().map(Integer::valueOf).collect(Collectors.toList()))
|
||||||
.setExtra("companyIds", StrUtil.split(user.getCompanyId(), ",").stream().map(Integer::valueOf).collect(Collectors.toList()))
|
.setExtra("isPrimary", user.getIsPrimary()));
|
||||||
.setExtra("isPrimary", user.getIsPrimary()));
|
user.setLastLoginTime(LocalDateTime.now());
|
||||||
user.setLastLoginTime(LocalDateTime.now());
|
appUserService.updateById(user);
|
||||||
appUserService.updateById(user);
|
SaTokenInfo tokenInfo = SaTokenAppUtil.getTokenInfo();
|
||||||
SaTokenInfo tokenInfo = SaTokenAppUtil.getTokenInfo();
|
return ApiResult.success(new AppLoginVO()
|
||||||
return ApiResult.success(new AppLoginVO()
|
.setUserId(user.getId())
|
||||||
.setUserId(user.getId())
|
.setToken(tokenInfo.getTokenValue())
|
||||||
.setToken(tokenInfo.getTokenValue())
|
.setExpire(tokenInfo.getTokenTimeout())
|
||||||
.setExpire(tokenInfo.getTokenTimeout())
|
.setLanguageCode(user.getLanguageCode())
|
||||||
.setLanguageCode(user.getLanguageCode()));
|
.setPlatform("app"));
|
||||||
|
}else {
|
||||||
|
AdminUser adminUser =adminUserService.getUser(userName,password);
|
||||||
|
VUtils.trueThrow(Objects.isNull(adminUser))
|
||||||
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_INCORRECTUSERNAMEORPASSWORD, Constant.DEFAULT_LANGUAGE_CODE));
|
||||||
|
VUtils.trueThrow(Objects.equals(adminUser.getState(), UserState.Disabled.getState()))
|
||||||
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_ACCOUNT_DISABLED, Constant.DEFAULT_LANGUAGE_CODE));
|
||||||
|
VUtils.trueThrow(Objects.equals(adminUser.getState(), UserState.ToBeActivated.getState()))
|
||||||
|
.throwMessage(STATE.PassportErr, dictionaryItemTranslateService.getValueByCode(Constant.DICTIONARY_SYSTEMERROR, Constant.DICTIONARY_ITEM_ACCOUNT_HAS_EXPIRED, Constant.DEFAULT_LANGUAGE_CODE));
|
||||||
|
SaTokenAppUtil.login(adminUser.getId(), SaLoginConfig
|
||||||
|
.setExtra("from", "admin")
|
||||||
|
.setExtra("name", adminUser.getUserName())
|
||||||
|
.setExtra("email", adminUser.getEmail()));
|
||||||
|
SaTokenInfo tokenInfo = SaTokenAppUtil.getTokenInfo();
|
||||||
|
return ApiResult.success(new AppLoginVO()
|
||||||
|
.setUserId(adminUser.getId())
|
||||||
|
.setToken(tokenInfo.getTokenValue())
|
||||||
|
.setExpire(tokenInfo.getTokenTimeout())
|
||||||
|
.setLanguageCode(Constant.DEFAULT_LANGUAGE_CODE)
|
||||||
|
.setPlatform("admin"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
///**
|
///**
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,21 @@ public class UserController extends ControllerBase {
|
||||||
**/
|
**/
|
||||||
@GetMapping("getInfo")
|
@GetMapping("getInfo")
|
||||||
public ApiResult<AppUserVO> getInfo(){
|
public ApiResult<AppUserVO> getInfo(){
|
||||||
return ApiResult.success(appUserService.getInfo(AppUserUtil.getUserId()));
|
if (StrUtil.equals(AppUserUtil.getFrom(), "app")) {
|
||||||
|
return ApiResult.success(appUserService.getInfo(AppUserUtil.getUserId()));
|
||||||
|
} else if (StrUtil.equals(AppUserUtil.getFrom(), "admin")) {
|
||||||
|
AdminUserVO adminUser = adminUserService.getInfo(AppUserUtil.getUserId());
|
||||||
|
return ApiResult.success(new AppUserVO()
|
||||||
|
.setId(adminUser.getId())
|
||||||
|
.setName(adminUser.getUserName())
|
||||||
|
.setLoginName(adminUser.getLoginName())
|
||||||
|
.setEmail(adminUser.getEmail())
|
||||||
|
.setAvatar(adminUser.getAvatar())
|
||||||
|
.setPhone(adminUser.getPhone())
|
||||||
|
.setPlatform("admin"));
|
||||||
|
}
|
||||||
|
VUtils.trueThrowBusinessError(true).throwMessage("不支持的平台:" + AppUserUtil.getFrom());
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,7 @@ public class AppLoginVO {
|
||||||
|
|
||||||
//语言编码
|
//语言编码
|
||||||
private String languageCode;
|
private String languageCode;
|
||||||
|
|
||||||
|
//平台,app或者admin
|
||||||
|
private String platform;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,15 +71,20 @@ public class AppUserVO {
|
||||||
|
|
||||||
//公司id列表
|
//公司id列表
|
||||||
public List<Integer> companyIds;
|
public List<Integer> companyIds;
|
||||||
|
|
||||||
//手机号
|
//手机号
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
//职位
|
//职位
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
//职位id
|
//职位id
|
||||||
private Integer titleId;
|
private Integer titleId;
|
||||||
|
|
||||||
//公司id
|
//公司id
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
private String companyId;
|
private String companyId;
|
||||||
|
|
||||||
//公司id
|
//公司id
|
||||||
private Integer companyId1;
|
private Integer companyId1;
|
||||||
|
|
||||||
|
|
@ -98,4 +103,7 @@ public class AppUserVO {
|
||||||
* 语言编码
|
* 语言编码
|
||||||
*/
|
*/
|
||||||
private String languageCode;
|
private String languageCode;
|
||||||
|
|
||||||
|
//平台,app或者admin
|
||||||
|
private String platform="app";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,11 @@ public class AppUserUtil {
|
||||||
return (Boolean) SaTokenAppUtil.getExtra("isPrimary");
|
return (Boolean) SaTokenAppUtil.getExtra("isPrimary");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFrom() {
|
||||||
|
VUtils.trueThrow(!SaTokenAppUtil.isLogin()).throwMessage(STATE.LoginError,"请重新登录");
|
||||||
|
return (String) SaTokenAppUtil.getExtra("from");
|
||||||
|
}
|
||||||
|
|
||||||
public static UserDTO getUser() {
|
public static UserDTO getUser() {
|
||||||
UserDTO user = new UserDTO();
|
UserDTO user = new UserDTO();
|
||||||
user.setId(getUserId());
|
user.setId(getUserId());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue