package com.ruoyi.web.controller.shipping.transship;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.warehouseBusiness.domain.TWarehouseBills;
import com.ruoyi.warehouseBusiness.service.ITWarehouseBillsService;
import lombok.extern.slf4j.Slf4j;
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;

/**
 * 凯和转配船功能
 *
 * @author ruoyi
 * @date 2021-04-08
 */
@Slf4j
@RestController
@RequestMapping("/transhipment")
public class Transhipment extends BaseController {
    @Autowired
    private ITWarehouseBillsService tWarehousebillsService;

    @PostMapping("/transship")
    public AjaxResult transship(@RequestBody TWarehouseBills tWarehouseBills) {
        if (CollectionUtils.isEmpty(tWarehouseBills.getOrderList())){
            throw new RuntimeException("请选择要转船的订单");
        }
        if (tWarehouseBills.getfVslid() == null){
            throw new RuntimeException("请选择要转的船名");
        }
        if (tWarehouseBills.getfVoyid() == null){
            throw new RuntimeException("请选择要转的航次");
        }
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return tWarehousebillsService.transship(tWarehouseBills,loginUser);
    }
    @PostMapping("/turnVoyage")
    public AjaxResult turnVoyage(@RequestBody TWarehouseBills tWarehouseBills) {
        if (CollectionUtils.isEmpty(tWarehouseBills.getOrderList())){
            throw new RuntimeException("请选择要转航次的订单");
        }
        if (tWarehouseBills.getfVslid() == null){
            throw new RuntimeException("请选择要转的船名");
        }
        if (tWarehouseBills.getfVoyid() == null){
            throw new RuntimeException("请选择要转的航次");
        }
        LoginUser loginUser = SpringUtils.getBean(TokenService.class).getLoginUser(ServletUtils.getRequest());
        return tWarehousebillsService.turnVoyage(tWarehouseBills,loginUser);
    }
}
