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.RescueDeptDriver;
import cn.iocoder.yudao.module.rescue.service.IRescueDeptDriverService;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 救援客户司机分配Controller
 *
 * @author zcy
 * @date 2023-09-21
 */
@RestController
@RequestMapping("/dept_driver/dept_driver")
public class RescueDeptDriverController extends BaseController {

    @Resource
    private IRescueDeptDriverService rescueDeptDriverService;

    /**
     * 查询救援客户司机分配列表
     */
    @GetMapping("/list")
    public CommonResult<IPage<?>> list(RescueDeptDriver rescueDeptDriver,
                                    @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<RescueDeptDriver> page = new Page<>(pageNo, pageSize);
        IPage<RescueDeptDriver> list = rescueDeptDriverService.selectRescueDeptDriverPage(rescueDeptDriver, page);
        return success(list);
    }

    /**
     * 导出救援客户司机分配列表
     */
//    @Log(title = "救援客户司机分配", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueDeptDriver rescueDeptDriver) {
        List<RescueDeptDriver> list = rescueDeptDriverService.list();
        ExcelUtil<RescueDeptDriver> util = new ExcelUtil<RescueDeptDriver>(RescueDeptDriver.class);
        util.exportExcel(response, list, "救援客户司机分配数据");
    }

    /**
     * 获取救援客户司机分配详细信息
     */
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id) {
        return success(rescueDeptDriverService.selectRescueDeptDriverById(id));
    }

    /**
     * 新增救援客户司机分配
     */
//    @Log(title = "救援客户司机分配", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody RescueDeptDriver rescueDeptDriver) {
        return toAjax(rescueDeptDriverService.insertRescueDeptDriver(rescueDeptDriver));
    }

    /**
     * 修改救援客户司机分配
     */
//    @Log(title = "救援客户司机分配", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody RescueDeptDriver rescueDeptDriver) {
        return toAjax(rescueDeptDriverService.updateRescueDeptDriver(rescueDeptDriver));
    }

    /**
     * 删除救援客户司机分配
     */
//    @PreAuthorize("@ss.hasPermission('dept_driver:dept_driver:remove')")
//    @Log(title = "救援客户司机分配", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids) {
        return toAjax(rescueDeptDriverService.deleteRescueDeptDriverByIds(ids));
    }
}

