package com.ym.mec.student.controller;


import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
import com.ym.mec.biz.dal.dto.MaintenancePayDto;
import com.ym.mec.biz.dal.dto.RegisterPayDto;
import com.ym.mec.biz.dal.entity.StudentInstrument;
import com.ym.mec.biz.dal.page.DegreeQueryInfo;
import com.ym.mec.biz.dal.page.StudentInstrumentQueryInfo;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
import com.ym.mec.biz.service.StudentInstrumentService;
import com.ym.mec.common.page.PageInfo;
import com.ym.mec.common.page.QueryInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@RequestMapping("studentInstrument")
@Api(tags = "乐器与乐保服务")
@RestController
public class StudentInstrumentController extends BaseController {
    @Autowired
    private StudentInstrumentService studentInstrumentService;
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private StudentInstrumentDao studentInstrumentDao;

    @ApiOperation(value = "获取乐器与乐保列表")
    @GetMapping("/getList")
    public HttpResponseResult<PageInfo<StudentInstrument>> getList(StudentInstrumentQueryInfo queryInfo) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || user.getId() == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        queryInfo.setStudentId(user.getId());
        studentInstrumentDao.batchUpdate();
        return succeed(studentInstrumentService.queryPage(queryInfo));
    }

    @ApiOperation(value = "乐保支付")
    @PostMapping("/pay")
    @ApiImplicitParams({@ApiImplicitParam(name = "maintenancePayDto", value = "支付参数", required = true, dataType = "MaintenancePayDto")})
    public HttpResponseResult pay(MaintenancePayDto maintenancePayDto) throws Exception {
        Map payMap = studentInstrumentService.pay(maintenancePayDto);
        if (payMap.containsKey("tradeState")) {
            return failed(HttpStatus.CREATED, payMap, "恭喜您,支付成功!");
        }
        return succeed(payMap);
    }
}
