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

package base

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

/******************************************************************************
 *
 * @Function Name            : RegisterOneWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterOneWorkOrderIdentifyRule(party router.Party, httpMethod string, path string, method func(*global.User, *model.WorkOrderIdentifyRule) 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.WorkOrderIdentifyRule)
		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            : RegisterIDOfWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个通过主键处理单条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterIDOfWorkOrderIdentifyRule(party router.Party, httpMethod string, path string, method func(*global.User, 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
		collerationBasis := ctx.Params().GetString("collerationBasis")
		collerationOperationId, err := ctx.Params().GetInt("collerationOperationId")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}

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

/******************************************************************************
 *
 * @Function Name            : RegisterInsertOneWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入单条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterInsertOneWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, *model.WorkOrderIdentifyRule) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteOneWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除单条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterDeleteOneWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, string, int) error) {

	RegisterIDOfWorkOrderIdentifyRule(party, "DELETE", path+"/{collerationBasis:string}/{collerationOperationId:int}", method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterSelectOneWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查找单条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterSelectOneWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, string, int) (*model.WorkOrderIdentifyRule, error)) {

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

		collerationBasis := ctx.Params().GetString("collerationBasis")
		collerationOperationId, err := ctx.Params().GetInt("collerationOperationId")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		result, err := method(user, collerationBasis, collerationOperationId)
		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            : RegisterUpdateOneWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterUpdateOneWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, *model.WorkOrderIdentifyRule) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterMultiWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理多条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterMultiWorkOrderIdentifyRule(party router.Party, httpMethod string, path string, method func(*global.User, *[]model.WorkOrderIdentifyRule) 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.WorkOrderIdentifyRule, 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            : RegisterInsertWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入多条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterInsertWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, *[]model.WorkOrderIdentifyRule) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除多条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterDeleteWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, *[]model.WorkOrderIdentifyRule) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterSelectWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterSelectWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, map[string]string) ([]model.WorkOrderIdentifyRule, 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            : RegisterQueryWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询WorkOrderIdentifyRule并分页的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterQueryWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, map[string]string) (grmi.PagingResult, 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            : RegisterUpdateWorkOrderIdentifyRule
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条WorkOrderIdentifyRule的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-30 14:27:09
 *
 ******************************************************************************/
func RegisterUpdateWorkOrderIdentifyRule(party router.Party, path string, method func(*global.User, *[]model.WorkOrderIdentifyRule) error) {

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