analysis_other.go 17 KB

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