You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
267 lines
14 KiB
267 lines
14 KiB
package com.cweb.controller;
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.hai.common.exception.ErrorCode;
|
|
import com.hai.common.exception.ErrorHelp;
|
|
import com.hai.common.exception.SysCode;
|
|
import com.hai.common.utils.CoordCommonUtil;
|
|
import com.hai.common.utils.PageUtil;
|
|
import com.hai.common.utils.ResponseMsgUtil;
|
|
import com.hai.config.CommonSysConst;
|
|
import com.hai.config.TuanYouConfig;
|
|
import com.hai.dao.HighGasOrderPushMapper;
|
|
import com.hai.entity.HighGasDiscountOilPrice;
|
|
import com.hai.entity.HighGasOrderPush;
|
|
import com.hai.entity.HighOrder;
|
|
import com.hai.entity.SecRegion;
|
|
import com.hai.model.ResponseData;
|
|
import com.hai.service.CommonService;
|
|
import com.hai.service.HighGasDiscountOilPriceService;
|
|
import com.hai.service.HighGasOilPriceService;
|
|
import com.hai.service.HighOrderService;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import org.apache.commons.collections4.MapUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
@Controller
|
|
@RequestMapping(value = "/highGas")
|
|
@Api(value = "团油业务接口")
|
|
public class HighGasController {
|
|
|
|
private static Logger log = LoggerFactory.getLogger(HighGasController.class);
|
|
|
|
@Resource
|
|
private HighGasOilPriceService highGasOilPriceService;
|
|
|
|
@Resource
|
|
private HighOrderService highOrderService;
|
|
|
|
@Resource
|
|
private CommonService commonService;
|
|
|
|
@Resource
|
|
private HighGasDiscountOilPriceService highGasDiscountOilPriceService;
|
|
|
|
@Resource
|
|
private HighGasOrderPushMapper highGasOrderPushMapper;
|
|
|
|
@RequestMapping(value="/getGasStoreList",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "查询加油站列表")
|
|
public ResponseData getGasStoreList(@RequestParam(name = "storeName", required = false) String storeName,
|
|
@RequestParam(name = "distance", required = true) Integer distanceRecent,
|
|
@RequestParam(name = "regionId", required = true) Long regionId,
|
|
@RequestParam(name = "oilNoName", required = true) String oilNoName,
|
|
@RequestParam(name = "longitude", required = true) String longitude,
|
|
@RequestParam(name = "latitude", required = true) String latitude,
|
|
@RequestParam(name = "pageNum", required = true) Integer pageNum,
|
|
@RequestParam(name = "pageSize", required = true) Integer pageSize
|
|
) {
|
|
try {
|
|
if (StringUtils.isBlank(storeName)) {
|
|
storeName = null;
|
|
}
|
|
SecRegion region = commonService.getParentByRegion(regionId);
|
|
if (region != null) {
|
|
List<Map<String, Object>> storeList = highGasOilPriceService.getStoreListByOilNo(storeName,region.getRegionId(), oilNoName);
|
|
for (Map<String, Object> store : storeList) {
|
|
double distance = CoordCommonUtil.getDistance(Double.valueOf(store.get("latitude").toString()), Double.valueOf(store.get("longitude").toString()), Double.valueOf(latitude), Double.valueOf(longitude));
|
|
store.put("distance", Math.round(distance/100d)/10d);
|
|
}
|
|
List<Map<String, Object>> distance = storeList.stream().sorted(Comparator.comparingDouble(entry -> Double.valueOf(entry.get("distance").toString()))).collect(Collectors.toList());
|
|
Iterator<Map<String, Object>> iterator = distance.iterator();
|
|
while (iterator.hasNext()) {
|
|
if ((int)Math.round(Double.valueOf(iterator.next().get("distance").toString())) > distanceRecent.intValue()) {
|
|
iterator.remove();
|
|
}
|
|
}
|
|
|
|
PageInfo<Map<String, Object>> mapPageInfo = PageUtil.initPageInfoObj(pageNum, distance.size(), pageSize, new PageInfo<>(distance));
|
|
for (Map<String, Object> map : mapPageInfo.getList()) {
|
|
if (StringUtils.isNotBlank(MapUtils.getString(map, "oil_no"))) {
|
|
// 查询是否配置了优惠比例
|
|
HighGasDiscountOilPrice gasDiscountOilPrice = highGasDiscountOilPriceService.getDetailByOilNo(MapUtils.getString(map, "oil_no"));
|
|
if (gasDiscountOilPrice != null) {
|
|
// 优惠比例 / 100 = 最终优惠比例
|
|
BigDecimal priceRate = gasDiscountOilPrice.getPriceRate().divide(new BigDecimal("100").setScale(2, BigDecimal.ROUND_DOWN));
|
|
// 油品国标价 * 最终优惠比例
|
|
map.put("price_vip", new BigDecimal(MapUtils.getString(map, "price_official")).multiply(priceRate).setScale(2, BigDecimal.ROUND_DOWN));
|
|
}
|
|
}
|
|
}
|
|
return ResponseMsgUtil.success(mapPageInfo);
|
|
}
|
|
return ResponseMsgUtil.success(new PageInfo<>());
|
|
} catch (Exception e) {
|
|
log.error("HighGasController -> getGasDetailByStoreKey() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value="/getGasDetailByStoreKey",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "根据门店key 查询")
|
|
public ResponseData getGasDetailByStoreKey(@RequestParam(name = "storeKey", required = true) String storeKey,
|
|
@RequestParam(name = "longitude", required = true) String longitude,
|
|
@RequestParam(name = "latitude", required = true) String latitude) {
|
|
try {
|
|
|
|
JSONObject jsonObject = TuanYouConfig.queryGasInfoByGasId(storeKey);
|
|
if (jsonObject != null && jsonObject.getString("code").equals("200")) {
|
|
JSONObject result = jsonObject.getJSONObject("result");
|
|
|
|
// 原始油品价格
|
|
JSONArray originalOilPriceList = result.getJSONArray("oilPriceList");
|
|
// 新油品价格
|
|
JSONArray newOilPriceList = new JSONArray();
|
|
|
|
// 处理油品价格
|
|
for (Object oilPriceObject : originalOilPriceList) {
|
|
JSONObject price = JSON.parseObject(JSONObject.toJSONString(oilPriceObject), JSONObject.class);
|
|
// 查询是否配置了优惠比例
|
|
HighGasDiscountOilPrice gasDiscountOilPrice = highGasDiscountOilPriceService.getDetailByOilNo(price.getString("oilNo"));
|
|
if (gasDiscountOilPrice != null) {
|
|
// 优惠比例 / 100 = 最终优惠比例
|
|
BigDecimal priceRate = gasDiscountOilPrice.getPriceRate().divide(new BigDecimal("100").setScale(2, BigDecimal.ROUND_DOWN));
|
|
// 油品国标价 * 最终优惠比例
|
|
price.put("priceVip", price.getBigDecimal("priceOfficial").multiply(priceRate).setScale(2, BigDecimal.ROUND_DOWN));
|
|
}
|
|
newOilPriceList.add(price);
|
|
}
|
|
result.put("oilPriceList", newOilPriceList);
|
|
|
|
double distance = CoordCommonUtil.getDistance(Double.valueOf(result.get("gasAddressLatitude").toString()), Double.valueOf(result.get("gasAddressLongitude").toString()), Double.valueOf(latitude), Double.valueOf(longitude));
|
|
result.put("distance", Math.round(distance/100d)/10d);
|
|
return ResponseMsgUtil.success(jsonObject.get("result"));
|
|
}
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
|
|
|
|
} catch (Exception e) {
|
|
log.error("HighGasController -> getGasDetailByStoreKey() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
/* @RequestMapping(value="/getGasPriceDetail",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "根据门店key和油号 查询油价")
|
|
public ResponseData getGasPriceDetail(@RequestParam(name = "storeKey", required = true) String storeKey,
|
|
@RequestParam(name = "oilNo", required = true) String oilNo) {
|
|
try {
|
|
|
|
JSONObject jsonObject = TuanYouConfig.queryCompanyPriceDetail(storeKey,oilNo);
|
|
if (jsonObject != null && jsonObject.getString("code").equals("200")) {
|
|
if(jsonObject.getJSONArray("result").size() == 0) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未获取到价格信息");
|
|
}
|
|
return ResponseMsgUtil.success(jsonObject);
|
|
}
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未获取到价格信息");
|
|
|
|
} catch (Exception e) {
|
|
log.error("HighGasController -> getGasPriceDetail() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}*/
|
|
|
|
@RequestMapping(value="/refuelingOrderRefund",method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ApiOperation(value = "订单退款")
|
|
public ResponseData refuelingOrderRefund(@RequestBody JSONObject body) {
|
|
try {
|
|
|
|
if(body == null && body.getLong("orderId") == null && StringUtils.isBlank(body.getString("refundContent"))) {
|
|
log.error("HighOrderController --> refuelingOrderRefund() error!", "参数错误");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
|
|
}
|
|
|
|
HighOrder order = highOrderService.getOrderById(body.getLong("orderId"));
|
|
if(order == null) {
|
|
log.error("HighOrderController --> refuelingOrderRefund() error!", "未找到订单信息");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到订单信息");
|
|
}
|
|
// 订单状态:1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消 6.退款中 7.拒绝退款
|
|
if (order.getOrderStatus() != 2) {
|
|
log.error("HighOrderController --> refuelingOrderRefund() error!", "提交退款审核失败,订单不处于已支付");
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "提交退款审核失败,订单不处于已支付");
|
|
}
|
|
|
|
JSONObject object = TuanYouConfig.refuelingOrderRefund(order.getMemPhone(), order.getOrderNo(), body.getString("refundContent"));
|
|
if (object == null || !object.getString("code").equals("200")) {
|
|
log.error("HighOrderController --> refuelingOrderRefund() error!", "提交退款审核失败," + object.getString("message"));
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "提交退款审核失败," + object.getString("message"));
|
|
}
|
|
|
|
order.setOrderStatus(6);
|
|
highOrderService.updateOrderDetail(order);
|
|
return ResponseMsgUtil.success("退款审核中");
|
|
|
|
} catch (Exception e) {
|
|
log.error("HighGasController -> refuelingOrderRefund() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
@RequestMapping(value="/refuelingOrderPush",method = RequestMethod.GET)
|
|
@ResponseBody
|
|
@ApiOperation(value = "手动推送订单")
|
|
public ResponseData refuelingOrderPush() {
|
|
try {
|
|
|
|
// {"app_key":"208241666939552","gunNo":"1","refuelingAmount":"1.02","thirdSerialNo":"HF2021062716143174807","sign":"83c7e8f70b984a04b937b28b8652aded","driverPhone":"15583658692","gasId":"CS000116587","priceVip":"7.31","oilNo":"90","timestamp":1624781755439,"priceGun":"7.31"}"
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
map.put("gasId", "CS000116587");
|
|
map.put("oilNo", "92");
|
|
map.put("gunNo", 2);
|
|
BigDecimal priceGun = new BigDecimal("7.50");
|
|
BigDecimal priceVip = new BigDecimal("7.50");
|
|
// BigDecimal priceGun = new BigDecimal("5.58");
|
|
// BigDecimal priceVip = new BigDecimal("5.40");
|
|
map.put("priceGun", priceGun); // 枪单价
|
|
map.put("priceVip", priceVip); // 优惠价
|
|
map.put("driverPhone", "18581170527");
|
|
map.put("thirdSerialNo", "HF2021063009483541009");
|
|
BigDecimal refuelingAmount = new BigDecimal("1").divide(priceGun,10,BigDecimal.ROUND_DOWN).multiply(priceVip).setScale(2,BigDecimal.ROUND_HALF_UP);
|
|
map.put("refuelingAmount", refuelingAmount);
|
|
/*JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(map);
|
|
if (orderPushObject == null || !orderPushObject.getString("code").equals("200")) {
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "提交订单,出现了未知错误");
|
|
}
|
|
JSONObject result = orderPushObject.getJSONObject("result");*/
|
|
//return ResponseMsgUtil.success(TuanYouConfig.refuelingOrderPush(map));
|
|
JSONObject orderPushObject = TuanYouConfig.refuelingOrderPush(map);
|
|
// 推送团油订单记录
|
|
HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
|
|
highGasOrderPush.setCreateTime(new Date());
|
|
highGasOrderPush.setCode(orderPushObject.getString("code"));
|
|
highGasOrderPush.setRequestContent(JSONObject.toJSONString(map));
|
|
highGasOrderPush.setReturnContent(orderPushObject.toJSONString());
|
|
highGasOrderPushMapper.insert(highGasOrderPush);
|
|
|
|
if (orderPushObject != null && orderPushObject.getString("code").equals("200")) {
|
|
return ResponseMsgUtil.success(orderPushObject.getJSONObject("result").getString("orderNo"));
|
|
}
|
|
return ResponseMsgUtil.success(map);
|
|
|
|
|
|
} catch (Exception e) {
|
|
log.error("HighGasController -> refuelingOrderPush() error!",e);
|
|
return ResponseMsgUtil.exception(e);
|
|
}
|
|
}
|
|
|
|
}
|
|
|