package com.hw.qms.service.impl;

import java.util.List;

import com.hw.common.core.constant.QmsConstants;
import com.hw.common.core.utils.DateUtils;
import com.hw.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hw.qms.mapper.QmsCheckProjectMapper;
import com.hw.qms.domain.QmsCheckProject;
import com.hw.qms.service.IQmsCheckProjectService;

/**
 * 检验项目Service业务层处理
 *
 * @author xins
 * @date 2024-01-23
 */
@Service
public class QmsCheckProjectServiceImpl implements IQmsCheckProjectService
{
    @Autowired
    private QmsCheckProjectMapper qmsCheckProjectMapper;

    /**
     * 查询检验项目
     *
     * @param checkProjectId 检验项目主键
     * @return 检验项目
     */
    @Override
    public QmsCheckProject selectQmsCheckProjectByCheckProjectId(Long checkProjectId)
    {
        return qmsCheckProjectMapper.selectQmsCheckProjectByCheckProjectId(checkProjectId);
    }

    /**
     * 查询检验项目列表
     *
     * @param qmsCheckProject 检验项目
     * @return 检验项目
     */
    @Override
    public List<QmsCheckProject> selectQmsCheckProjectList(QmsCheckProject qmsCheckProject)
    {
        return qmsCheckProjectMapper.selectQmsCheckProjectList(qmsCheckProject);
    }

    /**
     * 新增检验项目
     *
     * @param qmsCheckProject 检验项目
     * @return 结果
     */
    @Override
    public int insertQmsCheckProject(QmsCheckProject qmsCheckProject)
    {
        qmsCheckProject.setCreateBy(SecurityUtils.getUsername());
        qmsCheckProject.setCreateTime(DateUtils.getNowDate());
        return qmsCheckProjectMapper.insertQmsCheckProject(qmsCheckProject);
    }

    /**
     * 修改检验项目
     *
     * @param qmsCheckProject 检验项目
     * @return 结果
     */
    @Override
    public int updateQmsCheckProject(QmsCheckProject qmsCheckProject)
    {
        String checkProjectProperty = qmsCheckProject.getCheckProjectProperty();
        if(checkProjectProperty.equals(QmsConstants.QMS_CHECK_PROJECT_PROPERTY_QUALITATIVE)){
            qmsCheckProject.setStandardValue(null);
            qmsCheckProject.setUpperDiff(null);
            qmsCheckProject.setDownDiff(null);
        }

        qmsCheckProject.setUpdateBy(SecurityUtils.getUsername());
        qmsCheckProject.setUpdateTime(DateUtils.getNowDate());
        return qmsCheckProjectMapper.updateQmsCheckProject(qmsCheckProject);
    }

    /**
     * 批量删除检验项目
     *
     * @param checkProjectIds 需要删除的检验项目主键
     * @return 结果
     */
    @Override
    public int deleteQmsCheckProjectByCheckProjectIds(Long[] checkProjectIds)
    {
        return qmsCheckProjectMapper.deleteQmsCheckProjectByCheckProjectIds(checkProjectIds);
    }

    /**
     * 删除检验项目信息
     *
     * @param checkProjectId 检验项目主键
     * @return 结果
     */
    @Override
    public int deleteQmsCheckProjectByCheckProjectId(Long checkProjectId)
    {
        return qmsCheckProjectMapper.deleteQmsCheckProjectByCheckProjectId(checkProjectId);
    }






    /**
     * 查询检验项目列表,提供给检验规则查询未分配项目使用
     *
     * @param qmsCheckProject 检验项目
     * @return 检验项目
     */
    @Override
    public List<QmsCheckProject> selectQmsCheckProjects4AllocateCheckRule(QmsCheckProject qmsCheckProject)
    {
        return qmsCheckProjectMapper.selectQmsCheckProjects4AllocateCheckRule(qmsCheckProject);
    }

}
