feat:完善项目
This commit is contained in:
107
app/controller/work/schedule.go
Normal file
107
app/controller/work/schedule.go
Normal file
@ -0,0 +1,107 @@
|
||||
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"`
|
||||
}
|
||||
// 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
|
||||
}
|
||||
|
||||
// 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}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user