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

import com.prolog.framework.common.message.RestMessage;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.dto.ScanDispatchBillDTO;
import com.prolog.rdc.tms.app.model.dto.business.ScanDispatchInfoDTO;
import com.prolog.rdc.tms.app.model.dto.business.ScanDispatchOrderInfoDTO;
import com.prolog.rdc.tms.app.model.dto.business.ScanDispatchShipbillInfoDTO;
import com.prolog.rdc.tms.app.model.vo.BillScanVO;
import com.prolog.rdc.tms.app.model.vo.ScanShipbillDetailConfirmVO;
import com.prolog.rdc.tms.app.model.vo.business.LoadingScanConfirmVO;
import com.prolog.rdc.tms.app.model.vo.business.PendingDispatchVO;
import com.prolog.rdc.tms.app.service.business.ScanDispatchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 javax.validation.Valid;
import java.util.List;

/**
 * 扫描派车
 *
 * @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("/getScanOrderInfo")
	public RestMessage<ScanDispatchOrderInfoDTO> getScanOrderInfoExecute(@RequestBody BillScanVO vo) {
		try {
			ScanDispatchOrderInfoDTO scannedBillDTO = scanDispatchService.getScanDispatchInfo(vo);
			return RestMessage.newInstance(true, "查询成功", scannedBillDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("获取扫描运单信息")
	@ApiOperation(value = "获取扫描运单信息", notes = "获取扫描运单信息")
	@PostMapping("/getScanShipbillInfo")
	public RestMessage<ScanDispatchShipbillInfoDTO> getScanShipbillInfoExecute(@RequestBody BillScanVO vo) {
		try {
			ScanDispatchShipbillInfoDTO scannedBillDTO = scanDispatchService.getScanShipbillInfo(vo);
			return RestMessage.newInstance(true, "查询成功", scannedBillDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("获取扫描运单明细信息")
	@ApiOperation(value = "获取扫描运单明细信息", notes = "获取扫描运单明细信息")
	@PostMapping("/getScanShipbillDetailInfo")
	public RestMessage<ScanDispatchShipbillInfoDTO> getScanShipbillDetailInfoExecute(@RequestBody BillScanVO vo) {
		try {
			ScanDispatchShipbillInfoDTO scannedBillDTO = scanDispatchService.getScanShipbillDetailInfo(vo);
			return RestMessage.newInstance(true, "查询成功", scannedBillDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已扫运单确认")
	@ApiOperation(value = "已扫运单确认", notes = "已扫运单确认")
	@PostMapping("/scanShipbillConfirm")
	public RestMessage<Object> scanShipbillConfirmExecute(@RequestBody @Valid List<ScanShipbillDetailConfirmVO> vos) {
		try {
			scanDispatchService.scanShipbillConfirm(vos);
			return RestMessage.newInstance(true, "确认成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

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

	@UserLog("单据剔除")
	@ApiOperation(value = "单据剔除", notes = "单据剔除")
	@PostMapping("/billOut")
	public RestMessage<Object> shipBillOut(@RequestBody BillScanVO vo) {
		scanDispatchService.shipBillOut(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}
}
