| | |
| | | } |
| | | ] |
| | | }, |
| | | "checkedAt": { |
| | | "type": "string" |
| | | }, |
| | | "checkedBy": { |
| | | "type": "string" |
| | | }, |
| | | "comment": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "integer" |
| | | }, |
| | | "contacterName": { |
| | | "type": "string" |
| | | }, |
| | | "createBy": { |
| | | "type": "string" |
| | | }, |
| | | "createTime": { |
| | |
| | | "description": "数量", |
| | | "type": "number" |
| | | }, |
| | | "amountMoreUnits": { |
| | | "description": "在库数量多单位", |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.UnitItems" |
| | | } |
| | | }, |
| | | "locationId": { |
| | | "description": "位置id", |
| | | "type": "integer" |
| | |
| | | } |
| | | ] |
| | | }, |
| | | "checkedAt": { |
| | | "type": "string" |
| | | }, |
| | | "checkedBy": { |
| | | "type": "string" |
| | | }, |
| | | "comment": { |
| | | "type": "string" |
| | | }, |
| | |
| | | "type": "integer" |
| | | }, |
| | | "contacterName": { |
| | | "type": "string" |
| | | }, |
| | | "createBy": { |
| | | "type": "string" |
| | | }, |
| | | "createTime": { |
| | |
| | | "description": "数量", |
| | | "type": "number" |
| | | }, |
| | | "amountMoreUnits": { |
| | | "description": "在库数量多单位", |
| | | "type": "array", |
| | | "items": { |
| | | "$ref": "#/definitions/models.UnitItems" |
| | | } |
| | | }, |
| | | "locationId": { |
| | | "description": "位置id", |
| | | "type": "integer" |
| | |
| | | allOf: |
| | | - $ref: '#/definitions/constvar.BaseOperationType' |
| | | description: 基础作业类型 |
| | | checkedAt: |
| | | type: string |
| | | checkedBy: |
| | | type: string |
| | | comment: |
| | | type: string |
| | | companyID: |
| | |
| | | contacterID: |
| | | type: integer |
| | | contacterName: |
| | | type: string |
| | | createBy: |
| | | type: string |
| | | createTime: |
| | | type: string |
| | |
| | | amount: |
| | | description: 数量 |
| | | type: number |
| | | amountMoreUnits: |
| | | description: 在库数量多单位 |
| | | items: |
| | | $ref: '#/definitions/models.UnitItems' |
| | | type: array |
| | | locationId: |
| | | description: 位置id |
| | | type: integer |
| | |
| | | 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:单位"` //单位 |
| | |
| | | db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword)) |
| | | } |
| | | |
| | | if slf.Preload { |
| | | db = db.Model(&MoveHistory{}).Preload("Product") |
| | | } |
| | | |
| | | return db |
| | | } |
| | | |
| | |
| | | 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"` //状态 |
| | |
| | | |
| | | 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 |
| | | } |
| | |
| | | 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 |
| | | } |
| | |
| | | } |
| | | |
| | | 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) |
| | | } |
| | |
| | | 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) |
| | |
| | | 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 { |
| | |
| | | package service |
| | | |
| | | import ( |
| | | "errors" |
| | | "github.com/shopspring/decimal" |
| | | "github.com/xuri/excelize/v2" |
| | | "strconv" |
| | |
| | | } |
| | | 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) |
| | | } |