package com.yc.ship.module.trade.service.order.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yc.ship.framework.common.pojo.PageResult;
import com.yc.ship.framework.common.util.object.PageUtils;
import com.yc.ship.framework.mybatis.core.util.MyBatisUtils;
import com.yc.ship.module.trade.controller.admin.visitor.vo.VisitorPageReqVO;
import com.yc.ship.module.trade.controller.admin.visitor.vo.VisitorRespVO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeOrderDO;
import com.yc.ship.module.trade.dal.dataobject.order.TradeVisitorDO;
import com.yc.ship.module.trade.dal.mysql.order.TradeVisitorMapper;
import com.yc.ship.module.trade.service.order.TradeOrderService;
import com.yc.ship.module.trade.service.order.TradeVisitorService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yc.ship.module.trade.enums.ErrorCodeConstants.ORDER_NOT_EXIST;

/**
 * 游客数据
 */
@Slf4j
@Service
@Validated
@RequiredArgsConstructor
public class TradeVisitorServiceImpl implements TradeVisitorService {

    @Resource
    private TradeVisitorMapper tradeVisitorMapper;
    @Override
    public List<TradeVisitorDO> getShipByOrderIds(List<Long> orderIds) {
        if(orderIds.isEmpty()) {
            return Collections.emptyList();
        }
        return tradeVisitorMapper.selectShipByOrderIds(orderIds);
    }

    @Override
    public List<Long> getNotInsureByOrderIds(List<Long> orderIdList) {
        return tradeVisitorMapper.selectNotInsureByOrderIds(orderIdList);
    }

    @Override
    public PageResult<VisitorRespVO> getVisitorPage(VisitorPageReqVO pageReqVO) {
        IPage<VisitorRespVO> page = MyBatisUtils.buildPage(pageReqVO);
        IPage<VisitorRespVO> ipage = tradeVisitorMapper.selectVisitorPage(page, pageReqVO);
        return new PageResult<>(ipage.getRecords(), ipage.getTotal());
    }

    @Override
    public TradeVisitorDO getVisitor(Long id) {
        return tradeVisitorMapper.selectById(id);
    }

    @Override
    public void updateVisitor(TradeVisitorDO updateReqVO) {
        tradeVisitorMapper.updateById(updateReqVO);
    }
}
