package com.agentdriving.user.modular.system.service.impl; import com.agentdriving.user.core.util.ToolUtil; import com.agentdriving.user.modular.system.dao.SystemConfigMapper; import com.agentdriving.user.modular.system.model.SystemConfig; import com.agentdriving.user.modular.system.service.ISystemConfigService; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.agentdriving.user.modular.system.warpper.PriceRulesWarpper; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * 系统配置 * @author pzb * @Date 2023/2/15 16:26 */ @Service public class SystemConfigServiceImpl extends ServiceImpl implements ISystemConfigService { /** * 获取价格表 * @return * @throws Exception */ @Override public PriceRulesWarpper queryPriceRules() throws Exception { SystemConfig systemConfig = this.selectOne(new EntityWrapper().eq("type", 5)); PriceRulesWarpper priceRulesWarpper = new PriceRulesWarpper(); if(null != systemConfig){ JSONObject jsonObject = JSON.parseObject(systemConfig.getContent()); JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard"); List> basePrice = new ArrayList<>(); List> longDistanceCharges = new ArrayList<>(); for (int i = 0; i < chargeStandard.size(); i++) { JSONObject jsonObject1 = chargeStandard.getJSONObject(i); String num1 = jsonObject1.getString("num1"); String num2 = jsonObject1.getString("num2"); JSONArray num3 = jsonObject1.getJSONArray("num3"); Double num4 = jsonObject1.getDouble("num4"); Double num5 = jsonObject1.getDouble("num5"); Double num6 = jsonObject1.getDouble("num6"); Double num7 = jsonObject1.getDouble("num7"); Double num8 = jsonObject1.getDouble("num8"); Map map1 = new HashMap<>(); map1.put("time", ToolUtil.isEmpty(num1) ? "其他时段" : num1 + "-" + num2); List> list = new ArrayList<>(); for (int j = 0; j < num3.size(); j++) { Map map = new HashMap<>(); JSONObject jsonObject2 = num3.getJSONObject(j); Double num1_1 = jsonObject2.getDouble("num1"); Double num2_1 = jsonObject2.getDouble("num2"); Double num3_1 = jsonObject2.getDouble("num3"); map.put("startingMileage", num1_1 + "-" + num2_1 + "公里(含" + num2_1 + "公里)"); map.put("startingPrice", num3_1 + "元"); list.add(map); } map1.put("data", list); basePrice.add(map1); Map map2 = new HashMap<>(); map2.put("time", ToolUtil.isEmpty(num1) ? "其他时段" : num1 + "-" + num2); map2.put("startingMileage", num4 + "-" + num5 + "公里"); map2.put("startingPrice", num6 + "元"); if(num6 == 0){ JSONObject jsonObject2 = num3.getJSONObject(num3.size() - 1); Double num3_1 = jsonObject2.getDouble("num3"); map2.put("startingPrice", num3_1 + "元"); } map2.put("exceedStartingPrice", num7 + "公里/" + num8 + "元"); longDistanceCharges.add(map2); } priceRulesWarpper.setBasePrice(JSON.toJSONString(basePrice)); priceRulesWarpper.setLongDistanceCharges(JSON.toJSONString(longDistanceCharges)); //额外费用 JSONObject extraCost = jsonObject.getJSONObject("ExtraCost"); Integer num1 = extraCost.getInteger("num1"); Double num2 = extraCost.getDouble("num2"); Integer num3 = extraCost.getInteger("num3"); Double num4 = extraCost.getDouble("num4"); Double num5 = extraCost.getDouble("num5"); Double num6 = extraCost.getDouble("num6"); Double num7 = extraCost.getDouble("num7"); Double num8 = extraCost.getDouble("num8"); Double num9 = extraCost.getDouble("num9"); Map map = new HashMap<>(); map.put("waitTime", num1 + "分钟/" + num2 + "元"); map.put("exceedWaitTime", "超出" + num3 + "分钟,收取" + num4 + "元/分钟"); map.put("badWeather", ""); systemConfig = this.selectOne(new EntityWrapper().eq("type", 8)); JSONObject jsonObject1 = JSON.parseObject(systemConfig.getContent()); Integer num11 = jsonObject1.getInteger("num1");//开启恶劣天气计价 if(1 == num11){ map.put("badWeather", num5 + "公里内加收" + num6 + "元,超过" + num7 + "公里按照订单单价的" + num8 + "倍计费,最高收取" + num9 + "元"); } priceRulesWarpper.setAdditionalFee(JSON.toJSONString(map)); } return priceRulesWarpper; } }