jiangshuai
2024-01-05 62521666983845e0ed33b8d646c1814a28f5fbc3
修改模版获取
2个文件已修改
35 ■■■■ 已修改文件
controllers/operation.go 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/file_template_attachment.go 27 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/operation.go
@@ -860,11 +860,11 @@
}
func ExportInputSelfmade(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
    template, err := models.NewFileTemplateAttachmentSearch().SetPreload(true).SetCategory(category).First()
    template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
    if err != nil {
        return "", errors.New("获取模版记录失败:" + err.Error())
    }
    readerCloser, err := http.HttpGetWithReadCloser(template.Attachment.FileUrl)
    readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl)
    if err != nil {
        return "", errors.New("获取模版失败:" + err.Error())
    }
@@ -941,11 +941,11 @@
func ExportOutputOperation(category constvar.FileTemplateCategory, operation *models.Operation) (string, error) {
    repositoryLevels := strings.Split(operation.Location.JointName, "/")
    template, err := models.NewFileTemplateAttachmentSearch().SetPreload(true).SetCategory(category).First()
    template, err := models.NewFileTemplateAttachmentSearch().SetCategory(category).First()
    if err != nil {
        return "", errors.New("获取模版记录失败:" + err.Error())
    }
    readerCloser, err := http.HttpGetWithReadCloser(template.Attachment.FileUrl)
    readerCloser, err := http.HttpGetWithReadCloser(template.FileUrl)
    if err != nil {
        return "", errors.New("获取模版失败:" + err.Error())
    }
models/file_template_attachment.go
@@ -10,12 +10,13 @@
type (
    FileTemplateAttachment struct {
        WmsModel
        Id           int                           `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Category     constvar.FileTemplateCategory `json:"category" gorm:"type:int(11);comment:模版种类"`
        Name         string                        `json:"name" gorm:"type:varchar(63);comment:模版名称"`
        AttachmentId uint                          `json:"attachmentId" gorm:"comment:附件表外键"`
        Attachment   Attachment                    `json:"attachment" gorm:"foreignKey:AttachmentId;references:Id"`
        TableInfo    string                        `json:"tableInfo" gorm:"type:varchar(31);comment:表名"`
        Id       int                           `json:"id"  gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Category constvar.FileTemplateCategory `json:"category" gorm:"type:int(11);comment:模版种类"`
        Name     string                        `json:"name" gorm:"type:varchar(63);comment:模版名称"`
        //AttachmentId uint                          `json:"attachmentId" gorm:"comment:附件表外键"`
        //Attachment   Attachment                    `json:"attachment" gorm:"foreignKey:AttachmentId;references:Id"`
        TableInfo string `json:"tableInfo" gorm:"type:varchar(31);comment:表名"`
        FileUrl   string `json:"fileUrl" gorm:"type:varchar(255);comment:文件地址"`
    }
    FileTemplateAttachmentSearch struct {
        FileTemplateAttachment
@@ -61,10 +62,10 @@
    return slf
}
func (slf *FileTemplateAttachmentSearch) SetPreload(preload bool) *FileTemplateAttachmentSearch {
    slf.Preload = preload
    return slf
}
//func (slf *FileTemplateAttachmentSearch) SetPreload(preload bool) *FileTemplateAttachmentSearch {
//    slf.Preload = preload
//    return slf
//}
func (slf *FileTemplateAttachmentSearch) SetCategory(category constvar.FileTemplateCategory) *FileTemplateAttachmentSearch {
    slf.Category = category
@@ -81,9 +82,9 @@
        db = db.Order(slf.Order)
    }
    if slf.Preload {
        db = db.Model(&FileTemplateAttachment{}).Preload("Attachment")
    }
    //if slf.Preload {
    //    db = db.Model(&FileTemplateAttachment{}).Preload("Attachment")
    //}
    if int(slf.Category) != 0 {
        db = db.Where("category=?", slf.Category)