package com.leromro.core.controller;

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

import com.leromro.common.utils.SecurityUtils;
import com.leromro.core.domain.vo.AccountChangeTotalMoney;
import com.leromro.core.domain.vo.ClientAccountChangeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.leromro.common.core.domain.R;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.leromro.common.annotation.Log;
import com.leromro.common.core.controller.BaseController;
import com.leromro.common.core.domain.AjaxResult;
import com.leromro.common.enums.BusinessType;
import com.leromro.core.domain.ClientAccountChange;
import com.leromro.core.service.IClientAccountChangeService;
import com.leromro.common.utils.poi.ExcelUtil;
import com.leromro.common.core.page.TableDataInfo;

/**
 * 用户钱包余额变更记录Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@RestController
@Api(tags = "用户钱包余额变更记录")
@RequestMapping("/core/client/account-change")
public class ClientAccountChangeController extends BaseController
{
    @Autowired
    private IClientAccountChangeService lClientAccountChangeService;

    /**
     * 查询用户自己的钱包变更记录
     */
    @ApiOperation("查询用户自己的账户变更记录 收入或支出字段在字典中 类型为：jlzj_money_change_type 用户变更来源 字典字段为：jlzj_client_source_type ")
    @GetMapping
    public TableDataInfo<ClientAccountChangeVO> clientAccountChange(ClientAccountChange clientAccountChange){
        startPage();
        clientAccountChange.setUserId(SecurityUtils.getUserId());
        List<ClientAccountChangeVO> list = lClientAccountChangeService.selectAccountChangeByuserId(clientAccountChange);
        return getDataTable(list);
    }
    /**
     * 查询自己的历史总支出和总收入
     */
    @ApiOperation("查询用户的总收入和总支出 列表接口一样，选择了日期也传进来 就会返回选择的所在日期的总钱数")
    @GetMapping("/totalMoney")
    public R<AccountChangeTotalMoney> clientAccountChangTotalHistoryInfo (ClientAccountChange clientAccountChange){
        clientAccountChange.setUserId(SecurityUtils.getUserId());
        AccountChangeTotalMoney totalMoneyHistory = lClientAccountChangeService.selectTotalHistory(clientAccountChange);
        return  R.ok(totalMoneyHistory);
    }

    /**
     * 查询用户钱包余额变更记录列表
     */
    @ApiOperation("查询用户钱包余额变更记录列表")
    //@PreAuthorize("@ss.hasPermi('core:change:list')")
    @GetMapping("/list")
    public TableDataInfo<ClientAccountChange> list(ClientAccountChange clientAccountChange)
    {
        startPage();
        List<ClientAccountChange> list = lClientAccountChangeService.selectLClientAccountChangeList(clientAccountChange);
        return getDataTable(list);
    }

    /**
     * 导出用户钱包余额变更记录列表
     */
    @ApiOperation("导出用户钱包余额变更记录列表")
    //@PreAuthorize("@ss.hasPermi('core:change:export')")
    @Log(title = "用户钱包余额变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClientAccountChange clientAccountChange)
    {
        List<ClientAccountChange> list = lClientAccountChangeService.selectLClientAccountChangeList(clientAccountChange);
        ExcelUtil<ClientAccountChange> util = new ExcelUtil<ClientAccountChange>(ClientAccountChange.class);
        util.exportExcel(response, list, "用户钱包余额变更记录数据");
    }

    /**
     * 获取用户钱包余额变更记录详细信息
     */
    @ApiOperation("获取用户钱包余额变更记录详细信息")
   // @PreAuthorize("@ss.hasPermi('core:change:query')")
    @GetMapping(value = "/{clientAccountChangeId}")
    public R<ClientAccountChange> getInfo(@PathVariable("clientAccountChangeId") Long clientAccountChangeId)
    {
        return R.ok(lClientAccountChangeService.selectLClientAccountChangeByClientAccountChangeId(clientAccountChangeId));
    }

    /**
     * 新增用户钱包余额变更记录
     */
    @ApiOperation("新增用户钱包余额变更记录")
    //@PreAuthorize("@ss.hasPermi('core:change:add')")
    @Log(title = "用户钱包余额变更记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClientAccountChange clientAccountChange)
    {
        return toAjax(lClientAccountChangeService.insertLClientAccountChange(clientAccountChange));
    }

    /**
     * 修改用户钱包余额变更记录
     */
    @ApiOperation("修改用户钱包余额变更记录")
    //@PreAuthorize("@ss.hasPermi('core:change:edit')")
    @Log(title = "用户钱包余额变更记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClientAccountChange clientAccountChange)
    {
        return toAjax(lClientAccountChangeService.updateLClientAccountChange(clientAccountChange));
    }

    /**
     * 删除用户钱包余额变更记录
     */
    @ApiOperation("删除用户钱包余额变更记录")
    //@PreAuthorize("@ss.hasPermi('core:change:remove')")
    @Log(title = "用户钱包余额变更记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{clientAccountChangeIds}")
    public R<Integer> remove(@PathVariable Long[] clientAccountChangeIds)
    {
        return R.ok(lClientAccountChangeService.deleteLClientAccountChangeByClientAccountChangeIds(clientAccountChangeIds));
    }
}
