package cn.cecep.talroad.service.impl.analysis;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import cn.cecep.talroad.common.core.utils.DateUtils;
import cn.cecep.talroad.common.core.web.domain.AjaxResults;
import cn.cecep.talroad.domain.analysis.SRaRealTimeAnalysicComsitMonitor;
import cn.cecep.talroad.mapper.analysis.SRaRealTimeAnalysicComsitMonitorMapper;
import cn.cecep.talroad.service.analysis.ISRaRealTimeAnalysicComsitMonitorService;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;




/**
 * 关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位Service业务层处理
 *
 * @author szhpt
 * @date 2023-07-14*/
@Service
public class SRaRealTimeAnalysicComsitMonitorServiceImpl extends ServiceImpl<SRaRealTimeAnalysicComsitMonitorMapper,SRaRealTimeAnalysicComsitMonitor> implements ISRaRealTimeAnalysicComsitMonitorService
{
    @Autowired
    private SRaRealTimeAnalysicComsitMonitorMapper sRaRealTimeAnalysicComsitMonitorMapper;
    @Autowired
    private ISRaRealTimeAnalysicComsitMonitorService sRaRealTimeAnalysicComsitMonitorService;

    /**
     * 查询关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位列表
     *
     * @param sRaRealTimeAnalysicComsitMonitor 关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位
     * @return 关联分析系统-企业生产过程分析-监测点位对比分析-分组关联点位
     */
    @Override
    public List<SRaRealTimeAnalysicComsitMonitor> selectSRaRealTimeAnalysicComsitMonitorList(SRaRealTimeAnalysicComsitMonitor sRaRealTimeAnalysicComsitMonitor)
    {
        return sRaRealTimeAnalysicComsitMonitorMapper.selectSRaRealTimeAnalysicComsitMonitorList(sRaRealTimeAnalysicComsitMonitor);
    }

    @Override
    public AjaxResults<Boolean> addComsitMonitor(SRaRealTimeAnalysicComsitMonitor sRaRealTimeAnalysicComsitMonitor) {
        List<SRaRealTimeAnalysicComsitMonitor> list=new ArrayList<>();
        List<String> list1 = Arrays.asList(sRaRealTimeAnalysicComsitMonitor.getMonitorId().split(","));
//        sRaRealTimeAnalysicComsitMonitorService.remove(new QueryWrapper<SRaRealTimeAnalysicComsitMonitor>().eq("comsit_id",sRaRealTimeAnalysicComsitMonitor.getComsitId()));
        list1.forEach(item->{
            SRaRealTimeAnalysicComsitMonitor monitor=new SRaRealTimeAnalysicComsitMonitor();
            monitor.setDataId(BigInteger.valueOf(IdUtil.getSnowflakeNextId()));
            monitor.setMonitorId(item);
            monitor.setCreateTime(new Date());
            monitor.setComsitId(sRaRealTimeAnalysicComsitMonitor.getComsitId());
            list.add(monitor);
        });
        return AjaxResults.success(sRaRealTimeAnalysicComsitMonitorService.saveBatch(list));
    }
}
