package com.sckw.transport.controller;

import com.alibaba.fastjson.JSONObject;
import com.sckw.core.annotation.RepeatSubmit;
import com.sckw.core.web.constant.HttpStatus;
import com.sckw.core.web.response.HttpResult;
import com.sckw.transport.model.dto.LogisticsConsignmentDto;
import com.sckw.transport.model.dto.LogisticsOrderFinishDto;
import com.sckw.transport.model.dto.LogisticsOrderSubcontractDto;
import com.sckw.transport.model.param.AddLogisticsOrderParam;
import com.sckw.transport.service.KwtLogisticsConsignmentService;
import com.sckw.transport.service.KwtTransportCommonService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lfdc
 * @desc 物流订单Controller-v4.2
 * @date 2024-03-11 11:06:06
 */
@Slf4j
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping(value = "/kwtLogisticsOrder")
public class KwtLogisticsOrderController {

    @Autowired
    KwtLogisticsConsignmentService logisticsConsignmentService;

    @Autowired
    KwtTransportCommonService transportCommonService;


    /**
     * 采购订单/销售订单-物流托运-V4.2
     *
     * @param logisticsConsignmentDto 页面请求参数
     * @return  响应结果
     */
    @Validated
    @RepeatSubmit(interval = 1000,message ="前方拥堵，请稍后尝试")
    @RequestMapping(value = "/consignment", method = RequestMethod.POST)
    public HttpResult logisticsOrderConsignment(@Valid @RequestBody LogisticsConsignmentDto logisticsConsignmentDto) {
        log.info("采购订单/销售订单-物流托运传递参数信息:{}", JSONObject.toJSONString(logisticsConsignmentDto));
        try {
            return logisticsConsignmentService.logisticsOrderConsignment(logisticsConsignmentDto);
        } catch (Exception e) {
            log.error("采购订单/销售订单-物流托运生成托运订单 error :{}", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }


    /**
     * 承运订单/托运订单-自建物流订单 V4.2
     *
     * @param addLogisticsOrderParam 页面请求参数
     * @return  响应结果
     */
    @Validated
    @RepeatSubmit(interval = 1000,message ="前方拥堵，请稍后尝试")
    @RequestMapping(value = "/createOrder", method = RequestMethod.POST)
    public HttpResult addLogisticsOrder(@Valid @RequestBody AddLogisticsOrderParam addLogisticsOrderParam) {
        log.info("承运订单/托运订单-自建物流订单传递参数信息:{}", JSONObject.toJSONString(addLogisticsOrderParam));
        try {
            return logisticsConsignmentService.addLogisticsOrder(addLogisticsOrderParam);
        } catch (Exception e) {
            log.error("承运订单/托运订单-自建物流订单 error :{}", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }


    /**
     * 物流订单-分包托运-V4.2
     *
     * @param logisticsOrderSubcontractDto 页面请求参数
     * @return  响应结果
     */
    @Validated
    @RepeatSubmit(interval = 1000,message ="前方拥堵，请稍后尝试")
    @RequestMapping(value = "/subcontract", method = RequestMethod.POST)
    public HttpResult logisticsOrderSubcontract(@Valid @RequestBody LogisticsOrderSubcontractDto logisticsOrderSubcontractDto) {
        log.info("物流订单-分包托运传递参数信息:{}", JSONObject.toJSONString(logisticsOrderSubcontractDto));
        try {
            return logisticsConsignmentService.logisticsOrderSubcontract(logisticsOrderSubcontractDto);
        } catch (Exception e) {
            log.error("物流订单-分包托运 error :{}", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }

    /**
     * 物流订单-完结订单-V4.2
     *
     * @param logisticsOrderSubcontractDto 页面请求参数
     * @return  响应结果
     */
    @Validated
    @RepeatSubmit(interval = 1000,message ="前方拥堵，请稍后尝试")
    @RequestMapping(value = "/logisticsOrderFinish", method = RequestMethod.POST)
    public HttpResult logisticsOrderFinish(@Valid @RequestBody LogisticsOrderFinishDto logisticsOrderSubcontractDto) {
        log.info("物流订单-完结订单传递参数信息:{}", JSONObject.toJSONString(logisticsOrderSubcontractDto));
        try {
            return transportCommonService.logisticsOrderFinish(logisticsOrderSubcontractDto);
        } catch (Exception e) {
            log.error("物流订单-完结订单 error :{}", e.getMessage(), e);
            return HttpResult.error(HttpStatus.GLOBAL_EXCEPTION_CODE, e.getMessage());
        }
    }





}
