123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package models
- import (
- db "Medical_ERP/common/initialize"
- "fmt"
- _ "github.com/go-sql-driver/mysql"
- "log"
- "sync"
- )
- func init() {
- AutoMigrateDB()
- }
- func AutoMigrateDB() {
- //自动迁移模式
- err := db.DB.Set("gorm:table_options", "charset=utf8mb4").
- AutoMigrate(
- &OperationLog{},
- &RoleApi{},
- &Product{},
- &Enterprise{},
- &Spec{},
- &DosageForm{},
- &Unit{},
- &MedicineTemplate{},
- &StockIn{},
- &StockOut{},
- &MedicineInventory{},
- &Barcode{},
- &MedicineImg{},
- &ProductCode{},
- )
- if err != nil {
- log.Fatalf("migrate db fail: %v", err)
- }
- }
- var Spec_list *sync.Map
- var DosageForm_list *sync.Map
- var Enterprise_list *sync.Map
- var Product_list *sync.Map
- var Unit_list *sync.Map
- // 初始化基础数据
- func InitBasicData(deptId int) {
- Spec_list = new(sync.Map)
- DosageForm_list = new(sync.Map)
- Enterprise_list = new(sync.Map)
- Product_list = new(sync.Map)
- Unit_list = new(sync.Map)
- Read_Spec_All_Map(deptId)
- Read_Product_All_Map(deptId)
- Read_DosageForm_All_Map(deptId)
- Read_Enterprise_All_Map(deptId)
- Read_Unit_All_Map(deptId)
- }
- // 获取全部规格
- func Read_Spec_All_Map(deptId int) {
- var spec []Spec
- if err := db.DB.Where("dept_id = ?", deptId).Find(&spec).Error; err != nil {
- fmt.Println("Error loading Specs:", err)
- return
- }
- for _, v := range spec {
- Spec_list.Store(v.Id, v.Name)
- }
- }
- func Read_Spec_Get(Id int) string {
- v, ok := Spec_list.Load(Id)
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
- // 获取全部剂型
- func Read_DosageForm_All_Map(deptId int) {
- var dosageForm []DosageForm
- if err := db.DB.Where("dept_id = ?", deptId).Find(&dosageForm).Error; err != nil {
- fmt.Println("Error loading DosageForm:", err)
- return
- }
- for _, v := range dosageForm {
- DosageForm_list.Store(v.Id, v.Name)
- }
- }
- func Read_DosageForm_Get(Id int) string {
- v, ok := DosageForm_list.Load(Id)
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
- // 获取全部生产企业
- func Read_Enterprise_All_Map(deptId int) {
- var enterprise []Enterprise
- if err := db.DB.Where("dept_id = ?", deptId).Find(&enterprise).Error; err != nil {
- fmt.Println("Error loading Enterprise:", err)
- return
- }
- for _, v := range enterprise {
- Enterprise_list.Store(v.Id, v.Name)
- }
- }
- func Read_Enterprise_Get(Id int) string {
- v, ok := Enterprise_list.Load(Id)
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
- // 获取全部品名
- func Read_Product_All_Map(deptId int) {
- var product []Product
- if err := db.DB.Where("dept_id = ?", deptId).Find(&product).Error; err != nil {
- fmt.Println("Error loading Product:", err)
- return
- }
- for _, v := range product {
- Product_list.Store(v.Id, v.Name)
- }
- }
- func Read_Product_Get(Id int) string {
- v, ok := Product_list.Load(Id)
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
- // 获取全部单位
- func Read_Unit_All_Map(deptId int) {
- var unit []Unit
- if err := db.DB.Where("dept_id = ?", deptId).Find(&unit).Error; err != nil {
- fmt.Println("Error loading Unit:", err)
- return
- }
- for _, v := range unit {
- Unit_list.Store(v.Id, v.Name)
- }
- }
- func Read_Unit_Get(Id int) string {
- v, ok := Unit_list.Load(Id)
- if ok {
- return v.(string)
- } else {
- return ""
- }
- }
|