package com.ruoyi.predict.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.predict.domain.Projectplan;
import com.ruoyi.predict.mapper.ProjectplanMapper;
import com.ruoyi.predict.service.IProjectplanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ProjectplanService业务层处理
 * 
 * @author hlf
 * @date 2022-08-30
 */
@Service
public class ProjectplanServiceImpl implements IProjectplanService 
{
    @Autowired(required = false)
    private ProjectplanMapper projectplanMapper;

    /**
     * 查询Projectplan
     * 
     * @param id ProjectplanID
     * @return Projectplan
     */
    @Override
    public Projectplan selectProjectplanById(Long id)
    {
        return projectplanMapper.selectProjectplanById(id);
    }

    /**
     * 查询Projectplan列表
     * 
     * @param projectplan Projectplan
     * @return Projectplan
     */
    @Override
    public List<Projectplan> selectProjectplanList(Projectplan projectplan)
    {
        return projectplanMapper.selectProjectplanList(projectplan);
    }

    /**
     * 新增Projectplan
     * 
     * @param projectplan Projectplan
     * @return 结果
     */
    @Override
    public int insertProjectplan(Projectplan projectplan)
    {
        return projectplanMapper.insertProjectplan(projectplan);
    }

    /**
     * 修改Projectplan
     * 
     * @param projectplan Projectplan
     * @return 结果
     */
    @Override
    public int updateProjectplan(Projectplan projectplan)
    {
        return projectplanMapper.updateProjectplan(projectplan);
    }

    /**
     * 删除Projectplan对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteProjectplanByIds(String ids)
    {
        return projectplanMapper.deleteProjectplanByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除Projectplan信息
     * 
     * @param id ProjectplanID
     * @return 结果
     */
    @Override
    public int deleteProjectplanById(Long id)
    {
        return projectplanMapper.deleteProjectplanById(id);
    }

    @Override
    public Long selectNewData() {
        return projectplanMapper.selectNewData();
    }

    @Override
    public String checkProjectplanUnique(Long windpower, String projectid, Long year, Long month) {
        int count = projectplanMapper.checkProjectplanUnique(windpower, projectid, year, month);
        if (count > 0)
        {
            return UserConstants.USER_NAME_NOT_UNIQUE;
        }
        return UserConstants.USER_NAME_UNIQUE;
    }

    @Override
    public List<Projectplan> selectProjectplan(Long windplantNo, Long year, Long month) {
        long monthStr;
        if (Convert.toStr(month).length() == 1){
            monthStr = Convert.toLong("0" + Convert.toStr(month));
        }else {
            monthStr = month;
        }
        return projectplanMapper.selectProjectplan(windplantNo, year, monthStr);
    }

    @Override
    public List<Projectplan> selectProjectplanByProjectNo(Long windplantNo, String projectid, Long year, Long month) {
        return projectplanMapper.selectProjectplanByProjectNo(windplantNo, projectid, year, month);
    }

    @Override
    public List<Projectplan> selectProjectplanByYear(Long windplantNo, Long year) {
        return projectplanMapper.selectProjectplanByYear(windplantNo, year);
    }
}
