Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
| | |
| | | "errors" |
| | | "github.com/gin-gonic/gin" |
| | | "strconv" |
| | | "strings" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | } |
| | | params.JointName = first.JointName + "/" + params.Name |
| | | } else { |
| | | params.JointName = params.Name |
| | | params.JointName = strings.Split(params.JointName, "/")[0] + "/" + params.Name |
| | | } |
| | | err := models.NewLocationSearch().Update(¶ms) |
| | | if err != nil { |
| | |
| | | if params.PageInfo.Check() { |
| | | detailsSearch.SetPage(params.Page, params.PageSize) |
| | | } |
| | | details, total, err := detailsSearch.SetProductId(params.ProduceId).Find() |
| | | details, total, err := detailsSearch.SetPreload(true).SetProductId(params.ProduceId).Find() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询操作详情失败") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | | } |
| | | |
| | | //查询位置 |
| | | locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询位置失败") |
| | | return |
| | | } |
| | | ids := make([]int, 0) |
| | | for _, location := range locations { |
| | | ids = append(ids, location.Id) |
| | | if params.LocationId != 0 { |
| | | ids = append(ids, params.LocationId) |
| | | } else { |
| | | //查询位置 |
| | | locations, err := models.NewLocationSearch().SetJointName(params.WareHouseCode).FindAll() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "查询位置失败") |
| | | return |
| | | } |
| | | for _, location := range locations { |
| | | ids = append(ids, location.Id) |
| | | } |
| | | } |
| | | |
| | | amounts, total, err := models.NewLocationProductAmountSearch().SetPage(params.Page, params.PageSize).SetPreload(true).SetKeyword(params.KeyWord).SetProductId(params.ProductId).SetLocationIds(ids).FindByPage() |
| | |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "strings" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | //创建视图 |
| | | view := &models.Location{ |
| | | Name: params.Code, |
| | | JointName: params.Code, |
| | | Type: constvar.LocationTypeView, |
| | | } |
| | | id, err := models.NewLocationSearch().CreateReturnId(view) |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.SaveFail, "视图创建失败") |
| | | return |
| | | } |
| | | //创建默认位置 |
| | | location := &models.Location{ |
| | | Name: "默认位置", |
| | | JointName: params.Code, |
| | | JointName: params.Code + "/默认位置", |
| | | Type: constvar.LocationTypeInternal, |
| | | ReplenishLocation: true, |
| | | ParentId: id, |
| | | } |
| | | locationId, err := models.NewLocationSearch().CreateReturnId(location) |
| | | if err != nil { |
| | |
| | | } |
| | | //更新位置信息 |
| | | if oldRecord != nil && params.Code != oldRecord.Code { |
| | | m := make(map[string]interface{}) |
| | | m["joint_name"] = params.Code |
| | | err := models.NewLocationSearch().SetID(oldRecord.LocationId).UpdateByMap(m) |
| | | locations, err := models.NewLocationSearch().SetJointName(oldRecord.Code).FindNotTotal() |
| | | if err != nil { |
| | | return errors.New("查询位置信息失败") |
| | | } |
| | | |
| | | err = models.WithTransaction(func(db *gorm.DB) error { |
| | | for _, location := range locations { |
| | | m := make(map[string]interface{}) |
| | | index := strings.Index(location.JointName, "/") |
| | | if index > 0 { |
| | | m["joint_name"] = params.Code + location.JointName[index:] |
| | | } else { |
| | | m["joint_name"] = params.Code |
| | | } |
| | | err = models.NewLocationSearch().SetOrm(db).SetID(location.Id).UpdateByMap(m) |
| | | if err != nil { |
| | | return err |
| | | } |
| | | } |
| | | return nil |
| | | }) |
| | | if err != nil { |
| | | return errors.New("更新位置信息失败") |
| | | } |
| | |
| | | return |
| | | } |
| | | //获取位置信息 |
| | | codes := make([]string, 0) |
| | | ids := make([]int, 0) |
| | | for _, warehouse := range list { |
| | | codes = append(codes, warehouse.Code) |
| | | ids = append(ids, warehouse.LocationId) |
| | | } |
| | | locations, err := models.NewLocationSearch().SetJointNames(codes).FindNotTotal() |
| | | locations, err := models.NewLocationSearch().SetIds(ids).FindNotTotal() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "位置信息查找失败") |
| | | return |
| | |
| | | "keyWord": { |
| | | "type": "string" |
| | | }, |
| | | "locationId": { |
| | | "type": "integer" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | Description: "", |
| | | InfoInstanceName: "swagger", |
| | | SwaggerTemplate: docTemplate, |
| | | LeftDelim: "{{", |
| | | RightDelim: "}}", |
| | | } |
| | | |
| | | func init() { |
| | |
| | | "keyWord": { |
| | | "type": "string" |
| | | }, |
| | | "locationId": { |
| | | "type": "integer" |
| | | }, |
| | | "page": { |
| | | "description": "页码", |
| | | "type": "integer" |
| | |
| | | properties: |
| | | keyWord: |
| | | type: string |
| | | locationId: |
| | | type: integer |
| | | page: |
| | | description: 页码 |
| | | type: integer |
| | |
| | | Orm *gorm.DB |
| | | Preload bool |
| | | JointNames []string |
| | | Ids []int |
| | | } |
| | | ) |
| | | |
| | |
| | | |
| | | func (slf *LocationSearch) SetID(ID int) *LocationSearch { |
| | | slf.Id = ID |
| | | return slf |
| | | } |
| | | |
| | | func (slf *LocationSearch) SetIds(ids []int) *LocationSearch { |
| | | slf.Ids = ids |
| | | return slf |
| | | } |
| | | |
| | |
| | | db = db.Where("id = ?", slf.Id) |
| | | } |
| | | |
| | | if len(slf.Ids) > 0 { |
| | | db = db.Where("id in (?)", slf.Ids) |
| | | } |
| | | |
| | | if slf.Order != "" { |
| | | db = db.Order(slf.Order) |
| | | } |
| | |
| | | if slf.ProductId != "" { |
| | | db = db.Where("product_id = ?", slf.ProductId) |
| | | } |
| | | if slf.Preload { |
| | | db = db.Preload("Product") |
| | | } |
| | | |
| | | return db |
| | | } |
| | |
| | | if slf.PageNum*slf.PageSize > 0 { |
| | | db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize) |
| | | } |
| | | if err := db.Preload("Product").Find(&records).Error; err != nil { |
| | | if err := db.Find(&records).Error; err != nil { |
| | | return records, fmt.Errorf("find records err: %v", err) |
| | | } |
| | | |
| | |
| | | KeyWord string `json:"keyWord"` |
| | | WareHouseCode string `json:"wareHouseCode"` |
| | | ProductId string `json:"productId"` |
| | | LocationId int `json:"locationId"` |
| | | } |