package com.ruoyi.invest.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.invest.domain.AccountsDealRecord;
import com.ruoyi.invest.domain.dto.AccountsDealRecordDto;
import com.ruoyi.invest.domain.vo.AccountsDealRecordVo;
import com.ruoyi.invest.service.IAccountsDealRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 账户交易记录Controller
 *
 * @author tianyongbao
 * @date 2024-03-30
 */
@Api(tags=" 账户交易记录")
@RestController
@RequestMapping("/accountDealRecord")
public class AccountsDealRecordController extends BaseController
{
    @Resource
    private IAccountsDealRecordService accountsDealRecordService;

    /**
     * 查询账户交易记录列表
     */
    @ApiOperation(value="查询账户交易记录列表",response = AccountsDealRecordVo.class)
    @RequiresPermissions("invest:accountDealRecord:list")
    @GetMapping("/list")
    public TableDataInfo list(AccountsDealRecordDto accountsDealRecordDto)
    {
        startPage();
        List<AccountsDealRecordVo> list = accountsDealRecordService.selectAccountsDealRecordList(accountsDealRecordDto);
        return getDataTable(list);
    }

    /**
     * 导出账户交易记录列表
     */
    @ApiOperation(value="导出账户交易记录列表")
    @RequiresPermissions("invest:accountDealRecord:export")
    @Log(title = "账户交易记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountsDealRecordDto accountsDealRecordDto)
    {
        List<AccountsDealRecordVo> list = accountsDealRecordService.selectAccountsDealRecordList(accountsDealRecordDto);
        ExcelUtil<AccountsDealRecordVo> util = new ExcelUtil<AccountsDealRecordVo>(AccountsDealRecordVo.class);
        util.exportExcel(response, list, "账户交易记录数据");
    }

    /**
     * 获取账户交易记录详细信息
     */
    @ApiOperation(value="获取账户交易记录详细信息")
    @RequiresPermissions("invest:accountDealRecord:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountsDealRecordService.selectAccountsDealRecordById(id));
    }

    /**
     * 新增账户交易记录
     */
    @ApiOperation(value="新增账户交易记录")
    @RequiresPermissions("invest:accountDealRecord:add")
    @Log(title = "账户交易记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountsDealRecord accountsDealRecord)
    {
        return toAjax(accountsDealRecordService.insertAccountsDealRecord(accountsDealRecord));
    }

    /**
     * 修改账户交易记录
     */
    @ApiOperation(value="修改账户交易记录")
    @RequiresPermissions("invest:accountDealRecord:edit")
    @Log(title = "账户交易记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountsDealRecord accountsDealRecord)
    {
        return toAjax(accountsDealRecordService.updateAccountsDealRecord(accountsDealRecord));
    }

    /**
     * 删除账户交易记录
     */
    @ApiOperation(value="删除账户交易记录")
    @RequiresPermissions("invest:accountDealRecord:remove")
    @Log(title = "账户交易记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accountsDealRecordService.deleteAccountsDealRecordByIds(ids));
    }
}
