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

import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRole;
import cn.superdesk.uniorder.dao.entity.sys.role.SysRoleMenuKey;
import cn.superdesk.uniorder.dto.vo.sys.role.ViewRole;
import cn.superdesk.uniorder.dto.vo.sys.role.ViewRoleMenu;
import cn.superdesk.uniorder.dubbo.facade.sys.role.DubboSysRoleService;
import cn.superdesk.uniorder.service.sys.role.SysRoleMenuService;
import cn.superdesk.uniorder.service.sys.role.SysRoleService;
import cn.superdesk.uniorder.common.numerical.AnConvertBeanUtil;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

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

	@Autowired
	private SysRoleService     sysRoleService;
	@Autowired
	private SysRoleMenuService sysRoleMenuService;

	@Override
	public ViewRole findById(Long id) {

		SysRole role = sysRoleService.findById(id);
		if (role == null) return null;
		ViewRole            vr       = AnConvertBeanUtil.copyBean(role, ViewRole.class);
		Map<String, Object> queryMap = new HashMap<>();
		queryMap.put("roleId", id);
		List<ViewRoleMenu> menus = sysRoleMenuService.findAllView(queryMap);
		vr.setMenus(menus);
		return vr;
	}

	@Override
	public SysRole add(SysRole role, List<SysRoleMenuKey> ls) {


		return sysRoleService.addObjTran(role, ls);
	}

	@Override
	public void edit(SysRole role, List<SysRoleMenuKey> ls) {

		sysRoleService.updateObjTran(role, ls);
	}


	@Override
	public void delete(Long roleId) {
		sysRoleService.deleteTran(roleId);
	}

	@Override
	public R<List<SysRole>> findAllPage(Map<String, Object> params, int pageNo, int pageSize) {

		return sysRoleService.findAllPage(params, pageNo, pageSize);
	}
}
