medicine_template.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package models
  2. import (
  3. model2 "Medical_ERP/common/model"
  4. "github.com/beego/beego/v2/core/logs"
  5. "strconv"
  6. )
  7. const (
  8. FieldProductID = "product_id" // 品种ID
  9. FieldEnterpriseID = "enterprise_id" // 生产企业ID
  10. FieldSpecID = "spec_id" // 规格ID
  11. FieldUnitID = "unit_id" // 单位id
  12. FieldDosageFormID = "dosage_form_id" // 剂型id
  13. FieldBatchNumber = "batch_number" // 批号
  14. FieldExpiryDate = "expiry_date" // 失效日期
  15. FieldProducedDate = "produced_date" // 生产日期
  16. FieldApprovalNumber = "approval_number" // 批准文号
  17. FieldQualificationNumber = "qualification_number" // 批签发合格编号
  18. FieldProductName = "product_name"
  19. FieldEnterpriseName = "enterprise_name"
  20. FieldSpecName = "spec_name"
  21. FieldUnitName = "unit_name"
  22. FieldDosageFormName = "dosage_form_name"
  23. )
  24. func GetMedicineInfoTableName(deptId int) string {
  25. return "medicine_info_" + strconv.Itoa(deptId)
  26. }
  27. type MedicineTemplate struct {
  28. model2.Model
  29. Type int `json:"type" gorm:"size:11;"` // 数据类型
  30. Name string `json:"name" gorm:"size:32;"` // 标签名称
  31. FieldName string `json:"field_name" gorm:"size:128;"` // 英语名称
  32. Text string `json:"text" gorm:"size:256;"` // 描述
  33. Sort int `json:"sort" gorm:"size:11;"` // 排序
  34. Width int `json:"width" gorm:"size:11;"` // 宽度
  35. Show int `json:"show" gorm:"size:11;"` // 1-显示 2-隐藏
  36. State int `json:"state" gorm:"size:11;"` // 1-系统初始化 2-用户添加
  37. model2.ControlBy
  38. model2.ModelTime
  39. }
  40. func (e *MedicineTemplate) TableName() string {
  41. return "medicine_template"
  42. }
  43. func GetInitMedicineTemplateInfo(deptId, CreateBy int) []MedicineTemplate {
  44. return []MedicineTemplate{
  45. {Type: 1, Name: "品名", FieldName: FieldProductID, Show: 1, State: 1, Sort: -9, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  46. {Type: 2, Name: "生产企业", FieldName: FieldEnterpriseID, Show: 1, State: 1, Sort: -8, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  47. {Type: 3, Name: "规格", FieldName: FieldSpecID, Show: 1, State: 1, Sort: -7, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  48. {Type: 6, Name: "批号", FieldName: FieldBatchNumber, Show: 1, State: 1, Sort: -6, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  49. {Type: 9, Name: "失效日期", FieldName: FieldExpiryDate, Show: 1, State: 1, Sort: -5, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  50. {Type: 9, Name: "生产日期", FieldName: FieldProducedDate, Show: 1, State: 1, Sort: -5, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  51. {Type: 6, Name: "批准文号", FieldName: FieldApprovalNumber, Show: 1, State: 1, Sort: -4, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  52. {Type: 5, Name: "剂型", FieldName: FieldDosageFormID, Show: 1, State: 1, Sort: -3, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  53. {Type: 4, Name: "单位", FieldName: FieldUnitID, Show: 1, State: 1, Sort: -2, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  54. {Type: 6, Name: "批签发编号", FieldName: FieldQualificationNumber, Show: 1, State: 1, Sort: -1, ControlBy: model2.ControlBy{CreateBy: CreateBy, DeptId: deptId}},
  55. }
  56. }
  57. func GetInitMedicineTemplateSql(deptId int) string {
  58. sqlStmt := `
  59. CREATE TABLE IF NOT EXISTS ` + GetMedicineInfoTableName(deptId) + ` (
  60. id int primary key auto_increment comment '自增ID',
  61. product_id INT comment '品名ID',
  62. enterprise_id INT comment '生产企业ID',
  63. spec_id INT comment '规格ID',
  64. unit_id INT comment '单位ID',
  65. dosage_form_id INT comment '剂型ID',
  66. batch_number VARCHAR(256) comment '批号',
  67. expiry_date DATE comment '失效日期',
  68. produced_date DATE comment '生产日期',
  69. approval_number VARCHAR(256) comment '批准文号',
  70. qualification_number VARCHAR(256) comment '批签发编号',
  71. purchase_unit_price DECIMAL(10,2) comment '购进单价',
  72. sales_unit_price DECIMAL(10,2) comment '销售单价'
  73. );`
  74. return sqlStmt
  75. }
  76. // 获取插入数据sql
  77. func GetInsertMedicineTemplateSql(deptId, typeId int, columnName string) string {
  78. var typeStr string
  79. switch typeId {
  80. case 1, 2, 3, 4, 5:
  81. typeStr = " INT"
  82. case 6:
  83. typeStr = " VARCHAR(256)"
  84. case 7:
  85. typeStr = " INT"
  86. case 8:
  87. typeStr = " DECIMAL(10,2)"
  88. case 9:
  89. typeStr = " DATE"
  90. }
  91. sqlStmt := "ALTER TABLE " + GetMedicineInfoTableName(deptId) + " ADD `" + columnName + "`" + typeStr
  92. logs.Info("InsertMedicineTemplateSql", sqlStmt)
  93. return sqlStmt
  94. }
  95. // 获取更新列名sql
  96. func GetUpdateMedicineTemplateSql(deptId, typeId int, oldColumnName, newColumnName string) string {
  97. var typeStr string
  98. switch typeId {
  99. case 1, 2, 3, 4, 5:
  100. typeStr = " INT"
  101. case 6:
  102. typeStr = " VARCHAR(256)"
  103. case 7:
  104. typeStr = " INT"
  105. case 8:
  106. typeStr = " DECIMAL(10,4)"
  107. case 9:
  108. typeStr = " DATETIME"
  109. }
  110. sqlStmt := "ALTER TABLE " + GetMedicineInfoTableName(deptId) + " CHANGE `" + oldColumnName + "` `" + newColumnName + "`" + typeStr
  111. logs.Info("UpdateMedicineTemplateSql", sqlStmt)
  112. return sqlStmt
  113. }
  114. func GetDeleteMedicineTemplateSql(deptId int, columnName string) string {
  115. sqlStmt := "ALTER TABLE " + GetMedicineInfoTableName(deptId) + " DROP `" + columnName + "`"
  116. logs.Info("DeleteMedicineTemplateSql", sqlStmt)
  117. return sqlStmt
  118. }
  119. // type 说明 英文名称
  120. // 1 产品名称 ProductID
  121. // 2 生产企业 EnterpriseID
  122. // 3 规格 SpecID
  123. // 4 剂型 DosageFormID
  124. // 5 单位 UnitID
  125. // 6 文本
  126. // 7 数值(整数)
  127. // 7 数值(小数)
  128. // 9 日期