package routes

import (
	"LAPP_LF_MOM_BACKEND/container"
	"LAPP_LF_MOM_BACKEND/db"
	"LAPP_LF_MOM_BACKEND/grmi"
	"LAPP_LF_MOM_BACKEND/messaging"
	"LAPP_LF_MOM_BACKEND/rpc"
	_ "LAPP_LF_MOM_BACKEND/services/base/specifications"
	_ "LAPP_LF_MOM_BACKEND/services/log/specifications"
	_ "LAPP_LF_MOM_BACKEND/services/qm/specifications"
	"LAPP_LF_MOM_BACKEND/web/controllers"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/api"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/base"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/common"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/log"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/me"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/ods"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/om"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/pdc"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/pm"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/qm"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/report"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/wm"
	_ "LAPP_LF_MOM_BACKEND/web/controllers/ws"
	"LAPP_LF_MOM_BACKEND/web/middleware"
	"LAPP_LF_MOM_BACKEND/web/middleware/cors"
	"github.com/kataras/iris/v12"
)

// 所有的路由
func Hub(app *iris.Application) {

	/* 定义路由 */
	main := app.Party("/", cors.Mycors()).AllowMethods(iris.MethodOptions)
	//中间件，验证token和权限路径
	main.Use(middleware.ServeHTTP)

	home := main.Party("/")

	home.Get("/sysMenu", controllers.DynamicMenu) // 获取动态菜单

	// 用户API模块
	user := main.Party("/user")
	user.Post("/login", controllers.Login)            //登录
	user.Get("/plants", controllers.PlantsTable)      //车间列表
	user.Get("/getuserinfo", controllers.GetUserInfo) // 返回用户信息
	//个人中心
	user.Get("/profile", controllers.GetSysUserProfile)  //获取当前登录用户
	user.Get("/getimg", controllers.GetImg)              //重定向获取图片
	user.Post("/avatar", controllers.InsetSysUserAvatar) //上传图片
	user.Put("/pwd", controllers.SysUserUpdatePwd)       //更新密码

	//// 权限API模块
	admin := main.Party("/admin")
	{
		// 用户管理
		users := admin.Party("/users")
		users.Get("/userlist", controllers.GetSysUserList)                  // 用户列表
		users.Get("/user/{userId:string}", controllers.GetSysUser)          //获取用户
		users.Get("/urole", controllers.GetSysUserInit)                     //获取用户角色
		users.Post("/adduser", controllers.InsertSysUser)                   //添加用户
		users.Put("/upuser", controllers.UpdateSysUser)                     //更新用户
		users.Delete("/deluser/{userId:string}", controllers.DeleteSysUser) //删除用户

		//角色管理
		role := admin.Party("/role")
		role.Get("/rolelist", controllers.GetRoleList)                  // 角色报表
		role.Get("/rolebyid", controllers.GetRole)                      // 查询角色
		role.Post("/addrole", controllers.InsertRole)                   // 创建角色
		role.Put("/uprole", controllers.UpdateRole)                     // 更新角色
		role.Delete("/delrole/{roleId:string}", controllers.DeleteRole) // 删除角色

		//菜单管理
		menu := admin.Party("/menu")
		menu.Get("/menulist", controllers.GetMenuList)                                  //菜单列表
		menu.Get("/menubyid", controllers.GetMenu)                                      //by id查询
		menu.Post("/addmenu", controllers.InsertMenu)                                   //添加菜单
		menu.Put("/upmenu", controllers.UpdateMenu)                                     //更新菜单
		menu.Delete("/delmenu/{id:int}", controllers.DeleteMenu)                        //删除菜单
		menu.Get("/menuids", controllers.GetMenuIDS)                                    //通过ids查询菜单
		menu.Get("/menuTreeselect", controllers.GetMenuTreeelect)                       //获取菜单列表
		menu.Get("/roleMenuTreeselect/{roleId:int}", controllers.GetMenuTreeRoleselect) //获取菜单

		// 日志管理
		logs := admin.Party("/logs")
		logs.Get("/loglist", controllers.Loglist)

		// 翻译列表
		tabnames := admin.Party("/tabnames")
		tabnames.Post("/addinfo", controllers.TabInfo)
		tabnames.Get("/listpage", controllers.TabDataListPage)
		tabnames.Get("/list", controllers.TabDataList)
		tabnames.Get("/download", controllers.Download)
		tabnames.Delete("/del", controllers.DeleteTab)

		// 标准定义
		stdeftab := admin.Party("/stdeftab")
		stdeftab.Get("/listpage", controllers.GetStdeftabList)
		stdeftab.Get("/selectinfo", controllers.GetStdeftab)
		stdeftab.Post("/addinfo", controllers.InsertStdeftab)
		stdeftab.Delete("/del", controllers.DeleteStdeftab)
		stdeftab.Put("/upinfo", controllers.UpdateStdeftab)
		stdeftab.Get("/selectarr", controllers.SelectStdeftabArr)
		stdeftab.Get("/selectall", controllers.SelectStdeftabAll)

		// 订单流水号
		snrtab := admin.Party("/snrtab")
		snrtab.Get("/listpage", controllers.GetSnrtabList)
		snrtab.Get("/selectinfo", controllers.GetSnrtab)
		snrtab.Post("/addinfo", controllers.InsertSnrtab)
		snrtab.Delete("/del", controllers.DeleteSnrtab)
		snrtab.Put("/upinfo", controllers.UpdateSnrtab)

		// 导入表
		scripttab := admin.Party("/scripttab")
		scripttab.Get("/listpage", controllers.GetScripttabList)
		scripttab.Get("/selectinfo", controllers.GetScripttab)
		scripttab.Post("/addinfo", controllers.InsertScripttab)
		scripttab.Delete("/del", controllers.DeleteScripttab)
		scripttab.Put("/upinfo", controllers.UpdateScripttab)
		scripttab.Post("/upexcel", controllers.UpExcelScripttab)
		scripttab.Get("/selectarr", controllers.SelectArrScripttab)

		//打印机
		printertab := admin.Party("/printertab")
		printertab.Get("/listpage", controllers.GetPrintertabList)
		printertab.Get("/selectinfo", controllers.GetPrintertab)
		printertab.Post("/addinfo", controllers.InsertPrintertab)
		printertab.Delete("/del", controllers.DeletePrintertab)
		printertab.Put("/upinfo", controllers.UpdatePrintertab)

		//打印机任务
		printheadtab := admin.Party("/printheadtab")
		printheadtab.Get("/listpage", controllers.GetPrintheadtabList)
		printheadtab.Get("/selectinfo", controllers.GetPrintheadtab)
		printheadtab.Post("/addinfo", controllers.InsertPrintheadtab)
		printheadtab.Delete("/del", controllers.DeletePrintheadtab)
		printheadtab.Put("/upinfo", controllers.UpdatePrintheadtab)

		//打印明细
		printdetailtab := admin.Party("/printdetailtab")
		printdetailtab.Get("/listpage", controllers.GetPrintdetailtabList)

		//日模型
		daymodel := admin.Party("/daymodel")
		daymodel.Get("/listpage", controllers.GetDaymodelList)
		daymodel.Get("/selectinfo", controllers.GetDaymodel)
		daymodel.Post("/addinfo", controllers.InsertDaymodel)
		daymodel.Delete("/del", controllers.DeleteDaymodel)
		daymodel.Put("/upinfo", controllers.UpdateDaymodel)
		daymodel.Get("/selectarr", controllers.SelectArrDaymodel)

		//周模型
		weekmodel := admin.Party("/weekmodel")
		weekmodel.Get("/listpage", controllers.GetWeekmodelList)
		weekmodel.Get("/selectinfo", controllers.GetWeekmodel)
		weekmodel.Post("/addinfo", controllers.InsertWeekmodel)
		weekmodel.Delete("/del", controllers.DeleteWeekmodel)
		weekmodel.Put("/upinfo", controllers.UpdateWeekmodel)

		//工作日历
		workcalendar := admin.Party("/workcalendar")
		workcalendar.Get("/listpage", controllers.GetWorkcalendarList)
		workcalendar.Get("/selectinfo", controllers.GetWorkcalendar)
		workcalendar.Post("/addinfo", controllers.InsertWorkcalendar)
		workcalendar.Delete("/del", controllers.DeleteWorkcalendar)
		workcalendar.Put("/upinfo", controllers.UpdateWorkcalendar)

		//产线特殊工作日
		workline_specialday := admin.Party("/workline_specialday")
		workline_specialday.Get("/listpage", controllers.GetWorklineSpecialdayList)
		workline_specialday.Get("/selectinfo", controllers.GetWorklineSpecialday)
		workline_specialday.Post("/addinfo", controllers.InsertWorklineSpecialday)
		workline_specialday.Delete("/del", controllers.DeleteWorklineSpecialday)
		workline_specialday.Put("/upinfo", controllers.UpdateWorklineSpecialday)

		//资产类型
		pm_assettype := admin.Party("/pm_assettype")
		pm_assettype.Get("/all", controllers.GetAllPmAssettypes)
		pm_assettype.Get("/listpage", controllers.GetPmAssettypeList)
		pm_assettype.Get("/selectinfo", controllers.GetPmAssettype)
		pm_assettype.Post("/addinfo", controllers.InsertPmAssettype)
		pm_assettype.Delete("/del", controllers.DeletePmAssettype)
		pm_assettype.Put("/upinfo", controllers.UpdatePmAssettype)

		//地点定义
		pm_location := admin.Party("/pm_location")
		pm_location.Get("/listpage", controllers.GetPmLocationList)
		pm_location.Get("/selectinfo", controllers.GetPmLocation)
		pm_location.Post("/addinfo", controllers.InsertPmLocation)
		pm_location.Delete("/del", controllers.DeletePmLocation)
		pm_location.Put("/upinfo", controllers.UpdatePmLocation)
		pm_location.Get("/selectall", controllers.SelectArrPmLocation)
		pm_location.Get("/selectarr", controllers.SelectAarrPmLocations) //查询地点
		pm_location.Get("/menu_location", controllers.GetMenuPmLocation)

		//属性
		attribute := admin.Party("/attribute")
		attribute.Get("/listpage", controllers.GetAttributeList)
		attribute.Get("/selectinfo", controllers.GetAttribute)
		attribute.Put("/upinfo", controllers.UpdateAttribute)
		attribute.Post("/addinfo", controllers.InsertAttribute)
		attribute.Delete("/del", controllers.DeleteAttribute)

		//维护服务
		pm_service := admin.Party("/pm_service")
		pm_service.Get("/listpage", controllers.GetPmServiceList)
		pm_service.Get("/selectinfo", controllers.GetPmService)
		pm_service.Post("/addinfo", controllers.InsertPmService)
		pm_service.Delete("/del", controllers.DeletePmService)
		pm_service.Put("/upinfo", controllers.UpdatePmService)
		pm_service.Get("/selectall", controllers.SelectArrPmService)
		pm_service.Get("/query", controllers.SelectServiceByParam)

		//维护模板
		pm_template := admin.Party("/pm_template")
		pm_template.Get("/listpage", controllers.GetPmTemplateList)
		pm_template.Get("/selectinfo", controllers.GetPmTemplate)
		pm_template.Post("/addinfo", controllers.InsertPmTemplate)
		pm_template.Delete("/del", controllers.DeletePmTemplate)
		pm_template.Put("/upinfo", controllers.UpdatePmTemplate)
		pm_template.Get("/selectall", controllers.SelectAllPmTemplate)

		//资产定义
		pm_asset := admin.Party("/pm_asset")
		pm_asset.Get("/listpage", controllers.GetPmAssetList)
		pm_asset.Get("/selectinfo", controllers.GetPmAsset)
		pm_asset.Post("/addinfo", controllers.InsertPmAsset)
		pm_asset.Delete("/del", controllers.DeletePmAsset)
		pm_asset.Put("/upinfo", controllers.UpdatePmAsset)
		pm_asset.Get("/selectall", controllers.SelectArrPmAsset)
		pm_asset.Get("/templatearr", controllers.SelectArrPmTemplate)
		pm_asset.Get("/selectservice", controllers.GetPmAssetService)

		//维护工单
		pm_wo := admin.Party("/pm_wo")
		pm_wo.Get("/listpage", controllers.GetPmWoList)           //列表
		pm_wo.Get("/listmonthpage", controllers.GetPmWoMonthList) //日历
		pm_wo.Get("/selectone", controllers.GetPmWo)
		pm_wo.Get("/selectall", controllers.GetPmWoAll)
		pm_wo.Put("/upinfo", controllers.UpdatePmWo)
		pm_wo.Post("/insertone", controllers.InsertOnePMWO)

		//维护工单服务属性
		pm_wo_attr := admin.Party("/pm_wo_attr")
		pm_wo_attr.Put("/upinfo", controllers.UpdatePmWoAttrlst)
		pm_wo_attr.Post("/upload", controllers.UploadImgPmWoAttrlst) //上传图片

		//维护工单日志
		pm_wostatus := admin.Party("/pm_wostatus")
		pm_wostatus.Get("/listpage", controllers.GetPmWostatusList)
		pm_wostatus.Get("/selectinfo", controllers.GetPmWostatus)

		//阈值
		pm_asset_kpi := admin.Party("/pm_asset_kpi")
		pm_asset_kpi.Get("/listpage", controllers.GetPmAssetKpiList)
		pm_asset_kpi.Get("/selectinfo", controllers.GetPmAssetKpi)
		pm_asset_kpi.Put("/upinfo", controllers.UpdatePmAssetKpi)
		pm_asset_kpi.Post("/addinfo", controllers.InsertPmAssetKpi)
		pm_asset_kpi.Delete("/del", controllers.DeletePmAssetKpi)

		// etl表
		etltab := admin.Party("/etltab")
		etltab.Get("/listpage", controllers.GetEtltabList)
		etltab.Get("/selectinfo", controllers.GetEtltab)
		etltab.Post("/addinfo", controllers.InsertEtltab)
		etltab.Delete("/del", controllers.DeleteEtltab)
		etltab.Put("/upinfo", controllers.UpdateEtltab)
		etltab.Get("/selectarr", controllers.SelectArrEtltab)

		//buffer管理
		buffer := admin.Party("/buffer")
		buffer.Get("/bufferlist", controllers.Bufferlist)
		buffer.Get("/testsql", controllers.TestEtltabSql)

		// database管理
		database := admin.Party("/database")
		database.Get("/listpage", controllers.Databaselist)
		database.Get("/selectinfo", controllers.GetDatabase)
		database.Post("/addinfo", controllers.InsertDatabase)
		database.Put("/upinfo", controllers.UpdateDatabase)
		database.Delete("/del", controllers.DelDatabase)

		// etcd
		etcdtab := admin.Party("/etcdtab")
		etcdtab.Get("/listpage", controllers.GetEtcdtabList)
		etcdtab.Get("/selectinfo", controllers.GetEtcdtab)
		etcdtab.Post("/addinfo", controllers.InsertEtcdtab)
		etcdtab.Delete("/del", controllers.DeleteEtcdtab)
		etcdtab.Put("/upinfo", controllers.UpdateEtcdtab)

		messaging.BindRoutes(admin)

		grmi.BindRoutes(admin)
		transactionHandlerFactory := container.NewTransactionHandlerFactory(db.Eloquent.Master())
		container.RegisterRoutes(admin, rpc.DefaultMethodInvokerBuilder.Build, container.GlobalInformations, transactionHandlerFactory)
	}
}
