package com.ym.mec.web.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.SysUserBankCard;
import com.ym.mec.biz.service.SysUserBankCardService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("userBankCard")
@Api(tags = "银行卡信息服务")
@RestController
public class SysUserBankCardController extends BaseController {

    @Autowired
    private SysUserBankCardService sysUserBankCardService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增银行卡信息")
    @PostMapping("/add")
    public Object add(SysUserBankCard sysUserBankCard) {
        if(sysUserBankCard == null){
            return failed("参数校验异常");
        }
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null || sysUser.getId() == null){
            return failed("获取用户失败");
        }
        sysUserBankCard.setUserId(sysUser.getId());
        return succeed(sysUserBankCardService.add(sysUserBankCard));
    }

    @ApiOperation(value = "删除银行卡信息")
    @PostMapping("/del")
    public Object del(Long id) {
        if(id == null){
            return failed("参数校验失败");
        }
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null || sysUser.getId() == null){
            return failed("获取用户信息失败");
        }
        sysUserBankCardService.del(id,sysUser.getId());
        return succeed();
    }

    @ApiOperation(value = "分页查询银行卡信息列表")
    @GetMapping("/queryPage")
    public Object queryPage() {
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(sysUser == null || sysUser.getId() == null){
            return failed("获取用户失败");
        }
        return succeed(sysUserBankCardService.findByUser(sysUser.getId()));
    }
}
