|
package v1
|
|
import (
|
"aps_crm/model"
|
"aps_crm/model/request"
|
"aps_crm/model/response"
|
"aps_crm/pkg/contextx"
|
"aps_crm/pkg/ecode"
|
"github.com/gin-gonic/gin"
|
"strconv"
|
)
|
|
type OrderTypeApi struct{}
|
|
// Add
|
//
|
// @Tags OrderType
|
// @Summary 添加工单类型
|
// @Produce application/json
|
// @Param object body request.AddOrderType true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/orderType/add [post]
|
func (s *OrderTypeApi) Add(c *gin.Context) {
|
var params request.AddOrderType
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
orderType := new(model.OrderType)
|
orderType.Name = params.Name
|
|
errCode := orderTypeService.AddOrderType(orderType)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Delete
|
//
|
// @Tags OrderType
|
// @Summary 删除工单类型
|
// @Produce application/json
|
// @Param id path int true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/orderType/delete/{id} [delete]
|
func (s *OrderTypeApi) Delete(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
errCode := orderTypeService.DeleteOrderType(id)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// Update
|
//
|
// @Tags OrderType
|
// @Summary 更新工单类型
|
// @Produce application/json
|
// @Param object body request.UpdateOrderTypes true "查询参数"
|
// @Success 200 {object} contextx.Response{}
|
// @Router /api/orderType/update [put]
|
func (s *OrderTypeApi) Update(c *gin.Context) {
|
var params request.UpdateOrderTypes
|
ctx, ok := contextx.NewContext(c, ¶ms)
|
if !ok {
|
return
|
}
|
|
errCode := orderTypeService.UpdateOrderType(params.OrderTypes)
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.Ok()
|
}
|
|
// List
|
//
|
// @Tags OrderType
|
// @Summary 获取工单类型列表
|
// @Produce application/json
|
// @Success 200 {object} contextx.Response{data=response.OrderTypeResponse}
|
// @Router /api/orderType/list [get]
|
func (s *OrderTypeApi) List(c *gin.Context) {
|
ctx, ok := contextx.NewContext(c, nil)
|
if !ok {
|
return
|
}
|
|
orderTypes, errCode := orderTypeService.GetOrderTypeList()
|
if errCode != ecode.OK {
|
ctx.Fail(errCode)
|
return
|
}
|
|
ctx.OkWithDetailed(response.OrderTypeResponse{
|
List: orderTypes,
|
})
|
}
|