mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-04 23:52:53 +08:00
update
This commit is contained in:
@@ -47,9 +47,13 @@ func (p *procApi) KillProcess(ctx *gin.Context, req model.ProcessUuidReq) (err e
|
||||
func (p *procApi) StartProcess(ctx *gin.Context, req model.ProcessUuidReq) (err error) {
|
||||
prod, err := logic.ProcessCtlLogic.GetProcess(req.Uuid)
|
||||
if err != nil { // 进程不存在则创建
|
||||
proc, err1 := logic.ProcessCtlLogic.RunNewProcess(repository.ProcessRepository.GetProcessConfigById(req.Uuid))
|
||||
if err1 != nil {
|
||||
return err1
|
||||
proConfig, err := repository.ProcessRepository.GetProcessConfigById(req.Uuid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
proc, err := logic.ProcessCtlLogic.RunNewProcess(proConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logic.ProcessCtlLogic.AddProcess(req.Uuid, proc)
|
||||
return nil
|
||||
@@ -96,9 +100,9 @@ func (p *procApi) UpdateProcessConfig(ctx *gin.Context, req model.Process) (err
|
||||
}
|
||||
|
||||
func (p *procApi) GetProcessConfig(ctx *gin.Context, req model.ProcessUuidReq) (err error) {
|
||||
data := repository.ProcessRepository.GetProcessConfigById(req.Uuid)
|
||||
if data.Uuid == 0 {
|
||||
return errors.New("no information found")
|
||||
data, err := repository.ProcessRepository.GetProcessConfigById(req.Uuid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rOk(ctx, "success", data)
|
||||
return
|
||||
|
@@ -150,7 +150,10 @@ func (p *processCtlLogic) ProcessStartAll() {
|
||||
}
|
||||
|
||||
func (p *processCtlLogic) RunPrcessById(id int) (*ProcessBase, error) {
|
||||
config := repository.ProcessRepository.GetProcessConfigById(id)
|
||||
config, err := repository.ProcessRepository.GetProcessConfigById(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
proc, err := p.RunNewProcess(config)
|
||||
if err != nil {
|
||||
log.Logger.Warnw("初始化启动进程失败", config.Name, "name", "err", err)
|
||||
|
@@ -6,9 +6,9 @@ type FileStruct struct {
|
||||
}
|
||||
|
||||
type FilePathHandlerReq struct {
|
||||
Path string `form:"path"`
|
||||
Path string `form:"path" binding:"required"`
|
||||
}
|
||||
|
||||
type FileReadHandlerReq struct {
|
||||
FilePath string `form:"filePath"`
|
||||
FilePath string `form:"filePath" binding:"required"`
|
||||
}
|
||||
|
@@ -31,5 +31,5 @@ type PermissionPo struct {
|
||||
}
|
||||
|
||||
type GetPermissionListReq struct {
|
||||
Account string `form:"account"`
|
||||
Account string `form:"account" binding:"required"`
|
||||
}
|
||||
|
@@ -4,7 +4,7 @@ import "github.com/lzh-1625/go_process_manager/internal/app/constants"
|
||||
|
||||
type Process struct {
|
||||
Uuid int `gorm:"primaryKey;autoIncrement;column:uuid" json:"uuid"`
|
||||
Name string `gorm:"column:name;uniqueIndex;type:text" json:"name"`
|
||||
Name string `gorm:"column:name;uniqueIndex;type:text" json:"name" binding:"required"`
|
||||
Cmd string `gorm:"column:args" json:"cmd"`
|
||||
Cwd string `gorm:"column:cwd" json:"cwd"`
|
||||
AutoRestart bool `gorm:"column:auto_restart" json:"autoRestart"`
|
||||
|
@@ -14,5 +14,5 @@ func (*Push) TableName() string {
|
||||
}
|
||||
|
||||
type PushIdReq struct {
|
||||
Id int `form:"id"`
|
||||
Id int `form:"id" binding:"required"`
|
||||
}
|
||||
|
@@ -47,5 +47,5 @@ type TaskVo struct {
|
||||
}
|
||||
|
||||
type TaskIdReq struct {
|
||||
Id int `form:"id"`
|
||||
Id int `form:"id" binding:"required"`
|
||||
}
|
||||
|
@@ -19,10 +19,10 @@ func (*User) TableName() string {
|
||||
}
|
||||
|
||||
type LoginHandlerReq struct {
|
||||
Account string `form:"account"`
|
||||
Password string `form:"password"`
|
||||
Account string `form:"account" binding:"required"`
|
||||
Password string `form:"password" binding:"required"`
|
||||
}
|
||||
|
||||
type DeleteUserReq struct {
|
||||
Account string `form:"account"`
|
||||
Account string `form:"account" binding:"required"`
|
||||
}
|
||||
|
@@ -12,7 +12,6 @@ var ProcessRepository = new(processRepository)
|
||||
|
||||
func (p *processRepository) GetAllProcessConfig() []model.Process {
|
||||
result := []model.Process{}
|
||||
|
||||
tx := db.Find(&result)
|
||||
if tx.Error != nil {
|
||||
log.Logger.Error(tx.Error)
|
||||
@@ -35,17 +34,13 @@ func (p *processRepository) GetProcessConfigByUser(username string) []model.Proc
|
||||
}
|
||||
|
||||
func (p *processRepository) UpdateProcessConfig(process model.Process) error {
|
||||
tx := db.Save(&process)
|
||||
return tx.Error
|
||||
return db.Save(&process).Error
|
||||
}
|
||||
|
||||
func (p *processRepository) AddProcessConfig(process model.Process) (int, error) {
|
||||
tx := db.Create(&process)
|
||||
if tx.Error != nil {
|
||||
log.Logger.Error(tx.Error)
|
||||
return 0, tx.Error
|
||||
}
|
||||
return process.Uuid, nil
|
||||
func (p *processRepository) AddProcessConfig(process model.Process) (id int, err error) {
|
||||
err = db.Create(&process).Error
|
||||
id = process.Uuid
|
||||
return
|
||||
}
|
||||
|
||||
func (p *processRepository) DeleteProcessConfig(uuid int) error {
|
||||
@@ -54,12 +49,7 @@ func (p *processRepository) DeleteProcessConfig(uuid int) error {
|
||||
}).Error
|
||||
}
|
||||
|
||||
func (p *processRepository) GetProcessConfigById(uuid int) model.Process {
|
||||
result := model.Process{}
|
||||
tx := db.Model(&model.Process{}).Where(&model.Process{Uuid: uuid}).First(&result)
|
||||
if tx.Error != nil {
|
||||
log.Logger.Error(tx.Error)
|
||||
return model.Process{}
|
||||
}
|
||||
return result
|
||||
func (p *processRepository) GetProcessConfigById(uuid int) (data model.Process, err error) {
|
||||
err = db.Model(&model.Process{}).Where(&model.Process{Uuid: uuid}).First(&data).Error
|
||||
return
|
||||
}
|
||||
|
@@ -1,13 +1,9 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/constants"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/model"
|
||||
"github.com/lzh-1625/go_process_manager/internal/app/repository/query"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type taskRepository struct{}
|
||||
@@ -41,11 +37,6 @@ func (t *taskRepository) DeleteTask(id int) (err error) {
|
||||
}
|
||||
|
||||
func (t *taskRepository) EditTask(data model.Task) (err error) {
|
||||
err = db.Model(&model.Task{}).Where(&model.Task{Id: data.Id}).First(&model.Task{}).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
|
||||
err = db.Model(&model.Task{}).Where(&model.Task{Id: data.Id}).Save(data).Error
|
||||
return
|
||||
}
|
||||
|
@@ -25,20 +25,14 @@ func (u *userRepository) CreateUser(user model.User) error {
|
||||
}
|
||||
|
||||
func (u *userRepository) UpdatePassword(name string, password string) error {
|
||||
tx := db.Model(&model.User{}).Where(&model.User{Account: name}).Updates(&model.User{Password: utils.Md5(password)})
|
||||
return tx.Error
|
||||
return db.Model(&model.User{}).Where(&model.User{Account: name}).Updates(&model.User{Password: utils.Md5(password)}).Error
|
||||
}
|
||||
|
||||
func (u *userRepository) DeleteUser(name string) error {
|
||||
if err := db.Model(&model.User{}).Where(&model.User{Account: name}).First(&model.User{}).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
tx := db.Delete(&model.User{Account: name})
|
||||
return tx.Error
|
||||
return db.Delete(&model.User{Account: name}).Error
|
||||
}
|
||||
|
||||
func (u *userRepository) GetUserList() []model.User {
|
||||
result := []model.User{}
|
||||
func (u *userRepository) GetUserList() (result []model.User) {
|
||||
db.Find(&result)
|
||||
return result
|
||||
return
|
||||
}
|
||||
|
Reference in New Issue
Block a user