package com.hzs.sale.order.provider;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.hzs.common.core.domain.R;
import com.hzs.common.domain.sale.ext.SaOrderItemsExt;
import com.hzs.sale.order.ISaOrderItemsServiceApi;
import com.hzs.sale.order.dto.WaresOrderDTO;
import com.hzs.sale.order.service.ISaOrderItemsService;
import com.hzs.sale.order.vo.WaresOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 销售订单-明细表
 */
@Slf4j
@DubboService
public class SaOrderItemsServiceProvider implements ISaOrderItemsServiceApi {

    @Autowired
    private ISaOrderItemsService iSaOrderItemsService;

    @Override
    public R<List<WaresOrderDTO>> waresListByOrderId(List<Long> orderIdList) {
        List<WaresOrderDTO> dtoList = new ArrayList<>();
        List<WaresOrderVo> list = iSaOrderItemsService.waresListByOrderId(orderIdList);
        if (CollectionUtil.isNotEmpty(list)) {
            list.forEach(itm -> dtoList.add(BeanUtil.copyProperties(itm, WaresOrderDTO.class)));
        }
        return R.ok(dtoList);
    }

    @Override
    public R<List<SaOrderItemsExt>> queryListByOrderId(List<Long> orderIdList) {
        return R.ok(iSaOrderItemsService.queryListByOrderId(orderIdList));
    }

    @Override
    public R<?> orderItemsReturn(List<Long> orderItemsIdList, Long userId, Integer pkCountry) {
        if (iSaOrderItemsService.orderItemsReturn(orderItemsIdList, userId, pkCountry)) {
            return R.ok();
        }
        return R.fail();
    }

}
