1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package models
- import (
- db "Medical_ERP/common/initialize"
- model2 "Medical_ERP/common/model"
- "Medical_ERP/utils"
- "github.com/beego/beego/v2/core/logs"
- "strings"
- )
- type MedicineImg struct {
- model2.Model
- Product string `json:"product" gorm:"size:512;"` // 药品名称
- Enterprise string `json:"enterprise" gorm:"size:512;"` // 生产企业
- Spec string `json:"spec" gorm:"size:512;"` // 规格
- Unit string `json:"unit" gorm:"size:512;"` // 单位 非必填
- DosageForm string `json:"dosageForm" gorm:"size:512;"` // 剂型 非必填
- ApprovalNumber string `json:"approvalNumber" gorm:"size:128;"` // 批准文号
- QualificationNumber string `json:"qualificationNumber" gorm:"size:128;"` // 批签发合格编号
- ProductionDate string `json:"productionDate" gorm:"size:128;"` // 生产日期
- ExpiryDate string `json:"expiryDate" gorm:"size:128;"` // 失效日期
- BatchNumber string `json:"batchNumber" gorm:"size:128;"` // 批号
- Qrcode string `json:"qrcode" gorm:"size:256;"` // 追溯码
- Img string `json:"img" gorm:"type:longtext"` // 图片 001.jpg,002.jpg,003.jpg
- ImgUrl string `json:"imgUrl" gorm:"-"`
- SrcList []string `json:"crcList" gorm:"-"`
- model2.ControlBy
- model2.ModelTime
- }
- func (e *MedicineImg) TableName() string {
- return "medicine_img"
- }
- func (e *MedicineImg) GetId() interface{} {
- return e.Id
- }
- func SyncMedicineInfoToMedicineImg() {
- // 删除表内字段
- var tableName []string
- err := db.DB.Raw("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_NAME LIKE 'medicine_info_%';").
- Scan(&tableName).Error
- if err != nil {
- logs.Error("db error: %s", err)
- }
- tx := db.DB.Begin()
- for _, v := range tableName {
- var info []MedicineInfo
- err = tx.Table(v).
- Preload("Product").
- Preload("Enterprise").
- Preload("Spec").
- Preload("Unit").
- Preload("DosageForm").
- Find(&info).
- Error
- if err != nil {
- tx.Rollback()
- logs.Error("修改表结构失败: %s", err.Error())
- break
- }
- deptId := strings.Trim(v, "medicine_info_")
- for _, i := range info {
- img := MedicineImg{
- Product: i.Product.Name,
- Enterprise: i.Enterprise.Name,
- Spec: i.Spec.Name,
- Unit: i.Unit.Name,
- DosageForm: i.DosageForm.Name,
- BatchNumber: i.BatchNumber,
- ControlBy: model2.ControlBy{
- DeptId: utils.ToInt(deptId),
- },
- }
- err = tx.Model(MedicineImg{}).Create(&img).Error
- if err != nil {
- tx.Rollback()
- logs.Error("修改表结构失败: %s", err.Error())
- break
- }
- }
- }
- tx.Commit()
- }
|