package com.yeejoin.amos.boot.module.hygf.biz.excel.impl;

import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.hygf.api.mapper.BusinessFieldMapper;
import com.yeejoin.amos.boot.module.hygf.biz.excel.service.IExportPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.context.RequestContext;

import java.util.*;

@Service
public class YsshServiceImpl implements IExportPageService {
    @Autowired
    private BusinessFieldMapper businessFieldMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Value("${admin.tourong.roleId}")
    Long tourongId;
    @Value("${admin.fawu.roleId}")
    Long fawuId;
    @Value("${admin.area.roleId}")
    Long areaId;
    @Value("${admin.zichan.roleId}")
    Long zichanId;
    @Value("${admin.delerAdmin.roleId}")
    Long delerAdminId;
    @Override
    public List<String> getStationId(Map<String, Object> filters) {
        ReginParams reginParams = JSONObject.parseObject(redisUtils.get(RedisKey.buildReginKey(RequestContext.getExeUserId(), RequestContext.getToken())).toString(), ReginParams.class);
        List<String> basicGridNodes = new ArrayList<>();
        List<Long> roleIds = new ArrayList<>();
        for (Long aLong : reginParams.getUserModel().getOrgRoleSeqs().keySet()) {
            List<Long> longs = reginParams.getUserModel().getOrgRoleSeqs().get(aLong);
            roleIds.addAll(longs);
            if (longs.contains(areaId)) {
                basicGridNodes.add("ys-area");
            }
            if (longs.contains(tourongId)) {
                basicGridNodes.add("ys-tourong");
            }
            if (longs.contains(fawuId)) {
                basicGridNodes.add("ys-fawu");
            }
            if (longs.contains(zichanId)) {
                basicGridNodes.add("ys-zichan");
            }
            if (longs.contains(delerAdminId)) {
                basicGridNodes.add("ys-tourong");
                basicGridNodes.add("ys-area");
                basicGridNodes.add("ys-fawu");
                basicGridNodes.add("ys-zichan");
            }
        }
        Map<String, Object> map = new HashMap<>();
        if(Objects.nonNull(filters)){
            map.putAll(filters);
        }
        map.put("basicGridNodes",basicGridNodes);
        map.put("type","1");
        return businessFieldMapper.getYsshStationId(map);
    }
}
