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.RescueRefuelRecord;
import cn.iocoder.yudao.module.rescue.service.IRescueRefuelRecordService;
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-09-26
 */
@RestController
@RequestMapping("/rescue/refuelRecord")
public class RescueRefuelRecordController extends BaseController {
    @Autowired
    private IRescueRefuelRecordService rescueRefuelRecordService;

    /**
     * 查询加油记录列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:refuelRecord:list')")
    @GetMapping("/list")
    public CommonResult list(RescueRefuelRecord rescueRefuelRecord,
                             @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<RescueRefuelRecord> page = new Page<>(pageNo, pageSize);
        return success(rescueRefuelRecordService.selectRescueRefuelRecordList(rescueRefuelRecord, page));
    }

    /**
     * 导出加油记录列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:refuelRecord:export')")
//    @Log(title = "加油记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueRefuelRecord rescueRefuelRecord) {
        List<RescueRefuelRecord> list = rescueRefuelRecordService.list();
        ExcelUtil<RescueRefuelRecord> util = new ExcelUtil<RescueRefuelRecord>(RescueRefuelRecord.class);
        util.exportExcel(response, list, "加油记录数据");
    }

    /**
     * 获取加油记录详细信息
     */
    @PreAuthorize("@ss.hasPermission('rescue:refuelRecord:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id) {
        return success(rescueRefuelRecordService.selectRescueRefuelRecordById(id));
    }

    /**
     * 新增加油记录
     */
    @PreAuthorize("@ss.hasPermission('rescue:refuelRecord:add')")
//    @Log(title = "加油记录", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody RescueRefuelRecord rescueRefuelRecord) {
        return toAjax(rescueRefuelRecordService.insertRescueRefuelRecord(rescueRefuelRecord));
    }

    /**
     * 修改加油记录
     */
    @PreAuthorize("@ss.hasPermission('rescue:refuelRecord:edit')")
//    @Log(title = "加油记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody RescueRefuelRecord rescueRefuelRecord) {
        return toAjax(rescueRefuelRecordService.updateRescueRefuelRecord(rescueRefuelRecord));
    }

    /**
     * 删除加油记录
     */
    @PreAuthorize("@ss.hasPermission('rescue:refuelRecord:remove')")
//    @Log(title = "加油记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return toAjax(rescueRefuelRecordService.deleteRescueRefuelRecordByIds(ids));
    }
}

