package cn.pluss.platform.controller.merchantAccount;

import cn.pluss.platform.api.Result;
import cn.pluss.platform.api.ResultGenerator;
import cn.pluss.platform.dto.AccountDTO;
import cn.pluss.platform.entity.Account;
import cn.pluss.platform.entity.BankCard;
import cn.pluss.platform.merchant.AccountService;
import cn.pluss.platform.vo.AccountVO;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * @author djh
 *
 * 商户结算信息修改表
 */
@Controller
@RequestMapping("merchantAccount")
public class MerchantAccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 商户结算信息修改中的列表
     */
    @GetMapping("/index")
    public String index() {
        return "merchantAccount/edit_list";
    }

    /**
     * 获取分页信息
     * @param page          分页信息
     * @param entity        结算信息
     * @param orderItem     排序信息
     */
    @GetMapping("/page")
    @ResponseBody
    public Result<Page<AccountDTO>> page(Page<AccountDTO> page, Account entity, OrderItem orderItem) {
        AccountVO account = new AccountVO();
        BankCard bankCard = new BankCard();
        bankCard.setUserId("12345");
        bankCard.setBankCardNo("12345");
        bankCard.setBankName("建设银行");
        bankCard.setBranchName("建设银行湖北分行");
        account.setBankCard(bankCard);

        BankCard newBankCard = new BankCard();
        newBankCard.setUserId("12345");
        newBankCard.setBankCardNo("12345");
        newBankCard.setBankName("招商银行");
        newBankCard.setBranchName("招商银行湖北分行");
        newBankCard.setImgUrl("https://wwsdsd//sd");
        account.setBak((JSONObject) JSONObject.toJSON(newBankCard));
        account.setChannelType(Account.CHANNEL_TYPE_D0);
        account.setMerchantId("87551231131");

        page.setCurrent(1);
        page.setSize(10);
        page.setTotal(1);
        page.setRecords(new ArrayList<AccountDTO>() {{ add(account); }});

        return ResultGenerator.genSuccessResult(page);
    }
}