package cn.superdesk.uniorder.dubbo.provider.sys.role;

import cn.superdesk.uniorder.dao.entity.sys.SysUser;
import cn.superdesk.uniorder.dto.vo.sys.role.ViewMenuTree;
import cn.superdesk.uniorder.dto.vo.sys.role.ViewRoleMenu;
import cn.superdesk.uniorder.dubbo.facade.sys.role.DubboSysMenuService;
import cn.superdesk.uniorder.service.sys.SysUserService;
import cn.superdesk.uniorder.service.sys.role.SysMenuService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(version = "1.0.0", retries = -1, timeout = 10000)
public class DubboSysMenuServiceImpl implements DubboSysMenuService {

	@Autowired
	private SysUserService sysUserService;
	@Autowired
	private SysMenuService sysMenuService;

//	@Override
//	public List<SysMenuVO> GetMenuByUserRole(Long userId) {
//
//		SysUser user =  userService.findById(userId);
//		if(user.getUserName().equals("admin")) {
//			Map<String,Object> queryMap = new HashMap<String,Object>();
//			queryMap.put("menuType", 1);
//			List<SysMenu> sysMenus= menuService.findAll(queryMap);
//			List<SysMenuVO> sysMenuVos = AnConvertBeanUtil.copyListBeanToList(sysMenus, SysMenuVO.class);
//			for (SysMenuVO sysMenuVo : sysMenuVos) {
//				Map<String,Object> tempMap = new HashMap<String,Object>();
//				tempMap.put("menuType", 2);
//				tempMap.put("pid", sysMenuVo.getId());
//				sysMenuVo.setChildMenus(menuService.findAll(tempMap));
//			}
//			return sysMenuVos;
//			
//		}else {	
//			List<SysMenu> sysMenus= menuService.findUserMenuParent(user.getRoleId());
//			List<SysMenuVO> sysMenuVos = AnConvertBeanUtil.copyListBeanToList(sysMenus, SysMenuVO.class);
//			for (SysMenuVO sysMenuVo : sysMenuVos) {
//				Map<String,Object> tempMap = new HashMap<String,Object>();
//				tempMap.put("menuType", 2);
//				tempMap.put("roleId", user.getRoleId());
//				tempMap.put("pid", sysMenuVo.getId());
//				sysMenuVo.setChildMenus(menuService.findAllByRole(tempMap));
//			}
//			return sysMenuVos;
//		}
//	}

	@Override
	public List<ViewMenuTree> getTreeById(Long id) {

		return sysMenuService.getTreeByIdNew(id);

	}

	@Override
	public List<ViewMenuTree> getTreeByUserId(Long userId) {

		SysUser sysUser = sysUserService.findById(userId);
		if (sysUser.getUserName().equals("admin")) {
			return sysMenuService.getTreeByIdNew(null);
		} else {
			return sysMenuService.getTreeByRoleId(sysUser.getRoleId());
		}

	}

	@Override
	public List<ViewMenuTree> getTreeByRoleId(Long roleId) {

		return sysMenuService.getTreeByRoleId(roleId);
	}

	@Override
	public List<ViewRoleMenu> getDataByUser(Long roleId) {

		//SysUser user = userService.findById(userId);

		return sysMenuService.getDataByRoleId(roleId);
	}


}
