muzexing
2024-07-06 c1389eedfaf1c044b48b94c7a8d9d9bb4cca1064
controllers/operation.go
@@ -9,7 +9,6 @@
   "github.com/shopspring/decimal"
   "github.com/xuri/excelize/v2"
   "gorm.io/gorm"
   "io/ioutil"
   "sort"
   "strconv"
   "strings"
@@ -95,7 +94,7 @@
      params.WarehouseId = operationType.WarehouseId
   }
   if params.InventoryDealerType == 0 {
   if params.DealerType == "" {
      CheckInventoryDealerType(&params)
   }
@@ -150,41 +149,35 @@
func CheckInventoryDealerType(params *models.Operation) {
   var dictType constvar.MiniDictType
   dictName := "其它"
   dictName := "其他"
   switch params.BaseOperationType {
   case constvar.BaseOperationTypeIncoming:
      dictType = constvar.StorageType
      //dictName = "其它入库"
      //dictName = dictName + "入库"
   case constvar.BaseOperationTypeOutgoing:
      dictType = constvar.StockoutType
      //dictName = "其它出库"
      //dictName = dictName + "出库"
   case constvar.BaseOperationTypeInternal:
      dictType = constvar.TransferType
      //dictName = "其它调拨"
      //dictName = dictName + "调拨"
   case constvar.BaseOperationTypeDisuse:
      dictType = constvar.DisuseType
      //dictName = "其它报废"
      //dictName = dictName + "报废"
   case constvar.BaseOperationTypeAdjust:
      dictType = constvar.TakeStockType
      //dictName = "其它盘点"
      //dictName = dictName + "盘点"
   default:
      return
   }
   miniDict, _ := models.NewMiniDictSearch().SetType(dictType).SetName(dictName).First()
   if miniDict != nil {
      params.InventoryDealerType = int(miniDict.ID)
   } else {
      dict := &models.MiniDict{
   miniDict, err := models.NewMiniDictSearch().SetType(dictType).SetName(dictName).First()
   if err == gorm.ErrRecordNotFound {
      miniDict = &models.MiniDict{
         Type: dictType,
         Name: dictName,
      }
      models.NewMiniDictSearch().Create(dict)
      miniDict, err := models.NewMiniDictSearch().SetType(dictType).SetName(dictName).First()
      if err != nil {
         return
      }
      params.InventoryDealerType = int(miniDict.ID)
      models.NewMiniDictSearch().Create(miniDict)
   }
   params.DealerType = miniDict.Name
}
func CheckDetailsRepeat(details []*models.OperationDetails) bool {
@@ -260,12 +253,8 @@
   if params.OperationTypeId == 0 && int(params.BaseOperationType) == 0 {
      return errors.New("未识别该记录类型1")
   }
   if params.BaseOperationType != 0 {
      if params.WarehouseId == 0 {
         return errors.New("未识别该记录类型2")
      }
   } else if params.OperationTypeId == 0 && params.BaseOperationType != 0 && params.WarehouseId == 0 {
      return errors.New("未识别该记录类型2")
   }
   if params.OperationDate == "" {
@@ -298,12 +287,11 @@
// GetOperationInfo
// @Tags      入库/出库
// @Summary   入库/出库列表
// @Summary   操作详情接口
// @Produce   application/json
//
//   @Param      id   path      string         true   "id"
//
// @Success   200 {object} util.Response   "成功"
// @Param     id path  string true "id"
// @Param     Authorization   header string true "token"
// @Success   200 {object} util.Response{data=models.Operation}   "成功"
// @Router    /api-wms/v1/operation/getOperationInfo/{id} [get]
func (slf OperationController) GetOperationInfo(c *gin.Context) {
   number := c.Param("id")
@@ -317,6 +305,26 @@
      util.ResponseFormat(c, code.RequestParamError, err.Error())
      return
   }
   if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || operation.BaseOperationType == constvar.BaseOperationTypeInternal { //查询实时在库库存
      productIds := make([]string, 0)
      locationIds := make([]int, 0)
      for _, v := range operation.Details {
         productIds = append(productIds, v.ProductId)
         locationIds = append(locationIds, v.FromLocationID)
      }
      locationAmountMap, err := service.GetLocationAmounts(productIds, locationIds)
      if err != nil {
         util.ResponseFormat(c, code.RequestParamError, "查询产品库存错误")
         return
      }
      for _, v := range operation.Details {
         if locationAmountMap[v.ProductId] != nil {
            v.StockAmount = locationAmountMap[v.ProductId][v.FromLocationID]
         }
      }
   }
   util.ResponseFormat(c, code.Success, operation)
}
@@ -363,7 +371,7 @@
      util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error())
      return
   }
   //userList, err := service.GetUserList()
   //userList, err := user.GetUserList()
   //userMap := make(map[string]string)
   //if err == nil {
   //   for _, user := range userList {
@@ -372,11 +380,11 @@
   //}
   userInfo := middleware.GetUserInfo(c)
   for _, v := range list {
      v.CreatedBy = userInfo.NickName
      //if err == nil {
      if userInfo != nil {
         //   v.CreatedBy = userMap[v.CreatedBy]
         //   v.CheckedBy = userMap[v.CheckedBy]
         v.CreatedBy = userInfo.NickName
         v.CheckedBy = userInfo.NickName
      }
      for _, v1 := range v.Details {
@@ -847,22 +855,19 @@
            return
         }
         if warehouse.FileTemplateCategoryIn == constvar.FileTemplateCategory_JialianInput1 {
            fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryIn, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
            }
         } else if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 {
         if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 {
            fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
            }
         } else {
            fileUrl, err = JialianOperation2(constvar.FileTemplateCategory_JialianInput1, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
            }
         }
      } else if companyName == "geruimi" {
         fileUrl, err = ExportInputSelfmade(constvar.FileTemplateCategory_Selfmade, operation)
         if err != nil {
@@ -887,15 +892,15 @@
            return
         }
         if warehouse.FileTemplateCategoryOut == constvar.FileTemplateCategory_JialianOutput1 {
            fileUrl, err = JialianOperation2(warehouse.FileTemplateCategoryOut, operation)
         if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 {
            fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
            }
         } else if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 {
            fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation)
         } else {
            fileUrl, err = JialianOperation2(constvar.FileTemplateCategory_JialianOutput1, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
@@ -935,8 +940,6 @@
   // 读取模板内容
   f, err := excelize.OpenReader(readerCloser)
   //fl, err := os.Open("E:\\家纺出入库单.xlsx")
   //f, err := excelize.OpenReader(fl)
   if err != nil {
      return "", errors.New("读取excel模版失败:" + err.Error())
   }
@@ -988,11 +991,13 @@
   totalAmount := decimal.NewFromInt(0) // 总金额
   totalPrice := decimal.NewFromInt(0)  // 总价
   rowIndex := 6
   str := ""
   for i, v := range operation.Details {
      //设置表单最多6条数据
      if i > 6 {
         break
      }
      str += v.Remark
      f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Name)                                                          // 产品名称
      f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Specs)                                                         //规格
      f.SetCellValue(sheet, "D"+strconv.Itoa(rowIndex), attributeValueMap[fmt.Sprintf("%d%s", attributeMap["颜色"], v.ProductId)]) //颜色
@@ -1052,7 +1057,8 @@
   }
   // 备注 第13行
   f.SetCellValue(sheet, "B13", "备注:"+operation.Remark)
   //f.SetCellValue(sheet, "B13", "备注:"+operation.Comment)
   f.SetCellValue(sheet, "B13", "备注:"+str)
   // 第14行
   f.SetCellValue(sheet, "C14", operation.Manager)    // 审核
   f.SetCellValue(sheet, "F14", operation.Accountant) // 保管
@@ -1063,9 +1069,7 @@
   }
   fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
   ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644)
   if err != nil {
      //ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644)
      logx.Errorf("file upload err: %v", err)
      return "", err
   }
@@ -1102,11 +1106,13 @@
   totalAmount := decimal.NewFromInt(0) // 总金额
   totalPrice := decimal.NewFromInt(0)  // 总价
   rowIndex := 5
   str := ""
   for i, v := range operation.Details {
      //设置表单最多9条数据
      if i > 9 {
         break
      }
      str += v.Remark
      f.SetCellValue(sheet, "A"+strconv.Itoa(rowIndex), v.Product.Name)    // 品名
      f.SetCellValue(sheet, "B"+strconv.Itoa(rowIndex), v.Product.Type)    // 型号
      f.SetCellValue(sheet, "C"+strconv.Itoa(rowIndex), v.Product.Unit)    // 单位
@@ -1170,7 +1176,8 @@
      }
   }
   f.SetCellValue(sheet, "Q5", operation.Remark) // 备注
   //f.SetCellValue(sheet, "Q5", operation.Comment) // 备注
   f.SetCellValue(sheet, "Q5", str) // 备注
   // 第14行
   f.SetCellValue(sheet, "B15", operation.Manager)    // 主管
@@ -1183,7 +1190,6 @@
   }
   fileUrl, err := upload.UploadFileToSeaWeed(string(constvar.FileType_File), uuid.NewV4().String()+".xlsx", buf.Bytes())
   ioutil.WriteFile("E:\\"+uuid.NewV4().String()+".xlsx", buf.Bytes(), 0644)
   if err != nil {
      logx.Errorf("file upload err: %v", err)
      return "", err
@@ -1267,7 +1273,6 @@
      logx.Errorf("file upload err: %v", err)
      return "", err
   }
   return fileUrl, nil
}