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

import com.prolog.framework.core.pojo.Page;
import com.prolog.rdc.tms.app.model.dto.business.AllShipbillPageDTO;
import com.prolog.rdc.tms.app.model.dto.business.ShowContainerTemperatureDTO;
import com.prolog.rdc.tms.app.model.dto.business.StrategyBusinessTemperatureDTO;
import com.prolog.rdc.tms.app.model.vo.business.AllShipbillQueryVO;
import com.prolog.rdc.tms.app.model.vo.business.ShowContainerTemperatureVO;
import com.prolog.rdc.tms.app.model.vo.business.SignInShipBillVO;
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.log.aop.annotation.UserLog;
import com.prolog.rdc.tms.app.model.vo.business.ShipbillHeaderSaveVO;
import com.prolog.rdc.tms.app.service.business.ShipbillService;

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

import javax.validation.Valid;
import java.util.List;

/**
 *
 *
 * Company: 湖北普罗格科技股份有限公司
 *
 * @author zhangsj
 * @since 2022/7/19 16:10
 */
@RestController
@Api(tags = "业务APP-快速开单控制层")
@RequestMapping("/shipbill")
public class ShipbillController {

	@Autowired
	private ShipbillService shipbillService;

	@UserLog("快速开单")
	@ApiOperation(value = "快速开单", notes = "快速开单")
	@PostMapping("/quick_shipbill")
	public RestMessage<Object> quickShipbillExecute(@RequestBody ShipbillHeaderSaveVO shipbillHeaderSaveVO) {
		try {
			shipbillService.quickShipbillData(shipbillHeaderSaveVO);
			return RestMessage.newInstance(true, "开单成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}

	}

	@UserLog("退货运单")
	@ApiOperation(value = "退货运单", notes = "退货运单")
	@PostMapping("/createReturnShipBill")
	public RestMessage createReturnShipBill(@RequestBody SignInShipBillVO signInShipBillVO) {
		try {
			shipbillService.createReturnShipBill(signInShipBillVO);
			return RestMessage.newInstance(true, "退货成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("签收运单")
	@ApiOperation(value = "签收运单", notes = "签收运单")
	@PostMapping("/signIn")
	public RestMessage signIn(@RequestBody SignInShipBillVO signInShipBillVO) {
		try {
			shipbillService.signIn(signInShipBillVO);
			return RestMessage.newInstance(true, "签收成功", null);
		} catch (Exception e) {
			e.printStackTrace();
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("销售单模式查询")
	@ApiOperation(value = "销售单模式查询", notes = "销售单模式查询")
	@PostMapping("/query_sell")
	public RestMessage<Page<AllShipbillPageDTO>> querySellAllShipbillPage(@RequestBody AllShipbillQueryVO vo) {
		try {
			Page<AllShipbillPageDTO> page = shipbillService.querySellAllShipbillPage(vo);
			return RestMessage.newInstance(true, "查询成功！", page);
		}catch (Exception e){
			return RestMessage.newInstance(false, e.getMessage(), null);
		}
	}

	@UserLog("司机拒绝接单")
	@ApiOperation(value = "司机拒绝接单", notes = "司机拒绝接单")
	@PostMapping("/reject")
	public RestMessage<String> reject(@RequestBody List<String> shipBillIdList) {
		shipbillService.reject(shipBillIdList);
		return RestMessage.newInstance(true, "司机拒绝接单成功", null);
	}

	@UserLog("司机接单")
	@ApiOperation(value = "司机接单", notes = "司机接单")
	@PostMapping("/receive")
	public RestMessage<String> receive(@RequestBody List<String> shipBillIdList) {
		shipbillService.receive(shipBillIdList);
		return RestMessage.newInstance(true, "司机接单成功", null);
	}

	@UserLog("业务规则匹配-是否显示温度")
	@ApiOperation(value = "业务规则匹配-是否显示温度", notes = "业务规则匹配-是否显示温度")
	@PostMapping("/showTemperature")
	public RestMessage<StrategyBusinessTemperatureDTO> showTemperature(@RequestBody List<String> shipBillIdList) {
		return RestMessage.newInstance(true, "查询成功", shipbillService.showTemperature(shipBillIdList));
	}

	@UserLog("容器温度")
	@ApiOperation(value = "容器温度", notes = "容器温度")
	@PostMapping("/containerTemperature")
	public RestMessage<ShowContainerTemperatureDTO> containerTemperature(@RequestBody @Valid ShowContainerTemperatureVO vo) {
		return RestMessage.newInstance(true, "查询成功", shipbillService.containerTemperature(vo));
	}
}
