package com.microservices.dms.achievementLibrary.service.impl;

import java.util.Collections;
import java.util.List;
import com.microservices.common.core.utils.DateUtils;
import com.microservices.dms.achievementLibrary.domain.KeyValueVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.microservices.dms.achievementLibrary.mapper.AchievementDictDataMapper;
import com.microservices.dms.achievementLibrary.domain.AchievementDictData;
import com.microservices.dms.achievementLibrary.service.IAchievementDictDataService;

/**
 * 成果相关字典Service业务层处理
 * 
 * @author microservices
 * @date 2025-05-23
 */
@Service
public class AchievementDictDataServiceImpl implements IAchievementDictDataService 
{
    @Autowired
    private AchievementDictDataMapper achievementDictDataMapper;

    /**
     * 查询成果相关字典
     * 
     * @param dictCode 成果相关字典主键
     * @return 成果相关字典
     */
    @Override
    public AchievementDictData selectAchievementDictDataByDictCode(Long dictCode)
    {
        return achievementDictDataMapper.selectAchievementDictDataByDictCode(dictCode);
    }

    /**
     * 查询成果相关字典列表
     * 
     * @param achievementDictData 成果相关字典
     * @return 成果相关字典
     */
    @Override
    public List<AchievementDictData> selectAchievementDictDataList(AchievementDictData achievementDictData)
    {
        return achievementDictDataMapper.selectAchievementDictDataList(achievementDictData);
    }

    /**
     * 新增成果相关字典
     * 
     * @param achievementDictData 成果相关字典
     * @return 结果
     */
    @Override
    public int insertAchievementDictData(AchievementDictData achievementDictData)
    {
        //判断字典是否存在，存在则不管，不存在则新增
        String label = achievementDictData.getDictLabel();
        String type = achievementDictData.getDictType();
        int num = achievementDictDataMapper.selectDictDataByLabel(label,type);
        if (num > 0){
            return 0;
        }else{
            achievementDictData.setCreateTime(DateUtils.getNowDate());
            return achievementDictDataMapper.insertAchievementDictData(achievementDictData);
        }
    }

    /**
     * 修改成果相关字典
     * 
     * @param achievementDictData 成果相关字典
     * @return 结果
     */
    @Override
    public int updateAchievementDictData(AchievementDictData achievementDictData)
    {
        achievementDictData.setUpdateTime(DateUtils.getNowDate());
        return achievementDictDataMapper.updateAchievementDictData(achievementDictData);
    }

    /**
     * 批量删除成果相关字典
     * 
     * @param dictCodes 需要删除的成果相关字典主键
     * @return 结果
     */
    @Override
    public int deleteAchievementDictDataByDictCodes(Long[] dictCodes)
    {
        return achievementDictDataMapper.deleteAchievementDictDataByDictCodes(dictCodes);
    }

    /**
     * 删除成果相关字典信息
     * 
     * @param dictCode 成果相关字典主键
     * @return 结果
     */
    @Override
    public int deleteAchievementDictDataByDictCode(Long dictCode)
    {
        return achievementDictDataMapper.deleteAchievementDictDataByDictCode(dictCode);
    }

    @Override
    public List<KeyValueVo> selectDictDataByType(String dictType) {
        return achievementDictDataMapper.selectDictDataByType(dictType);
    }
}
