From e5df488268e29b272932e6cc1d2b1e7034590ba0 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期三, 12 六月 2024 11:40:45 +0800
Subject: [PATCH] weedfs包放到项目里

---
 controllers/operation_type.go |   94 +++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 82 insertions(+), 12 deletions(-)

diff --git a/controllers/operation_type.go b/controllers/operation_type.go
index b2d5dc3..5faabe7 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"
@@ -17,12 +19,12 @@
 type OperationTypeController struct{}
 
 // Add
-// @Tags      浣滀笟绫诲瀷
+// @Tags      涓氬姟绫诲瀷
 // @Summary   娣诲姞浣滀笟绫诲瀷
 // @Produce   application/json
 // @Param     object  body  request.AddOperationType true  "浣滀笟绫诲瀷淇℃伅"
 // @Success   200 {object} util.Response "鎴愬姛"
-// @Router    /api-wms/v1/warehouse/operationType [post]
+// @Router    /api-wms/v1/operationType/operationType [post]
 func (slf OperationTypeController) Add(c *gin.Context) {
 	var reqParams request.AddOperationType
 	var params models.OperationType
@@ -49,13 +51,13 @@
 }
 
 // Update
-// @Tags      浣滀笟绫诲瀷
+// @Tags      涓氬姟绫诲瀷
 // @Summary   缂栬緫浣滀笟绫诲瀷
 // @Produce   application/json
 // @Param     object  body request.UpdateOperationType true  "浣滀笟绫诲瀷淇℃伅"
 // @Param     id  path string true  "浣滀笟绫诲瀷id"
 // @Success   200 {object} util.Response "鎴愬姛"
-// @Router    /api-wms/v1/warehouse/operationType/{id} [put]
+// @Router    /api-wms/v1/operationType/operationType/{id} [put]
 func (slf OperationTypeController) Update(c *gin.Context) {
 	id := cast.ToUint(c.Param("id"))
 	if id == 0 {
@@ -102,12 +104,12 @@
 }
 
 // List
-// @Tags      浣滀笟绫诲瀷
+// @Tags      涓氬姟绫诲瀷
 // @Summary   鏌ヨ浣滀笟绫诲瀷鍒楄〃
 // @Produce   application/json
 // @Param     object  query    request.GetOperationTypeList true  "鏌ヨ鍙傛暟"
-// @Success   200   {object}  util.ResponseList{data=[]models.OperationType}  "鎴愬姛"
-// @Router    /api-wms/v1/warehouse/operationType [get]
+// @Success   200   {object}  util.ResponseList  "鎴愬姛"
+// @Router    /api-wms/v1/operationType/operationType [get]
 func (slf OperationTypeController) List(c *gin.Context) {
 	var params request.GetOperationTypeList
 	if err := c.ShouldBindQuery(&params); err != nil {
@@ -116,20 +118,43 @@
 	}
 	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
+		}
+		if value, ok := mapStatistics[strconv.Itoa(v.Id)+string(constvar.OperationStatus_Cancel)]; ok {
+			list[k].CancelCount = value.Count
+		}
+	}
+	util.ResponseFormatListWithPage(c, code.Success, list, cast.ToInt(total), params.Page, params.PageSize)
 }
 
 // Delete
-// @Tags      浣滀笟绫诲瀷
+// @Tags      涓氬姟绫诲瀷
 // @Summary   鍒犻櫎浣滀笟绫诲瀷
 // @Produce   application/json
 // @Param     id  path string true  "浣滀笟绫诲瀷id"
 // @Success   200 {object} util.Response "鎴愬姛"
-// @Router    /api-wms/v1/warehouse/operationType/{id} [delete]
+// @Router    /api-wms/v1/operationType/operationType/{id} [delete]
 func (slf OperationTypeController) Delete(c *gin.Context) {
 	id := cast.ToUint(c.Param("id"))
 	if id == 0 {
@@ -144,3 +169,48 @@
 	}
 	util.ResponseFormat(c, code.UpdateSuccess, "鍒犻櫎鎴愬姛")
 }
+
+// ListTransfer
+// @Tags      涓氬姟绫诲瀷
+// @Summary   璋冩嫧绫诲瀷鍒楄〃
+// @Produce   application/json
+// @Param     object  query    request.ListTransfer true  "鏌ヨ鍙傛暟"
+// @Success   200   {object}  util.ResponseList  "鎴愬姛"
+// @Router    /api-wms/v1/operationType/listTransfer [get]
+func (slf OperationTypeController) ListTransfer(c *gin.Context) {
+	var params request.GetOperationTypeList
+	if err := c.ShouldBindQuery(&params); err != nil {
+		util.ResponseFormat(c, code.RequestParamError, err.Error())
+		return
+	}
+	list, total, err := models.NewOperationTypeSearch().SetPage(params.Page, params.PageSize).SetBaseOperationType(constvar.BaseOperationTypeInternal).SetKeyword(params.Keyword).SetOrder("id desc").SetPreload(true).Find()
+	if err != nil {
+		util.ResponseFormat(c, code.RequestError, "鏌ユ壘澶辫触")
+		return
+	}
+	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
+		}
+		if value, ok := mapStatistics[strconv.Itoa(v.Id)+string(constvar.OperationStatus_Cancel)]; ok {
+			list[k].FinishCount = value.Count
+		}
+	}
+	util.ResponseFormatListWithPage(c, code.Success, list, cast.ToInt(total), params.Page, params.PageSize)
+}

--
Gitblit v1.8.0