feat:完善项目
This commit is contained in:
103
app/controller/work/person.go
Normal file
103
app/controller/work/person.go
Normal file
@ -0,0 +1,103 @@
|
||||
package work
|
||||
|
||||
import (
|
||||
model2 "ArmedPolice/app/common/model"
|
||||
"ArmedPolice/app/controller/basic"
|
||||
"ArmedPolice/app/model"
|
||||
"ArmedPolice/app/service"
|
||||
"ArmedPolice/serve/orm"
|
||||
"errors"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Person struct{ *service.Session }
|
||||
|
||||
type PersonHandle func(session *service.Session) *Person
|
||||
|
||||
func (c *Person) List() (*basic.PageDataResponse, error) {
|
||||
return &basic.PageDataResponse{Data: nil, Count: 0}, nil
|
||||
}
|
||||
|
||||
// Examine 审核操作
|
||||
func (c *Person) Examine(id uint64, status int, remark string, isAssist int) error {
|
||||
_status := model2.WorkProgressStatus(status)
|
||||
|
||||
if _status != model2.WorkProgressStatusForAgree && _status != model2.WorkProgressStatusForRefuse {
|
||||
return errors.New("操作错误,审核状态异常")
|
||||
}
|
||||
mWorkInstance := model.NewWorkInstance()
|
||||
mWorkInstance.ID = id
|
||||
|
||||
isExist, err := model2.FirstField(mWorkInstance.WorkInstance, []string{"id", "schedule", "status"})
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,工单信息不存在")
|
||||
} else if mWorkInstance.Status == model2.WorkInstanceStatusForComplete {
|
||||
return errors.New("操作错误,当前工单信息已结束")
|
||||
}
|
||||
// 查询当前工单所在流程的信息
|
||||
mWorkSchedule := model.NewWorkSchedule()
|
||||
mWorkSchedule.ID = mWorkInstance.Schedule
|
||||
|
||||
if isExist, err = model2.First(mWorkSchedule); err != nil {
|
||||
return err
|
||||
} else if !isExist {
|
||||
return errors.New("操作错误,未知的工单流程")
|
||||
}
|
||||
// 验证审核权限
|
||||
isAuth := false
|
||||
|
||||
if isAuth, err = mWorkSchedule.ValidateAuth(c.UID); err != nil {
|
||||
return err
|
||||
} else if !isAuth {
|
||||
return errors.New("操作错误,无权限审批")
|
||||
}
|
||||
if err = orm.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||
// 工单流程记录
|
||||
mWorkProgress := model.NewWorkProgress()
|
||||
mWorkProgress.UID = c.UID
|
||||
mWorkProgress.WorkID = id
|
||||
mWorkProgress.ScheduleID = mWorkSchedule.ID
|
||||
mWorkProgress.Status = _status
|
||||
mWorkProgress.Remark = remark
|
||||
|
||||
if err = model2.Create(mWorkProgress.WorkProgress, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
workUpdates := map[string]interface{}{
|
||||
"status": model2.WorkInstanceStatusForComplete, "updated_at": time.Now(),
|
||||
}
|
||||
// 下一流程
|
||||
newNextScheduleInfo := new(model.WorkScheduleInfo)
|
||||
|
||||
// 拒绝审批,工单直接结束
|
||||
if _status == model2.WorkProgressStatusForRefuse {
|
||||
goto FINISH
|
||||
}
|
||||
if newNextScheduleInfo, err = mWorkSchedule.NextSchedule(); err != nil {
|
||||
return err
|
||||
}
|
||||
// 无下一流程,工单直接完成
|
||||
if newNextScheduleInfo == nil {
|
||||
goto FINISH
|
||||
}
|
||||
workUpdates["status"] = model2.WorkInstanceStatusForOngoing
|
||||
FINISH:
|
||||
if err = model2.Updates(mWorkInstance.WorkInstance, workUpdates, tx); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func NewPerson() PersonHandle {
|
||||
return func(session *service.Session) *Person {
|
||||
return &Person{session}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user