package com.pj.project.tb_logistics;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.pj.api.dto.TbLogisticsDto;
import com.pj.project4sp.SP;
import com.pj.utils.sg.AjaxJson;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Controller: tb_logistics -- 物流订单表(APP接口)
 * @author qzy
 */
@RestController
@RequestMapping("/app/TbLogistics/")
public class TbLogisticsAppController {

	/** 底层 Service 对象 */
	@Autowired
	TbLogisticsService tbLogisticsService;

	/** 查 - 根据id */
	@RequestMapping("getById")
	public AjaxJson getById(Long id){
		TbLogistics t = tbLogisticsService.getById(id);
		return AjaxJson.getSuccessData(t);
	}

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


	/** 增 二级市场订单选择车辆时触发,物流订单在此传入并绑定二级市场订单号*/
	@RequestMapping("saveLogisticOrder")
	public AjaxJson saveLogisticOrder(TbLogisticsDto logisticsDto) {
		boolean result = tbLogisticsService.saveLogisticOrder(logisticsDto);
		if(result) return AjaxJson.getSuccess();

		return AjaxJson.getError();
	}

	/** 改 根据物流订单Id,修改物流状态*/
	@RequestMapping("updateLogisticStatus")
	public AjaxJson updateLogisticStatus(TbLogisticsDto logisticsDto) {
		boolean result = tbLogisticsService.saveLogisticOrder(logisticsDto);
		if(result) return AjaxJson.getSuccess();

		return AjaxJson.getError();
	}

	/** 查 通过司机Id查物流订单 */
	@RequestMapping("getAppList")
	public AjaxJson selectByDriverId() {
		SoMap so = SoMap.getRequestSoMap();
		List<TbLogistics> list = tbLogisticsService.selectByDriverId(so.startPage());
		return AjaxJson.getPageData(Long.valueOf(list.size()), list);
	}

}
