|
|
@ -8,6 +8,7 @@ import a8k.dbservice.type.UsrRole; |
|
|
|
import a8k.type.appret.AppRet; |
|
|
|
import a8k.controler.extapi.utils.ExtApiFn; |
|
|
|
import a8k.hardware.type.a8kcanprotocol.A8kEcode; |
|
|
|
import a8k.type.exception.AppException; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
@ -44,16 +45,16 @@ public class AppUserMgrService { |
|
|
|
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
|
|
|
|
|
|
@ExtApiFn(name = "用户登录", order = ORDER.login) |
|
|
|
public AppRet<AppUser> login(String account, String password) { |
|
|
|
public AppUser login(String account, String password) throws AppException { |
|
|
|
var usr = appUsrDBService.getUsrByAccount(account); |
|
|
|
if (usr == null) |
|
|
|
return AppRet.fail(A8kEcode.UsrNotExitError.index); |
|
|
|
throw new AppException(A8kEcode.UsrNotExitError.index); |
|
|
|
|
|
|
|
if (!usr.password.equals(password)) { |
|
|
|
return AppRet.fail(A8kEcode.UsrPasswdError.index); |
|
|
|
throw new AppException(A8kEcode.UsrPasswdError.index); |
|
|
|
} |
|
|
|
loginUsr = usr; |
|
|
|
return AppRet.success(usr); |
|
|
|
return (usr); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "用户登出", order = ORDER.unlogin) |
|
|
@ -62,21 +63,21 @@ public class AppUserMgrService { |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "获取当前用户", order = ORDER.getLoginUsr) |
|
|
|
public AppRet<AppUser> getLoginUsr() { |
|
|
|
return AppRet.success(loginUsr); |
|
|
|
public AppUser getLoginUsr() { |
|
|
|
return (loginUsr); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "获取用户列表", order = ORDER.getUsrlist) |
|
|
|
public AppRet<List<AppUser>> getUsrlist() { |
|
|
|
return AppRet.success(appUsrDBService.getAllUsr()); |
|
|
|
public List<AppUser> getUsrlist() { |
|
|
|
return (appUsrDBService.getAllUsr()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ExtApiFn(name = "用户添加", order = ORDER.addUser) |
|
|
|
public AppRet<List<AppUser>> addUser(String account, String password, UsrRole type) { |
|
|
|
public List<AppUser> addUser(String account, String password, UsrRole type) throws AppException { |
|
|
|
var user = appUsrDBService.getUsrByAccount(account); |
|
|
|
if (user != null) { |
|
|
|
return AppRet.fail(A8kEcode.UsrAlreadyExistError.index); |
|
|
|
throw new AppException(A8kEcode.UsrAlreadyExistError.index); |
|
|
|
} |
|
|
|
user = new AppUser(account, password, type); |
|
|
|
appUsrDBService.addUser(user); |
|
|
@ -84,16 +85,16 @@ public class AppUserMgrService { |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "删除用户", order = ORDER.delUser) |
|
|
|
public AppRet<List<AppUser>> delUser(String account) { |
|
|
|
public List<AppUser> delUser(String account) { |
|
|
|
appUsrDBService.deleteUserByAccount(account); |
|
|
|
return getUsrlist(); |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "修改用户密码", order = ORDER.modifyUsrPwd) |
|
|
|
public AppRet<List<AppUser>> modifyUsrPwd(String account, String password) { |
|
|
|
public List<AppUser> modifyUsrPwd(String account, String password) throws AppException { |
|
|
|
var user = appUsrDBService.getUsrByAccount(account); |
|
|
|
if (user == null) { |
|
|
|
return AppRet.fail(A8kEcode.UsrNotExitError.index); |
|
|
|
throw new AppException(A8kEcode.UsrNotExitError.index); |
|
|
|
} |
|
|
|
user.password = password; |
|
|
|
appUsrDBService.updateUser(user); |
|
|
@ -101,10 +102,10 @@ public class AppUserMgrService { |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "修改用户权限", order = ORDER.modifyUsrRole) |
|
|
|
public AppRet<List<AppUser>> modifyUsrRole(String account, UsrRole usrRole) { |
|
|
|
public List<AppUser> modifyUsrRole(String account, UsrRole usrRole) throws AppException { |
|
|
|
var user = appUsrDBService.getUsrByAccount(account); |
|
|
|
if (user == null) { |
|
|
|
return AppRet.fail(A8kEcode.UsrNotExitError.index); |
|
|
|
throw new AppException(A8kEcode.UsrNotExitError.index); |
|
|
|
} |
|
|
|
user.usrRole = usrRole; |
|
|
|
appUsrDBService.updateUser(user); |
|
|
@ -112,10 +113,10 @@ public class AppUserMgrService { |
|
|
|
} |
|
|
|
|
|
|
|
@ExtApiFn(name = "修改用户名称", order = ORDER.modifyUsrAccount) |
|
|
|
public AppRet<List<AppUser>> modifyUsrAccount(String account, String newaccount) { |
|
|
|
public List<AppUser> modifyUsrAccount(String account, String newaccount) throws AppException { |
|
|
|
var user = appUsrDBService.getUsrByAccount(account); |
|
|
|
if (user == null) { |
|
|
|
return AppRet.fail(A8kEcode.UsrNotExitError.index); |
|
|
|
throw new AppException(A8kEcode.UsrNotExitError.index); |
|
|
|
} |
|
|
|
user.account = newaccount; |
|
|
|
appUsrDBService.updateUser(user); |
|
|
|