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.intransit.InTransitTrackDTO;
import com.prolog.rdc.tms.model.dto.intransit.LoadingBillHeaderPageDTO;
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.RestController;

/**
 * @author hongbo.pan
 * @date 2022/9/20
 */
@RestController
@Api(tags = "在途管理-派车单定位/轨迹")
@RequestMapping("/inTransit/loadingBill")
public class InTransitLoadingBillController {

    @Autowired
    private InTransitFactory inTransitFactory;

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

    @UserLog("派车单定位")
    @ApiOperation(value = "派车单定位", notes = "派车单定位")
    @PostMapping("/getPositionByLoadingBillId/{positionType}")
    public RestMessage<Object> getPositionByLoadingBillId(@PathVariable(required = false) String positionType, @RequestBody InTransitQueryVO vo) {
        DataUtils.setBillIdAndNo(vo);
        Object dto = inTransitFactory.getInTransitService(positionType).getPositionByLoadingBillId(vo.getLoadingBillId());
        return RestMessage.newInstance(true, "查询成功！", dto);
    }

    @UserLog("派车单轨迹")
    @ApiOperation(value = "派车单轨迹", notes = "派车单轨迹")
    @PostMapping("/getTrackByLoadingBillId/{positionType}")
    public RestMessage<InTransitTrackDTO> getTrackByLoadingBillId(@PathVariable(required = false) String positionType, @RequestBody InTransitQueryVO vo) {
        DataUtils.setBillIdAndNo(vo);
        InTransitTrackDTO dto = inTransitFactory.getInTransitService(positionType).getTrackByLoadingBillId(vo.getLoadingBillId());
        return RestMessage.newInstance(true, "查询成功！", dto);
    }

}
