package cn.iocoder.yudao.module.rescue.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.rescue.core.controller.BaseController;
import cn.iocoder.yudao.module.rescue.domain.RescueCarSpend;
import cn.iocoder.yudao.module.rescue.service.IRescueCarSpendService;
import cn.iocoder.yudao.module.rescue.utils.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 车辆消费管理Controller
 *
 * @author zcy
 * @date 2023-11-30
 */
@RestController
@RequestMapping("/rescue/rescueCarSpend")
public class RescueCarSpendController extends BaseController {
    @Autowired
    private IRescueCarSpendService rescueCarSpendService;

    /**
     * 查询车辆消费管理列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:list')")
    @GetMapping("/list")
    public CommonResult list(RescueCarSpend rescueCarSpend,
                             @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<RescueCarSpend> page = new Page<>(pageNo, pageSize);
        IPage<RescueCarSpend> list = rescueCarSpendService.selectRescueCarSpendList(rescueCarSpend, page);
        return success(list);
    }

    /**
     * 导出车辆消费管理列表
     */
//    @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:export')")
//    @Log(title = "车辆消费管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, RescueCarSpend rescueCarSpend) {
        List<RescueCarSpend> list = rescueCarSpendService.list();
        ExcelUtil<RescueCarSpend> util = new ExcelUtil<RescueCarSpend>(RescueCarSpend.class);
        util.exportExcel(response, list, "车辆消费管理数据");
    }

    /**
     * 获取车辆消费管理详细信息
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id) {
        return success(rescueCarSpendService.selectRescueCarSpendById(id));
    }

    /**
     * 新增车辆消费管理
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:add')")
//    @Log(title = "车辆消费管理", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody RescueCarSpend rescueCarSpend) {
        return toAjax(rescueCarSpendService.insertRescueCarSpend(rescueCarSpend));
    }

    /**
     * 修改车辆消费管理
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:edit')")
//    @Log(title = "车辆消费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody RescueCarSpend rescueCarSpend) {
        return toAjax(rescueCarSpendService.updateRescueCarSpend(rescueCarSpend));
    }

    /**
     * 删除车辆消费管理
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescueCarSpend:remove')")
//    @Log(title = "车辆消费管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return toAjax(rescueCarSpendService.deleteRescueCarSpendByIds(ids));
    }
}
