优化结构
This commit is contained in:
@@ -73,6 +73,7 @@ func main() {
|
|||||||
|
|
||||||
//统一初始化
|
//统一初始化
|
||||||
models.ConfigAllInit()
|
models.ConfigAllInit()
|
||||||
|
routers.ReturnInit()
|
||||||
routers.ApiUserInit() //用户表先初始化这是必须的因为后面需要用到用户组
|
routers.ApiUserInit() //用户表先初始化这是必须的因为后面需要用到用户组
|
||||||
routers.ApiFilesInit()
|
routers.ApiFilesInit()
|
||||||
routers.ApiScheduleInit()
|
routers.ApiScheduleInit()
|
||||||
@@ -80,6 +81,8 @@ func main() {
|
|||||||
routers.ApiWorkOrderInit()
|
routers.ApiWorkOrderInit()
|
||||||
routers.ApiWarehouseInit()
|
routers.ApiWarehouseInit()
|
||||||
|
|
||||||
|
routers.BindsInit() //最后初始化绑定数据表
|
||||||
|
|
||||||
//创建必要目录
|
//创建必要目录
|
||||||
for _, path := range models.ConfigsFile.Pahts {
|
for _, path := range models.ConfigsFile.Pahts {
|
||||||
fmt.Println(path)
|
fmt.Println(path)
|
||||||
|
|||||||
@@ -1,15 +1,9 @@
|
|||||||
package routers
|
package routers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrorCode map[string]interface{}
|
|
||||||
|
|
||||||
// 版本信息,由 main.go 在启动前赋值(值来自 -ldflags 注入)
|
// 版本信息,由 main.go 在启动前赋值(值来自 -ldflags 注入)
|
||||||
var (
|
var (
|
||||||
GitVersion = "dev"
|
GitVersion = "dev"
|
||||||
@@ -17,21 +11,6 @@ var (
|
|||||||
BuildTime = "unknown"
|
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
|
// 把数据分离成cookie和json
|
||||||
func SeparateData(ctx *gin.Context) (map[string]interface{}, string) {
|
func SeparateData(ctx *gin.Context) (map[string]interface{}, string) {
|
||||||
var jsonData map[string]interface{}
|
var jsonData map[string]interface{}
|
||||||
|
|||||||
@@ -92,12 +92,7 @@ type TabPurchaseCosts struct {
|
|||||||
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
|
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 记录订单状态变更及评论
|
// TabPurchaseCommit 记录订单状态变更及评论
|
||||||
type TabPurchaseCommit struct {
|
type TabPurchaseCommit struct {
|
||||||
@@ -130,7 +125,7 @@ func ApiPurchaseInit() {
|
|||||||
|
|
||||||
models.DB.AutoMigrate(&TabPurchaseOrder{})
|
models.DB.AutoMigrate(&TabPurchaseOrder{})
|
||||||
models.DB.AutoMigrate(&TabPurchaseCosts{})
|
models.DB.AutoMigrate(&TabPurchaseCosts{})
|
||||||
models.DB.AutoMigrate(&TabPurchaseFileBind{})
|
|
||||||
models.DB.AutoMigrate(&TabPurchaseLog{})
|
models.DB.AutoMigrate(&TabPurchaseLog{})
|
||||||
models.DB.AutoMigrate(&TabPurchaseCommit{})
|
models.DB.AutoMigrate(&TabPurchaseCommit{})
|
||||||
|
|
||||||
|
|||||||
@@ -41,22 +41,6 @@ type TabWarehouseItem struct {
|
|||||||
ContainerID *uint `gorm:"index;comment:所属容器id,nil=未入库" json:"ContainerID"`
|
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 {
|
type TabWarehouseItemCommit struct {
|
||||||
ID uint `gorm:"primaryKey" json:"ID"`
|
ID uint `gorm:"primaryKey" json:"ID"`
|
||||||
ItemID uint `gorm:"not null;index;comment:关联物品id" json:"ItemID"`
|
ItemID uint `gorm:"not null;index;comment:关联物品id" json:"ItemID"`
|
||||||
@@ -81,15 +65,6 @@ type TabWarehouseLog struct {
|
|||||||
CreatedAt time.Time `gorm:"type:datetime;autoCreateTime"`
|
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 (
|
var (
|
||||||
warehouseUserGroup TabUserGroups
|
warehouseUserGroup TabUserGroups
|
||||||
warehouseAdmins []uint
|
warehouseAdmins []uint
|
||||||
@@ -163,11 +138,8 @@ func ApiWarehouseInit() {
|
|||||||
models.DB.AutoMigrate(
|
models.DB.AutoMigrate(
|
||||||
&TabWarehouseContainer{},
|
&TabWarehouseContainer{},
|
||||||
&TabWarehouseItem{},
|
&TabWarehouseItem{},
|
||||||
&TabWarehouseContainerFileBind{},
|
|
||||||
&TabWarehouseItemFileBind{},
|
|
||||||
&TabWarehouseItemCommit{},
|
&TabWarehouseItemCommit{},
|
||||||
&TabWarehouseLog{},
|
&TabWarehouseLog{},
|
||||||
&TabWarehouseItemWorkOrderBind{},
|
|
||||||
)
|
)
|
||||||
|
|
||||||
warehouseUserGroup.Name = "warehouse_admin"
|
warehouseUserGroup.Name = "warehouse_admin"
|
||||||
|
|||||||
@@ -50,12 +50,7 @@ type TabWorkOrder struct {
|
|||||||
DeletedAt gorm.DeletedAt `gorm:"index"`
|
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 {
|
type TabWorkOrderCommit struct {
|
||||||
ID uint `gorm:"primarykey"`
|
ID uint `gorm:"primarykey"`
|
||||||
@@ -81,22 +76,7 @@ type TabWorkOrderLog struct {
|
|||||||
CreatedAt *time.Time `gorm:"type:datetime;autoCreateTime"`
|
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 采购订单简要信息
|
// PurchaseOrderInfo 采购订单简要信息
|
||||||
type PurchaseOrderInfo struct {
|
type PurchaseOrderInfo struct {
|
||||||
@@ -109,11 +89,10 @@ type PurchaseOrderInfo struct {
|
|||||||
|
|
||||||
func ApiWorkOrderInit() {
|
func ApiWorkOrderInit() {
|
||||||
models.DB.AutoMigrate(&TabWorkOrder{})
|
models.DB.AutoMigrate(&TabWorkOrder{})
|
||||||
models.DB.AutoMigrate(&TabWorkOrderFileBind{})
|
|
||||||
models.DB.AutoMigrate(&TabWorkOrderCommit{})
|
models.DB.AutoMigrate(&TabWorkOrderCommit{})
|
||||||
models.DB.AutoMigrate(&TabWorkOrderLog{})
|
models.DB.AutoMigrate(&TabWorkOrderLog{})
|
||||||
models.DB.AutoMigrate(&TabWorkOrderCommitFileBind{})
|
|
||||||
models.DB.AutoMigrate(&TabWorkOrderPurchaseOrderBind{})
|
|
||||||
|
|
||||||
workOrderUserGroup.Name = "work_order_admin"
|
workOrderUserGroup.Name = "work_order_admin"
|
||||||
if models.DB.Where(&workOrderUserGroup).First(&workOrderUserGroup).Error == nil {
|
if models.DB.Where(&workOrderUserGroup).First(&workOrderUserGroup).Error == nil {
|
||||||
|
|||||||
@@ -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{},
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,10 +3,27 @@ package routers
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"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{}) {
|
func DebugPrintJson(data map[string]interface{}) {
|
||||||
p, _ := json.MarshalIndent(data, "", " ")
|
p, _ := json.MarshalIndent(data, "", " ")
|
||||||
fmt.Println("\n", string(p))
|
fmt.Println("\n", string(p))
|
||||||
|
|||||||
Reference in New Issue
Block a user