package com.ho.business.service.impl;

import com.ho.business.entity.PageConfig;
import com.ho.business.mapper.PageConfigMapper;
import com.ho.business.service.PageConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yy
 * @description 针对表【page_config】的数据库操作Service实现
 * @createDate 2023-08-08 14:08:50
 */
@Service
@Slf4j
public class PageConfigServiceImpl implements PageConfigService {
    @Autowired
    PageConfigMapper pageConfigMapper;


    @Override
    public int addBatch(List<PageConfig> configList) {
        for (PageConfig pageConfig : configList) {
            String deviceType = pageConfig.getDeviceType();
            String substring2 = deviceType.substring(deviceType.lastIndexOf("_")+1);
            pageConfig.setStationId( Integer.valueOf(substring2));
        }
        List<Integer> ids = configList.stream().map(PageConfig::getId).collect(Collectors.toList());
        int result = 0;
        try {
            result = pageConfigMapper.deleteBatch(ids);
            if(result>=0){
                result = pageConfigMapper.addBatch(configList);
            }
        }catch (Exception e){
            e.printStackTrace();
            log.info("模型设备关联管理增加报错,{}",e.getMessage());
        }
        return result;
    }

    @Override
    public List<PageConfig> selectPage(PageConfig vo) {
        List<PageConfig> list = pageConfigMapper.selectPage(vo);
        return list;
    }

    @Override
    public int delete(List<Integer> ids) {
        int i = pageConfigMapper.deleteBatch(ids);
        return i;
    }

    @Override
    public int deleteStationId(Integer stationId) {
        int i = pageConfigMapper.deleteStationId(stationId);
        return i;
    }
}




