diff --git a/backend/my_work/main.go b/backend/my_work/main.go index 056c467..cc61dd7 100644 --- a/backend/my_work/main.go +++ b/backend/my_work/main.go @@ -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) diff --git a/backend/my_work/routers/api.go b/backend/my_work/routers/api.go index 5f09389..aed2877 100644 --- a/backend/my_work/routers/api.go +++ b/backend/my_work/routers/api.go @@ -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{} @@ -67,9 +46,9 @@ func ApiRoot(r *gin.RouterGroup) { r.GET("/", func(ctx *gin.Context) { ReturnJson(ctx, "apiOK", gin.H{ "isOpsApiRoot": true, - "version": GitVersion, - "gitCommit": GitCommit, - "buildTime": BuildTime, + "version": GitVersion, + "gitCommit": GitCommit, + "buildTime": BuildTime, }) }) diff --git a/backend/my_work/routers/apiPurchase.go b/backend/my_work/routers/apiPurchase.go index ebf7b26..24a44e7 100644 --- a/backend/my_work/routers/apiPurchase.go +++ b/backend/my_work/routers/apiPurchase.go @@ -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{}) diff --git a/backend/my_work/routers/apiWarehouse.go b/backend/my_work/routers/apiWarehouse.go index e2a7fea..3c1e752 100644 --- a/backend/my_work/routers/apiWarehouse.go +++ b/backend/my_work/routers/apiWarehouse.go @@ -41,28 +41,12 @@ type TabWarehouseItem struct { ContainerID *uint `gorm:"index;comment:所属容器id,nil=未入库" 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"` UserID uint `gorm:"not null;comment:操作人id" json:"UserID"` - OldContainer *uint `gorm:"index;comment:原容器id" json:"OldContainer"` - NewContainer *uint `gorm:"index;comment:新容器id" json:"NewContainer"` + OldContainer *uint `gorm:"index;comment:原容器id" json:"OldContainer"` + NewContainer *uint `gorm:"index;comment:新容器id" json:"NewContainer"` Remark string `gorm:"type:text;comment:备注" json:"Remark"` IP string `gorm:"size:50;comment:操作IP" json:"IP"` CreatedAt time.Time `gorm:"type:datetime;autoCreateTime" json:"CreatedAt"` @@ -81,18 +65,9 @@ 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 + warehouseAdmins []uint ) // updateWarehouseAdminsCash 刷新仓库管理员缓存 @@ -163,11 +138,8 @@ func ApiWarehouseInit() { models.DB.AutoMigrate( &TabWarehouseContainer{}, &TabWarehouseItem{}, - &TabWarehouseContainerFileBind{}, - &TabWarehouseItemFileBind{}, &TabWarehouseItemCommit{}, &TabWarehouseLog{}, - &TabWarehouseItemWorkOrderBind{}, ) warehouseUserGroup.Name = "warehouse_admin" @@ -257,8 +229,8 @@ func ApiWarehouse(r *gin.RouterGroup) { if models.DB.Where(&TabFileInfo{Sha256: hash, Type: "image"}).First(&findFile).Error == nil { models.DB.Create(&TabWarehouseContainerFileBind{ ContainerID: c.ID, - FileID: findFile.ID, - CreatorID: user.ID, + FileID: findFile.ID, + CreatorID: user.ID, }) } } @@ -470,8 +442,8 @@ func ApiWarehouse(r *gin.RouterGroup) { } ReturnJson(ctx, "apiOK", gin.H{ - "all_count": count, - "containers": containers, + "all_count": count, + "containers": containers, "canModifyContainers": canModifyContainers, }) }) @@ -541,10 +513,10 @@ func ApiWarehouse(r *gin.RouterGroup) { } ReturnJson(ctx, "apiOK", gin.H{ - "container": c, - "photos": files, - "parent_chain": parentChain, - "depth": depth, + "container": c, + "photos": files, + "parent_chain": parentChain, + "depth": depth, "canModifyContainer": canModifyWarehouse(user.ID, c.CreatorID), }) }) @@ -558,11 +530,11 @@ func ApiWarehouse(r *gin.RouterGroup) { } type FromAdd struct { - Name string `json:"name"` - SerialNumber string `json:"serial_number"` - Remark string `json:"remark"` - Quantity int `json:"quantity"` - ContainerID *uint `json:"container_id"` + Name string `json:"name"` + SerialNumber string `json:"serial_number"` + Remark string `json:"remark"` + Quantity int `json:"quantity"` + ContainerID *uint `json:"container_id"` Photos []string `json:"photos"` } var from FromAdd @@ -705,11 +677,11 @@ func ApiWarehouse(r *gin.RouterGroup) { } type FromUpdate struct { - ID uint `json:"id"` - Name string `json:"name"` - SerialNumber string `json:"serial_number"` - Remark string `json:"remark"` - Quantity int `json:"quantity"` + ID uint `json:"id"` + Name string `json:"name"` + SerialNumber string `json:"serial_number"` + Remark string `json:"remark"` + Quantity int `json:"quantity"` Photos []string `json:"photos"` } var from FromUpdate @@ -906,8 +878,8 @@ func ApiWarehouse(r *gin.RouterGroup) { } ReturnJson(ctx, "apiOK", gin.H{ - "all_count": count, - "items": itemsWithBreadcrumb, + "all_count": count, + "items": itemsWithBreadcrumb, "canModifyItems": canModifyItems, }) }) @@ -1011,9 +983,9 @@ func ApiWarehouse(r *gin.RouterGroup) { } type FromMove struct { - ItemID uint `json:"item_id"` - NewContainer *uint `json:"new_container"` - Remark string `json:"remark"` + ItemID uint `json:"item_id"` + NewContainer *uint `json:"new_container"` + Remark string `json:"remark"` } var from FromMove if err := decodeJSON(data, &from); err != nil || from.ItemID == 0 { @@ -1095,7 +1067,7 @@ func ApiWarehouse(r *gin.RouterGroup) { ReturnJson(ctx, "apiOK", gin.H{ "container_total": count.ContainerTotal, "item_total": count.ItemTotal, - "unstored_items": count.UnstoredItems, + "unstored_items": count.UnstoredItems, }) }) } diff --git a/backend/my_work/routers/apiWorkOrder.go b/backend/my_work/routers/apiWorkOrder.go index 673e7f7..f9bc455 100644 --- a/backend/my_work/routers/apiWorkOrder.go +++ b/backend/my_work/routers/apiWorkOrder.go @@ -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 { diff --git a/backend/my_work/routers/binds.go b/backend/my_work/routers/binds.go new file mode 100644 index 0000000..b0b588d --- /dev/null +++ b/backend/my_work/routers/binds.go @@ -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{}, + ) + +} diff --git a/backend/my_work/routers/return.go b/backend/my_work/routers/return.go index c924dba..9c7bca4 100644 --- a/backend/my_work/routers/return.go +++ b/backend/my_work/routers/return.go @@ -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))