puzhibing
2023-08-16 c18ec3846c8483975de2224c1ecac9470e9b2804
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
package com.supersavedriving.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.supersavedriving.user.core.common.annotion.ServiceLog;
import com.supersavedriving.user.modular.system.model.Html;
import com.supersavedriving.user.modular.system.model.SystemConfig;
import com.supersavedriving.user.modular.system.service.IHtmlService;
import com.supersavedriving.user.modular.system.service.ISystemConfigService;
import com.supersavedriving.user.modular.system.util.ResultUtil;
import com.supersavedriving.user.modular.system.warpper.ResponseWarpper;
import com.supersavedriving.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.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();
            //{"ChargeStandard":[{"num1":"06:00","num2":"08:00","num3":2,"num4":2,"num5":2,"num6":2,"num7":2,"num8":2,"num9":2,"num10":2,"num11":2},{"num1":"06:00","num2":"08:00","num3":2,"num4":2,"num5":2,"num6":2,"num7":2,"num8":2,"num9":2,"num10":2,{"num1":"06:00","num2":"08:00","num3":2,"num4":2,"num5":2,"num6":2,"num7":2,"num8":2,"num9":2,"num10":2,"num11":2}],"ExtraCost":{"num1":1,"num2":1,"num3":1,"num4":1,"num5":1,"num6":1,"num7":1,"num8":1,"num9":1},"description":"这是一段说明文本"}
            SystemConfig systemConfig = systemConfigService.selectOne(new EntityWrapper<SystemConfig>().eq("type", 5));
            JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
            JSONArray chargeStandard = jsonObject.getJSONArray("ChargeStandard");
            Date date = new Date();
            for (int i = 0; i < chargeStandard.size(); i++) {
                JSONObject jsonObject1 = chargeStandard.getJSONObject(i);
                String num1 = jsonObject1.getString("num1");
                String num2 = jsonObject1.getString("num2");
                Double num3 = jsonObject1.getDouble("num3");
                Double num4 = jsonObject1.getDouble("num4");
                Double num5 = jsonObject1.getDouble("num5");
                Double num6 = jsonObject1.getDouble("num6");
 
                String[] split = num1.split(":");
                Integer hour1 = Integer.valueOf(split[0]);
                String[] split1 = num2.split(":");
                Integer hour2 = Integer.valueOf(split1[0]);
 
                Calendar s = Calendar.getInstance();
                s.setTime(date);
                s.set(Calendar.HOUR_OF_DAY, hour1);
                s.set(Calendar.MINUTE, Integer.valueOf(split[1]));
                s.set(Calendar.SECOND, 0);
 
                Calendar e = Calendar.getInstance();
                e.setTime(date);
                e.set(Calendar.HOUR_OF_DAY, hour2);
                e.set(Calendar.MINUTE, Integer.valueOf(split1[1]));
                e.set(Calendar.SECOND, 0);
 
                if(hour1 > hour2){
                    if(s.getTimeInMillis() > date.getTime()){
                        s.set(Calendar.DAY_OF_YEAR, s.get(Calendar.DAY_OF_YEAR) - 1);
                    }else{
                        e.set(Calendar.DAY_OF_YEAR, e.get(Calendar.DAY_OF_YEAR) + 1);
                    }
                }
                if(date.getTime() >= s.getTimeInMillis() && date.getTime() < e.getTimeInMillis()){
                    startPriceWarpper.setStartPrice(num4);
                    startPriceWarpper.setStartDistance(num3);
                    startPriceWarpper.setExcessMileageUnitPrice(num6);
                    startPriceWarpper.setOvermileage(num5);
                    break;
                }
            }
            startPriceWarpper.setDescription(null == html ? "" : html.getHtml());
            return ResponseWarpper.success(startPriceWarpper);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseWarpper(500, e.getMessage());
        }
    }
}