Browse Source

work_order: 工单管理

Yi 7 months ago
parent
commit
cac011ef9f

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240820033652-5d08bd96ae57
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240821064041-bc3b16fd71ff
 	gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/getsentry/sentry-go v0.23.0

+ 4 - 0
go.sum

@@ -98,6 +98,10 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240820032343-3d8bf42d67d5 h1:+7bWlvQX
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240820032343-3d8bf42d67d5/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240820033652-5d08bd96ae57 h1:UY7UYkWnR7BMBtb/lY7NGtXLB1M2x/8khip0dqHk10o=
 gitee.com/xuyiping_admin/go_proto v0.0.0-20240820033652-5d08bd96ae57/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240821061702-b851656a7140 h1:lmeVORSqtp5SCOSpcxa3TgjT/nEeAU3kZslwQDqYxCA=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240821061702-b851656a7140/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240821064041-bc3b16fd71ff h1:6zotOPYH1IR5qQ9Ub5Ejm2WgxLCdBUWq+8NplkGM5PU=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240821064041-bc3b16fd71ff/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015 h1:dfb5dRd57L2HKjdwLT93UFmPYFPOmEl56gtZmqcNnaE=
 gitee.com/xuyiping_admin/pkg v0.0.0-20231218082641-aac597b8a015/go.mod h1:Fk4GYI/v0IK3XFrm1Gn+VkgCz5Y7mfswD5hsTJYOG6A=
 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

+ 32 - 0
http/handler/work/order.go

@@ -0,0 +1,32 @@
+package work
+
+import (
+	"kpt-pasture/http/middleware"
+	"net/http"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"github.com/gin-gonic/gin"
+)
+
+func OrderList(c *gin.Context) {
+	var req pasturePb.SearchWorkOrderRequest
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusOK, err)
+		return
+	}
+
+	pagination := &pasturePb.PaginationModel{
+		Page:       int32(c.GetInt(middleware.Page)),
+		PageSize:   int32(c.GetInt(middleware.PageSize)),
+		PageOffset: int32(c.GetInt(middleware.PageOffset)),
+	}
+
+	res, err := middleware.Dependency(c).StoreEventHub.OpsService.OrderList(c, &req, pagination)
+	if err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, res)
+}

+ 1 - 0
http/route/route.go

@@ -14,6 +14,7 @@ func HTTPServerRoute(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		GoodsManageAPI(opts...),
 		AnalysisAPI(opts...),
 		DashboardApi(opts...),
+		WorkOrderAPI(opts...),
 	}
 
 	return func(s *gin.Engine) {

+ 20 - 0
http/route/work_order.go

@@ -0,0 +1,20 @@
+package route
+
+import (
+	"kpt-pasture/http/handler/goods"
+	"kpt-pasture/http/handler/work"
+
+	"github.com/gin-gonic/gin"
+)
+
+func WorkOrderAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+		// goods API 组  物品管理
+		workRoute := authRouteGroup(s, "/api/v1/work/")
+		workRoute.POST("/order/list", work.OrderList)
+		workRoute.POST("/order/createOrUpdate", goods.DrugsCreateOrUpdate)
+	}
+}

+ 21 - 0
http/util/util.go

@@ -0,0 +1,21 @@
+package util
+
+import (
+	"strconv"
+	"strings"
+)
+
+// Int32SliceToString 将int32的切片转换成字符串,元素之间用sep分隔
+func Int32SliceToString(slice []int32, sep string) string {
+	var builder strings.Builder
+
+	for i, v := range slice {
+		if i > 0 {
+			builder.WriteString(sep)
+		}
+		// 使用strconv.FormatInt将int32转换为字符串
+		builder.WriteString(strconv.FormatInt(int64(v), 10))
+	}
+
+	return builder.String()
+}

+ 47 - 0
model/work_order.go

@@ -0,0 +1,47 @@
+package model
+
+import (
+	"kpt-pasture/http/util"
+
+	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"`
+}
+
+func (w *WorkOrder) TableName() string {
+	return "work_order"
+}
+func NewWorkOrder(req *pasturePb.WorkOrderList, systemUser *SystemUser, workOrderCategoryMap map[pasturePb.WorkOrderCategory_Kind]string) *WorkOrder {
+	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,
+	}
+}

+ 93 - 0
module/backend/config_data.go

@@ -1,6 +1,7 @@
 package backend
 
 import (
+	"fmt"
 	"kpt-pasture/model"
 
 	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
@@ -627,3 +628,95 @@ func (s *StoreEntry) WeekEnumList() []*pasturePb.ConfigOptionsList {
 		})
 	return configOptions
 }
+
+func (s *StoreEntry) monthEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	for v := 1; v <= 31; v++ {
+		configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+			Value:    int32(v),
+			Label:    fmt.Sprintf("%d号", v),
+			Disabled: true,
+		})
+	}
+	return configOptions
+}
+
+func (s *StoreEntry) WorkOrderFrequencyEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderFrequency_None),
+		Label:    "一次性",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderFrequency_Daily),
+		Label:    "每天",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderFrequency_Weekly),
+		Label:    "每周",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderFrequency_Monthly),
+		Label:    "每月",
+		Disabled: true,
+	})
+	return configOptions
+}
+
+func (s *StoreEntry) WorkOrderSubUnitEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderSubscribeUnit_Person),
+		Label:    "个人",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderSubscribeUnit_dept),
+		Label:    "部门",
+		Disabled: true,
+	})
+	return configOptions
+}
+
+func (s *StoreEntry) WorkOrderPriorityEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.Priority_Low),
+		Label:    "低",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.Priority_Middle),
+		Label:    "一般",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.Priority_High),
+		Label:    "紧急",
+		Disabled: true,
+	})
+	return configOptions
+}
+
+func (s *StoreEntry) WorkOrderCategoryEnumList() []*pasturePb.ConfigOptionsList {
+	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
+	configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderCategory_Health),
+		Label:    "保健",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderCategory_Breed),
+		Label:    "繁殖",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderCategory_Nutrition),
+		Label:    "营养",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderCategory_Ordinary),
+		Label:    "日常",
+		Disabled: true,
+	}, &pasturePb.ConfigOptionsList{
+		Value:    int32(pasturePb.WorkOrderCategory_Other),
+		Label:    "其他",
+		Disabled: true,
+	})
+	return configOptions
+}

+ 8 - 0
module/backend/enum_map.go

@@ -73,3 +73,11 @@ func (s *StoreEntry) CowKindMap() map[pasturePb.CowKind_Kind]string {
 	}
 	return res
 }
+
+func (s *StoreEntry) WorkOrderCategoryMap() map[pasturePb.WorkOrderCategory_Kind]string {
+	res := make(map[pasturePb.WorkOrderCategory_Kind]string)
+	for _, v := range s.WorkOrderCategoryEnumList() {
+		res[pasturePb.WorkOrderCategory_Kind(v.Value)] = v.Label
+	}
+	return res
+}

+ 10 - 0
module/backend/enum_options.go

@@ -164,10 +164,20 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName st
 		configOptions = s.FrozenSemenTypeEnumList()
 	case "week":
 		configOptions = s.WeekEnumList()
+	case "month":
+		configOptions = s.monthEnumList()
 	case "sameTimeCowType":
 		configOptions = s.SemeTimeCowTypeEnumList()
 	case "immunizationCowType":
 		configOptions = s.ImmunizationCowTypeEnumList()
+	case "workOrderFrequency":
+		configOptions = s.WorkOrderFrequencyEnumList()
+	case "workOrderSubUnit":
+		configOptions = s.WorkOrderSubUnitEnumList()
+	case "workOrderPriority":
+		configOptions = s.WorkOrderPriorityEnumList()
+	case "workOrderCategory":
+		configOptions = s.WorkOrderCategoryEnumList()
 	case "immunizationConditions":
 		configOptions = s.ImmunizationConditionsEnumList()
 	}

+ 6 - 0
module/backend/interface.go

@@ -48,6 +48,7 @@ type KptService interface {
 	GoodsService         // 牧场物品相关
 	AnalyseService       // 分析相关
 	DashboardService     // 牧场统计相关
+	WorkService          // 日常工作相关
 }
 
 //go:generate mockgen -destination mock/SystemService.go -package kptservicemock kpt-pasture/module/backend SystemService
@@ -186,3 +187,8 @@ type AnalyseService interface {
 type DashboardService interface {
 	Bar(ctx context.Context) (*pasturePb.BarCowStructResponse, error)
 }
+
+//go:generate mockgen -destination mock/WorkService.go -package kptservicemock kpt-pasture/module/backend WorkService
+type WorkService interface {
+	OrderList(ctx context.Context, req *pasturePb.SearchWorkOrderRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchWorkOrderResponse, error)
+}

+ 23 - 0
module/backend/work.go

@@ -0,0 +1,23 @@
+package backend
+
+import (
+	"context"
+	"net/http"
+
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+)
+
+func (s *StoreEntry) OrderList(ctx context.Context, req *pasturePb.SearchWorkOrderRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchWorkOrderResponse, error) {
+	var count int64 = 0
+
+	return &pasturePb.SearchWorkOrderResponse{
+		Code:    http.StatusOK,
+		Message: "ok",
+		Data: &pasturePb.SearchWorkOrderData{
+			List:     nil,
+			Total:    int32(count),
+			PageSize: pagination.PageSize,
+			Page:     pagination.Page,
+		},
+	}, nil
+}