package com.prolog.rdc.tms.controller;

import java.util.List;

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

import com.prolog.common.util.DateUtils;
import com.prolog.rdc.tms.model.dto.*;
import com.prolog.rdc.tms.model.vo.*;
import com.prolog.wms.base.util.ExcelUtils;
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.framework.common.message.RestMessage;
import com.prolog.framework.core.pojo.Page;
import com.prolog.framework.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.service.WaitForArrangeGoodsService;

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

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

	@Autowired
	private WaitForArrangeGoodsService service;

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

	@UserLog("运单模式高级查询")
	@ApiOperation(value = "运单模式高级查询", notes = "运单模式高级查询")
	@PostMapping("/advanced_query_shipbill")
	public RestMessage<Page<WaitForArrangeGoodsShipbillPageDTO>> advancedQueryShipbillTypePage(@RequestBody @Valid ShipbillTypeAdvancedQueryVO vo) {
		Page<WaitForArrangeGoodsShipbillPageDTO> page = service.advancedQueryShipbillTypePage(vo);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("收货方模式分页查询")
	@ApiOperation(value = "收货方模式分页查询", notes = "收货方模式分页查询")
	@PostMapping("/queryReceiverTypePage")
	public RestMessage<Page<WaitForArrangeGoodsReceiverPageDTO>> queryReceiverTypePage(@RequestBody ReceiverTypeQueryVO ids) throws Exception {
		Page<WaitForArrangeGoodsReceiverPageDTO> page = service.queryReceiverTypePage(ids);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("预约单模式分页查询")
	@ApiOperation(value = "预约单模式分页查询", notes = "预约单模式分页查询")
	@PostMapping("/queryAppointmentTypePage")
	public RestMessage<Page<WaitForArrangeGoodsAppointmentDTO>> queryAppointmentTypePage(@RequestBody @Valid WaitForArrangeGoodsAppointmentVO vo) throws Exception {
		Page<WaitForArrangeGoodsAppointmentDTO> page = service.queryAppointmentTypePage(vo);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("配载运单查询")
	@ApiOperation(value = "配载运单查询", notes = "配载运单查询")
	@PostMapping("/queryShipbill")
	public RestMessage<Page<WaitForArrangeGoodsShipbillDTO>> queryShipbill(@RequestBody @Valid WaitForArrangeGoodsShipbillQueryVO vo) throws Exception {
		Page<WaitForArrangeGoodsShipbillDTO> page = service.queryShipbill(vo.getPageNum(), vo.getPageSize(), vo.getShipbillId());
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("运单商品查询")
	@ApiOperation(value = "运单商品查询", notes = "运单商品查询")
	@PostMapping("/queryItemDetail")
	public RestMessage<Page<WaitForArrangeGoodsItemDTO>> queryItemDetail(@RequestBody @Valid WaitForArrangeGoodsItemQueryVO vo) throws Exception {
		Page<WaitForArrangeGoodsItemDTO> page = service.queryItemDetail(vo.getPageNum(), vo.getPageSize(), vo.getShipbillId());
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("运单包裹查询")
	@ApiOperation(value = "运单包裹查询", notes = "运单包裹查询")
	@PostMapping("/queryPackageDetail")
	public RestMessage<Page<WaitForArrangeGoodsPackageDTO>> queryPackageDetail(@RequestBody WaitForArrangeGoodsPackQueryVO vo) throws Exception {
		Page<WaitForArrangeGoodsPackageDTO> page = service.queryPackageDetail(vo.getPageNum(), vo.getPageSize(), vo.getShipbillId());
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("开始理货")
	@ApiOperation(value = "开始理货", notes = "开始理货")
	@PostMapping("/startArrangeGoods")
	public RestMessage<Object> startArrangeGoods(@RequestBody List<String> ids) throws Exception {
		try {
			service.startArrangeGoods(ids);
			return RestMessage.newInstance(true, "开始理货完成", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("理货完成")
	@ApiOperation(value = "理货完成", notes = "理货完成")
	@PostMapping("/completeArrangeGoods")
	public RestMessage<Object> completeArrangeGoods(@RequestBody List<String> ids) throws Exception {
		try {
			service.completeArrangeGoods(ids);
			return RestMessage.newInstance(true, "理货完成", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("待理货运单模式导出")
	@ApiOperation(value = "待理货运单模式导出", notes = "待理货运单模式导出")
	@PostMapping("/export")
	public RestMessage<Object> export(@RequestBody ShipbillTypeQueryVO vo, HttpServletResponse response) throws Exception {
		List<WaitForArrangeGoodsExportDTO> list = service.export(vo);
		ExcelUtils.export(response, WaitForArrangeGoodsExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("待理货运单模式分页导出")
	@ApiOperation(value = "待理货运单模式分页导出", notes = "待理货运单模式分页导出")
	@PostMapping("/exportPage")
	public RestMessage<Object> exportPage(@RequestBody ShipbillTypeQueryVO vo, HttpServletResponse response) throws Exception {
		List<WaitForArrangeGoodsExportDTO> list = service.exportPage(vo);
		ExcelUtils.export(response, WaitForArrangeGoodsExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("待理货运单模式选中行导出")
	@ApiOperation(value = "待理货运单模式选中行导出", notes = "待理货运单模式选中行导出")
	@PostMapping("/exportSelected")
	public RestMessage<Object> exportSelected(@RequestBody List<String> ids, HttpServletResponse response) throws Exception {
		List<WaitForArrangeGoodsExportDTO> list = service.exportSelected(ids);
		ExcelUtils.export(response, WaitForArrangeGoodsExportDTO.class, DateUtils.format(DateUtils.nowDate(), DateUtils.PATTERN_FULL_SIMPLE), list);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

}
