package com.pj.tb_enterprise;

import com.pj.tb_enterprise.dto.EnterpriseDto;
import com.pj.tb_enterprise.vo.OrdersVo;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * Controller: tb_enterprise -- 商家(app接口)
 *
 * @author lbl
 */
@RestController
@RequestMapping("/app/TbEnterprise/")
public class TbEnterpriseAppController {


    /**
     * 底层 Service 对象
     */
    @Autowired
    TbEnterpriseService tbEnterpriseService;


    /**
     * 查认证信息
     */
    @RequestMapping("getInfo")
    public AjaxJson getInfo() {
        return AjaxJson.getSuccessData(tbEnterpriseService.selectByCreateBy());
    }

    /**
     * 改个人信息
     */
    @RequestMapping("update")
    public AjaxJson update(TbEnterprise t) {
        tbEnterpriseService.update(t);
        return AjaxJson.getSuccess();
    }

    /**
     * 商家认证
     */
    @PostMapping("identification")
    public AjaxJson identification(@Validated EnterpriseDto enterpriseParam) {
        boolean identification = tbEnterpriseService.identification(enterpriseParam);
        if (!identification) return AjaxJson.getError("商家认证信息提交失败!!!");

        return AjaxJson.getSuccess("商家认证信息已提交,管理员审核中,请耐心等待!");
    }



    /*------            正常业务👆👆    rpc远程调用👇👇                         -----------*/


    /**
     * 根据ID获取一级市场商户信息
     */
    @RequestMapping("rpc/getEnterpriseById")
    public com.pj.api.dto.EnterpriseDto getEnterpriseById(@RequestParam("id") Long enterpriseId) {
        com.pj.api.dto.EnterpriseDto enterpriseById = tbEnterpriseService.getEnterpriseById(enterpriseId);
        return enterpriseById;
    }

    /** 商户保存银行卡信息 */
    @RequestMapping("rpc/saveBankInfo")
    public boolean saveBankByEnterprise(@RequestParam("id")Long id, @RequestParam("bankName")String bankName, @RequestParam("bankAccount")String bankAccount) {
        return tbEnterpriseService.saveBankByEnterprise(id, bankName, bankAccount);
    }
}
