package cn.com.countrygarden.bi.main.service.insuranceOrder.impl;

import cn.com.countrygarden.bi.main.dao.insuranceOrder.InsuranceOrderMapper;
import cn.com.countrygarden.bi.main.exception.ServiceException;
import cn.com.countrygarden.bi.main.model.sys.UserRoles;
import cn.com.countrygarden.bi.main.service.insuranceOrder.insuranceOrderAuthorityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.*;

@Service
@Transactional
public class insuranceOrderAuthorityServiceImpl implements insuranceOrderAuthorityService {

    @Autowired
    private InsuranceOrderMapper insuranceOrderMapper;

    @Override
    public Map<String, Object> findRoleInfoMap(String sysUserCode) {
        Map<String, Object> map = new LinkedHashMap<>();
        if (null == sysUserCode || sysUserCode.equals("")) {
            throw new ServiceException("请登录");
        }

        List<String> rolePermissions=new ArrayList<>();

        List<UserRoles> sysUserRole=insuranceOrderMapper.selectuserRoles(sysUserCode);
        for (UserRoles userRoles : sysUserRole) {

            if (userRoles.getRoleCode().equals("admin")) {
                map.clear();
                map.put("admin", "管理员");
                break;
            }else if(userRoles.getRoleCode().equals("insurance_admin")){
                map.put("insurance_admin", "保险订单管理员");
                break;
            }else if (userRoles.getRoleCode().equals("insurance_regionUser")) {
                map.clear();
                map.put("insurance_regionUser", "保险订单区域用户");
                break;
            }else if(userRoles.getRoleCode().equals("insurance_projectUser")){
                map.put("insurance_projectUser", "保险订单项目用户");
            }
        }
        if (map.size() < 1) {
            map.put("role", "noRole");
        }
        return map;
        }

    @Override
    public List<Integer> roleInfoList(Map<String, Object> rolesMap) {
        List<Integer> paixu=new ArrayList<>();
        for (Map.Entry<String, Object> entry : rolesMap.entrySet()) {
            if(entry.getKey().equals("admin")){
                paixu.add(1);
            }
            if(entry.getKey().equals("insurance_admin")){
                paixu.add(2);
            }
            if(entry.getKey().equals("insurance_regionUser")){
                paixu.add(3);
            }
            if(entry.getKey().equals("insurance_projectUser")){
                paixu.add(4);
            }
        }
        Collections.sort(paixu);

        return paixu;
    }

}
