|
@@ -1,192 +0,0 @@
|
|
|
-package model
|
|
|
-
|
|
|
-import (
|
|
|
- "encoding/json"
|
|
|
- "kpt-pasture/http/util"
|
|
|
- "strconv"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
-
|
|
|
- "github.com/hibiken/asynq"
|
|
|
-
|
|
|
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
-)
|
|
|
-
|
|
|
-const (
|
|
|
- QueueWorkOrder = "workOrder"
|
|
|
- TaskWorkOrder = "event:workOrder"
|
|
|
-)
|
|
|
-
|
|
|
-func AsynqQueueWorkOrder() asynq.Option {
|
|
|
- return asynq.Queue(QueueWorkOrder)
|
|
|
-}
|
|
|
-
|
|
|
-type WorkOrder struct {
|
|
|
- Id int64 `json:"id"`
|
|
|
- Name string `json:"name"`
|
|
|
- CategoryId pasturePb.WorkOrderCategory_Kind `json:"categoryId"`
|
|
|
- CategoryName string `json:"categoryName"`
|
|
|
- Priority pasturePb.Priority_Kind `json:"priority"`
|
|
|
- Frequency pasturePb.WorkOrderFrequency_Kind `json:"frequency"`
|
|
|
- ExecTime string `json:"execTime"`
|
|
|
- SubscribeUnit pasturePb.WorkOrderSubscribeUnit_Kind `json:"subscribeUnit"`
|
|
|
- ExecPersons string `json:"execPersons"`
|
|
|
- ExecPersonNames string `json:"execPersonsNames"`
|
|
|
- ExecDepartmental string `json:"execDepartmental"`
|
|
|
- ExecDepartmentalNames string `json:"execDepartmentalNames"`
|
|
|
- WeekMonthValue string `json:"WeekMonthValue"`
|
|
|
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
|
|
|
- Photos string `json:"photos"`
|
|
|
- Remarks string `json:"remarks"`
|
|
|
- OperationId int64 `json:"operationId"`
|
|
|
- OperationName string `json:"operationName"`
|
|
|
- CreatedAt int64 `json:"createdAt"`
|
|
|
- UpdatedAt int64 `json:"updatedAt"`
|
|
|
-}
|
|
|
-
|
|
|
-func (w *WorkOrder) TableName() string {
|
|
|
- return "work_order"
|
|
|
-}
|
|
|
-func NewWorkOrder(
|
|
|
- req *pasturePb.WorkOrderList,
|
|
|
- curUser *SystemUser,
|
|
|
- systemUserList []*SystemUser,
|
|
|
- deptList []*SystemDept,
|
|
|
- workOrderCategoryMap map[pasturePb.WorkOrderCategory_Kind]string,
|
|
|
-) *WorkOrder {
|
|
|
- execPersonNames := make([]string, 0)
|
|
|
- execDeptNames := make([]string, 0)
|
|
|
- if len(req.ExecPersons) > 0 {
|
|
|
- for _, v := range req.ExecPersons {
|
|
|
- for _, vv := range systemUserList {
|
|
|
- if int32(vv.Id) != v {
|
|
|
- continue
|
|
|
- }
|
|
|
- execPersonNames = append(execPersonNames, vv.Name)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- for _, d := range deptList {
|
|
|
- for _, dd := range req.ExecDepartmental {
|
|
|
- if int32(d.Id) != dd {
|
|
|
- continue
|
|
|
- }
|
|
|
- execDeptNames = append(execDeptNames, d.Name)
|
|
|
- }
|
|
|
- }
|
|
|
- weekMonthValue := ""
|
|
|
- if req.Frequency == pasturePb.WorkOrderFrequency_Weekly || req.Frequency == pasturePb.WorkOrderFrequency_Monthly {
|
|
|
- weekMonthValue = util.Int32SliceToString(req.WeekMonthValue, ",")
|
|
|
- }
|
|
|
-
|
|
|
- return &WorkOrder{
|
|
|
- Name: req.Name,
|
|
|
- CategoryId: req.CategoryId,
|
|
|
- CategoryName: workOrderCategoryMap[req.CategoryId],
|
|
|
- Priority: req.Priority,
|
|
|
- ExecTime: req.ExecTime,
|
|
|
- SubscribeUnit: req.SubscribeUnit,
|
|
|
- ExecPersons: util.Int32SliceToString(req.ExecPersons, ","),
|
|
|
- ExecPersonNames: strings.Join(execPersonNames, ","),
|
|
|
- ExecDepartmental: util.Int32SliceToString(req.ExecDepartmental, ","),
|
|
|
- ExecDepartmentalNames: strings.Join(execDeptNames, ","),
|
|
|
- WeekMonthValue: weekMonthValue,
|
|
|
- IsShow: req.IsShow,
|
|
|
- Photos: strings.Join(req.Photos, ","),
|
|
|
- Frequency: req.Frequency,
|
|
|
- Remarks: req.Remarks,
|
|
|
- OperationId: curUser.Id,
|
|
|
- OperationName: curUser.Name,
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-type TaskWorkOrderPayload struct {
|
|
|
- WorkOrderId int64 `json:"workOrderId"`
|
|
|
-}
|
|
|
-
|
|
|
-func NewTaskWorkOrderOption(processAt int64) []asynq.Option {
|
|
|
- return []asynq.Option{
|
|
|
- asynq.MaxRetry(3),
|
|
|
- AsynqQueueWorkOrder(),
|
|
|
- asynq.ProcessAt(time.Unix(processAt, 64)),
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-func NewTaskWorkOrderPayload(id int64, execTime time.Duration) *asynq.Task {
|
|
|
- payload, _ := json.Marshal(TaskWorkOrderPayload{
|
|
|
- WorkOrderId: id,
|
|
|
- })
|
|
|
- processAt := time.Now().Add(execTime).Unix()
|
|
|
- return asynq.NewTask(TaskWorkOrder, payload, NewTaskWorkOrderOption(processAt)...)
|
|
|
-}
|
|
|
-
|
|
|
-type WorkOrderSlice []*WorkOrder
|
|
|
-
|
|
|
-func (w WorkOrderSlice) ToPB(
|
|
|
- priorityMap map[pasturePb.Priority_Kind]string,
|
|
|
- frequencyMap map[pasturePb.WorkOrderFrequency_Kind]string,
|
|
|
- subscribeUnitMap map[pasturePb.WorkOrderSubscribeUnit_Kind]string,
|
|
|
- weekMap map[pasturePb.Week_Kind]string,
|
|
|
- monthMap map[int32]string,
|
|
|
-) []*pasturePb.WorkOrderList {
|
|
|
- res := make([]*pasturePb.WorkOrderList, len(w))
|
|
|
- for i, v := range w {
|
|
|
- execPersons, execDepartmental, weekMonthValue := make([]int32, 0), make([]int32, 0), make([]int32, 0)
|
|
|
- weekMonthValueName := make([]string, 0)
|
|
|
- if len(v.ExecPersons) > 0 {
|
|
|
- for _, personId := range strings.Split(v.ExecPersons, ",") {
|
|
|
- p, _ := strconv.Atoi(personId)
|
|
|
- execPersons = append(execPersons, int32(p))
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if len(v.ExecDepartmental) > 0 {
|
|
|
- for _, deptId := range strings.Split(v.ExecDepartmental, ",") {
|
|
|
- d, _ := strconv.Atoi(deptId)
|
|
|
- execDepartmental = append(execDepartmental, int32(d))
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if len(v.WeekMonthValue) > 0 {
|
|
|
- for _, week := range strings.Split(v.WeekMonthValue, ",") {
|
|
|
- k, _ := strconv.Atoi(week)
|
|
|
- if v.Frequency == pasturePb.WorkOrderFrequency_Weekly {
|
|
|
- weekMonthValueName = append(weekMonthValueName, weekMap[pasturePb.Week_Kind(k)])
|
|
|
- }
|
|
|
- if v.Frequency == pasturePb.WorkOrderFrequency_Monthly {
|
|
|
- weekMonthValueName = append(weekMonthValueName, monthMap[int32(k)])
|
|
|
- }
|
|
|
- weekMonthValue = append(weekMonthValue, int32(k))
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- res[i] = &pasturePb.WorkOrderList{
|
|
|
- Id: int32(v.Id),
|
|
|
- Name: v.Name,
|
|
|
- CategoryId: v.CategoryId,
|
|
|
- CategoryName: v.CategoryName,
|
|
|
- Priority: v.Priority,
|
|
|
- PriorityName: priorityMap[v.Priority],
|
|
|
- Frequency: v.Frequency,
|
|
|
- FrequencyName: frequencyMap[v.Frequency],
|
|
|
- ExecTime: v.ExecTime,
|
|
|
- SubscribeUnit: v.SubscribeUnit,
|
|
|
- SubscribeUnitName: subscribeUnitMap[v.SubscribeUnit],
|
|
|
- ExecPersons: execPersons,
|
|
|
- ExecPersonsNames: strings.Split(v.ExecPersonNames, ","),
|
|
|
- ExecDepartmental: execDepartmental,
|
|
|
- ExecDepartmentalNames: strings.Split(v.ExecDepartmental, ","),
|
|
|
- IsShow: v.IsShow,
|
|
|
- Photos: strings.Split(v.Photos, ","),
|
|
|
- WeekMonthValue: weekMonthValue,
|
|
|
- WeekMonthValueName: weekMonthValueName,
|
|
|
- Remarks: v.Remarks,
|
|
|
- OperatorId: int32(v.OperationId),
|
|
|
- OperatorName: v.OperationName,
|
|
|
- CreatedAt: int32(v.CreatedAt),
|
|
|
- UpdatedAt: int32(v.UpdatedAt),
|
|
|
- }
|
|
|
- }
|
|
|
- return res
|
|
|
-}
|