
package com.tmerclub.cloud.order.feign;

import com.tmerclub.cloud.api.order.bo.EsPurchaseOrderBO;
import com.tmerclub.cloud.api.order.feign.PurchaseOrderFeignClient;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.order.manager.MongoPurchaseOrderManager;
import com.tmerclub.cloud.order.service.PurchaseOrderService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

/**
 * @author tmerclub
 * @date 2020/12/25
 */
@DubboService
public class PurchaseOrderFeignController implements PurchaseOrderFeignClient {

    @Autowired
    private PurchaseOrderService purchaseOrderService;
    @Autowired
    private MongoPurchaseOrderManager mongoPurchaseOrderManager;

    @Override
    public ServerResponseEntity<EsPurchaseOrderBO> saveMongoAndGetEsInfo(Long purchaseOrderId) {
        EsPurchaseOrderBO esOrderBO = purchaseOrderService.saveMongoAndGetEsInfo(purchaseOrderId);
        return ServerResponseEntity.success(esOrderBO);
    }


    @Override
    public ServerResponseEntity<Void> updatePurchaseOrderStatus(List<Long> purchaseOrderIds, Integer purchaseOrderStatus) {
        purchaseOrderService.updatePurchaseOrderStatus(purchaseOrderIds, purchaseOrderStatus);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<List<Long>> listSpuIdOfStockChange(Date beginTime, Date endTime) {
        List<Long> spuIds = mongoPurchaseOrderManager.listSpuIdOfStockChange(beginTime, endTime);
        return ServerResponseEntity.success(spuIds);
    }

    @Override
    public Long countUnFinish(Long warehouseId) {
        return purchaseOrderService.countUnFinish(warehouseId);
    }
}
