feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -1,34 +1,33 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
adminConstants "be.ems/src/framework/constants/admin"
|
||||
"be.ems/src/framework/constants/common"
|
||||
tokenConstants "be.ems/src/framework/constants/token"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/token"
|
||||
"be.ems/src/framework/utils/machine"
|
||||
"be.ems/src/framework/utils/regular"
|
||||
tokenUtils "be.ems/src/framework/utils/token"
|
||||
"be.ems/src/framework/vo"
|
||||
"be.ems/src/framework/vo/result"
|
||||
commonService "be.ems/src/modules/common/service"
|
||||
"be.ems/src/modules/common/service"
|
||||
systemService "be.ems/src/modules/system/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 BootloaderController 结构体
|
||||
var NewBootloader = &BootloaderController{
|
||||
accountService: commonService.NewAccount,
|
||||
sysUserService: systemService.NewSysUserImpl,
|
||||
accountService: service.NewAccount,
|
||||
sysUserService: systemService.NewSysUser,
|
||||
}
|
||||
|
||||
// 系统引导初始化
|
||||
//
|
||||
// PATH /bootloader
|
||||
type BootloaderController struct {
|
||||
accountService *commonService.Account // 账号身份操作服务
|
||||
// 用户信息服务
|
||||
sysUserService systemService.ISysUser
|
||||
accountService *service.Account // 账号身份操作服务
|
||||
sysUserService *systemService.SysUser // 用户信息服务
|
||||
}
|
||||
|
||||
// 首次引导开始
|
||||
@@ -38,44 +37,47 @@ func (s *BootloaderController) Start(c *gin.Context) {
|
||||
// 是否完成引导
|
||||
launchInfo := machine.LaunchInfo
|
||||
if launchInfo == nil {
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
return
|
||||
}
|
||||
if v, ok := launchInfo[common.LAUNCH_BOOTLOADER]; ok && !v.(bool) {
|
||||
c.JSON(200, result.ErrMsg("bootloader done"))
|
||||
if v, ok := launchInfo[constants.LAUNCH_BOOTLOADER]; ok && !v.(bool) {
|
||||
c.JSON(200, resp.ErrMsg("bootloader done"))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询用户登录账号
|
||||
sysUser := s.sysUserService.SelectUserById("1")
|
||||
if sysUser.UserID != "1" {
|
||||
c.JSON(200, result.ErrMsg("not found user data"))
|
||||
sysUser := s.sysUserService.FindById(1)
|
||||
if sysUser.UserId != 1 {
|
||||
c.JSON(200, resp.ErrMsg("not found user data"))
|
||||
return
|
||||
}
|
||||
|
||||
// 登录用户信息
|
||||
loginUser := vo.LoginUser{
|
||||
UserID: sysUser.UserID,
|
||||
DeptID: sysUser.DeptID,
|
||||
loginUser := token.TokenInfo{
|
||||
UserId: sysUser.UserId,
|
||||
DeptId: sysUser.DeptId,
|
||||
User: sysUser,
|
||||
Permissions: []string{adminConstants.PERMISSION},
|
||||
Permissions: []string{constants.SYS_PERMISSION_SYSTEM},
|
||||
}
|
||||
|
||||
// 当前请求信息
|
||||
ipaddr, location := ctx.IPAddrLocation(c)
|
||||
os, browser := ctx.UaOsBrowser(c)
|
||||
ipaddr, location := reqctx.IPAddrLocation(c)
|
||||
os, browser := reqctx.UaOsBrowser(c)
|
||||
|
||||
// 生成令牌,创建系统访问记录
|
||||
tokenStr := tokenUtils.Create(&loginUser, ipaddr, location, os, browser)
|
||||
tokenStr := token.Create(&loginUser, [4]string{ipaddr, location, os, browser})
|
||||
if tokenStr == "" {
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
return
|
||||
} else {
|
||||
s.accountService.UpdateLoginDateAndIP(&loginUser)
|
||||
s.accountService.UpdateLoginDateAndIP(loginUser)
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(map[string]any{
|
||||
tokenConstants.RESPONSE_FIELD: tokenStr,
|
||||
c.JSON(200, resp.OkData(map[string]any{
|
||||
"accessToken": tokenStr,
|
||||
"tokenType": strings.TrimRight(constants.HEADER_PREFIX, " "),
|
||||
"expiresIn": (loginUser.ExpireTime - loginUser.LoginTime) / 1000,
|
||||
"userId": loginUser.UserId,
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -86,23 +88,23 @@ func (s *BootloaderController) Done(c *gin.Context) {
|
||||
// 是否完成引导
|
||||
launchInfo := machine.LaunchInfo
|
||||
if launchInfo == nil {
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
return
|
||||
}
|
||||
if v, ok := launchInfo[common.LAUNCH_BOOTLOADER]; ok && !v.(bool) {
|
||||
c.JSON(200, result.ErrMsg("bootloader done"))
|
||||
if v, ok := launchInfo[constants.LAUNCH_BOOTLOADER]; ok && !v.(bool) {
|
||||
c.JSON(200, resp.ErrMsg("bootloader done"))
|
||||
return
|
||||
}
|
||||
|
||||
// 标记引导完成
|
||||
if err := machine.Bootloader(false); err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 清除授权信息
|
||||
tokenUtils.Remove(ctx.Authorization(c))
|
||||
c.JSON(200, result.Ok(nil))
|
||||
token.Remove(reqctx.Authorization(c))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 引导系统数据重置
|
||||
@@ -112,69 +114,69 @@ func (s *BootloaderController) Reset(c *gin.Context) {
|
||||
// 是否完成引导
|
||||
launchInfo := machine.LaunchInfo
|
||||
if launchInfo == nil {
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
return
|
||||
}
|
||||
if v, ok := launchInfo[common.LAUNCH_BOOTLOADER]; ok && v.(bool) {
|
||||
c.JSON(200, result.ErrMsg("bootloader not done"))
|
||||
if v, ok := launchInfo[constants.LAUNCH_BOOTLOADER]; ok && v.(bool) {
|
||||
c.JSON(200, resp.ErrMsg("bootloader not done"))
|
||||
return
|
||||
}
|
||||
|
||||
if err := machine.Reset(); err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// 清除授权信息
|
||||
tokenUtils.Remove(ctx.Authorization(c))
|
||||
c.JSON(200, result.Ok(nil))
|
||||
token.Remove(reqctx.Authorization(c))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 账号变更
|
||||
//
|
||||
// PUT /account
|
||||
func (s *BootloaderController) Account(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
UserName string `json:"username" binding:"required"`
|
||||
Password string `json:"password" binding:"required"`
|
||||
}
|
||||
if err := c.ShouldBindJSON(&body); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
c.JSON(400, resp.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
if !regular.ValidPassword(body.Password) {
|
||||
// 登录密码至少包含大小写字母、数字、特殊符号,且不少于6位
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.errPasswd")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "user.errPasswd")))
|
||||
return
|
||||
}
|
||||
|
||||
// 是否完成引导
|
||||
launchInfo := machine.LaunchInfo
|
||||
if launchInfo == nil {
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
return
|
||||
}
|
||||
if v, ok := launchInfo[common.LAUNCH_BOOTLOADER]; ok && !v.(bool) {
|
||||
c.JSON(200, result.ErrMsg("bootloader done"))
|
||||
if v, ok := launchInfo[constants.LAUNCH_BOOTLOADER]; ok && !v.(bool) {
|
||||
c.JSON(200, resp.ErrMsg("bootloader done"))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询用户登录账号
|
||||
sysUser := s.sysUserService.SelectUserById("2")
|
||||
if sysUser.UserID != "2" {
|
||||
c.JSON(200, result.ErrMsg("not found user data"))
|
||||
sysUser := s.sysUserService.FindById(2)
|
||||
if sysUser.UserId != 2 {
|
||||
c.JSON(200, resp.ErrMsg("not found user data"))
|
||||
return
|
||||
}
|
||||
sysUser.UserName = body.UserName
|
||||
sysUser.NickName = body.UserName
|
||||
sysUser.Password = body.Password
|
||||
sysUser.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.sysUserService.UpdateUser(sysUser)
|
||||
sysUser.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
rows := s.sysUserService.Update(sysUser)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user