修改文件表的名字
This commit is contained in:
@@ -180,7 +180,7 @@ func ApiPurchase(r *gin.RouterGroup) {
|
|||||||
for _, b := range binds {
|
for _, b := range binds {
|
||||||
fileIDs = append(fileIDs, b.FileID)
|
fileIDs = append(fileIDs, b.FileID)
|
||||||
}
|
}
|
||||||
var files []TabFileInfo_
|
var files []TabFileInfo
|
||||||
if len(fileIDs) > 0 {
|
if len(fileIDs) > 0 {
|
||||||
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
||||||
}
|
}
|
||||||
@@ -585,7 +585,7 @@ func ApiPurchase(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
//绑定文件
|
//绑定文件
|
||||||
for i := 0; i < len(jsondata.Photos); i++ {
|
for i := 0; i < len(jsondata.Photos); i++ {
|
||||||
findFile := TabFileInfo_{
|
findFile := TabFileInfo{
|
||||||
Sha256: jsondata.Photos[i],
|
Sha256: jsondata.Photos[i],
|
||||||
Type: "image",
|
Type: "image",
|
||||||
}
|
}
|
||||||
@@ -731,7 +731,7 @@ func ApiPurchase(r *gin.RouterGroup) {
|
|||||||
// 重建图片绑定:先删旧,再插新
|
// 重建图片绑定:先删旧,再插新
|
||||||
models.DB.Where("order_id = ?", from.ID).Delete(&TabPurchaseFileBind{})
|
models.DB.Where("order_id = ?", from.ID).Delete(&TabPurchaseFileBind{})
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
findFile := TabFileInfo_{Sha256: hash, Type: "image"}
|
findFile := TabFileInfo{Sha256: hash, Type: "image"}
|
||||||
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabPurchaseFileBind{
|
models.DB.Create(&TabPurchaseFileBind{
|
||||||
OrderID: from.ID,
|
OrderID: from.ID,
|
||||||
|
|||||||
@@ -253,8 +253,8 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
// 绑定图片
|
// 绑定图片
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
var findFile TabFileInfo_
|
var findFile TabFileInfo
|
||||||
if models.DB.Where(&TabFileInfo_{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
if models.DB.Where(&TabFileInfo{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWarehouseContainerFileBind{
|
models.DB.Create(&TabWarehouseContainerFileBind{
|
||||||
ContainerID: c.ID,
|
ContainerID: c.ID,
|
||||||
FileID: findFile.ID,
|
FileID: findFile.ID,
|
||||||
@@ -335,8 +335,8 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
// 重建图片绑定
|
// 重建图片绑定
|
||||||
models.DB.Where("container_id = ?", from.ID).Delete(&TabWarehouseContainerFileBind{})
|
models.DB.Where("container_id = ?", from.ID).Delete(&TabWarehouseContainerFileBind{})
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
var findFile TabFileInfo_
|
var findFile TabFileInfo
|
||||||
if models.DB.Where(&TabFileInfo_{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
if models.DB.Where(&TabFileInfo{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWarehouseContainerFileBind{
|
models.DB.Create(&TabWarehouseContainerFileBind{
|
||||||
ContainerID: from.ID,
|
ContainerID: from.ID,
|
||||||
FileID: findFile.ID,
|
FileID: findFile.ID,
|
||||||
@@ -535,7 +535,7 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
for _, b := range binds {
|
for _, b := range binds {
|
||||||
fileIDs = append(fileIDs, b.FileID)
|
fileIDs = append(fileIDs, b.FileID)
|
||||||
}
|
}
|
||||||
var files []TabFileInfo_
|
var files []TabFileInfo
|
||||||
if len(fileIDs) > 0 {
|
if len(fileIDs) > 0 {
|
||||||
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
||||||
}
|
}
|
||||||
@@ -639,8 +639,8 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
// 绑定图片
|
// 绑定图片
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
var findFile TabFileInfo_
|
var findFile TabFileInfo
|
||||||
if models.DB.Where(&TabFileInfo_{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
if models.DB.Where(&TabFileInfo{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWarehouseItemFileBind{
|
models.DB.Create(&TabWarehouseItemFileBind{
|
||||||
ItemID: item.ID,
|
ItemID: item.ID,
|
||||||
FileID: findFile.ID,
|
FileID: findFile.ID,
|
||||||
@@ -668,8 +668,8 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
// 新增/更新时绑定图片
|
// 新增/更新时绑定图片
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
var findFile TabFileInfo_
|
var findFile TabFileInfo
|
||||||
if models.DB.Where(&TabFileInfo_{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
if models.DB.Where(&TabFileInfo{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
||||||
// 检查是否已绑定,避免重复
|
// 检查是否已绑定,避免重复
|
||||||
var count int64
|
var count int64
|
||||||
models.DB.Model(&TabWarehouseItemFileBind{}).Where("item_id = ? AND file_id = ?", itemID, findFile.ID).Count(&count)
|
models.DB.Model(&TabWarehouseItemFileBind{}).Where("item_id = ? AND file_id = ?", itemID, findFile.ID).Count(&count)
|
||||||
@@ -748,8 +748,8 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
// 重建图片绑定
|
// 重建图片绑定
|
||||||
models.DB.Where("item_id = ?", from.ID).Delete(&TabWarehouseItemFileBind{})
|
models.DB.Where("item_id = ?", from.ID).Delete(&TabWarehouseItemFileBind{})
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
var findFile TabFileInfo_
|
var findFile TabFileInfo
|
||||||
if models.DB.Where(&TabFileInfo_{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
if models.DB.Where(&TabFileInfo{Sha256: hash, Type: "image"}).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWarehouseItemFileBind{
|
models.DB.Create(&TabWarehouseItemFileBind{
|
||||||
ItemID: from.ID,
|
ItemID: from.ID,
|
||||||
FileID: findFile.ID,
|
FileID: findFile.ID,
|
||||||
@@ -942,7 +942,7 @@ func ApiWarehouse(r *gin.RouterGroup) {
|
|||||||
for _, b := range binds {
|
for _, b := range binds {
|
||||||
fileIDs = append(fileIDs, b.FileID)
|
fileIDs = append(fileIDs, b.FileID)
|
||||||
}
|
}
|
||||||
var files []TabFileInfo_
|
var files []TabFileInfo
|
||||||
if len(fileIDs) > 0 {
|
if len(fileIDs) > 0 {
|
||||||
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
// 绑定图片
|
// 绑定图片
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
findFile := TabFileInfo_{Sha256: hash, Type: "image"}
|
findFile := TabFileInfo{Sha256: hash, Type: "image"}
|
||||||
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWorkOrderFileBind{
|
models.DB.Create(&TabWorkOrderFileBind{
|
||||||
WorkOrderID: order.ID,
|
WorkOrderID: order.ID,
|
||||||
@@ -257,7 +257,7 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
// 重建图片绑定
|
// 重建图片绑定
|
||||||
models.DB.Where("work_order_id = ?", from.ID).Delete(&TabWorkOrderFileBind{})
|
models.DB.Where("work_order_id = ?", from.ID).Delete(&TabWorkOrderFileBind{})
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
findFile := TabFileInfo_{Sha256: hash, Type: "image"}
|
findFile := TabFileInfo{Sha256: hash, Type: "image"}
|
||||||
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWorkOrderFileBind{
|
models.DB.Create(&TabWorkOrderFileBind{
|
||||||
WorkOrderID: from.ID,
|
WorkOrderID: from.ID,
|
||||||
@@ -357,7 +357,7 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
for _, b := range binds {
|
for _, b := range binds {
|
||||||
fileIDs = append(fileIDs, b.FileID)
|
fileIDs = append(fileIDs, b.FileID)
|
||||||
}
|
}
|
||||||
var files []TabFileInfo_
|
var files []TabFileInfo
|
||||||
if len(fileIDs) > 0 {
|
if len(fileIDs) > 0 {
|
||||||
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
models.DB.Where("id IN ?", fileIDs).Find(&files)
|
||||||
}
|
}
|
||||||
@@ -369,12 +369,12 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
// 为每条 commit 附加图片和采购订单
|
// 为每条 commit 附加图片和采购订单
|
||||||
type CommitWithPhotos struct {
|
type CommitWithPhotos struct {
|
||||||
TabWorkOrderCommit
|
TabWorkOrderCommit
|
||||||
Photos []TabFileInfo_ `json:"photos"`
|
Photos []TabFileInfo `json:"photos"`
|
||||||
PurchaseOrders []PurchaseOrderInfo `json:"purchaseOrders"`
|
PurchaseOrders []PurchaseOrderInfo `json:"purchaseOrders"`
|
||||||
}
|
}
|
||||||
var commitsWithPhotos []CommitWithPhotos
|
var commitsWithPhotos []CommitWithPhotos
|
||||||
for _, c := range commits {
|
for _, c := range commits {
|
||||||
item := CommitWithPhotos{TabWorkOrderCommit: c, Photos: []TabFileInfo_{}, PurchaseOrders: []PurchaseOrderInfo{}}
|
item := CommitWithPhotos{TabWorkOrderCommit: c, Photos: []TabFileInfo{}, PurchaseOrders: []PurchaseOrderInfo{}}
|
||||||
|
|
||||||
// 附加图片
|
// 附加图片
|
||||||
var fileBinds []TabWorkOrderCommitFileBind
|
var fileBinds []TabWorkOrderCommitFileBind
|
||||||
@@ -547,7 +547,7 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
|||||||
|
|
||||||
// 绑定进度图片
|
// 绑定进度图片
|
||||||
for _, hash := range from.Photos {
|
for _, hash := range from.Photos {
|
||||||
findFile := TabFileInfo_{Sha256: hash, Type: "image"}
|
findFile := TabFileInfo{Sha256: hash, Type: "image"}
|
||||||
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
if models.DB.Where(&findFile).First(&findFile).Error == nil {
|
||||||
models.DB.Create(&TabWorkOrderCommitFileBind{
|
models.DB.Create(&TabWorkOrderCommitFileBind{
|
||||||
CommitID: commit.ID,
|
CommitID: commit.ID,
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TabFileInfo_ struct {
|
type TabFileInfo struct {
|
||||||
ID uint `gorm:"primaryKey;autoIncrement"`
|
ID uint `gorm:"primaryKey;autoIncrement"`
|
||||||
Name string `gorm:"not null;size:256;index"` // 前端报告的文件名
|
Name string `gorm:"not null;size:256;index"` // 前端报告的文件名
|
||||||
Size int64 `gorm:"not null"`
|
Size int64 `gorm:"not null"`
|
||||||
@@ -31,7 +31,7 @@ func file_save() {
|
|||||||
|
|
||||||
func ApiFilesInit() {
|
func ApiFilesInit() {
|
||||||
|
|
||||||
models.DB.AutoMigrate(&TabFileInfo_{})
|
models.DB.AutoMigrate(&TabFileInfo{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func ApiFiles(r *gin.RouterGroup) {
|
func ApiFiles(r *gin.RouterGroup) {
|
||||||
@@ -55,7 +55,7 @@ func ApiFiles(r *gin.RouterGroup) {
|
|||||||
download = false
|
download = false
|
||||||
}
|
}
|
||||||
if isPartOK {
|
if isPartOK {
|
||||||
file_info := TabFileInfo_{
|
file_info := TabFileInfo{
|
||||||
Sha256: hash,
|
Sha256: hash,
|
||||||
}
|
}
|
||||||
if models.DB.Where(&file_info).First(&file_info).Error == nil {
|
if models.DB.Where(&file_info).First(&file_info).Error == nil {
|
||||||
@@ -127,7 +127,7 @@ func ApiFiles(r *gin.RouterGroup) {
|
|||||||
}
|
}
|
||||||
//记录到数据库
|
//记录到数据库
|
||||||
//先检查数据库有没有数据
|
//先检查数据库有没有数据
|
||||||
fund_file_info := TabFileInfo_{
|
fund_file_info := TabFileInfo{
|
||||||
Name: filename,
|
Name: filename,
|
||||||
Size: file.Size,
|
Size: file.Size,
|
||||||
Sha256: hash_str,
|
Sha256: hash_str,
|
||||||
@@ -135,7 +135,7 @@ func ApiFiles(r *gin.RouterGroup) {
|
|||||||
Type: "image",
|
Type: "image",
|
||||||
UserID: user.ID,
|
UserID: user.ID,
|
||||||
}
|
}
|
||||||
fund_file_info2 := TabFileInfo_{}
|
fund_file_info2 := TabFileInfo{}
|
||||||
|
|
||||||
models.DB.Where(&fund_file_info).Find(&fund_file_info2)
|
models.DB.Where(&fund_file_info).Find(&fund_file_info2)
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func ReturnJson(ctx *gin.Context, errMsg string, data map[string]interface{}) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReturnFile(ctx *gin.Context, file_info *TabFileInfo_, preview bool) {
|
func ReturnFile(ctx *gin.Context, file_info *TabFileInfo, preview bool) {
|
||||||
if preview {
|
if preview {
|
||||||
ctx.File(file_info.Path)
|
ctx.File(file_info.Path)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user