|
@@ -2,46 +2,134 @@ package model
|
|
|
|
|
|
import (
|
|
|
"kpt-pasture/http/util"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
|
|
|
pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
|
|
|
)
|
|
|
|
|
|
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"`
|
|
|
- ExecTime string `json:"execTime"`
|
|
|
- SubscribeUnit pasturePb.WorkOrderSubscribeUnit_Kind `json:"subscribeUnit"`
|
|
|
- ExecPersons string `json:"execPersons"`
|
|
|
- ExecDepartmental string `json:"execDepartmental"`
|
|
|
- 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"`
|
|
|
+ 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"`
|
|
|
+ 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, systemUser *SystemUser, workOrderCategoryMap map[pasturePb.WorkOrderCategory_Kind]string) *WorkOrder {
|
|
|
+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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
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, ","),
|
|
|
- ExecDepartmental: util.Int32SliceToString(req.ExecDepartmental, ","),
|
|
|
- IsShow: req.IsShow,
|
|
|
- Photos: "",
|
|
|
- Remarks: req.Remarks,
|
|
|
- OperationId: systemUser.Id,
|
|
|
- OperationName: systemUser.Name,
|
|
|
+ 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, ","),
|
|
|
+ IsShow: req.IsShow,
|
|
|
+ Photos: strings.Join(req.Photos, ","),
|
|
|
+ Frequency: req.Frequency,
|
|
|
+ Remarks: req.Remarks,
|
|
|
+ OperationId: curUser.Id,
|
|
|
+ OperationName: curUser.Name,
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+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,
|
|
|
+) []*pasturePb.WorkOrderList {
|
|
|
+ res := make([]*pasturePb.WorkOrderList, len(w))
|
|
|
+ for i, v := range w {
|
|
|
+ execPersons, execDepartmental := make([]int32, 0), make([]int32, 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))
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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, ","),
|
|
|
+ Remarks: v.Remarks,
|
|
|
+ OperatorId: int32(v.OperationId),
|
|
|
+ OperatorName: v.OperationName,
|
|
|
+ CreatedAt: int32(v.CreatedAt),
|
|
|
+ UpdatedAt: int32(v.UpdatedAt),
|
|
|
+ }
|
|
|
}
|
|
|
+ return res
|
|
|
}
|