
package com.tmerclub.cloud.distribution.feign;

import com.tmerclub.cloud.api.distribution.feign.DistributionFeignClient;
import com.tmerclub.cloud.api.distribution.vo.DistributionSpuVO;
import com.tmerclub.cloud.common.response.ServerResponseEntity;
import com.tmerclub.cloud.distribution.service.*;
import com.tmerclub.cloud.distribution.service.*;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author cl
 * @date 2021-08-05 15:38:50
 */
@DubboService
public class DistributionFeignController implements DistributionFeignClient {

    @Autowired
    private DistributionSpuService distributionSpuService;
    @Autowired
    private DistributionUserService distributionUserService;
    @Autowired
    private DistributionUserWalletService distributionUserWalletService;
    @Autowired
    private DistributionUserWalletBillService distributionUserWalletBillService;
    @Autowired
    private DistributionAuditingService distributionAuditingService;

    @Override
    public ServerResponseEntity<DistributionSpuVO> getByDistributionId(Long distributionId) {
        DistributionSpuVO distributionSpuVO = distributionSpuService.getByDistributionSpuId(distributionId);
        return ServerResponseEntity.success(distributionSpuVO);
    }

    @Override
    public ServerResponseEntity<DistributionSpuVO> getBySpuId(Long spuId) {
        DistributionSpuVO distributionSpuVO = distributionSpuService.getBySpuId(spuId);
        return ServerResponseEntity.success(distributionSpuVO);
    }

    @Override
    public ServerResponseEntity<Void> handleSpuState(List<Long> spuIds, List<Long> shopIds, Integer state) {
        distributionSpuService.handleSpuState(spuIds, shopIds, state);
        return ServerResponseEntity.success();
    }

    @Override
    public ServerResponseEntity<Void> initDistributionBySwitchAllinpay() {
        // 钱包初始化
        distributionUserWalletService.initDistributionWallet();
        // 流水记录初始化
        distributionUserWalletBillService.initDistributionWalletBill();
        // 自动拒绝未审核的分销员申请请求
        distributionAuditingService.autoRejectBySwitchAllinpay();
        return ServerResponseEntity.success();
    }
}
