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.dto.ShopOrderDto;
import com.foreverwin.mesnac.meapi.mapper.ShopOrderMapper;
import com.foreverwin.mesnac.meapi.model.ShopOrder;
import com.foreverwin.mesnac.meapi.service.ShopOrderService;
import com.foreverwin.modular.core.util.CommonMethods;
import com.foreverwin.modular.core.util.FrontPage;
import com.sap.me.status.StatusBOHandle;
import org.eclipse.jetty.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Leon.L
 * @since 2021-06-01
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ShopOrderServiceImpl extends ServiceImpl<ShopOrderMapper, ShopOrder> implements ShopOrderService {


    @Autowired
    private ShopOrderMapper shopOrderMapper;

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

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

    @Override
    public ShopOrder findById(String shopOrder,String plannedItemBo) {
        String site = CommonMethods.getSite();
        String status501 = new StatusBOHandle(site,"501").getValue();
        return shopOrderMapper.findById(site,shopOrder,status501,plannedItemBo);
    }

    @Override
    public ShopOrderDto findByShopOrderBo(String shopOrder) {
        String site = CommonMethods.getSite();
        if(!StringUtil.isBlank(shopOrder)){
            String handle = "ShopOrderBO:"+site+","+shopOrder;
            return shopOrderMapper.findByShopOrderBo(handle);
        }
        return null;
    }

    @Override
    public List<ShopOrder> findAbnormalShopOrder(ShopOrder shopOrder) {
        String site = CommonMethods.getSite();
        shopOrder.setSite(site);
        return shopOrderMapper.findAbnormalShopOrder(shopOrder);
    }


}