Files
2021-11-19 15:34:22 +08:00

128 lines
3.1 KiB
Go

package work
import (
model2 "ArmedPolice/app/common/model"
"ArmedPolice/app/controller/basic"
"ArmedPolice/app/model"
"ArmedPolice/app/service"
"errors"
"time"
)
type Schedule struct{ *service.Session }
type ScheduleHandle func(session *service.Session) *Schedule
type (
// ScheduleInfo 流程信息
ScheduleInfo struct {
Kind model2.WorkScheduleKind `json:"kind"`
Title string `json:"title"`
Schedules []*ScheduleDetailInfo `json:"schedules"`
}
// ScheduleBasicInfo 流程基本信息
ScheduleBasicInfo struct {
basic.CommonIDString
*model.WorkSchedule
}
// ScheduleDetailInfo 流程详细信息
ScheduleDetailInfo struct {
basic.CommonIDString
*model.WorkSchedules
}
// ScheduleParams 流程参数信息
ScheduleParams struct {
ID uint64
Title string
Stage, Step, Target, IsCountersign int
TargetValue []string
}
)
// List 列表信息
func (c *Schedule) List() ([]*ScheduleInfo, error) {
mWorkSchedule := model.NewWorkSchedule()
out, err := mWorkSchedule.Schedules()
if err != nil {
return nil, err
}
list := make([]*ScheduleInfo, 0)
for _, v := range out {
isExist := false
if len(list) <= 0 {
goto CONTINUE
}
for _, val := range list {
if val.Kind == v.Kind {
val.Schedules = append(val.Schedules, &ScheduleDetailInfo{
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
WorkSchedules: v,
})
isExist = true
break
}
}
if !isExist {
goto CONTINUE
}
continue
CONTINUE:
list = append(list, &ScheduleInfo{
Kind: v.Kind,
Title: v.KindTitle(),
Schedules: []*ScheduleDetailInfo{&ScheduleDetailInfo{
CommonIDString: basic.CommonIDString{ID: v.GetEncodeID()},
WorkSchedules: v,
}},
})
}
return list, nil
}
// Basic 基本信息
func (c *Schedule) Basic(id uint64) (*ScheduleBasicInfo, error) {
mWorkSchedule := model.NewWorkSchedule()
mWorkSchedule.ID = id
if isExist, err := model2.FirstField(mWorkSchedule.WorkSchedule, []string{"id", "kind", "title", "stage", "step"}); err != nil {
return nil, err
} else if !isExist {
return nil, errors.New("操作错误,流程信息不存在或已被删除")
}
return &ScheduleBasicInfo{
CommonIDString: basic.CommonIDString{ID: mWorkSchedule.GetEncodeID()},
WorkSchedule: mWorkSchedule,
}, nil
}
// Form 数据操作
func (c *Schedule) Form(params *ScheduleParams) error {
if params.ID > 0 {
mWorkSchedule := model.NewWorkSchedule()
mWorkSchedule.ID = params.ID
mWorkSchedule.SetTargetValueAttribute(params.TargetValue)
return model2.Updates(mWorkSchedule.WorkSchedule, map[string]interface{}{
"title": params.Title, "target": params.Target, "target_value": mWorkSchedule.TargetValue,
"updated_at": time.Now(),
})
}
return errors.New("操作错误,暂不支持新增流程")
}
// Delete 数据删除
func (c *Schedule) Delete(id uint64) error {
mWorkSchedule := model.NewWorkSchedule()
mWorkSchedule.ID = id
return model2.Delete(mWorkSchedule.WorkSchedule)
}
func NewSchedule() ScheduleHandle {
return func(session *service.Session) *Schedule {
return &Schedule{session}
}
}