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.DispatchCheckQueryDTO;
import com.prolog.rdc.tms.app.model.dto.business.TrailerQueryDTO;
import com.prolog.rdc.tms.app.model.vo.business.ShipbillQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.TrailerDeleteDetailVO;
import com.prolog.rdc.tms.app.model.vo.business.TrailerQueryVO;
import com.prolog.rdc.tms.app.service.business.TrailerService;
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;

/**
 * 已托运控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/4/18 12:42
 */
@RestController
@Api(tags = "调度管理-已托运控制层")
@RequestMapping("trailer")
public class TrailerController {

	@Autowired
	private TrailerService service;

	@UserLog("已托运查询")
	@ApiOperation(value = "已托运查询", notes = "已托运查询")
	@PostMapping("/page")
	public RestMessage<Page<TrailerQueryDTO>> loadingBillQueryExecute(@RequestBody TrailerQueryVO trailerQueryVO) {
		try {
			Page<TrailerQueryDTO> queryDTOS = service.loadingBillQuery(trailerQueryVO);
			return RestMessage.newInstance(true, "查询成功！", queryDTOS);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已托运审核")
	@ApiOperation(value = "已托运审核", notes = "已托运审核")
	@PostMapping("/trailer_audit")
	public RestMessage<Object> trailerAuditExecute(@RequestBody List<String> ids) {
		try {
			service.trailerAuditData(ids);
			return RestMessage.newInstance(true, "审核成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("运单查询")
	@ApiOperation(value = "运单查询", notes = "运单查询")
	@PostMapping("/shipbill")
	public RestMessage<Page<DispatchCheckQueryDTO>> shipbillQueryExecute(@RequestBody ShipbillQueryVO shipbillQueryVO) {
		try {
			Page<DispatchCheckQueryDTO> dispatchCheckQueryDTOS = service.shipbillQuery(shipbillQueryVO);
			return RestMessage.newInstance(true, "查询成功", dispatchCheckQueryDTOS);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已托运运单撤销")
	@ApiOperation(value = "已托运运单撤销", notes = "已托运运单撤销")
	@PostMapping("/trailer_undo")
	public RestMessage<Object> trailerUndoExecute(@RequestBody List<String> ids) {
		try {
			service.trailerUndoData(ids);
			return RestMessage.newInstance(true, "撤销成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("已托运配载运单剔除")
	@ApiOperation(value = "已托运配载运单剔除", notes = "已托运配载运单剔除")
	@PostMapping("/delete_detail")
	public RestMessage<Object> deleteDetailTrailerExecute(@RequestBody TrailerDeleteDetailVO trailerDeleteDetailVO) {
		try {
			service.deleteDetailTrailerData(trailerDeleteDetailVO);
			return RestMessage.newInstance(true, "剔除成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}
}
