package com.prolog.rdc.tms.controller;

import java.util.List;

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.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.AllShipbillItemDTO;
import com.prolog.rdc.tms.model.dto.AllShipbillPackageDTO;
import com.prolog.rdc.tms.model.dto.LoadingBillDetailDTO;
import com.prolog.rdc.tms.model.dto.TakeNumberInfoDTO;
import com.prolog.rdc.tms.model.dto.TakeNumberPageDTO;
import com.prolog.rdc.tms.model.dto.TakeNumberPageDetailDTO;
import com.prolog.rdc.tms.model.vo.AllShipbillItemQueryVO;
import com.prolog.rdc.tms.model.vo.AllShipbillPackageQueryVO;
import com.prolog.rdc.tms.model.vo.AppointDetailQueryVO;
import com.prolog.rdc.tms.model.vo.AppointItemQueryVO;
import com.prolog.rdc.tms.model.vo.AppointPackQueryVO;
import com.prolog.rdc.tms.model.vo.TakeNumberAppointQueryVO;
import com.prolog.rdc.tms.model.vo.TakeNumberByAppointVO;
import com.prolog.rdc.tms.model.vo.TakeNumberByShipbillVO;
import com.prolog.rdc.tms.model.vo.TakeNumberInfoByShipbillNoVO;
import com.prolog.rdc.tms.model.vo.TakeNumberQueryVO;
import com.prolog.rdc.tms.service.TakeNumberService;

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

/**
 * 园区管理——取号管理控制层 Company: 湖北普罗格科技股份有限公司
 *
 * @author xiaoyf
 * @since 2022/6/17 11:05
 */
@RestController
@Api(tags = "园区管理——取号管理")
@RequestMapping("/take_number")
public class TakeNumberController {

	@Autowired
	private TakeNumberService service;

	@UserLog("根据运单号查询取号信息")
	@ApiOperation(value = "根据运单号查询取号信息", notes = "根据运单号查询取号信息")
	@PostMapping("/getTakeNumberInfoByShipbillNo")
	public RestMessage<TakeNumberInfoDTO> getTakeNumberInfoByShipbillNo(@RequestBody @Valid TakeNumberInfoByShipbillNoVO vo) {
		try {
			TakeNumberInfoDTO data = service.getTakeNumberInfoByShipbillNo(vo.getShipbillNo());
			return RestMessage.newInstance(true, "查询成功！", data);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

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

	@UserLog("按预约单取号")
	@ApiOperation(value = "按预约单取号", notes = "按预约单取号")
	@PostMapping("/takeNumberByAppoint")
	public RestMessage<String> takeNumberByAppoint(@RequestBody @Valid TakeNumberByAppointVO vo) {
		try {
			String number = service.takeNumberByAppoint(vo);
			return RestMessage.newInstance(true, "取号成功！您的排队号为【" + number + "】", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("预约单明细查询(配载运单查询)")
	@ApiOperation(value = "预约单明细查询(配载运单查询)", notes = "预约单明细查询(配载运单查询)")
	@PostMapping("/queryAppointDetail")
	public RestMessage<List<TakeNumberPageDetailDTO>> queryAppointDetail(@RequestBody @Valid AppointDetailQueryVO vo) throws Exception {
		List<TakeNumberPageDetailDTO> list = service.queryAppointDetail(vo);
		return RestMessage.newInstance(true, "操作成功！", list);
	}

	@UserLog("预约单商品查询")
	@ApiOperation(value = "预约单商品查询", notes = "预约单商品查询")
	@PostMapping("/queryAppointItem")
	public RestMessage<Page<AllShipbillItemDTO>> queryAppointItem(@RequestBody @Valid AppointItemQueryVO vo) {
		Page<AllShipbillItemDTO> page = service.listItemDetailData(vo);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("预约单包裹查询")
	@ApiOperation(value = "预约单包裹查询", notes = "预约单包裹查询")
	@PostMapping("/queryAppointPack")
	public RestMessage<Page<AllShipbillPackageDTO>> queryAppointPack(@RequestBody @Valid AppointPackQueryVO vo) {
		Page<AllShipbillPackageDTO> page = service.listPackageData(vo);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("查询不到预约单时跳转查询运单")
	@ApiOperation(value = "查询不到预约单时跳转查询运单", notes = "查询不到预约单时跳转查询运单")
	@PostMapping("/queryShipbill")
	public RestMessage<List<LoadingBillDetailDTO>> queryShipbill(@RequestBody TakeNumberQueryVO vo) {
		try {
			List<LoadingBillDetailDTO> page = service.queryShipbill(vo);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("按运单取号")
	@ApiOperation(value = "按运单取号", notes = "按运单取号")
	@PostMapping("/takeNumberByShipbill")
	public RestMessage<String> takeNumberByShipbill(@RequestBody @Valid TakeNumberByShipbillVO vo) {
		try {
			String number = service.takeNumberByShipbill(vo);
			return RestMessage.newInstance(true, "取号成功！您的排队号为【" + number + "】", null);
		} catch (Exception e) {
			e.printStackTrace();

			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("运单商品查询")
	@ApiOperation(value = "运单商品查询", notes = "运单商品查询")
	@PostMapping("/listItemDetailData")
	public RestMessage<Page<AllShipbillItemDTO>> listItemDetailData(@RequestBody @Valid AllShipbillItemQueryVO allShipbillItemQueryVO) {
		Page<AllShipbillItemDTO> page = service.listItemDetailData(allShipbillItemQueryVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("运单包裹查询")
	@ApiOperation(value = "运单包裹查询", notes = "运单包裹查询")
	@PostMapping("/listPackageData")
	public RestMessage<Page<AllShipbillPackageDTO>> listPackageData(@RequestBody @Valid AllShipbillPackageQueryVO allShipbillPackageQueryVO) {
		Page<AllShipbillPackageDTO> page = service.listPackageData(allShipbillPackageQueryVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

}
