package com.friday.custody.service.basicService.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.friday.custody.dao.TenantEmailFieldConfigDao;
import com.friday.custody.entity.TenantEmailFieldConfigEntity;
import com.friday.custody.service.basicService.TenantEmailFieldConfigService;
import com.friday.custody.utils.PageUtils;
import com.friday.custody.utils.Query;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("tenantEmailFieldConfigService")
public class TenantEmailFieldConfigServiceImpl extends ServiceImpl<TenantEmailFieldConfigDao, TenantEmailFieldConfigEntity> implements TenantEmailFieldConfigService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<TenantEmailFieldConfigEntity> page = this.page(
                new Query<TenantEmailFieldConfigEntity>().getPage(params),
                new QueryWrapper<TenantEmailFieldConfigEntity>()
        );

        return new PageUtils(page);
    }

    @Override
    public List<TenantEmailFieldConfigEntity> getConfigByVersionAndPartOfFilename(String version, String partOfFilename) {
        QueryWrapper<TenantEmailFieldConfigEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("version",version);
        queryWrapper.likeRight("file_name",partOfFilename);

        List<TenantEmailFieldConfigEntity> configEntities = this.baseMapper.selectList(queryWrapper);

        return configEntities;
    }

    @Override
    public TenantEmailFieldConfigEntity getConfigByVerdionAndFiled(String version, String partOfFilename, String targetField) {
        QueryWrapper<TenantEmailFieldConfigEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("version",version);
        queryWrapper.likeRight("file_name",partOfFilename);
        queryWrapper.eq("target_field", targetField);
        TenantEmailFieldConfigEntity tenantEmailFieldConfigEntity = baseMapper.selectOne(queryWrapper);
        return tenantEmailFieldConfigEntity;
    }

}