package com.njzscloud.dispose.cst.driver.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.dispose.cst.driver.pojo.entity.DriverEntity;
import com.njzscloud.dispose.cst.driver.pojo.param.DriverQueryParam;
import com.njzscloud.dispose.cst.driver.pojo.param.QRCodeParam;
import com.njzscloud.dispose.cst.driver.pojo.result.DriverResult;
import com.njzscloud.dispose.cst.driver.service.DriverService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 司机
 *
 * @author ljw
 */
@Slf4j
@RestController
@RequestMapping("/driver")
@RequiredArgsConstructor
public class DriverController {

    private final DriverService driverService;

    /**
     * 新增
     */
    @PostMapping("/add")
    public R<?> add(@RequestBody DriverEntity driverEntity) {
        driverService.add(driverEntity);
        return R.success();
    }

    /**
     * 修改
     */
    @PostMapping("/modify")
    public R<?> modify(@RequestBody DriverEntity driverEntity) {
        driverService.modify(driverEntity);
        return R.success();
    }

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

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

    /**
     * 通过userId获取司机详情
     */
    @GetMapping("/detailByUserId")
    public R<DriverResult> detailByUserId(@RequestParam("userId") Long userId) {
        return R.success(driverService.detailByUserId(userId));
    }

    /**
     * 分页查询
     */
    @GetMapping("/paging")
    public R<PageResult<DriverResult>> paging(PageParam pageParam, DriverQueryParam queryParam) {
        return R.success(driverService.paging(pageParam, queryParam));
    }

    /**
     * 获取二维码
     */
    @GetMapping("/getCode")
    public R<?> getCode(QRCodeParam codeParam) {
        return R.success(driverService.getCode(codeParam));
    }

}


