package com.pj.project.tb_vehicle;

import com.pj.enummj.DeleteStatus;
import com.pj.project.tb_vehicle.param.MakeCarRecordParam;
import com.pj.project.tb_vehicle.vo.TbVehicleVo;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: tb_vehicle -- 车辆(app接口)
 * @author lbl
 */
@RestController
@RequestMapping("/app/TbVehicle/")
public class TbVehicleAppController {

	/** 底层 Service 对象 */
	@Autowired
	TbVehicleService tbVehicleService;


	/** 查 - 根据车牌号查车辆信息 */
	@RequestMapping("getByVehiclePlate")
	public AjaxJson getByVehiclePlate(String vehiclePlate){
		List<TbVehicle> t = tbVehicleService.getByVehiclePlate(vehiclePlate);
		if(t.size() == 0)return AjaxJson.getSuccess("暂无更多车辆信息~");
		return AjaxJson.getSuccessData(t);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */
	@RequestMapping("getList")
	public AjaxJson getList() {
		SoMap so = SoMap.getRequestSoMap();
		so.put("deleteStatus", DeleteStatus.DELETE_STATUS_ON.getCode());
		List<TbVehicle> list = tbVehicleService.getList(so.startPage());
		return AjaxJson.getPageData(so.getDataCount(), list);
	}


	/** 改 - 根据车辆Id修改车辆状态 */
	@RequestMapping("updateStatusByVehicleId")
	public AjaxJson updateStatusByVehicleId(TbVehicleVo vehicleVo) {
		boolean result = tbVehicleService.updateStatusByVehicleId(vehicleVo);
		if(result) return AjaxJson.getSuccess();

		return AjaxJson.getError();
	}

	/**
	 * 商户确定车辆后执行通知司机
	 * @param makeCarRecordParam
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("informDriver")
	public AjaxJson informDriver(@Validated @RequestBody MakeCarRecordParam makeCarRecordParam) throws Exception {
		tbVehicleService.informDriver(makeCarRecordParam);
		return AjaxJson.getSuccess();
	}



}
