| | |
| | | var reqParams request.AddOperation |
| | | var params models.Operation |
| | | if err := c.BindJSON(&reqParams); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误") |
| | | util.ResponseFormat(c, code.RequestParamError, "参数解析失败,数据类型错误"+err.Error()) |
| | | return |
| | | } |
| | | if err := structx.AssignTo(reqParams, params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, "数据转换错误") |
| | | return |
| | | } |
| | | if err := slf.CheckParams(params); err != nil { |
| | | util.ResponseFormat(c, code.RequestParamError, err.Error()) |
| | | return |
| | | } |
| | | if err := models.NewOperationSearch().Create(¶ms); err != nil { |
| | | logx.Errorf("Operation create err: %v", err) |
| | | util.ResponseFormat(c, code.SaveFail, "添加失败:"+err.Error()) |
| | | return |
| | | } |
| | | util.ResponseFormat(c, code.Success, "添加成功") |
| | | |
| | | } |
| | | |
| | | func (slf OperationController) CheckParams(params models.Operation) error { |
| | |
| | | return errors.New("请选择目标位置") |
| | | } |
| | | |
| | | if params.OperationDate.IsZero() { |
| | | if params.OperationDate == "" { |
| | | return errors.New("请选择安排日期") |
| | | } |
| | | |