package com.prolog.rdc.tms.controller;

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

import javax.servlet.http.HttpServletResponse;

import com.prolog.rdc.tms.model.vo.FinishAdsQueryVO;
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.ExportFinishShipbillDTO;
import com.prolog.rdc.tms.model.dto.FinishShipBillDetailDTO;
import com.prolog.rdc.tms.model.dto.FinishShipbillDTO;
import com.prolog.rdc.tms.model.dto.FinishShipbillPackageDTO;
import com.prolog.rdc.tms.model.vo.FinishShipbillDetailVO;
import com.prolog.rdc.tms.model.vo.FinishShipbillPrintVO;
import com.prolog.rdc.tms.model.vo.FinishShipbillQueryVO;
import com.prolog.rdc.tms.service.FinishShipbillService;
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("/finish_shipbill")
public class FinishShipbillController {

	@Autowired
	private FinishShipbillService finishShipbillService;

	@UserLog("完成运单分页查询")
	@ApiOperation(value = "完成运单分页查询", notes = "完成运单分页查询")
	@PostMapping("/shipbill_page")
	public RestMessage<Page<FinishShipbillDTO>> queryShipbillPageExecute(@RequestBody FinishShipbillQueryVO vo) {
		try {
			Page<FinishShipbillDTO> pendingReceiptShipbillPageDTOs = finishShipbillService.queryFinishShipbillPage(vo);
			return RestMessage.newInstance(true, "运单分页查询成功", pendingReceiptShipbillPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("完成运单高级查询")
	@ApiOperation(value = "完成运单高级查询", notes = "完成运单高级查询")
	@PostMapping("/advanced")
	public RestMessage<Page<FinishShipbillDTO>> pageAdvancedExecute(@RequestBody FinishAdsQueryVO adsQueryVO) {
		try {
			Page<FinishShipbillDTO> pendingReceiptShipbillPageDTOs = finishShipbillService.pageAdvanced(adsQueryVO);
			return RestMessage.newInstance(true, "运单分页查询成功", pendingReceiptShipbillPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("完成运单商品查询")
	@ApiOperation(value = "完成运单商品查询", notes = "完成运单商品查询")
	@PostMapping("/detail")
	public RestMessage<Page<FinishShipBillDetailDTO>> queryFinishShipbillDetailExecute(@RequestBody FinishShipbillDetailVO vo) {
		try {
			Page<FinishShipBillDetailDTO> finishShipBillDetailDTOs = finishShipbillService.queryFinishShipbillDetail(vo);
			return RestMessage.newInstance(true, "商品信息查询成功", finishShipBillDetailDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("完成运单包裹查询")
	@ApiOperation(value = "完成运单包裹查询", notes = "完成运单包裹查询")
	@PostMapping("/package")
	public RestMessage<Page<FinishShipbillPackageDTO>> queryFinishShipbillPackageExecute(@RequestBody FinishShipbillDetailVO vo) {
		try {
			Page<FinishShipbillPackageDTO> finishShipbillPackageDTOs = finishShipbillService.queryFinishShipbillPackage(vo);
			return RestMessage.newInstance(true, "包裹信息查询成功", finishShipbillPackageDTOs);
		} 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 FinishShipbillQueryVO vo, HttpServletResponse response) {
		try {
			List<ExportFinishShipbillDTO> list = finishShipbillService.exportAllShipbill(vo);
			ExcelUtils.export(response, ExportFinishShipbillDTO.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 FinishShipbillQueryVO vo, HttpServletResponse response) {
		try {
			List<ExportFinishShipbillDTO> list = finishShipbillService.exportCurrentPageShipbill(vo);
			ExcelUtils.export(response, ExportFinishShipbillDTO.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<ExportFinishShipbillDTO> list = finishShipbillService.exportSelectLineShipbill(shipbillIdList);
			ExcelUtils.export(response, ExportFinishShipbillDTO.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 FinishShipbillPrintVO finishShipbillPrintVO) {
		try {
			Map<String, Object> map = finishShipbillService.shipbillPrint(finishShipbillPrintVO);
			return RestMessage.newInstance(true, "打印成功", map);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
