优化结构

This commit is contained in:
2026-04-28 17:33:00 +08:00
parent 07b97bc514
commit c3253b588d
7 changed files with 133 additions and 110 deletions
+3
View File
@@ -73,6 +73,7 @@ func main() {
//统一初始化
models.ConfigAllInit()
routers.ReturnInit()
routers.ApiUserInit() //用户表先初始化这是必须的因为后面需要用到用户组
routers.ApiFilesInit()
routers.ApiScheduleInit()
@@ -80,6 +81,8 @@ func main() {
routers.ApiWorkOrderInit()
routers.ApiWarehouseInit()
routers.BindsInit() //最后初始化绑定数据表
//创建必要目录
for _, path := range models.ConfigsFile.Pahts {
fmt.Println(path)
-21
View File
@@ -1,15 +1,9 @@
package routers
import (
"encoding/json"
"fmt"
"os"
"github.com/gin-gonic/gin"
)
var ErrorCode map[string]interface{}
// 版本信息,由 main.go 在启动前赋值(值来自 -ldflags 注入)
var (
GitVersion = "dev"
@@ -17,21 +11,6 @@ var (
BuildTime = "unknown"
)
func init() {
//读取默认配置
fmt.Println("尝试读取错误码文件")
data, err := os.ReadFile("./defConfig/errorCodes.json")
if err != nil {
fmt.Println("读取错误码文件失败", err)
}
if err := json.Unmarshal(data, &ErrorCode); err != nil {
fmt.Println("解析错误码文件失败", err)
}
}
// 把数据分离成cookie和json
func SeparateData(ctx *gin.Context) (map[string]interface{}, string) {
var jsonData map[string]interface{}
+2 -7
View File
@@ -92,12 +92,7 @@ type TabPurchaseCosts struct {
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabPurchaseFileBind struct {
ID uint `gorm:"primarykey"`
OrderID uint `gorm:"not null"`
FileID uint `gorm:"not null"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
// TabPurchaseCommit 记录订单状态变更及评论
type TabPurchaseCommit struct {
@@ -130,7 +125,7 @@ func ApiPurchaseInit() {
models.DB.AutoMigrate(&TabPurchaseOrder{})
models.DB.AutoMigrate(&TabPurchaseCosts{})
models.DB.AutoMigrate(&TabPurchaseFileBind{})
models.DB.AutoMigrate(&TabPurchaseLog{})
models.DB.AutoMigrate(&TabPurchaseCommit{})
-28
View File
@@ -41,22 +41,6 @@ type TabWarehouseItem struct {
ContainerID *uint `gorm:"index;comment:所属容器idnil=未入库" json:"ContainerID"`
}
type TabWarehouseContainerFileBind struct {
ID uint `gorm:"primaryKey"`
ContainerID uint `gorm:"not null;index;comment:关联容器id"`
FileID uint `gorm:"not null;comment:关联文件id"`
CreatorID uint `gorm:"not null;comment:上传人id"`
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWarehouseItemFileBind struct {
ID uint `gorm:"primaryKey"`
ItemID uint `gorm:"not null;index;comment:关联物品id"`
FileID uint `gorm:"not null;comment:关联文件id"`
CreatorID uint `gorm:"not null;comment:上传人id"`
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWarehouseItemCommit struct {
ID uint `gorm:"primaryKey" json:"ID"`
ItemID uint `gorm:"not null;index;comment:关联物品id" json:"ItemID"`
@@ -81,15 +65,6 @@ type TabWarehouseLog struct {
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWarehouseItemWorkOrderBind struct {
ID uint `gorm:"primaryKey"`
ItemID uint `gorm:"not null;index;comment:关联物品id"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单id"`
Remark string `gorm:"size:500;comment:备注"`
CreatorID uint `gorm:"not null;comment:绑定人id"`
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
var (
warehouseUserGroup TabUserGroups
warehouseAdmins []uint
@@ -163,11 +138,8 @@ func ApiWarehouseInit() {
models.DB.AutoMigrate(
&TabWarehouseContainer{},
&TabWarehouseItem{},
&TabWarehouseContainerFileBind{},
&TabWarehouseItemFileBind{},
&TabWarehouseItemCommit{},
&TabWarehouseLog{},
&TabWarehouseItemWorkOrderBind{},
)
warehouseUserGroup.Name = "warehouse_admin"
+3 -24
View File
@@ -50,12 +50,7 @@ type TabWorkOrder struct {
DeletedAt gorm.DeletedAt `gorm:"index"`
}
type TabWorkOrderFileBind struct {
ID uint `gorm:"primarykey"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单ID"`
FileID uint `gorm:"not null;comment:关联文件ID"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWorkOrderCommit struct {
ID uint `gorm:"primarykey"`
@@ -81,22 +76,7 @@ type TabWorkOrderLog struct {
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWorkOrderCommitFileBind struct {
ID uint `gorm:"primarykey"`
CommitID uint `gorm:"not null;index;comment:关联进度ID"`
FileID uint `gorm:"not null;comment:关联文件ID"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单ID"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
// TabWorkOrderPurchaseOrderBind 工单与采购订单的关联表
type TabWorkOrderPurchaseOrderBind struct {
ID uint `gorm:"primarykey"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单ID"`
CommitID uint `gorm:"not null;index;comment:关联进度ID"`
PurchaseOrderID uint `gorm:"not null;comment:关联采购订单ID"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
// PurchaseOrderInfo 采购订单简要信息
type PurchaseOrderInfo struct {
@@ -109,11 +89,10 @@ type PurchaseOrderInfo struct {
func ApiWorkOrderInit() {
models.DB.AutoMigrate(&TabWorkOrder{})
models.DB.AutoMigrate(&TabWorkOrderFileBind{})
models.DB.AutoMigrate(&TabWorkOrderCommit{})
models.DB.AutoMigrate(&TabWorkOrderLog{})
models.DB.AutoMigrate(&TabWorkOrderCommitFileBind{})
models.DB.AutoMigrate(&TabWorkOrderPurchaseOrderBind{})
workOrderUserGroup.Name = "work_order_admin"
if models.DB.Where(&workOrderUserGroup).First(&workOrderUserGroup).Error == nil {
+78
View File
@@ -0,0 +1,78 @@
package routers
import (
"ops/models"
"time"
)
//跨模块绑定区
//绑定数据统一处理区
type TabPurchaseFileBind struct {
ID uint `gorm:"primarykey"`
OrderID uint `gorm:"not null"`
FileID uint `gorm:"not null"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWarehouseItemFileBind struct {
ID uint `gorm:"primaryKey"`
ItemID uint `gorm:"not null;index;comment:关联物品id"`
FileID uint `gorm:"not null;comment:关联文件id"`
CreatorID uint `gorm:"not null;comment:上传人id"`
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWarehouseItemWorkOrderBind struct {
ID uint `gorm:"primaryKey"`
ItemID uint `gorm:"not null;index;comment:关联物品id"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单id"`
Remark string `gorm:"size:500;comment:备注"`
CreatorID uint `gorm:"not null;comment:绑定人id"`
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWorkOrderFileBind struct {
ID uint `gorm:"primarykey"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单ID"`
FileID uint `gorm:"not null;comment:关联文件ID"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWorkOrderCommitFileBind struct {
ID uint `gorm:"primarykey"`
CommitID uint `gorm:"not null;index;comment:关联进度ID"`
FileID uint `gorm:"not null;comment:关联文件ID"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单ID"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
// TabWorkOrderPurchaseOrderBind 工单与采购订单的关联表
type TabWorkOrderPurchaseOrderBind struct {
ID uint `gorm:"primarykey"`
WorkOrderID uint `gorm:"not null;index;comment:关联工单ID"`
CommitID uint `gorm:"not null;index;comment:关联进度ID"`
PurchaseOrderID uint `gorm:"not null;comment:关联采购订单ID"`
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
}
type TabWarehouseContainerFileBind struct {
ID uint `gorm:"primaryKey"`
ContainerID uint `gorm:"not null;index;comment:关联容器id"`
FileID uint `gorm:"not null;comment:关联文件id"`
CreatorID uint `gorm:"not null;comment:上传人id"`
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
}
func BindsInit() {
models.DB.AutoMigrate(
&TabPurchaseFileBind{},
&TabWarehouseItemFileBind{},
&TabWarehouseItemWorkOrderBind{},
&TabWarehouseContainerFileBind{},
&TabWorkOrderFileBind{},
&TabWorkOrderCommitFileBind{},
&TabWorkOrderPurchaseOrderBind{},
)
}
+17
View File
@@ -3,10 +3,27 @@ package routers
import (
"encoding/json"
"fmt"
"os"
"github.com/gin-gonic/gin"
)
var ErrorCode map[string]interface{}
func ReturnInit() {
//读取默认配置
fmt.Println("尝试读取错误码文件")
data, err := os.ReadFile("./defConfig/errorCodes.json")
if err != nil {
fmt.Println("读取错误码文件失败", err)
}
if err := json.Unmarshal(data, &ErrorCode); err != nil {
fmt.Println("解析错误码文件失败", err)
}
}
func DebugPrintJson(data map[string]interface{}) {
p, _ := json.MarshalIndent(data, "", " ")
fmt.Println("\n", string(p))