puzhibing
2023-06-02 fb4902cf37252a3e47a7b7f49542b3b627f5b2d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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<SystemConfigMapper, SystemConfig> implements ISystemConfigService {
 
 
    /**
     * 获取价格表
     * @return
     * @throws Exception
     */
    @Override
    public PriceRulesWarpper queryPriceRules() throws Exception {
        SystemConfig systemConfig = this.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5));
        PriceRulesWarpper priceRulesWarpper = new PriceRulesWarpper();
        if(null != systemConfig){
            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
            JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard");
            List<Map<String, Object>> basePrice = new ArrayList<>();
            List<Map<String, Object>> 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<String, Object> map1 = new HashMap<>();
                map1.put("time", ToolUtil.isEmpty(num1) ? "其他时段" : num1 + "-" + num2);
                List<Map<String, String>> list = new ArrayList<>();
                for (int j = 0; j < num3.size(); j++) {
                    Map<String, String> 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<String, Object> 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<String, Object> map = new HashMap<>();
            map.put("waitTime", num1 + "分钟/" + num2 + "元");
            map.put("exceedWaitTime", "超出" + num3 + "分钟,收取" + num4 + "元/分钟");
            map.put("badWeather", num5 + "公里内加收" + num6 + "元,超过" + num7 + "公里按照订单单价的" + num8 + "倍计费,最高收取" + num9 + "元");
            priceRulesWarpper.setAdditionalFee(JSON.toJSONString(map));
        }
        return priceRulesWarpper;
    }
}