package com.prolog.rdc.tms.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

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.common.util.DateUtils;
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.model.dto.AppLoadingPackageDTO;
import com.prolog.rdc.tms.model.dto.AppLoadingShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.AppLoadingShipbillDTO;
import com.prolog.rdc.tms.model.dto.AppointmentConsigneeQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentExportShipbillDTO;
import com.prolog.rdc.tms.model.dto.AppointmentLoadingBillQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentQueryDTO;
import com.prolog.rdc.tms.model.dto.AppointmentShipperQueryDTO;
import com.prolog.rdc.tms.model.dto.PickUpAppointmentDTO;
import com.prolog.rdc.tms.model.dto.print.AppointmentPrintDTO;
import com.prolog.rdc.tms.model.vo.AppConfirmShipbillVO;
import com.prolog.rdc.tms.model.vo.AppLoadingShipbillPageVO;
import com.prolog.rdc.tms.model.vo.AppointmentAdsQueryVO;
import com.prolog.rdc.tms.model.vo.AppointmentPrintVO;
import com.prolog.rdc.tms.model.vo.AppointmentQueryVO;
import com.prolog.rdc.tms.model.vo.PickUpAppointmentConfirmVO;
import com.prolog.rdc.tms.model.vo.PickUpAppointmentVO;
import com.prolog.rdc.tms.service.AppointmentService;
import com.prolog.wms.base.util.ExcelUtils;

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

/**
 * 运输管理-待预约控制层
 *
 * @author lhb
 * @since 2022-04-11 09:04:35
 */
@RestController
@Api(tags = "运输管理-待预约控制层")
@RequestMapping("/appointment")
public class AppointmentController {

	@Autowired
	private AppointmentService appointmentService;

	@UserLog("待预约运单模式分页查询")
	@ApiOperation(value = "待预约运单模式分页查询", notes = "待预约运单模式分页查询")
	@PostMapping("/shipbill_page")
	public RestMessage<Page<AppointmentQueryDTO>> pageAppointmentShipbillExecute(@RequestBody AppointmentQueryVO appointmentQueryVO) {
		try {
			Page<AppointmentQueryDTO> appointmentDTOs = appointmentService.pageAppointmentShipbill(appointmentQueryVO);
			return RestMessage.newInstance(true, "查询成功", appointmentDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待预约派车单模式分页查询")
	@ApiOperation(value = "待预约派车单模式分页查询", notes = "待预约派车单模式分页查询")
	@PostMapping("/loadingbill_page")
	public RestMessage<Page<AppointmentLoadingBillQueryDTO>> pageAppointmentLoadingBill(@RequestBody AppointmentQueryVO appointmentQueryVO) {
		try {
			Page<AppointmentLoadingBillQueryDTO> appointmentDTOs = appointmentService.pageAppointmentLoadingBill(appointmentQueryVO);
			return RestMessage.newInstance(true, "查询成功", appointmentDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待预约高级查询")
	@ApiOperation(value = "待预约高级查询", notes = "待预约高级查询")
	@PostMapping("/advanced")
	public RestMessage<Page<AppointmentQueryDTO>> pageAdvancedExecute(@RequestBody AppointmentAdsQueryVO appointmentAdsQueryVO) {
		try {
			Page<AppointmentQueryDTO> appointmentDTOs = appointmentService.pageAdvanced(appointmentAdsQueryVO);
			return RestMessage.newInstance(true, "查询成功", appointmentDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待预约收货方模式分页查询")
	@ApiOperation(value = "待预约收货方模式分页查询", notes = "待预约收货方模式分页查询")
	@PostMapping("/consignee_page")
	public RestMessage<Page<AppointmentConsigneeQueryDTO>> pageAppointmentConsigneeExecute(@RequestBody AppointmentQueryVO appointmentQueryVO) {
		try {
			Page<AppointmentConsigneeQueryDTO> appointmentDTOs = appointmentService.pageAppointmentConsignee(appointmentQueryVO);
			return RestMessage.newInstance(true, "查询成功", appointmentDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待预约发货方模式分页查询")
	@ApiOperation(value = "待预约发货方模式分页查询", notes = "待预约发货方模式分页查询")
	@PostMapping("/shipper_page")
	public RestMessage<Page<AppointmentShipperQueryDTO>> pageAppointmentShipperExecute(@RequestBody AppointmentQueryVO appointmentQueryVO) {
		try {
			Page<AppointmentShipperQueryDTO> appointmentDTOs = appointmentService.pageAppointmentShipper(appointmentQueryVO);
			return RestMessage.newInstance(true, "查询成功", appointmentDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("配载运单查询")
	@ApiOperation(value = "配载运单查询", notes = "配载运单查询")
	@PostMapping("/loading_shipbill")
	public RestMessage<Page<AppLoadingShipbillDTO>> loadingShipbillQueryExecute(@RequestBody AppLoadingShipbillPageVO shipbillPageVO) {
		try {
			Page<AppLoadingShipbillDTO> loadingShipbillPageDTOs = appointmentService.loadingShipbillQuery(shipbillPageVO);
			return RestMessage.newInstance(true, "配载运单查询", loadingShipbillPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("预约确认运单查询")
	@ApiOperation(value = "预约确认运单查询", notes = "预约确认运单查询")
	@PostMapping("/confirm_shipbill")
	public RestMessage<List<AppLoadingShipbillDTO>> confirmShipbillQueryExecute(@RequestBody AppConfirmShipbillVO shipbillVO) {
		try {
			List<AppLoadingShipbillDTO> confirmShipbillQueryDTOs = appointmentService.confirmShipbillQuery(shipbillVO);
			return RestMessage.newInstance(true, "预约确认运单查询", confirmShipbillQueryDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("配载商品查询")
	@ApiOperation(value = "配载商品查询", notes = "配载商品查询")
	@PostMapping("/loading_shipbill_detail")
	public RestMessage<Page<AppLoadingShipBillDetailDTO>> loadingShipbillDetailExecute(@RequestBody AppLoadingShipbillPageVO shipbillPageVO) {
		try {
			Page<AppLoadingShipBillDetailDTO> receiptLoadingShipBillDetailDTOs = appointmentService.loadingShipbillDetail(shipbillPageVO);
			return RestMessage.newInstance(true, "配载商品查询成功", receiptLoadingShipBillDetailDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("配载包裹查询")
	@ApiOperation(value = "配载包裹查询", notes = "配载包裹查询")
	@PostMapping("/loading_shipbill_package")
	public RestMessage<Page<AppLoadingPackageDTO>> loadingShipbillPackageExecute(@RequestBody AppLoadingShipbillPageVO shipbillPageVO) {
		try {
			Page<AppLoadingPackageDTO> appLoadingPackageDTOs = appointmentService.loadingShipbillPackage(shipbillPageVO);
			return RestMessage.newInstance(true, "配载包裹查询成功", appLoadingPackageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("导出所有数据")
	@ApiOperation(value = "导出所有数据", notes = "导出所有数据")
	@PostMapping("/export_all_shipbill")
	public RestMessage<Object> exportAllShipbillExecute(@RequestBody AppointmentQueryVO appointmentQueryVO, HttpServletResponse response) {
		try {
			List<AppointmentExportShipbillDTO> list = appointmentService.exportAllShipbill(appointmentQueryVO);
			ExcelUtils.export(response, AppointmentExportShipbillDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
			return RestMessage.newInstance(true, "导出成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("导出当前页数据")
	@ApiOperation(value = "导出当前页数据", notes = "导出当前页数据")
	@PostMapping("/export_page_shipbill")
	public RestMessage<Object> exportCurrentPageShipbillExecute(@RequestBody AppointmentQueryVO appointmentQueryVO, HttpServletResponse response) {
		try {
			List<AppointmentExportShipbillDTO> list = appointmentService.exportCurrentPageShipbill(appointmentQueryVO);
			ExcelUtils.export(response, AppointmentExportShipbillDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
			return RestMessage.newInstance(true, "导出成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("导出选择行数据")
	@ApiOperation(value = "导出选择行数据", notes = "导出选择行数据")
	@PostMapping("/export_select_line_shipbill")
	public RestMessage<Object> exportSelectLineShipbillExecute(@RequestBody List<String> shipbillIdList, HttpServletResponse response) {
		try {
			List<AppointmentExportShipbillDTO> list = appointmentService.exportSelectLineShipbill(shipbillIdList);
			ExcelUtils.export(response, AppointmentExportShipbillDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
			return RestMessage.newInstance(true, "导出成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待预约打印")
	@ApiOperation(value = "待预约打印", notes = "待预约打印")
	@PostMapping("/print")
	public RestMessage<AppointmentPrintDTO> shipbillPrint(@RequestBody AppointmentPrintVO appointPrintVO) {
		try {
			AppointmentPrintDTO appointmentPrintDTO = appointmentService.shipbillPrint(appointPrintVO);
			return RestMessage.newInstance(true, "打印成功", appointmentPrintDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("提货预约")
	@ApiOperation(value = "提货预约", notes = "提货预约")
	@PostMapping("/pick_up_appointment")
	public RestMessage<PickUpAppointmentDTO> pickUpAppointmentQuery(@RequestBody PickUpAppointmentVO appointmentVO) {
		try {
			PickUpAppointmentDTO appointmentDTO = appointmentService.pickUpAppointmentQuery(appointmentVO);
			return RestMessage.newInstance(true, "提货预约成功", appointmentDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("提货预约确认")
	@ApiOperation(value = "提货预约确认", notes = "提货预约确认")
	@PostMapping("/pick_up_appointment_confirm")
	public RestMessage<String> pickUpAppointmentConfirm(@RequestBody PickUpAppointmentConfirmVO confirmVO) {
		try {
			appointmentService.pickUpAppointmentConfirm(confirmVO);
			return RestMessage.newInstance(true, "提货预约确认成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
