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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package com.agentdriving.user.modular.api;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.agentdriving.user.modular.system.model.Html;
import com.agentdriving.user.modular.system.model.SystemConfig;
import com.agentdriving.user.modular.system.service.IHtmlService;
import com.agentdriving.user.modular.system.service.ISystemConfigService;
import com.agentdriving.user.modular.system.util.ResultUtil;
import com.agentdriving.user.modular.system.warpper.ResponseWarpper;
import com.agentdriving.user.modular.system.warpper.StartPriceWarpper;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
 
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
/**
 * 协议控制器
 */
@RestController
@RequestMapping("")
public class HtmlController {
 
    @Autowired
    private IHtmlService htmlService;
 
    @Autowired
    private ISystemConfigService systemConfigService;
 
 
 
 
    @ResponseBody
    @PostMapping("/base/html/queryHtml")
//    @ServiceLog(name = "获取各种协议和说明", url = "/base/html/queryHtml")
    @ApiOperation(value = "获取各种协议和说明", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "类型(1=代驾服务协议与隐私政策保护,2=法律条款,3=个人信息处理规则,4=积分说明,5=佣金规则说明,6=行程录音说明,7=预估价格说明,8=加盟基本要求,9=加盟流程,10=起步价说明,11=注销协议,12=关于我们,13=司机消单说明)", name = "type", required = true, dataType = "int"),
    })
    public ResponseWarpper<String> queryHtml(Integer type){
        if(null == type){
            return ResponseWarpper.success(ResultUtil.paranErr("type"));
        }
        try {
            Html html = htmlService.selectOne(new EntityWrapper<Html>().eq("type", type));
            return ResponseWarpper.success(null == html ? "" : html.getHtml());
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/html/queryStartPrice")
//    @ServiceLog(name = "获取起步价和起步价说明", url = "/base/html/queryStartPrice")
    @ApiOperation(value = "获取起步价和起步价说明", tags = {"用户端-首页"}, notes = "")
    @ApiImplicitParams({
    })
    public ResponseWarpper<StartPriceWarpper> queryStartPrice(){
        try {
            Html html = htmlService.selectOne(new EntityWrapper<Html>().eq("type",10));
            StartPriceWarpper startPriceWarpper = new StartPriceWarpper();
            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5));
            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
            JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard");
            boolean b = true;
            Date date = new Date();
            for (int i = 1; i < chargeStandard.size(); i++) {//各种时间段
                JSONObject jsonObject1 = chargeStandard.getJSONObject(i);
                String num1 = jsonObject1.getString("num1");
                String num2 = jsonObject1.getString("num2");
                JSONArray num3 = jsonObject1.getJSONArray("num3");//起步里程
 
                String[] split = num1.split(":");
                Calendar s = Calendar.getInstance();
                s.setTime(date);
                s.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
                s.set(Calendar.MINUTE, Integer.valueOf(split[1]));
                s.set(Calendar.SECOND, 0);
 
                split = num2.split(":");
                Calendar e = Calendar.getInstance();
                e.setTime(date);
                e.set(Calendar.HOUR_OF_DAY, Integer.valueOf(split[0]));
                e.set(Calendar.MINUTE, Integer.valueOf(split[1]));
                e.set(Calendar.SECOND, 59);
 
                if(date.getTime() >= s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
                    b = false;
                    for (int j = 0; j < num3.size(); j++) {
                        JSONObject jsonObject2 = num3.getJSONObject(j);
                        Double num1_1 = jsonObject2.getDouble("num1");
                        Double num2_1 = jsonObject2.getDouble("num2");
                        Double num3_1 = jsonObject2.getDouble("num3");
                        startPriceWarpper.setStartPrice(num3_1);
                        startPriceWarpper.setStartDistance(num1_1);
                        break;
                    }
                }
            }
 
            if(b){//默认配置
                JSONObject jsonObject1 = chargeStandard.getJSONObject(0);
                JSONArray num3 = jsonObject1.getJSONArray("num3");//起步里程
                JSONObject jsonObject2 = num3.getJSONObject(0);
                Double num1_1 = jsonObject2.getDouble("num1");
                Double num2_1 = jsonObject2.getDouble("num2");
                Double num3_1 = jsonObject2.getDouble("num3");
                startPriceWarpper.setStartPrice(num3_1);
                startPriceWarpper.setStartDistance(num1_1);
            }
            startPriceWarpper.setDescription(null == html ? "" : html.getHtml());
            return ResponseWarpper.success(startPriceWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
}