feat: add Flutter mobile clients and staff delivery API
This commit is contained in:
@@ -3,6 +3,7 @@ package staff
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.apinb.com/bsm-sdk/core/errcode"
|
||||
"git.apinb.com/bsm-sdk/core/infra"
|
||||
@@ -63,6 +64,57 @@ func Profile(ctx *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// Preflight 返回当前单角色账号可由服务端确认的作业前置条件。
|
||||
func Preflight(ctx *gin.Context) {
|
||||
account, ok := clientcommon.StaffAccount(ctx)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
var credential models.StaffCredential
|
||||
credentialFound := impl.DBService.
|
||||
Where("staff_account_id = ? AND status = ?", account.ID, base.StatusEnable).
|
||||
Order("expired_at desc").
|
||||
First(&credential).Error == nil
|
||||
credentialValid := credentialFound && (credential.ExpiredAt == nil || credential.ExpiredAt.After(time.Now()))
|
||||
|
||||
organizationIdentity, organizationName, organizationType := "", "", ""
|
||||
if account.DeliveryBasicID != 0 {
|
||||
var organization models.DeliveryBasic
|
||||
if impl.DBService.First(&organization, account.DeliveryBasicID).Error == nil {
|
||||
organizationIdentity, organizationName, organizationType = organization.Identity, organization.Name, "delivery"
|
||||
}
|
||||
} else if account.GasBasicID != 0 {
|
||||
var organization models.GasBasic
|
||||
if impl.DBService.First(&organization, account.GasBasicID).Error == nil {
|
||||
organizationIdentity, organizationName, organizationType = organization.Identity, organization.Name, "gas"
|
||||
}
|
||||
}
|
||||
|
||||
checks := gin.H{
|
||||
"account": gin.H{"status": "passed"},
|
||||
"role": gin.H{"status": "passed", "role_code": account.RoleCode},
|
||||
"organization": gin.H{"status": checkStatus(organizationIdentity != ""), "identity": organizationIdentity, "name": organizationName, "type": organizationType},
|
||||
"credential": gin.H{"status": checkStatus(credentialValid), "expired_at": credential.ExpiredAt},
|
||||
"attendance": gin.H{"status": checkStatus(account.WorkStatus == "on_duty"), "work_status": account.WorkStatus},
|
||||
"daily_training": gin.H{"status": "not_configured"},
|
||||
"service_area": gin.H{"status": "not_configured"},
|
||||
"authorized_device": gin.H{"status": "not_configured"},
|
||||
}
|
||||
infra.Response.Success(ctx, gin.H{
|
||||
"role_code": account.RoleCode, "work_status": account.WorkStatus,
|
||||
"can_work": organizationIdentity != "" && credentialValid && account.WorkStatus == "on_duty",
|
||||
"checks": checks,
|
||||
})
|
||||
}
|
||||
|
||||
func checkStatus(passed bool) string {
|
||||
if passed {
|
||||
return "passed"
|
||||
}
|
||||
return "blocked"
|
||||
}
|
||||
|
||||
// ChangePassword 修改当前工作人员登录密码。
|
||||
func ChangePassword(ctx *gin.Context) {
|
||||
account, ok := clientcommon.StaffAccount(ctx)
|
||||
|
||||
Reference in New Issue
Block a user