package com.sifang.modules.smallprogram.yuexiu;

import com.sifang.modules.customer.Service.YueXiuBankCardService;
import com.sifang.modules.customer.entity.CrmTenantYxBankCard;
import com.sifang.modules.sunshine.SystemSetting.utils.BusinessException;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sys.web.BaseExceptionController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

//越秀开卡
@Controller
@RequestMapping(value = "${adminPath}/main/yueXiuBankCard")
public class YueXiuBankCardController extends BaseExceptionController {

    @Autowired
    private YueXiuBankCardService bankCardService;

    //开卡
    @ResponseBody
    @RequestMapping(value = "bankCardPage")
    public Result bankCardPage(String entryId){
        try {
            String gdUrl= bankCardService.openBankCard(entryId,"1");
            if ("10000".equals(gdUrl)) {
                return Result.fail("已开卡成功，请刷新列表!");
            }
            Map<String,String> result=new HashMap<>();
            result.put("gdUrl",gdUrl);
            return Result.success(result);
        } catch (BusinessException e) {
            return Result.fail(e.getMessage());
        } catch (Exception e) {
            return Result.fail("操作失败");
        }
    }

    //销户
    @ResponseBody
    @RequestMapping(value = "cancelBankCard")
    public Result cancelBankCard(String entryId){
        String result = bankCardService.openBankCard(entryId, "2");
        if ("10000".equals(result)) {
            return Result.fail("已开卡成功，请刷新列表!");
        }
        return Result.ok();
    }

    //pc端销户
    @ResponseBody
    @RequestMapping(value = "cancelBankCardByIdCode")
    public Result cancelBankCardByIdCode(String IdCode){
        Result result = null;
        try {
            result =  bankCardService.cancelBankCardByIdCode(IdCode);
        } catch (BusinessException e) {
            return Result.fail(e.getMessage());
        } catch (Exception e) {
            return Result.fail("操作失败");
        }
        return result;
    }

    //pc端同步开卡状态
    @ResponseBody
    @RequestMapping(value = "lookBankCardByIdCode")
    public Result lookBankCardByIdCode(String IdCode){
        Result result;
        try {
            result =  bankCardService.lookBankCardByIdCode(IdCode);
        } catch (BusinessException e) {
            return Result.fail(e.getMessage());
        } catch (Exception e) {
            return Result.fail("同步失败");
        }
        return result;
    }


    //查询开卡状态
    @ResponseBody
    @RequestMapping(value = "lookBankCardStatus")
    public Result lookBankCardStatus(String entryId){
        CrmTenantYxBankCard card= bankCardService.lookBankCardStatus(entryId);
        return Result.success(card);
    }

    @ResponseBody
    @RequestMapping(value = "bankCardDetail")
    public Result bankCardDetail(String idCard,String managementType,String partnerId){
        CrmTenantYxBankCard card= bankCardService.bankCardDetail(idCard,managementType, partnerId);
        return Result.success(card);
    }

}
