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

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.ShipbillHeaderPageDTO;
import com.prolog.rdc.tms.model.dto.intransit.LoadingAndShipBillHeaderDTO;
import com.prolog.rdc.tms.model.dto.intransit.VehicleAlarmDTO;
import com.prolog.rdc.tms.model.vo.intransit.InTransitQueryVO;
import com.prolog.rdc.tms.service.impl.intransit.InTransitFactory;
import com.prolog.rdc.tms.util.DataUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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 java.util.List;

/**
 * @author hongbo.pan
 * @date 2022/9/20
 */
@RestController
@Api(tags = "在途管理-公共接口")
@RequestMapping("/inTransit/common")
public class InTransitCommonController {

    @Autowired
    private InTransitFactory inTransitFactory;

    @UserLog("根据派车单号查询运单(分页)")
    @ApiOperation(value = "根据派车单号查询运单(分页)", notes = "根据派车单号查询运单(分页)")
    @PostMapping("/getShipBillByLoadingBillNo/{positionType}")
    public RestMessage<Page<ShipbillHeaderPageDTO>> getShipBillByLoadingBillNo(@PathVariable(required = false) String positionType, @RequestBody InTransitQueryVO vo) {
        DataUtils.setBillIdAndNo(vo);
        Page<ShipbillHeaderPageDTO> page = inTransitFactory.getInTransitService(positionType).getShipBillByLoadingBillNo(vo);
        return RestMessage.newInstance(true, "查询成功！", page);
    }

    @Deprecated
    @UserLog("根据位置信息查询运单派车单")
    @ApiOperation(value = "根据位置信息查询运单派车单", notes = "根据位置信息查询运单派车单")
    @PostMapping("/getLoadingAndShipBillByGpsId/{positionType}")
    public RestMessage<LoadingAndShipBillHeaderDTO> getLoadingAndShipBillByGpsId(@PathVariable(required = false) String positionType, @RequestParam("gpsId") String gpsId) {
        LoadingAndShipBillHeaderDTO dto = inTransitFactory.getInTransitService(positionType).getLoadingAndShipBillByGpsId(gpsId);
        return RestMessage.newInstance(true, "查询成功！", dto);
    }

    @UserLog("告警")
    @ApiOperation(value = "告警", notes = "告警")
    @PostMapping("/getAlarm/{positionType}")
    public RestMessage<List<VehicleAlarmDTO>> getAlarm(@PathVariable(required = false) String positionType, @RequestBody InTransitQueryVO vo) {
        DataUtils.setBillIdAndNo(vo);
        List<VehicleAlarmDTO> vehicleAlarmDTOList = inTransitFactory.getInTransitService(positionType).getAlarm(vo);
        return RestMessage.newInstance(true, "查询成功！", vehicleAlarmDTOList);
    }

}
