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.MoneyBillEntity;
import com.njzscloud.supervisory.money.service.MoneyBillService;
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;

/**
 * 对账单
 */
@Slf4j
@RestController
@RequestMapping("/money_bill")
@RequiredArgsConstructor
public class MoneyBillController {

    private final MoneyBillService moneyBillService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody MoneyBillEntity moneyBillEntity) {
        moneyBillService.add(moneyBillEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody MoneyBillEntity moneyBillEntity) {
        moneyBillService.modify(moneyBillEntity);
        return R.success();
    }

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

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

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

    /**
     * 根据清运公司ID分页查询
     */
    @GetMapping("/selectPagingByStationId")
    public R<PageResult<MoneyBillEntity>> selectPagingByStationId(PageParam pageParam, MoneyBillEntity moneyBillEntity) {
        return R.success(moneyBillService.selectPagingByStationId(pageParam, moneyBillEntity));
    }

    /**
     * 重新生成账单
     */
    @GetMapping("/rebuildBill")
    public R<?> rebuildBill(@RequestParam Long id) {
        moneyBillService.rebuildBill(id);
        return R.success();
    }

    /**
     * 导出
     */
    @GetMapping(value = "/export")
    public void export(HttpServletResponse response, MoneyBillEntity entity) throws IOException {
        moneyBillService.export(response, entity);
    }
}
