package com.yanzhu.jh.project.service.impl;

import java.util.List;

import cn.hutool.core.date.DateUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.jh.project.mapper.SmzProjectQuarterlyAssessMapper;
import com.yanzhu.jh.project.domain.SmzProjectQuarterlyAssess;
import com.yanzhu.jh.project.service.ISmzProjectQuarterlyAssessService;

/**
 * 项目季度考核Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-08-05
 */
@Service
public class SmzProjectQuarterlyAssessServiceImpl implements ISmzProjectQuarterlyAssessService 
{
    @Autowired
    private SmzProjectQuarterlyAssessMapper smzProjectQuarterlyAssessMapper;

    /**
     * 查询项目季度考核
     * 
     * @param id 项目季度考核主键
     * @return 项目季度考核
     */
    @Override
    public SmzProjectQuarterlyAssess selectSmzProjectQuarterlyAssessById(Long id)
    {
        return smzProjectQuarterlyAssessMapper.selectSmzProjectQuarterlyAssessById(id);
    }

    /**
     * 查询项目季度考核列表
     * 
     * @param smzProjectQuarterlyAssess 项目季度考核
     * @return 项目季度考核
     */
    @Override
    public List<SmzProjectQuarterlyAssess> selectSmzProjectQuarterlyAssessList(SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        return smzProjectQuarterlyAssessMapper.selectSmzProjectQuarterlyAssessList(smzProjectQuarterlyAssess);
    }

    /**
     * 新增项目季度考核
     * 
     * @param smzProjectQuarterlyAssess 项目季度考核
     * @return 结果
     */
    @Override
    public int insertSmzProjectQuarterlyAssess(SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        smzProjectQuarterlyAssess.setCreateTime(DateUtils.getNowDate());
        smzProjectQuarterlyAssess.setCreateBy(SecurityUtils.getUsername());
        smzProjectQuarterlyAssess.setIsDel(0l);
        return smzProjectQuarterlyAssessMapper.insertSmzProjectQuarterlyAssess(smzProjectQuarterlyAssess);
    }

    /**
     * 修改项目季度考核
     * 
     * @param smzProjectQuarterlyAssess 项目季度考核
     * @return 结果
     */
    @Override
    public int updateSmzProjectQuarterlyAssess(SmzProjectQuarterlyAssess smzProjectQuarterlyAssess)
    {
        smzProjectQuarterlyAssess.setUpdateTime(DateUtils.getNowDate());
        smzProjectQuarterlyAssess.setUpdateBy(SecurityUtils.getUsername());
        return smzProjectQuarterlyAssessMapper.updateSmzProjectQuarterlyAssess(smzProjectQuarterlyAssess);
    }

    /**
     * 批量删除项目季度考核
     * 
     * @param ids 需要删除的项目季度考核主键
     * @return 结果
     */
    @Override
    public int deleteSmzProjectQuarterlyAssessByIds(Long[] ids)
    {
        return smzProjectQuarterlyAssessMapper.deleteSmzProjectQuarterlyAssessByIds(ids);
    }

    /**
     * 删除项目季度考核信息
     * 
     * @param id 项目季度考核主键
     * @return 结果
     */
    @Override
    public int deleteSmzProjectQuarterlyAssessById(Long id)
    {
        return smzProjectQuarterlyAssessMapper.deleteSmzProjectQuarterlyAssessById(id);
    }

    @Override
    public void addYear(SmzProjectQuarterlyAssess smzProjectQuarterlyAssess) {

        long year=smzProjectQuarterlyAssess.getYear();
        SmzProjectQuarterlyAssess assess=new SmzProjectQuarterlyAssess();
        assess.setYear(smzProjectQuarterlyAssess.getYear());
        assess.setProjectId(smzProjectQuarterlyAssess.getProjectId());
        assess.setQuarterly(1l);
        assess.setDate(DateUtil.parse(year+"-01-01"));
        insertSmzProjectQuarterlyAssess(assess);
        assess.setId(null);
        assess.setQuarterly(2l);
        assess.setDate(DateUtil.parse(year+"-04-01"));
        insertSmzProjectQuarterlyAssess(assess);
        assess.setId(null);
        assess.setQuarterly(3l);
        assess.setDate(DateUtil.parse(year+"-07-01"));
        insertSmzProjectQuarterlyAssess(assess);
        assess.setId(null);
        assess.setQuarterly(4l);
        assess.setDate(DateUtil.parse(year+"-10-01"));
        insertSmzProjectQuarterlyAssess(assess);
    }

    @Override
    public List<SmzProjectQuarterlyAssess> currentListByDept( SmzProjectQuarterlyAssess smzProjectQuarterlyAssess) {
        return smzProjectQuarterlyAssessMapper.currentListByDept(smzProjectQuarterlyAssess);
    }

    /**
     * 根据项目类型查询项目的季度计划
     * @param where
     * @return
     */
    @Override
    public List queryByProjectType(SmzProjectQuarterlyAssess where) {
        return smzProjectQuarterlyAssessMapper.queryByProjectType(where);
    }
}
