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