package com.prolog.rdc.tms.app.controller.web;

import java.util.List;

import javax.annotation.Resource;
import javax.validation.Valid;

import com.prolog.rdc.tms.app.model.vo.business.TakeNumberByLoadingBillListVO;
import com.prolog.rdc.tms.app.service.business.TakeNumberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.dto.PendingPickUpDetailQueryDTO;
import com.prolog.rdc.tms.app.model.dto.PendingPickUpQueryDTO;
import com.prolog.rdc.tms.app.model.dto.PendingPickUpTakeNumberDTO;
import com.prolog.rdc.tms.app.model.dto.WarehousePickUpNumberDataDTO;
import com.prolog.rdc.tms.app.model.vo.PendingPickUpDetailQueryVO;
import com.prolog.rdc.tms.app.model.vo.PendingPickUpQueryVO;
import com.prolog.rdc.tms.app.model.vo.PendingPickUpSignInVO;
import com.prolog.rdc.tms.app.model.vo.PendingPickUpStartShipmentVO;
import com.prolog.rdc.tms.app.model.vo.PendingPickUpTakeNumberVO;
import com.prolog.rdc.tms.app.model.vo.TakeNumberByShipbillVO;
import com.prolog.rdc.tms.app.model.vo.WarehousePickUpNumberDataVO;
import com.prolog.rdc.tms.app.service.PendingPickUpService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 *
 *
 * 司机APP-待提货
 *
 * @className :PendingPickUpController
 * @author :qian.yh
 * @creationTime :2022/07/05
 * @description :
 *
 * @modifier :
 * @modifyTime :
 * @reviseRemarks:
 *
 * @version :1.0.0
 *
 */
@Api(tags = "司机APP-待提货控制层")
@RestController
@RequestMapping("/pending_pick_up")
public class PendingPickUpController {

	@Resource
	private PendingPickUpService pendingPickUpService;

	@Autowired
	private TakeNumberService takeNumberService;

	@UserLog("提货任务数汇总查询")
	@ApiOperation(value = "提货任务数汇总查询", notes = "提货任务数汇总查询")
	@PostMapping("/pending_pick_up_query")
	public RestMessage<List<PendingPickUpQueryDTO>> pendingPickUpQuery(@RequestBody PendingPickUpQueryVO pendingPickUpQueryVO) {
		try {
			List<PendingPickUpQueryDTO> dtos = pendingPickUpService.pendingPickUpQuery(pendingPickUpQueryVO);
			return RestMessage.newInstance(true, "查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("提货任务明细查询")
	@ApiOperation(value = "提货任务明细查询", notes = "提货任务明细查询")
	@PostMapping("/pending_pick_up_detail_query")
	public RestMessage<List<PendingPickUpDetailQueryDTO>> pendingPickUpDetailQuery(@RequestBody PendingPickUpDetailQueryVO pendingPickUpDetailQueryVO) {
		try {
			List<PendingPickUpDetailQueryDTO> dtos = pendingPickUpService.pendingPickUpDetailQuery(pendingPickUpDetailQueryVO);
			return RestMessage.newInstance(true, "查询成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("提货签到")
	@ApiOperation(value = "提货签到", notes = "提货签到")
	@PostMapping("/pending_pick_up_sign_in")
	public RestMessage<String> pendingPickUpSignIn(@RequestBody PendingPickUpSignInVO pendingPickUpSignInVO) {
		try {
			pendingPickUpService.pendingPickUpSignIn(pendingPickUpSignInVO);
			return RestMessage.newInstance(true, "提货签到成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("仓库提货取号数据查询")
	@ApiOperation(value = "仓库提货取号数据查询", notes = "仓库提货取号数据查询")
	@PostMapping("/warehouse_pick_up_number_data")
	public RestMessage<WarehousePickUpNumberDataDTO> warehousePickUpNumberData(@RequestBody WarehousePickUpNumberDataVO queryvo) {
		try {
			WarehousePickUpNumberDataDTO dto = pendingPickUpService.warehousePickUpNumberData(queryvo);
			return RestMessage.newInstance(true, "仓库提货取号数据查询成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("提货取号")
	@ApiOperation(value = "提货取号", notes = "提货取号")
	@PostMapping("/pending_pick_up_take_number")
	public RestMessage<PendingPickUpTakeNumberDTO> pendingPickUpTakeNumber(@RequestBody PendingPickUpTakeNumberVO pendingPickUpTakeNumberVO) {
		try {
			PendingPickUpTakeNumberDTO dto = pendingPickUpService.pendingPickUpTakeNumber(pendingPickUpTakeNumberVO);
			return RestMessage.newInstance(true, "提货取号成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("启运登记")
	@ApiOperation(value = "启运登记", notes = "启运登记")
	@PostMapping("/pending_pick_up_start_shipment")
	public RestMessage<List<PendingPickUpDetailQueryDTO>> pendingPickUpStartShipment(@RequestBody @Valid PendingPickUpStartShipmentVO pendingPickUpStartShipmentVO) {
		try {
			List<PendingPickUpDetailQueryDTO> dtos = pendingPickUpService.pendingPickUpStartShipment(pendingPickUpStartShipmentVO);
			return RestMessage.newInstance(true, "启运登记成功", dtos);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("按运单取号")
	@ApiOperation(value = "按运单取号", notes = "按运单取号")
	@PostMapping("/takeNumberByShipbill")
	public RestMessage<PendingPickUpTakeNumberDTO> takeNumberByShipbill(@RequestBody TakeNumberByShipbillVO vo) {
		try {
			PendingPickUpTakeNumberDTO dto = pendingPickUpService.takeNumberByShipbill(vo);
			return RestMessage.newInstance(true, "按运单取号成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("按派车单取号")
	@ApiOperation(value = "按派车单取号", notes = "按派车单取号")
	@PostMapping("/takeNumberByLoadingBill")
	public RestMessage<PendingPickUpTakeNumberDTO> takeNumberByLoadingBill(@RequestBody @Valid TakeNumberByLoadingBillListVO vo) {
		try {
			PendingPickUpTakeNumberDTO dto = takeNumberService.takeNumberByLoadingBillList(vo.getLoadingBillIdList());
			return RestMessage.newInstance(true, "按派车单取号成功", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
