Merge branch 'feature/bug-242' into develop

This commit is contained in:
曹鹏飞 2025-05-26 16:26:00 +08:00
commit 3858033f03
5 changed files with 80 additions and 25 deletions

View File

@ -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,16 +51,15 @@ 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())
@ -69,7 +73,28 @@ public class AppController extends ControllerBase {
.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"));
}
} }
///** ///**

View File

@ -96,7 +96,21 @@ public class UserController extends ControllerBase {
**/ **/
@GetMapping("getInfo") @GetMapping("getInfo")
public ApiResult<AppUserVO> getInfo(){ public ApiResult<AppUserVO> getInfo(){
if (StrUtil.equals(AppUserUtil.getFrom(), "app")) {
return ApiResult.success(appUserService.getInfo(AppUserUtil.getUserId())); 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;
} }
/** /**

View File

@ -15,4 +15,7 @@ public class AppLoginVO {
//语言编码 //语言编码
private String languageCode; private String languageCode;
//平台app或者admin
private String platform;
} }

View File

@ -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";
} }

View File

@ -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());