jiangshuai
2023-09-25 c2d8e537bb18c0892c0df6686ee5f5b5023f5bbb
1.修改业务类型列表接口,增加已就绪和已完成数量的统计
5个文件已修改
418 ■■■■ 已修改文件
controllers/operation_type.go 30 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/docs.go 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.json 139 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
docs/swagger.yaml 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
models/operation_type.go 25 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/operation_type.go
@@ -6,6 +6,8 @@
    "github.com/gin-gonic/gin"
    "github.com/spf13/cast"
    "gorm.io/gorm"
    "strconv"
    "wms/constvar"
    "wms/extend/code"
    "wms/extend/util"
    "wms/models"
@@ -106,7 +108,7 @@
// @Summary   查询作业类型列表
// @Produce   application/json
// @Param     object  query    request.GetOperationTypeList true  "查询参数"
// @Success   200   {object}  util.ResponseList{data=[]models.OperationType}  "成功"
// @Success   200   {object}  util.ResponseList  "成功"
// @Router    /api-wms/v1/operationType/operationType [get]
func (slf OperationTypeController) List(c *gin.Context) {
    var params request.GetOperationTypeList
@@ -116,11 +118,31 @@
    }
    list, total, err := models.NewOperationTypeSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("id desc").SetPreload(true).Find()
    if err != nil {
        util.ResponseFormat(c, code.RequestParamError, "查找失败")
        util.ResponseFormat(c, code.RequestError, "查找失败")
        return
    }
    util.ResponseFormatList(c, code.Success, list, cast.ToInt(total))
    var idList []int
    for _, v := range list {
        idList = append(idList, v.Id)
    }
    statistics, err := models.NewOperationTypeSearch().ListByStatusAndCount(idList)
    if err != nil {
        util.ResponseFormat(c, code.RequestError, err.Error())
        return
    }
    mapStatistics := make(map[string]*models.OperationTypeByStatus, 0)
    for _, v := range statistics {
        mapStatistics[strconv.Itoa(v.Id)+string(v.Status)] = v
    }
    for k, v := range list {
        if value, ok := mapStatistics[strconv.Itoa(v.Id)+string(constvar.OperationStatus_Ready)]; ok {
            list[k].ReadyCount = value.Count
        }
        if value, ok := mapStatistics[strconv.Itoa(v.Id)+string(constvar.OperationStatus_Finish)]; ok {
            list[k].FinishCount = value.Count
        }
    }
    util.ResponseFormatListWithPage(c, code.Success, list, cast.ToInt(total), params.Page, params.PageSize)
}
// Delete
docs/docs.go
@@ -675,22 +675,7 @@
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.OperationType"
                                            }
                                        }
                                    }
                                }
                            ]
                            "$ref": "#/definitions/util.ResponseList"
                        }
                    }
                }
@@ -2145,128 +2130,6 @@
                },
                "updateTime": {
                    "type": "string"
                }
            }
        },
        "models.OperationType": {
            "type": "object",
            "properties": {
                "ReservationDaysBeforePriority": {
                    "description": "在优先级的前几天",
                    "type": "integer"
                },
                "baseOperationType": {
                    "description": "基础作业类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.BaseOperationType"
                        }
                    ]
                },
                "company": {
                    "description": "公司",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Company"
                        }
                    ]
                },
                "companyId": {
                    "description": "公司id",
                    "type": "integer"
                },
                "createBackorder": {
                    "description": "创建欠单",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.WhetherType"
                        }
                    ]
                },
                "createTime": {
                    "type": "string"
                },
                "defaultLocationDest": {
                    "description": "默认目标位置",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Location"
                        }
                    ]
                },
                "defaultLocationDestId": {
                    "description": "默认目标位置id",
                    "type": "integer"
                },
                "defaultLocationSrc": {
                    "description": "默认源位置",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Location"
                        }
                    ]
                },
                "defaultLocationSrcId": {
                    "description": "默认源位置id",
                    "type": "integer"
                },
                "earlyOperations": {
                    "description": "预填写作业详情",
                    "type": "boolean"
                },
                "id": {
                    "type": "integer"
                },
                "name": {
                    "description": "仓库名称",
                    "type": "string"
                },
                "prefix": {
                    "description": "前缀",
                    "type": "string"
                },
                "printLabel": {
                    "description": "是否打印标签",
                    "type": "boolean"
                },
                "reservationDaysBefore": {
                    "description": "收货前几天",
                    "type": "integer"
                },
                "reservationMethod": {
                    "description": "保留方式",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ReservationMethod"
                        }
                    ]
                },
                "returnOperationType": {
                    "description": "退货类型名称",
                    "type": "string"
                },
                "returnOperationTypeID": {
                    "description": "退货类型ID",
                    "type": "integer"
                },
                "showOperations": {
                    "description": "显示作业详情",
                    "type": "boolean"
                },
                "updateTime": {
                    "type": "string"
                },
                "warehouse": {
                    "description": "仓库",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Warehouse"
                        }
                    ]
                },
                "warehouseId": {
                    "description": "仓库id",
                    "type": "integer"
                }
            }
        },
docs/swagger.json
@@ -663,22 +663,7 @@
                    "200": {
                        "description": "成功",
                        "schema": {
                            "allOf": [
                                {
                                    "$ref": "#/definitions/util.ResponseList"
                                },
                                {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/models.OperationType"
                                            }
                                        }
                                    }
                                }
                            ]
                            "$ref": "#/definitions/util.ResponseList"
                        }
                    }
                }
@@ -2133,128 +2118,6 @@
                },
                "updateTime": {
                    "type": "string"
                }
            }
        },
        "models.OperationType": {
            "type": "object",
            "properties": {
                "ReservationDaysBeforePriority": {
                    "description": "在优先级的前几天",
                    "type": "integer"
                },
                "baseOperationType": {
                    "description": "基础作业类型",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.BaseOperationType"
                        }
                    ]
                },
                "company": {
                    "description": "公司",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Company"
                        }
                    ]
                },
                "companyId": {
                    "description": "公司id",
                    "type": "integer"
                },
                "createBackorder": {
                    "description": "创建欠单",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.WhetherType"
                        }
                    ]
                },
                "createTime": {
                    "type": "string"
                },
                "defaultLocationDest": {
                    "description": "默认目标位置",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Location"
                        }
                    ]
                },
                "defaultLocationDestId": {
                    "description": "默认目标位置id",
                    "type": "integer"
                },
                "defaultLocationSrc": {
                    "description": "默认源位置",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Location"
                        }
                    ]
                },
                "defaultLocationSrcId": {
                    "description": "默认源位置id",
                    "type": "integer"
                },
                "earlyOperations": {
                    "description": "预填写作业详情",
                    "type": "boolean"
                },
                "id": {
                    "type": "integer"
                },
                "name": {
                    "description": "仓库名称",
                    "type": "string"
                },
                "prefix": {
                    "description": "前缀",
                    "type": "string"
                },
                "printLabel": {
                    "description": "是否打印标签",
                    "type": "boolean"
                },
                "reservationDaysBefore": {
                    "description": "收货前几天",
                    "type": "integer"
                },
                "reservationMethod": {
                    "description": "保留方式",
                    "allOf": [
                        {
                            "$ref": "#/definitions/constvar.ReservationMethod"
                        }
                    ]
                },
                "returnOperationType": {
                    "description": "退货类型名称",
                    "type": "string"
                },
                "returnOperationTypeID": {
                    "description": "退货类型ID",
                    "type": "integer"
                },
                "showOperations": {
                    "description": "显示作业详情",
                    "type": "boolean"
                },
                "updateTime": {
                    "type": "string"
                },
                "warehouse": {
                    "description": "仓库",
                    "allOf": [
                        {
                            "$ref": "#/definitions/models.Warehouse"
                        }
                    ]
                },
                "warehouseId": {
                    "description": "仓库id",
                    "type": "integer"
                }
            }
        },
docs/swagger.yaml
@@ -498,82 +498,6 @@
      updateTime:
        type: string
    type: object
  models.OperationType:
    properties:
      ReservationDaysBeforePriority:
        description: 在优先级的前几天
        type: integer
      baseOperationType:
        allOf:
        - $ref: '#/definitions/constvar.BaseOperationType'
        description: 基础作业类型
      company:
        allOf:
        - $ref: '#/definitions/models.Company'
        description: 公司
      companyId:
        description: 公司id
        type: integer
      createBackorder:
        allOf:
        - $ref: '#/definitions/constvar.WhetherType'
        description: 创建欠单
      createTime:
        type: string
      defaultLocationDest:
        allOf:
        - $ref: '#/definitions/models.Location'
        description: 默认目标位置
      defaultLocationDestId:
        description: 默认目标位置id
        type: integer
      defaultLocationSrc:
        allOf:
        - $ref: '#/definitions/models.Location'
        description: 默认源位置
      defaultLocationSrcId:
        description: 默认源位置id
        type: integer
      earlyOperations:
        description: 预填写作业详情
        type: boolean
      id:
        type: integer
      name:
        description: 仓库名称
        type: string
      prefix:
        description: 前缀
        type: string
      printLabel:
        description: 是否打印标签
        type: boolean
      reservationDaysBefore:
        description: 收货前几天
        type: integer
      reservationMethod:
        allOf:
        - $ref: '#/definitions/constvar.ReservationMethod'
        description: 保留方式
      returnOperationType:
        description: 退货类型名称
        type: string
      returnOperationTypeID:
        description: 退货类型ID
        type: integer
      showOperations:
        description: 显示作业详情
        type: boolean
      updateTime:
        type: string
      warehouse:
        allOf:
        - $ref: '#/definitions/models.Warehouse'
        description: 仓库
      warehouseId:
        description: 仓库id
        type: integer
    type: object
  models.ProductCategory:
    properties:
      costingMethod:
@@ -1485,14 +1409,7 @@
        "200":
          description: 成功
          schema:
            allOf:
            - $ref: '#/definitions/util.ResponseList'
            - properties:
                data:
                  items:
                    $ref: '#/definitions/models.OperationType'
                  type: array
              type: object
            $ref: '#/definitions/util.ResponseList'
      summary: 查询作业类型列表
      tags:
      - 业务类型
models/operation_type.go
@@ -34,6 +34,8 @@
        CreateBackorder               constvar.WhetherType       `json:"createBackorder" gorm:"column:create_backorder"`                 //创建欠单
        ReturnOperationTypeID         int                        `json:"returnOperationTypeID" gorm:"column:return_job_type_id"`         //退货类型ID
        ReturnOperationType           string                     `json:"returnOperationType" gorm:"-"`                                   //退货类型名称
        ReadyCount                    int                        `json:"readyCount" gorm:"-"`                                            //就绪数量
        FinishCount                   int                        `json:"finishCount" gorm:"-"`                                           //完成数量
    }
    OperationTypeSearch struct {
@@ -44,6 +46,12 @@
        Keyword  string
        Orm      *gorm.DB
        Preload  bool
    }
    OperationTypeByStatus struct {
        Id     int                      `gorm:"column:id"`
        Status constvar.OperationStatus `gorm:"column:status"`
        Count  int                      `gorm:"column:count"`
    }
)
@@ -268,3 +276,20 @@
    return records, nil
}
func (slf *OperationTypeSearch) ListByStatusAndCount(idList []int) ([]*OperationTypeByStatus, error) {
    var (
        records = make([]*OperationTypeByStatus, 0)
        db      = slf.Orm
    )
    db = db.Table("wms_job_type").Select("wms_job_type.id,wms_operation.status,count(wms_operation.id) as count").InnerJoins("inner join wms_operation on wms_operation.operation_type_id=wms_job_type.id").Group("wms_job_type.id,wms_operation.status")
    if len(idList) > 0 {
        db = db.Where("wms_job_type.id IN ?", idList)
    }
    if err := db.Find(&records).Error; err != nil {
        return records, fmt.Errorf("func ListByStatusAndCount err: %v, ", err)
    }
    return records, nil
}