package com.njzscloud.dispose.finance.controller;

import com.njzscloud.common.core.utils.R;
import com.njzscloud.common.mp.support.PageParam;
import com.njzscloud.common.mp.support.PageResult;
import com.njzscloud.dispose.finance.pojo.entity.MoneyFlowEntity;
import com.njzscloud.dispose.finance.pojo.param.SearchMoneyFlowParam;
import com.njzscloud.dispose.finance.pojo.result.MoneyFlowResult;
import com.njzscloud.dispose.finance.service.MoneyFlowService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 资金流水
 * @author ljw
 */
@Slf4j
@RestController
@RequestMapping("/money_flow")
@RequiredArgsConstructor
public class MoneyFlowController {

    private final MoneyFlowService moneyFlowService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody MoneyFlowEntity moneyFlowEntity) {
        moneyFlowService.add(moneyFlowEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody MoneyFlowEntity moneyFlowEntity) {
        moneyFlowService.modify(moneyFlowEntity);
        return R.success();
    }

    /**
     * 删除
     */
    @PostMapping("/del")
    public R<?> del(@RequestBody List<Long> ids) {
        moneyFlowService.del(ids);
        return R.success();
    }

    /**
     * 详情
     */
    @GetMapping("/detail")
    public R<MoneyFlowEntity> detail(@RequestParam("id") Long id) {
        return R.success(moneyFlowService.detail(id));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<MoneyFlowResult>> paging(PageParam pageParam, SearchMoneyFlowParam flowParam) {
        return R.success(moneyFlowService.paging(pageParam, flowParam));
    }

    /**
     * 导出资金流水
     */
    @GetMapping(value = "/export")
    public void export(HttpServletResponse response, SearchMoneyFlowParam flowParam) throws IOException {
        moneyFlowService.export(response, flowParam);
    }
}


