From c2d8e537bb18c0892c0df6686ee5f5b5023f5bbb Mon Sep 17 00:00:00 2001 From: jiangshuai <291802688@qq.com> Date: 星期一, 25 九月 2023 17:58:41 +0800 Subject: [PATCH] 1.修改业务类型列表接口,增加已就绪和已完成数量的统计 --- models/operation_type.go | 25 +++ controllers/operation_type.go | 30 +++ docs/swagger.yaml | 85 ------------ docs/docs.go | 139 ------------------- docs/swagger.json | 139 ------------------- 5 files changed, 54 insertions(+), 364 deletions(-) diff --git a/controllers/operation_type.go b/controllers/operation_type.go index 3d21412..8737781 100644 --- a/controllers/operation_type.go +++ b/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 diff --git a/docs/docs.go b/docs/docs.go index 20489c0..7e7b11a 100644 --- a/docs/docs.go +++ b/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": "榛樿婧愪綅缃甶d", - "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": "閫�璐х被鍨婭D", - "type": "integer" - }, - "showOperations": { - "description": "鏄剧ず浣滀笟璇︽儏", - "type": "boolean" - }, - "updateTime": { - "type": "string" - }, - "warehouse": { - "description": "浠撳簱", - "allOf": [ - { - "$ref": "#/definitions/models.Warehouse" - } - ] - }, - "warehouseId": { - "description": "浠撳簱id", - "type": "integer" } } }, diff --git a/docs/swagger.json b/docs/swagger.json index 9c6e3e4..1b041dd 100644 --- a/docs/swagger.json +++ b/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": "榛樿婧愪綅缃甶d", - "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": "閫�璐х被鍨婭D", - "type": "integer" - }, - "showOperations": { - "description": "鏄剧ず浣滀笟璇︽儏", - "type": "boolean" - }, - "updateTime": { - "type": "string" - }, - "warehouse": { - "description": "浠撳簱", - "allOf": [ - { - "$ref": "#/definitions/models.Warehouse" - } - ] - }, - "warehouseId": { - "description": "浠撳簱id", - "type": "integer" } } }, diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 0e09a58..e933993 100644 --- a/docs/swagger.yaml +++ b/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: 榛樿婧愪綅缃甶d - 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: 閫�璐х被鍨婭D - 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: - 涓氬姟绫诲瀷 diff --git a/models/operation_type.go b/models/operation_type.go index b97e0b0..26842f7 100644 --- a/models/operation_type.go +++ b/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"` //閫�璐х被鍨婭D 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 +} -- Gitblit v1.8.0