config_data_extend.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "kpt-pasture/util"
  7. "net/http"
  8. "time"
  9. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  10. "gitee.com/xuyiping_admin/pkg/xerr"
  11. )
  12. func (s *StoreEntry) WorkOrderSubUnitEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  13. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  14. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  15. Value: int32(pasturePb.WorkOrderSubscribeUnit_Person),
  16. Label: "个人",
  17. Disabled: true,
  18. }, &pasturePb.ConfigOptionsList{
  19. Value: int32(pasturePb.WorkOrderSubscribeUnit_dept),
  20. Label: "部门",
  21. Disabled: true,
  22. })
  23. return configOptions
  24. }
  25. func (s *StoreEntry) WorkOrderPriorityEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  26. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  27. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  28. Value: int32(pasturePb.Priority_Low),
  29. Label: "低",
  30. Disabled: true,
  31. }, &pasturePb.ConfigOptionsList{
  32. Value: int32(pasturePb.Priority_Middle),
  33. Label: "一般",
  34. Disabled: true,
  35. }, &pasturePb.ConfigOptionsList{
  36. Value: int32(pasturePb.Priority_High),
  37. Label: "紧急",
  38. Disabled: true,
  39. })
  40. return configOptions
  41. }
  42. func (s *StoreEntry) WorkOrderCategoryEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  43. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  44. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  45. Value: int32(pasturePb.WorkOrderCategory_Health),
  46. Label: "保健",
  47. Disabled: true,
  48. }, &pasturePb.ConfigOptionsList{
  49. Value: int32(pasturePb.WorkOrderCategory_Breed),
  50. Label: "繁殖",
  51. Disabled: true,
  52. }, &pasturePb.ConfigOptionsList{
  53. Value: int32(pasturePb.WorkOrderCategory_Nutrition),
  54. Label: "营养",
  55. Disabled: true,
  56. }, &pasturePb.ConfigOptionsList{
  57. Value: int32(pasturePb.WorkOrderCategory_Ordinary),
  58. Label: "日常",
  59. Disabled: true,
  60. }, &pasturePb.ConfigOptionsList{
  61. Value: int32(pasturePb.WorkOrderCategory_Other),
  62. Label: "其他",
  63. Disabled: true,
  64. })
  65. return configOptions
  66. }
  67. func (s *StoreEntry) AdmissionStatusEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  68. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  69. if isAll == model.IsAllYes {
  70. configOptions = append(configOptions,
  71. &pasturePb.ConfigOptionsList{
  72. Value: int32(pasturePb.AuditStatus_Invalid),
  73. Label: "全部",
  74. Disabled: true,
  75. })
  76. }
  77. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  78. Value: int32(pasturePb.AdmissionStatus_Admission),
  79. Label: "在群",
  80. Disabled: true,
  81. }, &pasturePb.ConfigOptionsList{
  82. Value: int32(pasturePb.AdmissionStatus_Die),
  83. Label: "死亡",
  84. Disabled: true,
  85. }, &pasturePb.ConfigOptionsList{
  86. Value: int32(pasturePb.AdmissionStatus_Out),
  87. Label: "淘汰",
  88. Disabled: true,
  89. }, &pasturePb.ConfigOptionsList{
  90. Value: int32(pasturePb.AdmissionStatus_Sale),
  91. Label: "售卖",
  92. Disabled: true,
  93. }, &pasturePb.ConfigOptionsList{
  94. Value: int32(pasturePb.AdmissionStatus_Transfer),
  95. Label: "转出",
  96. Disabled: true,
  97. })
  98. return configOptions
  99. }
  100. func (s *StoreEntry) ForbiddenMatingReasonsEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  101. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  102. if isAll == model.IsAllYes {
  103. configOptions = append(configOptions,
  104. &pasturePb.ConfigOptionsList{
  105. Value: int32(pasturePb.AuditStatus_Invalid),
  106. Label: "全部",
  107. Disabled: true,
  108. })
  109. }
  110. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  111. Value: int32(pasturePb.ForbiddenMatingReasons_Metritis),
  112. Label: "子宫炎",
  113. Disabled: true,
  114. }, &pasturePb.ConfigOptionsList{
  115. Value: int32(pasturePb.ForbiddenMatingReasons_Reproductive_Diseases),
  116. Label: "繁殖疾病",
  117. Disabled: true,
  118. }, &pasturePb.ConfigOptionsList{
  119. Value: int32(pasturePb.ForbiddenMatingReasons_Reproductive_Failure),
  120. Label: "繁殖障碍",
  121. Disabled: true,
  122. }, &pasturePb.ConfigOptionsList{
  123. Value: int32(pasturePb.ForbiddenMatingReasons_Breast_Abnormalities),
  124. Label: "乳腺异常",
  125. Disabled: true,
  126. }, &pasturePb.ConfigOptionsList{
  127. Value: int32(pasturePb.ForbiddenMatingReasons_Low_Yield),
  128. Label: "低产",
  129. Disabled: true,
  130. }, &pasturePb.ConfigOptionsList{
  131. Value: int32(pasturePb.ForbiddenMatingReasons_Hoof_Disease),
  132. Label: "蹄病",
  133. Disabled: true,
  134. }, &pasturePb.ConfigOptionsList{
  135. Value: int32(pasturePb.ForbiddenMatingReasons_Other),
  136. Label: "其他",
  137. Disabled: true,
  138. })
  139. return configOptions
  140. }
  141. func (s *StoreEntry) WarningHealthLevel(isAll string) []*pasturePb.ConfigOptionsList {
  142. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  143. if isAll == model.IsAllYes {
  144. configOptions = append(configOptions,
  145. &pasturePb.ConfigOptionsList{
  146. Value: int32(0),
  147. Label: "全部",
  148. Disabled: true,
  149. })
  150. }
  151. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  152. Value: int32(pasturePb.WarningHealthLevel_Preliminary),
  153. Label: "初级疑似",
  154. Disabled: true,
  155. }, &pasturePb.ConfigOptionsList{
  156. Value: int32(pasturePb.WarningHealthLevel_Moderate),
  157. Label: "中级疑似",
  158. Disabled: true,
  159. }, &pasturePb.ConfigOptionsList{
  160. Value: int32(pasturePb.WarningHealthLevel_Height),
  161. Label: "高度疑似",
  162. Disabled: true,
  163. })
  164. return configOptions
  165. }
  166. func (s *StoreEntry) Behavior(isAll string) []*pasturePb.ConfigOptionsList {
  167. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  168. if isAll == model.IsAllYes {
  169. configOptions = append(configOptions,
  170. &pasturePb.ConfigOptionsList{
  171. Value: int32(0),
  172. Label: "全部",
  173. Disabled: true,
  174. })
  175. }
  176. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  177. Value: int32(pasturePb.Behavior_Rumina),
  178. Label: "反刍",
  179. Disabled: true,
  180. }, &pasturePb.ConfigOptionsList{
  181. Value: int32(pasturePb.Behavior_Intake),
  182. Label: "采食",
  183. Disabled: true,
  184. }, &pasturePb.ConfigOptionsList{
  185. Value: int32(pasturePb.Behavior_Reset),
  186. Label: "休息",
  187. Disabled: true,
  188. }, &pasturePb.ConfigOptionsList{
  189. Value: int32(pasturePb.Behavior_Immobility),
  190. Label: "静止",
  191. Disabled: true,
  192. }, &pasturePb.ConfigOptionsList{
  193. Value: int32(pasturePb.Behavior_Chew),
  194. Label: "咀嚼",
  195. Disabled: true,
  196. })
  197. return configOptions
  198. }
  199. func (s *StoreEntry) HealthStatusEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  200. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  201. if isAll == model.IsAllYes {
  202. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  203. Value: int32(pasturePb.HealthStatus_Invalid),
  204. Label: "全部",
  205. Disabled: true,
  206. })
  207. }
  208. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  209. Value: int32(pasturePb.HealthStatus_Health),
  210. Label: "健康",
  211. Disabled: true,
  212. }, &pasturePb.ConfigOptionsList{
  213. Value: int32(pasturePb.HealthStatus_Disease),
  214. Label: "发病",
  215. Disabled: true,
  216. }, &pasturePb.ConfigOptionsList{
  217. Value: int32(pasturePb.HealthStatus_Treatment),
  218. Label: "治疗中",
  219. Disabled: true,
  220. }, &pasturePb.ConfigOptionsList{
  221. Value: int32(pasturePb.HealthStatus_Curable),
  222. Label: "治愈",
  223. Disabled: true,
  224. }, &pasturePb.ConfigOptionsList{
  225. Value: int32(pasturePb.HealthStatus_Out),
  226. Label: "淘汰",
  227. Disabled: true,
  228. }, &pasturePb.ConfigOptionsList{
  229. Value: int32(pasturePb.HealthStatus_Dead),
  230. Label: "死亡",
  231. Disabled: true,
  232. })
  233. return configOptions
  234. }
  235. func (s *StoreEntry) MatingWindowPeriodEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  236. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  237. if isAll == model.IsAllYes {
  238. configOptions = append(configOptions,
  239. &pasturePb.ConfigOptionsList{
  240. Value: int32(0),
  241. Label: "全部",
  242. Disabled: true,
  243. })
  244. }
  245. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  246. Value: int32(pasturePb.MatingWindowPeriod_Front),
  247. Label: "早期",
  248. Disabled: true,
  249. }, &pasturePb.ConfigOptionsList{
  250. Value: int32(pasturePb.MatingWindowPeriod_Middle),
  251. Label: "最优",
  252. Disabled: true,
  253. }, &pasturePb.ConfigOptionsList{
  254. Value: int32(pasturePb.MatingWindowPeriod_Behind),
  255. Label: "晚期",
  256. Disabled: true,
  257. })
  258. return configOptions
  259. }
  260. func (s *StoreEntry) DataWaringTypeEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  261. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  262. if isAll == model.IsAllYes {
  263. configOptions = append(configOptions,
  264. &pasturePb.ConfigOptionsList{
  265. Value: int32(0),
  266. Label: "全部",
  267. Disabled: true,
  268. })
  269. }
  270. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  271. Value: int32(pasturePb.DataWarningType_Sale_Standard),
  272. Label: "出栏标准",
  273. Disabled: true,
  274. Props: "达到出栏重量的牛只",
  275. }, &pasturePb.ConfigOptionsList{
  276. Value: int32(pasturePb.DataWarningType_UnPregnant_Mating_Time),
  277. Label: ">6次未孕牛只",
  278. Disabled: true,
  279. Props: "配次高于6次未孕牛只",
  280. }, &pasturePb.ConfigOptionsList{
  281. Value: int32(pasturePb.DataWarningType_Abortion_Time),
  282. Label: ">2次流产牛只",
  283. Disabled: true,
  284. Props: "本胎次内流产大于2次的牛只",
  285. }, &pasturePb.ConfigOptionsList{
  286. Value: int32(pasturePb.DataWarningType_Over_Age_UnPaired_Young),
  287. Label: "超龄未配(青年牛)",
  288. Disabled: true,
  289. Props: "超15个月未配青年牛",
  290. }, &pasturePb.ConfigOptionsList{
  291. Value: int32(pasturePb.DataWarningType_Over_Age_UnPregnant_Young),
  292. Label: "超龄未孕(青年牛)",
  293. Disabled: true,
  294. Props: "超22月未孕青年牛",
  295. }, &pasturePb.ConfigOptionsList{
  296. Value: int32(pasturePb.DataWarningType_Over_Age_UnPregnant_Young),
  297. Label: "超18月未卖",
  298. Disabled: true,
  299. Props: "饲养超过18个月未卖出牛只",
  300. })
  301. return configOptions
  302. }
  303. func (s *StoreEntry) NeckRingErrorEnumList(isAll string) []*pasturePb.ConfigOptionsList {
  304. configOptions := make([]*pasturePb.ConfigOptionsList, 0)
  305. if isAll == model.IsAllYes {
  306. configOptions = append(configOptions,
  307. &pasturePb.ConfigOptionsList{
  308. Value: int32(0),
  309. Label: "全部",
  310. Disabled: true,
  311. })
  312. }
  313. configOptions = append(configOptions, &pasturePb.ConfigOptionsList{
  314. Value: int32(pasturePb.NeckRingNumberError_Suspected_Fall_Off),
  315. Label: "疑似脱落",
  316. Disabled: true,
  317. }, &pasturePb.ConfigOptionsList{
  318. Value: int32(pasturePb.NeckRingNumberError_No_Signal),
  319. Label: "无信号",
  320. Disabled: true,
  321. }, &pasturePb.ConfigOptionsList{
  322. Value: int32(pasturePb.NeckRingNumberError_Receiving_Less),
  323. Label: "接受数据过少",
  324. Disabled: true,
  325. }, &pasturePb.ConfigOptionsList{
  326. Value: int32(pasturePb.NeckRingNumberError_Low_Battery),
  327. Label: "低电量",
  328. Disabled: true,
  329. }, &pasturePb.ConfigOptionsList{
  330. Value: int32(pasturePb.NeckRingNumberError_Data_Latency),
  331. Label: "数据有延迟",
  332. Disabled: true,
  333. }, &pasturePb.ConfigOptionsList{
  334. Value: int32(pasturePb.NeckRingNumberError_Low_Activity_Level),
  335. Label: "活动量过低",
  336. Disabled: true,
  337. }, &pasturePb.ConfigOptionsList{
  338. Value: int32(pasturePb.NeckRingNumberError_Abnormal_Wearing),
  339. Label: "佩戴异常",
  340. Disabled: true,
  341. }, &pasturePb.ConfigOptionsList{
  342. Value: int32(pasturePb.NeckRingNumberError_Should_Associated),
  343. Label: "脖环号未绑定牛号",
  344. Disabled: true,
  345. })
  346. return configOptions
  347. }
  348. // FindCowHistoryBatchNumber 获取历史批次号
  349. func (s *StoreEntry) FindCowHistoryBatchNumber(ctx context.Context) (*model.HistoryBatchNumberResponse, error) {
  350. userModel, err := s.GetUserModel(ctx)
  351. if err != nil {
  352. return nil, xerr.WithStack(err)
  353. }
  354. res := make([]string, 0)
  355. if err = s.DB.Model(new(model.EventEnter)).
  356. Select("batch_number").
  357. Where("pasture_id = ?", userModel.AppPasture.Id).
  358. Where("batch_number != ''").
  359. Group("batch_number").
  360. Find(&res).Error; err != nil {
  361. return nil, xerr.WithStack(err)
  362. }
  363. return &model.HistoryBatchNumberResponse{
  364. Code: http.StatusOK,
  365. Msg: "ok",
  366. Data: res,
  367. }, nil
  368. }
  369. func (s *StoreEntry) GenerateBatchNumber(ctx context.Context) (*model.GenerateBatchNumberResponse, error) {
  370. userModel, err := s.GetUserModel(ctx)
  371. if err != nil {
  372. return nil, xerr.WithStack(err)
  373. }
  374. data := fmt.Sprintf("%s%d%s", time.Now().Local().Format(model.LayoutDate), userModel.AppPasture.Id, util.GenerateRandomNumber(10))
  375. return &model.GenerateBatchNumberResponse{
  376. Code: http.StatusOK,
  377. Msg: "ok",
  378. Data: data,
  379. }, nil
  380. }