package com.hzs.system.sys.provider;

import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.system.sys.SysRoleMenuColumn;
import com.hzs.system.sys.IMenuColumnServiceApi;
import com.hzs.system.sys.service.ISysRoleMenuColumnService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

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

/**
 * 菜单列服务
 */
@DubboService
public class MenuColumnServiceProvider implements IMenuColumnServiceApi {

    @Autowired
    private ISysRoleMenuColumnService iSysRoleMenuColumnService;

    @Override
    public R<Map<String, Integer>> queryMenuColumn(String perms, Long userId) {
        // 列权限map（key: 列名，value: 是否显示（0=显示））
        Map<String, Integer> columnMap = new HashMap<>();

        List<SysRoleMenuColumn> columnList = iSysRoleMenuColumnService.queryMenuColumn(perms, userId);
        if (CollectionUtil.isNotEmpty(columnList)) {
            for (SysRoleMenuColumn sysRoleMenuColumn : columnList) {
                columnMap.put(sysRoleMenuColumn.getMenuColumn(), sysRoleMenuColumn.getShowFlag());
            }
        }
        return R.ok(columnMap);
    }

}
