package com.fs.provider.service.impl;

import java.util.Collections;
import java.util.List;
import com.fs.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.provider.mapper.ServiceOrderTaskRelMapper;
import com.fs.provider.domain.ServiceOrderTaskRel;
import com.fs.provider.service.IServiceOrderTaskRelService;

/**
 * 服务单-任务关联Service业务层处理
 * 
 * @author fs
 * @date 2026-01-26
 */
@Service
public class ServiceOrderTaskRelServiceImpl implements IServiceOrderTaskRelService 
{
    @Autowired
    private ServiceOrderTaskRelMapper serviceOrderTaskRelMapper;

    /**
     * 查询服务单-任务关联
     * 
     * @param id 服务单-任务关联主键
     * @return 服务单-任务关联
     */
    @Override
    public ServiceOrderTaskRel selectServiceOrderTaskRelById(Long id)
    {
        return serviceOrderTaskRelMapper.selectServiceOrderTaskRelById(id);
    }

    /**
     * 查询服务单-任务关联列表
     * 
     * @param serviceOrderTaskRel 服务单-任务关联
     * @return 服务单-任务关联
     */
    @Override
    public List<ServiceOrderTaskRel> selectServiceOrderTaskRelList(ServiceOrderTaskRel serviceOrderTaskRel)
    {
        return serviceOrderTaskRelMapper.selectServiceOrderTaskRelList(serviceOrderTaskRel);
    }

    /**
     * 新增服务单-任务关联
     * 
     * @param serviceOrderTaskRel 服务单-任务关联
     * @return 结果
     */
    @Override
    public int insertServiceOrderTaskRel(ServiceOrderTaskRel serviceOrderTaskRel)
    {
        serviceOrderTaskRel.setCreateTime(DateUtils.getNowDate());
        return serviceOrderTaskRelMapper.insertServiceOrderTaskRel(serviceOrderTaskRel);
    }

    /**
     * 修改服务单-任务关联
     * 
     * @param serviceOrderTaskRel 服务单-任务关联
     * @return 结果
     */
    @Override
    public int updateServiceOrderTaskRel(ServiceOrderTaskRel serviceOrderTaskRel)
    {
        serviceOrderTaskRel.setUpdateTime(DateUtils.getNowDate());
        return serviceOrderTaskRelMapper.updateServiceOrderTaskRel(serviceOrderTaskRel);
    }

    /**
     * 批量删除服务单-任务关联
     * 
     * @param ids 需要删除的服务单-任务关联主键
     * @return 结果
     */
    @Override
    public int deleteServiceOrderTaskRelByIds(Long[] ids)
    {
        return serviceOrderTaskRelMapper.deleteServiceOrderTaskRelByIds(ids);
    }

    /**
     * 删除服务单-任务关联信息
     * 
     * @param id 服务单-任务关联主键
     * @return 结果
     */
    @Override
    public int deleteServiceOrderTaskRelById(Long id)
    {
        return serviceOrderTaskRelMapper.deleteServiceOrderTaskRelById(id);
    }

    @Override
    public boolean existsByTaskId(Long taskId) {
        boolean exists = (serviceOrderTaskRelMapper.countByTaskId(taskId) != null
                && serviceOrderTaskRelMapper.countByTaskId(taskId) > 0);
        return exists;
    }


    @Override
    public List<ServiceOrderTaskRel> selectByServiceOrderId(Long id) {
        return serviceOrderTaskRelMapper.selectByServiceOrderId(id);
    }
}
