123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package model
- import (
- "strconv"
- "strings"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- )
- type Prescription struct {
- Id int32 `json:"id"`
- PastureId int64 `json:"pastureId"`
- Name string `json:"name"`
- ApplicableDisease string `json:"applicableDisease"`
- UseDays int32 `json:"useDays"`
- UseCount int32 `json:"useCount"`
- MeatExpiredDays int32 `json:"meatExpiredDays"`
- MilkExpiredDays int32 `json:"milkExpiredDays"`
- IsShow pasturePb.IsShow_Kind `json:"isShow"`
- Remarks string `json:"remarks"`
- OperationId int64 `json:"operationId"`
- OperationName string `json:"operationName"`
- CreatedAt int64 `json:"createdAt"`
- UpdatedAt int64 `json:"updatedAt"`
- }
- func (p *Prescription) TableName() string {
- return "prescription"
- }
- func (p *Prescription) EventUseCountUpdate() {
- p.UseCount += 1
- }
- func NewPrescription(
- pastureId int64,
- req *pasturePb.PrescriptionRequest,
- applicableDisease string,
- useDays,
- meatExpiredDays,
- milkExpiredDays int32,
- systemUser *SystemUser,
- ) *Prescription {
- return &Prescription{
- PastureId: pastureId,
- Name: req.Name,
- ApplicableDisease: applicableDisease,
- UseDays: useDays,
- UseCount: 0,
- MeatExpiredDays: meatExpiredDays,
- MilkExpiredDays: milkExpiredDays,
- IsShow: req.IsShow,
- Remarks: req.Remarks,
- OperationId: systemUser.Id,
- OperationName: systemUser.Name,
- }
- }
- type PrescriptionSlice []*Prescription
- func (p PrescriptionSlice) ToPB(prescriptionDrugsList []*PrescriptionDrugs, diseaseMap map[int64]*Disease) []*pasturePb.SearchPrescriptionList {
- res := make([]*pasturePb.SearchPrescriptionList, len(p))
- for i, v := range p {
- drugsList := make([]*pasturePb.PrescriptionDrugsList, 0)
- for _, pl := range prescriptionDrugsList {
- if pl.PrescriptionId != v.Id {
- continue
- }
- drugsList = append(drugsList, &pasturePb.PrescriptionDrugsList{
- Id: pl.Id,
- DrugsId: int32(pl.DrugsId),
- DrugsName: pl.DrugsName,
- Unit: pl.Unit,
- UnitName: pl.UnitName,
- Dosages: pl.Dosages,
- UseDays: pl.UseDays,
- Specs: pl.Specs,
- })
- }
- applicableDiseaseList := strings.Split(v.ApplicableDisease, ",")
- applicableDiseaseNames := make([]string, 0)
- applicableDiseaseIds := make([]int32, 0)
- for _, ad := range applicableDiseaseList {
- diseaseId, _ := strconv.ParseInt(ad, 10, 64)
- applicableDiseaseIds = append(applicableDiseaseIds, int32(diseaseId))
- if dis, ok := diseaseMap[diseaseId]; ok {
- applicableDiseaseNames = append(applicableDiseaseNames, dis.Name)
- }
- }
- res[i] = &pasturePb.SearchPrescriptionList{
- Id: int32(v.Id),
- Name: v.Name,
- ApplicableDisease: v.ApplicableDisease,
- ApplicableDiseaseIds: applicableDiseaseIds,
- ApplicableDiseaseNames: applicableDiseaseNames,
- UseDays: v.UseDays,
- UseCount: v.UseCount,
- MeatExpiredDays: v.MeatExpiredDays,
- MilkExpiredDays: v.MilkExpiredDays,
- IsShow: v.IsShow,
- Remarks: v.Remarks,
- OperationId: int32(v.OperationId),
- OperationName: v.OperationName,
- CreatedAt: int32(v.CreatedAt),
- UpdatedAt: int32(v.UpdatedAt),
- DrugsList: drugsList,
- }
- }
- return res
- }
- func (p PrescriptionSlice) ToPB2() []*pasturePb.ConfigOptionsList {
- res := make([]*pasturePb.ConfigOptionsList, len(p))
- for i, d := range p {
- res[i] = &pasturePb.ConfigOptionsList{
- Value: int32(d.Id),
- Label: d.Name,
- Disabled: true,
- }
- }
- return res
- }
|