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

import javax.validation.Valid;

import com.prolog.rdc.tms.app.model.dto.AppointmentHeaderDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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.app.model.dto.business.QueryTypeByAppointmentDTO;
import com.prolog.rdc.tms.app.model.dto.business.QueryTypeByShipbillDTO;
import com.prolog.rdc.tms.app.model.vo.business.QueryTypeByAppointmentVO;
import com.prolog.rdc.tms.app.model.vo.business.QueryTypeByShipbillVO;
import com.prolog.rdc.tms.app.model.vo.business.StartLoadVO;
import com.prolog.rdc.tms.app.service.business.WaitLoadingAndUnloadingService;
import com.prolog.rdc.tms.app.util.PublicMethods;

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

/**
 * 运输管理-待装卸控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author xiaoyf
 * @since 2022/6/6 10:34
 */
@RestController
@Api(tags = "业务APP——待装卸控制层")
@RequestMapping("/waitLoadingAndUnloading")
public class WaitLoadingAndUnloadingController {

	@Autowired
	private WaitLoadingAndUnloadingService service;

	@UserLog("下一位")
	@ApiOperation(value = "下一位", notes = "下一位")
	@PostMapping("/queryAppointmentTypePage")
	public RestMessage<Page<QueryTypeByAppointmentDTO>> queryAppointment(@RequestBody @Valid QueryTypeByAppointmentVO queryTypeByAppointmentVO) throws Exception {
		Page<QueryTypeByAppointmentDTO> page = service.queryAppointment(queryTypeByAppointmentVO);
		return RestMessage.newInstance(true, "查询成功！", page);
	}

	@UserLog("开始装卸操作成功后刷新预约单数据")
	@ApiOperation(value = "开始装卸操作成功后刷新预约单数据", notes = "开始装卸操作成功后刷新预约单数据")
	@PostMapping("/refreshAppoint")
	public RestMessage<AppointmentHeaderDTO> refreshAppoint(@RequestParam(value = "appointmentId") Long appointmentId) throws Exception {
		AppointmentHeaderDTO data = service.refreshAppoint(appointmentId);
		return RestMessage.newInstance(true, "查询成功！", data);
	}

	@UserLog("运单(预约明细)分页查询")
	@ApiOperation(value = "运单分页查询", notes = "运单分页查询")
	@PostMapping("/query_shipbill")
	public RestMessage<Page<QueryTypeByShipbillDTO>> queryTypeByShipbillPageExecute(@RequestBody QueryTypeByShipbillVO queryTypeByShipbillVO) {
		try {
			Page<QueryTypeByShipbillDTO> page = service.queryTypeByShipbillPageData(queryTypeByShipbillVO);
			return RestMessage.newInstance(true, "查询成功！", page);
		} catch (Exception e) {
			return RestMessage.newInstance(false, PublicMethods.getExceptionMessage(e), null);
		}
	}

	@UserLog("开始装卸")
	@ApiOperation(value = "开始装卸", notes = "开始装卸")
	@PostMapping("/started_work")
	public RestMessage<Object> startedWorkExecute(@RequestBody StartLoadVO vo) {
		service.startedWorkData(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

	@UserLog("装卸完成")
	@ApiOperation(value = "装卸完成", notes = "装卸完成")
	@PostMapping("/complete_work")
	public RestMessage<Object> completeWorkExecute(@RequestBody StartLoadVO vo) {
		service.completeWorkData(vo);
		return RestMessage.newInstance(true, "操作成功！", null);
	}

}
