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.runeconomy.init.CacheContext;
import com.gyee.runeconomy.mapper.auto.ProBasicEquipmentPointMapper;
import com.gyee.runeconomy.model.auto.ProBasicEquipmentPoint;
import com.gyee.runeconomy.service.auto.IProBasicEquipmentPointService;
import com.gyee.runeconomy.util.StringUtils;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 设备测点 服务实现类
 * </p>
 *
 * @author shilin
 * @since 2022-10-31
 */
@Service
public class ProBasicEquipmentPointServiceImpl extends ServiceImpl<ProBasicEquipmentPointMapper, ProBasicEquipmentPoint> implements IProBasicEquipmentPointService {

    @Override
    public ProBasicEquipmentPoint getEquipmentPoint(String wpId, String uniformCode) {

        ProBasicEquipmentPoint point = new ProBasicEquipmentPoint();
        if (StringUtils.notEmp(wpId) && StringUtils.notEmp(uniformCode)) {
            if (CacheContext.wtmap.containsKey(wpId)) {
                if (CacheContext.wtpAimap.containsKey(wpId)) {
                    Map<String, ProBasicEquipmentPoint> map = CacheContext.wtpAimap.get(wpId);
                    if (map.containsKey(uniformCode)) {
                        point = map.get(uniformCode);
                    }
                }
            }
        }
        return point;
    }


    @Override
    public List<ProBasicEquipmentPoint> selectList(String station, List<String> points) {
        List<ProBasicEquipmentPoint> list = new ArrayList();
        QueryWrapper<ProBasicEquipmentPoint> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(ProBasicEquipmentPoint::getWindpowerstationId, station).in(ProBasicEquipmentPoint::getUniformCode,points);

        try{
            list = baseMapper.selectList(wrapper);
        }catch (Exception e){
            log.error("ProBasicEquipmentPoint--selectList", e);
        }

        return list;
    }
}
