package com.njzscloud.supervisory.money.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.supervisory.money.pojo.entity.MoneyChangeDetailEntity;
import com.njzscloud.supervisory.money.pojo.result.MoneyChangeDetailExportResult;
import com.njzscloud.supervisory.money.service.MoneyChangeDetailService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

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

/**
 * 资金明细
 * @author ljw
 */
@Slf4j
@RestController
@RequestMapping("/money_change_detail")
@RequiredArgsConstructor
public class MoneyChangeDetailController {

    private final MoneyChangeDetailService moneyChangeDetailService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody MoneyChangeDetailEntity moneyChangeDetailEntity) {
        moneyChangeDetailService.add(moneyChangeDetailEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody MoneyChangeDetailEntity moneyChangeDetailEntity) {
        moneyChangeDetailService.modify(moneyChangeDetailEntity);
        return R.success();
    }

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

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

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<MoneyChangeDetailEntity>> paging(PageParam pageParam, MoneyChangeDetailEntity moneyChangeDetailEntity) {
        return R.success(moneyChangeDetailService.paging(pageParam, moneyChangeDetailEntity));
    }

    /**
     * 根据清运公司查询资金明细接口
     */
    @GetMapping("/selectPagingByCompanyId")
    public R<PageResult<MoneyChangeDetailExportResult>> selectPagingByCompanyId(PageParam pageParam, MoneyChangeDetailEntity entity) {
        return R.success(moneyChangeDetailService.selectPagingByCompanyId(pageParam, entity));
    }

    /**
     * 导出资金明细
     */
    @GetMapping(value = "/export")
    public void export(HttpServletResponse response, MoneyChangeDetailEntity entity) throws IOException {
        moneyChangeDetailService.export(response, entity);
    }

}
