| | |
| | | "github.com/shopspring/decimal" |
| | | "github.com/xuri/excelize/v2" |
| | | "gorm.io/gorm" |
| | | "io/ioutil" |
| | | "sort" |
| | | "strconv" |
| | | "strings" |
| | |
| | | return |
| | | } |
| | | |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | if CheckDetailsRepeat(params.Details) { |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | if params.BaseOperationType != constvar.BaseOperationTypeAdjust { |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | |
| | | var operationType *models.OperationType |
| | | var err error |
| | | if params.OperationTypeId == 0 { |
| | | operationType, err := models.NewOperationTypeSearch(). |
| | | SetWarehouseId(params.WarehouseId).SetBaseOperationType(params.BaseOperationType). |
| | | First() |
| | | if err != nil || params.WarehouseId != operationType.WarehouseId { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数缺失") |
| | | return |
| | | } |
| | | } else { |
| | | operationType, err = models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } |
| | | params.BaseOperationType = operationType.BaseOperationType |
| | | params.WarehouseId = operationType.WarehouseId |
| | | } |
| | | |
| | | if params.InventoryDealerType == 0 { |
| | | CheckInventoryDealerType(¶ms) |
| | | } |
| | | |
| | | userInfo := middleware.GetUserInfo(c) |
| | | if userInfo == nil { |
| | | util.ResponseFormat(c, code.SetStatusError, "登录用户信息为空,请登录后重试!") |
| | | return |
| | | } |
| | | userInfo := middleware.GetUserInfo(c) |
| | | params.CreatedBy = userInfo.Username |
| | | params.Status = constvar.OperationStatus_Ready |
| | | //params.Number = strconv.FormatInt(time.Now().Unix(), 10) |
| | | params.BaseOperationType = operationType.BaseOperationType |
| | | |
| | | for _, detail := range params.Details { |
| | | detail.BaseOperationType = params.BaseOperationType |
| | | } |
| | | |
| | | var numberNum int64 |
| | | if err := mysqlx.GetDB().Model(&models.Operation{}).Where("number=?", params.Number).Count(&numberNum).Error; err != nil { |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "单号已存在") |
| | | return |
| | | } |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | err := models.WithTransaction(func(db *gorm.DB) error { |
| | | if err := models.NewOperationSearch().Create(¶ms); err != nil { |
| | | return err |
| | | } |
| | |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | } |
| | | |
| | | func CheckInventoryDealerType(params *models.Operation) { |
| | | var dictType constvar.MiniDictType |
| | | dictName := "其它" |
| | | switch params.BaseOperationType { |
| | | case constvar.BaseOperationTypeIncoming: |
| | | dictType = constvar.StorageType |
| | | //dictName = "其它入库" |
| | | case constvar.BaseOperationTypeOutgoing: |
| | | dictType = constvar.StockoutType |
| | | //dictName = "其它出库" |
| | | case constvar.BaseOperationTypeInternal: |
| | | dictType = constvar.TransferType |
| | | //dictName = "其它调拨" |
| | | case constvar.BaseOperationTypeDisuse: |
| | | dictType = constvar.DisuseType |
| | | //dictName = "其它报废" |
| | | case constvar.BaseOperationTypeAdjust: |
| | | dictType = constvar.TakeStockType |
| | | //dictName = "其它盘点" |
| | | default: |
| | | return |
| | | } |
| | | miniDict, _ := models.NewMiniDictSearch().SetType(dictType).SetName(dictName).First() |
| | | if miniDict != nil { |
| | | params.InventoryDealerType = int(miniDict.ID) |
| | | } else { |
| | | dict := &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) |
| | | } |
| | | } |
| | | |
| | | func CheckDetailsRepeat(details []*models.OperationDetails) bool { |
| | | var detailIDs []string |
| | | var tempID string |
| | |
| | | return false |
| | | } |
| | | |
| | | // FormatLocation 位置检查 |
| | | func (slf OperationController) FormatLocation(params *models.Operation) error { |
| | | operationType, err := models.NewOperationTypeSearch().SetID(uint(params.OperationTypeId)).First() |
| | | if err != nil { |
| | |
| | | } |
| | | |
| | | if params.OperationTypeId == 0 && int(params.BaseOperationType) == 0 { |
| | | return errors.New("未识别该记录类型") |
| | | return errors.New("未识别该记录类型1") |
| | | } else if params.OperationTypeId == 0 && params.BaseOperationType != 0 && params.WarehouseId == 0 { |
| | | return errors.New("未识别该记录类型2") |
| | | } |
| | | |
| | | if params.OperationDate == "" { |
| | | return errors.New("请选择安排日期") |
| | | } |
| | | |
| | | if params.LocationID == 0 { |
| | | return errors.New("请选择源位置") |
| | | } |
| | | //if params.LocationID == 0 { |
| | | // return errors.New("请选择源位置") |
| | | //} |
| | | |
| | | if len(params.Details) <= 0 { |
| | | return errors.New("请添加明细信息") |
| | |
| | | // @Summary 入库/出库列表 |
| | | // @Produce application/json |
| | | // @Param object body request.OperationList true "查询参数" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.Operation} "成功" |
| | | // @Router /api-wms/v1/operation/list [post] |
| | | func (slf OperationController) List(c *gin.Context) { |
| | | var params request.OperationList |
| | |
| | | costMap[material.ID] = material.Cost |
| | | salePriceMap[material.ID] = material.SalePrice |
| | | } |
| | | list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find() |
| | | list, total, err := search.SetOperationTypeId(params.OperationTypeId). |
| | | SetBaseOperationType(params.BaseOperationType). |
| | | SetPreload(true).SetOrder("created_at desc").Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error()) |
| | | return |
| | | } |
| | | //userList, err := service.GetUserList() |
| | | //userMap := make(map[string]string) |
| | | //if err == nil { |
| | | // for _, user := range userList { |
| | | // userMap[user.UserName] = user.NickName |
| | | // } |
| | | //} |
| | | userInfo := middleware.GetUserInfo(c) |
| | | for _, v := range list { |
| | | //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 { |
| | | //v1.SalePrice = decimal.NewFromFloat(1.2345) |
| | | //v1.Cost = decimal.NewFromFloat(9.678) |
| | |
| | | if !params.PageInfo.Check() { |
| | | return errors.New("数据分页信息错误") |
| | | } |
| | | if params.OperationTypeId == 0 { |
| | | return errors.New("operationTypeId为0") |
| | | if params.OperationTypeId == 0 && params.BaseOperationType == 0 { |
| | | return errors.New("operationTypeId和baseOperationType不能同时为0") |
| | | } |
| | | return nil |
| | | } |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "明细中不能存在重复的产品") |
| | | return |
| | | } |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | |
| | | if params.BaseOperationType != constvar.BaseOperationTypeAdjust { |
| | | if err := slf.FormatLocation(¶ms); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | } |
| | | if err := models.WithTransaction(func(tx *gorm.DB) error { |
| | | if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(params.Id).Delete(); err != nil { |
| | |
| | | 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(warehouse.FileTemplateCategoryIn, 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 { |
| | |
| | | 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(warehouse.FileTemplateCategoryOut, operation) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | |
| | | |
| | | // 读取模板内容 |
| | | 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()) |
| | | } |
| | |
| | | } |
| | | |
| | | 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 |
| | | } |
| | |
| | | } |
| | | |
| | | 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 |
| | |
| | | logx.Errorf("file upload err: %v", err) |
| | | return "", err |
| | | } |
| | | |
| | | return fileUrl, nil |
| | | } |
| | | |
| | |
| | | // @Tags 入库/出库 |
| | | // @Summary 获取人员列表 |
| | | // @Produce application/json |
| | | // @Param object body request.OperationCondition true "参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]inventory_order.WorkerInfo} "成功" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/operation/getPersonnelList [get] |
| | | func (slf OperationController) GetPersonnelList(c *gin.Context) { |
| | | cli := inventory_order.NewInventoryOrderServiceClient(init_client.ApsConn) |