medicine.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package services
  2. import (
  3. "Medical_ERP/common/global"
  4. db "Medical_ERP/common/initialize"
  5. "Medical_ERP/dto"
  6. "Medical_ERP/models"
  7. "github.com/beego/beego/v2/core/logs"
  8. "strconv"
  9. )
  10. type Medicine struct {
  11. }
  12. func (e *Medicine) GetBatchNumber(c *dto.MedicineBatchNumberReq, list *[]string, deptId int) error {
  13. var err error
  14. whereSql := "1=1"
  15. if c.ProductID > 0 {
  16. whereSql += " AND product_id = " + strconv.Itoa(c.ProductID)
  17. }
  18. if c.EnterpriseID > 0 {
  19. whereSql += " AND enterprise_id = " + strconv.Itoa(c.EnterpriseID)
  20. }
  21. if c.SpecID > 0 {
  22. whereSql += " AND spec_id = " + strconv.Itoa(c.SpecID)
  23. }
  24. if len(c.BatchNumber) > 0 {
  25. whereSql += " AND batch_number like '%" + c.BatchNumber + "%'"
  26. }
  27. err = db.DB.Table(models.GetMedicineInfoTableName(deptId)).Distinct("batch_number").Where(whereSql).Find(list).Error
  28. if err != nil {
  29. logs.Error("db error: %s ", err)
  30. return global.GetFailedErr
  31. }
  32. return nil
  33. }
  34. func (e *Medicine) BasicDataStat(deptId int) (list map[string]int64, err error) {
  35. var unitCount int64
  36. var specCount int64
  37. var enterpriseCount int64
  38. var dosageFormCount int64
  39. var productCount int64
  40. var medicineTemplateCount int64
  41. list = make(map[string]int64)
  42. err = db.DB.Model(&models.Unit{}).Where("dept_id = ?", deptId).Count(&unitCount).Error
  43. if err != nil {
  44. logs.Error("get unitCount error: %s ", err)
  45. return list, global.GetFailedErr
  46. }
  47. err = db.DB.Model(&models.Spec{}).Where("dept_id = ?", deptId).Count(&specCount).Error
  48. if err != nil {
  49. logs.Error("get specCount error: %s ", err)
  50. return list, global.GetFailedErr
  51. }
  52. err = db.DB.Model(&models.Enterprise{}).Where("dept_id = ?", deptId).Count(&enterpriseCount).Error
  53. if err != nil {
  54. logs.Error("get enterpriseCount error: %s ", err)
  55. return list, global.GetFailedErr
  56. }
  57. err = db.DB.Model(&models.Product{}).Where("dept_id = ?", deptId).Count(&productCount).Error
  58. if err != nil {
  59. logs.Error("get productCount error: %s ", err)
  60. return list, global.GetFailedErr
  61. }
  62. err = db.DB.Model(&models.DosageForm{}).Where("dept_id = ?", deptId).Count(&dosageFormCount).Error
  63. if err != nil {
  64. logs.Error("get dosageFormCount error: %s ", err)
  65. return list, global.GetFailedErr
  66. }
  67. err = db.DB.Model(&models.MedicineTemplate{}).Where("dept_id = ?", deptId).Count(&medicineTemplateCount).Error
  68. if err != nil {
  69. logs.Error("get dosageFormCount error: %s ", err)
  70. return list, global.GetFailedErr
  71. }
  72. list["unitCount"] = unitCount
  73. list["specCount"] = specCount
  74. list["enterpriseCount"] = enterpriseCount
  75. list["productCount"] = productCount
  76. list["dosageFormCount"] = dosageFormCount
  77. list["medicineTemplateCount"] = medicineTemplateCount
  78. return list, nil
  79. }