package com.fs.project.service.impl;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

import cn.hutool.core.lang.Assert;
import com.fs.common.exception.file.OssException;
import com.fs.common.utils.DateUtils;
import com.fs.project.vo.ProjectOptionVO;
import com.fs.project.vo.QueryAllDataVO;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fs.project.mapper.ProjectTaskTypeMapper;
import com.fs.project.domain.ProjectTaskType;
import com.fs.project.service.IProjectTaskTypeService;

/**
 * 项目任务类型Service业务层处理
 *
 * @author fs
 * @date 2025-12-30
 */
@Service
public class ProjectTaskTypeServiceImpl implements IProjectTaskTypeService
{
    @Autowired
    private ProjectTaskTypeMapper projectTaskTypeMapper;

    /**
     * 查询项目任务类型
     *
     * @param id 项目任务类型主键
     * @return 项目任务类型
     */
    @Override
    public ProjectTaskType selectProjectTaskTypeById(Long id)
    {
        return projectTaskTypeMapper.selectProjectTaskTypeById(id);
    }

    /**
     * 查询项目任务类型列表
     *
     * @param projectTaskType 项目任务类型
     * @return 项目任务类型
     */
    @Override
    public List<ProjectTaskType> selectProjectTaskTypeList(ProjectTaskType projectTaskType)
    {
        return projectTaskTypeMapper.selectProjectTaskTypeList(projectTaskType);
    }

    /**
     * 新增项目任务类型
     *
     * @param projectTaskType 项目任务类型
     * @return 结果
     */
    @Override
    public int insertProjectTaskType(ProjectTaskType projectTaskType)
    {
        ProjectTaskType searchProjectType = new ProjectTaskType();
        searchProjectType.setCompanyId(projectTaskType.getCompanyId());
        searchProjectType.setDeptId(projectTaskType.getDeptId());
        searchProjectType.setProjectId(projectTaskType.getProjectId());
        List<ProjectTaskType> projectTaskTypes = projectTaskTypeMapper.selectProjectTaskTypeList(searchProjectType);
        if(Objects.nonNull(projectTaskTypes)&&!projectTaskTypes.isEmpty()){
            throw new OssException("已有该部门与项目的配置");
        }
        projectTaskType.setCreateTime(DateUtils.getNowDate());
        return projectTaskTypeMapper.insertProjectTaskType(projectTaskType);
    }

    /**
     * 修改项目任务类型
     *
     * @param projectTaskType 项目任务类型
     * @return 结果
     */
    @Override
    public int updateProjectTaskType(ProjectTaskType projectTaskType)
    {
        projectTaskType.setUpdateTime(DateUtils.getNowDate());
        return projectTaskTypeMapper.updateProjectTaskType(projectTaskType);
    }

    /**
     * 批量删除项目任务类型
     *
     * @param ids 需要删除的项目任务类型主键
     * @return 结果
     */
    @Override
    public int deleteProjectTaskTypeByIds(Long[] ids)
    {
        return projectTaskTypeMapper.deleteProjectTaskTypeByIds(ids);
    }

    /**
     * 删除项目任务类型信息
     *
     * @param id 项目任务类型主键
     * @return 结果
     */
    @Override
    public int deleteProjectTaskTypeById(Long id)
    {
        return projectTaskTypeMapper.deleteProjectTaskTypeById(id);
    }


    @Override
    public List<ProjectOptionVO>  selectProjectOptionsByDept(Long deptId, String projectName) {
        return projectTaskTypeMapper.selectProjectOptionsByDept(deptId,projectName);
    }

    @Override
    public List<ProjectTaskType> queryAllData(QueryAllDataVO queryAllDataVO) {
        return projectTaskTypeMapper.queryAllData(queryAllDataVO);
    }
}
