
package com.tmerclub.cloud.order.feign;

import com.tmerclub.cloud.api.order.bo.EsOrderRefundBO;
import com.tmerclub.cloud.api.order.feign.OrderRefundFeignClient;
import com.tmerclub.cloud.api.order.vo.*;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.common.util.Json;
import com.tmerclub.cloud.order.dto.multishop.OrderRefundDTO;
import com.tmerclub.cloud.order.service.OrderRefundService;
import com.tmerclub.cloud.order.vo.OrderRefundVO;
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 OrderRefundFeignController implements OrderRefundFeignClient {


    @Autowired
    private OrderRefundService orderRefundService;

    @Override
    public ServerResponseEntity<Integer> getRefundStatus(Long refundId) {

        return ServerResponseEntity.success(orderRefundService.getRefundStatus(refundId));
    }

    @Override
    public ServerResponseEntity<List<OrderRefundProdEffectRespVO>> getProdRefundEffectByDateAndProdIds(List<Long> spuIds, Long startTime, Long endTime) {
        return ServerResponseEntity.success(orderRefundService.getProdRefundEffectByDateAndProdIds(spuIds, new Date(startTime), new Date(endTime)));
    }

    @Override
    public ServerResponseEntity<List<com.tmerclub.cloud.api.order.vo.OrderRefundVO>> getOrderRefundByOrderIdAndRefundStatus(Long orderId, Integer returnMoneySts) {
        return ServerResponseEntity.success(orderRefundService.getOrderRefundByOrderIdAndRefundStatus(orderId, returnMoneySts));
    }

    @Override
    public ServerResponseEntity<List<OrderRefundSimpleVO>> listOrderIdsByRefundIds(List<Long> refundIds) {
        return ServerResponseEntity.success(orderRefundService.listOrderIdsByRefundIds(refundIds));
    }

    @Override
    public ServerResponseEntity<List<Long>> listOrderRefundByOrderIds(List<Long> orderIds) {
        return ServerResponseEntity.success(orderRefundService.listOrderRefundByOrderIds(orderIds));
    }

    @Override
    public ServerResponseEntity<com.tmerclub.cloud.api.order.vo.OrderRefundVO> getOrderRefundByRefundId(Long refundId) {
        return ServerResponseEntity.success(orderRefundService.getOrderRefundByRefundId(refundId));
    }

    @Override
    public ServerResponseEntity<EsOrderRefundBO> saveMongoAndGetEsOrderRefundInfo(Long refundId) {
        return ServerResponseEntity.success(orderRefundService.saveMongoAndGetEsOrderRefundInfo(refundId));
    }

    @Override
    public ServerResponseEntity<AccountOrderDetailVO> getAccountOrderDetail(Date startTime, Date endTime, String shopName, Long shopId) {
        AccountOrderDetailVO accountOrderDetail = orderRefundService.getAccountOrderDetail(startTime, endTime, shopName, shopId);
        return ServerResponseEntity.success(accountOrderDetail);
    }

    @Override
    public ServerResponseEntity<PageShopAccountOrderVO> listShopAccountDetail(Date startTime, Date endTime, String shopName, Integer pageSize, Integer pageNum) {
        PageShopAccountOrderVO accountDetail = orderRefundService.listShopAccountDetail(startTime, endTime, shopName, pageSize, pageNum);
        return ServerResponseEntity.success(accountDetail);
    }

    @Override
    public ServerResponseEntity<PageShopAccountOrderVO> listOrderRefundInfo(Date startTime, Date endTime, Long shopId, String shopName, Integer pageSize, Integer pageNum) {
        PageShopAccountOrderVO orderRefundInfo = orderRefundService.listOrderRefundInfo(startTime, endTime, shopId, shopName, pageSize, pageNum);
        return ServerResponseEntity.success(orderRefundInfo);
    }

    @Override
    public void doRefund(String extendInfo) {
        OrderRefundDTO orderRefundDTO = Json.parseObject(extendInfo, OrderRefundDTO.class);
        // 获取退款单信息
        OrderRefundVO orderRefundVO = orderRefundService.getDetailByRefundId(orderRefundDTO.getRefundId());
        orderRefundService.agreeRefund(orderRefundDTO, orderRefundVO);
    }
}
