63 lines
1.8 KiB
Go
63 lines
1.8 KiB
Go
package handler
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
|
||
|
|
"bj_power_mes/common/httpx"
|
||
|
|
"bj_power_mes/internal/logic"
|
||
|
|
"bj_power_mes/internal/svc"
|
||
|
|
)
|
||
|
|
|
||
|
|
// ListRoutesHandler GET /process-routes?name=&status=&page=&pageSize=
|
||
|
|
func ListRoutesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
q := r.URL.Query()
|
||
|
|
data, err := logic.New(svcCtx).ListRoutes(r.Context(), q.Get("name"), q.Get("status"),
|
||
|
|
atoiDefault(q.Get("page"), 0), atoiDefault(q.Get("pageSize"), 20))
|
||
|
|
if err != nil {
|
||
|
|
httpx.Fail(w, 2301, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
httpx.Ok(w, data)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// SaveRouteHandler POST /process-routes(新建或更新工艺路线,含段)
|
||
|
|
func SaveRouteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
var req logic.RouteReq
|
||
|
|
if err := httpx.ParseJSON(r, &req); err != nil {
|
||
|
|
httpx.BadRequest(w, "请求体解析失败")
|
||
|
|
return
|
||
|
|
}
|
||
|
|
if err := logic.New(svcCtx).SaveRoute(r.Context(), req, operator(r, "")); err != nil {
|
||
|
|
httpx.Fail(w, 2302, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
httpx.OkMessage(w, "工艺路线已保存", nil)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// GetRouteHandler GET /process-routes/:id
|
||
|
|
func GetRouteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
data, err := logic.New(svcCtx).GetRoute(r.Context(), pathId(r))
|
||
|
|
if err != nil {
|
||
|
|
httpx.Fail(w, 2303, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
httpx.Ok(w, data)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// DeleteRouteHandler DELETE /process-routes/:id
|
||
|
|
func DeleteRouteHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
if err := logic.New(svcCtx).DeleteRoute(r.Context(), pathId(r), operator(r, "")); err != nil {
|
||
|
|
httpx.Fail(w, 2304, err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
httpx.OkMessage(w, "工艺路线已删除", nil)
|
||
|
|
}
|
||
|
|
}
|