| | |
| | | "github.com/gin-gonic/gin" |
| | | "github.com/spf13/cast" |
| | | "gorm.io/gorm" |
| | | "strconv" |
| | | "wms/constvar" |
| | | "wms/extend/code" |
| | | "wms/extend/util" |
| | | "wms/models" |
| | |
| | | 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 |
| | |
| | | } |
| | | |
| | | // 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 { |
| | |
| | | } |
| | | |
| | | // 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(¶ms); err != nil { |
| | |
| | | } |
| | | 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 { |
| | |
| | | } |
| | | 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(¶ms); 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) |
| | | } |