package com.zjrs.ggfw.yjt.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.zjrs.ggfw.yjt.bpo.YjtBPO;
import com.zjrs.ggfw.yjt.dto.KyeDTO;
import com.zjrs.ggfw.yjt.dto.XfmxDTO;
import org.mohrss.leaf.core.framework.web.controller.AjaxResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;

@Api(tags = "银结通服务平台接口")
@RestController
@RequestMapping("/api/ylt/comm")
public class YjtController {

    private static final Logger LOG = LoggerFactory.getLogger(YjtController.class);
    @Resource
    private YjtBPO yjtBPO;
    @ApiOperation(value = "查询消费明细")
    @PostMapping("/upayDetail")
    public AjaxResponse upayDetail(@RequestBody @Valid XfmxDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
        }
        try {
            return yjtBPO.upayDetail(dto);
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
    @ApiOperation(value = "查询卡余额")
    @PostMapping("/getBalance")
    public AjaxResponse getBalance(@RequestBody @Valid KyeDTO dto, BindingResult bindingResult) {
        AjaxResponse ajaxResponse = new AjaxResponse();
        //校验入参
        if(bindingResult.hasErrors()) {
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg(bindingResult.getFieldError().getDefaultMessage());
            return ajaxResponse;
        }
        try {
            return yjtBPO.getBalance(dto);
        } catch (Exception e) {
            e.printStackTrace();
            LOG.error(e.getMessage());
            ajaxResponse.setAppcode("1");
            ajaxResponse.setErrorMsg("系统异常");
        }
        return ajaxResponse;
    }
}
