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.RequestParam;
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.ApprovalInfoDTO;
import com.prolog.rdc.tms.model.dto.WaitPickUpGoodsExportShipbillDTO;
import com.prolog.rdc.tms.model.dto.WaitPickUpGoodsItemDetailDTO;
import com.prolog.rdc.tms.model.dto.WaitPickUpGoodsPackageDetailDTO;
import com.prolog.rdc.tms.model.dto.WaitPickUpGoodsQueryByShipbillDTO;
import com.prolog.rdc.tms.model.dto.WaitPickUpGoodsQueryTypeByReceiverDTO;
import com.prolog.rdc.tms.model.dto.WaitPickUpGoodsReceiverGetShipbillDTO;
import com.prolog.rdc.tms.model.vo.ApprovalVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsAdvancedQueryByShipbillVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsExportAllVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsExportPageVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsItemDetailVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsPackageDetailVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsQueryByShipbillVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsQueryTypeByReceiverVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsReceiverGetShipbillVO;
import com.prolog.rdc.tms.model.vo.WaitPickUpGoodsStartShipmentVO;
import com.prolog.rdc.tms.service.WaitPickUpGoodsService;
import com.prolog.rdc.tms.util.PublicMethods;
import com.prolog.wms.base.util.ExcelUtils;

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

/**
 * 运输管理-待提货控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/6/8 10:38
 */
@RestController
@Api(tags = "运输管理-待提货控制层")
@RequestMapping("/waitPickUpGoods")
public class WaitPickUpGoodsController {

	@Autowired
	private WaitPickUpGoodsService service;

	@UserLog("运单模式分页查询")
	@ApiOperation(value = "运单模式分页查询", notes = "运单模式分页查询")
	@PostMapping("/query_shipbill")
	public RestMessage<Page<WaitPickUpGoodsQueryByShipbillDTO>> queryTypeByShipbillPageExecute(@RequestBody WaitPickUpGoodsQueryByShipbillVO waitPickUpGoodsQueryByShipbillVO) {
		try {
			Page<WaitPickUpGoodsQueryByShipbillDTO> page = service.queryTypeByShipbillPageData(waitPickUpGoodsQueryByShipbillVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("运单模式高级查询")
	@ApiOperation(value = "运单模式高级查询", notes = "运单模式高级查询")
	@PostMapping("/advanced_query_shipbill")
	public RestMessage<Page<WaitPickUpGoodsQueryByShipbillDTO>> advancedQueryTypeByShipbillPageExecute(@RequestBody WaitPickUpGoodsAdvancedQueryByShipbillVO waitPickUpGoodsAdvancedQueryByShipbillVO) {
		try {
			Page<WaitPickUpGoodsQueryByShipbillDTO> page = service.advancedQueryTypeByShipbillPageData(waitPickUpGoodsAdvancedQueryByShipbillVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("收货方模式分页查询")
	@ApiOperation(value = "收货方模式分页查询", notes = "收货方模式分页查询")
	@PostMapping("/query_receiver")
	public RestMessage<Page<WaitPickUpGoodsQueryTypeByReceiverDTO>> queryTypeByReceiverPageExecute(@RequestBody WaitPickUpGoodsQueryTypeByReceiverVO waitPickUpGoodsQueryTypeByReceiverVO) {
		try {
			Page<WaitPickUpGoodsQueryTypeByReceiverDTO> page = service.queryTypeByReceiverPageData(waitPickUpGoodsQueryTypeByReceiverVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("配载运单查询")
	@ApiOperation(value = "配载运单查询", notes = "配载运单查询")
	@PostMapping("/receiver_get_shipbill")
	public RestMessage<Page<WaitPickUpGoodsReceiverGetShipbillDTO>> receiverGetShipbillExecute(@RequestBody WaitPickUpGoodsReceiverGetShipbillVO waitPickUpGoodsReceiverGetShipbillVO) {
		try {
			Page<WaitPickUpGoodsReceiverGetShipbillDTO> page = service.receiverGetShipbillData(waitPickUpGoodsReceiverGetShipbillVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("配载商品查询")
	@ApiOperation(value = "配载商品查询", notes = "配载商品查询")
	@PostMapping("/item_detail")
	public RestMessage<Page<WaitPickUpGoodsItemDetailDTO>> itemDetailExecute(@RequestBody WaitPickUpGoodsItemDetailVO waitPickUpGoodsItemDetailVO) {
		try {
			Page<WaitPickUpGoodsItemDetailDTO> page = service.itemDetailData(waitPickUpGoodsItemDetailVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("配载包裹查询")
	@ApiOperation(value = "配载包裹查询", notes = "配载包裹查询")
	@PostMapping("/package_detail")
	public RestMessage<Page<WaitPickUpGoodsPackageDetailDTO>> packageDetailExecute(@RequestBody WaitPickUpGoodsPackageDetailVO waitPickUpGoodsPackageDetailVO) {
		try {
			Page<WaitPickUpGoodsPackageDetailDTO> page = service.packageDetailData(waitPickUpGoodsPackageDetailVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

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

	@UserLog("导出当前页数据")
	@ApiOperation(value = "导出当前页数据", notes = "导出当前页数据")
	@PostMapping("/export_page_shipbill")
	public RestMessage<Object> exportPageShipbillExecute(@RequestBody WaitPickUpGoodsExportPageVO waitPickUpGoodsExportPageVO, HttpServletResponse response) {
		try {
			List<WaitPickUpGoodsExportShipbillDTO> list = service.exportPageShipbill(waitPickUpGoodsExportPageVO);
			ExcelUtils.export(response, WaitPickUpGoodsExportShipbillDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
			return RestMessage.newInstance(true, "导出成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

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

	@UserLog("启运登记")
	@ApiOperation(value = "启运登记", notes = "启运登记")
	@PostMapping("/start_shipment")
	public RestMessage<Object> startShipmentExecute(@RequestBody WaitPickUpGoodsStartShipmentVO waitPickUpGoodsStartShipmentVO) {
		try {
			service.startShipmentData(waitPickUpGoodsStartShipmentVO);
			return RestMessage.newInstance(true, "操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("待提货打印")
	@ApiOperation(value = "待提货打印", notes = "待提货打印")
	@PostMapping("/print")
	public RestMessage<Object> printShipbillExecute(@RequestParam("shipbillId") String shipbillId) {
		try {
			Map<String, Object> map = service.printShipbillData(shipbillId);
			return RestMessage.newInstance(true, "打印成功！", map);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

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

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

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

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

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

}
