liujiandao
2023-09-20 2baa7bad0482613829e217997c44a51d8ec0ec66
Merge branch 'master' of http://192.168.5.5:10010/r/aps/WMS

# Conflicts:
# models/db.go
2个文件已添加
10个文件已修改
871 ■■■■■ 已修改文件
controllers/location.go 53 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/operation.go 128 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 201 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 201 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 132 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extend/code/code.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/location.go 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation.go 47 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation_details.go 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/location.go 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
request/operation.go 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/location.go
New file
@@ -0,0 +1,53 @@
package controllers
import (
    "errors"
    "github.com/gin-gonic/gin"
    "wms/extend/code"
    "wms/extend/util"
    "wms/models"
    "wms/request"
)
type LocationController struct {
}
func (slf LocationController) ListLocationByType(c *gin.Context) {
    var params request.LocationByType
    if err := c.BindJSON(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数绑定失败")
        return
    }
    if err := slf.CheckLocationByTypeParams(params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
    }
    search := models.NewLocationSearch()
    search.SetType(params.Type)
    if params.Keyword != "" {
        search.SetKeyword(params.Keyword)
    }
    if params.ParentId != 0 {
        search.SetParentId(params.ParentId)
    }
    if params.CompanyId != 0 {
        search.SetCompanyId(params.CompanyId)
    }
    res, err := search.SetOrder("created_at desc").FindAll()
    if err != nil {
        util.ResponseFormat(c, code.RequestError, err.Error())
    }
    util.ResponseFormat(c, code.Success, res)
}
func (slf LocationController) CheckLocationByTypeParams(params request.LocationByType) error {
    if params.Type == 0 {
        return errors.New("请选择正确的位置类型")
    }
    if params.ParentId < 0 {
        return errors.New("错误参数ParentId")
    }
    if params.CompanyId < 0 {
        return errors.New("错误参数CompanyId")
    }
    return nil
}
controllers/operation.go
@@ -2,8 +2,10 @@
import (
    "errors"
    "fmt"
    "github.com/gin-gonic/gin"
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "strconv"
    "wms/extend/code"
    "wms/extend/util"
    "wms/models"
@@ -26,11 +28,11 @@
    var reqParams request.AddOperation
    var params models.Operation
    if err := c.BindJSON(&reqParams); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误"+err.Error())
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误")
        return
    }
    if err := structx.AssignTo(reqParams, params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换错误")
    if err := structx.AssignTo(reqParams, &params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换错误"+err.Error())
        return
    }
    if err := slf.CheckParams(params); err != nil {
@@ -85,7 +87,123 @@
            return errors.New("产品数量出错")
        }
    }
    fmt.Println(111111)
    return nil
}
// List
// @Tags      入库/出库
// @Summary   入库/出库列表
// @Produce   application/json
// @Accept      json
// @Param     object  query  request.OperationList true  "参数"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/operation/operation [get]
func (slf OperationController) List(c *gin.Context) {
    var params request.OperationList
    if err := c.ShouldBindQuery(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error())
        return
    }
    if err := slf.CheckListParams(&params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, err.Error())
        return
    }
    search := models.NewOperationSearch()
    search.SetPage(params.Page, params.PageSize)
    list, total, err := search.SetOperationTypeId(params.OperationTypeId).SetPreload(true).SetOrder("created_at desc").Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestError, "查找失败:"+err.Error())
        return
    }
    util.ResponseFormatList(c, code.Success, list, int(total))
}
func (slf OperationController) CheckListParams(params *request.OperationList) error {
    if !params.PageInfo.Check() {
        return errors.New("数据分页信息错误")
    }
    if params.OperationTypeId == 0 {
        return errors.New("operationTypeId为0")
    }
    return nil
}
// Update
// @Tags      入库/出库
// @Summary   修改入库/出库信息
// @Produce   application/json
// @Param     object  body request.UpdateOperation true  "入库信息"
// @Param     id  path int true  "入库信息id"
// @Success   200 {object} util.Response "成功"
// @Router    /api-wms/v1/operation/operation/{id} [put]
func (slf OperationController) Update(c *gin.Context) {
    id := cast.ToUint(c.Param("id"))
    if id == 0 {
        util.ResponseFormat(c, code.RequestParamError, "空的记录id")
        return
    }
    var reqParams request.UpdateOperation
    var params models.Operation
    if err := c.BindJSON(&reqParams); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误:"+err.Error())
        return
    }
    if err := structx.AssignTo(reqParams, &params); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "数据转换错误"+err.Error())
        return
    }
    if err := slf.CheckParams(params); 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 err
        }
        if err := models.NewOperationSearch().SetOrm(tx).SetID(params.Id).Save(&params); err != nil {
            return err
        }
        return nil
    }); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "修改失败:"+err.Error())
        return
    }
    util.ResponseFormat(c, code.Success, "修改成功")
}
// DeleteDevice
//
//    @Tags        入库/出库
//    @Summary    删除入库/出库信息
//    @Produce    application/json
//    @Param        id    path        int            true    "id"
//    @Success    200    {object}    util.Response    "成功"
//    @Router        /api-wms/v1/operation/operation/{id} [delete]
func (slf OperationController) Delete(c *gin.Context) {
    id, err := strconv.Atoi(c.Param("id"))
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "错误的id值")
        return
    }
    if id == 0 {
        util.ResponseFormat(c, code.RequestParamError, "空的记录id")
        return
    }
    if err := models.WithTransaction(func(tx *gorm.DB) error {
        if err := models.NewOperationDetailsSearch().SetOrm(tx).SetOperationId(id).Delete(); err != nil {
            return err
        }
        if err := models.NewOperationSearch().SetOrm(tx).SetID(id).Delete(); err != nil {
            return err
        }
        return nil
    }); err != nil {
        util.ResponseFormat(c, code.RequestParamError, "修改失败:"+err.Error())
        return
    }
    util.ResponseFormat(c, code.Success, "删除成功")
}
docs/docs.go
@@ -295,6 +295,45 @@
            }
        },
        "/api-wms/v1/operation/operation": {
            "get": {
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "入库/出库"
                ],
                "summary": "入库/出库列表",
                "parameters": [
                    {
                        "type": "integer",
                        "name": "operationTypeId",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            },
            "post": {
                "produces": [
                    "application/json"
@@ -312,6 +351,69 @@
                        "schema": {
                            "$ref": "#/definitions/request.AddOperation"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/operation/operation/{id}": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "入库/出库"
                ],
                "summary": "修改入库/出库信息",
                "parameters": [
                    {
                        "description": "入库信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateOperation"
                        }
                    },
                    {
                        "type": "integer",
                        "description": "入库信息id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            },
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "入库/出库"
                ],
                "summary": "删除入库/出库信息",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
@@ -1687,6 +1789,24 @@
        "request.AddOperation": {
            "type": "object",
            "properties": {
                "carrierID": {
                    "type": "integer"
                },
                "carrierName": {
                    "type": "string"
                },
                "companyID": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "contacterID": {
                    "type": "integer"
                },
                "contacterName": {
                    "type": "string"
                },
                "details": {
                    "type": "array",
                    "items": {
@@ -1726,6 +1846,15 @@
                "toLocationId": {
                    "description": "目标位置id",
                    "type": "integer"
                },
                "tracking": {
                    "type": "string"
                },
                "transferWeight": {
                    "type": "number"
                },
                "weight": {
                    "type": "number"
                }
            }
        },
@@ -1911,6 +2040,78 @@
                }
            }
        },
        "request.UpdateOperation": {
            "type": "object",
            "properties": {
                "carrierID": {
                    "type": "integer"
                },
                "carrierName": {
                    "type": "string"
                },
                "companyID": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "contacterID": {
                    "type": "integer"
                },
                "contacterName": {
                    "type": "string"
                },
                "details": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.OperationDetails"
                    }
                },
                "fromLocationId": {
                    "description": "源位置id",
                    "type": "integer"
                },
                "id": {
                    "type": "integer"
                },
                "number": {
                    "description": "单号",
                    "type": "string"
                },
                "operationDate": {
                    "type": "string"
                },
                "operationTypeId": {
                    "description": "作业类型id",
                    "type": "integer"
                },
                "sourceNumber": {
                    "description": "源单号",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.OperationStatus"
                        }
                    ]
                },
                "toLocationId": {
                    "description": "目标位置id",
                    "type": "integer"
                },
                "tracking": {
                    "type": "string"
                },
                "transferWeight": {
                    "type": "number"
                },
                "weight": {
                    "type": "number"
                }
            }
        },
        "request.UpdateOperationType": {
            "type": "object",
            "properties": {
docs/swagger.json
@@ -283,6 +283,45 @@
            }
        },
        "/api-wms/v1/operation/operation": {
            "get": {
                "consumes": [
                    "application/json"
                ],
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "入库/出库"
                ],
                "summary": "入库/出库列表",
                "parameters": [
                    {
                        "type": "integer",
                        "name": "operationTypeId",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "页码",
                        "name": "page",
                        "in": "query"
                    },
                    {
                        "type": "integer",
                        "description": "每页大小",
                        "name": "pageSize",
                        "in": "query"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            },
            "post": {
                "produces": [
                    "application/json"
@@ -300,6 +339,69 @@
                        "schema": {
                            "$ref": "#/definitions/request.AddOperation"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            }
        },
        "/api-wms/v1/operation/operation/{id}": {
            "put": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "入库/出库"
                ],
                "summary": "修改入库/出库信息",
                "parameters": [
                    {
                        "description": "入库信息",
                        "name": "object",
                        "in": "body",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/request.UpdateOperation"
                        }
                    },
                    {
                        "type": "integer",
                        "description": "入库信息id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "成功",
                        "schema": {
                            "$ref": "#/definitions/util.Response"
                        }
                    }
                }
            },
            "delete": {
                "produces": [
                    "application/json"
                ],
                "tags": [
                    "入库/出库"
                ],
                "summary": "删除入库/出库信息",
                "parameters": [
                    {
                        "type": "integer",
                        "description": "id",
                        "name": "id",
                        "in": "path",
                        "required": true
                    }
                ],
                "responses": {
@@ -1675,6 +1777,24 @@
        "request.AddOperation": {
            "type": "object",
            "properties": {
                "carrierID": {
                    "type": "integer"
                },
                "carrierName": {
                    "type": "string"
                },
                "companyID": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "contacterID": {
                    "type": "integer"
                },
                "contacterName": {
                    "type": "string"
                },
                "details": {
                    "type": "array",
                    "items": {
@@ -1714,6 +1834,15 @@
                "toLocationId": {
                    "description": "目标位置id",
                    "type": "integer"
                },
                "tracking": {
                    "type": "string"
                },
                "transferWeight": {
                    "type": "number"
                },
                "weight": {
                    "type": "number"
                }
            }
        },
@@ -1899,6 +2028,78 @@
                }
            }
        },
        "request.UpdateOperation": {
            "type": "object",
            "properties": {
                "carrierID": {
                    "type": "integer"
                },
                "carrierName": {
                    "type": "string"
                },
                "companyID": {
                    "type": "integer"
                },
                "companyName": {
                    "type": "string"
                },
                "contacterID": {
                    "type": "integer"
                },
                "contacterName": {
                    "type": "string"
                },
                "details": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/request.OperationDetails"
                    }
                },
                "fromLocationId": {
                    "description": "源位置id",
                    "type": "integer"
                },
                "id": {
                    "type": "integer"
                },
                "number": {
                    "description": "单号",
                    "type": "string"
                },
                "operationDate": {
                    "type": "string"
                },
                "operationTypeId": {
                    "description": "作业类型id",
                    "type": "integer"
                },
                "sourceNumber": {
                    "description": "源单号",
                    "type": "string"
                },
                "status": {
                    "description": "状态",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.OperationStatus"
                        }
                    ]
                },
                "toLocationId": {
                    "description": "目标位置id",
                    "type": "integer"
                },
                "tracking": {
                    "type": "string"
                },
                "transferWeight": {
                    "type": "number"
                },
                "weight": {
                    "type": "number"
                }
            }
        },
        "request.UpdateOperationType": {
            "type": "object",
            "properties": {
docs/swagger.yaml
@@ -520,6 +520,18 @@
    type: object
  request.AddOperation:
    properties:
      carrierID:
        type: integer
      carrierName:
        type: string
      companyID:
        type: integer
      companyName:
        type: string
      contacterID:
        type: integer
      contacterName:
        type: string
      details:
        items:
          $ref: '#/definitions/request.OperationDetails'
@@ -547,6 +559,12 @@
      toLocationId:
        description: 目标位置id
        type: integer
      tracking:
        type: string
      transferWeight:
        type: number
      weight:
        type: number
    type: object
  request.AddOperationType:
    properties:
@@ -672,6 +690,54 @@
      remark:
        description: 备注
        type: string
    type: object
  request.UpdateOperation:
    properties:
      carrierID:
        type: integer
      carrierName:
        type: string
      companyID:
        type: integer
      companyName:
        type: string
      contacterID:
        type: integer
      contacterName:
        type: string
      details:
        items:
          $ref: '#/definitions/request.OperationDetails'
        type: array
      fromLocationId:
        description: 源位置id
        type: integer
      id:
        type: integer
      number:
        description: 单号
        type: string
      operationDate:
        type: string
      operationTypeId:
        description: 作业类型id
        type: integer
      sourceNumber:
        description: 源单号
        type: string
      status:
        allOf:
        - $ref: '#/definitions/constvar.OperationStatus'
        description: 状态
      toLocationId:
        description: 目标位置id
        type: integer
      tracking:
        type: string
      transferWeight:
        type: number
      weight:
        type: number
    type: object
  request.UpdateOperationType:
    properties:
@@ -948,6 +1014,31 @@
      tags:
      - 公司
  /api-wms/v1/operation/operation:
    get:
      consumes:
      - application/json
      parameters:
      - in: query
        name: operationTypeId
        type: integer
      - description: 页码
        in: query
        name: page
        type: integer
      - description: 每页大小
        in: query
        name: pageSize
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 入库/出库列表
      tags:
      - 入库/出库
    post:
      parameters:
      - description: 入库/出库信息
@@ -966,6 +1057,47 @@
      summary: 添加入库/出库
      tags:
      - 入库/出库
  /api-wms/v1/operation/operation/{id}:
    delete:
      parameters:
      - description: id
        in: path
        name: id
        required: true
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 删除入库/出库信息
      tags:
      - 入库/出库
    put:
      parameters:
      - description: 入库信息
        in: body
        name: object
        required: true
        schema:
          $ref: '#/definitions/request.UpdateOperation'
      - description: 入库信息id
        in: path
        name: id
        required: true
        type: integer
      produces:
      - application/json
      responses:
        "200":
          description: 成功
          schema:
            $ref: '#/definitions/util.Response'
      summary: 修改入库/出库信息
      tags:
      - 入库/出库
  /api-wms/v1/product/addProduct:
    post:
      parameters:
extend/code/code.go
@@ -25,4 +25,5 @@
    NoTemplateError              = &Code{3010, "未配置订单模板"}
    InternalError                = &Code{3011, "内部错误"}
    NoProductionRequiredError    = &Code{3012, "当前库存满足毛需求量,暂时无需进行生产"}
    RequestError                 = &Code{3013, "请求失败"}
)
models/location.go
@@ -16,7 +16,7 @@
        ParentId          int                   `json:"parentId" gorm:"type:int;not null"`                             //上级id
        CompanyId         int                   `json:"companyId" gorm:"type:int;not null"`                            //公司id
        Company           Company               `json:"company" gorm:"foreignKey:CompanyId"`                           //公司
        Type              constvar.LocationType `json:"type" gorm:"type:tinyint;not null;comment:位置类型"`                //位置类型
        Type              constvar.LocationType `json:"type" gorm:"type:int(11);not null;comment:位置类型"`                //位置类型
        CountFrequency    int                   `json:"countFrequency" gorm:"type:tinyint;not null;comment:盘点频率(天)"`   //盘点频率(天)
        IsScrapLocation   bool                  `json:"isScrapLocation" gorm:"type:tinyint;not null;comment:是否报废位置"`   //是否报废位置
        IsReturnLocation  bool                  `json:"isReturnLocation" gorm:"type:tinyint;not null;comment:是否退货位置"`  //是否退货位置
@@ -77,6 +77,21 @@
    return slf
}
func (slf *LocationSearch) SetType(_type int) *LocationSearch {
    slf.Type = constvar.LocationType(_type)
    return slf
}
func (slf *LocationSearch) SetParentId(parentId int) *LocationSearch {
    slf.ParentId = parentId
    return slf
}
func (slf *LocationSearch) SetCompanyId(companyId int) *LocationSearch {
    slf.CompanyId = companyId
    return slf
}
func (slf *LocationSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Location{})
@@ -94,6 +109,17 @@
    if slf.Name != "" {
        db = db.Where("name = ?", slf.Name)
    }
    if slf.Type != 0 {
        db = db.Where("type=?", slf.Type)
    }
    if slf.ParentId != 0 {
        db = db.Where("parent_id=?", slf.ParentId)
    }
    if slf.CompanyId != 0 {
        db = db.Where("company_id=?", slf.CompanyId)
    }
    return db
@@ -246,3 +272,14 @@
    return records, nil
}
func (slf *LocationSearch) FindAll() ([]*Location, error) {
    var (
        records = make([]*Location, 0)
        db      = slf.build()
    )
    if err := db.Find(&records); err != nil {
        return records, fmt.Errorf("func FindAll err: %v", err)
    }
    return records, nil
}
models/operation.go
@@ -2,6 +2,7 @@
import (
    "fmt"
    "github.com/shopspring/decimal"
    "gorm.io/gorm"
    "wms/constvar"
    "wms/pkg/mysqlx"
@@ -12,7 +13,7 @@
    Operation struct {
        WmsModel
        Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //单号
        Number          string                   `json:"number" gorm:"type:varchar(255)"`                         //单号
        SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //源单号
        OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id
        Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`          //状态
@@ -26,8 +27,8 @@
        Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"`
        ContacterID     int                      `json:"contacterID" gorm:"type:int;comment:联系人ID"`
        ContacterName   string                   `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
        Weight          float64                  `json:"weight" gorm:"type:decimal;comment:重量(kg)"`
        TransferWeight  float64                  `json:"transferWeight" gorm:"type:decimal;comment:物流重量(kg)"`
        Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"`
        TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"`
        CompanyID       int                      `json:"companyID" gorm:"type:int;comment:公司ID"`
        CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"`
        Details         []*OperationDetails      `json:"details"`
@@ -67,13 +68,18 @@
    return slf
}
func (slf *OperationSearch) SetID(id uint) *OperationSearch {
    slf.ID = id
func (slf *OperationSearch) SetID(id int) *OperationSearch {
    slf.Id = id
    return slf
}
func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
    slf.Keyword = keyword
//func (slf *OperationSearch) SetKeyword(keyword string) *OperationSearch {
//    slf.Keyword = keyword
//    return slf
//}
func (slf *OperationSearch) SetOperationTypeId(operationTypeId int) *OperationSearch {
    slf.OperationTypeId = operationTypeId
    return slf
}
@@ -85,16 +91,23 @@
func (slf *OperationSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&Operation{})
    if slf.ID != 0 {
        db = db.Where("id = ?", slf.ID)
    if slf.Id != 0 {
        db = db.Where("id = ?", slf.Id)
    }
    if slf.Order != "" {
        db = db.Order(slf.Order)
    }
    if slf.Keyword != "" {
        db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
    //if slf.Keyword != "" {
    //    db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
    //}
    if slf.OperationTypeId != 0 {
        db.Where("operation_type_id = ?", slf.OperationTypeId)
    }
    if slf.Preload {
        db = db.Model(&Operation{}).Preload("Details")
    }
    return db
@@ -122,6 +135,16 @@
    return nil
}
func (slf *OperationSearch) Save(record *Operation) 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 *OperationSearch) Update(record *Operation) error {
    var db = slf.build()
models/operation_details.go
@@ -12,9 +12,8 @@
    OperationDetails struct {
        WmsModel
        Id          int `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        OperationId int `json:"OperationId" gorm:"type:int;not null;comment:操作记录id"` //操作id
        Id             int             `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
        OperationId    int             `json:"OperationId" gorm:"type:int;not null;comment:操作记录id"`          //操作id
        ProductId      int             `json:"productId" gorm:"type:int;not null;comment:产品id"`              //产品id
        ProductName    string          `json:"productName" gorm:"type:varchar(255);not null;comment:产品名称"`   //产品名称
        Quantity       decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:数量"`       //数量
@@ -70,6 +69,11 @@
    return slf
}
func (slf *OperationDetailsSearch) SetOperationId(operationId int) *OperationDetailsSearch {
    slf.OperationId = operationId
    return slf
}
func (slf *OperationDetailsSearch) build() *gorm.DB {
    var db = slf.Orm.Model(&OperationDetails{})
@@ -85,6 +89,10 @@
        db = db.Where("product_name like ?", fmt.Sprintf("%%%v%%", slf.Keyword))
    }
    if slf.OperationId != 0 {
        db = db.Where("operation_id = ?", slf.OperationId)
    }
    return db
}
request/location.go
New file
@@ -0,0 +1,8 @@
package request
type LocationByType struct {
    Type      int    `json:"type" form:"type"`
    Keyword   string `json:"keyword" form:"keyword"`
    ParentId  int    `json:"parentId" form:"parentId"`
    CompanyId int    `json:"companyId" form:"companyId"`
}
request/operation.go
@@ -1,7 +1,7 @@
package request
import (
    "google.golang.org/genproto/googleapis/type/decimal"
    "github.com/shopspring/decimal"
    "wms/constvar"
)
@@ -15,6 +15,15 @@
    ToLocationId    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"` //目标位置id
    OperationDate   string                   `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"`
    Details         []*OperationDetails      `json:"details"`
    CarrierID       int                      `json:"carrierID" gorm:"type:int;comment:承运商ID"`
    CarrierName     string                   `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"`
    Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"`
    ContacterID     int                      `json:"contacterID" gorm:"type:int;comment:联系人ID"`
    ContacterName   string                   `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
    Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"`
    TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"`
    CompanyID       int                      `json:"companyID" gorm:"type:int;comment:公司ID"`
    CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"`
}
type OperationDetails struct {
@@ -23,3 +32,29 @@
    Quantity       decimal.Decimal `json:"quantity" gorm:"type:decimal(20,2);not null;comment:数量"`       //数量
    FinishQuantity decimal.Decimal `json:"finishQuantity" gorm:"type:decimal(20,2);not null;comment:数量"` //完成数量
}
type OperationList struct {
    PageInfo
    OperationTypeId int `json:"operationTypeId" form:"operationTypeId"`
}
type UpdateOperation struct {
    Id              int                      `json:"id" gorm:"column:id;primary_key;AUTO_INCREMENT"`
    Number          string                   `json:"number" gorm:"column:number;type:varchar(255)"`           //单号
    SourceNumber    string                   `json:"sourceNumber" gorm:"type:varchar(255)"`                   //源单号
    OperationTypeId int                      `json:"operationTypeId" gorm:"type:int;not null;comment:作业类型id"` //作业类型id
    Status          constvar.OperationStatus `json:"status" gorm:"type:int(11);not null;comment:状态"`          //状态
    FromLocationId  int                      `json:"fromLocationId"   gorm:"type:int;not null;comment:源位置id"` //源位置id
    ToLocationId    int                      `json:"toLocationId"    gorm:"type:int;not null;comment:目标位置id"` //目标位置id
    OperationDate   string                   `json:"operationDate" gorm:"type:varchar(31);comment:安排日期"`
    Details         []*OperationDetails      `json:"details"`
    CarrierID       int                      `json:"carrierID" gorm:"type:int;comment:承运商ID"`
    CarrierName     string                   `json:"carrierName" gorm:"type:varchar(63);comment:承运商名称"`
    Tracking        string                   `json:"tracking" gorm:"type:varchar(127);comment:追踪参考"`
    ContacterID     int                      `json:"contacterID" gorm:"type:int;comment:联系人ID"`
    ContacterName   string                   `json:"contacterName" gorm:"type:varchar(63);comment:联系人姓名"`
    Weight          decimal.Decimal          `json:"weight" gorm:"type:decimal(20,2);comment:重量(kg)"`
    TransferWeight  decimal.Decimal          `json:"transferWeight" gorm:"type:decimal(20,2);comment:物流重量(kg)"`
    CompanyID       int                      `json:"companyID" gorm:"type:int;comment:公司ID"`
    CompanyName     string                   `json:"companyName" gorm:"type:varchar(127);comment:公司名称(kg)"`
}
router/router.go
@@ -65,8 +65,10 @@
    operationController := new(controllers.OperationController)
    operationAPI := r.Group(urlPrefix + "/operation")
    {
        //operationAPI.GET()
        operationAPI.GET("operation", operationController.List)
        operationAPI.POST("operation", operationController.Add)
        operationAPI.PUT("operation/:id", operationController.Update)
        operationAPI.DELETE("operation/:id", operationController.Delete)
    }
    //产品
@@ -86,5 +88,11 @@
        productAPI.DELETE("deleteProductCategory/:id", productController.DeleteProductCategory)      //删除产品类型
    }
    locationController := new(controllers.LocationController)
    locationAPI := r.Group(urlPrefix + "/location")
    {
        locationAPI.POST("listByType", locationController.ListLocationByType)
    }
    return r
}