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.mapper.auto.ProEconPowerFittingAnalySisMapper;
import com.gyee.runeconomy.model.auto.ProEconPowerFittingAnalySis;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author chenmh
 * @since 2023-09-24
 */
@Service
public class ProEconPowerFittingAnalySisServiceImpl extends ServiceImpl<ProEconPowerFittingAnalySisMapper, ProEconPowerFittingAnalySis> implements ProEconPowerFittingAnalySisService {

    @Override
    public ProEconPowerFittingAnalySis selectItemById(String id) {
        ProEconPowerFittingAnalySis obj = new ProEconPowerFittingAnalySis();

        QueryWrapper<ProEconPowerFittingAnalySis> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        try{
            obj = baseMapper.selectOne(wrapper);
        }catch (Exception e){
            log.error("PowerfittinganalysisServiceImpl--selectItemById", e);
        }

        return obj;
    }

    @Override
    public ProEconPowerFittingAnalySis delete(String time, String fileName) {
        QueryWrapper<ProEconPowerFittingAnalySis> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("time",time);
        queryWrapper.eq("path", fileName);
        int delete = baseMapper.delete(queryWrapper);
        return null;
    }

    @Override
    public List<ProEconPowerFittingAnalySis> selectList(List<String> stations,String type) {
        List<ProEconPowerFittingAnalySis> list = new ArrayList();

        QueryWrapper<ProEconPowerFittingAnalySis> wrapper = new QueryWrapper<>();
        wrapper.eq("type", type);


        wrapper.in("station", stations);

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

        return list;
    }

//    @Override
//    public void insertItem(ProEconPowerFittingAnalySis obj) {
//        if (obj == null)
//            return;
//
//        obj.setId(SnowFlakeUtil.generateId());
//        try{
//            baseMapper.insert(obj);
//        }catch (Exception e){
//            log.error("PowerfittinganalysisServiceImpl--insertItem", e);
//        }
//    }

    @Override
    public List<ProEconPowerFittingAnalySis> selectListByIds(String ids) {
        try{
            return baseMapper.selectBatchIds(Arrays.asList(ids.split(",")));
        }catch (Exception e){
            log.error("PowerfittinganalysisServiceImpl--selectListByIds", e);
        }

        return Collections.EMPTY_LIST;
    }

    @Override
    public void deleteList(String ids) {
        try{
            baseMapper.deleteBatchIds(Arrays.asList(ids.split(",")));
        }catch (Exception e){
            log.error("PowerfittinganalysisServiceImpl--deleteList", e);
        }
    }

    @Override
    public List<ProEconPowerFittingAnalySis> selectListByIsCal(String type, int isCal) {
        QueryWrapper<ProEconPowerFittingAnalySis> wrapper = new QueryWrapper<>();
        wrapper.eq("type", type);
        wrapper.eq("iscal", isCal);
        try{
            return baseMapper.selectList(wrapper);
        }catch (Exception e){
            log.error("PowerfittinganalysisServiceImpl--selectListByIsCal", e);
        }

        return Collections.EMPTY_LIST;
    }
}
