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

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.PendingReviewQueryDTO;
import com.prolog.rdc.tms.app.model.vo.business.PendingReviewQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.ShipbillGoBackVO;
import com.prolog.rdc.tms.app.service.business.PendingReviewService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 java.util.List;

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

	@Autowired
	private PendingReviewService pendingReviewService;

	@UserLog("待审核查询")
	@ApiOperation(value = "待审核查询", notes = "待审核查询")
	@PostMapping("/page")
	public RestMessage<Page<PendingReviewQueryDTO>> pendingReviewQueryExecute(@RequestBody PendingReviewQueryVO pendingReviewVO) {
		try {
			Page<PendingReviewQueryDTO> pendingReviewTOs = pendingReviewService.pendingReviewQuery(pendingReviewVO);
			return RestMessage.newInstance(true, "查询成功", pendingReviewTOs);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}


	@UserLog("运单审核")
	@ApiOperation(value = "运单审核", notes = "运单审核")
	@PostMapping("/review")
	public RestMessage<String> reviewShipbillExecute(@RequestBody List<String> shipbillIds) {
		try {
			pendingReviewService.reviewShipbillData(shipbillIds);
			return RestMessage.newInstance(true, "审核成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@PostMapping("/back")
	@UserLog("运单待审核-回退")
	@ApiOperation(value = "运单待审核-回退", notes = "运单待审核-回退")
	public RestMessage<String> goBackShipbill(@RequestBody ShipbillGoBackVO vo) {
		try {
			pendingReviewService.goBackShipbill(vo);
			return RestMessage.newInstance(true, "运单待审核-回退成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

}
