package com.prolog.rdc.tms.controller;

import java.util.List;
import java.util.Map;

import com.prolog.rdc.tms.model.dto.*;
import com.prolog.rdc.tms.model.vo.*;
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.servlet.http.HttpServletResponse;

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.service.PendingReceiptService;
import com.prolog.wms.base.util.ExcelUtils;

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

/**
 * 运输管理-待回单控制层
 *
 * @author lhb
 * @since 2022-06-01 09:04:35
 */
@RestController
@Api(tags = "运输管理-待回单控制层")
@RequestMapping("/pending_receipt")
public class PendingReceiptController {

	@Autowired
	private PendingReceiptService pendingReceiptService;

	@UserLog("待回单运单模式分页查询")
	@ApiOperation(value = "待回单运单模式分页查询", notes = "待回单运单模式分页查询")
	@PostMapping("/shipbill_page")
	public RestMessage<Page<PendingReceiptShipbillPageDTO>> shipbillPagePendingReceiptExecute(@RequestBody PendingReceiptPageVO pendingReceiptPageVO) {
		try {
			Page<PendingReceiptShipbillPageDTO> pendingReceiptShipbillPageDTOs = pendingReceiptService.shipbillPage(pendingReceiptPageVO);
			return RestMessage.newInstance(true, "待回单运单模式分页查询成功", pendingReceiptShipbillPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待回单运单模式高级查询")
	@ApiOperation(value = "待回单运单模式高级查询", notes = "待回单运单模式高级查询")
	@PostMapping("/advanced_shipbill_page")
	public RestMessage<Page<PendingReceiptShipbillPageDTO>> advancedShipbillPagePendingReceiptExecute(@RequestBody PendingReceiptAdvancedPageVO pendingReceiptAdvancedPageVO) {
		try {
			Page<PendingReceiptShipbillPageDTO> pendingReceiptShipbillPageDTOs = pendingReceiptService.advancedShipbillPage(pendingReceiptAdvancedPageVO);
			return RestMessage.newInstance(true, "待回单运单模式高级查询成功", pendingReceiptShipbillPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待回单收货方模式分页查询")
	@ApiOperation(value = "待回单收货方模式分页查询", notes = "待回单收货方模式分页查询")
	@PostMapping("/consignee_page")
	public RestMessage<Page<PendingReceiptConsigneePageDTO>> consigneePagePendingReceiptExecute(@RequestBody PendingReceiptPageVO pendingReceiptPageVO) {
		try {
			Page<PendingReceiptConsigneePageDTO> pendingReceiptConsigneePageDTOs = pendingReceiptService.consigneePage(pendingReceiptPageVO);
			return RestMessage.newInstance(true, "待回单收货方模式分页查询成功", pendingReceiptConsigneePageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("回单确认")
	@ApiOperation(value = "回单确认", notes = "回单确认")
	@PostMapping("/receipt_confirm")
	public RestMessage<String> receiptConfirmExecute(@RequestBody ReceiptConfirmVO receiptConfirmVO) {
		try {
			pendingReceiptService.receiptConfirm(receiptConfirmVO);
			return RestMessage.newInstance(true, "回单确认成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

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

	@UserLog("配载商品查询")
	@ApiOperation(value = "配载商品查询", notes = "配载商品查询")
	@PostMapping("/loading_shipbill_detail")
	public RestMessage<Page<ReceiptLoadingShipBillDetailDTO>> loadingShipbillDetailExecute(@RequestBody ReceiptLoadingShipbillPageVO vo) {
		try {
			Page<ReceiptLoadingShipBillDetailDTO> receiptLoadingShipBillDetailDTOs = pendingReceiptService.loadingShipbillDetail(vo);
			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<ReceiptLoadingPackageDTO>> loadingShipbillPackageExecute(@RequestBody ReceiptLoadingShipbillPageVO vo) {
		try {
			Page<ReceiptLoadingPackageDTO> pendingReviewPackageDTOS = pendingReceiptService.loadingShipbillPackage(vo);
			return RestMessage.newInstance(true, "配载包裹查询成功", pendingReviewPackageDTOS);
		} 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 PendingReceiptExportAllDataVO vo, HttpServletResponse response) {
		try {
			List<PendingReceiptExportShipbillDTO> list = pendingReceiptService.exportAllShipbill(vo);
			ExcelUtils.export(response, PendingReceiptExportShipbillDTO.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 PendingReceiptExportCurrPgDataVO vo, HttpServletResponse response) {
		try {
			List<PendingReceiptExportShipbillDTO> list = pendingReceiptService.exportCurrentPageShipbill(vo);
			ExcelUtils.export(response, PendingReceiptExportShipbillDTO.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<PendingReceiptExportShipbillDTO> list = pendingReceiptService.exportSelectLineShipbill(shipbillIdList);
			ExcelUtils.export(response, PendingReceiptExportShipbillDTO.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<Map<String, Object>> shipbillPrint(@RequestBody ReceiptLoadingShipbillPrintVO receiptLoadingShipbillPrintVO) {
		try {
			Map<String, Object> map = pendingReceiptService.shipbillPrint(receiptLoadingShipbillPrintVO);
			return RestMessage.newInstance(true, "打印成功", map);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("审核信息查询")
	@ApiOperation(value = "审核信息查询", notes = "审核信息查询")
	@PostMapping("/getApprovalInfo")
	public RestMessage<PendingReceiptShipbillApprovalDTO> getApprovalInfo(@RequestBody ApprovalVO vo) {
		PendingReceiptShipbillApprovalDTO dto = pendingReceiptService.getApprovalInfo(vo);
		return RestMessage.newInstance(true, "操作成功！", dto);
	}

	@UserLog("审批作废")
	@ApiOperation(value = "审批作废", notes = "审批作废")
	@PostMapping("/invalidApproval")
	public RestMessage<Object> invalidApproval(@RequestBody ApprovalVO vo) {
		pendingReceiptService.invalidApproval(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("审批撤回")
	@ApiOperation(value = "审批撤回", notes = "审批撤回")
	@PostMapping("/retractApproval")
	public RestMessage<Object> retractApproval(@RequestBody ApprovalVO vo) {
		pendingReceiptService.retractApproval(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("审批提交")
	@ApiOperation(value = "审批提交", notes = "审批提交")
	@PostMapping("/submitApproval")
	public RestMessage<Object> submitApproval(@RequestBody ApprovalVO vo) {
		pendingReceiptService.submitApproval(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("审批审核")
	@ApiOperation(value = "审批审核", notes = "审批审核")
	@PostMapping("/reviewApproval")
	public RestMessage<Object> reviewApproval(@RequestBody ApprovalVO vo) {
		pendingReceiptService.reviewApproval(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}
}
