Procházet zdrojové kódy

work_order: 工单管理

Yi před 7 měsíci
rodič
revize
d3a4d88518
2 změnil soubory, kde provedl 15 přidání a 19 odebrání
  1. 13 16
      model/prescription.go
  2. 2 3
      module/backend/prescription.go

+ 13 - 16
model/prescription.go

@@ -3,10 +3,9 @@ package model
 import (
 	"encoding/json"
 
+	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 	"gitee.com/xuyiping_admin/pkg/logger/zaplog"
 	"go.uber.org/zap"
-
-	pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
 )
 
 type Prescription struct {
@@ -20,6 +19,7 @@ type Prescription struct {
 	IsShow            pasturePb.IsShow_Kind `json:"is_show"`
 	Remarks           string                `json:"remarks"`
 	OperationId       int64                 `json:"operation_id"`
+	OperationName     string                `json:"operation_name"`
 	CreatedAt         int64                 `json:"created_at"`
 	UpdatedAt         int64                 `json:"updated_at"`
 }
@@ -33,7 +33,8 @@ type ApplicableDisease struct {
 	DiseaseName string `json:"disease_name"`
 }
 
-func NewPrescription(req *pasturePb.PrescriptionRequest, applicableDisease string, useDays, meatExpiredDays, milkExpiredDays int32, operationId int64) *Prescription {
+func NewPrescription(req *pasturePb.PrescriptionRequest, applicableDisease string, useDays,
+	meatExpiredDays, milkExpiredDays int32, systemUser *SystemUser) *Prescription {
 	return &Prescription{
 		Name:              req.Name,
 		ApplicableDisease: applicableDisease,
@@ -43,22 +44,16 @@ func NewPrescription(req *pasturePb.PrescriptionRequest, applicableDisease strin
 		MilkExpiredDays:   milkExpiredDays,
 		IsShow:            req.IsShow,
 		Remarks:           req.Remarks,
-		OperationId:       operationId,
+		OperationId:       systemUser.Id,
+		OperationName:     systemUser.Name,
 	}
 }
 
 type PrescriptionSlice []*Prescription
 
-func (p PrescriptionSlice) ToPB(userList []*SystemUser, prescriptionDrugsList []*PrescriptionDrugs) []*pasturePb.SearchPrescriptionList {
+func (p PrescriptionSlice) ToPB(prescriptionDrugsList []*PrescriptionDrugs) []*pasturePb.SearchPrescriptionList {
 	res := make([]*pasturePb.SearchPrescriptionList, len(p))
 	for i, v := range p {
-		operationName := ""
-		for _, u := range userList {
-			if u.Id == v.OperationId {
-				operationName = u.Name
-				break
-			}
-		}
 		drugsList := make([]*pasturePb.PrescriptionDrugsList, 0)
 		for _, d := range prescriptionDrugsList {
 			if d.PrescriptionId != v.Id {
@@ -76,9 +71,11 @@ func (p PrescriptionSlice) ToPB(userList []*SystemUser, prescriptionDrugsList []
 			})
 		}
 		applicableDiseaseList := make([]*ApplicableDisease, 0)
-		err := json.Unmarshal([]byte(v.ApplicableDisease), &applicableDiseaseList)
-		if err != nil {
-			zaplog.Error("PrescriptionSliceToPB", zap.Any("err", err))
+		if v.ApplicableDisease != "" {
+			err := json.Unmarshal([]byte(v.ApplicableDisease), &applicableDiseaseList)
+			if err != nil {
+				zaplog.Error("PrescriptionSliceToPB", zap.Any("err", err))
+			}
 		}
 		applicableDiseaseNames := make([]string, 0)
 		applicableDiseaseIds := make([]int32, 0)
@@ -99,7 +96,7 @@ func (p PrescriptionSlice) ToPB(userList []*SystemUser, prescriptionDrugsList []
 			IsShow:                 v.IsShow,
 			Remarks:                v.Remarks,
 			OperationId:            int32(v.OperationId),
-			OperationName:          operationName,
+			OperationName:          v.OperationName,
 			CreatedAt:              int32(v.CreatedAt),
 			UpdatedAt:              int32(v.UpdatedAt),
 			DrugsList:              drugsList,

+ 2 - 3
module/backend/prescription.go

@@ -241,12 +241,11 @@ func (s *StoreEntry) SearchPrescriptionList(ctx context.Context, req *pasturePb.
 		}
 	}
 
-	systemUserList, _ := s.SystemUserList(ctx)
 	return &pasturePb.SearchPrescriptionResponse{
 		Code:    http.StatusOK,
 		Message: "ok",
 		Data: &pasturePb.SearchPrescriptionData{
-			List:     model.PrescriptionSlice(prescriptionList).ToPB(systemUserList, prescriptionDrugs),
+			List:     model.PrescriptionSlice(prescriptionList).ToPB(prescriptionDrugs),
 			Total:    int32(count),
 			PageSize: pagination.PageSize,
 			Page:     pagination.Page,
@@ -298,7 +297,7 @@ func (s *StoreEntry) CreateOrUpdatePrescription(ctx context.Context, req *pastur
 		b, _ := json.Marshal(applicableDiseaseList)
 		applicableDisease = string(b)
 	}
-	newPrescription := model.NewPrescription(req, applicableDisease, maxUseDays, maxMeatExpiredDays, maxMilkExpiredDays, currUser.Id)
+	newPrescription := model.NewPrescription(req, applicableDisease, maxUseDays, maxMeatExpiredDays, maxMilkExpiredDays, currUser)
 
 	if req.Id > 0 {
 		prescription := &model.Prescription{Id: int64(req.Id)}