Browse Source

work_order: 工单业务

Yi 7 months ago
parent
commit
f0e6c44453

+ 2 - 1
.gitignore

@@ -47,4 +47,5 @@ _testmain.go
 bin/
 .vscode/
 logger/
-config/private.key
+config/private.key
+files/*

+ 1 - 1
Dockerfile

@@ -25,6 +25,6 @@ COPY --from=0 /app/kpt-pasture/config/ /app/kpt-pasture/bin/config/
 COPY --from=0  /app/kpt-pasture/bin/kptTmrGroup /app/kpt-pasture/bin/kptTmrGroup
 
 EXPOSE 8090
-VOLUME ["/app/kpt-pasture/logger","/app/kpt-pasture/bin/config"]
+VOLUME ["/app/kpt-pasture/logger","/app/kpt-pasture/bin/config","/app/kpt-pasture/files"]
 
 CMD ["/app/kpt-pasture/bin/kptTmrGroup","http"]

+ 1 - 1
go.mod

@@ -3,7 +3,7 @@ module kpt-pasture
 go 1.17
 
 require (
-	gitee.com/xuyiping_admin/go_proto v0.0.0-20240821064041-bc3b16fd71ff
+	gitee.com/xuyiping_admin/go_proto v0.0.0-20240826085327-e7ccf8f3b63c
 	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

+ 8 - 0
go.sum

@@ -102,6 +102,14 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240821061702-b851656a7140 h1:lmeVORSq
 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/go_proto v0.0.0-20240826074944-ef0b91e66b73 h1:exOIMfdvXUTHlT4xbeLxi4ueO1D7GcZ4rCUJIDjg7U0=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826074944-ef0b91e66b73/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826075440-c7cd4d7cee95 h1:dg6uaCgCmdBwOjb6UW2nrNAfitgfPqh7WeVq5ihOqv4=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826075440-c7cd4d7cee95/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826081928-dc3ee5936a5b h1:znMSddT9XKv7p2gfPjagpSGhZV/UNauJJN+Hqr1Dv1Y=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826081928-dc3ee5936a5b/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826085327-e7ccf8f3b63c h1:M43VNB4dyO5GuDHTA/zBCGjNRiSL0R2ZAeZCeOwauoM=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240826085327-e7ccf8f3b63c/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=

+ 0 - 9
http/handler/config/config.go

@@ -78,15 +78,6 @@ func CowSourceOptions(c *gin.Context) {
 	ginutil.JSONResp(c, res)
 }
 
-func CowStatusOptions(c *gin.Context) {
-	res, err := middleware.Dependency(c).StoreEventHub.OpsService.CowStatusOptions(c)
-	if err != nil {
-		apierr.ClassifiedAbort(c, err)
-		return
-	}
-	ginutil.JSONResp(c, res)
-}
-
 func CowTypeOptions(c *gin.Context) {
 	res, err := middleware.Dependency(c).StoreEventHub.OpsService.CowTypeOptions(c)
 	if err != nil {

+ 61 - 0
http/handler/upload/upload.go

@@ -0,0 +1,61 @@
+package upload
+
+import (
+	"fmt"
+	"net/http"
+	"os"
+	"time"
+
+	"gitee.com/xuyiping_admin/pkg/apierr"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"github.com/gin-gonic/gin"
+)
+
+func Photos(c *gin.Context) {
+	form, err := c.MultipartForm()
+	if err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Customf("No multipartForm: %s", err.Error()))
+		return
+	}
+	files := form.File["uploads"]
+	// 验证文件数量
+	if len(files) == 0 {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Custom("No files selected"))
+		return
+	}
+
+	saveDir := "./files/photos"
+	if _, err = os.Stat(saveDir); os.IsNotExist(err) {
+		if err = os.MkdirAll(saveDir, 0755); err != nil {
+			apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Customf("创建目录失败: %s", err.Error()))
+			return
+		}
+	}
+
+	// 处理每个文件
+	filePaths := make([]string, len(files))
+	timestamp := time.Now().Unix()
+	for i, file := range files {
+		if file.Header.Get("Content-Type") != "image/jpeg" &&
+			file.Header.Get("Content-Type") != "image/png" &&
+			file.Header.Get("Content-Type") != "image/gif" {
+			apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Customf("图片格式错误: %s", file.Filename))
+			return
+		}
+		if file.Size > 1024*1024*5 {
+			apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Custom("单个图片文件不能超过5MB"))
+			return
+		}
+		fpath := fmt.Sprintf("%s/%d_%d_%s", saveDir, timestamp, i+1, file.Filename)
+		if err = c.SaveUploadedFile(file, fpath); err != nil {
+			apierr.AbortBadRequest(c, http.StatusBadRequest, xerr.Customf("保存文件失败: %s", err.Error()))
+			return
+		}
+		filePaths[i] = fpath
+	}
+	c.JSON(http.StatusOK, gin.H{"code": http.StatusOK, "message": "ok", "data": filePaths})
+}
+
+func Files(c *gin.Context) {
+
+}

+ 12 - 23
http/handler/work/order.go

@@ -1,11 +1,10 @@
 package work
 
 import (
-	"encoding/json"
-	"fmt"
 	"kpt-pasture/http/middleware"
 	"net/http"
-	"time"
+
+	"gitee.com/xuyiping_admin/pkg/valid"
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
@@ -36,30 +35,20 @@ func OrderList(c *gin.Context) {
 }
 
 func OrderCreateOrUpdate(c *gin.Context) {
-	files, err := c.MultipartForm()
-	if err != nil {
-		c.JSON(http.StatusBadRequest, gin.H{"error": "MultipartForm"})
-		return
-	}
-	b, _ := json.Marshal(files.Value)
-	fmt.Println("===Value====", string(b))
-	fileHeaders := files.File["photos"] // 注意这里使用 "files[]" 作为 key,与前端匹配
-	// 验证文件数量
-	if len(fileHeaders) == 0 {
-		c.JSON(http.StatusBadRequest, gin.H{"error": "No files selected"})
+	var req pasturePb.WorkOrderList
+	if err := ginutil.BindProto(c, &req); err != nil {
+		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
 	}
 
-	// 处理每个文件
-	for i, file := range fileHeaders {
-		if err = c.SaveUploadedFile(file, fmt.Sprintf("%d_%d_%s", i+1, time.Now().Unix(), file.Filename)); err != nil {
-			fmt.Println("===SaveUploadedFile==", err, i)
-		}
-	}
-
-	/*if err := valid.ValidateStruct(&req,
+	if err := valid.ValidateStruct(&req,
 		valid.Field(&req.Name, valid.Required),
 		valid.Field(&req.CategoryId, valid.Required),
+		valid.Field(&req.Priority, valid.Required),
+		valid.Field(&req.IsShow, valid.Required),
+		valid.Field(&req.ExecTime, valid.Required),
+		valid.Field(&req.SubscribeUnit, valid.Required),
+		valid.Field(&req.Frequency, valid.Required),
 	); err != nil {
 		apierr.AbortBadRequest(c, http.StatusBadRequest, err)
 		return
@@ -68,7 +57,7 @@ func OrderCreateOrUpdate(c *gin.Context) {
 	if err := middleware.BackendOperation(c).OpsService.OrderCreateOrUpdate(c, &req); err != nil {
 		apierr.ClassifiedAbort(c, err)
 		return
-	}*/
+	}
 
 	ginutil.JSONResp(c, &operationPb.CommonOK{
 		Code: http.StatusOK,

+ 0 - 1
http/route/config_api.go

@@ -18,7 +18,6 @@ func ConfigAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		pastureRoute.GET("/breed/status/options", config.BreedStatusOptions)
 		pastureRoute.GET("/cow/kind/options", config.CowKindOptions)
 		pastureRoute.GET("/cow/source/options", config.CowSourceOptions)
-		pastureRoute.GET("/cow/status/options", config.CowStatusOptions)
 		pastureRoute.GET("/cow/type/options", config.CowTypeOptions)
 		pastureRoute.GET("/cow/transfer/pen/reason/options", config.CowTransferPenReasonOptions)
 		pastureRoute.GET("/bull/frozen/semen/options", config.BullListOptions)

+ 19 - 0
http/route/files_api.go

@@ -0,0 +1,19 @@
+package route
+
+import (
+	"kpt-pasture/http/handler/upload"
+
+	"github.com/gin-gonic/gin"
+)
+
+func FilesManageAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
+	return func(s *gin.Engine) {
+		for _, opt := range opts {
+			opt(s)
+		}
+		// upload API 组  上传文件
+		uploadRoute := authRouteGroup(s, "/api/v1/upload/")
+		uploadRoute.POST("/photos", upload.Photos)
+		uploadRoute.POST("/files", upload.Files)
+	}
+}

+ 1 - 0
http/route/route.go

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

+ 22 - 31
model/cow.go

@@ -16,9 +16,9 @@ type Cow struct {
 	EarOldNumber        string                     `json:"ear_old_number"`
 	PenId               int64                      `json:"pen_id"`
 	Lact                int32                      `json:"lact"`
-	TypeId              pasturePb.CowType_Kind     `json:"type_id"`
-	BreedStatusId       pasturePb.BreedStatus_Kind `json:"breed_status_id"`
-	KindId              pasturePb.CowKind_Kind     `json:"kind_id"`
+	CowType             pasturePb.CowType_Kind     `json:"cow_type"`
+	BreedStatus         pasturePb.BreedStatus_Kind `json:"breed_status"`
+	CowKind             pasturePb.CowKind_Kind     `json:"cow_kind"`
 	BirthWeight         int64                      `json:"birth_weight"`
 	CurrentWeight       int64                      `json:"current_weight"`
 	SourceId            pasturePb.CowSource_Kind   `json:"source_id"`
@@ -26,7 +26,6 @@ type Cow struct {
 	MotherId            int64                      `json:"mother_id"`
 	IsRemove            pasturePb.IsShow_Kind      `json:"is_remove"`
 	IsPregnant          pasturePb.IsShow_Kind      `json:"is_pregnant"`
-	Status              pasturePb.CowStatus_Kind   `json:"status"`
 	WeaningAt           int64                      `json:"weaning_at"`
 	BirthAt             int64                      `json:"birth_at"`
 	FirstMatingAt       int64                      `json:"first_mating_at"`
@@ -48,15 +47,9 @@ func (c *Cow) TableName() string {
 }
 
 func NewCow(req *pasturePb.SearchEnterData) *Cow {
-	var (
-		status     = pasturePb.CowStatus_Calving
-		isPregnant = pasturePb.IsShow_No
-	)
-
-	if req.BreedStatusId == pasturePb.BreedStatus_InCheck_Pregnant ||
-		req.BreedStatusId == pasturePb.BreedStatus_Recheck_Pregnant {
+	var isPregnant = pasturePb.IsShow_No
+	if req.BreedStatusId == pasturePb.BreedStatus_Pregnant {
 		isPregnant = pasturePb.IsShow_Ok
-		status = pasturePb.CowStatus_Pregnant
 	}
 
 	return &Cow{
@@ -64,15 +57,14 @@ func NewCow(req *pasturePb.SearchEnterData) *Cow {
 		EarNumber:           req.EarNumber,
 		PenId:               int64(req.PenId),
 		Lact:                req.Lact,
-		TypeId:              req.CowTypeId,
-		BreedStatusId:       req.BreedStatusId,
-		KindId:              req.CowKindId,
+		CowType:             req.CowTypeId,
+		BreedStatus:         req.BreedStatusId,
+		CowKind:             req.CowKindId,
 		SourceId:            req.CowSourceId,
 		FatherId:            int64(req.FatherId),
 		MotherId:            int64(req.MotherId),
 		IsRemove:            pasturePb.IsShow_Ok,
 		IsPregnant:          isPregnant,
-		Status:              status,
 		WeaningAt:           int64(req.WeaningAt),
 		BirthAt:             int64(req.BirthAt),
 		FirstMatingAt:       int64(req.MatingAt),
@@ -83,19 +75,18 @@ func NewCow(req *pasturePb.SearchEnterData) *Cow {
 
 func NewCalfCow(motherId, fatherId int64, calf *EventCalvingCalf) *Cow {
 	return &Cow{
-		Sex:           calf.Sex,
-		EarNumber:     calf.EarNumber,
-		PenId:         int64(calf.PenId),
-		TypeId:        pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
-		BreedStatusId: pasturePb.BreedStatus_Unmarried,  // 未配
-		KindId:        pasturePb.CowKind_HST,            // 荷斯坦
-		BirthWeight:   calf.Weight,
-		SourceId:      pasturePb.CowSource_Calving, // 产犊方式
-		FatherId:      fatherId,
-		MotherId:      motherId,
-		IsRemove:      pasturePb.IsShow_Ok,
-		IsPregnant:    pasturePb.IsShow_No,
-		Status:        pasturePb.CowStatus_Calving, // 哺乳犊牛
+		Sex:         calf.Sex,
+		EarNumber:   calf.EarNumber,
+		PenId:       int64(calf.PenId),
+		CowType:     pasturePb.CowType_Lactating_Calf, // 哺乳犊牛
+		BreedStatus: pasturePb.BreedStatus_UnBreed,    // 未配
+		CowKind:     calf.CowKind,                     // 牛只品种
+		BirthWeight: calf.Weight,
+		SourceId:    pasturePb.CowSource_Calving, // 产犊方式
+		FatherId:    fatherId,
+		MotherId:    motherId,
+		IsRemove:    pasturePb.IsShow_Ok,
+		IsPregnant:  pasturePb.IsShow_No,
 	}
 }
 
@@ -122,7 +113,7 @@ func (c *Cow) GetDayAge() int32 {
 
 // GetDaysPregnant 在胎天数
 func (c *Cow) GetDaysPregnant() int32 {
-	if c.Status == pasturePb.CowStatus_Breeding || c.Status == pasturePb.CowStatus_Pregnant {
+	if c.BreedStatus == pasturePb.BreedStatus_Pregnant {
 		return int32(math.Floor(float64(time.Now().Unix()-c.LastMatingAt) / 86400))
 	}
 	return 0
@@ -130,7 +121,7 @@ func (c *Cow) GetDaysPregnant() int32 {
 
 // GetLactationDays 泌乳天数
 func (c *Cow) GetLactationDays() int32 {
-	if c.Status == pasturePb.CowStatus_Calving {
+	if c.BreedStatus == pasturePb.BreedStatus_Calving {
 		return int32(math.Floor(float64(time.Now().Unix()-c.LastCalvingAt) / 86400))
 	}
 	return 0

+ 1 - 0
model/event_calving_calf.go

@@ -9,6 +9,7 @@ type EventCalvingCalf struct {
 	MotherId   int64                  `json:"mother_id"`
 	EarNumber  string                 `json:"ear_number"`
 	Sex        pasturePb.Genders_Kind `json:"sex"`
+	CowKind    pasturePb.CowKind_Kind `json:"cow_kind"`
 	Weight     int64                  `json:"weight"`
 	IsLive     pasturePb.IsShow_Kind  `json:"is_live"`
 	IsAdoption pasturePb.IsShow_Kind  `json:"is_adoption"`

+ 9 - 11
model/event_enter.go

@@ -16,13 +16,12 @@ type EventEnter struct {
 	BirthAt          int64                      `json:"birth_at"`
 	CowSourceId      pasturePb.CowSource_Kind   `json:"cow_source_id"`
 	OldEarNumber     string                     `json:"old_ear_number"`
-	CowTypeId        pasturePb.CowType_Kind     `json:"cow_type_id"`
-	BreedStatusId    pasturePb.BreedStatus_Kind `json:"breed_status_id"`
+	CowType          pasturePb.CowType_Kind     `json:"cow_type"`
+	BreedStatus      pasturePb.BreedStatus_Kind `json:"breed_status"`
 	Lact             int32                      `json:"lact"`
 	DayAge           int32                      `json:"day_age"`
 	PenId            int32                      `json:"pen_id"`
-	CowKindId        pasturePb.CowKind_Kind     `json:"cow_kind_id"`
-	Status           pasturePb.CowStatus_Kind   `json:"status"`
+	CowKind          pasturePb.CowKind_Kind     `json:"cow_kind"`
 	FatherId         int64                      `json:"father_id"`
 	MotherId         int64                      `json:"mother_id"`
 	MatingAt         int64                      `json:"mating_at"`
@@ -50,13 +49,12 @@ func NewEventEnter(cowId, operationId int64, req *pasturePb.SearchEnterData) *Ev
 		Sex:              req.Sex,
 		BirthAt:          int64(req.BirthAt),
 		CowSourceId:      req.CowSourceId,
-		CowTypeId:        req.CowTypeId,
-		BreedStatusId:    req.BreedStatusId,
+		CowType:          req.CowTypeId,
+		BreedStatus:      req.BreedStatusId,
 		Lact:             req.Lact,
 		DayAge:           int32(math.Floor(float64(int32(time.Now().Unix())-req.BirthAt) / 86400)),
 		PenId:            req.PenId,
-		CowKindId:        req.CowKindId,
-		Status:           1,
+		CowKind:          req.CowKindId,
 		FatherId:         int64(req.FatherId),
 		MotherId:         int64(req.MotherId),
 		MatingAt:         int64(req.MatingAt),
@@ -85,11 +83,11 @@ func (e EventEnterSlice) ToPB() []*pasturePb.SearchEnterData {
 			Sex:              d.Sex,
 			BirthAt:          int32(d.BirthAt),
 			CowSourceId:      d.CowSourceId,
-			CowTypeId:        d.CowTypeId,
-			BreedStatusId:    d.BreedStatusId,
+			CowTypeId:        d.CowType,
+			BreedStatusId:    d.BreedStatus,
 			Lact:             d.Lact,
 			PenId:            d.PenId,
-			CowKindId:        d.CowKindId,
+			CowKindId:        d.CowKind,
 			FatherId:         int32(d.FatherId),
 			MotherId:         int32(d.MotherId),
 			MatingAt:         int32(d.MatingAt),

+ 118 - 30
model/work_order.go

@@ -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
 }

+ 11 - 46
module/backend/config_data.go

@@ -55,28 +55,28 @@ func (s *StoreEntry) BarnTypeEnumList() []*pasturePb.ConfigOptionsList {
 func (s *StoreEntry) BreedStatusEnumList() []*pasturePb.ConfigOptionsList {
 	breedStatusList := make([]*pasturePb.ConfigOptionsList, 0)
 	breedStatusList = append(breedStatusList, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.BreedStatus_Unmarried),
+		Value:    int32(pasturePb.BreedStatus_UnBreed),
 		Label:    "未配",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.BreedStatus_InCheck_Unpregnant),
-		Label:    "初检无胎",
+		Value:    int32(pasturePb.BreedStatus_Breeding),
+		Label:    "已配未检",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.BreedStatus_InCheck_Pregnant),
-		Label:    "初检有胎",
+		Value:    int32(pasturePb.BreedStatus_Pregnant),
+		Label:    "怀孕",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.BreedStatus_Recheck_Unpregnant),
-		Label:    "复检无胎",
+		Value:    int32(pasturePb.BreedStatus_Empty),
+		Label:    "空怀",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.BreedStatus_Recheck_Pregnant),
-		Label:    "复检有胎",
+		Value:    int32(pasturePb.BreedStatus_Calving),
+		Label:    "产犊",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.BreedStatus_Pause_Pregnant),
-		Label:    "停配",
+		Value:    int32(pasturePb.BreedStatus_Abort),
+		Label:    "流产",
 		Disabled: true,
 	}, &pasturePb.ConfigOptionsList{
 		Value:    int32(pasturePb.BreedStatus_No_Pregnant),
@@ -133,41 +133,6 @@ func (s *StoreEntry) CowSourceEnumList() []*pasturePb.ConfigOptionsList {
 	})
 	return cowSourceList
 }
-
-func (s *StoreEntry) CowStatusEnumList() []*pasturePb.ConfigOptionsList {
-	cowStatusList := make([]*pasturePb.ConfigOptionsList, 0)
-	cowStatusList = append(cowStatusList, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_Calving),
-		Label:    "产犊",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_Empty),
-		Label:    "空怀",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_Breeding),
-		Label:    "配种",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_Pregnant),
-		Label:    "怀孕",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_Dry_Milk),
-		Label:    "干奶",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_Peripartum),
-		Label:    "围产",
-		Disabled: true,
-	}, &pasturePb.ConfigOptionsList{
-		Value:    int32(pasturePb.CowStatus_No_Pregnant),
-		Label:    "禁配",
-		Disabled: true,
-	})
-	return cowStatusList
-}
-
 func (s *StoreEntry) CowTypeEnumList() []*pasturePb.ConfigOptionsList {
 	cowTypeList := make([]*pasturePb.ConfigOptionsList, 0)
 	cowTypeList = append(cowTypeList, &pasturePb.ConfigOptionsList{

+ 24 - 8
module/backend/enum_map.go

@@ -58,14 +58,6 @@ func (s *StoreEntry) CowTypeMap() map[pasturePb.CowType_Kind]string {
 	return res
 }
 
-func (s *StoreEntry) CowStatusMap() map[pasturePb.CowStatus_Kind]string {
-	res := make(map[pasturePb.CowStatus_Kind]string)
-	for _, v := range s.CowStatusEnumList() {
-		res[pasturePb.CowStatus_Kind(v.Value)] = v.Label
-	}
-	return res
-}
-
 func (s *StoreEntry) CowKindMap() map[pasturePb.CowKind_Kind]string {
 	res := make(map[pasturePb.CowKind_Kind]string)
 	for _, v := range s.CowKindEnumList() {
@@ -81,3 +73,27 @@ func (s *StoreEntry) WorkOrderCategoryMap() map[pasturePb.WorkOrderCategory_Kind
 	}
 	return res
 }
+
+func (s *StoreEntry) WorkOrderFrequencyMap() map[pasturePb.WorkOrderFrequency_Kind]string {
+	res := make(map[pasturePb.WorkOrderFrequency_Kind]string)
+	for _, v := range s.WorkOrderFrequencyEnumList() {
+		res[pasturePb.WorkOrderFrequency_Kind(v.Value)] = v.Label
+	}
+	return res
+}
+
+func (s *StoreEntry) WorkOrderSubUnitMap() map[pasturePb.WorkOrderSubscribeUnit_Kind]string {
+	res := make(map[pasturePb.WorkOrderSubscribeUnit_Kind]string)
+	for _, v := range s.WorkOrderSubUnitEnumList() {
+		res[pasturePb.WorkOrderSubscribeUnit_Kind(v.Value)] = v.Label
+	}
+	return res
+}
+
+func (s *StoreEntry) WorkOrderPriorityMap() map[pasturePb.Priority_Kind]string {
+	res := make(map[pasturePb.Priority_Kind]string)
+	for _, v := range s.WorkOrderPriorityEnumList() {
+		res[pasturePb.Priority_Kind(v.Value)] = v.Label
+	}
+	return res
+}

+ 0 - 8
module/backend/enum_options.go

@@ -89,14 +89,6 @@ func (s *StoreEntry) CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOpt
 	}, nil
 }
 
-func (s *StoreEntry) CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
-	return &pasturePb.ConfigOptionsListResponse{
-		Code:    http.StatusOK,
-		Message: "ok",
-		Data:    s.CowStatusEnumList(),
-	}, nil
-}
-
 func (s *StoreEntry) CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error) {
 	return &pasturePb.ConfigOptionsListResponse{
 		Code:    http.StatusOK,

+ 5 - 5
module/backend/event.go

@@ -25,14 +25,14 @@ func (s *StoreEntry) EnterList(ctx context.Context, req *pasturePb.SearchEventRe
 	eventEnterList := make([]*pasturePb.SearchEnterData, 0)
 	var count int64 = 0
 	pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventEnter).TableName())).
-		Select(`a.id,a.birth_at,a.weaning_at,a.dry_milk_at,a.cow_source_id,a.remarks,a.mating_at,a.status,a.lact,
-		a.breed_status_id,a.mother_id,a.cow_kind_id,a.cow_id,a.ear_number,a.sex,a.created_at,a.updated_at,a.enter_at,
+		Select(`a.id,a.birth_at,a.weaning_at,a.dry_milk_at,a.cow_source_id,a.remarks,a.mating_at,a.lact,
+		a.breed_status,a.mother_id,a.cow_kind,a.cow_id,a.ear_number,a.sex,a.created_at,a.updated_at,a.enter_at,
 		a.weight / 100 as weight,a.price / 100 as price,b.name as breed_status_name,c.name as cow_source_name,d.name as cow_type_name,
 		e.name as cow_kind_name,f.name as pen_name,g.name as operation_name,h.name as staff_member_name`).
-		Joins(fmt.Sprintf("JOIN %s AS b ON a.breed_status_id = b.id", new(model.ConfigBreedStatus).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS b ON a.breed_status = b.id", new(model.ConfigBreedStatus).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS c on a.cow_source_id = c.id", new(model.ConfigCowSource).TableName())).
-		Joins(fmt.Sprintf("JOIN %s AS d on a.cow_type_id = d.id", new(model.ConfigCowType).TableName())).
-		Joins(fmt.Sprintf("JOIN %s AS e ON a.cow_kind_id = e.id", new(model.ConfigCowKind).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS d on a.cow_type = d.id", new(model.ConfigCowType).TableName())).
+		Joins(fmt.Sprintf("JOIN %s AS e ON a.cow_kind = e.id", new(model.ConfigCowKind).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS f on a.pen_id = f.id", new(model.Pen).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS g on a.operation_id = g.id", new(model.SystemUser).TableName())).
 		Joins(fmt.Sprintf("JOIN %s AS h on a.staff_member_id = h.id", new(model.SystemUser).TableName()))

+ 0 - 1
module/backend/interface.go

@@ -133,7 +133,6 @@ type ConfigDataService interface {
 	BreedStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowKindOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowSourceOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
-	CowStatusOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowTypeOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	CowTransferPenReasonOptions(ctx context.Context) (*pasturePb.ConfigOptionsListResponse, error)
 	SystemUserOptions(ctx context.Context, depId int) (*pasturePb.ConfigOptionsListResponse, error)

+ 8 - 0
module/backend/sql.go

@@ -56,6 +56,14 @@ func (s *StoreEntry) GetSystemUserInfo(ctx context.Context, userId int64) (*mode
 	return systemUser, nil
 }
 
+func (s *StoreEntry) SystemDeptList(ctx context.Context) ([]*model.SystemDept, error) {
+	deptList := make([]*model.SystemDept, 0)
+	if err := s.DB.Where("is_delete = ?", pasturePb.IsShow_Ok).Find(&deptList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+	return deptList, nil
+}
+
 func (s *StoreEntry) GetPenInfo(ctx context.Context, penId int64) (*model.Pen, error) {
 	penData := &model.Pen{
 		Id: penId,

+ 53 - 1
module/backend/work.go

@@ -2,19 +2,57 @@ package backend
 
 import (
 	"context"
+	"fmt"
+	"kpt-pasture/model"
 	"net/http"
 
+	"gitee.com/xuyiping_admin/pkg/xerr"
+
 	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) {
+	workOrderList := make([]*model.WorkOrder, 0)
 	var count int64 = 0
 
+	pref := s.DB.Model(new(model.WorkOrder))
+	if req.Name != "" {
+		pref.Where("name like ?", fmt.Sprintf("%s%s%s", "%", req.Name, "%"))
+	}
+
+	if req.Frequency > 0 {
+		pref.Where("frequency = ?", req.Frequency)
+	}
+
+	if req.Priority > 0 {
+		pref.Where("priority = ?", req.Priority)
+	}
+
+	if req.IsShow > 0 {
+		pref.Where("is_show = ?", req.IsShow)
+	}
+
+	if req.SubscribeUnit > 0 {
+		pref.Where("subscribe_unit = ?", req.SubscribeUnit)
+	}
+
+	if req.CategoryId > 0 {
+		pref.Where("category_id = ?", req.CategoryId)
+	}
+
+	if err := pref.Order("id desc").Count(&count).Limit(int(pagination.PageSize)).Offset(int(pagination.PageOffset)).
+		Find(&workOrderList).Error; err != nil {
+		return nil, xerr.WithStack(err)
+	}
+
+	priorityMap := s.WorkOrderPriorityMap()
+	frequencyMap := s.WorkOrderFrequencyMap()
+	subscribeUnitMap := s.WorkOrderSubUnitMap()
 	return &pasturePb.SearchWorkOrderResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SearchWorkOrderData{
-			List:     nil,
+			List:     model.WorkOrderSlice(workOrderList).ToPB(priorityMap, frequencyMap, subscribeUnitMap),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,
@@ -23,5 +61,19 @@ func (s *StoreEntry) OrderList(ctx context.Context, req *pasturePb.SearchWorkOrd
 }
 
 func (s *StoreEntry) OrderCreateOrUpdate(ctx context.Context, req *pasturePb.WorkOrderList) error {
+	currentUser, _ := s.GetCurrentSystemUser(ctx)
+	workOrderCategoryMap := s.WorkOrderCategoryMap()
+	systemUserList, _ := s.SystemUserList(ctx)
+	deptList, _ := s.SystemDeptList(ctx)
+	newWorkOrder := model.NewWorkOrder(req, currentUser, systemUserList, deptList, workOrderCategoryMap)
+	if req.Id <= 0 {
+		if err := s.DB.Create(newWorkOrder).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+	} else {
+		if err := s.DB.Where("id = ?", req.Id).Updates(newWorkOrder).Error; err != nil {
+			return xerr.WithStack(err)
+		}
+	}
 	return nil
 }