package com.zanxiang.game.back.serve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zanxiang.game.back.serve.dao.mapper.GameOceanengineAppOrderSplitLogMapper;
import com.zanxiang.game.back.serve.pojo.entity.GameOceanengineAppOrderSplitLog;
import com.zanxiang.game.back.serve.pojo.vo.GameOceanengineAppOrderSplitLogVO;
import com.zanxiang.game.back.serve.service.IGameOceanengineAppOrderSplitLogService;
import com.zanxiang.module.util.NumberUtil;
import com.zanxiang.module.util.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class GameOceanengineAppOrderSplitLogServiceImpl extends ServiceImpl<GameOceanengineAppOrderSplitLogMapper, GameOceanengineAppOrderSplitLog>
implements IGameOceanengineAppOrderSplitLogService {
    @Override
    public List<GameOceanengineAppOrderSplitLogVO> listByOrderNo(Collection<String> orderNos) {
        if (CollectionUtils.isEmpty(orderNos)) {
            return Collections.emptyList();
        }
        return list(new LambdaQueryWrapper<GameOceanengineAppOrderSplitLog>()
                .in(GameOceanengineAppOrderSplitLog::getOrderNo, orderNos)
                .orderByAsc(GameOceanengineAppOrderSplitLog::getBackIndex)
        ).stream().map(this::toVOSimple).collect(Collectors.toList());
    }

    private GameOceanengineAppOrderSplitLogVO toVOSimple(GameOceanengineAppOrderSplitLog log) {
        if (log == null) {
            return null;
        }
        GameOceanengineAppOrderSplitLogVO vo = BeanUtil.copy(log, GameOceanengineAppOrderSplitLogVO.class);
        if (log.getSplitMoney() != null) {
            vo.setSplitMoney(NumberUtil.divide100(new BigDecimal(log.getSplitMoney())));
        }
        return vo;
    }
}
