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.dto.WorkOrderPage;
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 BwysServiceImpl implements IExportPageService {
    @Autowired
    private BusinessFieldMapper businessFieldMapper;
    @Autowired
    private RedisUtils redisUtils;
    @Value("${admin.engineering.roleId}")
    Long engineeringId;
    @Value("${admin.area.roleId}")
    Long areaId;
    @Value("${admin.design.roleId}")
    Long designId;
    @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("bw-area");
            }
            if (longs.contains(engineeringId)) {
                basicGridNodes.add("bw-engineering");
            }
            if (longs.contains(designId)) {
                basicGridNodes.add("bw-design");
            }
            if (longs.contains(delerAdminId)) {
                basicGridNodes.add("bw-design");
                basicGridNodes.add("bw-engineering");
                basicGridNodes.add("bw-area");
            }
        }
        Map<String, Object> map = new HashMap<>();
        if (Objects.nonNull(filters)) {
            map.putAll(filters);
        }
        map.put("basicGridNodes", basicGridNodes);
        map.put("type", "1");
        return businessFieldMapper.getBwysStationId(map);
    }
}
