package com.prolog.rdc.tms.app.controller.business;

import java.util.List;

import javax.validation.Valid;

import com.prolog.rdc.tms.app.model.dto.business.TakeNumberPageDetailDTO;
import com.prolog.rdc.tms.app.model.vo.business.AppointDetailQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.TakeNumberByLoadingBillVO;
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.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.dto.business.LoadingBillDetailDTO;
import com.prolog.rdc.tms.app.model.dto.business.TakeNumberPageDTO;
import com.prolog.rdc.tms.app.model.dto.business.TakeNumberQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.TakeNumberAppointQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.TakeNumberByAppointVO;
import com.prolog.rdc.tms.app.model.vo.business.TakeNumberByShipbillVO;
import com.prolog.rdc.tms.app.service.business.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("/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("/queryShipbill")
	public RestMessage<List<LoadingBillDetailDTO>> queryShipbill(@RequestBody TakeNumberQueryVO vo) {
		List<LoadingBillDetailDTO> page = service.queryShipbill(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("/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("/takeNumberByLoadingBill")
	public RestMessage<String> takeNumberByLoadingBill(@RequestBody @Valid TakeNumberByLoadingBillVO vo) {
		try {
			String number = service.takeNumberByLoadingBill(vo);
			return RestMessage.newInstance(true, "", number);
		} 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);
	}

}
