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