package production import ( "shylinux.com/x/ice" kit "shylinux.com/x/toolkits" "shylinux.com/x/operation/src/production/model" ) type Case struct { Table order string `data:"3"` fields string `data:"title,content,case_status,process_time,finish_time,plan_uid,user_uid"` create string `name:"create title* content*" role:"leader,worker"` modify string `name:"modify title* content*" role:"leader,worker"` remove string `name:"remove" role:"leader,worker"` process string `name:"process" role:"leader,worker"` finish string `name:"finish" role:"leader,worker"` planBind string `name:"planBind plan_uid*" role:"leader"` } func (s Case) Create(m *ice.Message, arg ...string) { s.ValueCreate(m, arg...) s.taskCount(m, "1") s.planCount(m, "1") s.GetCommandUID(m) s.SendMessage(m, "", "") } func (s Case) Remove(m *ice.Message, arg ...string) { s.ValueRemove(m, arg...) s.taskCount(m, "-1") s.planCount(m, "-1") } func (s Case) List(m *ice.Message, arg ...string) { isLeader, user_uid := s.IsLeader(m), m.Option(model.USER_UID) s.ValueList(m, arg).Table(func(value ice.Maps) { button := []ice.Any{} switch CaseStatus(kit.Int(value[model.CASE_STATUS])) { case CaseCreate: if isLeader && value[model.PLAN_UID] == "" { button = append(button, s.PlanBind) } if isLeader || user_uid == value[model.USER_UID] { button = append(button, s.Process) } case CaseProcess: if isLeader || user_uid == value[model.USER_UID] { button = append(button, s.Finish) } case CaseFinish: kit.If(len(arg) == 2, func() { s.DoneMessage(m) }) } m.PushButton(button...) }).Display("") s.SelectJoinPlan(m) } func (s Case) Process(m *ice.Message, arg ...string) { s.changeStatus(m, CaseCreate, CaseProcess) } func (s Case) Finish(m *ice.Message, arg ...string) { s.changeStatus(m, CaseProcess, CaseFinish) } func (s Case) PlanBind(m *ice.Message, arg ...string) { s.ValueModify(m, arg...) s.planCount(m, "1") } func init() { ice.TeamCtxCmd(Case{}) } func (s Case) changeStatus(m *ice.Message, from, to CaseStatus) { s.ChangeStatus(m, int(from), int(to), m.ActionKey()+"_time", m.Time()) } func (s Case) planCount(m *ice.Message, value string) { s.Table.planCount(m, model.CASE_COUNT, value) } func (s Case) taskCount(m *ice.Message, value string) { if m.IsErr() || m.Option(model.TASK_UID) == "" { return } m.Cmd(task{}, s.AddCount, model.CASE_COUNT, value, m.Option(model.TASK_UID)) } type CaseStatus int const ( CaseCreate CaseStatus = iota CaseProcess CaseFinish ) var CaseStatusList = map[CaseStatus]string{ CaseCreate: "create", CaseProcess: "process", CaseFinish: "finish", } func (s CaseStatus) String() string { return CaseStatusList[s] }