package com.zfire.mall.manager.logic.k3;

import com.aliyuncs.utils.StringUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.zfire.mall.manager.bean.k3.RequestApiBean;
import com.zfire.mall.manager.constant.KingDeeCons;
import com.zfire.mall.manager.logic.wallet.WalletLogic;
import com.zfire.mall.manager.plus.entity.KingDeeCustomer;
import com.zfire.mall.manager.plus.entity.KingDeeReceipt;
import com.zfire.mall.manager.plus.entity.KingDeeTransfer;
import com.zfire.mall.manager.plus.entity.KingDeeWallet;
import com.zfire.mall.manager.plus.service.KingDeeReceiptService;
import com.zfire.mall.manager.plus.service.KingDeeWalletService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class K3WalletLogic {

    @Autowired
    K3Logic k3Logic;
    @Autowired
    WalletLogic walletLogic;
    @Autowired
    K3CustomerLogic k3CustomerLogic;
    @Autowired
    KingDeeWalletService kingDeeWalletService;
    @Autowired
    KingDeeReceiptService kingDeeReceiptService;


    /**
     * 同步钱包
     * @param orgId
     * @param orgNumber
     * @param startTime
     * @param endTime
     * @throws Exception
     */
//    public void allSync(String orgId, String orgNumber, String startTime, String endTime) throws Exception {
//        // 同步钱包接口
//        RequestApiBean request = k3Logic.getInstance(orgId, orgNumber, KingDeeCons.WALLET, startTime, endTime);
//        String filterStr = "FId='62a150496fabe3'"+ k3Logic.supplySql("FApproveDate", request.getStartTime(), request.getEndTime());
//        request.setFieldKeys("FEntryID,FNumber,FDataValue,FUseOrgId,FForbidStatus");
//        request.setFilterString(String.format(filterStr, orgNumber));
//        request.setOrderString("FEntryID ASC");
//
//        String[] fields = new String[]{"id","number","name","useOrgId","forbidStatus"};
//        List<KingDeeWallet> objects = k3Logic.allSync(request, fields, KingDeeWallet.class);
//        if (Objects.nonNull(objects)) {
//            kingDeeWalletService.saveOrUpdateBatch(objects);
//
//            List<KingDeeCustomer> kingDeeCustomers = k3CustomerLogic.allList();
//            for(KingDeeCustomer customer : kingDeeCustomers){
//                walletLogic.initByK3Customer(customer.getId());
//            }
//        }
//    }









}
