package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.SnowFlakeUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.vo.UrYearValidDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.mapper.UrYearValidDataMapper;
import com.ruoyi.system.domain.UrYearValidData;
import com.ruoyi.system.service.IUrYearValidDataService;

/**
 * 专利有效按年统计结果Service业务层处理
 * 
 * @author dm
 * @date 2023-02-12
 */
@Service
@Transactional
public class UrYearValidDataServiceImpl implements IUrYearValidDataService 
{
    @Autowired
    private UrYearValidDataMapper urYearValidDataMapper;

    /**
     * 查询专利有效按年统计结果
     * 
     * @param id 专利有效按年统计结果主键
     * @return 专利有效按年统计结果
     */
    @Override
    public UrYearValidData selectUrYearValidDataById(Long id)
    {
        return urYearValidDataMapper.selectUrYearValidDataById(id);
    }

    /**
     * 查询专利有效按年统计结果列表
     * 
     * @param urYearValidData 专利有效按年统计结果
     * @return 专利有效按年统计结果
     */
    @Override
    public List<UrYearValidData> selectUrYearValidDataList(UrYearValidDataVo urYearValidData)
    {
        return urYearValidDataMapper.selectUrYearValidDataList(urYearValidData);
    }

    /**
     * 新增专利有效按年统计结果
     * 
     * @param urYearValidData 专利有效按年统计结果
     * @return 结果
     */
    @Override
    public int insertUrYearValidData(UrYearValidData urYearValidData)
    {
        if(urYearValidData.getId()==null){
        urYearValidData.setId(SnowFlakeUtils.snowFlakeId());
    }
        return urYearValidDataMapper.insertUrYearValidData(urYearValidData);
    }

    /**
     * 修改专利有效按年统计结果
     * 
     * @param urYearValidData 专利有效按年统计结果
     * @return 结果
     */
    @Override
    public int updateUrYearValidData(UrYearValidData urYearValidData)
    {
        return urYearValidDataMapper.updateUrYearValidData(urYearValidData);
    }

    /**
     * 批量删除专利有效按年统计结果
     * 
     * @param ids 需要删除的专利有效按年统计结果主键
     * @return 结果
     */
    @Override
    public int deleteUrYearValidDataByIds(Long[] ids)
    {
        return urYearValidDataMapper.deleteUrYearValidDataByIds(ids);
    }

    /**
     * 删除专利有效按年统计结果信息
     * 
     * @param id 专利有效按年统计结果主键
     * @return 结果
     */
    @Override
    public int deleteUrYearValidDataById(Long id)
    {
        return urYearValidDataMapper.deleteUrYearValidDataById(id);
    }

    /**
     * 批量---逻辑删除
     *
     * @param ids 需要删除的专利有效按年统计结果ID
     * @return 结果
     */
    @Override
    public int setDeleteByIds(Long[] ids)
    {
        Long userId = SecurityUtils.getUserId();
        String userNickName = SecurityUtils.getUserNickName();
        return urYearValidDataMapper.setDeleteByIds(ids,userId,userNickName);
    }

    /**
     * 删除---逻辑删除
     *
     * @param id 专利有效按年统计结果ID
     * @return 结果
     */
    @Override
    public int setDeleteById(Long id)
    {
        Long userId = SecurityUtils.getUserId();
        String userNickName = SecurityUtils.getUserNickName();
        return urYearValidDataMapper.setDeleteById(id,userId,userNickName);
    }

    /**
     * 获取有效概览左侧表头列表
     * @return
     */
    public List<UrYearValidData> selectUrLeftList() {
        return urYearValidDataMapper.selectUrLeftList();
    }

    /**
     * 查询云南省专利有效按年统计结果列表
     *
     * @param urYearValidData 专利有效按年统计结果
     * @return 云南省专利有效按年统计结果集合
     */
    public List<UrYearValidData> selectUrYearValidDataProvinceList(UrYearValidDataVo urYearValidData) {
        return urYearValidDataMapper.selectUrYearValidDataProvinceList(urYearValidData);
    }

    /**
     * 查询有效概览里需要的最新有效数据所在年
     * @return
     */
    public List<String> selectYearList() {
        List<String> list = new ArrayList<>();
//        UrYearValidData data = urYearValidDataMapper.selectYearList();
//        if(null != data) {
//            int year = Integer.parseInt(data.getYear());
//            list.add(data.getYear());
//            list.add(String.valueOf(year - 1));
//        }
        list.add("2022");
        list.add("2021");
        return list;
    }

}
