123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- package backend
- import (
- "context"
- "fmt"
- "kpt-pasture/model"
- "kpt-pasture/util"
- "net/http"
- "time"
- pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
- "gitee.com/xuyiping_admin/pkg/xerr"
- )
- func (s *StoreEntry) WorkOrderSubUnitEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderSubscribeUnit_Person),
- Label: "个人",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderSubscribeUnit_dept),
- Label: "部门",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) WorkOrderPriorityEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Priority_Low),
- Label: "低",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Priority_Middle),
- Label: "一般",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Priority_High),
- Label: "紧急",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) WorkOrderCategoryEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderCategory_Health),
- Label: "保健",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderCategory_Breed),
- Label: "繁殖",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderCategory_Nutrition),
- Label: "营养",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderCategory_Ordinary),
- Label: "日常",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WorkOrderCategory_Other),
- Label: "其他",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) AdmissionStatusEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AuditStatus_Invalid),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AdmissionStatus_Admission),
- Label: "在群",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AdmissionStatus_Die),
- Label: "死亡",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AdmissionStatus_Out),
- Label: "淘汰",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AdmissionStatus_Sale),
- Label: "售卖",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AdmissionStatus_Transfer),
- Label: "转出",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) ForbiddenMatingReasonsEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.AuditStatus_Invalid),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Metritis),
- Label: "子宫炎",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Reproductive_Diseases),
- Label: "繁殖疾病",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Reproductive_Failure),
- Label: "繁殖障碍",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Breast_Abnormalities),
- Label: "乳腺异常",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Low_Yield),
- Label: "低产",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Hoof_Disease),
- Label: "蹄病",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.ForbiddenMatingReasons_Other),
- Label: "其他",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) WarningHealthLevel(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WarningHealthLevel_Preliminary),
- Label: "初级疑似",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WarningHealthLevel_Moderate),
- Label: "中级疑似",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.WarningHealthLevel_Height),
- Label: "高度疑似",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) Behavior(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Behavior_Rumina),
- Label: "反刍",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Behavior_Intake),
- Label: "采食",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Behavior_Reset),
- Label: "休息",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Behavior_Immobility),
- Label: "静止",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.Behavior_Chew),
- Label: "咀嚼",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) HealthStatusEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Invalid),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Health),
- Label: "健康",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Disease),
- Label: "发病",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Treatment),
- Label: "治疗中",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Curable),
- Label: "治愈",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Out),
- Label: "淘汰",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.HealthStatus_Dead),
- Label: "死亡",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) MatingWindowPeriodEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.MatingWindowPeriod_Front),
- Label: "早期",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.MatingWindowPeriod_Middle),
- Label: "最优",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.MatingWindowPeriod_Behind),
- Label: "晚期",
- Disabled: true,
- })
- return configOptions
- }
- func (s *StoreEntry) DataWaringTypeEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DataWarningType_Sale_Standard),
- Label: "出栏标准",
- Disabled: true,
- Props: "达到出栏重量的牛只",
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DataWarningType_UnPregnant_Mating_Time),
- Label: ">6次未孕牛只",
- Disabled: true,
- Props: "配次高于6次未孕牛只",
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DataWarningType_Abortion_Time),
- Label: ">2次流产牛只",
- Disabled: true,
- Props: "本胎次内流产大于2次的牛只",
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DataWarningType_Over_Age_UnPaired_Young),
- Label: "超龄未配(青年牛)",
- Disabled: true,
- Props: "超15个月未配青年牛",
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DataWarningType_Over_Age_UnPregnant_Young),
- Label: "超龄未孕(青年牛)",
- Disabled: true,
- Props: "超22月未孕青年牛",
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.DataWarningType_Over_Age_UnPregnant_Young),
- Label: "超18月未卖",
- Disabled: true,
- Props: "饲养超过18个月未卖出牛只",
- })
- return configOptions
- }
- func (s *StoreEntry) NeckRingErrorEnumList(isAll string) []*pasturePb.ConfigOptionsList {
- configOptions := make([]*pasturePb.ConfigOptionsList, 0)
- if isAll == model.IsAllYes {
- configOptions = append(configOptions,
- &pasturePb.ConfigOptionsList{
- Value: int32(0),
- Label: "全部",
- Disabled: true,
- })
- }
- configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Suspected_Fall_Off),
- Label: "疑似脱落",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_No_Signal),
- Label: "无信号",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Receiving_Less),
- Label: "接受数据过少",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Low_Battery),
- Label: "低电量",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Data_Latency),
- Label: "数据有延迟",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Low_Activity_Level),
- Label: "活动量过低",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Abnormal_Wearing),
- Label: "佩戴异常",
- Disabled: true,
- }, &pasturePb.ConfigOptionsList{
- Value: int32(pasturePb.NeckRingNumberError_Should_Associated),
- Label: "脖环号未绑定牛号",
- Disabled: true,
- })
- return configOptions
- }
- // FindCowHistoryBatchNumber 获取历史批次号
- func (s *StoreEntry) FindCowHistoryBatchNumber(ctx context.Context) (*model.HistoryBatchNumberResponse, error) {
- userModel, err := s.GetUserModel(ctx)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- res := make([]string, 0)
- if err = s.DB.Model(new(model.EventEnter)).
- Select("batch_number").
- Where("pasture_id = ?", userModel.AppPasture.Id).
- Where("batch_number != ''").
- Group("batch_number").
- Find(&res).Error; err != nil {
- return nil, xerr.WithStack(err)
- }
- return &model.HistoryBatchNumberResponse{
- Code: http.StatusOK,
- Msg: "ok",
- Data: res,
- }, nil
- }
- func (s *StoreEntry) GenerateBatchNumber(ctx context.Context) (*model.GenerateBatchNumberResponse, error) {
- userModel, err := s.GetUserModel(ctx)
- if err != nil {
- return nil, xerr.WithStack(err)
- }
- data := fmt.Sprintf("%s%d%s", time.Now().Local().Format(model.LayoutDate), userModel.AppPasture.Id, util.GenerateRandomNumber(10))
- return &model.GenerateBatchNumberResponse{
- Code: http.StatusOK,
- Msg: "ok",
- Data: data,
- }, nil
- }
|