zhangqian
2024-06-06 6b2c4936814854f658b501e87cdcca454937a786
下载出入库明细报表接口
1个文件已添加
7个文件已修改
832 ■■■■ 已修改文件
controllers/report_forms_controller.go 90 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 210 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 210 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 143 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/move_history.go 43 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
response/report_forms_response.go 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/history_forms.go 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/report_forms_controller.go
@@ -1,7 +1,6 @@
package controllers
import (
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/shopspring/decimal"
    "net/url"
@@ -12,7 +11,6 @@
    "wms/models"
    "wms/pkg/logx"
    "wms/request"
    "wms/response"
    "wms/service"
    "wms/task"
)
@@ -102,10 +100,11 @@
// GetHistory
// @Tags      报表
// @Summary   获取历史信息
// @Summary   获取出入库明细
// @Produce   application/json
// @Param     Authorization    header string true "token"
// @Param     object  body  request.GetInventoryHistory true  "查询参数"
// @Success   200 {object} util.ResponseList{data=[]response.InventoryHistory}    "成功"
// @Success   200 {object} util.ResponseList{data=[]models.MoveHistory}    "成功"
// @Router    /api-wms/v1/forms/getHistory [post]
func (slf ReportFormsController) GetHistory(c *gin.Context) {
    slf.GetHistoryNew(c)
@@ -195,53 +194,58 @@
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    //获取操作详情
    detailsSearch := models.NewMoveHistorySearch()
    var (
        result []*response.InventoryHistory
        total  uint64
        ids    []int
        err    error
    )
    if params.KeyWord != "" {
        ids, total, err = service.SearchHistoryReport(params.KeyWord, params.BaseOperationType, params.Page, params.PageSize)
        if err != nil {
            util.ResponseFormat(c, code.InternalError, err.Error())
            return
        }
        if len(ids) == 0 {
            util.ResponseFormatList(c, code.Success, result, 0)
            return
        }
    historyFormsService := service.NewHistoryFormsService()
    result, err := historyFormsService.Query(params)
    if err != nil {
        util.ResponseFormat(c, code.InternalError, "内部错误")
        return
    }
    detailsSearch.Orm = detailsSearch.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")
    if len(ids) > 0 {
        detailsSearch.Orm = detailsSearch.Orm.Where("id in ?", ids)
    }
    if params.BaseOperationType != 0 {
        detailsSearch.Orm = detailsSearch.Orm.Where("base_operation_type = ?", params.BaseOperationType)
    }
    var t int64
    err = detailsSearch.Orm.Count(&t).Error
    total, err := historyFormsService.Count(params)
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询总条数失败: %v", err))
        util.ResponseFormat(c, code.InternalError, "内部错误")
        return
    }
    total = uint64(t)
    if params.Page*params.PageSize > 0 {
        detailsSearch.Orm = detailsSearch.Orm.Offset((params.Page - 1) * params.PageSize).Limit(params.PageSize)
    }
    err = detailsSearch.Orm.Find(&result).Error
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, fmt.Errorf("查询操作明细失败: %v", err))
        return
    }
    util.ResponseFormatList(c, code.Success, result, int(total))
}
// DownloadHistory
// @Tags      报表
// @Summary   下载出入库明细报表
// @Produce   application/json
// @Param     Authorization    header string true "token"
// @Param     object  body  request.GetInventoryHistory true  "查询参数"
// @Success   200 {object} util.ResponseList{data=[]models.MoveHistory}    "成功"
// @Router    /api-wms/v1/forms/downloadHistory [post]
func (slf ReportFormsController) DownloadHistory(c *gin.Context) {
    var params request.GetInventoryHistory
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    historyFormsService := service.NewHistoryFormsService()
    list, err := historyFormsService.FetchAll(params)
    if err != nil {
        logx.Errorf("DownloadHistory FetchAll err:%v", err)
        util.ResponseFormat(c, code.InternalError, "查询失败")
        return
    }
    filename, err := historyFormsService.Export(list, params)
    if err != nil {
        logx.Errorf("DownloadHistory Export err:%v", err)
        util.ResponseFormat(c, code.InternalError, "导出数据到文件失败")
        return
    }
    fileContentDisposition := "attachment;filename=\"" + url.QueryEscape(filename) + "\""
    c.Header("Content-Type", "application/xlsx")
    c.Header("Content-Disposition", fileContentDisposition)
    c.File(filename)
    defer os.Remove(filename)
}
// GetLocationForms
// @Tags      报表
// @Summary   获取位置报表
docs/docs.go
@@ -468,6 +468,58 @@
                }
            }
        },
        "/api-wms/v1/forms/downloadHistory": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "报表"
                ],
                "summary": "下载出入库明细报表",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    },
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetInventoryHistory"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.MoveHistory"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/forms/downloadInventoryForms": {
            "post": {
                "produces": [
@@ -580,8 +632,15 @@
                "tags": [
                    "报表"
                ],
                "summary": "获取历史信息",
                "summary": "获取出入库明细",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    },
                    {
                        "description": "查询参数",
                        "name": "object",
@@ -606,7 +665,7 @@
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/response.InventoryHistory"
                                                "$ref": "#/definitions/models.MoveHistory"
                                            }
                                        }
                                    }
@@ -3940,6 +3999,84 @@
                }
            }
        },
        "models.MoveHistory": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "数量",
                    "type": "number"
                },
                "baseOperationType": {
                    "description": "基础作业类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.BaseOperationType"
                        }
                    ]
                },
                "createTime": {
                    "type": "string"
                },
                "fromLocation": {
                    "description": "源位置",
                    "type": "string"
                },
                "fromLocationId": {
                    "description": "源位置id",
                    "type": "integer"
                },
                "id": {
                    "type": "integer"
                },
                "number": {
                    "description": "单号",
                    "type": "string"
                },
                "operationId": {
                    "description": "操作id",
                    "type": "integer"
                },
                "operationTypeId": {
                    "description": "作业类型id",
                    "type": "integer"
                },
                "operationTypeName": {
                    "description": "作业类型名称",
                    "type": "string"
                },
                "operator": {
                    "description": "操作者",
                    "type": "string"
                },
                "productId": {
                    "description": "产品id",
                    "type": "string"
                },
                "productName": {
                    "description": "产品名称",
                    "type": "string"
                },
                "toLocation": {
                    "description": "目标位置",
                    "type": "string"
                },
                "toLocationId": {
                    "description": "目标位置id",
                    "type": "integer"
                },
                "unit": {
                    "description": "单位",
                    "type": "string"
                },
                "updateTime": {
                    "type": "string"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                }
            }
        },
        "models.Operation": {
            "type": "object",
            "properties": {
@@ -5519,75 +5656,6 @@
                },
                "value": {
                    "description": "总价值",
                    "type": "number"
                }
            }
        },
        "response.InventoryHistory": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "数量",
                    "type": "number"
                },
                "baseOperationType": {
                    "description": "基础作业类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.BaseOperationType"
                        }
                    ]
                },
                "contactedName": {
                    "description": "完成者",
                    "type": "string"
                },
                "date": {
                    "description": "日期",
                    "type": "string"
                },
                "fromLocation": {
                    "description": "源位置",
                    "type": "string"
                },
                "fromLocationId": {
                    "type": "integer"
                },
                "number": {
                    "description": "单号",
                    "type": "string"
                },
                "operationId": {
                    "type": "integer"
                },
                "operationTypeName": {
                    "description": "作业类型名称",
                    "type": "string"
                },
                "productId": {
                    "type": "string"
                },
                "productName": {
                    "description": "产品名称",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "type": "string"
                },
                "toLocation": {
                    "description": "目标位置",
                    "type": "string"
                },
                "toLocationId": {
                    "type": "integer"
                },
                "unit": {
                    "description": "单位",
                    "type": "string"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                }
            }
docs/swagger.json
@@ -456,6 +456,58 @@
                }
            }
        },
        "/api-wms/v1/forms/downloadHistory": {
            "post": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "报表"
                ],
                "summary": "下载出入库明细报表",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    },
                    {
                        "description": "查询参数",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.GetInventoryHistory"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.MoveHistory"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/forms/downloadInventoryForms": {
            "post": {
                "produces": [
@@ -568,8 +620,15 @@
                "tags": [
                    "报表"
                ],
                "summary": "获取历史信息",
                "summary": "获取出入库明细",
                "parameters": [
                    {
                        "type": "string",
                        "description": "token",
                        "name": "Authorization",
                        "in": "header",
                        "required": true
                    },
                    {
                        "description": "查询参数",
                        "name": "object",
@@ -594,7 +653,7 @@
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/response.InventoryHistory"
                                                "$ref": "#/definitions/models.MoveHistory"
                                            }
                                        }
                                    }
@@ -3928,6 +3987,84 @@
                }
            }
        },
        "models.MoveHistory": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "数量",
                    "type": "number"
                },
                "baseOperationType": {
                    "description": "基础作业类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.BaseOperationType"
                        }
                    ]
                },
                "createTime": {
                    "type": "string"
                },
                "fromLocation": {
                    "description": "源位置",
                    "type": "string"
                },
                "fromLocationId": {
                    "description": "源位置id",
                    "type": "integer"
                },
                "id": {
                    "type": "integer"
                },
                "number": {
                    "description": "单号",
                    "type": "string"
                },
                "operationId": {
                    "description": "操作id",
                    "type": "integer"
                },
                "operationTypeId": {
                    "description": "作业类型id",
                    "type": "integer"
                },
                "operationTypeName": {
                    "description": "作业类型名称",
                    "type": "string"
                },
                "operator": {
                    "description": "操作者",
                    "type": "string"
                },
                "productId": {
                    "description": "产品id",
                    "type": "string"
                },
                "productName": {
                    "description": "产品名称",
                    "type": "string"
                },
                "toLocation": {
                    "description": "目标位置",
                    "type": "string"
                },
                "toLocationId": {
                    "description": "目标位置id",
                    "type": "integer"
                },
                "unit": {
                    "description": "单位",
                    "type": "string"
                },
                "updateTime": {
                    "type": "string"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                }
            }
        },
        "models.Operation": {
            "type": "object",
            "properties": {
@@ -5507,75 +5644,6 @@
                },
                "value": {
                    "description": "总价值",
                    "type": "number"
                }
            }
        },
        "response.InventoryHistory": {
            "type": "object",
            "properties": {
                "amount": {
                    "description": "数量",
                    "type": "number"
                },
                "baseOperationType": {
                    "description": "基础作业类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.BaseOperationType"
                        }
                    ]
                },
                "contactedName": {
                    "description": "完成者",
                    "type": "string"
                },
                "date": {
                    "description": "日期",
                    "type": "string"
                },
                "fromLocation": {
                    "description": "源位置",
                    "type": "string"
                },
                "fromLocationId": {
                    "type": "integer"
                },
                "number": {
                    "description": "单号",
                    "type": "string"
                },
                "operationId": {
                    "type": "integer"
                },
                "operationTypeName": {
                    "description": "作业类型名称",
                    "type": "string"
                },
                "productId": {
                    "type": "string"
                },
                "productName": {
                    "description": "产品名称",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "type": "string"
                },
                "toLocation": {
                    "description": "目标位置",
                    "type": "string"
                },
                "toLocationId": {
                    "type": "integer"
                },
                "unit": {
                    "description": "单位",
                    "type": "string"
                },
                "weight": {
                    "description": "重量",
                    "type": "number"
                }
            }
docs/swagger.yaml
@@ -742,6 +742,61 @@
        description: 重量
        type: number
    type: object
  models.MoveHistory:
    properties:
      amount:
        description: 数量
        type: number
      baseOperationType:
        allOf:
        - $ref: '#/definitions/constvar.BaseOperationType'
        description: 基础作业类型
      createTime:
        type: string
      fromLocation:
        description: 源位置
        type: string
      fromLocationId:
        description: 源位置id
        type: integer
      id:
        type: integer
      number:
        description: 单号
        type: string
      operationId:
        description: 操作id
        type: integer
      operationTypeId:
        description: 作业类型id
        type: integer
      operationTypeName:
        description: 作业类型名称
        type: string
      operator:
        description: 操作者
        type: string
      productId:
        description: 产品id
        type: string
      productName:
        description: 产品名称
        type: string
      toLocation:
        description: 目标位置
        type: string
      toLocationId:
        description: 目标位置id
        type: integer
      unit:
        description: 单位
        type: string
      updateTime:
        type: string
      weight:
        description: 重量
        type: number
    type: object
  models.Operation:
    properties:
      accountant:
@@ -1831,54 +1886,6 @@
        description: 总价值
        type: number
    type: object
  response.InventoryHistory:
    properties:
      amount:
        description: 数量
        type: number
      baseOperationType:
        allOf:
        - $ref: '#/definitions/constvar.BaseOperationType'
        description: 基础作业类型
      contactedName:
        description: 完成者
        type: string
      date:
        description: 日期
        type: string
      fromLocation:
        description: 源位置
        type: string
      fromLocationId:
        type: integer
      number:
        description: 单号
        type: string
      operationId:
        type: integer
      operationTypeName:
        description: 作业类型名称
        type: string
      productId:
        type: string
      productName:
        description: 产品名称
        type: string
      status:
        description: 状态
        type: string
      toLocation:
        description: 目标位置
        type: string
      toLocationId:
        type: integer
      unit:
        description: 单位
        type: string
      weight:
        description: 重量
        type: number
    type: object
  response.LocationForms:
    properties:
      amount:
@@ -2220,6 +2227,37 @@
      summary: 手动跑月度统计库存报表
      tags:
      - 报表
  /api-wms/v1/forms/downloadHistory:
    post:
      parameters:
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      - description: 查询参数
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.GetInventoryHistory'
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.ResponseList'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/models.MoveHistory'
                  type: array
              type: object
      summary: 下载出入库明细报表
      tags:
      - 报表
  /api-wms/v1/forms/downloadInventoryForms:
    post:
      parameters:
@@ -2285,6 +2323,11 @@
  /api-wms/v1/forms/getHistory:
    post:
      parameters:
      - description: token
        in: header
        name: Authorization
        required: true
        type: string
      - description: 查询参数
        in: body
        name: object
@@ -2302,10 +2345,10 @@
            - properties:
                data:
                  items:
                    $ref: '#/definitions/response.InventoryHistory'
                    $ref: '#/definitions/models.MoveHistory'
                  type: array
              type: object
      summary: 获取历史信息
      summary: 获取出入库明细
      tags:
      - 报表
  /api-wms/v1/forms/getInventoryForms:
models/move_history.go
@@ -79,7 +79,7 @@
    return slf
}
func (slf *MoveHistorySearch) build() *gorm.DB {
func (slf *MoveHistorySearch) Build() *gorm.DB {
    var db = slf.Orm.Model(&MoveHistory{})
    if slf.ID != 0 {
@@ -99,7 +99,7 @@
// Create 单条插入
func (slf *MoveHistorySearch) Create(record *MoveHistory) error {
    var db = slf.build()
    var db = slf.Build()
    if err := db.Create(record).Error; err != nil {
        return err
@@ -110,7 +110,7 @@
// CreateBatch 批量插入
func (slf *MoveHistorySearch) CreateBatch(records []*MoveHistory) error {
    var db = slf.build()
    var db = slf.Build()
    if err := db.Create(&records).Error; err != nil {
        return fmt.Errorf("create batch err: %v, records: %+v", err, records)
@@ -120,7 +120,7 @@
}
func (slf *MoveHistorySearch) Update(record *MoveHistory) error {
    var db = slf.build()
    var db = slf.Build()
    if err := db.Omit("CreatedAt").Updates(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
@@ -131,7 +131,7 @@
func (slf *MoveHistorySearch) UpdateByMap(upMap map[string]interface{}) error {
    var (
        db = slf.build()
        db = slf.Build()
    )
    if err := db.Updates(upMap).Error; err != nil {
@@ -154,14 +154,14 @@
}
func (slf *MoveHistorySearch) Delete() error {
    var db = slf.build()
    var db = slf.Build()
    return db.Delete(&MoveHistory{}).Error
}
func (slf *MoveHistorySearch) First() (*MoveHistory, error) {
    var (
        record = new(MoveHistory)
        db     = slf.build()
        db     = slf.Build()
    )
    if err := db.First(record).Error; err != nil {
@@ -175,7 +175,7 @@
    var (
        records = make([]*MoveHistory, 0)
        total   int64
        db      = slf.build()
        db      = slf.Build()
    )
    if err := db.Count(&total).Error; err != nil {
@@ -191,10 +191,25 @@
    return records, total, nil
}
// FindAs 按指定形式
func (slf *MoveHistorySearch) FindAs(obj interface{}) (err error) {
    var (
        db = slf.Build()
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(obj).Error; err != nil {
        return fmt.Errorf("find records err: %v", err)
    }
    return nil
}
func (slf *MoveHistorySearch) FindNotTotal() ([]*MoveHistory, error) {
    var (
        records = make([]*MoveHistory, 0)
        db      = slf.build()
        db      = slf.Build()
    )
    if slf.PageNum*slf.PageSize > 0 {
@@ -244,3 +259,13 @@
    return records, nil
}
func (slf *MoveHistorySearch) Count() (int64, error) {
    var (
        total int64
        db    = slf.Build()
    )
    err := db.Count(&total).Error
    return total, err
}
response/report_forms_response.go
@@ -2,6 +2,7 @@
import (
    "github.com/shopspring/decimal"
    "time"
    "wms/constvar"
)
@@ -20,7 +21,7 @@
type InventoryHistory struct {
    Number            string                     `json:"number"`            //单号
    Date              string                     `json:"date"`              //日期
    Date              time.Time                  `json:"date"`              //日期
    ProductName       string                     `json:"productName"`       //产品名称
    FromLocation      string                     `json:"fromLocation"`      //源位置
    ToLocation        string                     `json:"toLocation"`        //目标位置
router/router.go
@@ -156,6 +156,7 @@
        reportFormsAPI.POST("getInventoryForms", reportFormsController.GetInventoryForms)           //获取库存报表
        reportFormsAPI.POST("downloadInventoryForms", reportFormsController.DownloadInventoryForms) //下载库存报表
        reportFormsAPI.POST("getHistory", reportFormsController.GetHistory)                         //获取库存历史
        reportFormsAPI.POST("downloadHistory", reportFormsController.DownloadHistory)               //下载库存报表
        reportFormsAPI.POST("getLocationForms", reportFormsController.GetLocationForms)             //获取位置报表
        reportFormsAPI.POST("downloadLocationForms", reportFormsController.DownloadLocationForms)   //下载位置报表
        reportFormsAPI.POST("monthStats", reportFormsController.MonthStats)                         //获取月度统计报表
service/history_forms.go
New file
@@ -0,0 +1,132 @@
package service
import (
    "fmt"
    "github.com/xuri/excelize/v2"
    "strconv"
    "time"
    "wms/constvar"
    "wms/models"
    "wms/request"
    "wms/response"
)
type HistoryFormsService struct{}
func NewHistoryFormsService() *HistoryFormsService {
    return &HistoryFormsService{}
}
func (slf *HistoryFormsService) Query(params request.GetInventoryHistory) (result []*response.InventoryHistory, err error) {
    search, err := slf.BuildSearch(params)
    if err != nil {
        return nil, err
    }
    if params.Page > 0 && params.PageSize > 0 {
        search = search.SetPage(params.Page, params.PageSize)
    }
    result = make([]*response.InventoryHistory, 0, params.PageSize)
    err = search.FindAs(&result)
    return result, nil
}
func (slf *HistoryFormsService) BuildSearch(params request.GetInventoryHistory) (search *models.MoveHistorySearch, err error) {
    search = models.NewMoveHistorySearch()
    var (
        ids []int
    )
    if params.KeyWord != "" {
        ids, _, err = SearchHistoryReport(params.KeyWord, params.BaseOperationType, params.Page, params.PageSize)
        if err != nil {
            return
        }
        if len(ids) == 0 {
            return nil, nil
        }
    }
    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")
    if len(ids) > 0 {
        search.Orm = search.Orm.Where("id in ?", ids)
    }
    if params.BaseOperationType != 0 {
        search.Orm = search.Orm.Where("base_operation_type = ?", params.BaseOperationType)
    }
    return search, err
}
func (slf *HistoryFormsService) Count(params request.GetInventoryHistory) (total int64, err error) {
    search, err := slf.BuildSearch(params)
    if err != nil {
        return 0, err
    }
    total, err = search.Count()
    return
}
func (slf *HistoryFormsService) FetchAll(params request.GetInventoryHistory) (list []*response.InventoryHistory, err error) {
    total, err := slf.Count(params)
    if err != nil {
        return nil, err
    }
    list = make([]*response.InventoryHistory, 0, total)
    params.PageSize = 500
    page := 1
    for {
        params.Page = page
        data, err := slf.Query(params)
        if err != nil {
            return nil, err
        }
        if len(data) == 0 {
            break
        }
        list = append(list, data...)
        page++
    }
    return
}
func (slf *HistoryFormsService) Export(dataList []*response.InventoryHistory, params request.GetInventoryHistory) (filename string, err error) {
    var fileName string
    f := excelize.NewFile()
    // 自定义表头
    headers := []string{"日期", "单号", "产品", "产品编码", "业务类型", "从", "至", "数量", "单位", "重量"}
    // 设置表头
    for i, header := range headers {
        cell := getColumnAlphabet(i+1) + "1"
        f.SetCellValue("Sheet1", cell, header)
    }
    for i, v := range dataList {
        column := strconv.Itoa(i + 2)
        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)
        f.SetCellValue("Sheet1", "D"+column, v.ProductId)
        f.SetCellValue("Sheet1", "E"+column, v.OperationTypeName)
        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)
    }
    if params.BaseOperationType == constvar.BaseOperationTypeIncoming {
        fileName = fmt.Sprintf("入库明细报表%s.xlsx", time.Now().Format("2006-01-02-1504"))
    } else if params.BaseOperationType == constvar.BaseOperationTypeOutgoing {
        fileName = fmt.Sprintf("出库明细报表%s.xlsx", time.Now().Format("2006-01-02-1504"))
    }
    if err := f.SaveAs(fileName); err != nil {
        return fileName, err
    }
    return fileName, nil
}