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.SelfPickUpShipBillDetailDTO;
import com.prolog.rdc.tms.app.model.dto.business.SelfWithdrawalConfirmQueryDTO;
import com.prolog.rdc.tms.app.model.dto.business.WaitForSelfWithdrawalDTO;
import com.prolog.rdc.tms.app.model.vo.business.*;
import com.prolog.rdc.tms.app.service.business.WaitForSelfWithdrawalService;
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 javax.validation.Valid;
import java.util.List;

/**
 * 待自提控制层
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author xyf
 * @since 2022/4/18 12:42
 */
@RestController
@Api(tags = "业务APP-待自提控制层")
@RequestMapping("waitForSelfWithdrawal")
public class WaitForSelfWithdrawalController {

	@Autowired
	private WaitForSelfWithdrawalService service;

	@UserLog("运单查询")
	@ApiOperation(value = "运单查询", notes = "运单查询")
	@PostMapping("/page")
	public RestMessage<Page<WaitForSelfWithdrawalDTO>> queryShipbill(@RequestBody @Valid WaitForSelfWithdrawalQueryVO vo) throws Exception {
		Page<WaitForSelfWithdrawalDTO> waitForSelfWithdrawalDTOList = service.queryShipbill(vo);
		return RestMessage.newInstance(true, "查询成功！", waitForSelfWithdrawalDTOList);
	}

	@UserLog("自提确认")
	@ApiOperation(value = "自提确认", notes = "自提确认")
	@PostMapping("/confirm")
	public RestMessage<Object> selfWithdrawalConfirm(@RequestBody @Valid SelfWithdrawalConfirmVO vo) {
		try {
			service.selfWithdrawalConfirm(vo);
			return RestMessage.newInstance(true, "自提确认操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("自提车辆登记")
	@ApiOperation(value = "自提车辆登记", notes = "自提车辆登记")
	@PostMapping("/vehicle_register")
	public RestMessage<Object> vehicleRegister(@RequestBody @Valid SelfPickUpVehicleRegisterVO vehicleRegisterVO) throws Exception {
		try {
			service.vehicleRegister(vehicleRegisterVO);
			return RestMessage.newInstance(true, "自提车辆登记操作成功！", null);
		} catch (Exception e) {
			e.printStackTrace();

			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("自提确认查询")
	@ApiOperation(value = "自提确认查询", notes = "自提确认查询")
	@PostMapping("/confirm_query")
	public RestMessage<SelfWithdrawalConfirmQueryDTO> selfWithdrawalConfirmQuery(@RequestBody @Valid SelfWithdrawalConfirmQueryVO vo) throws Exception {
		SelfWithdrawalConfirmQueryDTO dto = service.ConfirmQuery(vo);
		return RestMessage.newInstance(true, "自提确认查询成功！", dto);
	}

	@UserLog("商品查询")
	@ApiOperation(value = "商品查询", notes = "商品查询")
	@PostMapping("/item_detail")
	public RestMessage<List<SelfPickUpShipBillDetailDTO>> queryShipbillDetail_(@RequestBody WaitForSelfItemQueryVO itemQueryVO) throws Exception {
		List<SelfPickUpShipBillDetailDTO> shipbillDetails = service.queryShipbillDetail_(itemQueryVO);
		return RestMessage.newInstance(true, "查询成功！", shipbillDetails);
	}

}
