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

import com.prolog.rdc.tms.app.model.dto.business.MatchCarrierStrategyDTO;
import com.prolog.rdc.tms.app.model.vo.business.MatchCarrierStrategyVO;
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.app.model.dto.business.PendingDispatchQueryDTO;
import com.prolog.rdc.tms.app.model.vo.business.PendingDispatchQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.PendingDispatchVO;
import com.prolog.rdc.tms.app.service.business.PendingDispatchService;

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

import javax.validation.Valid;

/**
 * 调度管理-待调度控制层
 *
 * @author lhb
 * @since 2022-04-11 09:04:35
 */
@RestController
@Api(tags = "调度管理-待调度控制层")
@RequestMapping("/pending_dispatch")
public class PendingDispatchController {

	@Autowired
	private PendingDispatchService pendingDispatchService;

	@UserLog("待调度查询")
	@ApiOperation(value = "待调度查询", notes = "待调度查询")
	@PostMapping("/page")
	public RestMessage<Page<PendingDispatchQueryDTO>> dispatchShipbillQueryExecute(@RequestBody PendingDispatchQueryVO pendingDispatchVO) {
		try {
			Page<PendingDispatchQueryDTO> pendingDispatchDTOs = pendingDispatchService.dispatchShipbillQuery(pendingDispatchVO);
			return RestMessage.newInstance(true, "查询成功", pendingDispatchDTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("调度")
	@ApiOperation(value = "调度", notes = "调度")
	@PostMapping("/dispatch")
	public RestMessage<String> dispatchShipbillExecute(@RequestBody PendingDispatchVO dispatchVO) {
		try {
			pendingDispatchService.dispatch(dispatchVO);
			return RestMessage.newInstance(true, "调度成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("调度承运商策略匹配")
	@ApiOperation(value = "调度承运商策略匹配", notes = "调度承运商策略匹配")
	@PostMapping("/matchCarrierStrategy")
	public RestMessage<MatchCarrierStrategyDTO> matchCarrierStrategy(@RequestBody @Valid MatchCarrierStrategyVO vo) {
		return RestMessage.newInstance(true, "调度承运商策略匹配成功", pendingDispatchService.matchCarrierStrategy(vo));
	}

}
