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.common.util.ToolKits;
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.AppointTimeCountDTO;
import com.prolog.rdc.tms.model.dto.CallNumberGetShipbillDTO;
import com.prolog.rdc.tms.model.dto.CallNumberPageDTO;
import com.prolog.rdc.tms.model.dto.CallNumberWaitingAreaDTO;
import com.prolog.rdc.tms.model.dto.PlatformAndVehicleDTO;
import com.prolog.rdc.tms.model.vo.CallNumberByNextOneVO;
import com.prolog.rdc.tms.model.vo.CallNumberGetShipbillVO;
import com.prolog.rdc.tms.model.vo.CallNumberQueryVO;
import com.prolog.rdc.tms.model.vo.CallNumberWaitingAreaVO;
import com.prolog.rdc.tms.model.vo.InsertSortVO;
import com.prolog.rdc.tms.model.vo.PassNumberVO;
import com.prolog.rdc.tms.model.vo.PlatformAndVehicleVO;
import com.prolog.rdc.tms.service.CallNumberService;

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

/**
 * 园区管理-叫号管理控制层
 * <p>
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/7/8 14:09
 */
@RestController
@Api(tags = "园区管理-叫号管理控制层")
@RequestMapping("/callNumber")
public class CallNumberController {

	@Autowired
	private CallNumberService callNumberService;

	@UserLog("预约单分页查询")
	@ApiOperation(value = "预约单分页查询", notes = "预约单分页查询")
	@PostMapping("/queryAppoint")
	public RestMessage<Page<CallNumberPageDTO>> queryAppoint(@RequestBody @Valid CallNumberQueryVO vo) throws Exception {
		Page<CallNumberPageDTO> page = callNumberService.queryAppoint(vo);
		return RestMessage.newInstance(true, "操作成功！", page);
	}

	@UserLog("叫号管理-下一位")
	@ApiOperation(value = "叫号管理-下一位", notes = "叫号管理-下一位")
	@PostMapping("/next_one")
	public RestMessage<Object> nextOneExecute(@RequestBody @Valid CallNumberByNextOneVO callNumberByNextOneVO) throws Exception {
		Integer rs = callNumberService.nextOneData(callNumberByNextOneVO);
		String msg = null;
		if (ToolKits.isEmpty(rs) || rs.intValue() == 0) {
			msg = "没有符合叫号条件的预约单！";
		} else {
			msg = "叫号操作成功！";
		}
		return RestMessage.newInstance(true, msg, null);
	}

	@UserLog("过号")
	@ApiOperation(value = "过号", notes = "过号")
	@PostMapping("/passNumber")
	public RestMessage<Object> passNumber(@RequestBody @Valid PassNumberVO vo) {
		try {
			callNumberService.passNumber(vo);
			return RestMessage.newInstance(true, "操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("插队")
	@ApiOperation(value = "插队", notes = "插队")
	@PostMapping("/insertSort")
	public RestMessage<Object> insertSort(@RequestBody @Valid InsertSortVO vo) {
		try {
			callNumberService.insertSort(vo);
			return RestMessage.newInstance(true, "操作成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("仓库各预约时间段排队数查询")
	@ApiOperation(value = "仓库各预约时间段排队数查询", notes = "仓库各预约时间段排队数查询")
	@PostMapping("/queryTimeCount")
	public RestMessage<List<AppointTimeCountDTO>> queryTimeCount(@RequestBody @Valid CallNumberQueryVO vo) throws Exception {
		List<AppointTimeCountDTO> list = callNumberService.queryTimeCount(vo);
		return RestMessage.newInstance(true, "操作成功！", list);
	}

	@UserLog("月台与当前装卸车辆查询")
	@ApiOperation(value = "月台与当前装卸车辆查询", notes = "月台与当前装卸车辆查询")
	@PostMapping("/platformAndVehicle")
	public RestMessage<List<PlatformAndVehicleDTO>> platformAndVehicle(@RequestBody @Valid PlatformAndVehicleVO platformAndVehicleVO) {
		try {
			List<PlatformAndVehicleDTO> list = callNumberService.platformAndVehicle(platformAndVehicleVO);
			return RestMessage.newInstance(true, "操作成功！", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("等待区车辆查询")
	@ApiOperation(value = "等待区车辆查询", notes = "等待区车辆查询")
	@PostMapping("/queryWaitingZone")
	public RestMessage<List<CallNumberWaitingAreaDTO>> queryWaitingZone(@RequestBody @Valid CallNumberWaitingAreaVO callNumberWaitingAreaVO) {
		try {
			List<CallNumberWaitingAreaDTO> list = callNumberService.queryWaitingZone(callNumberWaitingAreaVO);
			return RestMessage.newInstance(true, "操作成功！", list);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("运单查询")
	@ApiOperation(value = "运单查询", notes = "运单查询")
	@PostMapping("/get_shipbill")
	public RestMessage<List<CallNumberGetShipbillDTO>> getShipbillExecute(@RequestBody @Valid CallNumberGetShipbillVO callNumberGetShipbillVO) {
		List<CallNumberGetShipbillDTO> list = callNumberService.getShipbillData(callNumberGetShipbillVO);
		return RestMessage.newInstance(true, "操作成功！", list);
	}

}
