20 changed files with 344 additions and 209 deletions
-
63src/main/java/a8k/appbase/appret/AppRet.java
-
8src/main/java/a8k/appbase/appret/AppRetType.java
-
23src/main/java/a8k/appbase/ecode/AppRetEcodeInfo.java
-
2src/main/java/a8k/controler/A8kExceptionProcesser.java
-
2src/main/java/a8k/controler/engineer/EngineerPageControler.java
-
44src/main/java/a8k/db/AppUser.java
-
51src/main/java/a8k/db/MdbUser.java
-
2src/main/java/a8k/service/ctrl_service/DeviceInitializationCtrlService.java
-
2src/main/java/a8k/service/hardware/CommonHardwareOpeartion.java
-
2src/main/java/a8k/service/hardware/HbotControlService.java
-
2src/main/java/a8k/service/hardware/MotorTubeRackMoveCtrlService.java
-
2src/main/java/a8k/service/hardware/ReactionPlatesTransmitCtrlService.java
-
2src/main/java/a8k/service/hardware/SamplesPreProcessModuleCtrlService.java
-
2src/main/java/a8k/service/hardware/TestScript.java
-
6src/main/java/a8k/service/hardware/canbus/protocol/A8kEcode.java
-
8src/main/java/a8k/service/state_service/A8kStateMgrService.java
-
107src/main/java/a8k/service/usermgr/AppUserMgrService.java
-
9src/main/resources/db/migration/V100_3__create_table_AppUserTable.sql
-
BINzhaohe_app.db
@ -0,0 +1,8 @@ |
|||
package a8k.appbase.appret; |
|||
|
|||
public enum AppRetType { |
|||
NORMAL, |
|||
FAILURE, |
|||
RECONFIRM, |
|||
MESSAGE, |
|||
} |
@ -0,0 +1,44 @@ |
|||
package a8k.db; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.iflytop.uf.UfActiveRecord; |
|||
import com.iflytop.uf.UfActiveRecordField; |
|||
|
|||
public class AppUser extends UfActiveRecord { |
|||
@UfActiveRecordField |
|||
public String account; |
|||
|
|||
@JsonIgnore |
|||
@UfActiveRecordField |
|||
public String password = ""; |
|||
|
|||
@UfActiveRecordField |
|||
public Integer isAdmin = 0; |
|||
|
|||
@UfActiveRecordField |
|||
public Integer isBuiltInUser = 0; |
|||
|
|||
// get table name |
|||
public static String getTableName() { |
|||
return "AppUser" + "Table"; |
|||
} |
|||
|
|||
// check if password matches |
|||
public Boolean matchPassword(String password) { |
|||
return this.password.equals(password); |
|||
} |
|||
|
|||
public Boolean isAdmin() { |
|||
if (isAdmin == null) { |
|||
return false; |
|||
} |
|||
return isAdmin != 0; |
|||
} |
|||
|
|||
public Boolean isBuiltInUser() { |
|||
if (isBuiltInUser == null) { |
|||
return false; |
|||
} |
|||
return isBuiltInUser != 0; |
|||
} |
|||
} |
@ -1,51 +0,0 @@ |
|||
package a8k.db; |
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.iflytop.uf.UfActiveRecord; |
|||
import com.iflytop.uf.UfActiveRecordField; |
|||
import org.springframework.util.DigestUtils; |
|||
public class MdbUser extends UfActiveRecord { |
|||
@UfActiveRecordField |
|||
public String account; |
|||
|
|||
@JsonIgnore |
|||
@UfActiveRecordField |
|||
public String password; |
|||
|
|||
@JsonIgnore |
|||
@UfActiveRecordField |
|||
public String salt; |
|||
|
|||
@UfActiveRecordField |
|||
public Integer isAdmin; |
|||
|
|||
@UfActiveRecordField |
|||
public Integer createdAt; |
|||
|
|||
@UfActiveRecordField |
|||
public String createdBy; |
|||
|
|||
@JsonIgnore |
|||
@UfActiveRecordField |
|||
public String accessToken; |
|||
|
|||
@JsonIgnore |
|||
@UfActiveRecordField |
|||
public Integer accessTokenExpiredAt; |
|||
|
|||
// get table name |
|||
public static String getTableName() { |
|||
return "app_users"; |
|||
} |
|||
|
|||
// check if password matches |
|||
public Boolean matchPassword(String password) { |
|||
String hash = this.hashPassword(password); |
|||
return this.password.equals(hash); |
|||
} |
|||
|
|||
// hash password |
|||
public String hashPassword(String password) { |
|||
String salt = this.salt; |
|||
return DigestUtils.md5DigestAsHex((salt + password + salt).getBytes()); |
|||
} |
|||
} |
@ -0,0 +1,107 @@ |
|||
package a8k.service.usermgr; |
|||
|
|||
import a8k.appbase.appret.AppRet; |
|||
import a8k.db.AppUser; |
|||
import a8k.service.hardware.canbus.protocol.A8kEcode; |
|||
import com.iflytop.uf.UfActiveRecord; |
|||
import jakarta.annotation.PostConstruct; |
|||
import org.slf4j.Logger; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
@Component |
|||
public class AppUserMgrService { |
|||
static Logger logger = org.slf4j.LoggerFactory.getLogger(AppUserMgrService.class); |
|||
|
|||
AppUser loginUsr; |
|||
|
|||
@PostConstruct |
|||
public void init() { |
|||
logger.info("UserMgrService init"); |
|||
AppUser admin = getUser("管理员"); |
|||
if (admin == null) { |
|||
admin = new AppUser(); |
|||
admin.account = "管理员"; |
|||
admin.password = "0000"; |
|||
admin.isAdmin = 1; |
|||
admin.isBuiltInUser = 1; |
|||
admin.save(); |
|||
} |
|||
|
|||
} |
|||
|
|||
List<AppUser> getUserList() { |
|||
return UfActiveRecord.find(AppUser.class); |
|||
} |
|||
|
|||
AppUser getUser(String account) { |
|||
return UfActiveRecord.findOne(AppUser.class, Map.of("account", account)); |
|||
} |
|||
|
|||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|||
// EXT FUNC |
|||
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
|||
|
|||
public AppRet<AppUser> login(String account, String password) { |
|||
var user = getUser(account); |
|||
if (user == null) { |
|||
return AppRet.fail(A8kEcode.UsrNotExitError); |
|||
} |
|||
if (!user.matchPassword(password)) { |
|||
return AppRet.fail(A8kEcode.PasswdError); |
|||
} |
|||
loginUsr = user; |
|||
return AppRet.success(user); |
|||
} |
|||
|
|||
public AppRet<AppUser> getLoginUsr() { |
|||
return AppRet.success(loginUsr); |
|||
} |
|||
|
|||
public AppRet<List<AppUser>> loginList() { |
|||
return AppRet.success(getUserList()); |
|||
} |
|||
|
|||
public AppRet<AppUser> addUser(String account, String password, int isAdmin) { |
|||
if (getUser(account) != null) { |
|||
return AppRet.fail(A8kEcode.UsrExistError); |
|||
} |
|||
var user = new AppUser(); |
|||
user.account = account; |
|||
user.password = password; |
|||
user.isAdmin = isAdmin; |
|||
user.save(); |
|||
return AppRet.success(user); |
|||
} |
|||
|
|||
public AppRet<AppUser> delUser(String account) { |
|||
var user = getUser(account); |
|||
if (user == null) { |
|||
return AppRet.fail(A8kEcode.UsrNotExitError); |
|||
} |
|||
if (user.isBuiltInUser == 1) { |
|||
return AppRet.fail(A8kEcode.UsrNotAllowBeDeleted); |
|||
} |
|||
user.delete(); |
|||
return AppRet.success(user); |
|||
} |
|||
|
|||
public AppRet<AppUser> modifyUser(String account, String password, int isAdmin) { |
|||
var user = getUser(account); |
|||
if (user == null) { |
|||
return AppRet.fail(A8kEcode.UsrNotExitError); |
|||
} |
|||
user.password = password; |
|||
user.isAdmin = isAdmin; |
|||
user.save(); |
|||
return AppRet.success(user); |
|||
} |
|||
|
|||
public AppRet<AppUser> getLoginUsrInfo() { |
|||
return AppRet.success(loginUsr); |
|||
} |
|||
|
|||
|
|||
} |
@ -0,0 +1,9 @@ |
|||
CREATE TABLE "AppUserTable" |
|||
( |
|||
"id" text NOT NULL, |
|||
"account" text, |
|||
"password" text, |
|||
"isAdmin" integer, |
|||
"isBuiltInUser" integer, |
|||
PRIMARY KEY ("id") |
|||
); |
Write
Preview
Loading…
Cancel
Save
Reference in new issue