package com.dcs.dcs.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.dcs.hnyz.domain.Equipment;
import com.dcs.hnyz.service.IEquipmentService;
import org.springframework.stereotype.Service;
import com.dcs.dcs.mapper.DcsFlowMapper;
import com.dcs.dcs.domain.DcsFlow;
import com.dcs.dcs.service.IDcsFlowService;

import javax.annotation.Resource;

/**
 * 流程Service业务层处理
 * 
 * @author hmy
 * @date 2025-03-08
 */
@Service
public class DcsFlowServiceImpl implements IDcsFlowService 
{
    @Resource
    private DcsFlowMapper dcsFlowMapper;
    @Resource
    private IEquipmentService equipmentService;

    /**
     * 查询流程
     * 
     * @param flowId 流程主键
     * @return 流程
     */
    @Override
    public DcsFlow selectDcsFlowByFlowId(Long flowId)
    {
        return dcsFlowMapper.selectDcsFlowByFlowId(flowId);
    }

    /**
     * 查询流程列表
     * 
     * @param dcsFlow 流程
     * @return 流程
     */
    @Override
    public List<DcsFlow> selectDcsFlowList(DcsFlow dcsFlow)
    {
        return dcsFlowMapper.selectDcsFlowList(dcsFlow);
    }

    /**
     * 新增流程
     * 
     * @param dcsFlow 流程
     * @return 结果
     */
    @Override
    public int insertDcsFlow(DcsFlow dcsFlow)
    {
        return dcsFlowMapper.insertDcsFlow(dcsFlow);
    }

    /**
     * 修改流程
     * 
     * @param dcsFlow 流程
     * @return 结果
     */
    @Override
    public int updateDcsFlow(DcsFlow dcsFlow)
    {
        return dcsFlowMapper.updateDcsFlow(dcsFlow);
    }

    /**
     * 批量删除流程
     * 
     * @param flowIds 需要删除的流程主键
     * @return 结果
     */
    @Override
    public int deleteDcsFlowByFlowIds(Long[] flowIds)
    {
        return dcsFlowMapper.deleteDcsFlowByFlowIds(flowIds);
    }

    /**
     * 删除流程信息
     * 
     * @param flowId 流程主键
     * @return 结果
     */
    @Override
    public int deleteDcsFlowByFlowId(Long flowId)
    {
        return dcsFlowMapper.deleteDcsFlowByFlowId(flowId);
    }

    public String selectFlowNameByFlowId(Long valueOf) {
        return dcsFlowMapper.selectFlowNameByFlowId(valueOf);
    }

    /**
     * 通过设备id获取流程列表
     * @param equipmentId
     * @return
     */
    @Override
    public List<DcsFlow> getFlowListByEquipmentId(Long equipmentId) {
        if(equipmentId==null){//不传设备id时默认查全部
            return dcsFlowMapper.selectDcsFlowList(null);
        }
        Equipment e = equipmentService.selectEquipmentByEquipmentId(equipmentId);
        String flowIds = e.getFlowIds();//获取流程ids
        List<DcsFlow> list=new ArrayList<>();
        for (String s : flowIds.split(",")) {
            DcsFlow dcsFlow = dcsFlowMapper.selectDcsFlowByFlowId(Long.valueOf(s));
            list.add(dcsFlow);
        }
        return list;
    }
}
