package com.gyee.runeconomy.service.auto.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gyee.common.model.StringUtils;
import com.gyee.runeconomy.init.CacheContext;
import com.gyee.runeconomy.mapper.auto.ProBasicPowerstationPointMapper;
import com.gyee.runeconomy.model.auto.ProBasicPowerstationPoint;
import com.gyee.runeconomy.service.auto.IProBasicPowerstationPointService;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 场站测点，期次测点，线路测点，三级公司测点，区域测点
 * <p>
 * <p>
 * <p>
 * +方阵测点 服务实现类
 * </p>
 *
 * @author shilin
 * @since 2022-10-31
 */
@Service
public class ProBasicPowerstationPointServiceImpl extends ServiceImpl<ProBasicPowerstationPointMapper, ProBasicPowerstationPoint> implements IProBasicPowerstationPointService {

    @Override
    public List<ProBasicPowerstationPoint> getProBasicPowerstationPointList(String windpowerstationId, String uniformCode) {

        QueryWrapper<ProBasicPowerstationPoint> qw = new QueryWrapper<>();

        if (StringUtils.isNotEmpty(windpowerstationId)) {
            qw.lambda().eq(ProBasicPowerstationPoint::getWindpowerstationId, windpowerstationId);
        }
        if (StringUtils.isNotEmpty(uniformCode)) {
            qw.lambda().eq(ProBasicPowerstationPoint::getUniformCode, uniformCode);
        }
        List<ProBasicPowerstationPoint> list = baseMapper.selectList(qw);

        return list;
    }

    @Override
    public ProBasicPowerstationPoint getPowerstationPoint(String wpId, String uniformCode) {
        ProBasicPowerstationPoint point = new ProBasicPowerstationPoint();

        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(uniformCode)) {
            if (wpId.endsWith("0") || wpId.endsWith("-1") || wpId.endsWith("-2") || CacheContext.wpmap.containsKey(wpId)) {
                if (CacheContext.wppointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.wppointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                } else if (CacheContext.subwppointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.subwppointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                } else if (CacheContext.weatherwppointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.weatherwppointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                } else if (CacheContext.companypointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.companypointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                } else if (CacheContext.regionpointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.regionpointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                } else if (CacheContext.grouppointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.grouppointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                }
            } else if (CacheContext.pjmap.containsKey(wpId)) {
                if (CacheContext.propointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.propointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                }
            } else if (CacheContext.lnmap.containsKey(wpId)) {
                if (CacheContext.linepointmap.containsKey(wpId)) {
                    Map<String, ProBasicPowerstationPoint> map = CacheContext.linepointmap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                }
            } else if (CacheContext.weatherwppointmap.containsKey(wpId)) {
                Map<String, ProBasicPowerstationPoint> map = CacheContext.weatherwppointmap.get(wpId);
                if (map.containsKey(uniformCode)) {
                    point = map.get(uniformCode);
                }
            }
        }


        return point;
    }
}
