Browse Source

work_order: update

Yi 7 months ago
parent
commit
a990edb355

+ 1 - 1
go.mod

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

+ 6 - 0
go.sum

@@ -110,6 +110,12 @@ gitee.com/xuyiping_admin/go_proto v0.0.0-20240826081928-dc3ee5936a5b h1:znMSddT9
 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/go_proto v0.0.0-20240827023703-7eba31c2d498 h1:YjkXWHrtStOY29Qo0WNu45spuH2XaIU5N1LCpAmPhTI=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240827023703-7eba31c2d498/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240827031701-9ef29f36dc6d h1:DAGw5me2AWPbZuJdqVhbGz4SPJ+HqResWMX83QgXnUE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240827031701-9ef29f36dc6d/go.mod h1:BKrFW6YLDectlQcQk3FYKBeXvjEiodAKJ5rq7O/QiPE=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240827035612-bee09217eaa1 h1:8J2NBwEMMcAc8qwSlC9cNrhVcvVVhkRh046XO9IVvZY=
+gitee.com/xuyiping_admin/go_proto v0.0.0-20240827035612-bee09217eaa1/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=

+ 22 - 2
http/handler/work/order.go

@@ -1,15 +1,16 @@
 package work
 
 import (
-	"kpt-pasture/http/middleware"
 	"net/http"
+	"strconv"
 
-	"gitee.com/xuyiping_admin/pkg/valid"
+	"kpt-pasture/http/middleware"
 
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	operationPb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/operation"
 	"gitee.com/xuyiping_admin/pkg/apierr"
 	"gitee.com/xuyiping_admin/pkg/ginutil"
+	"gitee.com/xuyiping_admin/pkg/valid"
 	"github.com/gin-gonic/gin"
 )
 
@@ -65,3 +66,22 @@ func OrderCreateOrUpdate(c *gin.Context) {
 		Data: &operationPb.Success{Success: true},
 	})
 }
+
+func OrderIsShow(c *gin.Context) {
+	workOrderIdStr := c.Param("id")
+	workOrderId, _ := strconv.Atoi(workOrderIdStr)
+
+	if err := valid.Validate(workOrderId, valid.Required, valid.Min(1)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	if err := middleware.Dependency(c).StoreEventHub.OpsService.OrderIsShow(c, int64(workOrderId)); err != nil {
+		apierr.ClassifiedAbort(c, err)
+		return
+	}
+	ginutil.JSONResp(c, &operationPb.CommonOK{
+		Code: http.StatusOK,
+		Msg:  "ok",
+		Data: &operationPb.Success{Success: true},
+	})
+}

+ 1 - 0
http/route/system_api.go

@@ -18,6 +18,7 @@ func SystemAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		// Health Check
 		s.GET("/check", handler.Health)
 		s.POST("/api/v1/login", system.Login)
+		s.Static("/api/v1/files", "./files")
 
 		// system API 组  系统用户
 		systemRoute := authRouteGroup(s, "/api/v1/system/")

+ 1 - 0
http/route/work_order.go

@@ -15,5 +15,6 @@ func WorkOrderAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 		workRoute := authRouteGroup(s, "/api/v1/work/")
 		workRoute.POST("/order/list", work.OrderList)
 		workRoute.POST("/order/createOrUpdate", work.OrderCreateOrUpdate)
+		workRoute.PUT("/order/is_show/:id", work.OrderIsShow)
 	}
 }

+ 25 - 1
model/work_order.go

@@ -21,6 +21,7 @@ type WorkOrder struct {
 	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"`
@@ -61,6 +62,10 @@ func NewWorkOrder(
 			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,
@@ -73,6 +78,7 @@ func NewWorkOrder(
 		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,
@@ -88,10 +94,13 @@ 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 := make([]int32, 0), make([]int32, 0)
+		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)
@@ -106,6 +115,19 @@ func (w WorkOrderSlice) ToPB(
 			}
 		}
 
+		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,
@@ -124,6 +146,8 @@ func (w WorkOrderSlice) ToPB(
 			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,

+ 1 - 1
module/backend/config_data.go

@@ -594,7 +594,7 @@ func (s *StoreEntry) WeekEnumList() []*pasturePb.ConfigOptionsList {
 	return configOptions
 }
 
-func (s *StoreEntry) monthEnumList() []*pasturePb.ConfigOptionsList {
+func (s *StoreEntry) MonthEnumList() []*pasturePb.ConfigOptionsList {
 	configOptions := make([]*pasturePb.ConfigOptionsList, 0)
 	for v := 1; v <= 31; v++ {
 		configOptions = append(configOptions, &pasturePb.ConfigOptionsList{

+ 2 - 2
module/backend/dashboard.go

@@ -13,9 +13,9 @@ import (
 func (s *StoreEntry) Bar(ctx context.Context) (*pasturePb.BarCowStructResponse, error) {
 	barCowStructList := make([]*model.BarCowStruct, 0)
 	var count int32 = 0
-	if err := s.DB.Model(new(model.Cow)).Select("COUNT(*) AS number ,type_id").
+	if err := s.DB.Model(new(model.Cow)).Select("COUNT(*) AS number ,cow_type").
 		Where("is_remove = ?", pasturePb.IsShow_Ok).
-		Group("type_id").
+		Group("cow_type").
 		Find(&barCowStructList).Error; err != nil {
 		return nil, xerr.WithStack(err)
 	}

+ 8 - 0
module/backend/enum_map.go

@@ -50,6 +50,14 @@ func (s *StoreEntry) WeekMap() map[pasturePb.Week_Kind]string {
 	return res
 }
 
+func (s *StoreEntry) MonthMap() map[int32]string {
+	res := make(map[int32]string)
+	for _, v := range s.MonthEnumList() {
+		res[v.Value] = v.Label
+	}
+	return res
+}
+
 func (s *StoreEntry) CowTypeMap() map[pasturePb.CowType_Kind]string {
 	res := make(map[pasturePb.CowType_Kind]string)
 	for _, v := range s.CowTypeEnumList() {

+ 1 - 1
module/backend/enum_options.go

@@ -157,7 +157,7 @@ func (s *StoreEntry) SystemBaseConfigOptions(ctx context.Context, optionsName st
 	case "week":
 		configOptions = s.WeekEnumList()
 	case "month":
-		configOptions = s.monthEnumList()
+		configOptions = s.MonthEnumList()
 	case "sameTimeCowType":
 		configOptions = s.SemeTimeCowTypeEnumList()
 	case "immunizationCowType":

+ 1 - 0
module/backend/interface.go

@@ -191,4 +191,5 @@ type DashboardService interface {
 type WorkService interface {
 	OrderList(ctx context.Context, req *pasturePb.SearchWorkOrderRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchWorkOrderResponse, error)
 	OrderCreateOrUpdate(ctx context.Context, req *pasturePb.WorkOrderList) error
+	OrderIsShow(ctx context.Context, id int64) error
 }

+ 28 - 3
module/backend/work.go

@@ -2,13 +2,14 @@ package backend
 
 import (
 	"context"
+	"errors"
 	"fmt"
 	"kpt-pasture/model"
 	"net/http"
 
-	"gitee.com/xuyiping_admin/pkg/xerr"
-
 	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
+	"gitee.com/xuyiping_admin/pkg/xerr"
+	"gorm.io/gorm"
 )
 
 func (s *StoreEntry) OrderList(ctx context.Context, req *pasturePb.SearchWorkOrderRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SearchWorkOrderResponse, error) {
@@ -48,11 +49,13 @@ func (s *StoreEntry) OrderList(ctx context.Context, req *pasturePb.SearchWorkOrd
 	priorityMap := s.WorkOrderPriorityMap()
 	frequencyMap := s.WorkOrderFrequencyMap()
 	subscribeUnitMap := s.WorkOrderSubUnitMap()
+	weekMap := s.WeekMap()
+	monthMap := s.MonthMap()
 	return &pasturePb.SearchWorkOrderResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SearchWorkOrderData{
-			List:     model.WorkOrderSlice(workOrderList).ToPB(priorityMap, frequencyMap, subscribeUnitMap),
+			List:     model.WorkOrderSlice(workOrderList).ToPB(priorityMap, frequencyMap, subscribeUnitMap, weekMap, monthMap),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,
@@ -77,3 +80,25 @@ func (s *StoreEntry) OrderCreateOrUpdate(ctx context.Context, req *pasturePb.Wor
 	}
 	return nil
 }
+
+func (s *StoreEntry) OrderIsShow(ctx context.Context, id int64) error {
+	workOrder := &model.WorkOrder{
+		Id: id,
+	}
+	if err := s.DB.First(workOrder).Error; err != nil {
+		if errors.Is(err, gorm.ErrRecordNotFound) {
+			return xerr.Custom("该工单不存在")
+		}
+		return xerr.WithStack(err)
+	}
+	isShow := pasturePb.IsShow_No
+	if workOrder.IsShow == pasturePb.IsShow_No {
+		isShow = pasturePb.IsShow_Ok
+	}
+
+	if err := s.DB.Model(workOrder).Update("is_show", isShow).Error; err != nil {
+		return xerr.WithStack(err)
+	}
+
+	return nil
+}