calendar.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "kpt-pasture/util"
  7. "net/http"
  8. "regexp"
  9. "time"
  10. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  11. "gitee.com/xuyiping_admin/pkg/xerr"
  12. )
  13. // CalendarToDoList 获取日历待办列表
  14. func (s *StoreEntry) CalendarToDoList(ctx context.Context, req *pasturePb.CalendarToDoRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalendarToDoResponse, error) {
  15. userModel, err := s.GetUserModel(ctx)
  16. if err != nil {
  17. return nil, xerr.WithStack(err)
  18. }
  19. calendarToDoList := make([]*pasturePb.CalendarToDoList, 0)
  20. pastureWhereSql := fmt.Sprintf(" AND pasture_id = %d", userModel.AppPasture.Id)
  21. whereSql := ""
  22. if req.CowId > 0 {
  23. whereSql += fmt.Sprintf(" AND cow_id = %d", req.CowId)
  24. }
  25. if req.CalendarType > 0 {
  26. calendarTypeMap := CalendarTypeMap()
  27. calendarTypeName := calendarTypeMap[req.CalendarType]
  28. if len(calendarTypeName) > 0 {
  29. re := regexp.MustCompile(`[a-zA-Z]`) // 使用正则表达式替换匹配的字母为空字符串
  30. calendarTypeName = re.ReplaceAllString(calendarTypeName, "")
  31. whereSql += fmt.Sprintf(" AND calendar_type_name = '%s'", calendarTypeName)
  32. }
  33. }
  34. sql := `SELECT a.cow_id,b.pen_name,a.calendar_type_name,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day,b.lact,
  35. b.ear_number FROM (
  36. SELECT cow_id,plan_day,'免疫' as calendar_type_name FROM event_immunization_plan WHERE status = 2 ` + pastureWhereSql + `
  37. UNION ALL
  38. SELECT cow_id,plan_day ,'同期' as calendar_type_name FROM event_cow_same_time WHERE status = 2 ` + pastureWhereSql + `
  39. UNION ALL
  40. SELECT cow_id,plan_day ,'孕检' as calendar_type_name FROM event_pregnant_check WHERE status = 2 ` + pastureWhereSql + `
  41. UNION ALL
  42. SELECT cow_id,plan_day ,'断奶' as calendar_type_name FROM event_weaning WHERE status = 2 ` + pastureWhereSql + `
  43. UNION ALL
  44. SELECT cow_id,plan_day ,'配种' as calendar_type_name FROM event_mating WHERE status = 2 ` + pastureWhereSql + `
  45. UNION ALL
  46. SELECT cow_id,plan_day ,'产犊' as calendar_type_name FROM event_calving WHERE status = 2 ` + pastureWhereSql + `
  47. ) as a JOIN cow b ON a.cow_id = b.id WHERE 1 = 1 `
  48. completeSql := fmt.Sprintf("%s %s ORDER BY a.plan_day ASC", sql, whereSql)
  49. if err = s.DB.Raw(completeSql).Find(&calendarToDoList).Error; err != nil {
  50. return nil, err
  51. }
  52. list := Paginate(calendarToDoList, pagination.Page, pagination.PageSize)
  53. return &pasturePb.CalendarToDoResponse{
  54. Code: http.StatusOK,
  55. Msg: "ok",
  56. Data: &pasturePb.CalendarToDoData{
  57. List: list,
  58. Total: int32(len(list)),
  59. PageSize: pagination.PageSize,
  60. Page: pagination.Page,
  61. },
  62. }, nil
  63. }
  64. func (s *StoreEntry) CalendarList(ctx context.Context, req *pasturePb.CalendarRequest) (*pasturePb.CalendarResponse, error) {
  65. userModel, err := s.GetUserModel(ctx)
  66. if err != nil {
  67. return nil, xerr.WithStack(err)
  68. }
  69. calendarList := make([]*model.Calendar, 0)
  70. if err = s.DB.Model(&model.Calendar{}).
  71. Where("show_day >= ?", req.ShowStartDay).
  72. Where("show_day <= ?", req.ShowEndDay).
  73. Where("pasture_id = ?", userModel.AppPasture.Id).
  74. Where("is_show = ?", pasturePb.IsShow_Ok).
  75. Find(&calendarList).Error; err != nil {
  76. return nil, xerr.WithStack(err)
  77. }
  78. return &pasturePb.CalendarResponse{
  79. Code: http.StatusOK,
  80. Msg: "ok",
  81. Data: model.CalendarSlice(calendarList).ToPB(),
  82. }, nil
  83. }
  84. func (s *StoreEntry) CalendarTableDetail(
  85. ctx context.Context,
  86. req *pasturePb.CalendarTableRequest,
  87. pagination *pasturePb.PaginationModel,
  88. ) (interface{}, error) {
  89. userModel, err := s.GetUserModel(ctx)
  90. if err != nil {
  91. return nil, xerr.WithStack(err)
  92. }
  93. if req.Start != time.Now().Format(model.LayoutDate2) {
  94. return nil, xerr.Custom("只能获取当天的数据")
  95. }
  96. newCalendar := &model.Calendar{}
  97. if err = s.DB.Model(&model.Calendar{}).
  98. Where("calendar_type = ?", req.CalendarType).
  99. Where("show_day = ?", req.Start).
  100. Where("is_show = ?", pasturePb.IsShow_Ok).
  101. Where("pasture_id = ?", userModel.AppPasture.Id).
  102. First(newCalendar).Error; err != nil {
  103. return nil, xerr.WithStack(err)
  104. }
  105. if newCalendar.Id <= 0 {
  106. return nil, xerr.New("不存在该日历数据")
  107. }
  108. return s.getCalendarCowList(ctx, req.CalendarType, req.Start, pagination, userModel.AppPasture.Id)
  109. }
  110. func (s *StoreEntry) getCalendarCowList(
  111. ctx context.Context,
  112. calendarType pasturePb.CalendarType_Kind,
  113. showDay string,
  114. pagination *pasturePb.PaginationModel,
  115. pastureId int64,
  116. ) (interface{}, error) {
  117. req := &pasturePb.ItemsRequest{EndDay: showDay, CalendarType: calendarType, PastureId: int32(pastureId)}
  118. switch calendarType {
  119. case pasturePb.CalendarType_Immunisation: // 免疫
  120. return s.ImmunisationCowList(ctx, req, pagination)
  121. case pasturePb.CalendarType_PG, pasturePb.CalendarType_RnGH: // 同期
  122. return s.SameTimeCowList(ctx, req, pagination)
  123. case pasturePb.CalendarType_Pregnancy_Check: // 孕检
  124. return s.PregnancyCheckCowList(ctx, req, pagination)
  125. case pasturePb.CalendarType_WorkOrder: // 工作单
  126. return s.WorkOrderCowList(ctx, req, pagination)
  127. case pasturePb.CalendarType_Weaning: // 断奶
  128. return s.WeaningCowList(ctx, req, pagination)
  129. case pasturePb.CalendarType_Treatment: // 治疗
  130. return s.TreatmentCowList(ctx, req, pagination)
  131. case pasturePb.CalendarType_Mating: // 配种
  132. return s.MatingCowList(ctx, req, pagination)
  133. case pasturePb.CalendarType_Calving: // 产犊
  134. return s.CalvingCowList(ctx, req, pagination)
  135. default:
  136. return nil, xerr.New("不支持的日历类型")
  137. }
  138. }
  139. func (s *StoreEntry) ImmunisationCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.ImmunizationItemsResponse, error) {
  140. userModel, err := s.GetUserModel(ctx)
  141. if err != nil {
  142. return nil, xerr.WithStack(err)
  143. }
  144. eventImmunizationPlanList := make([]*model.EventImmunizationPlan, 0)
  145. count := int64(0)
  146. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventImmunizationPlan).TableName())).
  147. Select("a.id,a.cow_id,a.plan_day,a.plan_name as immunization_plan_name,b.pen_name,b.day_age,b.ear_number").
  148. Joins(fmt.Sprintf("JOIN %s AS b on a.cow_id = b.id", new(model.Cow).TableName())).
  149. Where("a.status = ?", pasturePb.IsShow_No).
  150. Where("a.pasture_id = ?", userModel.AppPasture.Id)
  151. if req.StartDay != "" && req.EndDay != "" {
  152. startTime := util.TimeParseLocalUnix(req.StartDay)
  153. endTime := util.TimeParseLocalEndUnix(req.EndDay)
  154. pref.Where("a.plan_day between ? and ?", startTime, endTime)
  155. }
  156. if req.CowId > 0 {
  157. pref.Where("a.cow_id = ?", req.CowId)
  158. }
  159. if req.ImmunizationId > 0 {
  160. pref.Where("a.plan_id = ?", req.ImmunizationId)
  161. }
  162. if req.PenId > 0 {
  163. pref.Where("b.pen_id = ?", req.PenId)
  164. }
  165. if err = pref.Order("id desc").
  166. Count(&count).
  167. Limit(int(pagination.PageSize)).
  168. Offset(int(pagination.PageOffset)).
  169. Order("id desc").
  170. Find(&eventImmunizationPlanList).Error; err != nil {
  171. return nil, xerr.WithStack(err)
  172. }
  173. return &pasturePb.ImmunizationItemsResponse{
  174. Code: http.StatusOK,
  175. Msg: "ok",
  176. Data: &pasturePb.ImmunizationItemsData{
  177. Total: int32(count),
  178. Page: pagination.Page,
  179. PageSize: pagination.PageSize,
  180. Header: map[string]string{
  181. "id": "编号",
  182. "cowId": "牛号",
  183. "earNumber": "耳标号",
  184. "penName": "栏舍",
  185. "dayAge": "日龄",
  186. "planDay": "免疫时间",
  187. "immunizationPlanName": "免疫名称",
  188. },
  189. List: model.EventImmunizationPlanSlice(eventImmunizationPlanList).ToPB(),
  190. },
  191. }, nil
  192. }
  193. func (s *StoreEntry) SameTimeCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.SameTimeItemResponse, error) {
  194. userModel, err := s.GetUserModel(ctx)
  195. if err != nil {
  196. return nil, xerr.WithStack(err)
  197. }
  198. sameTimeBodyList := make([]*model.SameTimeItemBody, 0)
  199. count := int64(0)
  200. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCowSameTime).TableName())).
  201. Select(`a.id,a.cow_id,a.ear_number,a.pen_name,a.status,a.same_time_type,b.breed_status,a.same_time_name,a.plan_day,
  202. b.cow_type,b.day_age,b.calving_age,b.abortion_age,b.last_calving_at,b.last_abortion_at,b.lact,b.pen_name,b.mating_times`).
  203. Joins("left join cow as b on a.cow_id = b.id").
  204. Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
  205. Where("a.pasture_id = ?", userModel.AppPasture.Id).
  206. Where("a.status = ?", pasturePb.IsShow_No)
  207. if req.EndDay != "" {
  208. dateTime := util.TimeParseLocalEndUnix(req.EndDay)
  209. pref.Where("a.plan_day <= ?", dateTime)
  210. }
  211. if req.CowType > 0 {
  212. pref.Where("b.cow_type = ?", req.CowType)
  213. }
  214. if err = pref.Order("a.plan_day ASC").Count(&count).
  215. Limit(int(pagination.PageSize)).
  216. Offset(int(pagination.PageOffset)).
  217. Find(&sameTimeBodyList).Error; err != nil {
  218. return nil, xerr.WithStack(err)
  219. }
  220. breedStatusMap := s.CowBreedStatusMap()
  221. penMap := s.PenMap(ctx, int64(req.PastureId))
  222. sameTimeTypeMap := s.SameTimeTypeMap()
  223. return &pasturePb.SameTimeItemResponse{
  224. Code: http.StatusOK,
  225. Msg: "ok",
  226. Data: &pasturePb.SameTimeItemsData{
  227. Total: int32(count),
  228. Page: pagination.Page,
  229. PageSize: pagination.PageSize,
  230. Header: map[string]string{
  231. "id": "编号",
  232. "cowId": "牛号",
  233. "earNumber": "耳标号",
  234. "breedStatusName": "繁殖状态",
  235. "cowTypeName": "牛只类型",
  236. "planDayAtFormat": "执行日期",
  237. "penName": "栏舍",
  238. "lact": "胎次",
  239. "calvingAge": "产后天数",
  240. "abortionAge": "流产天数",
  241. "dayAge": "日龄",
  242. "status": "状态",
  243. "sameTimeTypeName": "处理方式",
  244. "matingTimes": "本胎次配次",
  245. "calvingAtFormat": "产犊日期",
  246. "abortionAtFormat": "流产日期",
  247. "sameTimeName": "同期名称",
  248. },
  249. List: model.SameTimeBodySlice(sameTimeBodyList).ToPB(breedStatusMap, penMap, sameTimeTypeMap),
  250. },
  251. }, nil
  252. }
  253. func (s *StoreEntry) PregnancyCheckCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyCheckItemsResponse, error) {
  254. userModel, err := s.GetUserModel(ctx)
  255. if err != nil {
  256. return nil, xerr.WithStack(err)
  257. }
  258. newPregnancyCheckItems := make([]*pasturePb.PregnancyCheckItems, 0)
  259. var count int64
  260. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventPregnantCheck).TableName())).
  261. Select("a.id,a.cow_id,a.ear_number,a.pen_id,a.status,b.breed_status,b.pen_name,b.cow_type,b.day_age,b.calving_age,b.abortion_age,a.bull_id").
  262. Joins("left join cow as b on a.cow_id = b.id").
  263. Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
  264. Where("a.pasture_id = ?", userModel.AppPasture.Id).
  265. Where("a.status = ?", pasturePb.IsShow_No)
  266. if req.EndDay != "" {
  267. dateTime := util.TimeParseLocalEndUnix(req.EndDay)
  268. pref.Where("a.plan_day <= ?", dateTime)
  269. }
  270. if req.CowType > 0 {
  271. pref.Where("a.cow_type = ?", req.CowType)
  272. }
  273. if req.Status > 0 {
  274. pref.Where("a.status = ?", req.Status)
  275. }
  276. if req.PregnantCheckType > 0 {
  277. pref.Where("a.pregnant_check_name = ?", model.PregnantCheckNameValueMap[req.PregnantCheckType])
  278. }
  279. if err = pref.Order("a.plan_day ASC").
  280. Count(&count).
  281. Limit(int(pagination.PageSize)).
  282. Offset(int(pagination.PageOffset)).
  283. Find(&newPregnancyCheckItems).Error; err != nil {
  284. return nil, xerr.WithStack(err)
  285. }
  286. return &pasturePb.PregnancyCheckItemsResponse{
  287. Code: http.StatusOK,
  288. Msg: "ok",
  289. Data: &pasturePb.PregnancyCheckItemsData{
  290. Total: int32(count),
  291. Page: pagination.Page,
  292. PageSize: pagination.PageSize,
  293. Header: map[string]string{
  294. "id": "编号",
  295. "cowId": "牛号",
  296. "earNumber": "耳标号",
  297. "cowTypeName": "牛只类型",
  298. "penName": "栏舍",
  299. "lact": "胎次",
  300. "dayAge": "日龄",
  301. "planDay": "孕检日期",
  302. "checkTypeName": "孕检名称",
  303. "status": "状态",
  304. "matingTimes": "配次",
  305. "calvingAtFormat": "产检日期",
  306. "matingAtFormat": "配种日期",
  307. "matingAge": "配后天数",
  308. "bullId": "配种公牛",
  309. },
  310. List: newPregnancyCheckItems,
  311. },
  312. }, nil
  313. }
  314. func (s *StoreEntry) WeaningCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.WeaningItemsResponse, error) {
  315. userModel, err := s.GetUserModel(ctx)
  316. if err != nil {
  317. return nil, xerr.WithStack(err)
  318. }
  319. weaningItems := make([]*pasturePb.WeaningItems, 0)
  320. count := int64(0)
  321. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventWeaning).TableName())).
  322. Select(`a.id,a.cow_id,b.current_weight as current_weight,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day_format,
  323. b.day_age,b.pen_name,b.ear_number,DATE_FORMAT(FROM_UNIXTIME(b.birth_at), '%Y-%m-%d') AS birth_at_format`).
  324. Joins("left join cow as b on a.cow_id = b.id").
  325. Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
  326. Where("a.status = ?", pasturePb.IsShow_No).
  327. Where("a.pasture_id = ?", userModel.AppPasture.Id)
  328. if req.EndDay != "" {
  329. dateTime := util.TimeParseLocalEndUnix(req.EndDay)
  330. pref.Where("a.plan_day <= ?", dateTime)
  331. }
  332. if err = pref.Order("a.plan_day ASC").Count(&count).
  333. Limit(int(pagination.PageSize)).
  334. Offset(int(pagination.PageOffset)).
  335. Find(&weaningItems).Error; err != nil {
  336. return nil, xerr.WithStack(err)
  337. }
  338. return &pasturePb.WeaningItemsResponse{
  339. Code: http.StatusOK,
  340. Msg: "ok",
  341. Data: &pasturePb.WeaningItemsData{
  342. Total: int32(count),
  343. Page: pagination.Page,
  344. PageSize: pagination.PageSize,
  345. Header: map[string]string{
  346. "id": "编号",
  347. "cowId": "牛号",
  348. "earNumber": "耳标号",
  349. "penName": "栏舍",
  350. "dayAge": "日龄",
  351. "planDayFormat": "断奶日期",
  352. "birthAtFormat": "出生日期",
  353. "currentWeight": "体重",
  354. },
  355. List: weaningItems,
  356. },
  357. }, nil
  358. }
  359. func (s *StoreEntry) MatingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.MatingItemsResponse, error) {
  360. userModel, err := s.GetUserModel(ctx)
  361. if err != nil {
  362. return nil, xerr.WithStack(err)
  363. }
  364. matingItems := make([]*pasturePb.MatingItems, 0)
  365. count := int64(0)
  366. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventMating).TableName())).
  367. Select(`a.id,a.cow_id,a.status,a.ear_number,
  368. CASE a.expose_estrus_type
  369. WHEN 1 THEN '脖环揭发'
  370. WHEN 2 THEN '脚环/计步器'
  371. WHEN 3 THEN '自然发情'
  372. WHEN 4 THEN '同期'
  373. ELSE '其他'
  374. END AS expose_estrus_type_name,
  375. b.breed_status,b.cow_type,b.pen_id,b.day_age,b.calving_age,b.abortion_age,b.pen_name`).
  376. Joins("left join cow as b on a.cow_id = b.id").
  377. Where("a.pasture_id = ?", userModel.AppPasture.Id).
  378. Where("a.status = ?", pasturePb.IsShow_No)
  379. if req.EndDay != "" {
  380. dateTime := util.TimeParseLocalEndUnix(req.EndDay)
  381. pref.Where("a.plan_day <= ?", dateTime)
  382. }
  383. if req.PenId > 0 {
  384. pref.Where("b.pen_id = ?", req.PenId)
  385. }
  386. if err = pref.Order("a.plan_day ASC").
  387. Count(&count).
  388. Limit(int(pagination.PageSize)).
  389. Offset(int(pagination.PageOffset)).
  390. Find(&matingItems).Error; err != nil {
  391. return nil, xerr.WithStack(err)
  392. }
  393. return &pasturePb.MatingItemsResponse{
  394. Code: http.StatusOK,
  395. Msg: "ok",
  396. Data: &pasturePb.MatingItemsData{
  397. Total: int32(count),
  398. Page: pagination.Page,
  399. PageSize: pagination.PageSize,
  400. Header: map[string]string{
  401. "id": "编号",
  402. "cowId": "牛号",
  403. "earNumber": "耳标号",
  404. "breedStatusName": "繁殖状态",
  405. "cowTypeName": "牛只类型",
  406. "penName": "栏舍",
  407. "lact": "胎次",
  408. "calvingAge": "产后天数",
  409. "abortionAge": "流产天数",
  410. "dayAge": "日龄",
  411. "status": "状态",
  412. "exposeEstrusTypeName": "发情揭发方式",
  413. },
  414. List: matingItems,
  415. },
  416. }, nil
  417. }
  418. func (s *StoreEntry) CalvingCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (*pasturePb.CalvingItemsResponse, error) {
  419. userModel, err := s.GetUserModel(ctx)
  420. if err != nil {
  421. return nil, xerr.WithStack(err)
  422. }
  423. calvingItems := make([]*pasturePb.CalvingItems, 0)
  424. count := int64(0)
  425. pref := s.DB.Table(fmt.Sprintf("%s as a", new(model.EventCalving).TableName())).
  426. Select(`a.id,a.cow_id,a.ear_number,a.status,b.breed_status,b.pen_id,DATE_FORMAT(FROM_UNIXTIME(last_mating_at), '%Y-%m-%d') AS mating_at_format,
  427. b.day_age,b.last_bull_number as bull_id,b.pen_name,DATEDIFF(NOW(),FROM_UNIXTIME(last_mating_at)) AS mating_age,DATE_FORMAT(FROM_UNIXTIME(a.plan_day), '%Y-%m-%d') AS plan_day`).
  428. Joins("left join cow as b on a.cow_id = b.id").
  429. Where("a.status = ?", pasturePb.IsShow_No).
  430. Where("b.admission_status = ?", pasturePb.AdmissionStatus_Admission).
  431. Where("a.pasture_id = ?", userModel.AppPasture.Id)
  432. if req.EndDay != "" {
  433. dateTime := util.TimeParseLocalEndUnix(req.EndDay)
  434. pref.Where("a.plan_day <= ?", dateTime)
  435. }
  436. if req.Status > 0 {
  437. pref.Where("a.status = ?", req.Status)
  438. }
  439. if err = pref.Order("a.plan_day ASC").
  440. Count(&count).
  441. Limit(int(pagination.PageSize)).
  442. Offset(int(pagination.PageOffset)).
  443. Find(&calvingItems).Error; err != nil {
  444. return nil, xerr.WithStack(err)
  445. }
  446. breedStatusMap := s.CowBreedStatusMap()
  447. for _, v := range calvingItems {
  448. breedStatusName := ""
  449. if breedStatus, ok := breedStatusMap[v.BreedStatus]; ok {
  450. breedStatusName = breedStatus
  451. }
  452. v.BreedStatusName = breedStatusName
  453. }
  454. return &pasturePb.CalvingItemsResponse{
  455. Code: http.StatusOK,
  456. Msg: "ok",
  457. Data: &pasturePb.CalvingItemsData{
  458. Total: int32(count),
  459. Page: pagination.Page,
  460. PageSize: pagination.PageSize,
  461. Header: map[string]string{
  462. "id": "编号",
  463. "cowId": "牛号",
  464. "earNumber": "耳标号",
  465. "breedStatusName": "繁殖状态",
  466. "penName": "栏舍",
  467. "lact": "胎次",
  468. "matingAge": "配后天数",
  469. "dayAge": "日龄",
  470. "status": "是否完成",
  471. "bullId": "配种公牛号",
  472. "planDay": "预产时间",
  473. "matingAtFormat": "配种时间",
  474. },
  475. List: calvingItems,
  476. },
  477. }, nil
  478. }
  479. // WorkOrderCowList 暂时不处理工单业务
  480. func (s *StoreEntry) WorkOrderCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (interface{}, error) {
  481. return nil, nil
  482. }
  483. // TreatmentCowList 治疗清单
  484. func (s *StoreEntry) TreatmentCowList(ctx context.Context, req *pasturePb.ItemsRequest, pagination *pasturePb.PaginationModel) (interface{}, error) {
  485. return nil, nil
  486. }
  487. // Paginate 函数用于对切片进行分页
  488. func Paginate(slice []*pasturePb.CalendarToDoList, page int32, pageSize int32) []*pasturePb.CalendarToDoList {
  489. // 计算起始索引
  490. start := (page - 1) * pageSize
  491. // 如果起始索引超出切片长度,返回空切片
  492. if start >= int32(len(slice)) {
  493. return []*pasturePb.CalendarToDoList{}
  494. }
  495. // 计算结束索引
  496. end := start + pageSize
  497. // 如果结束索引超出切片长度,调整到切片末尾
  498. if end > int32(len(slice)) {
  499. end = int32(len(slice))
  500. }
  501. // 返回分页后的切片
  502. return slice[start:end]
  503. }