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

import java.util.List;

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.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.dto.business.DispatchCheckQueryDTO;
import com.prolog.rdc.tms.app.model.dto.business.SendCarQueryDTO;
import com.prolog.rdc.tms.app.model.vo.SendCarUndoAuditVO;
import com.prolog.rdc.tms.app.model.vo.business.SendCarDeleteDetailVO;
import com.prolog.rdc.tms.app.model.vo.business.SendCarQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.ShipbillQueryVO;
import com.prolog.rdc.tms.app.service.business.SendCarService;

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

/**
 * 已派车控制层
 *
 * @author zhangsj
 * @since 2022-04-13 14:35:06
 */
@RestController
@Api(tags = "调度管理-已派车控制层")
@RequestMapping("send_car")
public class SendCarController {

	@Autowired
	private SendCarService service;

	@UserLog("已派车查询")
	@ApiOperation(value = "已派车查询", notes = "已派车查询")
	@PostMapping("/page")
	public RestMessage<Page<SendCarQueryDTO>> loadingBillQueryExecute(@RequestBody SendCarQueryVO sendCarVO) {
		try {
			Page<SendCarQueryDTO> queryDTOS = service.loadingBillQuery(sendCarVO);
			return RestMessage.newInstance(true, "查询成功！", queryDTOS);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("运单查询")
	@ApiOperation(value = "运单查询", notes = "运单查询")
	@PostMapping("/shipbill")
	public RestMessage<Page<DispatchCheckQueryDTO>> shipbillQueryExecute(@RequestBody ShipbillQueryVO shipbillQueryVO) {
		try {
			Page<DispatchCheckQueryDTO> dispatchCheckQueryDTOS = service.shipbillQuery(shipbillQueryVO);
			return RestMessage.newInstance(true, "查询成功", dispatchCheckQueryDTOS);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已派车运单撤销")
	@ApiOperation(value = "已派车运单撤销", notes = "已派车运单撤销")
	@PostMapping("/sendcar_undo")
	public RestMessage<Object> sendcarUndoExecute(@RequestBody List<String> ids) {
		try {
			service.sendcarUndoData(ids);
			return RestMessage.newInstance(true, "撤销成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已派车审核")
	@ApiOperation(value = "已派车审核", notes = "已派车审核")
	@PostMapping("/sendcar_audit")
	public RestMessage<Object> sendcarAuditExecute(@RequestBody List<String> ids) {
		try {
			service.sendcarAuditData(ids);
			return RestMessage.newInstance(true, "审核成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已派车配载运单剔除")
	@ApiOperation(value = "已派车配载运单剔除", notes = "已派车配载运单剔除")
	@PostMapping("/delete_detail")
	public RestMessage<Object> deleteDetailSendCarExecute(@RequestBody SendCarDeleteDetailVO sendCarDeleteDetailVO) {
		try {
			service.deleteDetailSendCarData(sendCarDeleteDetailVO);
			return RestMessage.newInstance(true, "剔除成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已派车-反审核")
	@ApiOperation(value = "已派车-反审核", notes = "已派车-反审核")
	@PostMapping("/undoAudit")
	public RestMessage<Object> undoAuditSendCarExecute(@RequestBody SendCarUndoAuditVO sendCarUndoAuditVO) {
		try {
			service.undoAuditSendCarData(sendCarUndoAuditVO);
			return RestMessage.newInstance(true, "反审核成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
