1
0

feat: 合并Gin_Vue

This commit is contained in:
TsMask
2023-10-16 20:04:08 +08:00
parent 55fe1d534d
commit 05c7e9b9e8
213 changed files with 20338 additions and 311 deletions

View File

@@ -12,6 +12,7 @@ import (
"io"
"net/http"
tokenConst "ems.agt/src/framework/constants/token"
"github.com/go-resty/resty/v2"
"github.com/gorilla/mux"
)
@@ -43,7 +44,7 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
}
restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
getNeInfoPattern := fmt.Sprintf(config.UriPrefix+"/databaseManagement/v1/%s/ne_info", config.GetYamlConfig().Database.Name)
getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/%s/ne_info", config.GetYamlConfig().Database.Name)
getNeInfoURI := restHostPort + getNeInfoPattern
neId := services.GetUriParamString(r, "ne_id", ",", true, false)
if neId == "" {
@@ -56,6 +57,7 @@ func GetParamConfigFromNF(w http.ResponseWriter, r *http.Request) {
client := resty.New()
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).

View File

@@ -75,7 +75,7 @@ func (s *FirewallApi) Rule(w http.ResponseWriter, r *http.Request) {
var body model.RuleQuerys
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Type == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
data, err := s.firewallService.RulePage(body)

View File

@@ -16,9 +16,8 @@ import (
"ems.agt/lib/services"
"ems.agt/restagent/config"
tokenConst "ems.agt/src/framework/constants/token"
"github.com/gorilla/mux"
_ "github.com/go-sql-driver/mysql"
)
const (
@@ -153,7 +152,7 @@ func PostMMLToNF(w http.ResponseWriter, r *http.Request) {
for _, mml := range mmlRequest.MML {
mmlCommand := fmt.Sprintf("%s\n", mml)
log.Debug("mml command:", mmlCommand)
n, err = conn.Write([]byte(mmlCommand))
_, err = conn.Write([]byte(mmlCommand))
if err != nil {
log.Errorf("Error: %s", err.Error())
return
@@ -211,14 +210,15 @@ func PostMMLToOMC(w http.ResponseWriter, r *http.Request) {
hostUri := fmt.Sprintf("http://%s:%s", neInfo.Ip, neInfo.Port)
omcMmlVar := &mmlp.MmlVar{
Version: "16.1.1",
Output: mmlp.DefaultFormatType,
MmlHome: config.GetYamlConfig().MML.MmlHome,
Limit: 50,
User: "",
SessionToken: token,
HttpUri: hostUri,
UserAgent: config.GetDefaultUserAgent(),
Version: "16.1.1",
Output: mmlp.DefaultFormatType,
MmlHome: config.GetYamlConfig().MML.MmlHome,
Limit: 50,
User: "",
SessionToken: token, // 旧token
Authorization: r.Header.Get(tokenConst.HEADER_KEY), // 请求Token
HttpUri: hostUri,
UserAgent: config.GetDefaultUserAgent(),
}
mmlRequest := new(MMLRequest)
_ = json.Unmarshal(body, mmlRequest)

View File

@@ -14,7 +14,6 @@ import (
sysConfigService "ems.agt/features/sys_config/service"
"ems.agt/lib/core/account"
"ems.agt/lib/core/cache"
"ems.agt/lib/core/conf"
"ems.agt/lib/core/constants/cachekey"
"ems.agt/lib/core/utils/ctx"
"ems.agt/lib/core/vo/result"
@@ -24,7 +23,8 @@ import (
"ems.agt/lib/oauth"
"ems.agt/lib/services"
"ems.agt/restagent/config"
"github.com/go-admin-team/go-admin-core/logger"
srcConfig "ems.agt/src/framework/config"
"ems.agt/src/framework/redis"
"github.com/mojocn/base64Captcha"
)
@@ -136,9 +136,10 @@ func LoginFromOMC(w http.ResponseWriter, r *http.Request) {
if user != nil {
// 缓存用户信息
account.CacheLoginUser(user)
redis.SetByExpire("", "session_token", token, time.Second*1800)
// 角色权限集合,管理员拥有所有权限
userId := fmt.Sprint(user.Id)
isAdmin := conf.IsAdmin(userId)
isAdmin := srcConfig.IsAdmin(userId)
roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin)
services.ResponseStatusOK200LoginWhitRP(w, token, user, roles, perms)
return
@@ -237,13 +238,13 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) {
err := ctx.ShouldBindJSON(r, &body)
if err != nil {
log.Error("Invalid Json Format")
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// response 400-5
if body.Username == "" || body.Password == "" {
log.Error("Wrong parameter value")
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -257,20 +258,20 @@ func LoginOMC(w http.ResponseWriter, r *http.Request) {
if captchaEnabled {
if body.Code == "" || body.UUID == "" {
log.Error("Authentication failed, mismatch captcha")
ctx.JSON(w, 400, result.CodeMsg(400, "验证码信息错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "Verification code information error"))
return
}
verifyKey := cachekey.CAPTCHA_CODE_KEY + body.UUID
captcha, ok := cache.GetLocalTTL(verifyKey)
if captcha == nil || !ok {
log.Error("Authentication failed, captcha emtry")
ctx.JSON(w, 400, result.CodeMsg(400, "验证码已失效"))
ctx.JSON(w, 400, result.CodeMsg(400, "The verification code has expired"))
return
}
cache.DeleteLocalTTL(verifyKey)
if captcha.(string) != body.Code {
log.Error("Authentication failed, not match captcha")
ctx.JSON(w, 400, result.CodeMsg(400, "验证码错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "Verification code error"))
return
}
}
@@ -363,7 +364,7 @@ func CaptchaImage(w http.ResponseWriter, r *http.Request) {
// 验证码表达式解析输出
item, err := driverCaptcha.DrawCaptcha(question)
if err != nil {
logger.Infof("Generate Id Question Answer %s : %v", question, err)
log.Infof("Generate Id Question Answer %s : %v", question, err)
} else {
data["uuid"] = id
data["img"] = item.EncodeB64string()
@@ -388,7 +389,7 @@ func UserInfo(w http.ResponseWriter, r *http.Request) {
}
// 角色权限集合,管理员拥有所有权限
userId := fmt.Sprint(loginUser.UserID)
isAdmin := conf.IsAdmin(userId)
isAdmin := srcConfig.IsAdmin(userId)
roles, perms := service.NewServiceAccount.RoleAndMenuPerms(userId, isAdmin)
ctx.JSON(w, 200, result.OkData(map[string]any{
@@ -403,7 +404,7 @@ func Routers(w http.ResponseWriter, r *http.Request) {
userID := ctx.LoginUserToUserID(r)
// 前端路由,管理员拥有所有
isAdmin := conf.IsAdmin(userID)
isAdmin := srcConfig.IsAdmin(userID)
buildMenus := service.NewServiceAccount.RouteMenus(userID, isAdmin)
ctx.JSON(w, 200, result.OkData(buildMenus))
}

View File

@@ -3,15 +3,51 @@ package sm
import (
"database/sql"
"fmt"
"net/http"
"os"
"os/exec"
"time"
"ems.agt/lib/log"
"ems.agt/lib/services"
"ems.agt/restagent/config"
_ "github.com/go-sql-driver/mysql"
)
var (
// Get OMC local time
UriOMCLocalTime = config.DefaultUriPrefix + "/systemManagement/{apiVersion}/elementType/OMC/objectType/time"
CustomUriOMCLocalTime = config.UriPrefix + "/systemManagement/{apiVersion}/elementType/OMC/objectType/time"
)
type OMCLocalTime struct {
Timestamp int64 `json:"timestamp"` // 时间戳 (单位:毫秒)
TimeZone int `json:"timeZone"` // 本地时区偏移(单位:秒)
}
func GetOMCLocalTime(w http.ResponseWriter, r *http.Request) {
log.Debug("GetOMCLocalTime processing... ")
_, err := services.CheckFrontValidRequest(w, r)
if err != nil {
log.Error("Http request error:", err)
return
}
t := time.Now()
_, offset := t.Zone()
localTime := OMCLocalTime{
Timestamp: t.UnixMilli(),
TimeZone: offset,
}
response := services.DataResponse{
Data: localTime,
}
services.ResponseWithJson(w, http.StatusOK, response)
}
var dbConfig = config.GetYamlConfig().Database
func DatabaseWhoreBackup() {

View File

@@ -17,6 +17,7 @@ import (
"ems.agt/lib/log"
"ems.agt/lib/services"
"ems.agt/restagent/config"
tokenConst "ems.agt/src/framework/constants/token"
)
type CpuUsage struct {
@@ -238,6 +239,7 @@ func GetOneLicenseInfoFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -342,6 +344,7 @@ func GetAllLicenseInfoFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -461,6 +464,7 @@ func GetOneSysinfoFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -594,6 +598,7 @@ func GetAllSysinfoFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -704,13 +709,14 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
// query all NFs
// create rest client
restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
getNeInfoPattern := fmt.Sprintf(config.UriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
config.GetYamlConfig().Database.Name)
getNeInfoURI := restHostPort + getNeInfoPattern + "?WHERE=status='0'"
log.Debug("getNeInfoPattern:", getNeInfoPattern)
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"AccessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -724,7 +730,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
neList, _ = dborm.XormParseResult(resp.Body())
default:
restHostPort := fmt.Sprintf("http://127.0.0.1:%d", config.GetYamlConfig().Rest[0].Port)
getNeInfoPattern := fmt.Sprintf(config.UriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
getNeInfoPattern := fmt.Sprintf(config.DefaultUriPrefix+"/databaseManagement/v1/elementType/%s/objectType/ne_info",
config.GetYamlConfig().Database.Name)
getNeInfoURI := restHostPort + getNeInfoPattern
neId := services.GetUriParamString(r, "ne_id", ",", true, false)
@@ -737,6 +743,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -767,6 +774,7 @@ func GetStateFromNF(w http.ResponseWriter, r *http.Request) {
result["ipAddress"] = ne.Ip
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).

View File

@@ -105,7 +105,7 @@ func (s *SysConfigApi) List(w http.ResponseWriter, r *http.Request) {
func (s *SysConfigApi) Info(w http.ResponseWriter, r *http.Request) {
configId := ctx.Param(r, "configId")
if configId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
data := s.sysConfigService.SelectConfigById(configId)
@@ -123,14 +123,14 @@ func (s *SysConfigApi) Add(w http.ResponseWriter, r *http.Request) {
var body model.SysConfig
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.ConfigID != "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查属性值唯一
uniqueConfigKey := s.sysConfigService.CheckUniqueConfigKey(body.ConfigKey, "")
if !uniqueConfigKey {
msg := fmt.Sprintf("参数配置新增【%s】失败参数键名已存在", body.ConfigKey)
msg := fmt.Sprintf("[%s] Parameter key name already exists", body.ConfigKey)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -151,14 +151,14 @@ func (s *SysConfigApi) Edit(w http.ResponseWriter, r *http.Request) {
var body model.SysConfig
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.ConfigID == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查属性值唯一
uniqueConfigKey := s.sysConfigService.CheckUniqueConfigKey(body.ConfigKey, body.ConfigID)
if !uniqueConfigKey {
msg := fmt.Sprintf("参数配置修改【%s】失败参数键名已存在", body.ConfigKey)
msg := fmt.Sprintf("[%s] Parameter key name already exists", body.ConfigKey)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -166,7 +166,7 @@ func (s *SysConfigApi) Edit(w http.ResponseWriter, r *http.Request) {
// 检查是否存在
config := s.sysConfigService.SelectConfigById(body.ConfigID)
if config.ConfigID != body.ConfigID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问参数配置数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access parameter configuration data!"))
return
}
@@ -185,7 +185,7 @@ func (s *SysConfigApi) Edit(w http.ResponseWriter, r *http.Request) {
func (s *SysConfigApi) Remove(w http.ResponseWriter, r *http.Request) {
configIds := ctx.Param(r, "configIds")
if configIds == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 处理字符转id数组后去重
@@ -218,7 +218,7 @@ func (s *SysConfigApi) RefreshCache(w http.ResponseWriter, r *http.Request) {
func (s *SysConfigApi) ConfigKey(w http.ResponseWriter, r *http.Request) {
configKey := ctx.Param(r, "configKey")
if configKey == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
key := s.sysConfigService.SelectConfigValueByKey(configKey)

View File

@@ -103,7 +103,7 @@ func (s *SysDictDataApi) List(w http.ResponseWriter, r *http.Request) {
func (s *SysDictDataApi) Info(w http.ResponseWriter, r *http.Request) {
dictCode := ctx.Param(r, "dictCode")
if dictCode == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
data := s.sysDictDataService.SelectDictDataByCode(dictCode)
@@ -121,21 +121,21 @@ func (s *SysDictDataApi) Add(w http.ResponseWriter, r *http.Request) {
var body model.SysDictData
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.DictCode != "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查字典类型是否存在
sysDictType := s.sysDictTypeService.SelectDictTypeByType(body.DictType)
if sysDictType.DictType != body.DictType {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问字典类型数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access dictionary type data!"))
return
}
// 检查字典标签唯一
uniqueDictLabel := s.sysDictDataService.CheckUniqueDictLabel(body.DictType, body.DictLabel, "")
if !uniqueDictLabel {
msg := fmt.Sprintf("数据新增【%s】失败该字典类型下标签名已存在", body.DictLabel)
msg := fmt.Sprintf("[%s] The subscript signature of this dictionary type already exists", body.DictLabel)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -143,7 +143,7 @@ func (s *SysDictDataApi) Add(w http.ResponseWriter, r *http.Request) {
// 检查字典键值唯一
uniqueDictValue := s.sysDictDataService.CheckUniqueDictValue(body.DictType, body.DictValue, "")
if !uniqueDictValue {
msg := fmt.Sprintf("数据新增【%s】失败该字典类型下标签值已存在", body.DictValue)
msg := fmt.Sprintf("[%s] The label value under this dictionary type already exists", body.DictValue)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -164,28 +164,28 @@ func (s *SysDictDataApi) Edit(w http.ResponseWriter, r *http.Request) {
var body model.SysDictData
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.DictCode == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查字典类型是否存在
sysDictType := s.sysDictTypeService.SelectDictTypeByType(body.DictType)
if sysDictType.DictType != body.DictType {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问字典类型数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access dictionary type data!"))
return
}
// 检查字典编码是否存在
SysDictDataApi := s.sysDictDataService.SelectDictDataByCode(body.DictCode)
if SysDictDataApi.DictCode != body.DictCode {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问字典编码数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access dictionary encoding data!"))
return
}
// 检查字典标签唯一
uniqueDictLabel := s.sysDictDataService.CheckUniqueDictLabel(body.DictType, body.DictLabel, body.DictCode)
if !uniqueDictLabel {
msg := fmt.Sprintf("数据修改【%s】失败该字典类型下标签名已存在", body.DictLabel)
msg := fmt.Sprintf("Data modification failed for [%s], the dictionary type subscript signature already exists", body.DictLabel)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -193,7 +193,7 @@ func (s *SysDictDataApi) Edit(w http.ResponseWriter, r *http.Request) {
// 检查字典键值唯一
uniqueDictValue := s.sysDictDataService.CheckUniqueDictValue(body.DictType, body.DictValue, body.DictCode)
if !uniqueDictValue {
msg := fmt.Sprintf("数据修改【%s】失败该字典类型下标签值已存在", body.DictValue)
msg := fmt.Sprintf("Data modification failed for [%s], label value already exists under this dictionary type", body.DictValue)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -213,7 +213,7 @@ func (s *SysDictDataApi) Edit(w http.ResponseWriter, r *http.Request) {
func (s *SysDictDataApi) Remove(w http.ResponseWriter, r *http.Request) {
dictCodes := ctx.Param(r, "dictCodes")
if dictCodes == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 处理字符转id数组后去重
@@ -228,7 +228,7 @@ func (s *SysDictDataApi) Remove(w http.ResponseWriter, r *http.Request) {
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
return
}
msg := fmt.Sprintf("删除成功:%d", rows)
msg := fmt.Sprintf("Successfully deleted: %d", rows)
ctx.JSON(w, 200, result.OkMsg(msg))
}
@@ -238,7 +238,7 @@ func (s *SysDictDataApi) Remove(w http.ResponseWriter, r *http.Request) {
func (s *SysDictDataApi) DictType(w http.ResponseWriter, r *http.Request) {
dictType := ctx.Param(r, "dictType")
if dictType == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}

View File

@@ -105,7 +105,7 @@ func (s *SysDictTypeApi) List(w http.ResponseWriter, r *http.Request) {
func (s *SysDictTypeApi) Info(w http.ResponseWriter, r *http.Request) {
dictId := ctx.Param(r, "dictId")
if dictId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
data := s.sysDictTypeService.SelectDictTypeByID(dictId)
@@ -123,14 +123,14 @@ func (s *SysDictTypeApi) Add(w http.ResponseWriter, r *http.Request) {
var body model.SysDictType
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.DictID != "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查字典名称唯一
uniqueDictName := s.sysDictTypeService.CheckUniqueDictName(body.DictName, "")
if !uniqueDictName {
msg := fmt.Sprintf("字典新增【%s】失败字典名称已存在", body.DictName)
msg := fmt.Sprintf("Failed to add dictionary '%s', dictionary name already exists", body.DictName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -138,7 +138,7 @@ func (s *SysDictTypeApi) Add(w http.ResponseWriter, r *http.Request) {
// 检查字典类型唯一
uniqueDictType := s.sysDictTypeService.CheckUniqueDictType(body.DictType, "")
if !uniqueDictType {
msg := fmt.Sprintf("字典新增【%s】失败字典类型已存在", body.DictType)
msg := fmt.Sprintf("Failed to add dictionary '%s', dictionary type already exists", body.DictType)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -159,21 +159,21 @@ func (s *SysDictTypeApi) Edit(w http.ResponseWriter, r *http.Request) {
var body model.SysDictType
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.DictID == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查数据是否存在
dictInfo := s.sysDictTypeService.SelectDictTypeByID(body.DictID)
if dictInfo.DictID != body.DictID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问字典类型数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access dictionary type data!"))
return
}
// 检查字典名称唯一
uniqueDictName := s.sysDictTypeService.CheckUniqueDictName(body.DictName, body.DictID)
if !uniqueDictName {
msg := fmt.Sprintf("字典修改【%s】失败字典名称已存在", body.DictName)
msg := fmt.Sprintf("Dictionary modification failed for [%s], dictionary name already exists", body.DictName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -181,7 +181,7 @@ func (s *SysDictTypeApi) Edit(w http.ResponseWriter, r *http.Request) {
// 检查字典类型唯一
uniqueDictType := s.sysDictTypeService.CheckUniqueDictType(body.DictType, body.DictID)
if !uniqueDictType {
msg := fmt.Sprintf("字典修改【%s】失败字典类型已存在", body.DictType)
msg := fmt.Sprintf("Dictionary modification failed for [%s], dictionary type already exists", body.DictType)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -201,7 +201,7 @@ func (s *SysDictTypeApi) Edit(w http.ResponseWriter, r *http.Request) {
func (s *SysDictTypeApi) Remove(w http.ResponseWriter, r *http.Request) {
dictIds := ctx.Param(r, "dictIds")
if dictIds == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 处理字符转id数组后去重
@@ -216,7 +216,7 @@ func (s *SysDictTypeApi) Remove(w http.ResponseWriter, r *http.Request) {
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
return
}
msg := fmt.Sprintf("删除成功:%d", rows)
msg := fmt.Sprintf("Successfully deleted: %d", rows)
ctx.JSON(w, 200, result.OkMsg(msg))
}

View File

@@ -7,13 +7,13 @@ import (
"ems.agt/features/sys_menu/consts"
"ems.agt/features/sys_menu/model"
"ems.agt/features/sys_menu/service"
"ems.agt/lib/core/conf"
"ems.agt/lib/core/utils/ctx"
"ems.agt/lib/core/utils/regular"
"ems.agt/lib/core/vo/result"
"ems.agt/lib/midware"
"ems.agt/lib/services"
"ems.agt/restagent/config"
srcConfig "ems.agt/src/framework/config"
)
// 菜单接口添加到路由
@@ -109,7 +109,7 @@ func (s *SysMenuApi) List(w http.ResponseWriter, r *http.Request) {
}
userId := ctx.LoginUserToUserID(r)
if conf.IsAdmin(userId) {
if srcConfig.IsAdmin(userId) {
userId = "*"
}
data := s.sysMenuService.SelectMenuList(query, userId)
@@ -122,7 +122,7 @@ func (s *SysMenuApi) List(w http.ResponseWriter, r *http.Request) {
func (s *SysMenuApi) Info(w http.ResponseWriter, r *http.Request) {
menuId := ctx.Param(r, "menuId")
if menuId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
data := s.sysMenuService.SelectMenuById(menuId)
@@ -140,7 +140,7 @@ func (s *SysMenuApi) Add(w http.ResponseWriter, r *http.Request) {
var body model.SysMenu
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.MenuID != "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -185,13 +185,13 @@ func (s *SysMenuApi) Edit(w http.ResponseWriter, r *http.Request) {
var body model.SysMenu
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.MenuID == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 上级菜单不能选自己
if body.MenuID == body.ParentID {
msg := fmt.Sprintf("菜单修改【%s】失败上级菜单不能选择自己", body.MenuName)
msg := fmt.Sprintf("Menu modification failed for [%s], parent menu cannot select itself", body.MenuName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -199,19 +199,19 @@ func (s *SysMenuApi) Edit(w http.ResponseWriter, r *http.Request) {
// 检查数据是否存在
menuInfo := s.sysMenuService.SelectMenuById(body.MenuID)
if menuInfo.MenuID != body.MenuID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问菜单数据"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access menu data"))
return
}
// 父级ID不为0是要检查
if body.ParentID != "0" {
menuParent := s.sysMenuService.SelectMenuById(body.ParentID)
if menuParent.MenuID != body.ParentID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问菜单数据"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access menu data"))
return
}
// 禁用菜单时检查父菜单是否使用
if body.Status == "1" && menuParent.Status == "0" {
ctx.JSON(w, 200, result.ErrMsg("父菜单未启用!"))
ctx.JSON(w, 200, result.ErrMsg("Parent menu not enabled!"))
return
}
}
@@ -266,21 +266,21 @@ func (s *SysMenuApi) Edit(w http.ResponseWriter, r *http.Request) {
func (s *SysMenuApi) Remove(w http.ResponseWriter, r *http.Request) {
menuId := ctx.Param(r, "menuId")
if menuId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查数据是否存在
menu := s.sysMenuService.SelectMenuById(menuId)
if menu.MenuID != menuId {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问菜单数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access menu data!"))
return
}
// 检查是否存在子菜单
hasChild := s.sysMenuService.HasChildByMenuIdAndStatus(menuId, "")
if hasChild > 0 {
msg := fmt.Sprintf("不允许删除,存在子菜单数:%d", hasChild)
msg := fmt.Sprintf("Deletion not allowed, there are sub orders: %d", hasChild)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -288,14 +288,14 @@ func (s *SysMenuApi) Remove(w http.ResponseWriter, r *http.Request) {
// 检查是否分配给角色
existRole := s.sysMenuService.CheckMenuExistRole(menuId)
if existRole > 0 {
msg := fmt.Sprintf("不允许删除,菜单已分配给角色数:%d", existRole)
msg := fmt.Sprintf("Deletion not allowed, menu already assigned to roles: %d", existRole)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
rows := s.sysMenuService.DeleteMenuById(menuId)
if rows > 0 {
msg := fmt.Sprintf("删除成功:%d", rows)
msg := fmt.Sprintf("Successfully deleted: %d", rows)
ctx.JSON(w, 200, result.OkMsg(msg))
return
}
@@ -315,7 +315,7 @@ func (s *SysMenuApi) TreeSelect(w http.ResponseWriter, r *http.Request) {
}
userId := ctx.LoginUserToUserID(r)
if conf.IsAdmin(userId) {
if srcConfig.IsAdmin(userId) {
userId = "*"
}
data := s.sysMenuService.SelectMenuTreeSelectByUserId(query, userId)
@@ -329,7 +329,7 @@ func (s *SysMenuApi) TreeSelect(w http.ResponseWriter, r *http.Request) {
func (s *SysMenuApi) RoleMenuTreeSelect(w http.ResponseWriter, r *http.Request) {
roleId := ctx.Param(r, "roleId")
if roleId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -342,7 +342,7 @@ func (s *SysMenuApi) RoleMenuTreeSelect(w http.ResponseWriter, r *http.Request)
}
userId := ctx.LoginUserToUserID(r)
if conf.IsAdmin(userId) {
if srcConfig.IsAdmin(userId) {
userId = "*"
}
menuTreeSelect := s.sysMenuService.SelectMenuTreeSelectByUserId(query, userId)

View File

@@ -121,7 +121,7 @@ func (s *SysRoleApi) List(w http.ResponseWriter, r *http.Request) {
func (s *SysRoleApi) Info(w http.ResponseWriter, r *http.Request) {
roleId := ctx.Param(r, "roleId")
if roleId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
data := s.sysRoleService.SelectRoleById(roleId)
@@ -139,14 +139,14 @@ func (s *SysRoleApi) Add(w http.ResponseWriter, r *http.Request) {
var body model.SysRole
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.RoleID != "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 判断角色名称是否唯一
uniqueRoleName := s.sysRoleService.CheckUniqueRoleName(body.RoleName, "")
if !uniqueRoleName {
msg := fmt.Sprintf("角色新增【%s】失败角色名称已存在", body.RoleName)
msg := fmt.Sprintf("[%s] Role name already exists", body.RoleName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -154,7 +154,7 @@ func (s *SysRoleApi) Add(w http.ResponseWriter, r *http.Request) {
// 判断角色键值是否唯一
uniqueRoleKey := s.sysRoleService.CheckUniqueRoleKey(body.RoleKey, "")
if !uniqueRoleKey {
msg := fmt.Sprintf("角色新增【%s】失败角色键值已存在", body.RoleName)
msg := fmt.Sprintf("[%s] The role key value already exists", body.RoleName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -175,27 +175,27 @@ func (s *SysRoleApi) Edit(w http.ResponseWriter, r *http.Request) {
var body model.SysRole
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.RoleID == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否管理员角色
if body.RoleID == "1" {
ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员角色"))
ctx.JSON(w, 200, result.ErrMsg("Operation of administrator role is not allowed"))
return
}
// 检查是否存在
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问角色数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access role data!"))
return
}
// 判断角色名称是否唯一
uniqueRoleName := s.sysRoleService.CheckUniqueRoleName(body.RoleName, body.RoleID)
if !uniqueRoleName {
msg := fmt.Sprintf("角色修改【%s】失败角色名称已存在", body.RoleName)
msg := fmt.Sprintf("[%s] Role name already exists", body.RoleName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -203,7 +203,7 @@ func (s *SysRoleApi) Edit(w http.ResponseWriter, r *http.Request) {
// 判断角色键值是否唯一
uniqueRoleKey := s.sysRoleService.CheckUniqueRoleKey(body.RoleKey, body.RoleID)
if !uniqueRoleKey {
msg := fmt.Sprintf("角色修改【%s】失败角色键值已存在", body.RoleName)
msg := fmt.Sprintf("[%s] The role key value already exists", body.RoleName)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -223,7 +223,7 @@ func (s *SysRoleApi) Edit(w http.ResponseWriter, r *http.Request) {
func (s *SysRoleApi) Remove(w http.ResponseWriter, r *http.Request) {
roleIds := ctx.Param(r, "roleIds")
if roleIds == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 处理字符转id数组后去重
@@ -236,7 +236,7 @@ func (s *SysRoleApi) Remove(w http.ResponseWriter, r *http.Request) {
// 检查是否管理员角色
for _, id := range uniqueIDs {
if id == "1" {
ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员角色"))
ctx.JSON(w, 200, result.ErrMsg("Operation of administrator role is not allowed"))
return
}
}
@@ -245,7 +245,7 @@ func (s *SysRoleApi) Remove(w http.ResponseWriter, r *http.Request) {
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
return
}
msg := fmt.Sprintf("删除成功:%d", rows)
msg := fmt.Sprintf("Successfully deleted: %d", rows)
ctx.JSON(w, 200, result.OkMsg(msg))
}
@@ -261,26 +261,26 @@ func (s *SysRoleApi) Status(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否管理员角色
if body.RoleID == "1" {
ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员角色"))
ctx.JSON(w, 200, result.ErrMsg("Operation of administrator role is not allowed"))
return
}
// 检查是否存在
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问角色数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access role data!"))
return
}
// 与旧值相等不变更
if role.Status == body.Status {
ctx.JSON(w, 200, result.ErrMsg("变更状态与旧值相等!"))
ctx.JSON(w, 200, result.ErrMsg("Change status equals old value!"))
return
}
@@ -306,14 +306,14 @@ func (s *SysRoleApi) AuthUserAllocatedList(w http.ResponseWriter, r *http.Reques
querys := ctx.QueryMap(r)
roleId, ok := querys["roleId"]
if !ok || roleId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否存在
role := s.sysRoleService.SelectRoleById(roleId.(string))
if role.RoleID != roleId {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问角色数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access role data!"))
return
}
@@ -335,7 +335,7 @@ func (s *SysRoleApi) AuthUserChecked(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -350,7 +350,7 @@ func (s *SysRoleApi) AuthUserChecked(w http.ResponseWriter, r *http.Request) {
// 检查是否存在
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问角色数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access role data!"))
return
}

View File

@@ -9,13 +9,13 @@ import (
sysRoleService "ems.agt/features/sys_role/service"
sysUserModel "ems.agt/features/sys_user/model"
"ems.agt/features/sys_user/service"
"ems.agt/lib/core/conf"
"ems.agt/lib/core/utils/ctx"
"ems.agt/lib/core/utils/parse"
"ems.agt/lib/core/vo/result"
"ems.agt/lib/midware"
"ems.agt/lib/services"
"ems.agt/restagent/config"
srcConfig "ems.agt/src/framework/config"
)
// 用户接口添加到路由
@@ -107,14 +107,14 @@ func (s *SysUserApi) List(w http.ResponseWriter, r *http.Request) {
func (s *SysUserApi) Info(w http.ResponseWriter, r *http.Request) {
userId := ctx.Param(r, "userId")
if userId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 查询系统角色列表
roles := s.sysRoleService.SelectRoleList(sysRoleModel.SysRole{})
// 不是系统指定管理员需要排除其角色
if !conf.IsAdmin(userId) {
if !srcConfig.IsAdmin(userId) {
rolesFilter := make([]sysRoleModel.SysRole, 0)
for _, r := range roles {
if r.RoleID != "1" {
@@ -137,7 +137,7 @@ func (s *SysUserApi) Info(w http.ResponseWriter, r *http.Request) {
// 检查用户是否存在
user := s.sysUserService.SelectUserById(userId)
if user.Id != userId {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问用户数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access user data!"))
return
}
@@ -161,14 +161,14 @@ func (s *SysUserApi) Add(w http.ResponseWriter, r *http.Request) {
var body sysUserModel.SysUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Id != "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.AccountId, "")
if !uniqueUserName {
msg := fmt.Sprintf("新增用户【%s】失败登录账号已存在", body.AccountId)
msg := fmt.Sprintf("[%s] Login account already exists", body.AccountId)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -188,26 +188,26 @@ func (s *SysUserApi) Edit(w http.ResponseWriter, r *http.Request) {
var body sysUserModel.SysUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Id == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否管理员用户
// if conf.IsAdmin(body.Id) {
// if srcConfig.IsAdmin(body.Id) {
// ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员用户"))
// return
// }
user := s.sysUserService.SelectUserById(body.Id)
if user.Id != body.Id {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问用户数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access user data!"))
return
}
// 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.AccountId, body.Id)
if !uniqueUserName {
msg := fmt.Sprintf("修改用户【%s】失败登录账号已存在", body.AccountId)
msg := fmt.Sprintf("[%s] Login account already exists", body.AccountId)
ctx.JSON(w, 200, result.ErrMsg(msg))
return
}
@@ -228,7 +228,7 @@ func (s *SysUserApi) Edit(w http.ResponseWriter, r *http.Request) {
func (s *SysUserApi) Remove(w http.ResponseWriter, r *http.Request) {
userIds := ctx.Param(r, "userIds")
if userIds == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 处理字符转id数组后去重
@@ -243,7 +243,7 @@ func (s *SysUserApi) Remove(w http.ResponseWriter, r *http.Request) {
ctx.JSON(w, 200, result.ErrMsg(err.Error()))
return
}
msg := fmt.Sprintf("删除成功:%d", rows)
msg := fmt.Sprintf("Successfully deleted: %d", rows)
ctx.JSON(w, 200, result.OkMsg(msg))
}
@@ -256,19 +256,19 @@ func (s *SysUserApi) ResetPwd(w http.ResponseWriter, r *http.Request) {
Password string `json:"password" binding:"required"`
}
if err := ctx.ShouldBindJSON(r, &body); err != nil {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否管理员用户
if conf.IsAdmin(body.UserID) {
ctx.JSON(w, 200, result.ErrMsg("不允许操作管理员用户"))
if srcConfig.IsAdmin(body.UserID) {
ctx.JSON(w, 200, result.ErrMsg("No permission to access user data!"))
return
}
user := s.sysUserService.SelectUserById(body.UserID)
if user.Id != body.UserID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问用户数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access user data!"))
return
}
@@ -293,20 +293,20 @@ func (s *SysUserApi) Status(w http.ResponseWriter, r *http.Request) {
Status string `json:"status" binding:"required"`
}
if err := ctx.ShouldBindJSON(r, &body); err != nil {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否存在
user := s.sysUserService.SelectUserById(body.UserID)
if user.Id != body.UserID {
ctx.JSON(w, 200, result.ErrMsg("没有权限访问用户数据!"))
ctx.JSON(w, 200, result.ErrMsg("No permission to access user data!"))
return
}
// 与旧值相等不变更
if user.Status == body.Status {
ctx.JSON(w, 200, result.ErrMsg("变更状态与旧值相等!"))
ctx.JSON(w, 200, result.ErrMsg("Change status equals old value!"))
return
}

View File

@@ -8,10 +8,10 @@ import (
sysRoleModel "ems.agt/features/sys_role/model"
sysUserModel "ems.agt/features/sys_user/model"
"ems.agt/lib/core/datasource"
"ems.agt/lib/core/utils/crypto"
"ems.agt/lib/core/utils/date"
"ems.agt/lib/core/utils/parse"
"ems.agt/lib/log"
"ems.agt/src/framework/utils/crypto"
)
// 实例化数据层 RepoSysUser 结构体

View File

@@ -51,7 +51,7 @@ func TcpdumpNeTask(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.NeType == "" || body.NeId == "" || body.Timeout < 5 || body.Cmd == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -89,7 +89,7 @@ func TcpdumpPcapDownload(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.NeType == "" || body.NeId == "" || body.FileName == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -120,7 +120,7 @@ func TcpdumpNeUPFTask(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.NeType != "UPF" || body.NeId == "" || body.Cmd == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}

View File

@@ -228,7 +228,7 @@ func (s *UdmUserApi) UdmAuthUserList(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmAuthUserSave(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -244,7 +244,7 @@ func (s *UdmUserApi) UdmAuthUserInfo(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
imsi := ctx.Param(r, "imsi")
if neId == "" || imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -290,14 +290,14 @@ func (s *UdmUserApi) UdmAuthUserInfo(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmAuthUserAdd(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmAuthUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -331,14 +331,14 @@ func (s *UdmUserApi) UdmAuthUserAdds(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
num := ctx.Param(r, "num")
if neId == "" || num == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmAuthUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -371,14 +371,14 @@ func (s *UdmUserApi) UdmAuthUserAdds(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmAuthUserEdit(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmAuthUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -425,7 +425,7 @@ func (s *UdmUserApi) UdmAuthUserRemove(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
imsi := ctx.Param(r, "imsi")
if neId == "" || imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -460,7 +460,7 @@ func (s *UdmUserApi) UdmAuthUserRemoves(w http.ResponseWriter, r *http.Request)
imsi := ctx.Param(r, "imsi")
num := ctx.Param(r, "num")
if neId == "" || imsi == "" || num == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -497,16 +497,16 @@ func (s *UdmUserApi) UdmAuthUserExport(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.NeId == "" || body.Type == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
if !(body.Type == "csv" || body.Type == "txt") {
ctx.JSON(w, 200, result.ErrMsg("导出文件类型支持csv、txt"))
ctx.JSON(w, 200, result.ErrMsg("Export file types support CSV and txt"))
return
}
neId := "-"
neId := ""
list := s.authUser.List(model.UdmAuthUser{NeID: neId})
// 文件名
fileName := fmt.Sprintf("OMC_AUTH_USER_EXPORT_%s_%d.%s", neId, time.Now().UnixMilli(), body.Type)
@@ -554,7 +554,7 @@ func (s *UdmUserApi) UdmAuthUserExport(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmAuthUserImport(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -565,7 +565,7 @@ func (s *UdmUserApi) UdmAuthUserImport(w http.ResponseWriter, r *http.Request) {
return
}
if !(strings.HasSuffix(fileHeader.Filename, ".csv") || strings.HasSuffix(fileHeader.Filename, ".txt")) {
ctx.JSON(w, 200, result.ErrMsg("请上传.csv、.txt格式文件内容字段imsi,ki,algo,amf,opc"))
ctx.JSON(w, 200, result.ErrMsg("Please upload files in. csv and. txt formats with content fields: imsi,ki,algo,amf,opc"))
return
}
@@ -634,7 +634,7 @@ func (s *UdmUserApi) UdmSubUserList(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUserSave(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -650,7 +650,7 @@ func (s *UdmUserApi) UdmSubUserInfo(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
imsi := ctx.Param(r, "imsi")
if neId == "" || imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -714,14 +714,14 @@ func (s *UdmUserApi) UdmSubUserInfo(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUserAdd(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmSubUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -760,14 +760,14 @@ func (s *UdmUserApi) UdmSubUserAdds(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
num := ctx.Param(r, "num")
if neId == "" || num == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmSubUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -805,14 +805,14 @@ func (s *UdmUserApi) UdmSubUserAdds(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUserAdd4G(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmSubUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" || body.SubNum == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -845,14 +845,14 @@ func (s *UdmUserApi) UdmSubUserAdd4G(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUserEdit(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmSubUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -940,14 +940,14 @@ func (s *UdmUserApi) UdmSubUserEdit(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUser4GIP(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmSubUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" || body.SubNum == "" || body.StaticIp == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -979,14 +979,14 @@ func (s *UdmUserApi) UdmSubUser4GIP(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUserSmData(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
var body model.UdmSubUser
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.Imsi == "" || body.SubNum == "" || body.SmData == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -1020,7 +1020,7 @@ func (s *UdmUserApi) UdmSubUserRemove(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
imsi := ctx.Param(r, "imsi")
if neId == "" || imsi == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -1055,7 +1055,7 @@ func (s *UdmUserApi) UdmSubUserRemoves(w http.ResponseWriter, r *http.Request) {
imsi := ctx.Param(r, "imsi")
num := ctx.Param(r, "num")
if neId == "" || imsi == "" || num == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -1092,16 +1092,16 @@ func (s *UdmUserApi) UdmSubUserExport(w http.ResponseWriter, r *http.Request) {
}
err := ctx.ShouldBindJSON(r, &body)
if err != nil || body.NeId == "" || body.Type == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
if !(body.Type == "csv" || body.Type == "txt") {
ctx.JSON(w, 200, result.ErrMsg("导出文件类型支持csv、txt"))
ctx.JSON(w, 200, result.ErrMsg("Export file type support csv、txt"))
return
}
neId := "-"
neId := ""
list := s.subUser.List(model.UdmSubUser{NeID: neId})
// 文件名
fileName := fmt.Sprintf("OMC_AUTH_USER_EXPORT_%s_%d.%s", neId, time.Now().UnixMilli(), body.Type)
@@ -1145,7 +1145,7 @@ func (s *UdmUserApi) UdmSubUserExport(w http.ResponseWriter, r *http.Request) {
func (s *UdmUserApi) UdmSubUserImport(w http.ResponseWriter, r *http.Request) {
neId := ctx.Param(r, "neId")
if neId == "" {
ctx.JSON(w, 400, result.CodeMsg(400, "参数错误"))
ctx.JSON(w, 400, result.CodeMsg(400, "parameter error"))
return
}
@@ -1156,7 +1156,7 @@ func (s *UdmUserApi) UdmSubUserImport(w http.ResponseWriter, r *http.Request) {
return
}
if !(strings.HasSuffix(fileHeader.Filename, ".csv") || strings.HasSuffix(fileHeader.Filename, ".txt")) {
ctx.JSON(w, 200, result.ErrMsg("请上传.csv、.txt格式文件内容字段imsi,msisdn,ambr,nssai,arfb,sar,rat,cn,smf_sel,sm_dat,eps_dat"))
ctx.JSON(w, 200, result.ErrMsg("Please upload files in. csv and. txt formats with content fields: imsi,msisdn,ambr,nssai,arfb,sar,rat,cn,smf_sel,sm_dat,eps_dat"))
return
}

View File

@@ -4,7 +4,7 @@ import (
"strings"
"ems.agt/features/udm_user/model"
"ems.agt/lib/core/redis"
"ems.agt/src/framework/redis"
)
// phoneImsiList 获取所有imsi

View File

@@ -11,6 +11,7 @@ import (
"ems.agt/lib/log"
"ems.agt/lib/services"
"ems.agt/restagent/config"
tokenConst "ems.agt/src/framework/constants/token"
"github.com/go-resty/resty/v2"
"github.com/gorilla/mux"
)
@@ -129,6 +130,7 @@ func GetUEInfoFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -192,6 +194,7 @@ func GetUENumFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).
@@ -255,6 +258,7 @@ func GetNBInfoFromNF(w http.ResponseWriter, r *http.Request) {
resp, err := client.R().
EnableTrace().
SetHeaders(map[string]string{tokenConst.HEADER_KEY: r.Header.Get(tokenConst.HEADER_KEY)}).
SetHeaders(map[string]string{"accessToken": token}).
SetHeaders(map[string]string{"User-Agent": config.GetDefaultUserAgent()}).
SetHeaders(map[string]string{"Content-Type": "application/json;charset=UTF-8"}).