medicine.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 len(c.BatchNumber) > 0 {
  22. whereSql += " AND batch_number like '%" + c.BatchNumber + "%'"
  23. }
  24. err = db.DB.Table(models.GetMedicineInfoTableName(deptId)).Distinct("batch_number").Where(whereSql).Find(list).Error
  25. if err != nil {
  26. logs.Error("db error: %s ", err)
  27. return global.GetFailedErr
  28. }
  29. return nil
  30. }
  31. func (e *Medicine) BasicDataStat(deptId int) (list map[string]int64, err error) {
  32. var unitCount int64
  33. var specCount int64
  34. var enterpriseCount int64
  35. var dosageFormCount int64
  36. var productCount int64
  37. var medicineTemplateCount int64
  38. list = make(map[string]int64)
  39. err = db.DB.Model(&models.Unit{}).Where("dept_id = ?", deptId).Count(&unitCount).Error
  40. if err != nil {
  41. logs.Error("get unitCount error: %s ", err)
  42. return list, global.GetFailedErr
  43. }
  44. err = db.DB.Model(&models.Spec{}).Where("dept_id = ?", deptId).Count(&specCount).Error
  45. if err != nil {
  46. logs.Error("get specCount error: %s ", err)
  47. return list, global.GetFailedErr
  48. }
  49. err = db.DB.Model(&models.Enterprise{}).Where("dept_id = ?", deptId).Count(&enterpriseCount).Error
  50. if err != nil {
  51. logs.Error("get enterpriseCount error: %s ", err)
  52. return list, global.GetFailedErr
  53. }
  54. err = db.DB.Model(&models.Product{}).Where("dept_id = ?", deptId).Count(&productCount).Error
  55. if err != nil {
  56. logs.Error("get productCount error: %s ", err)
  57. return list, global.GetFailedErr
  58. }
  59. err = db.DB.Model(&models.DosageForm{}).Where("dept_id = ?", deptId).Count(&dosageFormCount).Error
  60. if err != nil {
  61. logs.Error("get dosageFormCount error: %s ", err)
  62. return list, global.GetFailedErr
  63. }
  64. err = db.DB.Model(&models.MedicineTemplate{}).Where("dept_id = ?", deptId).Count(&medicineTemplateCount).Error
  65. if err != nil {
  66. logs.Error("get dosageFormCount error: %s ", err)
  67. return list, global.GetFailedErr
  68. }
  69. list["unitCount"] = unitCount
  70. list["specCount"] = specCount
  71. list["enterpriseCount"] = enterpriseCount
  72. list["productCount"] = productCount
  73. list["dosageFormCount"] = dosageFormCount
  74. list["medicineTemplateCount"] = medicineTemplateCount
  75. return list, nil
  76. }