package com.prolog.rdc.tms.controller;

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

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.OrigReceiptLoadingPackageDTO;
import com.prolog.rdc.tms.model.dto.OrigReceiptLoadingShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.OrigReceiptLoadingShipbillDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptConsigneeDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptExportShipbillDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptPictureDTO;
import com.prolog.rdc.tms.model.dto.PendingOrigReceiptShipbillDTO;
import com.prolog.rdc.tms.model.dto.PendingReceiptShipbillApprovalDTO;
import com.prolog.rdc.tms.model.vo.ApprovalVO;
import com.prolog.rdc.tms.model.vo.OrigReceiptConfirmVO;
import com.prolog.rdc.tms.model.vo.OrigReceiptLoadingShipbillPageVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptAdvancedPageVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptExportAllDataVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptExportCurrPgDataVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptPageVO;
import com.prolog.rdc.tms.model.vo.PendingOrigReceiptPrintVO;
import com.prolog.rdc.tms.service.PendingOrigReceiptService;
import com.prolog.wms.base.util.ExcelUtils;

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

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

	@Autowired
	private PendingOrigReceiptService pendingOrigReceiptService;

	@UserLog("待正本回单运单模式分页查询")
	@ApiOperation(value = "待正本回单运单模式分页查询", notes = "待正本回单运单模式分页查询")
	@PostMapping("/shipbill_page")
	public RestMessage<Page<PendingOrigReceiptShipbillDTO>> shipbillPagePendingReceiptExecute(@RequestBody PendingOrigReceiptPageVO pendingReceiptPageVO) {
		try {
			Page<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = pendingOrigReceiptService.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<PendingOrigReceiptShipbillDTO>> advancedShipbillPagePendingReceiptExecute(@RequestBody PendingOrigReceiptAdvancedPageVO pendingOrigReceiptAdvancedPageVO) {
		Page<PendingOrigReceiptShipbillDTO> pendingReceiptShipbillPageDTOs = pendingOrigReceiptService.advancedShipbillPage(pendingOrigReceiptAdvancedPageVO);
		return RestMessage.newInstance(true, "待正本回单运单模式分页查询成功", pendingReceiptShipbillPageDTOs);
	}

	@UserLog("待正本回单收货方模式分页查询")
	@ApiOperation(value = "待正本回单收货方模式分页查询", notes = "待正本回单收货方模式分页查询")
	@PostMapping("/consignee_page")
	public RestMessage<Page<PendingOrigReceiptConsigneeDTO>> consigneePagePendingReceiptExecute(@RequestBody PendingOrigReceiptPageVO pendingReceiptPageVO) {
		try {
			Page<PendingOrigReceiptConsigneeDTO> pendingReceiptConsigneePageDTOs = pendingOrigReceiptService.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 OrigReceiptConfirmVO receiptConfirmVO) {
		try {
			pendingOrigReceiptService.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<OrigReceiptLoadingShipbillDTO>> loadingShipbillQueryExecute(@RequestBody OrigReceiptLoadingShipbillPageVO vo) {
		try {
			Page<OrigReceiptLoadingShipbillDTO> loadingShipbillPageDTOs = pendingOrigReceiptService.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<OrigReceiptLoadingShipBillDetailDTO>> loadingShipbillDetailExecute(@RequestBody OrigReceiptLoadingShipbillPageVO vo) {
		try {
			Page<OrigReceiptLoadingShipBillDetailDTO> receiptLoadingShipBillDetailDTOs = pendingOrigReceiptService.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<OrigReceiptLoadingPackageDTO>> loadingShipbillPackageExecute(@RequestBody OrigReceiptLoadingShipbillPageVO vo) {
		try {
			Page<OrigReceiptLoadingPackageDTO> pendingReviewPackageDTOS = pendingOrigReceiptService.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 PendingOrigReceiptExportAllDataVO vo, HttpServletResponse response) {
		try {
			List<PendingOrigReceiptExportShipbillDTO> list = pendingOrigReceiptService.exportAllShipbill(vo);
			ExcelUtils.export(response, PendingOrigReceiptExportShipbillDTO.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 PendingOrigReceiptExportCurrPgDataVO vo, HttpServletResponse response) {
		try {
			List<PendingOrigReceiptExportShipbillDTO> list = pendingOrigReceiptService.exportCurrentPageShipbill(vo);
			ExcelUtils.export(response, PendingOrigReceiptExportShipbillDTO.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<PendingOrigReceiptExportShipbillDTO> list = pendingOrigReceiptService.exportSelectLineShipbill(shipbillIdList);
			ExcelUtils.export(response, PendingOrigReceiptExportShipbillDTO.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 PendingOrigReceiptPrintVO pendingOrigReceiptPrintVO) {
		try {
			Map<String, Object> map = pendingOrigReceiptService.shipbillPrint(pendingOrigReceiptPrintVO);
			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 = pendingOrigReceiptService.getApprovalInfo(vo);
		return RestMessage.newInstance(true, "操作成功！", dto);
	}

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

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

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

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

	@UserLog("待正本回单查询回单图片")
	@ApiOperation(value = "待正本回单查询回单图片", notes = "待正本回单查询回单图片")
	@PostMapping("/receiptPicture")
	public RestMessage<PendingOrigReceiptPictureDTO> listPendingOrigReceiptPictureExecute(@RequestBody List<String> shipbillIds) {
		try {
			PendingOrigReceiptPictureDTO pendingOrigReceiptPictureDTO = pendingOrigReceiptService.listPendingOrigReceiptPictureData(shipbillIds);
			return RestMessage.newInstance(true, "查询成功", pendingOrigReceiptPictureDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
