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.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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.PendingReviewDetailDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewExportDetailDataDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPackageDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPackageDetailDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewPageDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewParseAddressPageDTO;
import com.prolog.rdc.tms.model.dto.PendingReviewViewDTO;
import com.prolog.rdc.tms.service.PendingReviewService;
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("/pending_review")
public class PendingReviewController {

	@Autowired
	private PendingReviewService pendingReviewService;

	@UserLog("待审核分页查询")
	@ApiOperation(value = "待审核分页查询", notes = "待审核分页查询")
	@PostMapping("/page")
	public RestMessage<Page<PendingReviewPageDTO>> pagePendingReviewExecute(@RequestBody PendingReviewPageVO pendingReviewPageVO) {
		try {
			Page<PendingReviewPageDTO> pendingReviewPageDTOs = pendingReviewService.pagePendingReviewData(pendingReviewPageVO);
			return RestMessage.newInstance(true, "查询成功", pendingReviewPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待审核高级查询")
	@ApiOperation(value = "待审核高级查询", notes = "待审核高级查询")
	@PostMapping("/advanced")
	public RestMessage<Page<PendingReviewPageDTO>> pageAdvancedExecute(@RequestBody PendingReviewAdvancedQueryVO advancedQueryVO) {
		try {
			Page<PendingReviewPageDTO> pendingReviewPageDTOs = pendingReviewService.pageAdvanced(advancedQueryVO);
			return RestMessage.newInstance(true, "查询成功", pendingReviewPageDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待审核商品信息查询")
	@ApiOperation(value = "待审核商品信息查询", notes = "待审核商品信息查询")
	@PostMapping("/detail/list")
	public RestMessage<Page<PendingReviewDetailDTO>> listShipbillDetailExecute(@RequestBody PendingReviewDetailVO pendingReviewDetailVO) {
		try {
			Page<PendingReviewDetailDTO> pendingReviewDetailDTOs = pendingReviewService.listShipbillDetailData(pendingReviewDetailVO);
			return RestMessage.newInstance(true, "查询成功", pendingReviewDetailDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待审核包裹信息查询")
	@ApiOperation(value = "待审核包裹信息查询", notes = "待审核包裹信息查询")
	@PostMapping("/package/list")
	public RestMessage<Page<PendingReviewPackageDTO>> listShipbillPackageExecute(@RequestBody PendingReviewShipbillPackageListVO pendingReviewShipbillPackageListVO) {
		try {
			Page<PendingReviewPackageDTO> pendingReviewPackageDTOS = pendingReviewService.listShipbillPackageData(pendingReviewShipbillPackageListVO);
			return RestMessage.newInstance(true, "查询成功", pendingReviewPackageDTOS);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("运单审核")
	@ApiOperation(value = "运单审核", notes = "运单审核")
	@PostMapping("/review")
	public RestMessage<String> reviewShipbillExecute(@RequestBody List<String> shipbillIds) {
		try {
			pendingReviewService.reviewShipbillData(shipbillIds);
			return RestMessage.newInstance(true, "审核成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/back")
	@UserLog("运单待审核-回退")
	@ApiOperation(value = "运单待审核-回退", notes = "运单待审核-回退")
	public RestMessage<String> goBackShipbill(@RequestBody ShipbillGoBackVO vo) {
		try {
			pendingReviewService.goBackShipbill(vo);
			return RestMessage.newInstance(true, "运单待审核-回退成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("地址解析查询")
	@ApiOperation(value = "地址解析查询", notes = "地址解析查询")
	@PostMapping("/address_resolution/page")
	public RestMessage<Page<PendingReviewParseAddressPageDTO>> pageAddressResolutionExecute(@RequestBody PendingReviewParseAddressPageVO pendingReviewParseAddressPageVO) {
		Page<PendingReviewParseAddressPageDTO> pendingReviewParseAddressPageDTOs = pendingReviewService.parseAddressQueryData(pendingReviewParseAddressPageVO);
		return RestMessage.newInstance(true, "查询成功", pendingReviewParseAddressPageDTOs);
	}

	@UserLog("待审核-地址解析")
	@ApiOperation(value = "待审核-地址解析", notes = "待审核-地址解析")
	@PostMapping("/parse_address")
	public RestMessage<String> parseAddressShipbill(@RequestBody PendingReviewParseAddressVO vo) {
		try {
			pendingReviewService.parseAddressData(vo);
			return RestMessage.newInstance(true, "地址解析成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待审核导出所有数据")
	@ApiOperation(value = "待审核导出所有数据", notes = "待审核导出所有数据")
	@PostMapping("/export_all_detail")
	public RestMessage<Object> exportAllDetailExecute(@RequestBody PendingReviewExportAllDataVO pendingReviewExportAllDataVO, HttpServletResponse response) {
		try {
			List<PendingReviewExportDetailDataDTO> list = pendingReviewService.exportAllDetailData(pendingReviewExportAllDataVO);
			ExcelUtils.export(response, PendingReviewExportDetailDataDTO.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_current_page_detail")
	public RestMessage<Object> exportCurrentPageDetailExecute(@RequestBody PendingReviewExportCurrentPageDataVO pendingReviewExportCurrentPageDataVO, HttpServletResponse response) {
		try {
			List<PendingReviewExportDetailDataDTO> list = pendingReviewService.exportCurrentPageDetailData(pendingReviewExportCurrentPageDataVO);
			ExcelUtils.export(response, PendingReviewExportDetailDataDTO.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_detail")
	public RestMessage<Object> exportSelectLineDetailExecute(@RequestBody List<String> shipbillIdList, HttpServletResponse response) {
		try {
			List<PendingReviewExportDetailDataDTO> list = pendingReviewService.exportSelectLineData(shipbillIdList);
			ExcelUtils.export(response, PendingReviewExportDetailDataDTO.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(@RequestParam("shipbillId") String shipbillId) {
		try {
			Map<String, Object> map = pendingReviewService.shipbillPrint(shipbillId);
			return RestMessage.newInstance(true, "打印成功", map);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/view")
	@UserLog("待审核运单查看")
	@ApiOperation(value = "待审核运单查看", notes = "待审核运单查看")
	public RestMessage<PendingReviewViewDTO> viewShipbillExecute(@RequestBody PendingReviewViewVO pendingReviewViewVO) {
		try {
			PendingReviewViewDTO dto = pendingReviewService.viewShipbillData(pendingReviewViewVO);
			return RestMessage.newInstance(true, "运单查看成功！", dto);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/detail/package")
	@UserLog("待审核商品包裹信息查询")
	@ApiOperation(value = "待审核商品包裹信息查询", notes = "待审核商品包裹信息查询")
	public RestMessage<Page<PendingReviewPackageDTO>> viewDetailPackageExecute(@RequestBody PendingReviewPackageByDetailVO pendingReviewPackageByDetailVO) {
		try {
			Page<PendingReviewPackageDTO> pkgDtoList = pendingReviewService.viewDetailPackage(pendingReviewPackageByDetailVO);
			return RestMessage.newInstance(true, "包裹信息查询成功！", pkgDtoList);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/package/detail")
	@UserLog("待审核包裹商品信息查询")
	@ApiOperation(value = "待审核包裹商品信息查询", notes = "待审核包裹商品信息查询")
	public RestMessage<Page<PendingReviewPackageDetailDTO>> viewPackageDetailExecute(@RequestBody PendingReviewDetailByPackageVO pendingReviewDetailByPackageVO) {
		try {
			Page<PendingReviewPackageDetailDTO> detailDtoList = pendingReviewService.viewPackageDetail(pendingReviewDetailByPackageVO);
			return RestMessage.newInstance(true, "商品信息查询成功！", detailDtoList);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
