package com.pj.project.tb_driver;

import com.pj.api.dto.DriverDto;
import com.pj.project.tb_driver.param.SucessDriverResultParam;
import com.pj.project.tb_driver.param.FailDriverResultParam;
import com.pj.utils.sg.AjaxJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * Controller: tb_driver -- 司机(app接口)
 * @author lbl
 */
@RestController
@RequestMapping("/app/TbDriver/")
public class TbDriverAppController {

	/** 底层 Service 对象 */
	@Autowired
	TbDriverService tbDriverService;

	/** 查个人信息 - 根据id */
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		TbDriver t = tbDriverService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

	/** 改个人信息 */
	@RequestMapping("update")
	public AjaxJson update(TbDriver t){
		tbDriverService.update(t);
		return AjaxJson.getSuccess();
	}

	/**
	 * 司机处理结果,同意
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("driverAgree")
	public AjaxJson driverDispose(@Validated @RequestBody SucessDriverResultParam driverResultParam) throws Exception {
		boolean dispose = tbDriverService.driverAgree(driverResultParam);
		if(dispose)return AjaxJson.getSuccess();
		return AjaxJson.getError();
	}

	/**
	 * 司机处理结果,拒绝
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("driverRefuse")
	public AjaxJson driverRefuse(FailDriverResultParam failDriverResultParam) throws Exception {
		boolean dispose = tbDriverService.driverRefuse(failDriverResultParam);
		if(dispose)return AjaxJson.getSuccess();
		return AjaxJson.getError();
	}


	/*--     正常业务方法 👆👆  远程调用 👇👇      --*/

	/** 查司机信息 - 根据id */
	@RequestMapping("rpc/getById")
	public DriverDto getByDriverId(@RequestParam("id") Long id){
		DriverDto t = tbDriverService.getByDriverId(id);
		return t;
	}


}
