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.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.foreverwin.mesnac.meapi.dto.SfcDto;
import com.foreverwin.mesnac.meapi.mapper.SfcMapper;
import com.foreverwin.mesnac.meapi.model.Sfc;
import com.foreverwin.mesnac.meapi.service.SfcService;
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.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Leon.L
 * @since 2021-06-02
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SfcServiceImpl extends ServiceImpl<SfcMapper, Sfc> implements SfcService {


    @Autowired
    private SfcMapper sfcMapper;

    @Override
    public IPage pageByResrce(Page<Sfc> pagePlus, QueryWrapper<SfcDto> queryWrapper, String globalQuery) {
        return sfcMapper.pageByResrce(pagePlus, queryWrapper, LocaleContextHolder.getLocale().getLanguage(),globalQuery);
    }

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

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

    @Override
    public List<Sfc> getSfcListByShopOrderBo(String shopOrderBo) {
        QueryWrapper<Sfc> queryWrapper = new QueryWrapper<>();
        Sfc sfc = new Sfc();
        sfc.setShopOrderBo(shopOrderBo);
        queryWrapper.setEntity(sfc);
        return super.list(queryWrapper);
    }

    @Override
    public LocalDateTime getSfcStartTime(String sfcBO) {
        LocalDateTime startTime=sfcMapper.getSfcStartTime(sfcBO);
        return startTime;
    }



    @Override
    public SfcDto findSfcData(String site, String sfc) {
        return sfcMapper.findSfcData(site, sfc);
    }

    @Override
    public Map findOperationBySfc(String sfc) {
        String site = CommonMethods.getSite();
        return sfcMapper.findOperationBySfc(site,sfc);
    }

    @Override
    public List<Sfc> findSfcByResrce(String resource,Sfc sfc) {
        String site = CommonMethods.getSite();
        sfcMapper.findSfcByResrce(site,resource,sfc);
        return null;
    }
}