package org.springblade.flow.permission.controller;

import org.springblade.flow.base.ActionResult;
import org.springblade.flow.database.exception.DataException;
import org.springblade.flow.permission.entity.Role4FlowEntity;
import org.springblade.flow.permission.model.role.RoleInfoVO;
import org.springblade.flow.permission.service.Role4FlowService;
import org.springblade.flow.util.JsonUtilEx;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.hutool.core.lang.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 *  数据处理
 *
 * @author william
 * @date   2022-07-14 10:57:53
 */
@Api(tags = "角色管理", value = "Role")
@RestController
@RequestMapping("/paas/permission/Role")
public class Role4FlowController {
	@Autowired
	private Role4FlowService roleService;

//	@ApiOperation("获取角色列表")
//	@GetMapping
//	public ActionResult<RoleListVO> list(Page page) {
//		List<RoleEntity> data = roleService.getList(page);
//		List<String> type = data.stream().map(t -> t.getType()).distinct().collect(Collectors.toList());
//		List<DictionaryDataEntity> typeList = dataService.getDictionName(type);
//		List<RoleModel> modelAll = new LinkedList<>();
//		for (DictionaryDataEntity entity : typeList) {
//			RoleModel model = new RoleModel();
//			model.setFullName(entity.getFullName());
//			model.setId(entity.getId());
//			Long num = data.stream().filter(t -> t.getType().equals(entity.getEnCode())).count();
//			model.setNum(num);
//			modelAll.add(model);
//		}
//		for (RoleEntity entity : data) {
//			RoleModel model = JsonUtil.getJsonToBean(entity, RoleModel.class);
//			DictionaryDataEntity dataEntity = typeList.stream().filter(t -> t.getEnCode().equals(entity.getType()))
//					.findFirst().orElse(null);
//			if (dataEntity != null) {
//				model.setParentId(dataEntity.getId());
//				modelAll.add(model);
//			}
//		}
//		List<SumTree<RoleModel>> trees = TreeDotUtils.convertListToTreeDot(modelAll);
//		List<RoleListVO> list = JsonUtil.getJsonToList(trees, RoleListVO.class);
//		ListVO vo = new ListVO();
//		vo.setList(list);
//		return ActionResult.success(vo);
//	}

	/**
	 * 角色下拉框列表
	 *
	 * @return
	 */
	@ApiOperation("角色下拉框列表")
	@GetMapping("/Selector")
	public ActionResult listAll() {
		return ActionResult.success(Dict.create().set("list", roleService.getTreeList()));
	}

	/**
	 * 获取角色信息
	 *
	 * @param id 主键值
	 * @return
	 */
	@ApiOperation("获取角色信息")
	@GetMapping("/{id}")
	public ActionResult<RoleInfoVO> getInfo(@PathVariable("id") String id) throws DataException {
		Role4FlowEntity entity = roleService.getInfo(id);
		RoleInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, RoleInfoVO.class);
		return ActionResult.success(vo);
	}

}
