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.RescueDriverPosition;
import cn.iocoder.yudao.module.rescue.service.IRescueDriverPositionService;
import cn.iocoder.yudao.module.rescue.utils.ExcelUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.java.Log;
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-19
 */
@RestController
@RequestMapping("/rescue/rescue_driver_position")
public class RescueDriverPositionController extends BaseController {
    @Autowired
    private IRescueDriverPositionService rescueDriverPositionService;

    /**
     * 查询救援司机位置记录列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescue_driver_position:list')")
    @GetMapping("/list")
    public CommonResult list(RescueDriverPosition rescueDriverPosition,
                             @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                             @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<RescueDriverPosition> page = new Page<>(pageNum, pageSize);
        IPage<RescueDriverPosition> list = rescueDriverPositionService.selectRescueDriverPositionList(page,rescueDriverPosition);
        return success(list);
    }

    /**
     * 导出救援司机位置记录列表
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescue_driver_position:export')")
//    @Log(title = "救援司机位置记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RescueDriverPosition rescueDriverPosition,
                       @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                       @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize)
    {
        Page<RescueDriverPosition> page = new Page<>(pageNum, pageSize);
        IPage<RescueDriverPosition> list = rescueDriverPositionService.selectRescueDriverPositionList(page,rescueDriverPosition);
        ExcelUtil<RescueDriverPosition> util = new ExcelUtil<RescueDriverPosition>(RescueDriverPosition.class);
        util.exportExcel(response, list.getRecords(), "救援司机位置记录数据");
    }

    /**
     * 获取救援司机位置记录详细信息
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescue_driver_position:query')")
    @GetMapping(value = "/{id}")
    public CommonResult getInfo(@PathVariable("id") Long id)
    {
        return success(rescueDriverPositionService.selectRescueDriverPositionById(id));
    }

    /**
     * 新增救援司机位置记录
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescue_driver_position:add')")
//    @Log(title = "救援司机位置记录", businessType = BusinessType.INSERT)
    @PostMapping
    public CommonResult add(@RequestBody RescueDriverPosition rescueDriverPosition)
    {
        return toAjax(rescueDriverPositionService.insertRescueDriverPosition(rescueDriverPosition));
    }

    /**
     * 修改救援司机位置记录
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescue_driver_position:edit')")
//    @Log(title = "救援司机位置记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public CommonResult edit(@RequestBody RescueDriverPosition rescueDriverPosition)
    {
        return toAjax(rescueDriverPositionService.updateRescueDriverPosition(rescueDriverPosition));
    }

    /**
     * 删除救援司机位置记录
     */
    @PreAuthorize("@ss.hasPermission('rescue:rescue_driver_position:remove')")
//    @Log(title = "救援司机位置记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public CommonResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rescueDriverPositionService.deleteRescueDriverPositionByIds(ids));
    }


    /**
     * 查询救援司机位置记录列表
     */
    @GetMapping("/listByInfoId")
    public CommonResult listByInfoId(RescueDriverPosition rescueDriverPosition,
                                     @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                     @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<RescueDriverPosition> page = new Page<>(pageNum, pageSize);
        IPage<RescueDriverPosition> list = rescueDriverPositionService.listByInfoId(page,rescueDriverPosition);
        return success(list);
    }

    /**
     * 查询救援司机位置记录列表
     */
    @GetMapping("/routeInfo")
    public CommonResult routeInfo(RescueDriverPosition rescueDriverPosition,
                                  @RequestParam(value = "pageNum" ,required = false ,defaultValue = "1") Integer pageNum,
                                  @RequestParam(value ="pageSize" ,required = false ,defaultValue = "10") Integer pageSize) {
        Page<RescueDriverPosition> page = new Page<>(pageNum, pageSize);
        IPage<JSONObject> res = rescueDriverPositionService.routeInfo(page,rescueDriverPosition);
        return success(res);
    }
}
