service apis edit, info, items, status, names
This commit is contained in:
@@ -1,36 +1,27 @@
|
||||
package dao
|
||||
|
||||
import "pkg.local/utils"
|
||||
|
||||
// Services 项目表
|
||||
type Services struct {
|
||||
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
|
||||
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
|
||||
Remarks string `gorm:"column:remarks;type:varchar(255);default:'';comment:描述;NOT NULL" json:"remarks"`
|
||||
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
|
||||
AdminId int `gorm:"column:admin_id;type:int(11);comment:操作人员ID" json:"admin_id"`
|
||||
AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"`
|
||||
CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime" json:"create_time"`
|
||||
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime" json:"update_time"`
|
||||
}
|
||||
|
||||
type ServicesItems struct {
|
||||
Items []Services `json:"items"`
|
||||
Count int64 `json:"count"`
|
||||
Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
|
||||
Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"`
|
||||
Description string `json:"description" gorm:"description"` // 描述
|
||||
Reason string `json:"reason" gorm:"reason"` // 理由
|
||||
AdminId int64 `gorm:"column:admin_id;type:int(11);comment:操作人员ID" json:"admin_id"`
|
||||
AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"`
|
||||
}
|
||||
|
||||
// ServicesStatus 修改状态
|
||||
type ServicesStatus struct {
|
||||
Id int `json:"id"`
|
||||
Status uint8 `json:"status"`
|
||||
Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"`
|
||||
AdminId int `json:"admin_id"`
|
||||
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
|
||||
UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime" json:"update_time"`
|
||||
Id int64 `json:"id"`
|
||||
Status uint8 `json:"status"`
|
||||
Reason string `json:"reason" gorm:"reason"` // 理由
|
||||
AdminId int64 `json:"admin_id"`
|
||||
AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"`
|
||||
}
|
||||
|
||||
type ServicesNameItems struct {
|
||||
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
|
||||
type ServicesNames struct {
|
||||
Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
|
||||
Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"`
|
||||
Description string `json:"description" gorm:"description"` // 描述
|
||||
}
|
||||
|
||||
@@ -103,12 +103,12 @@ func (l *AdminItemsLogic) getRoleInfos(data []dao.AdminInfo) map[string]dao.Role
|
||||
}
|
||||
|
||||
w = modelbase.Params{}
|
||||
var serversItems []dao.ServicesNameItems
|
||||
var serversItems []dao.ServicesNames
|
||||
pErr := model.ServicesModel{}.Init().Items(w, &serversItems)
|
||||
serverIds := make(map[int]string)
|
||||
if pErr == nil {
|
||||
for _, item := range serversItems {
|
||||
serverIds[item.Id] = item.Name
|
||||
serverIds[int(item.Id)] = item.Name
|
||||
}
|
||||
}
|
||||
for i := utils.NumberZero; i < len(items); i++ {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/validator"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type ServiceEditLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewServiceEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceEditLogic {
|
||||
return &ServiceEditLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ServiceEditLogic) ServiceEdit(in *admin.ServiceEditRequest) (*admin.Response, error) {
|
||||
var v validator.ServiceEditValidator
|
||||
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), nil
|
||||
}
|
||||
edit := dao.Services{
|
||||
Name: in.Name,
|
||||
Description: in.Description,
|
||||
AdminId: adminInfo.ID,
|
||||
AdminName: adminInfo.Name,
|
||||
}
|
||||
|
||||
modelObj := model.ServicesModel{}.Init()
|
||||
var err error
|
||||
if in.Id > utils.NumberZero {
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
info := dao.Services{}
|
||||
err = modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund), nil
|
||||
}
|
||||
edit.Id = info.Id
|
||||
_, err = modelObj.Edit(w, &edit)
|
||||
} else {
|
||||
err = modelObj.Create(&edit)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
|
||||
return l.ok(edit.Id), nil
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/validator"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type ServiceInfoLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewServiceInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceInfoLogic {
|
||||
return &ServiceInfoLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ServiceInfoLogic) ServiceInfo(in *admin.InfoRequest) (*admin.Response, error) {
|
||||
var v validator.ServiceInfoValidator
|
||||
l.Logger.Error(in.Id)
|
||||
if fail := l.checkParams(in, &v); fail != nil {
|
||||
return fail, nil
|
||||
}
|
||||
|
||||
info := dao.Services{}
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
err := model.ServicesModel{}.Init().GetOne(w, &info)
|
||||
if err != nil {
|
||||
return l.fail(utils.ErrorNotFund), nil
|
||||
}
|
||||
return l.ok(info), nil
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type ServiceItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewServiceItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceItemsLogic {
|
||||
return &ServiceItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ServiceItemsLogic) ServiceItems(in *admin.ServiceItemsRequest) (*admin.Response, error) {
|
||||
modelObj := model.ServicesModel{}.Init()
|
||||
w := modelbase.Params{
|
||||
Order: "id desc",
|
||||
}
|
||||
w.Like = make(map[string]string)
|
||||
if in.Status > utils.NumberZero {
|
||||
w.Eq = map[string]string{"status": strconv.Itoa(int(in.Status))}
|
||||
}
|
||||
if len(in.Name) > utils.NumberZero {
|
||||
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
|
||||
}
|
||||
var data []dao.Services
|
||||
err := modelObj.Items(w, &data)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
return l.ok(data), nil
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/admin"
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/internal/svc"
|
||||
"context"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type ServiceNamesLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewServiceNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceNamesLogic {
|
||||
return &ServiceNamesLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ServiceNamesLogic) ServiceNames(in *admin.ServiceNameRequest) (*admin.Response, error) {
|
||||
var items []dao.ServicesNames
|
||||
modelObj := model.ServicesModel{}.Init()
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{"status": utils.StringStatusOk},
|
||||
}
|
||||
w.Like = make(map[string]string)
|
||||
if len(in.Name) > utils.NumberZero {
|
||||
w.Like["name LIKE ? "] = "%%" + in.Name + "%%"
|
||||
}
|
||||
err := modelObj.Items(w, &items)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
return l.ok(items), nil
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"admin/internal/dao"
|
||||
"admin/internal/model"
|
||||
"admin/validator"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"admin/admin"
|
||||
"admin/internal/svc"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
)
|
||||
|
||||
type ServiceStatusLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
BaseLogic
|
||||
}
|
||||
|
||||
func NewServiceStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceStatusLogic {
|
||||
return &ServiceStatusLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ServiceStatusLogic) ServiceStatus(in *admin.StatusRequest) (*admin.Response, error) {
|
||||
var v validator.ServiceStatusValidator
|
||||
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), nil
|
||||
}
|
||||
info := dao.ServicesStatus{}
|
||||
w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}}
|
||||
modelObj := model.ServicesModel{}.Init()
|
||||
err := modelObj.GetOne(w, &info)
|
||||
if err != nil {
|
||||
l.Logger.Error(err)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
return l.fail(utils.ErrorNotFund), nil
|
||||
}
|
||||
|
||||
info.Status = uint8(in.Status)
|
||||
info.Reason = in.Reason
|
||||
info.AdminName = adminInfo.Name
|
||||
info.AdminId = adminInfo.ID
|
||||
_, editErr := modelObj.Edit(w, info)
|
||||
if editErr != nil {
|
||||
l.Logger.Error(editErr)
|
||||
return l.fail(utils.Fail), nil
|
||||
}
|
||||
|
||||
return l.ok(utils.NumberOne), nil
|
||||
}
|
||||
@@ -19,6 +19,6 @@ func (m ServicesModel) Init() ServicesModel {
|
||||
return m
|
||||
}
|
||||
|
||||
func (m ServicesModel) Create(data *dao.Admin) error {
|
||||
func (m ServicesModel) Create(data *dao.Services) error {
|
||||
return m.Base.Create(data)
|
||||
}
|
||||
|
||||
@@ -67,3 +67,28 @@ func (s *AdminServer) LoginInfo(ctx context.Context, in *admin.AdminEmptyRequest
|
||||
l := logic.NewLoginInfoLogic(ctx, s.svcCtx)
|
||||
return l.LoginInfo(in)
|
||||
}
|
||||
|
||||
func (s *AdminServer) ServiceInfo(ctx context.Context, in *admin.InfoRequest) (*admin.Response, error) {
|
||||
l := logic.NewServiceInfoLogic(ctx, s.svcCtx)
|
||||
return l.ServiceInfo(in)
|
||||
}
|
||||
|
||||
func (s *AdminServer) ServiceEdit(ctx context.Context, in *admin.ServiceEditRequest) (*admin.Response, error) {
|
||||
l := logic.NewServiceEditLogic(ctx, s.svcCtx)
|
||||
return l.ServiceEdit(in)
|
||||
}
|
||||
|
||||
func (s *AdminServer) ServiceItems(ctx context.Context, in *admin.ServiceItemsRequest) (*admin.Response, error) {
|
||||
l := logic.NewServiceItemsLogic(ctx, s.svcCtx)
|
||||
return l.ServiceItems(in)
|
||||
}
|
||||
|
||||
func (s *AdminServer) ServiceStatus(ctx context.Context, in *admin.StatusRequest) (*admin.Response, error) {
|
||||
l := logic.NewServiceStatusLogic(ctx, s.svcCtx)
|
||||
return l.ServiceStatus(in)
|
||||
}
|
||||
|
||||
func (s *AdminServer) ServiceNames(ctx context.Context, in *admin.ServiceNameRequest) (*admin.Response, error) {
|
||||
l := logic.NewServiceNamesLogic(ctx, s.svcCtx)
|
||||
return l.ServiceNames(in)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user