package com.ruoyi.system.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.assessment.ZxAssessment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ZxAssessmentMapper;
import com.ruoyi.system.service.IZxAssessmentService;

import java.util.List;

/**
 * 政协评价考核Service业务层处理
 * 
 * @author boman
 * @date 2024-03-19
 */
@Service
public class ZxAssessmentServiceImpl implements IZxAssessmentService 
{
    @Autowired
    private ZxAssessmentMapper zxAssessmentMapper;

    /**
     * 查询政协评价考核
     * 
     * @param assessmentId 政协评价考核主键
     * @return 政协评价考核
     */
    @Override
    public ZxAssessment selectZxAssessmentByAssessmentId(Long assessmentId)
    {
        return zxAssessmentMapper.selectZxAssessmentByAssessmentId(assessmentId);
    }

    /**
     * 查询政协评价考核列表
     * 
     * @param zxAssessment 政协评价考核
     * @return 政协评价考核
     */
    @Override
    public List<ZxAssessment> selectZxAssessmentList(ZxAssessment zxAssessment)
    {
        return zxAssessmentMapper.selectZxAssessmentList(zxAssessment);
    }

    /**
     * 新增政协评价考核
     * 
     * @param zxAssessment 政协评价考核
     * @return 结果
     */
    @Override
    public int insertZxAssessment(ZxAssessment zxAssessment)
    {
/*        ZxAssessment info = zxAssessmentMapper.selectZxAssessmentByAssessmentId(zxAssessment.getAssessmentId());
        // 如果父节点不为正常状态,则不允许新增子节点
        if (!UserConstants.YES.equals(info.getIsUse()))
        {
            throw new ServiceException("停用，不允许新增");
        }*/
        zxAssessment.setCreateTime(DateUtils.getNowDate());
        return zxAssessmentMapper.insertZxAssessment(zxAssessment);
    }

    /**
     * 校验考核项目是否唯一
     *
     * @param zxAssessment 考核信息
     * @return 结果
     */
    @Override
    public boolean checkAssessmentProjectUnique(ZxAssessment zxAssessment) {
        String assessmentTypeId = StringUtils.isNull(zxAssessment.getAssessmentTypeId()) ? "-1" : zxAssessment.getAssessmentTypeId();
        ZxAssessment info = zxAssessmentMapper.checkAssessmentProjectUnique(assessmentTypeId, zxAssessment.getParentId());
        if (StringUtils.isNotNull(info) && !info.getAssessmentTypeId().equals(assessmentTypeId))
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }

    /**
     * 修改政协评价考核
     * 
     * @param zxAssessment 政协评价考核
     * @return 结果
     */
    @Override
    public int updateZxAssessment(ZxAssessment zxAssessment)
    {
        zxAssessment.setUpdateTime(DateUtils.getNowDate());
        return zxAssessmentMapper.updateZxAssessment(zxAssessment);
    }

    /**
     * 批量删除政协评价考核
     * 
     * @param assessmentIds 需要删除的政协评价考核主键
     * @return 结果
     */
    @Override
    public int deleteZxAssessmentByAssessmentIds(Long[] assessmentIds)
    {
        return zxAssessmentMapper.deleteZxAssessmentByAssessmentIds(assessmentIds);
    }

    /**
     * 删除政协评价考核信息
     * 
     * @param assessmentId 政协评价考核主键
     * @return 结果
     */
    @Override
    public int deleteZxAssessmentByAssessmentId(Long assessmentId)
    {
        return zxAssessmentMapper.deleteZxAssessmentByAssessmentId(assessmentId);
    }
}
