zhangqian
2024-07-31 155f70979af20ca520a55b89c6ec8cd46c43f8a5
controllers/operation.go
@@ -9,7 +9,6 @@
   "github.com/shopspring/decimal"
   "github.com/xuri/excelize/v2"
   "gorm.io/gorm"
   "sort"
   "strconv"
   "strings"
   "time"
@@ -42,6 +41,7 @@
// @Tags      入库/出库
// @Summary   添加入库/出库
// @Produce   application/json
// @Param     Authorization   header string true "token"
// @Param     object  body  request.AddOperation true  "入库/出库信息"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/operation/operation [post]
@@ -147,6 +147,7 @@
   util.ResponseFormat(c, code.Success, "添加成功")
}
// CheckInventoryDealerType 检查基础类型,防止类型为空添加其它类型
func CheckInventoryDealerType(params *models.Operation) {
   var dictType constvar.MiniDictType
   dictName := "其他"
@@ -180,19 +181,19 @@
   params.DealerType = miniDict.Name
}
// CheckDetailsRepeat 出库、入库、盘点涉及产品重复性检查(以产品编号、出库库房编号、入库库房编号)
// 存在重复值 true; 不存在返回 false
func CheckDetailsRepeat(details []*models.OperationDetails) bool {
   var detailIDs []string
   var tempID string
   for _, v := range details {
      detailIDs = append(detailIDs, v.ProductId)
   if len(details) == 0 {
      return false
   }
   sort.Strings(detailIDs)
   for _, v := range detailIDs {
      if v != tempID {
         tempID = v
      } else {
         return true
      }
   var detailKeyMap = make(map[string]bool)
   for _, v := range details {
      key := fmt.Sprintf("%v%v%v", v.ProductId, v.FromLocationID, v.ToLocationID)
      detailKeyMap[key] = true
   }
   if len(detailKeyMap) != len(details) { // 长度相同,不存在重复值;长度不同存在存在不同
      return true
   }
   return false
}
@@ -332,6 +333,7 @@
// @Tags      入库/出库
// @Summary   入库/出库列表
// @Produce   application/json
// @Param     Authorization   header string true "token"
// @Param       object  body  request.OperationList true  "查询参数"
// @Success   200   {object}   util.ResponseList{data=[]models.Operation}   "成功"
// @Router    /api-wms/v1/operation/list [post]
@@ -379,6 +381,10 @@
   //   }
   //}
   userInfo := middleware.GetUserInfo(c)
   if userInfo == nil {
      util.ResponseFormat(c, code.SetStatusError, "登录用户信息为空,请登录后重试!")
      return
   }
   for _, v := range list {
      v.CreatedBy = userInfo.NickName
      //if err == nil {
@@ -482,6 +488,7 @@
//   @Tags      入库/出库
//   @Summary   删除入库/出库信息
//   @Produce   application/json
//   @Param     Authorization   header string true "token"
//   @Param      id   path      int         true   "id"
//   @Success   200   {object}   util.Response   "成功"
//   @Router      /api-wms/v1/operation/operation/{id} [delete]
@@ -529,9 +536,10 @@
//   @Tags      入库/出库
//   @Summary   更改记录状态
//   @Produce   application/json
//   @Param      id   path      int         true   "id"
//   @Param   Authorization   header   string   true   "token"
//   @Param   id   path   int   true   "id"
//   @Success   200   {object}   util.Response   "成功"
//   @Router      /api-wms/v1/operation/finish/{id} [put]
//   @Router   /api-wms/v1/operation/finish/{id} [put]
func (slf OperationController) Finish(c *gin.Context) {
   id, err := strconv.Atoi(c.Param("id"))
   if err != nil {
@@ -582,25 +590,26 @@
         return err
      }
      if operation.BaseOperationType == constvar.BaseOperationTypeIncoming {
      if operation.BaseOperationType == constvar.BaseOperationTypeIncoming { // 入库
         if err := service.FinishOperationInput(c, tx, operation, listDetails, mapLocAmount); err != nil {
            return err
         }
      }
      if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || operation.BaseOperationType == constvar.BaseOperationTypeDisuse {
      if operation.BaseOperationType == constvar.BaseOperationTypeOutgoing || // 出库
         operation.BaseOperationType == constvar.BaseOperationTypeDisuse { // 报废
         if err := service.FinishOperationOutput(tx, listDetails, mapLocAmount, operation); err != nil {
            return err
         }
      }
      if operation.BaseOperationType == constvar.BaseOperationTypeInternal {
      if operation.BaseOperationType == constvar.BaseOperationTypeInternal { // 内部调拨
         if err := service.FinishOperationInternal(tx, listDetails, operation); err != nil {
            return err
         }
      }
      if operation.BaseOperationType == constvar.BaseOperationTypeAdjust {
      if operation.BaseOperationType == constvar.BaseOperationTypeAdjust { // 库存盘点
         if err := service.FinishOperationAdjust(tx, listDetails, mapLocAmount, operation); err != nil {
            return err
         }
@@ -623,7 +632,6 @@
         go UpdateOutStatus(operation.Source, operation.SourceNumber, 4)
      }
   }
   util.ResponseFormat(c, code.Success, "操作成功")
}
@@ -856,7 +864,7 @@
         }
         if warehouse.FileTemplateCategoryIn == constvar.FileWarehouseCategory_JialianInput2 {
            fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryIn, operation)
            fileUrl, err = JialianOperation1(constvar.FileWarehouseCategory_JialianInput2, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
@@ -893,7 +901,7 @@
         }
         if warehouse.FileTemplateCategoryOut == constvar.FileWarehouseCategory_JialianOutput2 {
            fileUrl, err = JialianOperation1(warehouse.FileTemplateCategoryOut, operation)
            fileUrl, err = JialianOperation1(constvar.FileWarehouseCategory_JialianOutput2, operation)
            if err != nil {
               util.ResponseFormat(c, code.RequestParamError, err.Error())
               return
@@ -991,11 +999,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)]) //颜色
@@ -1055,7 +1065,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) // 保管
@@ -1103,11 +1114,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)    // 单位
@@ -1171,7 +1184,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)    // 主管