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

package qm

import (
	model "LAPP_LF_MOM_BACKEND/models/qm"
	"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            : RegisterOneDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterOneDefectGrpReasonLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *model.DefectGrpReasonLst) 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.DefectGrpReasonLst)
		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            : RegisterIDOfDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个通过主键处理单条DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterIDOfDefectGrpReasonLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, string, string) 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
		defectGrpId := ctx.Params().GetString("defectGrpId")
		defectReasonId := ctx.Params().GetString("defectReasonId")

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

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

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

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

	RegisterIDOfDefectGrpReasonLst(party, "DELETE", path+"/{defectGrpId:string}/{defectReasonId:string}", method)
}

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

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

		defectGrpId := ctx.Params().GetString("defectGrpId")
		defectReasonId := ctx.Params().GetString("defectReasonId")
		result, err := method(user, defectGrpId, defectReasonId)
		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            : RegisterUpdateOneDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateOneDefectGrpReasonLst(party router.Party, path string, method func(*models.Usertab, *model.DefectGrpReasonLst) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterMultiDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理多条DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterMultiDefectGrpReasonLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *[]model.DefectGrpReasonLst) 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.DefectGrpReasonLst, 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            : RegisterInsertDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入多条DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterInsertDefectGrpReasonLst(party router.Party, path string, method func(*models.Usertab, *[]model.DefectGrpReasonLst) error) {

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

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

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

/******************************************************************************
 *
 * @Function Name            : RegisterSelectDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterSelectDefectGrpReasonLst(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            : RegisterUpdateDefectGrpReasonLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条DefectGrpReasonLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateDefectGrpReasonLst(party router.Party, path string, method func(*models.Usertab, *[]model.DefectGrpReasonLst) error) {

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