package com.trade.service.contract.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.trade.common.exception.ServiceException;
import com.trade.service.contract.entity.SFileTemplate;
import com.trade.service.contract.mapper.SFileTemplateMapper;
import com.trade.service.contract.service.ISFileTemplateService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 文件模板配置 服务实现类
 * </p>
 *
 * @author zhangchenm
 * @since 2024-09-05
 */
@Service
public class SFileTemplateServiceImpl extends ServiceImpl<SFileTemplateMapper, SFileTemplate> implements ISFileTemplateService {

    @Override
    // @Cacheable(value = "fileTemplate", key = "#code", cacheManager = "nonExpireCacheManager")
    public SFileTemplate selectByCode(String code) {
        QueryWrapper<SFileTemplate> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("template_code", code);
        SFileTemplate sFileTemplate = this.getOne(queryWrapper);
        if (sFileTemplate == null) {
            throw new ServiceException("无效的模板代码");
        }
        return sFileTemplate;
    }

    @Override
    public SFileTemplate selectByFileType(String fileType) {
        QueryWrapper<SFileTemplate> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("file_type", fileType);
        SFileTemplate sFileTemplate = this.getOne(queryWrapper);
        if (sFileTemplate == null) {
            throw new ServiceException("无效的文件类型");
        }
        return sFileTemplate;
    }
}
