analysis_other.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. package backend
  2. import (
  3. "context"
  4. "fmt"
  5. "kpt-pasture/model"
  6. "kpt-pasture/util"
  7. "net/http"
  8. "gorm.io/gorm"
  9. pasturePb "gitee.com/xuyiping_admin/go_proto/proto/go/backend/cow"
  10. "gitee.com/xuyiping_admin/pkg/xerr"
  11. )
  12. // PregnancyReport 孕检报告
  13. func (s *StoreEntry) PregnancyReport(ctx context.Context, req *pasturePb.PregnancyReportRequest, pagination *pasturePb.PaginationModel) (*pasturePb.PregnancyReportResponse, error) {
  14. userModel, err := s.GetUserModel(ctx)
  15. if err != nil {
  16. return nil, xerr.WithStack(err)
  17. }
  18. startDayUnix := util.TimeParseLocalUnix(req.StartDayTime)
  19. endDayUnix := util.TimeParseLocalEndUnix(req.EndDayTime)
  20. if startDayUnix > endDayUnix || startDayUnix == 0 || endDayUnix == 0 {
  21. return nil, xerr.Custom("开始时间不能大于结束时间")
  22. }
  23. eventPregnantCheckList := make([]*model.EventPregnantCheck, 0)
  24. pref := s.DB.Model(new(model.EventPregnantCheck)).
  25. Where("status = ?", pasturePb.IsShow_Ok).
  26. Where("cow_type = ?", req.CowType).
  27. Where("pasture_id = ?", userModel.AppPasture.Id)
  28. if startDayUnix > 0 && endDayUnix > 0 && endDayUnix >= startDayUnix {
  29. pref = pref.Where("create_time BETWEEN ? AND ?", startDayUnix, endDayUnix)
  30. }
  31. if req.PregnantCheckResult > 0 {
  32. pref = pref.Where("pregnant_check_result = ?", req.PregnantCheckResult)
  33. }
  34. var count int64 = 0
  35. if err = pref.Count(&count).
  36. Limit(int(pagination.PageSize)).
  37. Offset(int(pagination.PageOffset)).
  38. Order("id desc").
  39. Find(&eventPregnantCheckList).Error; err != nil {
  40. return nil, xerr.WithStack(err)
  41. }
  42. pregnantCheckResultMap := s.PregnantCheckResultMap()
  43. pregnantCheckMethodMap := s.PregnantCheckMethodMap()
  44. return &pasturePb.PregnancyReportResponse{
  45. Code: http.StatusOK,
  46. Msg: "ok",
  47. Data: &pasturePb.PregnancyReportData{
  48. List: model.EventPregnantCheckSlice(eventPregnantCheckList).ToPB3(pregnantCheckResultMap, pregnantCheckMethodMap),
  49. Total: int32(count),
  50. PageSize: pagination.PageSize,
  51. Page: pagination.Page,
  52. },
  53. }, nil
  54. }
  55. // CalvingReport 产犊报告
  56. func (s *StoreEntry) CalvingReport(ctx context.Context, req *pasturePb.CalvingReportRequest) (*pasturePb.CalvingReportResponse, error) {
  57. userModel, err := s.GetUserModel(ctx)
  58. if err != nil {
  59. return nil, xerr.WithStack(err)
  60. }
  61. lastDayOfMonth, err := util.GetLastDayOfMonth(req.EndDayTime)
  62. if err != nil {
  63. return nil, xerr.WithStack(err)
  64. }
  65. endDayTimeUnix := util.TimeParseLocalEndUnix(lastDayOfMonth)
  66. startDayTimeUnix := util.TimeParseLocalUnix(fmt.Sprintf("%s-01", req.StartDayTime))
  67. if startDayTimeUnix == 0 || endDayTimeUnix == 0 || endDayTimeUnix <= startDayTimeUnix {
  68. return nil, xerr.Custom("开始时间不能大于结束时间")
  69. }
  70. eventCalving1 := make([]*pasturePb.CalvingReportTable, 0)
  71. pref1 := s.DB.Model(new(model.EventCalving)).
  72. Select(fmt.Sprint(`DATE_FORMAT(FROM_UNIXTIME(reality_day), '%Y-%m') AS statistic_method,cow_kind,`)+fmt.Sprintf(
  73. `SUM(child_number) AS totalCount,
  74. SUM(CASE WHEN child_number > 1 THEN child_number ELSE 0 END) AS twins,
  75. SUM(CASE WHEN pregnancy_age <= %d THEN 1 ELSE 0 END) AS premature_labor_count,
  76. SUM(CASE WHEN pregnancy_age >= %d THEN 1 ELSE 0 END) AS late_labor_count,
  77. count(*) as total_count`, req.PrematureLabor, req.LateLabor),
  78. ).Where("status = ?", pasturePb.IsShow_Ok).Where("pasture_id = ?", userModel.AppPasture.Id).
  79. Where("reality_day BETWEEN ? AND ? ", startDayTimeUnix, endDayTimeUnix)
  80. if req.AnalysisMethod > 0 {
  81. switch req.AnalysisMethod {
  82. case pasturePb.CalvingAnalysisMethod_Months:
  83. pref1.Group("statistic_method").Order("statistic_method")
  84. case pasturePb.CalvingAnalysisMethod_CowKind:
  85. pref1.Group("cow_kind").Order("cow_kind")
  86. }
  87. }
  88. if err = pref1.Find(&eventCalving1).Error; err != nil {
  89. return nil, xerr.WithStack(err)
  90. }
  91. eventCalving2 := make([]*pasturePb.CalvingReportTable, 0)
  92. pref2 := s.DB.Model(new(model.CalvingCalf)).
  93. Select(fmt.Sprint(`DATE_FORMAT(FROM_UNIXTIME(birth_at), '%Y-%m') AS statistic_method, cow_kind,
  94. SUM(CASE WHEN sex = 1 THEN 1 ELSE 0 END) AS bulls,
  95. SUM(CASE WHEN sex = 2 THEN 1 ELSE 0 END) AS cows,
  96. SUM(CASE WHEN is_live = 1 THEN 1 ELSE 0 END) AS survive_count,
  97. SUM(CASE WHEN is_live = 2 THEN 1 ELSE 0 END) AS die_count,
  98. SUM(CASE WHEN is_live = 2 AND sex = 1 THEN 1 ELSE 0 END) AS bulls_die_count,
  99. SUM(CASE WHEN is_live = 2 AND sex = 2 THEN 1 ELSE 0 END) AS cows_die_count,
  100. SUM(CASE WHEN is_adoption = 1 THEN 1 ELSE 0 END) AS adopt_count`)).
  101. Where("birth_at BETWEEN ? AND ?", startDayTimeUnix, endDayTimeUnix).
  102. Where("pasture_id = ?", userModel.AppPasture.Id)
  103. if req.AnalysisMethod > 0 {
  104. switch req.AnalysisMethod {
  105. case pasturePb.CalvingAnalysisMethod_Months:
  106. pref2.Group("statistic_method").Order("statistic_method")
  107. case pasturePb.CalvingAnalysisMethod_CowKind:
  108. pref2.Group("cow_kind").Order("cow_kind")
  109. }
  110. }
  111. if err = pref2.Find(&eventCalving2).Error; err != nil {
  112. return nil, xerr.WithStack(err)
  113. }
  114. // 合并数据集
  115. for _, v1 := range eventCalving1 {
  116. for _, v2 := range eventCalving2 {
  117. if v1.StatisticMethod != v2.StatisticMethod && v1.CowKind != v2.CowKind {
  118. continue
  119. }
  120. v1.Bulls = v2.Bulls
  121. v1.Cows = v2.Cows
  122. v1.SurviveCount = v2.SurviveCount
  123. v1.DieCount = v2.DieCount
  124. v1.BullsDieCount = v2.BullsDieCount
  125. v1.CowsDieCount = v2.CowsDieCount
  126. v1.AdoptCount = v2.AdoptCount
  127. }
  128. }
  129. cowKindMap := s.CowKindMap()
  130. for _, v := range eventCalving1 {
  131. if req.AnalysisMethod == pasturePb.CalvingAnalysisMethod_CowKind {
  132. v.StatisticMethod = cowKindMap[v.CowKind]
  133. }
  134. if v.TotalCount > 0 {
  135. v.TwinsRate = float32(util.RoundToTwoDecimals(float64(v.Twins) / float64(v.TotalCount) * 100))
  136. v.CowsRate = float32(util.RoundToTwoDecimals(float64(v.Cows) / float64(v.TotalCount) * 100))
  137. v.DieRate = float32(util.RoundToTwoDecimals(float64(v.DieCount) / float64(v.TotalCount) * 100))
  138. v.BullsRate = float32(util.RoundToTwoDecimals(float64(v.Bulls) / float64(v.TotalCount) * 100))
  139. v.SurviveRate = float32(util.RoundToTwoDecimals(float64(v.SurviveCount) / float64(v.TotalCount) * 100))
  140. }
  141. if v.Bulls > 0 {
  142. v.BullsDieRate = float32(util.RoundToTwoDecimals(float64(v.BullsDieCount) / float64(v.Bulls) * 100))
  143. }
  144. if v.Cows > 0 {
  145. v.CowsDieRate = float32(util.RoundToTwoDecimals(float64(v.CowsDieCount) / float64(v.Cows) * 100))
  146. }
  147. v.NormalLaborCount = v.TotalCount - (v.PrematureLaborCount + v.LateLaborCount)
  148. if v.NormalLaborCount <= 0 {
  149. v.NormalLaborCount = 0
  150. }
  151. }
  152. return &pasturePb.CalvingReportResponse{
  153. Code: http.StatusOK,
  154. Msg: "ok",
  155. Data: &pasturePb.CalvingReportData{
  156. List: eventCalving1,
  157. Total: int32(len(eventCalving1)),
  158. },
  159. }, nil
  160. }
  161. // DiseaseCureReport 疾病治愈率报告
  162. func (s *StoreEntry) DiseaseCureReport(ctx context.Context, req *pasturePb.DiseaseCureRateRequest) (*pasturePb.DiseaseCureRateResponse, error) {
  163. userModel, err := s.GetUserModel(ctx)
  164. if err != nil {
  165. return nil, xerr.WithStack(err)
  166. }
  167. lastDayOfMonth, err := util.GetLastDayOfMonth(req.EndDayTime)
  168. if err != nil {
  169. return nil, xerr.WithStack(err)
  170. }
  171. endDayTimeUnix := util.TimeParseLocalEndUnix(lastDayOfMonth)
  172. startDayTimeUnix := util.TimeParseLocalUnix(fmt.Sprintf("%s-01", req.StartDayTime))
  173. if startDayTimeUnix == 0 || endDayTimeUnix == 0 || endDayTimeUnix <= startDayTimeUnix {
  174. return nil, xerr.Custom("开始时间不能大于结束时间")
  175. }
  176. diseaseCureRateList1 := make([]*pasturePb.DiseaseCureRateList, 0)
  177. diseaseCureRateList2 := make([]*pasturePb.DiseaseCureRateList, 0)
  178. pref1, err := s.query1(userModel.AppPasture.Id, req.CowType, startDayTimeUnix, endDayTimeUnix)
  179. if err != nil {
  180. return nil, xerr.WithStack(err)
  181. }
  182. pref2, err := s.query2(userModel.AppPasture.Id, startDayTimeUnix, endDayTimeUnix)
  183. if err != nil {
  184. return nil, xerr.WithStack(err)
  185. }
  186. switch req.AnalysisMethod {
  187. case pasturePb.DiseaseAnalysisMethod_Months:
  188. pref1.Where("diagnosed_at > 0").Group("months").Order("months")
  189. pref2.Where("treatment_at > 0").Group("months").Order("months")
  190. case pasturePb.DiseaseAnalysisMethod_Disease_Category:
  191. pref1.Where("disease_type > 0").Group("disease_type").Order("disease_type")
  192. pref2.Where("disease_type > 0").Group("disease_type").Order("disease_type")
  193. case pasturePb.DiseaseAnalysisMethod_Disease:
  194. pref1.Where("diagnose_id > 0").Group("diagnose_id").Order("diagnose_id")
  195. pref2.Where("disease_id > 0").Group("disease_id").Order("disease_id")
  196. case pasturePb.DiseaseAnalysisMethod_Operator:
  197. pref1.Where("diagnose_operation_id > 0").Group("diagnose_operation_id").Order("diagnose_operation_id")
  198. pref2.Where("operation_id > 0").Group("operation_id").Order("operation_id")
  199. default:
  200. return nil, xerr.Custom("错误的统计方式")
  201. }
  202. if err = pref1.Find(&diseaseCureRateList1).Error; err != nil {
  203. return nil, xerr.WithStack(err)
  204. }
  205. if err = pref2.Find(&diseaseCureRateList2).Error; err != nil {
  206. return nil, xerr.WithStack(err)
  207. }
  208. // 处理数据
  209. processDiseaseCureRateList(diseaseCureRateList1, diseaseCureRateList2, req.AnalysisMethod)
  210. chart := &pasturePb.DiseaseCureRateChart{
  211. Headers: make([]string, 0),
  212. DiseaseCureCount: make([]int32, 0),
  213. DiseaseCureRate: make([]float32, 0),
  214. DiseaseCount: make([]int32, 0),
  215. }
  216. for _, v := range diseaseCureRateList1 {
  217. switch req.AnalysisMethod {
  218. case pasturePb.DiseaseAnalysisMethod_Months:
  219. v.StatisticMethod = v.Months
  220. case pasturePb.DiseaseAnalysisMethod_Disease_Category:
  221. diseaseTypeMap := s.DiseaseTypeMap()
  222. v.StatisticMethod = diseaseTypeMap[v.DiseaseType]
  223. case pasturePb.DiseaseAnalysisMethod_Disease:
  224. v.StatisticMethod = v.DiseaseName
  225. case pasturePb.DiseaseAnalysisMethod_Operator:
  226. v.StatisticMethod = v.OperationName
  227. case pasturePb.DiseaseAnalysisMethod_Prescription:
  228. v.StatisticMethod = v.PrescriptionName
  229. }
  230. chart.Headers = append(chart.Headers, v.StatisticMethod)
  231. chart.DiseaseCureCount = append(chart.DiseaseCureCount, v.DiseaseTreatmentCount)
  232. diseaseCureRate := float32(0)
  233. if v.DiseaseTreatmentCount > 0 {
  234. diseaseCureRate = float32(util.RoundToTwoDecimals(float64(v.DiseaseCureCount) / float64(v.DiseaseCount) * 100))
  235. }
  236. chart.DiseaseCureRate = append(chart.DiseaseCureRate, diseaseCureRate)
  237. chart.DiseaseCount = append(chart.DiseaseCount, v.DiseaseCount)
  238. }
  239. return &pasturePb.DiseaseCureRateResponse{
  240. Code: http.StatusOK,
  241. Msg: "ok",
  242. Data: &pasturePb.DiseaseCureRateData{
  243. List: diseaseCureRateList1,
  244. Chart: chart,
  245. },
  246. }, nil
  247. }
  248. func (s *StoreEntry) SaleCowReport(ctx context.Context, req *pasturePb.SaleCowReportRequest) (*pasturePb.SaleCowReportResponse, error) {
  249. userModel, err := s.GetUserModel(ctx)
  250. if err != nil {
  251. return nil, xerr.WithStack(err)
  252. }
  253. lastDayOfMonth, err := util.GetLastDayOfMonth(req.EndDay)
  254. if err != nil {
  255. return nil, xerr.WithStack(err)
  256. }
  257. endDayTimeUnix := util.TimeParseLocalEndUnix(lastDayOfMonth)
  258. startDayTimeUnix := util.TimeParseLocalUnix(fmt.Sprintf("%s-01", req.StartDay))
  259. if startDayTimeUnix == 0 || endDayTimeUnix == 0 || endDayTimeUnix <= startDayTimeUnix {
  260. return nil, xerr.Custom("开始时间不能大于结束时间")
  261. }
  262. list := make([]*pasturePb.SaleCowReportList, 0)
  263. pref := s.DB.Model(new(model.EventSale)).
  264. Select(
  265. `SUM(sale_cow_count) AS sale_all_count,
  266. SUM(sale_all_amount) AS sale_all_amount,
  267. SUM(sale_cow_count) AS sale_all_count,
  268. SUM(sale_all_weight) AS sale_all_weight`,
  269. ).Where("sale_at BETWEEN ? AND ?", startDayTimeUnix, endDayTimeUnix).
  270. Where("pasture_id = ?", userModel.AppPasture.Id)
  271. if req.AnalysisMethod == pasturePb.SaleCowAnalysisMethod_Months {
  272. pref.Select(`DATE_FORMAT(FROM_UNIXTIME(sale_at), '%Y-%m') AS statisticMethod`)
  273. }
  274. if req.AnalysisMethod == pasturePb.SaleCowAnalysisMethod_Dealer {
  275. pref.Select(`dealer_name as statisticMethod`)
  276. }
  277. if err = pref.Group("statisticMethod").Order("statisticMethod ASC").Find(&list).Error; err != nil {
  278. return nil, xerr.WithStack(err)
  279. }
  280. chart := &pasturePb.SaleCowReportChart{
  281. Headers: make([]string, 0),
  282. SaleMount: make([]float32, 0),
  283. SaleWeight: make([]float32, 0),
  284. SaleCount: make([]int32, 0),
  285. AverageSaleWeight: make([]float32, 0),
  286. }
  287. for i, v := range list {
  288. if v.SaleAllCount > 0 && v.SaleAllWeight > 0 {
  289. v.SaleAvgWeight = float32(util.RoundToTwoDecimals(float64(v.SaleAllWeight / float32(v.SaleAllCount))))
  290. }
  291. chart.Headers = append(chart.Headers, v.StatisticMethod)
  292. chart.SaleMount = append(chart.SaleMount, v.SaleAllMount)
  293. chart.SaleWeight = append(chart.SaleWeight, v.SaleAllWeight)
  294. chart.SaleCount = append(chart.SaleCount, v.SaleAllCount)
  295. chart.AverageSaleWeight = append(chart.AverageSaleWeight, v.SaleAvgWeight)
  296. v.Id = int32(i)
  297. }
  298. return &pasturePb.SaleCowReportResponse{
  299. Code: http.StatusOK,
  300. Msg: "ok",
  301. Data: &pasturePb.SaleCowReportData{
  302. Chart: chart,
  303. List: list,
  304. Total: int32(len(list)),
  305. },
  306. }, err
  307. }
  308. func (s *StoreEntry) query1(pastureId int64, cowType pasturePb.CowType_Kind, startDayTimeUnix, endDayTimeUnix int64) (*gorm.DB, error) {
  309. pref := s.DB.Model(new(model.EventCowDisease)).
  310. Select(
  311. `DATE_FORMAT(FROM_UNIXTIME(diagnosed_at), '%Y-%m') AS months,
  312. diagnose_id as disease_id,
  313. diagnose_name as disease_name,
  314. diagnose_operation_id as operation_id,
  315. diagnose_operation_name as operation_name,
  316. disease_type,
  317. COUNT(DISTINCT CASE WHEN health_status = ? THEN cow_id END) AS disease_treatment_count, -- 治疗头数
  318. COUNT(DISTINCT CASE WHEN health_status = ? AND curable_at > 0 THEN cow_id END) AS disease_cure_count, -- 治愈头数
  319. COUNT(DISTINCT CASE WHEN diagnosed_result = ? THEN cow_id END) AS disease_count, -- 发病数
  320. COUNT(DISTINCT CASE WHEN health_status IN (?, ?) THEN cow_id END) AS die_out_count, -- 死淘数
  321. COUNT(DISTINCT CASE
  322. WHEN health_status = ?
  323. AND TIMESTAMPDIFF(DAY, FROM_UNIXTIME(disease_at), FROM_UNIXTIME(curable_at)) <= 7
  324. THEN cow_id
  325. END) AS seven_cure_count, -- 7天内治愈头数
  326. COUNT(DISTINCT CASE
  327. WHEN health_status = ?
  328. AND TIMESTAMPDIFF(DAY, FROM_UNIXTIME(disease_at), FROM_UNIXTIME(curable_at)) <= 14
  329. THEN cow_id
  330. END) AS seventeen_cure_count, -- 14天内治愈头数
  331. COUNT(DISTINCT CASE
  332. WHEN health_status = ?
  333. AND TIMESTAMPDIFF(DAY, FROM_UNIXTIME(disease_at), FROM_UNIXTIME(curable_at)) <= 30
  334. THEN cow_id
  335. END) AS thirty_cure_count -- 30天内治愈头数
  336. `,
  337. pasturePb.HealthStatus_Treatment, pasturePb.HealthStatus_Curable, pasturePb.IsShow_Ok, pasturePb.HealthStatus_Out,
  338. pasturePb.HealthStatus_Dead, pasturePb.HealthStatus_Curable, pasturePb.HealthStatus_Curable, pasturePb.HealthStatus_Curable,
  339. ).
  340. Where("diagnosed_result = ?", pasturePb.IsShow_Ok).
  341. Where("pastureI_id = ?", pastureId).
  342. Where("diagnosed_at BETWEEN ? AND ?", startDayTimeUnix, endDayTimeUnix)
  343. if cowType > 0 {
  344. pref.Where("cow_type = ?", cowType)
  345. }
  346. return pref, nil
  347. }
  348. func (s *StoreEntry) query2(pastureId int64, startDayTimeUnix, endDayTimeUnix int64) (*gorm.DB, error) {
  349. pref := s.DB.Model(new(model.EventCowTreatment)).
  350. Select(`
  351. DATE_FORMAT(FROM_UNIXTIME(treatment_at), '%Y-%m') AS months,
  352. disease_id,
  353. disease_name,
  354. disease_type,
  355. prescription_id,
  356. prescription_name,
  357. operation_id,
  358. operation_name,
  359. COUNT(DISTINCT cow_id) AS disease_treatment_count`,
  360. ).Where("treatment_at BETWEEN ? AND ?", startDayTimeUnix, endDayTimeUnix).
  361. Where("pasture_id = ?", pastureId)
  362. return pref, nil
  363. }
  364. // 构建哈希表
  365. func buildMap(list []*pasturePb.DiseaseCureRateList, method pasturePb.DiseaseAnalysisMethod_Kind) map[interface{}]*pasturePb.DiseaseCureRateList {
  366. m := make(map[interface{}]*pasturePb.DiseaseCureRateList)
  367. for _, v := range list {
  368. var key interface{}
  369. switch method {
  370. case pasturePb.DiseaseAnalysisMethod_Months:
  371. key = v.Months
  372. case pasturePb.DiseaseAnalysisMethod_Disease_Category:
  373. key = v.DiseaseType
  374. case pasturePb.DiseaseAnalysisMethod_Disease:
  375. key = v.DiseaseId
  376. case pasturePb.DiseaseAnalysisMethod_Operator:
  377. key = v.OperationId
  378. case pasturePb.DiseaseAnalysisMethod_Prescription:
  379. key = v.PrescriptionId
  380. }
  381. m[key] = v
  382. }
  383. return m
  384. }
  385. // 更新 DiseaseTreatmentCount
  386. func updateDiseaseTreatmentCount(v1 *pasturePb.DiseaseCureRateList, v2 *pasturePb.DiseaseCureRateList) {
  387. v1.DiseaseTreatmentCount = v2.DiseaseTreatmentCount
  388. }
  389. // 主逻辑
  390. func processDiseaseCureRateList(diseaseCureRateList1, diseaseCureRateList2 []*pasturePb.DiseaseCureRateList, analysisMethod pasturePb.DiseaseAnalysisMethod_Kind) {
  391. if len(diseaseCureRateList1) == 0 || len(diseaseCureRateList2) == 0 {
  392. return
  393. }
  394. map2 := buildMap(diseaseCureRateList2, analysisMethod)
  395. for i := range diseaseCureRateList1 {
  396. v1 := diseaseCureRateList1[i]
  397. var key interface{}
  398. switch analysisMethod {
  399. case pasturePb.DiseaseAnalysisMethod_Months:
  400. key = v1.Months
  401. case pasturePb.DiseaseAnalysisMethod_Disease_Category:
  402. key = v1.DiseaseType
  403. case pasturePb.DiseaseAnalysisMethod_Disease:
  404. key = v1.DiseaseId
  405. case pasturePb.DiseaseAnalysisMethod_Operator:
  406. key = v1.OperationId
  407. case pasturePb.DiseaseAnalysisMethod_Prescription:
  408. key = v1.PrescriptionId
  409. default:
  410. continue // 处理无效的 AnalysisMethod
  411. }
  412. if v2, ok := map2[key]; ok {
  413. updateDiseaseTreatmentCount(v1, v2)
  414. }
  415. }
  416. }