package com.sqx.modules.travelconf.controller.app;

import com.sqx.common.exception.SqxException;
import com.sqx.common.utils.DateUtils;
import com.sqx.common.utils.Result2;
import com.sqx.modules.travelconf.service.TravelConfService;
import com.sqx.modules.travelconf.vo.TravelPriceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @author bai
 * @date 2024/06/08
 */
@Slf4j
@RestController
@Api(value = "出行", tags = { "APP" })
@RequestMapping(value = "/app/travelConf")
public class AppTravelConfController {

    @Autowired
    private TravelConfService service;

    @GetMapping("/calcTravelPrice")
    @ApiOperation("计算本次服务出行金额")
    public Result2<TravelPriceVo> calcTravelPrice(@ApiParam(value = "技师ID 示例：116", required = true, example = "116") Long artificerId,
                                                  @ApiParam(value = "经度 示例：125.294234", required = true, example = "125.294234") String toLongitude,
                                                  @ApiParam(value = "纬度 示例：43.887282", required = true, example = "43.887282") String toLatitude){
        Result2<TravelPriceVo> res = new Result2<>();
        try {
            res.setData(service.calcTravelPrice(artificerId, toLongitude, toLatitude, DateUtils.format(new Date())));
        }catch (SqxException e) {
            //业务错误
            log.error(e.getMsg(),e);
            res.error(e.getMsg());
        }
        return res;
    }

}