// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.

package base

import (
	model "LAPP_LF_MOM_BACKEND/models/base"
	"LAPP_LF_MOM_BACKEND/web/middleware/jwts"
	"LAPP_LF_MOM_BACKEND/web/models"
	"LAPP_LF_MOM_BACKEND/web/supports"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/core/router"
)

/******************************************************************************
 *
 * @Function Name            : RegisterOneWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterOneWorkLineWorkPlaceLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *model.WorkLineWorkPlaceLst) error) {

	party.Handle(httpMethod, path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		var err error = nil

		entity := new(model.WorkLineWorkPlaceLst)
		if ctx.GetContentLength() > 0 {
			err := ctx.ReadJSON(entity)
			if err != nil {
				supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
				return
			}
		} else {
			entity = nil
		}

		err = method(user, entity)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, nil)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterIDOfWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个通过主键处理单条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterIDOfWorkLineWorkPlaceLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, string, int) error) {

	party.Handle(httpMethod, path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		var err error = nil
		workLineId := ctx.Params().GetString("workLineId")
		workPlaceNr, err := ctx.Params().GetInt("workPlaceNr")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}

		err = method(user, workLineId, workPlaceNr)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, nil)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterInsertOneWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入单条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterInsertOneWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, *model.WorkLineWorkPlaceLst) error) {

	RegisterOneWorkLineWorkPlaceLst(party, "POST", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteOneWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除单条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterDeleteOneWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, string, int) error) {

	RegisterIDOfWorkLineWorkPlaceLst(party, "DELETE", path+"/{workLineId:string}/{workPlaceNr:int}", method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterSelectOneWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查找单条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterSelectOneWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, string, int) (*model.WorkLineWorkPlaceLst, error)) {

	party.Get(path+"/{workLineId:string}/{workPlaceNr:int}", func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		workLineId := ctx.Params().GetString("workLineId")
		workPlaceNr, err := ctx.Params().GetInt("workPlaceNr")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		result, err := method(user, workLineId, workPlaceNr)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		if result == nil {
			supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, result)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterUpdateOneWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterUpdateOneWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, *model.WorkLineWorkPlaceLst) error) {

	RegisterOneWorkLineWorkPlaceLst(party, "PUT", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterMultiWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理多条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterMultiWorkLineWorkPlaceLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *[]model.WorkLineWorkPlaceLst) error) {

	party.Handle(httpMethod, path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		entities := make([]model.WorkLineWorkPlaceLst, 0, 10)
		err := ctx.ReadJSON(&entities)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}

		err = method(user, &entities)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, nil)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterInsertWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入多条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterInsertWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkLineWorkPlaceLst) error) {

	RegisterMultiWorkLineWorkPlaceLst(party, "POST", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除多条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterDeleteWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkLineWorkPlaceLst) error) {

	RegisterMultiWorkLineWorkPlaceLst(party, "DELETE", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterSelectWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterSelectWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, map[string]string) (interface{}, error)) {

	party.Get(path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		result, err := method(user, ctx.URLParams())
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, result)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterUpdateWorkLineWorkPlaceLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条WorkLineWorkPlaceLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-22 16:03:30
 *
 ******************************************************************************/
func RegisterUpdateWorkLineWorkPlaceLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkLineWorkPlaceLst) error) {

	RegisterMultiWorkLineWorkPlaceLst(party, "PUT", path, method)
}
