zhangqian
2024-03-11 7d4f02f6a8066018911d09bad42c5c540abaa66b
Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS
1个文件已添加
5个文件已修改
371 ■■■■■ 已修改文件
controllers/product_controller.go 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 48 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/unit_dict.go 230 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/product_controller.go
@@ -761,3 +761,19 @@
    m["userName"] = userInfo.Username
    util.ResponseFormat(c, code.Success, m)
}
// GetUnitInfo
//
//    @Tags        产品
//    @Summary    获取单位信息
//    @Produce    application/json
//    @Success    200    {object}    util.ResponseList{data=[]models.UnitDict}    "成功"
//    @Router        /api-wms/v1/product/getUnitInfo [get]
func (slf ProductController) GetUnitInfo(c *gin.Context) {
    dicts, total, err := models.NewUnitDictSearch().Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查询出错")
        return
    }
    util.ResponseFormatList(c, code.Success, dicts, int(total))
}
docs/docs.go
@@ -1930,6 +1930,40 @@
                }
            }
        },
        "/api-wms/v1/product/getUnitInfo": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取单位信息",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.UnitDict"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getUserInfo": {
            "get": {
                "produces": [
@@ -3675,6 +3709,20 @@
                }
            }
        },
        "models.UnitDict": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "isDefault": {
                    "type": "boolean"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "models.Warehouse": {
            "type": "object",
            "required": [
docs/swagger.json
@@ -1918,6 +1918,40 @@
                }
            }
        },
        "/api-wms/v1/product/getUnitInfo": {
            "get": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "产品"
                ],
                "summary": "获取单位信息",
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.UnitDict"
                                            }
                                        }
                                    }
                                }
                            ]
                        }
                    }
                }
            }
        },
        "/api-wms/v1/product/getUserInfo": {
            "get": {
                "produces": [
@@ -3663,6 +3697,20 @@
                }
            }
        },
        "models.UnitDict": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "isDefault": {
                    "type": "boolean"
                },
                "name": {
                    "type": "string"
                }
            }
        },
        "models.Warehouse": {
            "type": "object",
            "required": [
docs/swagger.yaml
@@ -803,6 +803,15 @@
      updateTime:
        type: string
    type: object
  models.UnitDict:
    properties:
      id:
        type: integer
      isDefault:
        type: boolean
      name:
        type: string
    type: object
  models.Warehouse:
    properties:
      active:
@@ -2864,6 +2873,25 @@
      summary: 获取产品列表
      tags:
      - 产品
  /api-wms/v1/product/getUnitInfo:
    get:
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.ResponseList'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/models.UnitDict'
                  type: array
              type: object
      summary: 获取单位信息
      tags:
      - 产品
  /api-wms/v1/product/getUserInfo:
    get:
      produces:
models/unit_dict.go
New file
@@ -0,0 +1,230 @@
package models
import (
    "fmt"
    "gorm.io/gorm"
    "wms/pkg/mysqlx"
)
type (
    // UnitDict 计量单位字典
    UnitDict struct {
        BaseModelInt
        Name      string `gorm:"unique;type:varchar(191);not null;comment:名称" json:"name"`
        IsDefault bool   `gorm:"type:tinyint(1);comment:是否默认" json:"isDefault"`
        Sort      int    `gorm:"type:int(11);comment:排序" json:"-"`
    }
    UnitDictSearch struct {
        UnitDict
        Order    string
        PageNum  int
        PageSize int
        Orm      *gorm.DB
    }
)
func (slf UnitDict) TableName() string {
    return "unit_dict"
}
func NewUnitDictSearch() *UnitDictSearch {
    return &UnitDictSearch{Orm: mysqlx.GetDB()}
}
func (slf *UnitDictSearch) SetOrm(tx *gorm.DB) *UnitDictSearch {
    slf.Orm = tx
    return slf
}
func (slf *UnitDictSearch) SetPage(page, size int) *UnitDictSearch {
    slf.PageNum, slf.PageSize = page, size
    return slf
}
func (slf *UnitDictSearch) SetOrder(order string) *UnitDictSearch {
    slf.Order = order
    return slf
}
func (slf *UnitDictSearch) SetID(id uint) *UnitDictSearch {
    slf.ID = id
    return slf
}
func (slf *UnitDictSearch) SetName(name string) *UnitDictSearch {
    slf.Name = name
    return slf
}
func (slf *UnitDictSearch) build() *gorm.DB {
    var db = slf.Orm.Table(slf.TableName())
    if slf.ID > 0 {
        db = db.Where("id = ?", slf.ID)
    }
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    db.Where("1 = 1")
    if slf.Order != "" {
        db = db.Order(slf.Order)
    }
    return db
}
// Create 单条插入
func (slf *UnitDictSearch) Create(record *UnitDict) error {
    var db = slf.build()
    if err := db.Create(record).Error; err != nil {
        return fmt.Errorf("create err: %v, record: %+v", err, record)
    }
    return nil
}
// CreateBatch 批量插入
func (slf *UnitDictSearch) CreateBatch(records []*UnitDict) error {
    var db = slf.build()
    if err := db.Create(&records).Error; err != nil {
        return fmt.Errorf("create batch err: %v, records: %+v", err, records)
    }
    return nil
}
func (slf *UnitDictSearch) Save(record *UnitDict) error {
    var db = slf.build()
    if err := db.Omit("CreatedAt").Save(record).Error; err != nil {
        return fmt.Errorf("save err: %v, record: %+v", err, record)
    }
    return nil
}
func (slf *UnitDictSearch) UpdateByMap(upMap map[string]interface{}) error {
    var (
        db = slf.build()
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by map err: %v, upMap: %+v", err, upMap)
    }
    return nil
}
func (slf *UnitDictSearch) UpdateByQuery(query string, args []interface{}, upMap map[string]interface{}) error {
    var (
        db = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Updates(upMap).Error; err != nil {
        return fmt.Errorf("update by query err: %v, query: %s, args: %+v, upMap: %+v", err, query, args, upMap)
    }
    return nil
}
func (slf *UnitDictSearch) Delete() error {
    var db = slf.build()
    if err := db.Unscoped().Delete(&UnitDict{}).Error; err != nil {
        return err
    }
    return nil
}
func (slf *UnitDictSearch) First() (*UnitDict, error) {
    var (
        record = new(UnitDict)
        db     = slf.build()
    )
    if err := db.First(record).Error; err != nil {
        return record, err
    }
    return record, nil
}
func (slf *UnitDictSearch) Find() ([]*UnitDict, int64, error) {
    var (
        records = make([]*UnitDict, 0)
        total   int64
        db      = slf.build()
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find records err: %v", err)
    }
    return records, total, nil
}
func (slf *UnitDictSearch) FindNotTotal() ([]*UnitDict, error) {
    var (
        records = make([]*UnitDict, 0)
        db      = slf.build()
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find records err: %v", err)
    }
    return records, nil
}
// FindByQuery 指定条件查询.
func (slf *UnitDictSearch) FindByQuery(query string, args []interface{}) ([]*UnitDict, int64, error) {
    var (
        records = make([]*UnitDict, 0)
        total   int64
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if err := db.Count(&total).Error; err != nil {
        return records, total, fmt.Errorf("find by query count err: %v", err)
    }
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, total, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, total, nil
}
// FindByQueryNotTotal 指定条件查询&不查询总条数.
func (slf *UnitDictSearch) FindByQueryNotTotal(query string, args []interface{}) ([]*UnitDict, error) {
    var (
        records = make([]*UnitDict, 0)
        db      = slf.Orm.Table(slf.TableName()).Where(query, args...)
    )
    if slf.PageNum*slf.PageSize > 0 {
        db = db.Offset((slf.PageNum - 1) * slf.PageSize).Limit(slf.PageSize)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("find by query records err: %v, query: %s, args: %+v", err, query, args)
    }
    return records, nil
}
router/router.go
@@ -121,6 +121,7 @@
        productAPI.POST("listHistory", productController.ListHistory)      //产品位置历史记录
        productAPI.PUT("cancelDisuse/:id", productController.CancelDisuse) //取消报废
        productAPI.GET("getUserInfo", productController.GetUserInfo)       //获取登录用户信息
        productAPI.GET("getUnitInfo", productController.GetUnitInfo)       //获取单位信息
    }