/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.cqcis.com</a>
 */
package com.crunii.micro.service.sysmgr.controller;

import com.crunii.micro.common.dto.CBTree;
import com.crunii.micro.common.dto.PageRsp;
import com.crunii.micro.common.dto.Result;
import com.crunii.micro.domain.dto.Worker;
import com.crunii.micro.domain.entity.main.TsmMenu;
import com.crunii.micro.domain.entity.main.TsmRole;
import com.crunii.micro.domain.entity.main.TsmRoleApp;
import com.crunii.micro.service.sysmgr.dto.sysmgr.*;
import com.crunii.micro.service.sysmgr.service.AuthService;
import com.crunii.micro.web.mvc.CurrWorker;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author 田平 create 2023-02-21 10:48:00
 */
@Api(value = "权限相关")
@Controller
@RequestMapping("/auth/AuthController")
public class AuthController {
	@Autowired
	private AuthService authService;

	@ApiOperation(value = "获取用户的角色（只需要传token）")
	@RequestMapping(path = "/getAuthRoles", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<TsmRole>> getAuthRoles(@CurrWorker @ApiIgnore Worker worker) {
		Result<List<TsmRole>> result = new Result<>();
		result.setData(authService.getAuthRoles(worker.getLoginId()));
		return result;
	}

	@ApiOperation(value = "获取用户的菜单（只需要传token）")
	@RequestMapping(path = "/getAuthMenus", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<TsmMenu>> getAuthMenus(@CurrWorker @ApiIgnore Worker worker) {
		Result<List<TsmMenu>> result = new Result<>();
		result.setData(authService.getAuthMenus(worker.getLoginId()));
		return result;
	}

	@ApiOperation(value = "获取用户的角色CheckBox列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "loginId", value = "员工ID", required = true)
	})
	@RequestMapping(path = "/getCheckedAuthRole", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<AuthRoleCB>> getCheckedAuthRole(int loginId) {
		Result<List<AuthRoleCB>> result = new Result<>();
		result.setData(authService.getCheckedAuthRole(loginId));
		return result;
	}

	@ApiOperation(value = "获取角色的Url组的CheckBox列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "roleId", value = "角色ID", required = true)
	})
	@RequestMapping(path = "/getCheckedRoleUrlGroup", method = RequestMethod.GET)
	@ResponseBody
	public Result<List<RoleUrlGroupCB>> getCheckedRoleUrlGroup(int roleId) {
		Result<List<RoleUrlGroupCB>> result = new Result<>();
		result.setData(authService.getCheckedRoleUrlGroup(roleId));
		return result;
	}

	@ApiOperation(value = "获取用户的菜单权限CheckBox树")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "loginId", value = "员工ID", required = true)
	})
	@RequestMapping(path = "/getCheckedAuthTreeNode", method = RequestMethod.GET)
	@ResponseBody
	public Result<CBTree> getCheckedAuthTreeNode(int loginId) {
		Result<CBTree> result = new Result<>();
		result.setData(authService.getCheckedAuthTreeNode(loginId));
		return result;
	}

	@ApiOperation(value = "获取角色的菜单权限CheckBox树")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "roleId", value = "角色ID", required = true)
	})
	@RequestMapping(path = "/getCheckedRoleTreeNode", method = RequestMethod.GET)
	@ResponseBody
	public Result<CBTree> getCheckedRoleTreeNode(int roleId) {
		Result<CBTree> result = new Result<>();
		result.setData(authService.getCheckedRoleTreeNode(roleId));
		return result;
	}

	@ApiOperation(value = "获取角色的按钮权限CheckBox树")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "roleId", value = "角色ID", required = true)
	})
	@RequestMapping(path = "/getRoleBtnTreeNode", method = RequestMethod.GET)
	@ResponseBody
	public Result<CBTree> getRoleBtnTreeNode(int roleId) {
		Result<CBTree> result = new Result<>();
		result.setData(authService.getRoleBtnTreeNode(roleId));
		return result;
	}

	@ApiOperation(value = "员工关联角色")
	@RequestMapping(path = "/doWorkerRelaRole", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> doWorkerRelaRole(@RequestBody @ApiParam WorkerRelaRole workerRelaRole) {
		Result<String> result = new Result<>();
		authService.doWorkerRelaRole(workerRelaRole);
		return result;
	}

	@ApiOperation(value = "角色关联Url组")
	@RequestMapping(path = "/doRoleRelaUrlGroup", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> doRoleRelaUrlGroup(@RequestBody @ApiParam RoleRelaUrlGroup roleRelaUrlGroup) {
		Result<String> result = new Result<>();
		authService.doRoleRelaUrlGroup(roleRelaUrlGroup);
		return result;
	}

	@ApiOperation(value = "角色关联菜单")
	@RequestMapping(path = "/doRoleRelaMenu", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> doRoleRelaMenu(@RequestBody @ApiParam RoleRelaMenu roleRelaMenu) {
		Result<String> result = new Result<>();
		authService.doRoleRelaMenu(roleRelaMenu);
		return result;
	}

	@ApiOperation(value = "角色关联按钮")
	@RequestMapping(path = "/doRoleRelaButton", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> doRoleRelaButton(@RequestBody @ApiParam RoleButton roleRelaMenu) {
		Result<String> result = new Result<>();
		authService.doRoleRelaButton(roleRelaMenu);
		return result;
	}

	@ApiOperation(value = "角色关联应用")
	@RequestMapping(path = "/doRoleAssociationApp", method = RequestMethod.POST)
	@ResponseBody
	public Result<String> doRoleAssociationApp(@RequestBody @ApiParam RoleApp roleApp) {
		Result<String> result = new Result<>();
		authService.doRoleAssociationApp(roleApp);
		return result;
	}
//
//	@ApiOperation(value = "获取用户所拥有的app按钮")
//	@RequestMapping(path = "/getBtnIds", method = RequestMethod.GET)
//	@ResponseBody
//	public Result<List<String>> getBtnIds(@CurrWorker Worker worker) {
//		Result<String> result = new Result<>();
//		authService.doRoleRelaMenu(roleRelaMenu);
//		return result;
//	}

}
