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.ShipbillHeaderPageDTO;
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/shipBill")
public class InTransitShipBillController {

    @Autowired
    private InTransitFactory inTransitFactory;

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

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

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

}
