| | |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | // @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 |
| | |
| | | } |
| | | 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 |