1
0

marge: 合并代码

This commit is contained in:
TsMask
2023-11-28 10:22:37 +08:00
parent 5050f4f113
commit 3df3b5b5f7
18 changed files with 234 additions and 46 deletions

View File

@@ -2,7 +2,9 @@ package file
import (
"fmt"
"io"
"mime/multipart"
"os"
"path"
"path/filepath"
"strconv"
@@ -295,6 +297,43 @@ func ChunkMergeFile(identifier, originalFileName, subPath string) (string, error
return filepath.ToSlash(urlPath), nil
}
// CopyUploadFile 将上传文件资源转移新目录
//
// filePath 上传得到的文件路径 /upload....
// dst 新文件路径 /a/xx.pdf
func CopyUploadFile(filePath, dst string) error {
srcPath := ParseUploadFilePath(filePath)
src, err := os.Open(srcPath)
if err != nil {
return err
}
defer src.Close()
if err := os.MkdirAll(filepath.Dir(dst), 0750); err != nil {
return err
}
// 如果目标文件已经存在,先将目标文件重命名
if _, err := os.Stat(dst); err == nil {
ext := filepath.Ext(dst)
name := dst[0 : len(dst)-len(ext)]
newName := fmt.Sprintf("%s-%s%s", name, time.Now().Format("20060102_150405"), ext)
err := os.Rename(dst, newName)
if err != nil {
return err
}
}
out, err := os.Create(dst)
if err != nil {
return err
}
defer out.Close()
_, err = io.Copy(out, src)
return err
}
// ParseUploadFileDir 得到上传资源目录
//
// subPath 子路径,默认 UploadSubPath.DEFAULT
@@ -304,7 +343,7 @@ func ParseUploadFileDir(subPath string) string {
return filepath.Join(dir, filePath)
}
// ParseUploadFilePath 本地资源路径
// ParseUploadFilePath 上传资源本地绝对资源路径
//
// filePath 上传文件路径
func ParseUploadFilePath(filePath string) string {

View File

@@ -3,6 +3,7 @@ package common
import (
"ems.agt/src/framework/logger"
"ems.agt/src/framework/middleware"
"ems.agt/src/framework/middleware/collectlogs"
"ems.agt/src/modules/common/controller"
"github.com/gin-gonic/gin"
@@ -25,6 +26,12 @@ func Setup(router *gin.Engine) {
// 系统可暴露的配置信息
indexGroup.GET("/sys-conf", controller.NewCommont.SysConfig)
// 系统使用文档转存
indexGroup.POST("/helpDoc",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.helpDoc", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewCommont.HelpDoc,
)
// 验证码操作处理
indexGroup.GET("/captchaImage",
@@ -49,11 +56,11 @@ func Setup(router *gin.Engine) {
indexGroup.GET("/getInfo", middleware.PreAuthorize(nil), controller.NewAccount.Info)
indexGroup.GET("/getRouters", middleware.PreAuthorize(nil), controller.NewAccount.Router)
indexGroup.POST("/logout",
// middleware.RateLimit(middleware.LimitOption{
// Time: 300,
// Count: 5,
// Type: middleware.LIMIT_IP,
// }),
middleware.RateLimit(middleware.LimitOption{
Time: 300,
Count: 5,
Type: middleware.LIMIT_IP,
}),
controller.NewAccount.Logout,
)
}

View File

@@ -1,11 +1,18 @@
package controller
import (
"fmt"
"path/filepath"
"strings"
"ems.agt/src/framework/config"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/vo/result"
commonService "ems.agt/src/modules/common/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 CommontController 结构体
@@ -69,3 +76,41 @@ func (s *CommontController) SysConfig(c *gin.Context) {
c.JSON(200, result.OkData(data))
}
// 转存帮助文档
//
// POST /helpDoc
func (s *CommontController) HelpDoc(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
UploadPath string `json:"uploadPath" binding:"required"`
Language string `json:"language" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 取语言前缀
lang := strings.SplitN(body.Language, "_", 2)[0]
// 默认静态资源
static := config.Get("staticFile.default").(map[string]any)
dir, err := filepath.Abs(static["dir"].(string))
if err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
return
}
newFile := fmt.Sprintf("%s/helpDoc/%s_doc.pdf", dir, lang)
fmt.Println(newFile)
err = file.CopyUploadFile(body.UploadPath, newFile)
if err != nil {
c.JSON(400, result.CodeMsg(400, err.Error()))
return
}
urlPath := strings.Replace(newFile, dir, static["prefix"].(string), 1)
c.JSON(200, result.OkData(filepath.ToSlash(urlPath)))
}

View File

@@ -41,5 +41,11 @@ func (s *CommontImpl) SystemConfigInfo() map[string]string {
// 获取登录界面背景
loginBackground := s.sysConfigService.SelectConfigValueByKey("sys.loginBackground")
infoMap["loginBackground"] = loginBackground
// 系统设置-官网网址
officialUrl := s.sysConfigService.SelectConfigValueByKey("sys.officialUrl")
infoMap["officialUrl"] = officialUrl
// 系统设置-系统使用文档
helpDoc := s.sysConfigService.SelectConfigValueByKey("sys.helpDoc")
infoMap["helpDoc"] = helpDoc
return infoMap
}

View File

@@ -34,6 +34,7 @@ type SysUserOnlineController struct {
//
// GET /list
func (s *SysUserOnlineController) List(c *gin.Context) {
language := ctx.AcceptLanguage(c)
ipaddr := c.Query("ipaddr")
userName := c.Query("userName")
@@ -69,6 +70,7 @@ func (s *SysUserOnlineController) List(c *gin.Context) {
onlineUser := s.sysUserOnlineService.LoginUserToUserOnline(loginUser)
if onlineUser.TokenID != "" {
onlineUser.LoginLocation = i18n.TKey(language, onlineUser.LoginLocation)
userOnlines = append(userOnlines, onlineUser)
}
}

View File

@@ -0,0 +1,68 @@
package controller
import (
"fmt"
"path/filepath"
"strings"
"ems.agt/src/framework/config"
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/ssh"
"ems.agt/src/framework/vo/result"
neService "ems.agt/src/modules/network_element/service"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
)
// 实例化控制层 NeActionController 结构体
var NewNeAction = &NeActionController{
neInfoService: neService.NewNeInfoImpl,
}
// 网元处理请求
//
// PATH /
type NeActionController struct {
// 网元信息服务
neInfoService neService.INeInfo
}
// 发送文件到网元端
//
// POST /pushFile
func (s *NeActionController) PushFile(c *gin.Context) {
language := ctx.AcceptLanguage(c)
var body struct {
NeType string `json:"neType" binding:"required"`
NeID string `json:"neId" binding:"required"`
UploadPath string `json:"uploadPath" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(body.NeType, body.NeID)
if neInfo.NeId != body.NeID || neInfo.IP == "" {
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
// 本地文件
localPath := file.ParseUploadFilePath(body.UploadPath)
nePath := config.Get("mml.upload").(string)
// 复制到远程
err := ssh.FileSCPLocalToNe(neInfo.IP, localPath, nePath)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
// 网元端文件路径
fileName := localPath[strings.LastIndex(localPath, "/")+1:]
neFilePath := fmt.Sprintf("%s/%s", nePath, fileName)
c.JSON(200, result.OkData(filepath.ToSlash(neFilePath)))
}

View File

@@ -35,7 +35,7 @@ func (s *NeInfoController) NeTypeAndID(c *gin.Context) {
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID(neType, neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
c.JSON(200, result.OkData(neInfo))

View File

@@ -76,7 +76,7 @@ func (s *UDMAuthController) Info(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -134,7 +134,7 @@ func (s *UDMAuthController) Add(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -177,7 +177,7 @@ func (s *UDMAuthController) Adds(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -219,7 +219,7 @@ func (s *UDMAuthController) Edit(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -268,7 +268,7 @@ func (s *UDMAuthController) Remove(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -305,7 +305,7 @@ func (s *UDMAuthController) Removes(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -414,7 +414,7 @@ func (s *UDMAuthController) Import(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}

View File

@@ -77,7 +77,7 @@ func (s *UDMSubController) Info(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -158,7 +158,7 @@ func (s *UDMSubController) Add(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -206,7 +206,7 @@ func (s *UDMSubController) Adds(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -253,7 +253,7 @@ func (s *UDMSubController) Edit(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -344,7 +344,7 @@ func (s *UDMSubController) Remove(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -381,7 +381,7 @@ func (s *UDMSubController) Removes(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}
@@ -492,7 +492,7 @@ func (s *UDMSubController) Import(c *gin.Context) {
// 查询网元获取IP
neInfo := s.neInfoService.SelectNeInfoByNeTypeAndNeID("UDM", neId)
if neInfo.NeId != neId || neInfo.IP == "" {
c.JSON(200, result.OkData(i18n.TKey(language, "app.common.noNEInfo")))
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.noNEInfo")))
return
}

View File

@@ -22,6 +22,17 @@ func Setup(router *gin.Engine) {
)
}
// 网元处理
neActionGroup := neGroup.Group("/action")
{
// 发送文件到网元服务器
neActionGroup.POST("/pushFile",
middleware.PreAuthorize(nil),
collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.neAction", collectlogs.BUSINESS_TYPE_IMPORT)),
controller.NewNeAction.PushFile,
)
}
// UDM鉴权用户信息
udmAuthGroup := neGroup.Group("/udm/auth")
{

View File

@@ -23,7 +23,8 @@ type UDMAuthImpl struct {
// authDataByRedis UDM鉴权用户
func (r *UDMAuthImpl) authDataByRedis(imsi, neID string) []model.UDMAuth {
arr := []model.UDMAuth{}
ausfArr, err := redis.GetKeys("udmuser", fmt.Sprintf("ausf:%s", imsi))
key := fmt.Sprintf("ausf:%s", imsi)
ausfArr, err := redis.GetKeys("udmuser", key)
if err != nil {
return arr
}
@@ -39,10 +40,8 @@ func (r *UDMAuthImpl) authDataByRedis(imsi, neID string) []model.UDMAuth {
continue
}
status := "0"
if _, ok := m["auth_success"]; ok {
status = "1"
}
status := "1" // 默认给1
amf := ""
if v, ok := m["amf"]; ok {
amf = strings.Replace(v, "\r\n", "", 1)
@@ -166,11 +165,12 @@ func (r *UDMAuthImpl) Delete(neID, imsi string) int64 {
// Insert UDM鉴权用户-删除范围
func (r *UDMAuthImpl) Deletes(neID, imsi, num string) int64 {
prefix := imsi[:len(imsi)-len(num)]
// keys udm-sd:4600001000004*
prefix := imsi[:len(imsi)-len(num)-1]
// 直接删除前缀的记录
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
// keys ausf:4600001000004*
authArr := r.authDataByRedis(prefix+"*", neID)
if len(authArr) > 0 {
r.udmAuthRepository.DeletePrefixImsi(neID, prefix)
return r.udmAuthRepository.Inserts(authArr)
}
return 0

View File

@@ -23,7 +23,8 @@ type UDMSubImpl struct {
// subDataByRedis UDM签约用户
func (r *UDMSubImpl) subDataByRedis(imsi, neID string) []model.UDMSub {
arr := []model.UDMSub{}
udmsdArr, err := redis.GetKeys("udmuser", fmt.Sprintf("udm-sd:%s", imsi))
key := fmt.Sprintf("udm-sd:%s", imsi)
udmsdArr, err := redis.GetKeys("udmuser", key)
if err != nil {
return arr
}
@@ -180,11 +181,12 @@ func (r *UDMSubImpl) Delete(neID, imsi string) int64 {
// Insert UDM签约用户-删除范围
func (r *UDMSubImpl) Deletes(neID, imsi, num string) int64 {
prefix := imsi[:len(imsi)-len(num)]
prefix := imsi[:len(imsi)-len(num)-1]
// 直接删除前缀的记录
r.udmSubRepository.DeletePrefixImsi(neID, prefix)
// keys udm-sd:4600001000004*
authArr := r.subDataByRedis(prefix+"*", neID)
if len(authArr) > 0 {
r.udmSubRepository.DeletePrefixImsi(neID, prefix)
return r.udmSubRepository.Inserts(authArr)
}
return 0

View File

@@ -759,7 +759,7 @@ func (s *SysUserController) ImportData(c *gin.Context) {
message = strings.Join(append([]string{msg}, failureMsgArr...), "<br/>")
} else {
// 恭喜您,数据已全部导入成功!共 %d 条,数据如下:
msg := i18n.TTemplate(language, "user.import.successTip", map[string]any{"num": failureNum})
msg := i18n.TTemplate(language, "user.import.successTip", map[string]any{"num": successNum})
message = strings.Join(append([]string{msg}, successMsgArr...), "<br/>")
}

View File

@@ -1,7 +1,7 @@
package service
import (
fmt "fmt"
"fmt"
"net"
"time"