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.dto.CashAccountDetail;
import com.ym.mec.biz.dal.entity.SysUserCashAccountDetail;
import com.ym.mec.biz.service.SysUserCashAccountDetailService;
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("userCashAccountDetail")
@Api(tags = "用户交易明细服务")
@RestController
public class SysUserCashAccountDetailController extends BaseController {

    @Autowired
    private SysUserCashAccountDetailService sysUserCashAccountDetailService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增用户交易明细")
    @PostMapping("/add")
    public Object add(SysUserCashAccountDetail sysUserCashAccountDetail) {
        sysUserCashAccountDetailService.insert(sysUserCashAccountDetail);
        return succeed();
    }

    @ApiOperation(value = "分页查询用户交易明细")
    @GetMapping("/queryPage")
    public Object queryPage(CashAccountDetail queryInfo) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if(user == null && user.getId() != null){
            return failed("请重新登录");
        }
        queryInfo.setUserId(user.getId());
        return succeed(sysUserCashAccountDetailService.queryPage(queryInfo));
    }

}
