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, 0);
|
|
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");//起步里程
|
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);
|
}
|
}
|
startPriceWarpper.setDescription(null == html ? "" : html.getHtml());
|
return ResponseWarpper.success(startPriceWarpper);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
}
|