package com.prolog.rdc.tms.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

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.SelfPickUpRegApprovalDTO;
import com.prolog.rdc.tms.model.dto.SelfWithdrawalConfirmQueryDTO;
import com.prolog.rdc.tms.model.dto.SelfWithdrawalDetailDTO;
import com.prolog.rdc.tms.model.dto.SmartSplitDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalExportDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalItemDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalPackageDTO;
import com.prolog.rdc.tms.model.dto.WaitForSelfWithdrawalPageDTO;
import com.prolog.rdc.tms.model.vo.DetailItemSplitVO;
import com.prolog.rdc.tms.model.vo.SelfPickUpApprovalVO;
import com.prolog.rdc.tms.model.vo.SelfPickUpRegApprovalInfoVO;
import com.prolog.rdc.tms.model.vo.SelfPickUpVehicleRegisterVO;
import com.prolog.rdc.tms.model.vo.SelfWithdrawalConfirmQueryVO;
import com.prolog.rdc.tms.model.vo.SelfWithdrawalConfirmVO;
import com.prolog.rdc.tms.model.vo.SmartSplitStrategyVO;
import com.prolog.rdc.tms.model.vo.SmartSplitVO;
import com.prolog.rdc.tms.model.vo.SplitVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfAdsQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalItemQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalPackageQueryVO;
import com.prolog.rdc.tms.model.vo.WaitForSelfWithdrawalQueryVO;
import com.prolog.rdc.tms.service.WaitForSelfWithdrawalService;
import com.prolog.wms.base.util.ExcelUtils;

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

/**
 * 待自提控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author xyf
 * @since 2022/4/18 12:42
 */
@RestController
@Api(tags = "运输管理-待自提控制层")
@RequestMapping("/waitForSelfWithdrawal")
public class WaitForSelfWithdrawalController {

	@Autowired
	private WaitForSelfWithdrawalService service;

	@UserLog("运单分页查询")
	@ApiOperation(value = "运单分页查询", notes = "运单分页查询")
	@PostMapping("/page")
	public RestMessage<Page<WaitForSelfWithdrawalPageDTO>> queryPage(@RequestBody @Valid WaitForSelfWithdrawalQueryVO vo) throws Exception {
		Page<WaitForSelfWithdrawalPageDTO> page = service.queryPage(vo);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("运单高级查询")
	@ApiOperation(value = "运单高级查询", notes = "运单高级查询")
	@PostMapping("/advanced")
	public RestMessage<Page<WaitForSelfWithdrawalPageDTO>> pageAdvancedExecute(@RequestBody WaitForSelfAdsQueryVO adsQueryVO) throws Exception {
		Page<WaitForSelfWithdrawalPageDTO> page = service.pageAdvanced(adsQueryVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("运单商品查询")
	@ApiOperation(value = "运单商品查询", notes = "运单商品查询")
	@PostMapping("/query/Item")
	public RestMessage<Page<WaitForSelfWithdrawalItemDTO>> queryItemDetail(@RequestBody WaitForSelfWithdrawalItemQueryVO waitForSelfWithdrawalItemQueryVO) throws Exception {
		Page<WaitForSelfWithdrawalItemDTO> page = service.queryItemDetail(waitForSelfWithdrawalItemQueryVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("运单包裹查询")
	@ApiOperation(value = "运单包裹查询", notes = "运单包裹查询")
	@PostMapping("/query/package")
	public RestMessage<Page<WaitForSelfWithdrawalPackageDTO>> queryPackageDetail(@RequestBody WaitForSelfWithdrawalPackageQueryVO waitForSelfWithdrawalPackageQueryVO) throws Exception {
		Page<WaitForSelfWithdrawalPackageDTO> page = service.queryPackageDetail(waitForSelfWithdrawalPackageQueryVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("导出所有页")
	@ApiOperation(value = "导出所有页", notes = "导出所有页")
	@PostMapping("/export_all_shipbill")
	public RestMessage<Object> exportAllPage(@RequestBody WaitForSelfWithdrawalQueryVO vo, HttpServletResponse response) throws Exception {
		List<WaitForSelfWithdrawalExportDTO> list = service.exportAllPage(vo);
		ExcelUtils.export(response, WaitForSelfWithdrawalExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
		return RestMessage.newInstance(true, "导出成功！", null);
	}

	@UserLog("导出当前页")
	@ApiOperation(value = "导出当前页", notes = "导出当前页")
	@PostMapping("/export_page_shipbill")
	public RestMessage<Object> exportCurrentPage(@RequestBody WaitForSelfWithdrawalQueryVO vo, HttpServletResponse response) throws Exception {
		List<WaitForSelfWithdrawalExportDTO> list = service.exportCurrentPage(vo);
		ExcelUtils.export(response, WaitForSelfWithdrawalExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
		return RestMessage.newInstance(true, "导出成功！", null);
	}

	@UserLog("导出选择行")
	@ApiOperation(value = "导出选择行", notes = "导出选择行")
	@PostMapping("/export_select_line_shipbill")
	public RestMessage<Object> exportsSelectLine(@RequestBody List<String> shipbillIdList, HttpServletResponse response) throws Exception {
		List<WaitForSelfWithdrawalExportDTO> list = service.exportsSelectLine(shipbillIdList);
		ExcelUtils.export(response, WaitForSelfWithdrawalExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
		return RestMessage.newInstance(true, "导出成功！", null);
	}

	@UserLog("自提确认")
	@ApiOperation(value = "自提确认", notes = "自提确认")
	@PostMapping("/confirm")
	public RestMessage<Object> selfWithdrawalConfirm(@RequestBody @Valid SelfWithdrawalConfirmVO vo) {
		try {
			service.selfWithdrawalConfirm(vo);
			return RestMessage.newInstance(true, "自提确认操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("自提确认查询")
	@ApiOperation(value = "自提确认查询", notes = "自提确认查询")
	@PostMapping("/confirm_query")
	public RestMessage<SelfWithdrawalConfirmQueryDTO> selfWithdrawalConfirmQuery(@RequestBody @Valid SelfWithdrawalConfirmQueryVO vo) throws Exception {
		SelfWithdrawalConfirmQueryDTO dto = service.confirmQuery(vo);
		return RestMessage.newInstance(true, "自提确认查询成功！", dto);
	}

	@UserLog("自提车辆登记")
	@ApiOperation(value = "自提车辆登记", notes = "自提车辆登记")
	@PostMapping("/vehicle_register")
	public RestMessage<Object> vehicleRegister(@RequestBody @Valid SelfPickUpVehicleRegisterVO vehicleRegisterVO) {
		try {
			service.vehicleRegister(vehicleRegisterVO);
			return RestMessage.newInstance(true, "自提车辆登记操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, "自提车辆登记操作失败:" + e.getMessage(), null);
		}

	}

	// STD-DEVELOP20220823 lhb bwc0823003 20220824 自提拆分 start
	@UserLog("待自提折分商品信息查询")
	@ApiOperation(value = "待自提折分商品信息查询", notes = "待自提折分商品信息查询")
	@PostMapping("/split_detail_list")
	public RestMessage<List<SelfWithdrawalDetailDTO>> splitListShipbillDetailExecute(@RequestBody DetailItemSplitVO detailItemPageVO) {
		try {
			List<SelfWithdrawalDetailDTO> pendingReviewDetailDTOs = service.splitListShipbillDetail(detailItemPageVO);
			return RestMessage.newInstance(true, "查询成功", pendingReviewDetailDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/smart_split")
	@UserLog("智能拆分")
	@ApiOperation(value = "智能拆分", notes = "智能拆分")
	public RestMessage<List<SmartSplitDTO>> smartSplitExecute(@RequestBody SmartSplitVO smartSplitVO) {
		try {
			List<SmartSplitDTO> list = service.smartSplitData(smartSplitVO);
			return RestMessage.newInstance(true, "操作成功！", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/smart_split_strategy")
	@UserLog("智能拆分(选择策略)")
	@ApiOperation(value = "智能拆分(选择策略)", notes = "智能拆分(选择策略)")
	public RestMessage<Object> smartSplitStrategyExecute(@RequestBody List<SmartSplitStrategyVO> smartSplitStrategyVOS) {
		try {
			service.smartSplitStrategyData(smartSplitStrategyVOS);
			return RestMessage.newInstance(true, "操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/goods_split")
	@UserLog("待自提按商品拆分")
	@ApiOperation(value = "待自提按商品拆分", notes = "待自提按商品拆分")
	public RestMessage<String> goodsSplitExecute(@RequestBody SplitVO splitVO) {
		try {
			service.goodsSplit(splitVO);
			return RestMessage.newInstance(true, "商品拆分成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
	// STD-DEVELOP20220823 lhb bwc0823003 20220824 自提拆分 end

	// STD-DEVELOP20220823 lhb bwc0825001 20220905 自提拆分 start
	@UserLog("自提登记审核信息查询")
	@ApiOperation(value = "自提登记审核信息查询", notes = "自提登记审核信息查询")
	@PostMapping("/vehicle_register_get_approval_info")
	public RestMessage<SelfPickUpRegApprovalDTO> getApprovalInfoExecute(@RequestBody SelfPickUpRegApprovalInfoVO approvalInfoVO) {
		try {
			SelfPickUpRegApprovalDTO approvalSCDTO = service.getApprovalInfoData(approvalInfoVO);
			return RestMessage.newInstance(true, "查询成功", approvalSCDTO);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("自提登记审批作废")
	@ApiOperation(value = "自提登记审批作废", notes = "自提登记审批作废")
	@PostMapping("/vehicle_register_approval_invalid")
	public RestMessage<Object> regApprovalInvalidExecute(@RequestBody SelfPickUpRegApprovalInfoVO approvalInvalidVO) {
		try {
			service.regApprovalInvalidData(approvalInvalidVO);
			return RestMessage.newInstance(true, "作废成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("自提登记审批流撤回")
	@ApiOperation(value = "自提登记审批流撤回", notes = "自提登记审批流撤回")
	@PostMapping("/vehicle_register_approval_retract")
	public RestMessage<Object> retractApprovalRetractExecute(@RequestBody SelfPickUpRegApprovalInfoVO approvalRetractVO) {
		try {
			service.regApprovalRetractData(approvalRetractVO);
			return RestMessage.newInstance(true, "撤回成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("自提登记审批流提交")
	@ApiOperation(value = "自提登记审批流提交", notes = "自提登记审批流提交")
	@PostMapping("/vehicle_register_approval_submit")
	public RestMessage<Object> regApprovalSubmitExecute(@RequestBody SelfPickUpRegApprovalInfoVO approvalSubmitVO) {
		try {
			service.regApprovalSubmitData(approvalSubmitVO);
			return RestMessage.newInstance(true, "提交成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("自提登记审批流审核")
	@ApiOperation(value = "自提登记审批流审核", notes = "自提登记审批流审核")
	@PostMapping("/vehicle_register_approval")
	public RestMessage<Object> regApprovalExecute(@RequestBody SelfPickUpApprovalVO approvalVO) {
		try {
			service.regApprovalData(approvalVO);
			return RestMessage.newInstance(true, "审核成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
	// STD-DEVELOP20220823 lhb bwc0825001 20220905 自提拆分 end
}
