zhangqian
2024-06-13 2f856eaa7e46c884f1cb7ad721919a086d7f34a3
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 {