package com.zfire.mall.manager.controller.wallet;

import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zfire.mall.manager.annotation.ZfireList;
import com.zfire.mall.manager.bean.ExcelData;
import com.zfire.mall.manager.bean.k3.KingDeeOtherStockInAdd;
import com.zfire.mall.manager.bean.k3.KingDeeWalletVO;
import com.zfire.mall.manager.bean.k3.v2.KingTransferVO;
import com.zfire.mall.manager.bean.listV2.CustomerWalletAmountVO;
import com.zfire.mall.manager.bean.listV2.WalletRebateVO;
import com.zfire.mall.manager.bean.listV2.WalletSaleTypeRelaVO;
import com.zfire.mall.manager.bean.listV2.dto.CustomerAmountDTO;
import com.zfire.mall.manager.bean.wallet.CustomerWalletBean;
import com.zfire.mall.manager.bean.wallet.RebateWalletSaleBean;
import com.zfire.mall.manager.bean.wallet.WalletListBean;
import com.zfire.mall.manager.bean.wallet.WalletRebateBean;
import com.zfire.mall.manager.constant.Constant;
import com.zfire.mall.manager.exception.RemoteServiceException;
import com.zfire.mall.manager.helper.ResponseHelper;
import com.zfire.mall.manager.logic.wallet.WalletLogic;
import com.zfire.mall.manager.plus.entity.KingDeeWallet;
import com.zfire.mall.manager.plus.entity.WalletRebate;
import com.zfire.mall.manager.plus.entity.WalletRebateSaleType;
import com.zfire.mall.manager.utils.excel.ExcelUtils;
import com.zfire.mall.manager.zfire.bean.ZfireParamBean;
import com.zfire.mall.manager.zfire.util.FieldUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.redis.util.RedisLockRegistry;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

@Slf4j
@RestController
@Api(value = "钱包新增API", tags ={"钱包新增API"} )
@RequestMapping(value = "/walletNew", produces = "application/json; charset=utf-8")
public class WalletNewController {


    @Autowired
    WalletLogic walletLogic;
    @Autowired
    RedisLockRegistry redisLockRegistry;


    @ZfireList
    @ApiOperation(value = "钱包-列表")
    @PostMapping("/list")
    public ResponseHelper<IPage<KingDeeWalletVO>> v2ListPage(
            @RequestBody ZfireParamBean zfireParamBean
    ) throws Exception {
        IPage<KingDeeWalletVO> page = walletLogic.v2ListPage(zfireParamBean);
        return ResponseHelper.success(page, new TypeReference<KingDeeWalletVO>() {});
    }

    @PostMapping("/list/export")
    @ApiOperation("钱包-导出")
    public void v2ListPageExport(
            @RequestBody ZfireParamBean zfireParamBean,
            HttpServletRequest request,
            HttpServletResponse response
    ) throws Exception {
        //1.组装查询条件
        ZfireParamBean zfireParam = FieldUtils.supplyParam(zfireParamBean);
        //2.查询要导出的内容
        IPage<KingDeeWalletVO> list = walletLogic.v2ListPage(zfireParamBean);
        //3.导出
        FieldUtils.exportData(list.getRecords(),zfireParam.getExportFields(),request,response);
    }



    @ApiOperation(value = "新增钱包")
    @PostMapping("/add")
    public ResponseHelper add(
            @RequestBody KingDeeWallet kingDeeWallet
    ) throws Exception {
        walletLogic.addWallet(kingDeeWallet);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "修改钱包")
    @PostMapping("/updateCustomer")
    public ResponseHelper updateCustomer(
            @RequestBody KingDeeWallet kingDeeWallet
    ) throws Exception {
        walletLogic.updateWallet(kingDeeWallet);
        return ResponseHelper.success();
    }


}
