feat: 首次引导安装开始和完成的触发接口
This commit is contained in:
@@ -25,6 +25,12 @@ func Setup(router *gin.Engine) {
|
|||||||
|
|
||||||
// 系统可暴露的配置信息
|
// 系统可暴露的配置信息
|
||||||
indexGroup.GET("/sys-conf", controller.NewCommont.SysConfig)
|
indexGroup.GET("/sys-conf", controller.NewCommont.SysConfig)
|
||||||
|
// 首次引导安装
|
||||||
|
guideGroup := router.Group("/guide")
|
||||||
|
{
|
||||||
|
guideGroup.POST("", controller.NewLaunch.GuideStart)
|
||||||
|
guideGroup.PUT("", middleware.PreAuthorize(nil), controller.NewLaunch.GuideDone)
|
||||||
|
}
|
||||||
|
|
||||||
// 验证码操作处理
|
// 验证码操作处理
|
||||||
indexGroup.GET("/captchaImage",
|
indexGroup.GET("/captchaImage",
|
||||||
|
|||||||
110
src/modules/common/controller/launch.go
Normal file
110
src/modules/common/controller/launch.go
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
adminConstants "be.ems/src/framework/constants/admin"
|
||||||
|
tokenConstants "be.ems/src/framework/constants/token"
|
||||||
|
"be.ems/src/framework/utils/ctx"
|
||||||
|
"be.ems/src/framework/utils/machine"
|
||||||
|
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"
|
||||||
|
systemService "be.ems/src/modules/system/service"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 实例化控制层 LaunchController 结构体
|
||||||
|
var NewLaunch = &LaunchController{
|
||||||
|
accountService: commonService.NewAccountImpl,
|
||||||
|
sysUserService: systemService.NewSysUserImpl,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 首次启动安装
|
||||||
|
//
|
||||||
|
// PATH /launch
|
||||||
|
type LaunchController struct {
|
||||||
|
// 账号身份操作服务
|
||||||
|
accountService commonService.IAccount
|
||||||
|
// 用户信息服务
|
||||||
|
sysUserService systemService.ISysUser
|
||||||
|
}
|
||||||
|
|
||||||
|
// 首次引导安装开始
|
||||||
|
//
|
||||||
|
// POST /guide
|
||||||
|
func (s *LaunchController) GuideStart(c *gin.Context) {
|
||||||
|
// 是否完成引导
|
||||||
|
launchInfo := machine.LaunchInfo
|
||||||
|
if launchInfo == nil {
|
||||||
|
c.JSON(200, result.Err(nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v, ok := launchInfo["sysGuide"]; ok && !v.(bool) {
|
||||||
|
c.JSON(200, result.ErrMsg("guide done"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查询用户登录账号
|
||||||
|
sysUser := s.sysUserService.SelectUserById("1")
|
||||||
|
if sysUser.UserID != "1" {
|
||||||
|
c.JSON(200, result.ErrMsg("not found user data"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 登录用户信息
|
||||||
|
loginUser := vo.LoginUser{
|
||||||
|
UserID: sysUser.UserID,
|
||||||
|
DeptID: sysUser.DeptID,
|
||||||
|
User: sysUser,
|
||||||
|
Permissions: []string{adminConstants.PERMISSION},
|
||||||
|
}
|
||||||
|
|
||||||
|
// 当前请求信息
|
||||||
|
ipaddr, location := ctx.IPAddrLocation(c)
|
||||||
|
os, browser := ctx.UaOsBrowser(c)
|
||||||
|
|
||||||
|
// 生成令牌,创建系统访问记录
|
||||||
|
tokenStr := tokenUtils.Create(&loginUser, ipaddr, location, os, browser)
|
||||||
|
if tokenStr == "" {
|
||||||
|
c.JSON(200, result.Err(nil))
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
s.accountService.UpdateLoginDateAndIP(&loginUser)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(200, result.OkData(map[string]any{
|
||||||
|
tokenConstants.RESPONSE_FIELD: tokenStr,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 首次引导安装完成
|
||||||
|
//
|
||||||
|
// PUT /guide
|
||||||
|
func (s *LaunchController) GuideDone(c *gin.Context) {
|
||||||
|
// 是否完成引导
|
||||||
|
launchInfo := machine.LaunchInfo
|
||||||
|
if launchInfo == nil {
|
||||||
|
c.JSON(200, result.Err(nil))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if v, ok := launchInfo["sysGuide"]; ok && !v.(bool) {
|
||||||
|
c.JSON(200, result.ErrMsg("guide done"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 记录完成时间
|
||||||
|
err := machine.SetLaunchInfo(map[string]any{
|
||||||
|
"sysGuide": false, // 首次引导
|
||||||
|
"sysGuideTime": time.Now().UnixMilli(), // 引导完成时间
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 清除授权信息
|
||||||
|
tokenUtils.Remove(ctx.Authorization(c))
|
||||||
|
c.JSON(200, result.Ok(nil))
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
|
|
||||||
"be.ems/lib/global"
|
"be.ems/lib/global"
|
||||||
"be.ems/src/framework/config"
|
"be.ems/src/framework/config"
|
||||||
|
"be.ems/src/framework/utils/machine"
|
||||||
systemService "be.ems/src/modules/system/service"
|
systemService "be.ems/src/modules/system/service"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -29,6 +30,17 @@ func (s *CommontImpl) SystemConfigInfo() map[string]string {
|
|||||||
infoMap["version"] = global.Version
|
infoMap["version"] = global.Version
|
||||||
infoMap["buildTime"] = global.BuildTime
|
infoMap["buildTime"] = global.BuildTime
|
||||||
infoMap["goVer"] = global.GoVer
|
infoMap["goVer"] = global.GoVer
|
||||||
|
// 系统首次使用标记
|
||||||
|
launchInfo := machine.LaunchInfo
|
||||||
|
if launchInfo != nil {
|
||||||
|
if v, ok := launchInfo["sysGuide"]; ok {
|
||||||
|
infoMap["sysGuide"] = fmt.Sprint(v)
|
||||||
|
} else {
|
||||||
|
infoMap["sysGuide"] = "true"
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
infoMap["sysGuide"] = "true"
|
||||||
|
}
|
||||||
// 序列号
|
// 序列号
|
||||||
infoMap["serialNum"] = fmt.Sprint(config.Get("omc.sn"))
|
infoMap["serialNum"] = fmt.Sprint(config.Get("omc.sn"))
|
||||||
// 获取LOGO类型
|
// 获取LOGO类型
|
||||||
|
|||||||
Reference in New Issue
Block a user