File was renamed from controllers/job_type.go |
| | |
| | | "wms/request" |
| | | ) |
| | | |
| | | type JobTypeController struct{} |
| | | type OperationTypeController struct{} |
| | | |
| | | // Add |
| | | // @Tags 作业类型 |
| | | // @Summary 添加作业类型 |
| | | // @Produce application/json |
| | | // @Param object body request.AddJobType true "作业类型信息" |
| | | // @Param object body request.AddOperationType true "作业类型信息" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/warehouse/jobType [post] |
| | | func (slf JobTypeController) Add(c *gin.Context) { |
| | | var reqParams request.AddJobType |
| | | var params models.JobType |
| | | // @Router /api-wms/v1/warehouse/operationType [post] |
| | | func (slf OperationTypeController) Add(c *gin.Context) { |
| | | var reqParams request.AddOperationType |
| | | var params models.OperationType |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | return |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if err := models.NewJobTypeSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("JobType create err: %v", err) |
| | | if err := models.NewOperationTypeSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("OperationType create err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "插入失败") |
| | | return |
| | | } |
| | |
| | | // @Tags 作业类型 |
| | | // @Summary 编辑作业类型 |
| | | // @Produce application/json |
| | | // @Param object body request.UpdateJobType true "作业类型信息" |
| | | // @Param object body request.UpdateOperationType true "作业类型信息" |
| | | // @Param id path string true "作业类型id" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/warehouse/jobType/{id} [put] |
| | | func (slf JobTypeController) Update(c *gin.Context) { |
| | | // @Router /api-wms/v1/warehouse/operationType/{id} [put] |
| | | func (slf OperationTypeController) Update(c *gin.Context) { |
| | | id := cast.ToUint(c.Param("id")) |
| | | if id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "空的记录id") |
| | | return |
| | | } |
| | | var ( |
| | | reqParams request.UpdateJobType |
| | | params models.JobType |
| | | reqParams request.UpdateOperationType |
| | | params models.OperationType |
| | | ) |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, fmt.Sprintf("参数解析失败: %v"+err.Error())) |
| | |
| | | return |
| | | } |
| | | |
| | | err := models.NewJobTypeSearch().SetID(params.ID).Update(¶ms) |
| | | err := models.NewOperationTypeSearch().SetID(params.ID).Update(¶ms) |
| | | |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "修改失败") |
| | |
| | | util.ResponseFormat(c, code.UpdateSuccess, "更新成功") |
| | | } |
| | | |
| | | func (slf JobTypeController) ParamsCheck(params models.JobType) (err error) { |
| | | func (slf OperationTypeController) ParamsCheck(params models.OperationType) (err error) { |
| | | if params.ID != 0 { |
| | | _, err = models.NewJobTypeSearch().SetID(params.ID).First() |
| | | _, err = models.NewOperationTypeSearch().SetID(params.ID).First() |
| | | if err == gorm.ErrRecordNotFound { |
| | | return errors.New("记录不存在") |
| | | } |
| | |
| | | // @Tags 作业类型 |
| | | // @Summary 查询作业类型列表 |
| | | // @Produce application/json |
| | | // @Param object query request.GetJobTypeList true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.JobType} "成功" |
| | | // @Router /api-wms/v1/warehouse/jobType [get] |
| | | func (slf JobTypeController) List(c *gin.Context) { |
| | | var params request.GetJobTypeList |
| | | // @Param object query request.GetOperationTypeList true "查询参数" |
| | | // @Success 200 {object} util.ResponseList{data=[]models.OperationType} "成功" |
| | | // @Router /api-wms/v1/warehouse/operationType [get] |
| | | func (slf OperationTypeController) List(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.NewJobTypeSearch().SetPage(params.Page, params.PageSize).SetKeyword(params.Keyword).SetOrder("id desc").SetPreload(true).Find() |
| | | 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, "查找失败") |
| | | return |
| | |
| | | // @Produce application/json |
| | | // @Param id path string true "作业类型id" |
| | | // @Success 200 {object} util.Response "成功" |
| | | // @Router /api-wms/v1/warehouse/jobType/{id} [delete] |
| | | func (slf JobTypeController) Delete(c *gin.Context) { |
| | | // @Router /api-wms/v1/warehouse/operationType/{id} [delete] |
| | | func (slf OperationTypeController) Delete(c *gin.Context) { |
| | | id := cast.ToUint(c.Param("id")) |
| | | if id == 0 { |
| | | util.ResponseFormat(c, code.RequestParamError, "空的记录id") |
| | | return |
| | | } |
| | | |
| | | err := models.NewJobTypeSearch().SetID(id).Delete() |
| | | err := models.NewOperationTypeSearch().SetID(id).Delete() |
| | | if err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "删除失败") |
| | | return |