package com.ho.business.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ho.business.entity.Convert;
import com.ho.business.mapper.ConvertMapper;
import com.ho.business.service.ConvertService;
import com.ho.business.vo.req.colCount.ColCountReq;
import com.ho.common.tools.exception.BaseResponseCode;
import com.ho.common.tools.exception.BusinessException;
import com.ho.common.tools.util.PageResult;
import com.ho.common.tools.util.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author yy
 * @description 针对表【convert】的数据库操作Service实现
 * @createDate 2023-07-11 15:12:50
 */
@Service
@Slf4j
public class ConvertServiceImpl implements ConvertService {
    @Autowired
    ConvertMapper convertMapper;

    @Override
    public void add(Convert vo) {
        //新增时，先判断是否存在
        List<Convert> list = convertMapper.selectByStationIdAndCol(vo.getStationId(), vo.getCol());
        if(list.isEmpty()){
            convertMapper.insertSelective(vo);
        }else{
            //该遥测点已经配置为遥信点
            throw new BusinessException(BaseResponseCode.TELEMETRY_POINT_CONFIGURED_REMOTE_SIGNAL);
        }
    }


    @Override
    public void delete(Integer id) {
        convertMapper.delete(id);
    }

    @Override
    public PageResult<Convert> getPageList(ColCountReq vo) {
        PageHelper.startPage(vo.getPageNum(), vo.getPageSize());
        List<Convert> list = convertMapper.selectByParam(vo);
        return PageUtils.getPageResult(new PageInfo<>(list));
    }

    @Override
    public List<Convert> selectByStationIdAndCol(Integer stationId, String col) {
        List<Convert> list = convertMapper.selectByStationIdAndCol(stationId, col);
        return list;
    }


    @Override
    public List<String> selectByCols(Integer stationId,Integer srcId, List<String> cols) {
        List<String> list = convertMapper.selectByCols(stationId, srcId, cols);
        return list;
    }
}




