package com.dcs.hnyz.service.impl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dcs.common.core.page.TableDataInfo;
import com.dcs.common.enums.GeneralStatus;
import com.dcs.common.utils.DateUtils;
import com.dcs.common.utils.bean.BeanUtils;
import com.dcs.hnyz.domain.vo.PipeLineInstanceFormVO;
import com.dcs.hnyz.service.IFlowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dcs.hnyz.mapper.PipelineInstanceMapper;
import com.dcs.hnyz.domain.PipelineInstance;
import com.dcs.hnyz.service.IPipelineInstanceService;

import javax.annotation.Resource;

import static oshi.software.os.linux.LinuxOperatingSystem.getPageSize;

/**
 * 管道实例管理Service业务层处理
 * 
 * @author hmy
 * @date 2025-07-04
 */
@Service
public class PipelineInstanceServiceImpl implements IPipelineInstanceService 
{
    @Resource
    private PipelineInstanceMapper pipelineInstanceMapper;

    @Resource
    private IFlowService flowService;

    /**
     * 查询管道实例管理
     * 
     * @param id 管道实例管理主键
     * @return 管道实例管理
     */
    @Override
    public PipelineInstance selectPipelineInstanceById(Long id)
    {
        return pipelineInstanceMapper.selectById(id);
    }

    /**
     * 查询管道实例管理列表
     * 
     * @param pipelineInstance 管道实例管理
     * @return 管道实例管理
     */
    @Override
    public List<PipeLineInstanceFormVO> selectPipelineInstanceList(PipelineInstance pipelineInstance)
    {
        return pipelineInstanceMapper.selectPipelineInstanceList(pipelineInstance);
    }

    /**
     * 新增管道实例管理
     * 
     * @param pipelineInstance 管道实例管理
     * @return 结果
     */
    @Override
    public int insertPipelineInstance(PipelineInstance pipelineInstance)
    {
//        pipelineInstance.setCreateTime(DateUtils.getNowDate());
        return pipelineInstanceMapper.insert(pipelineInstance);
    }

    /**
     * 修改管道实例管理
     * 
     * @param pipelineInstance 管道实例管理
     * @return 结果
     */
    @Override
    public int updatePipelineInstance(PipelineInstance pipelineInstance)
    {
//        pipelineInstance.setUpdateTime(DateUtils.getNowDate());
        return pipelineInstanceMapper.updateById(pipelineInstance);
    }

    /**
     * 批量删除管道实例管理
     * 
     * @param ids 需要删除的管道实例管理主键
     * @return 结果
     */
    @Override
    public int deletePipelineInstanceByIds(Long[] ids)
    {
        return pipelineInstanceMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除管道实例管理信息
     * 
     * @param id 管道实例管理主键
     * @return 结果
     */
    @Override
    public int deletePipelineInstanceById(Long id)
    {
        return pipelineInstanceMapper.deleteById(id);
    }

    @Override
    public List<PipelineInstance> getListByPageId(Long pageId) {
        LambdaQueryWrapper<PipelineInstance> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PipelineInstance::getPageId,pageId);
        wrapper.eq(PipelineInstance::getStatus, GeneralStatus.ENABLE.getCode());
        return pipelineInstanceMapper.selectList(wrapper);
    }
}
