package com.prolog.rdc.tms.controller.intelligent;

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.model.dto.intelligent.IntelligentDispatchCallBackDTO;
import com.prolog.rdc.tms.model.dto.intelligent.IntelligentDispatchDTO;
import com.prolog.rdc.tms.model.dto.intelligent.IntelligentDispatchGroupDTO;
import com.prolog.rdc.tms.model.dto.intelligent.IntelligentDispatchLoadingDTO;
import com.prolog.rdc.tms.model.dto.intelligent.IntelligentDispatchShipCountDTO;
import com.prolog.rdc.tms.model.dto.intelligent.IntelligentDispatchShipDTO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchGroupQueryVO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchLoadingAdjustVO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchLoadingQueryVO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchLoadingVO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchQueryVO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchShipBillQueryVO;
import com.prolog.rdc.tms.model.vo.intelligent.IntelligentDispatchVO;
import com.prolog.rdc.tms.service.intelligent.IntelligentDispatchService;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

/**
 * @author hongbo.pan
 * @date 2023/8/24
 */
@RestController
@Api(tags = "智能调度")
@RequestMapping("/intelligentDispatch")
public class IntelligentDispatchController {

    @Autowired
    private IntelligentDispatchService service;

    @UserLog("分组统计查询")
    @ApiOperation(value = "分组统计查询", notes = "分组统计查询")
    @PostMapping("/queryGroup")
    public RestMessage<IntelligentDispatchGroupDTO> queryGroup(@RequestBody IntelligentDispatchGroupQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功！", service.queryGroup(vo));
    }

    @UserLog("分组运单查询")
    @ApiOperation(value = "分组运单查询", notes = "分组运单查询")
    @PostMapping("/queryShipBill")
    public RestMessage<Page<IntelligentDispatchShipDTO>> queryShipBill(@RequestBody IntelligentDispatchShipBillQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功！", service.queryShipBill(vo));
    }

    @UserLog("统计运单查询")
    @ApiOperation(value = "统计运单查询", notes = "统计运单查询")
    @PostMapping("/countShipBill")
    public RestMessage<IntelligentDispatchShipCountDTO> countShipBill(@RequestBody IntelligentDispatchShipBillQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功！", service.countShipBill(vo));
    }

    @UserLog("开始调度")
    @ApiOperation(value = "开始调度", notes = "开始调度")
    @PostMapping("/dispatch")
    public RestMessage<IntelligentDispatchDTO> dispatch(@RequestBody @Valid IntelligentDispatchVO vo) {
        return RestMessage.newInstance(true, "操作成功！", service.dispatch(vo));
    }

    @UserLog("取消调度")
    @ApiOperation(value = "取消调度", notes = "取消调度")
    @PostMapping("/cancelDispatch")
    public RestMessage<IntelligentDispatchDTO> cancelDispatch(@RequestParam String intelligentDispatchId) {
        service.cancelDispatch(intelligentDispatchId);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("轮询进度")
    @ApiOperation(value = "轮询进度", notes = "轮询进度")
    @PostMapping("/getDispatchInfo")
    public RestMessage<IntelligentDispatchDTO> getDispatchInfo(@RequestParam String intelligentDispatchId) {
        return RestMessage.newInstance(true, "操作成功！", service.getDispatchInfo(intelligentDispatchId));
    }

    @UserLog("智能调度记录查询")
    @ApiOperation(value = "智能调度记录查询", notes = "智能调度记录查询")
    @PostMapping("/findByCondition")
    public RestMessage<Page<IntelligentDispatchDTO>> findByCondition(@RequestBody @Valid IntelligentDispatchQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功！", service.findByCondition(vo));
    }

    @UserLog("排线结果")
    @ApiOperation(value = "排线结果", notes = "排线结果")
    @PostMapping("/getDispatchResult")
    public RestMessage<IntelligentDispatchDTO> getDispatchResult(@RequestParam String intelligentDispatchId) {
        return RestMessage.newInstance(true, "操作成功！", service.getDispatchResult(intelligentDispatchId));
    }

    @UserLog("排线结果过滤")
    @ApiOperation(value = "排线结果过滤", notes = "排线结果过滤")
    @PostMapping("/filterDispatchLoading")
    public RestMessage<List<IntelligentDispatchLoadingDTO>> filterDispatchLoading(@RequestBody IntelligentDispatchLoadingQueryVO vo) {
        return RestMessage.newInstance(true, "操作成功！", service.filterDispatchLoading(vo));
    }

    @UserLog("线路调度")
    @ApiOperation(value = "线路调度", notes = "线路调度")
    @PostMapping("/dispatchLoading")
    public RestMessage<Object> dispatchLoading(@RequestBody List<String> loadingIdList) {
        service.dispatchLoading(loadingIdList);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("线路调度审核")
    @ApiOperation(value = "线路调度审核", notes = "线路调度审核")
    @PostMapping("/dispatchReviewLoading")
    public RestMessage<Object> dispatchReviewLoading(@RequestBody List<String> loadingIdList) {
        service.dispatchReviewLoading(loadingIdList);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("线路取消")
    @ApiOperation(value = "线路取消", notes = "线路取消")
    @PostMapping("/cancelLoading")
    public RestMessage<Object> cancelLoading(@RequestBody List<String> loadingIdList) {
        service.cancelLoading(loadingIdList);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("车辆司机改派/指派")
    @ApiOperation(value = "车辆司机改派/指派", notes = "车辆司机改派/指派")
    @PostMapping("/assignVehicleDriver")
    public RestMessage<Object> assignVehicleDriver(@RequestBody @Valid IntelligentDispatchLoadingVO vo) {
        service.assignVehicleDriver(vo);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("线路调整")
    @ApiOperation(value = "线路调整", notes = "线路调整")
    @PostMapping("/adjust")
    public RestMessage<Object> adjust(@RequestBody @Valid List<IntelligentDispatchLoadingAdjustVO> voList) {
        service.adjust(voList);
        return RestMessage.newInstance(true, "操作成功！", null);
    }

    @UserLog("回调处理")
    @ApiOperation(value = "回调处理", notes = "回调处理")
    @PostMapping("/callBack")
    public RestMessage<Object> callBack(@RequestBody @Valid IntelligentDispatchCallBackDTO callBackDTO) {
        service.callBack(callBackDTO);
        return RestMessage.newInstance(true, "操作成功！", null);
    }
}
