package com.foreverwin.mesnac.meapi.service.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.foreverwin.mesnac.meapi.mapper.NcCodeMapper;
import com.foreverwin.mesnac.meapi.model.NcCode;
import com.foreverwin.mesnac.meapi.service.NcCodeService;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.FrontPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author robert
 * @since 2021-06-23
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class NcCodeServiceImpl extends ServiceImpl<NcCodeMapper, NcCode> implements NcCodeService {


    @Autowired
    private NcCodeMapper ncCodeMapper;

    @Override
    public IPage<NcCode> selectPage(FrontPage<NcCode> frontPage, NcCode ncCode) {
        QueryWrapper<NcCode> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(ncCode);
        return super.page(frontPage.getPagePlus(), queryWrapper);
    }

    @Override
    public List<NcCode> selectList(NcCode ncCode) {
        QueryWrapper<NcCode> queryWrapper = new QueryWrapper<>();
        queryWrapper.setEntity(ncCode);
        return super.list(queryWrapper);
    }

    @Override
    public List<NcCode> findNcByNG(String messageType) {
        String site = CommonMethods.getSite();
        String locale = LocaleContextHolder.getLocale().getLanguage();
        return ncCodeMapper.findNcByNG(site,locale,messageType);
    }

    @Override
    public List<NcCode> findSecondaryNcByNc(String ncCode) {
        String site = CommonMethods.getSite();
        String locale = LocaleContextHolder.getLocale().getLanguage();
        return ncCodeMapper.findSecondaryNcByNc(site,locale,ncCode);
    }


}