zhangqian
2024-06-13 2f856eaa7e46c884f1cb7ad721919a086d7f34a3
出入库明细列表和报表增加多单位
7个文件已修改
159 ■■■■■ 已修改文件
docs/docs.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/move_history.go 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
response/report_forms_response.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/history_forms.go 58 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/more_units.go 52 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go
@@ -4149,6 +4149,12 @@
                        }
                    ]
                },
                "checkedAt": {
                    "type": "string"
                },
                "checkedBy": {
                    "type": "string"
                },
                "comment": {
                    "type": "string"
                },
@@ -4162,6 +4168,9 @@
                    "type": "integer"
                },
                "contacterName": {
                    "type": "string"
                },
                "createBy": {
                    "type": "string"
                },
                "createTime": {
@@ -5748,6 +5757,13 @@
                    "description": "数量",
                    "type": "number"
                },
                "amountMoreUnits": {
                    "description": "在库数量多单位",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.UnitItems"
                    }
                },
                "locationId": {
                    "description": "位置id",
                    "type": "integer"
docs/swagger.json
@@ -4137,6 +4137,12 @@
                        }
                    ]
                },
                "checkedAt": {
                    "type": "string"
                },
                "checkedBy": {
                    "type": "string"
                },
                "comment": {
                    "type": "string"
                },
@@ -4150,6 +4156,9 @@
                    "type": "integer"
                },
                "contacterName": {
                    "type": "string"
                },
                "createBy": {
                    "type": "string"
                },
                "createTime": {
@@ -5736,6 +5745,13 @@
                    "description": "数量",
                    "type": "number"
                },
                "amountMoreUnits": {
                    "description": "在库数量多单位",
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/models.UnitItems"
                    }
                },
                "locationId": {
                    "description": "位置id",
                    "type": "integer"
docs/swagger.yaml
@@ -809,6 +809,10 @@
        allOf:
        - $ref: '#/definitions/constvar.BaseOperationType'
        description: 基础作业类型
      checkedAt:
        type: string
      checkedBy:
        type: string
      comment:
        type: string
      companyID:
@@ -818,6 +822,8 @@
      contacterID:
        type: integer
      contacterName:
        type: string
      createBy:
        type: string
      createTime:
        type: string
@@ -1912,6 +1918,11 @@
      amount:
        description: 数量
        type: number
      amountMoreUnits:
        description: 在库数量多单位
        items:
          $ref: '#/definitions/models.UnitItems'
        type: array
      locationId:
        description: 位置id
        type: integer
models/move_history.go
@@ -19,6 +19,7 @@
        OperationTypeName string                     `json:"operationTypeName" gorm:"type:varchar(127);not null;comment:作业类型名称"` //作业类型名称
        OperationId       int                        `json:"operationId" gorm:"type:int;not null;comment:操作id"`                  //操作id
        ProductId         string                     `json:"productId" gorm:"type:varchar(255);not null;comment:产品id"`           //产品id
        Product           Material                   `json:"-" gorm:"foreignKey:ProductId"`                                      //产品
        ProductName       string                     `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"`         //产品名称
        Amount            decimal.Decimal            `json:"amount" gorm:"type:decimal(20,2);not null;comment:数量"`               //数量
        Unit              string                     `json:"unit" gorm:"type:char(10);not null;comment:单位"`                      //单位
@@ -94,6 +95,10 @@
        db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
    }
    if slf.Preload {
        db = db.Model(&MoveHistory{}).Preload("Product")
    }
    return db
}
response/report_forms_response.go
@@ -31,6 +31,7 @@
    FromLocation      string                     `json:"fromLocation"`      //源位置
    ToLocation        string                     `json:"toLocation"`        //目标位置
    Amount            decimal.Decimal            `json:"amount"`            //数量
    AmountMoreUnits   []models.UnitItems         `json:"amountMoreUnits"`   //数量多单位
    Unit              string                     `json:"unit"`              //单位
    ContactedName     string                     `json:"contactedName"`     //完成者
    Status            string                     `json:"status"`            //状态
service/history_forms.go
@@ -19,6 +19,7 @@
func (slf *HistoryFormsService) Query(params request.GetInventoryHistory) (result []*response.InventoryHistory, err error) {
    search, err := slf.BuildSearch(params)
    search = search.SetPreload(true)
    if err != nil {
        return nil, err
    }
@@ -27,7 +28,33 @@
        search = search.SetPage(params.Page, params.PageSize)
    }
    result = make([]*response.InventoryHistory, 0, params.PageSize)
    err = search.FindAs(&result)
    list, err := search.FindNotTotal()
    for _, v := range list {
        data := &response.InventoryHistory{
            Number:            v.Number,
            Date:              v.UpdatedAt,
            ProductName:       v.ProductName,
            FromLocation:      v.FromLocation,
            ToLocation:        v.ToLocation,
            Amount:            v.Amount,
            AmountMoreUnits:   nil,
            Unit:              v.Unit,
            ContactedName:     v.Operator,
            BaseOperationType: v.BaseOperationType,
            Weight:            v.Weight,
            ProductId:         v.ProductId,
            FromLocationId:    v.FromLocationId,
            ToLocationId:      v.ToLocationId,
            OperationId:       v.OperationId,
            OperationTypeName: v.OperationTypeName,
        }
        moreUnit := v.Product.MoreUnit
        if moreUnit != nil && *moreUnit {
            data.AmountMoreUnits = CreateMoreUnit(v.Amount, v.Product.MoreUnitList)
        }
        result = append(result, data)
    }
    return result, nil
}
@@ -48,8 +75,8 @@
    }
    search.Orm = search.Orm.Model(&models.MoveHistory{}).
        Select("number, updated_at as date, product_name as product_name, from_location_id, operation_id,to_location_id, amount, " +
            "unit, operator as contacted_name, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc")
        Select("number, updated_at, product_name, from_location_id, operation_id,to_location_id, amount, " +
            "unit, operator, base_operation_type, weight, product_id, from_location, to_location, operation_type_name, weight").Order("id desc")
    if len(ids) > 0 {
        search.Orm = search.Orm.Where("id in ?", ids)
    }
@@ -96,16 +123,26 @@
    f := excelize.NewFile()
    // 自定义表头
    headers := []string{"日期", "单号", "产品", "产品编码", "业务类型", "从", "至", "数量", "单位", "重量"}
    headers := []interface{}{"日期", "单号", "产品", "产品编码", "业务类型", "从", "至", map[string][]string{"数量": {"件", "匹", "米", "重量"}}, "单位", "重量"}
    // 设置表头
    for i, header := range headers {
        cell := getColumnAlphabet(i) + "1"
        f.SetCellValue("Sheet1", cell, header)
    if err := SetExcelHeader(headers, f); err != nil {
        return "", err
    }
    style, err := SetHeaderStyle(f)
    if err != nil {
        return "", err
    }
    lastColumn := getColumnAlphabet(13)
    f.SetCellStyle("Sheet1", "A1", lastColumn+"2", style)
    // 设置列宽
    f.SetColWidth("Sheet1", "A", "G", 30)
    f.SetColWidth("Sheet1", "H", "K", 15)
    for i, v := range dataList {
        column := strconv.Itoa(i + 2)
        column := strconv.Itoa(i + 3)
        f.SetCellValue("Sheet1", "A"+column, v.Date.Format("2006-01-02"))
        f.SetCellValue("Sheet1", "B"+column, v.Number)
        f.SetCellValue("Sheet1", "C"+column, v.ProductName)
@@ -114,8 +151,9 @@
        f.SetCellValue("Sheet1", "F"+column, v.FromLocation)
        f.SetCellValue("Sheet1", "G"+column, v.ToLocation)
        f.SetCellValue("Sheet1", "H"+column, v.Amount)
        f.SetCellValue("Sheet1", "I"+column, v.Unit)
        f.SetCellValue("Sheet1", "J"+column, v.Weight)
        FillMoreUnitToExcel(v.Amount, v.AmountMoreUnits, 7, i+3, f)
        f.SetCellValue("Sheet1", "L"+column, v.Unit)
        f.SetCellValue("Sheet1", "M"+column, v.Weight)
    }
    if params.BaseOperationType == constvar.BaseOperationTypeIncoming {
service/more_units.go
@@ -1,6 +1,7 @@
package service
import (
    "errors"
    "github.com/shopspring/decimal"
    "github.com/xuri/excelize/v2"
    "strconv"
@@ -33,3 +34,54 @@
    }
    return
}
func SetExcelHeader(headers []interface{}, f *excelize.File) (err error) {
    // 设置表头
    var i int
    for _, h := range headers {
        if v, ok := h.(string); ok {
            err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", v)
            if err != nil {
                return
            }
            i++
        } else if childHeaders, ok := h.(map[string][]string); ok {
            for title, list := range childHeaders {
                err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"1", title)
                if err != nil {
                    return err
                }
                err = f.MergeCell("Sheet1", getColumnAlphabet(i)+"1", getColumnAlphabet(i-1+len(list))+"1") // 合并单元格
                for _, t := range list {
                    err = f.SetCellValue("Sheet1", getColumnAlphabet(i)+"2", t)
                    if err != nil {
                        return err
                    }
                    i++
                }
            }
        } else {
            return errors.New("unsupported header value")
        }
    }
    return nil
}
func SetHeaderStyle(f *excelize.File) (styleInt int, err error) {
    // 设置表头样式
    style := &excelize.Style{
        Border: nil,
        Fill: excelize.Fill{
            Type:    "pattern",
            Pattern: 1,
            Shading: 0,
        },
        Font: &excelize.Font{
            Bold: true,
        },
        Alignment: &excelize.Alignment{
            Horizontal: "center",
        },
    }
    return f.NewStyle(style)
}