add action,login log
This commit is contained in:
@@ -50,6 +50,7 @@ func (l *AdminEditLogic) AdminEdit(in *admin.AdminEditRequest) (*admin.Response,
|
||||
return l.fail(utils.ErrorEncryptAesError)
|
||||
}
|
||||
modelObj := model.AdminModel{}.Init()
|
||||
var action = utils.ActionAdd{}
|
||||
if in.Id > utils.NumberZero && info.Id < utils.NumberOne {
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
info = dao.Admin{}
|
||||
@@ -80,6 +81,8 @@ func (l *AdminEditLogic) AdminEdit(in *admin.AdminEditRequest) (*admin.Response,
|
||||
return l.fail(utils.ErrorExistUser)
|
||||
}
|
||||
}
|
||||
action.Type = utils.LogActionTypeEdit
|
||||
action.OldContent = info
|
||||
|
||||
info.AdminId = int(adminInfo.ID)
|
||||
info.AdminName = adminInfo.Name
|
||||
@@ -96,9 +99,10 @@ func (l *AdminEditLogic) AdminEdit(in *admin.AdminEditRequest) (*admin.Response,
|
||||
info.Email = in.Email
|
||||
info.Avatar = in.Avatar
|
||||
var err error
|
||||
var row int64
|
||||
if info.Id > utils.NumberZero {
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(info.Id))}}
|
||||
_, err = modelObj.Edit(w, info)
|
||||
row, err = modelObj.Edit(w, info)
|
||||
} else {
|
||||
salt := utils.GetRandstring(utils.NumberFive)
|
||||
pwd := utils.GetSaltPassword(salt, in.Password)
|
||||
@@ -106,12 +110,20 @@ func (l *AdminEditLogic) AdminEdit(in *admin.AdminEditRequest) (*admin.Response,
|
||||
info.Password = pwd
|
||||
info.Salt = salt
|
||||
err = modelObj.Init().Create(&info)
|
||||
row = info.Id
|
||||
action.Type = utils.LogActionTypeAdd
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.ModuleName = utils.LogActionModuleAdmin
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(info.Id)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,14 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
admin "lone-services/rpc/admin/pb"
|
||||
"lone-services/services/admin/internal/dao"
|
||||
"lone-services/services/admin/internal/model"
|
||||
"lone-services/services/admin/internal/svc"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
@@ -24,7 +30,96 @@ func NewAdminItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminI
|
||||
}
|
||||
|
||||
func (l *AdminItemsLogic) AdminItems(in *admin.AdminItemsRequest) (*admin.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
modelObj := model.AdminModel{}.Init()
|
||||
w := modelbase.Params{
|
||||
Page: int(in.Page),
|
||||
Size: int(in.Size),
|
||||
Order: "id desc",
|
||||
}
|
||||
|
||||
return &admin.Response{}, nil
|
||||
w.Like = make(map[string]string)
|
||||
eq := make(map[string]string)
|
||||
if len(in.Name) > utils.NumberZero {
|
||||
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
|
||||
}
|
||||
if len(in.Phone) > utils.NumberZero {
|
||||
phone := utils.GetSearchPhone(in.Phone)
|
||||
if len(phone) > utils.NumberZero {
|
||||
w.Like["phone LIKE ? "] = "%%" + phone + "%%"
|
||||
}
|
||||
}
|
||||
if len(in.Email) > utils.NumberZero {
|
||||
w.Like["email LIKE ? "] = "%%" + in.Email + "%%"
|
||||
}
|
||||
if in.Status > utils.NumberZero {
|
||||
eq["status"] = strconv.Itoa(int(in.Status))
|
||||
}
|
||||
|
||||
if len(eq) > utils.NumberZero {
|
||||
w.Eq = eq
|
||||
}
|
||||
|
||||
var data []dao.AdminInfo
|
||||
var list []dao.AdminItemsRet
|
||||
items, _ := modelObj.Page(w, &data)
|
||||
roleInfos := l.getRoleInfos(data)
|
||||
for _, item := range data {
|
||||
var roles []dao.RoleNameItems
|
||||
for _, role := range strings.Split(item.Roles, utils.DecollatorComma) {
|
||||
if _, ok := roleInfos[role]; ok {
|
||||
roles = append(roles, roleInfos[role])
|
||||
}
|
||||
}
|
||||
|
||||
mobile, dErr := utils.DecryptPhone(item.Phone)
|
||||
if dErr == nil {
|
||||
item.Phone = mobile
|
||||
}
|
||||
|
||||
list = append(list, dao.AdminItemsRet{
|
||||
AdminInfo: item,
|
||||
RoleInfo: roles,
|
||||
})
|
||||
}
|
||||
items.Items = list
|
||||
|
||||
return l.ok(items)
|
||||
}
|
||||
|
||||
func (l *AdminItemsLogic) getRoleInfos(data []dao.AdminInfo) map[string]dao.RoleNameItems {
|
||||
var ids []string
|
||||
for _, item := range data {
|
||||
ids = append(ids, strings.Split(item.Roles, utils.DecollatorComma)...)
|
||||
}
|
||||
|
||||
w := modelbase.Params{In: map[string][]string{"id in ?": ids}}
|
||||
var items []dao.RoleNameItems
|
||||
retData := make(map[string]dao.RoleNameItems)
|
||||
|
||||
err := model.RoleModel{}.Init().Items(w, &items)
|
||||
if err != nil {
|
||||
return retData
|
||||
}
|
||||
|
||||
w = modelbase.Params{}
|
||||
var serversItems []dao.ServicesNames
|
||||
pErr := model.ServicesModel{}.Init().Items(w, &serversItems)
|
||||
serverIds := make(map[int]string)
|
||||
if pErr == nil {
|
||||
for _, item := range serversItems {
|
||||
serverIds[int(item.Id)] = item.Name
|
||||
}
|
||||
}
|
||||
for i := utils.NumberZero; i < len(items); i++ {
|
||||
serverName := utils.StringEmpty
|
||||
if _, ok := serverIds[int(items[i].ServiceId)]; ok {
|
||||
serverName = serverIds[int(items[i].ServiceId)] + utils.DecollatorColon
|
||||
}
|
||||
retData[strconv.Itoa(int(items[i].Id))] = dao.RoleNameItems{
|
||||
Id: items[i].Id,
|
||||
Name: serverName + items[i].Name,
|
||||
}
|
||||
}
|
||||
|
||||
return retData
|
||||
}
|
||||
|
||||
@@ -51,18 +51,20 @@ func (l *AdminStatusLogic) AdminStatus(in *admin.StatusRequest) (*admin.Response
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
action.OldContent = info
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleAdmin
|
||||
info.Status = uint8(in.Status)
|
||||
info.Reason = in.Reason
|
||||
info.AdminName = adminInfo.Name
|
||||
info.AdminId = adminInfo.ID
|
||||
_, editErr := modelObj.Edit(w, info)
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
action.NewContent = info
|
||||
_ = utils.GetActionStruct(adminInfo, action)
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleAdmin
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,17 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
admin "lone-services/rpc/admin/pb"
|
||||
"lone-services/services/admin/internal/dao"
|
||||
"lone-services/services/admin/internal/model"
|
||||
"lone-services/services/admin/internal/svc"
|
||||
"lone-services/services/admin/validator"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
@@ -12,6 +20,7 @@ type AuthorityEditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewAuthorityEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AuthorityEditLogic {
|
||||
@@ -23,7 +32,305 @@ func NewAuthorityEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Aut
|
||||
}
|
||||
|
||||
func (l *AuthorityEditLogic) AuthorityEdit(in *admin.AuthorityEditRequest) (*admin.Response, error) {
|
||||
// todo: add your logic here and delete this line
|
||||
var v validator.AuthorityEditValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if adminInfo.ID < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNoLoginInfo)
|
||||
}
|
||||
edit, dErr := l.getData(adminInfo, in)
|
||||
if dErr != utils.Ok {
|
||||
return l.fail(dErr)
|
||||
}
|
||||
modelObj := model.AuthorityModel{}.Init()
|
||||
var err error
|
||||
jErr, jsonData := l.getJsonData(in)
|
||||
if jErr != utils.Ok {
|
||||
return l.fail(jErr)
|
||||
}
|
||||
id := in.Id
|
||||
var row int64
|
||||
var action utils.ActionAdd
|
||||
if id > utils.NumberZero {
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}}
|
||||
info := dao.Authority{}
|
||||
err = modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
action.Type = utils.LogActionTypeEdit
|
||||
action.OldContent = info
|
||||
edit.Id = info.Id
|
||||
edit.Type = info.Type
|
||||
edit.Sort = info.Sort
|
||||
edit.ServiceId = info.ServiceId
|
||||
edit.Status = info.Status
|
||||
w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(info.Id, utils.NumberTen)}}
|
||||
if edit.Type == dao.TypeData {
|
||||
edit.DataIds = info.DataIds
|
||||
ids := strings.Split(info.DataIds, ",")
|
||||
eId, _ := strconv.Atoi(ids[utils.NumberZero])
|
||||
eId1, _ := strconv.Atoi(ids[utils.NumberOne])
|
||||
eId2, _ := strconv.Atoi(ids[utils.NumberTwo])
|
||||
upW := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(eId)}}
|
||||
l.setJsonData(&edit, int64(eId), "base", jsonData, in)
|
||||
_, err = modelObj.Edit(upW, edit)
|
||||
l.setJsonData(&edit, int64(eId1), "department", jsonData, in)
|
||||
upW.Eq["id"] = strconv.Itoa(eId1)
|
||||
_, err = modelObj.Edit(upW, edit)
|
||||
l.setJsonData(&edit, int64(eId2), "oneself", jsonData, in)
|
||||
upW.Eq["id"] = strconv.Itoa(eId2)
|
||||
row, err = modelObj.Edit(upW, edit)
|
||||
|
||||
return &admin.Response{}, nil
|
||||
} else {
|
||||
row, err = modelObj.Edit(w, edit)
|
||||
}
|
||||
} else {
|
||||
if edit.Type == dao.TypeData {
|
||||
var ids []string
|
||||
l.setJsonData(&edit, utils.NumberZero, "base", jsonData, in)
|
||||
err = modelObj.Create(&edit)
|
||||
ids = append(ids, strconv.FormatInt(edit.Id, utils.NumberTen))
|
||||
l.setJsonData(&edit, utils.NumberZero, "department", jsonData, in)
|
||||
err = modelObj.Create(&edit)
|
||||
ids = append(ids, strconv.FormatInt(edit.Id, utils.NumberTen))
|
||||
l.setJsonData(&edit, utils.NumberZero, "oneself", jsonData, in)
|
||||
err = modelObj.Create(&edit)
|
||||
row = edit.Id
|
||||
ids = append(ids, strconv.FormatInt(edit.Id, utils.NumberTen))
|
||||
|
||||
jsonIds := dao.AuthorityUpJsonIds{
|
||||
DataIds: strings.Join(ids, ","),
|
||||
}
|
||||
jsonW := modelbase.Params{In: map[string][]string{"id": ids}}
|
||||
modelObj.Edit(jsonW, &jsonIds)
|
||||
|
||||
} else {
|
||||
err = modelObj.Create(&edit)
|
||||
id = edit.Id
|
||||
row = id
|
||||
}
|
||||
action.Type = utils.LogActionTypeAdd
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = edit
|
||||
action.ModuleName = utils.LogActionModuleAuthority
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
|
||||
return l.ok(id)
|
||||
}
|
||||
|
||||
func (l *AuthorityEditLogic) getData(adminInfo utils.UserInfo, in *admin.AuthorityEditRequest) (dao.Authority, utils.Status) {
|
||||
edit := dao.Authority{
|
||||
Name: in.Name,
|
||||
Type: uint8(in.Type),
|
||||
Sort: l.getSort(in.ParentId, in.ServiceId),
|
||||
Description: in.Description,
|
||||
Icon: in.Icon,
|
||||
Identification: in.Identification,
|
||||
ServiceId: in.ServiceId,
|
||||
ParentId: in.ParentId,
|
||||
Api: dao.NoData,
|
||||
ViewPath: in.ViewPath,
|
||||
Path: in.Path,
|
||||
IsShow: uint8(in.IsShow),
|
||||
AdminId: adminInfo.ID,
|
||||
AdminName: adminInfo.Name,
|
||||
}
|
||||
|
||||
edit.Path = "/" + strings.TrimLeft(edit.Path, "/")
|
||||
|
||||
if edit.ParentId < utils.NumberOne {
|
||||
edit.ParentId = utils.NumberZero
|
||||
}
|
||||
|
||||
check := l.checkName(in.Id, map[string]string{
|
||||
"service_id": strconv.FormatInt(edit.ServiceId, utils.NumberTen),
|
||||
"name": edit.Name,
|
||||
})
|
||||
if !check {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "权限名称已存在")
|
||||
}
|
||||
|
||||
check = l.check(edit.Id, map[string]string{
|
||||
"service_id": strconv.FormatInt(edit.ServiceId, utils.NumberTen),
|
||||
"identification": edit.Identification,
|
||||
})
|
||||
if !check {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "权限标识已存在")
|
||||
}
|
||||
|
||||
if edit.Type == dao.TypeWeb {
|
||||
if len(edit.ViewPath) < utils.NumberOne {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "组件路径不能为空")
|
||||
}
|
||||
check := l.check(in.Id, map[string]string{"path": edit.Path, "service_id": strconv.FormatInt(edit.ServiceId, utils.NumberTen)})
|
||||
if !check {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "PATH已存在")
|
||||
}
|
||||
} else if edit.Type == dao.TypeButton {
|
||||
edit.Icon = utils.StringEmpty
|
||||
if len(edit.Api) < utils.NumberOne {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "API不能为空")
|
||||
}
|
||||
edit.Api = in.Api
|
||||
edit.Path = dao.NoData
|
||||
edit.ViewPath = dao.NoData
|
||||
} else if edit.Type == dao.TypeDir {
|
||||
edit.ViewPath = dao.NoData
|
||||
check := l.check(in.Id, map[string]string{"path": edit.Path, "service_id": strconv.FormatInt(edit.ServiceId, utils.NumberTen)})
|
||||
if !check {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "PATH已存在")
|
||||
}
|
||||
} else if edit.Type == dao.TypeData {
|
||||
if len(edit.Api) < utils.NumberOne {
|
||||
return edit, utils.SetError(utils.ErrorMissingParams, "API不能为空")
|
||||
}
|
||||
edit.Icon = utils.StringEmpty
|
||||
edit.Api = in.Api
|
||||
edit.Path = dao.NoData
|
||||
edit.ViewPath = dao.NoData
|
||||
}
|
||||
|
||||
if edit.ParentId == utils.NumberZero {
|
||||
edit.ParentIds = utils.StringZero
|
||||
} else {
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(edit.ParentId, utils.NumberTen)}}
|
||||
info := dao.Authority{}
|
||||
err := model.AuthorityModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
return edit, utils.Ok
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return edit, utils.ErrorNotFund
|
||||
}
|
||||
edit.ParentIds = info.ParentIds + "," + strconv.FormatInt(edit.ParentId, utils.NumberTen)
|
||||
}
|
||||
|
||||
idsArr := strings.SplitAfter(edit.ParentIds, ",")
|
||||
edit.Level = uint8(len(idsArr))
|
||||
|
||||
return edit, utils.Ok
|
||||
}
|
||||
|
||||
func (l *AuthorityEditLogic) check(id int64, check map[string]string) bool {
|
||||
w := modelbase.Params{Eq: check}
|
||||
info := dao.AuthorityCheck{}
|
||||
_ = model.AuthorityModel{}.Init().GetOne(w, &info)
|
||||
if id > utils.NumberZero && info.Id == id {
|
||||
return true
|
||||
}
|
||||
if info.Id > utils.NumberZero {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *AuthorityEditLogic) checkName(id int64, check map[string]string) bool {
|
||||
w := modelbase.Params{Eq: check}
|
||||
info := dao.AuthorityCheck{}
|
||||
_ = model.AuthorityModel{}.Init().GetOne(w, &info)
|
||||
if id > utils.NumberZero && info.Id == id {
|
||||
return true
|
||||
}
|
||||
if info.Id > utils.NumberZero {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (l *AuthorityEditLogic) getSort(pid, serviceId int64) uint8 {
|
||||
if pid < utils.NumberZero {
|
||||
pid = utils.NumberZero
|
||||
}
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"parent_id": strconv.FormatInt(pid, utils.NumberTen),
|
||||
"project_id": strconv.FormatInt(serviceId, utils.NumberTen)},
|
||||
Order: "sort DESC",
|
||||
}
|
||||
info := dao.Authority{}
|
||||
err := model.AuthorityModel{}.Init().GetOne(w, &info)
|
||||
if err != nil || info.Id < utils.NumberOne {
|
||||
return utils.NumberOne
|
||||
}
|
||||
return info.Sort + utils.NumberOne
|
||||
}
|
||||
|
||||
func (l *AuthorityEditLogic) setJsonData(edit *dao.Authority, id int64, name string, data map[string]string, in *admin.AuthorityEditRequest) {
|
||||
edit.Id = id
|
||||
if name == "base" {
|
||||
edit.Name = in.Name + "-全部"
|
||||
edit.JsonDataBase = data["base"]
|
||||
edit.JsonData = data["all"]
|
||||
edit.JsonTreeData = data["tree_all"]
|
||||
} else if name == "department" {
|
||||
edit.JsonData = data["department"]
|
||||
edit.Name = in.Name + "-部门"
|
||||
edit.JsonTreeData = data["tree_department"]
|
||||
edit.Identification = in.Identification + ":department"
|
||||
} else if name == "oneself" {
|
||||
edit.JsonData = data["oneself"]
|
||||
edit.Name = in.Name + "-个人"
|
||||
edit.JsonTreeData = data["tree_oneself"]
|
||||
edit.Identification = in.Identification + ":oneself"
|
||||
}
|
||||
if id == utils.NumberZero {
|
||||
edit.Sort += utils.NumberOne
|
||||
} else {
|
||||
info := dao.AuthoritySort{}
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(id, utils.NumberTen)}}
|
||||
_ = model.AuthorityModel{}.Init().GetOne(w, &info)
|
||||
edit.Sort = info.Sort
|
||||
}
|
||||
}
|
||||
func (l *AuthorityEditLogic) getJsonData(in *admin.AuthorityEditRequest) (utils.Status, map[string]string) {
|
||||
data := map[string]string{}
|
||||
if in.Type != dao.TypeData {
|
||||
return utils.Ok, data
|
||||
}
|
||||
var check map[string]interface{}
|
||||
// 解析JSON字符串到map
|
||||
err := jsoniter.Unmarshal([]byte(in.DataBaseStr), &check)
|
||||
if err != nil {
|
||||
return utils.ErrorJsonDataError, data
|
||||
}
|
||||
// 解析JSON字符串到map
|
||||
err = jsoniter.Unmarshal([]byte(in.DataAll), &check)
|
||||
if err != nil {
|
||||
return utils.ErrorJsonDataError, data
|
||||
}
|
||||
// 解析JSON字符串到map
|
||||
err = jsoniter.Unmarshal([]byte(in.DataDepartment), &check)
|
||||
if err != nil {
|
||||
return utils.ErrorJsonDataError, data
|
||||
}
|
||||
// 解析JSON字符串到map
|
||||
err = jsoniter.Unmarshal([]byte(in.DataOneself), &check)
|
||||
if err != nil {
|
||||
return utils.ErrorJsonDataError, data
|
||||
}
|
||||
data["base"] = in.DataBaseStr
|
||||
data["all"] = in.DataAll
|
||||
data["department"] = in.DataDepartment
|
||||
data["oneself"] = in.DataOneself
|
||||
data["tree_all"] = in.DataTreeAll
|
||||
data["tree_department"] = in.DataTreeDepartment
|
||||
data["tree_oneself"] = in.DataTreeOneself
|
||||
return utils.Ok, data
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (l *AuthoritySortLogic) AuthoritySort(in *admin.AuthoritySortRequest) (*adm
|
||||
info := dao.AuthoritySort{}
|
||||
modelObj := model.AuthorityModel{}.Init()
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}}
|
||||
err := modelObj.Items(w, &info)
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
@@ -61,15 +61,20 @@ func (l *AuthoritySortLogic) AuthoritySort(in *admin.AuthoritySortRequest) (*adm
|
||||
}
|
||||
w.Other = map[string]string{sortKey: strconv.Itoa(int(info.Sort))}
|
||||
other := dao.AuthoritySort{}
|
||||
err = modelObj.Items(w, &other)
|
||||
err = modelObj.GetOne(w, &other)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
action := utils.ActionAdd{}
|
||||
action.Type = utils.LogActionTypeSort
|
||||
action.ModuleName = utils.LogActionModuleAuthority
|
||||
action.OldContent = info
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(info.Id, utils.NumberTen)}}
|
||||
|
||||
infoSort := info.Sort
|
||||
info.Sort = other.Sort
|
||||
info.AdminId = adminInfo.ID
|
||||
@@ -79,6 +84,9 @@ func (l *AuthoritySortLogic) AuthoritySort(in *admin.AuthoritySortRequest) (*adm
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
action.NewContent = info
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
action.OldContent = other
|
||||
w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(other.Id, utils.NumberTen)}}
|
||||
other.Sort = infoSort
|
||||
other.AdminId = info.AdminId
|
||||
@@ -88,6 +96,8 @@ func (l *AuthoritySortLogic) AuthoritySort(in *admin.AuthoritySortRequest) (*adm
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
action.NewContent = other
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -66,15 +66,24 @@ func (l *AuthorityStatusLogic) AuthorityStatus(in *admin.StatusRequest) (*admin.
|
||||
return l.fail(utils.ErrorAuthorityChange)
|
||||
}
|
||||
|
||||
var action utils.ActionAdd
|
||||
action.OldContent = info
|
||||
info.Status = uint8(in.Status)
|
||||
info.Reason = in.Reason
|
||||
info.AdminId = adminInfo.ID
|
||||
info.AdminName = adminInfo.Name
|
||||
_, editErr := modelObj.Edit(w, info)
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleAuthority
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ func NewLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *LoginLogic
|
||||
}
|
||||
|
||||
func (l *LoginLogic) Login(in *admin.LoginRequest) (*admin.Response, error) {
|
||||
l.Logger.Error("u:", in.Username, "p:", in.Password, "|")
|
||||
var v validator.LoginValidator
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
@@ -44,7 +43,8 @@ func (l *LoginLogic) Login(in *admin.LoginRequest) (*admin.Response, error) {
|
||||
l.Logger.Error(dErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
adminInfo := utils.GetUserFromCtx(l.ctx)
|
||||
adminInfo.Name = in.Username
|
||||
var info dao.Admin
|
||||
w := modelbase.Params{Eq: map[string]string{"phone": phone}}
|
||||
modelObj := model.AdminModel{}.Init()
|
||||
@@ -54,12 +54,14 @@ func (l *LoginLogic) Login(in *admin.LoginRequest) (*admin.Response, error) {
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
utils.SetLoginLog(adminInfo, false, utils.ErrorNotFund.Msg)
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
pwd := utils.GetSaltPassword(info.Salt, in.Password)
|
||||
eq := utils.EqualsPassword(pwd, info.Password)
|
||||
if !eq {
|
||||
utils.SetLoginLog(adminInfo, false, utils.ErrorPwdError.Msg)
|
||||
return l.fail(utils.ErrorPwdError)
|
||||
}
|
||||
|
||||
@@ -85,6 +87,8 @@ func (l *LoginLogic) Login(in *admin.LoginRequest) (*admin.Response, error) {
|
||||
retData.Refresh = utils.MD5Encrypt(data.Phone + retData.Token)
|
||||
|
||||
l.setLogin(retData.Token, retData.Refresh, data)
|
||||
adminInfo.ID = data.Id
|
||||
utils.SetLoginLog(adminInfo, true, utils.StringEmpty)
|
||||
return l.ok(retData)
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,22 @@ func (l *PasswordLogic) Password(in *admin.PasswordRequest) (*admin.Response, er
|
||||
|
||||
pwd := utils.GetSaltPassword(info.Salt, in.Password)
|
||||
pwd, _ = utils.EncryptPassword(pwd)
|
||||
var action utils.ActionAdd
|
||||
action.OldContent = info
|
||||
info.Password = pwd
|
||||
info.AdminId = int(adminInfo.ID)
|
||||
info.AdminName = adminInfo.Name
|
||||
_, editErr := modelObj.Edit(w, info)
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Type = utils.LogActionTypePassword
|
||||
action.ModuleName = utils.LogActionModuleAdmin
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ func (l *RoleEditLogic) RoleEdit(in *admin.RoleEditRequest) (*admin.Response, er
|
||||
modelObj := model.RoleModel{}.Init()
|
||||
id := in.Id
|
||||
var editErr error
|
||||
var row int64
|
||||
var action utils.ActionAdd
|
||||
if id > utils.NumberZero {
|
||||
if check.Id > utils.NumberZero && check.Id != id {
|
||||
return l.fail(utils.ErrorExist)
|
||||
@@ -71,18 +73,21 @@ func (l *RoleEditLogic) RoleEdit(in *admin.RoleEditRequest) (*admin.Response, er
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
action.OldContent = info
|
||||
edit.Id = info.Id
|
||||
edit.Status = info.Status
|
||||
|
||||
w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(info.Id, utils.NumberTen)}}
|
||||
_, editErr = modelObj.Edit(w, edit)
|
||||
row, editErr = modelObj.Edit(w, edit)
|
||||
action.Type = utils.LogActionTypeEdit
|
||||
} else {
|
||||
if check.Id > utils.NumberZero {
|
||||
return l.fail(utils.ErrorExist)
|
||||
}
|
||||
editErr = modelObj.Create(&edit)
|
||||
id = edit.Id
|
||||
row = id
|
||||
action.Type = utils.LogActionTypeAdd
|
||||
}
|
||||
|
||||
if editErr != nil {
|
||||
@@ -90,6 +95,11 @@ func (l *RoleEditLogic) RoleEdit(in *admin.RoleEditRequest) (*admin.Response, er
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = edit
|
||||
action.ModuleName = utils.LogActionModuleRole
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(id)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,15 +50,24 @@ func (l *RoleStatusLogic) RoleStatus(in *admin.StatusRequest) (*admin.Response,
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
var action utils.ActionAdd
|
||||
action.OldContent = info
|
||||
info.Status = uint8(in.Status)
|
||||
info.Reason = in.Reason
|
||||
info.AdminId = adminInfo.ID
|
||||
info.AdminName = adminInfo.Name
|
||||
_, editErr := modelObj.Edit(w, info)
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleRole
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
@@ -47,6 +47,9 @@ func (l *ServiceEditLogic) ServiceEdit(in *admin.ServiceEditRequest) (*admin.Res
|
||||
|
||||
modelObj := model.ServicesModel{}.Init()
|
||||
var err error
|
||||
var row int64
|
||||
var action utils.ActionAdd
|
||||
|
||||
if in.Id > utils.NumberZero {
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
info := dao.Services{}
|
||||
@@ -58,10 +61,14 @@ func (l *ServiceEditLogic) ServiceEdit(in *admin.ServiceEditRequest) (*admin.Res
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
action.OldContent = info
|
||||
edit.Id = info.Id
|
||||
_, err = modelObj.Edit(w, &edit)
|
||||
row, err = modelObj.Edit(w, &edit)
|
||||
action.Type = utils.LogActionTypeEdit
|
||||
} else {
|
||||
err = modelObj.Create(&edit)
|
||||
row = edit.Id
|
||||
action.Type = utils.LogActionTypeAdd
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -69,5 +76,10 @@ func (l *ServiceEditLogic) ServiceEdit(in *admin.ServiceEditRequest) (*admin.Res
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = edit
|
||||
action.ModuleName = utils.LogActionModuleService
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(edit.Id)
|
||||
}
|
||||
|
||||
@@ -50,15 +50,23 @@ func (l *ServiceStatusLogic) ServiceStatus(in *admin.StatusRequest) (*admin.Resp
|
||||
return l.fail(utils.ErrorNotFund)
|
||||
}
|
||||
|
||||
var action utils.ActionAdd
|
||||
action.OldContent = info
|
||||
info.Status = uint8(in.Status)
|
||||
info.Reason = in.Reason
|
||||
info.AdminName = adminInfo.Name
|
||||
info.AdminId = adminInfo.ID
|
||||
_, editErr := modelObj.Edit(w, info)
|
||||
row, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail)
|
||||
}
|
||||
|
||||
if row > utils.NumberZero {
|
||||
action.NewContent = info
|
||||
action.Type = utils.LogActionTypeStatus
|
||||
action.ModuleName = utils.LogActionModuleService
|
||||
utils.SetActionLog(adminInfo, action)
|
||||
}
|
||||
return l.ok(utils.NumberOne)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user