package com.prolog.rdc.tms.controller;

import com.prolog.rdc.tms.model.dto.ScanDispatchBillDTO;
import com.prolog.rdc.tms.model.vo.BillScanVO;
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.RequestParam;
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.model.dto.ScanDispatchShipbillDTO;
import com.prolog.rdc.tms.model.vo.ScanDispatchReviewVO;
import com.prolog.rdc.tms.model.vo.ScanDispatchVO;
import com.prolog.rdc.tms.service.ScanDispatchService;

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

import javax.validation.Valid;

/**
 * 扫描派车
 *
 * @author lhb
 * @since 2022-04-26 09:04:35
 */
@RestController
@Api(tags = "调度管理-扫描派车")
@RequestMapping("/scanDispatch")
public class ScanDispatchController {

	@Autowired
	private ScanDispatchService scanDispatchService;

	@UserLog("单号扫描")
	@ApiOperation(value = "单号扫描", notes = "单号扫描")
	@PostMapping("/scanBill")
	public RestMessage<ScanDispatchBillDTO> scanBillExecute(@RequestBody @Valid BillScanVO vo) {
		try {
			ScanDispatchBillDTO scannedBillDTO = scanDispatchService.scanBill(vo);
			return RestMessage.newInstance(true, "单号扫描查询成功", scannedBillDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("扫描派车调度")
	@ApiOperation(value = "扫描派车调度", notes = "扫描派车调度")
	@PostMapping("/dispatch")
	public RestMessage<String> dispatchShipbillExecute(@RequestBody ScanDispatchVO vo) {
		try {
			scanDispatchService.dispatch(vo);
			return RestMessage.newInstance(true, "调度成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
