123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- package services
- import (
- "Medical_ERP/common/global"
- db "Medical_ERP/common/initialize"
- "Medical_ERP/dto"
- "Medical_ERP/models"
- "github.com/beego/beego/v2/core/logs"
- "strconv"
- )
- type Medicine struct {
- }
- func (e *Medicine) GetBatchNumber(c *dto.MedicineBatchNumberReq, list *[]string, deptId int) error {
- var err error
- whereSql := "1=1"
- if c.ProductID > 0 {
- whereSql += " AND product_id = " + strconv.Itoa(c.ProductID)
- }
- if c.EnterpriseID > 0 {
- whereSql += " AND enterprise_id = " + strconv.Itoa(c.EnterpriseID)
- }
- if c.SpecID > 0 {
- whereSql += " AND spec_id = " + strconv.Itoa(c.SpecID)
- }
- if len(c.BatchNumber) > 0 {
- whereSql += " AND batch_number like '%" + c.BatchNumber + "%'"
- }
- err = db.DB.Table(models.GetMedicineInfoTableName(deptId)).Distinct("batch_number").Where(whereSql).Find(list).Error
- if err != nil {
- logs.Error("db error: %s ", err)
- return global.GetFailedErr
- }
- return nil
- }
- func (e *Medicine) BasicDataStat(deptId int) (list map[string]int64, err error) {
- var unitCount int64
- var specCount int64
- var enterpriseCount int64
- var dosageFormCount int64
- var productCount int64
- var medicineTemplateCount int64
- list = make(map[string]int64)
- err = db.DB.Model(&models.Unit{}).Where("dept_id = ?", deptId).Count(&unitCount).Error
- if err != nil {
- logs.Error("get unitCount error: %s ", err)
- return list, global.GetFailedErr
- }
- err = db.DB.Model(&models.Spec{}).Where("dept_id = ?", deptId).Count(&specCount).Error
- if err != nil {
- logs.Error("get specCount error: %s ", err)
- return list, global.GetFailedErr
- }
- err = db.DB.Model(&models.Enterprise{}).Where("dept_id = ?", deptId).Count(&enterpriseCount).Error
- if err != nil {
- logs.Error("get enterpriseCount error: %s ", err)
- return list, global.GetFailedErr
- }
- err = db.DB.Model(&models.Product{}).Where("dept_id = ?", deptId).Count(&productCount).Error
- if err != nil {
- logs.Error("get productCount error: %s ", err)
- return list, global.GetFailedErr
- }
- err = db.DB.Model(&models.DosageForm{}).Where("dept_id = ?", deptId).Count(&dosageFormCount).Error
- if err != nil {
- logs.Error("get dosageFormCount error: %s ", err)
- return list, global.GetFailedErr
- }
- err = db.DB.Model(&models.MedicineTemplate{}).Where("dept_id = ?", deptId).Count(&medicineTemplateCount).Error
- if err != nil {
- logs.Error("get dosageFormCount error: %s ", err)
- return list, global.GetFailedErr
- }
- list["unitCount"] = unitCount
- list["specCount"] = specCount
- list["enterpriseCount"] = enterpriseCount
- list["productCount"] = productCount
- list["dosageFormCount"] = dosageFormCount
- list["medicineTemplateCount"] = medicineTemplateCount
- return list, nil
- }
|