Pu Zhibing
2025-05-16 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
UserIGOTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/service/impl/ServerCarModelServiceImpl.java
@@ -3,10 +3,12 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.dao.ServerCarModelMapper;
import com.stylefeng.guns.modular.system.dao.SystemPriceMapper;
import com.stylefeng.guns.modular.system.model.Company;
import com.stylefeng.guns.modular.system.model.ServerCarModel;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.ICompanyCityService;
import com.stylefeng.guns.modular.system.service.IServerCarModelService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
@@ -16,6 +18,7 @@
import com.stylefeng.guns.modular.system.util.GoogleMap.DistancematrixVo;
import com.stylefeng.guns.modular.system.util.GoogleMap.GoogleMapUtil;
import com.stylefeng.guns.modular.system.util.GoogleMap.ReverseGeocodeVo;
import com.stylefeng.guns.modular.system.util.RedisUtil;
import com.stylefeng.guns.modular.system.util.ResultUtil;
import com.stylefeng.guns.modular.system.warpper.ServerCarModelWarpper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,6 +49,9 @@
    @Autowired
    private IUserInfoService userInfoService;
    @Resource
    private RedisUtil redisUtil;
@@ -61,9 +67,22 @@
     * @throws Exception
     */
    @Override
    public ResultUtil<List<ServerCarModelWarpper>> queryServerCarModel(String startLonLat, String endLonLat, Integer type, Integer language) throws Exception {
    public ResultUtil<List<ServerCarModelWarpper>> queryServerCarModel(Integer uid, String startLonLat, String endLonLat, Integer type, Integer language) throws Exception {
        UserInfo userInfo = userInfoService.selectById(uid);
        if(null != userInfo && ToolUtil.isEmpty(userInfo.getPhone())){
            return ResultUtil.error(language == 1 ? "请先绑定手机号码" : language == 2 ? "Please bind your mobile phone number first." : "Veuillez d’abord vous inscrire en liant votre numéro de téléphone portable.");
        }
        String[] split = startLonLat.split(",");
        Company company = companyCityService.query1(uid, split[0], split[1]);
        if(null != userInfo && null != company){
            userInfo.setCompanyId(company.getId());
            userInfoService.updateById(userInfo);
        }
        String tripId = redisUtil.getValue("trip" + uid);
        //查找与起点匹配的企业(经营范围)
        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(startLonLat.split(",")[1]), Double.valueOf(startLonLat.split(",")[0]));
        System.err.println("经纬度:" + startLonLat);
        ReverseGeocodeVo reverseGeocode = GoogleMapUtil.getReverseGeocode(Double.valueOf(startLonLat.split(",")[1]), Double.valueOf(startLonLat.split(",")[0]), tripId);
        if(null == language){
            language = 2;
        }
@@ -83,7 +102,7 @@
        Double slat = Double.valueOf(startLonLat.split(",")[1]);
        Double elnt = Double.valueOf(endLonLat.split(",")[0]);
        Double elat = Double.valueOf(endLonLat.split(",")[1]);
        DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(slat, slnt, elat, elnt);
        DistancematrixVo distancematrix = GoogleMapUtil.getDistancematrix(slat, slnt, elat, elnt, tripId);
        if(null == distancematrix){
            return ResultUtil.error(language == 1 ? "获取预估距离出错" : language == 2 ? "Obtaining-estimated-distance error" : "Erreur d’obtention de la distance estimée", new ArrayList<>());
        }else if(distancematrix.getDistance() == 0){
@@ -94,7 +113,7 @@
        long duration = distancematrix.getDuration();//时间(秒)
        long duration_ = Long.valueOf(duration).longValue();
        List<ServerCarModelWarpper> price = this.getPrice(query.getId(), distance1_, duration_, 0, 1);
        List<ServerCarModelWarpper> price = this.getPrice(query.getId(), distance1_, duration_, 0, type, language);
        if(price.size() == 0){
            return ResultUtil.error(language == 1 ? "未获取到可服务的车型" : language == 2 ? "Not obtaining available vehicle-type" : "Ne pas obtenir le type de véhicule disponible", new ArrayList<>());
        }
@@ -123,18 +142,28 @@
     * @return
     * @throws Exception
     */
    public List<ServerCarModelWarpper> getPrice(Integer companyId, double distance, long duration, long wait, Integer type) throws Exception {
    public List<ServerCarModelWarpper> getPrice(Integer companyId, double distance, long duration, long wait, Integer type, Integer language) throws Exception {
        List<Map<String, Object>> list = serverCarModelMapper.queryServerCarModel(type);
        List<ServerCarModelWarpper> data = new ArrayList<>();
        for(Map<String, Object> map : list){
            Map<String, Object> query1 = systemPriceMapper.query(companyId, type, Integer.valueOf(map.get("id").toString()));
            if(1 == language){
                map.put("name", map.get("chineseName"));
            }
            if(2 == language){
                map.put("name", map.get("englishName"));
            }
            if(3 == language){
                map.put("name", map.get("frenchName"));
            }
            Map<String, Object> query1 = systemPriceMapper.query(companyId, type, Integer.valueOf(map.get("id").toString()), language);
            if(null == query1){//排除没有设置价格的车型
                continue;
            }
            //开始根据不同的方式计算金额
            double amount = 0;
            if(type == 1){//专车
            if(type == 1 || type == 4){//专车
                JSONObject jsonObject = JSON.parseObject(query1.get("content").toString());
                String fareTypeNote = query1.get("fareTypeNote").toString();
                Double num1 = jsonObject.getDouble("num1");//起步价(元)
                Double num2 = jsonObject.getDouble("num2");//起步公里(公里)
                Double num3 = jsonObject.getDouble("num3");//起步时间(分钟)
@@ -244,6 +273,7 @@
                    serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue());
                    serverCarModelWarpper.setMileage(d);
                    serverCarModelWarpper.setDuration(t);
                    serverCarModelWarpper.setFareTypeNote(fareTypeNote);
                    data.add(serverCarModelWarpper);
                    continue;
                }
@@ -263,6 +293,7 @@
                serverCarModelWarpper.setAmount(new BigDecimal(amount).setScale(BigDecimal.ROUND_HALF_EVEN, 2).doubleValue());
                serverCarModelWarpper.setMileage(d);
                serverCarModelWarpper.setDuration(t);
                serverCarModelWarpper.setFareTypeNote(fareTypeNote);
                data.add(serverCarModelWarpper);
                continue;
            }