From 7b477828acb81c542b34dc603511bf6bcbe88ca5 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期六, 12 十月 2024 17:00:08 +0800
Subject: [PATCH] 修改bug
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java | 14 ++
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java | 265 ++++++++++++++++++++-----------------------
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java | 35 +++++
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java | 6 +
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java | 8 +
5 files changed, 185 insertions(+), 143 deletions(-)
diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java
index 67b6a52..d00fb80 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserFallbackFactory.java
@@ -85,6 +85,12 @@
public R<TAppUserAddress> getAddressById(Long id) {
return R.fail("通过地址id `查询用户地址失败:"+throwable.getMessage());
}
+
+
+ @Override
+ public R<String> getWXToken() {
+ return R.fail("获取微信token失败:" + throwable.getMessage());
+ }
};
}
}
diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
index 0f42ada..1646c54 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
@@ -85,4 +85,12 @@
@PostMapping(value = "/t-app-user/user/give/vip")
public R giveVip(@RequestBody GiveVipDto giveVipDto);
+
+
+ /**
+ * 获取微信token
+ * @return
+ */
+ @PostMapping("/wxLogin/getWXToken")
+ R<String> getWXToken();
}
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
index 4d5e00f..43741a2 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/WxLoginController.java
@@ -15,6 +15,7 @@
import com.ruoyi.account.wx.pojo.AppletUserEncrypteData;
import com.ruoyi.account.wx.tools.WxAppletTools;
import com.ruoyi.account.wx.tools.WxUtils;
+import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.FileUploadUtils;
import com.ruoyi.common.core.utils.StringUtils;
@@ -162,5 +163,16 @@
}
return AjaxResult.success();
}
-
+
+
+ /**
+ * 获取微信token
+ * @return
+ */
+ @PostMapping("/getWXToken")
+ public R<String> getWXToken(){
+ WxAppletTools appletTools = new WxAppletTools(wxRestTemplate, wxConfig);
+ String accessToken = appletTools.getAccessToken("");
+ return R.ok(accessToken);
+ }
}
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
index a0b4ccd..d88a463 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TChargingOrderServiceImpl.java
@@ -679,7 +679,7 @@
if(null != preChargeCheck1){
preChargeCheck1.setElectronicLockLock(true);
preChargeCheck1.setInsulationTesting(true);
- preChargeCheck1.setSecureConnectionDetection(preChargeCheck1.getSecureConnectionDetection());
+ preChargeCheck1.setSecureConnectionDetection(securityDetection.getSecure_connection() == 1);
preChargeCheck1.setStartupSuccess(1);
redisService.setCacheObject("AQJC_" + chargingOrder.getChargingGunId(), preChargeCheck1, 24L, TimeUnit.HOURS);
}
@@ -773,8 +773,7 @@
if(null != preChargeCheck1){
preChargeCheck1.setElectronicLockLock(true);
preChargeCheck1.setInsulationTesting(true);
- preChargeCheck1.setSecureConnectionDetection(preChargeCheck1.getSecureConnectionDetection());
- preChargeCheck1.setStartupSuccess(1);
+ preChargeCheck1.setSecureConnectionDetection(securityDetection.getSecure_connection() == 1);
redisService.setCacheObject("AQJC_" + chargingGun.getId(), preChargeCheck1, 24L, TimeUnit.HOURS);
}
}
@@ -796,7 +795,6 @@
if(null != preChargeCheck1){
preChargeCheck1.setElectronicLockLock(true);
preChargeCheck1.setInsulationTesting(true);
- preChargeCheck1.setSecureConnectionDetection(preChargeCheck1.getSecureConnectionDetection());
preChargeCheck1.setStartupSuccess(1);
}
if(0 == startup_result){
@@ -910,7 +908,7 @@
public ChargingDetails getChargingDetails(Integer id) {
Long userId = tokenService.getLoginUserApplet().getUserId();
TChargingOrder one = this.getOne(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, userId).eq(TChargingOrder::getChargingGunId, id)
- .in(TChargingOrder::getStatus, Arrays.asList(1, 2, 3)).eq(TChargingOrder::getRechargePaymentStatus, 2).eq(TChargingOrder::getDelFlag, 0));
+ .eq(TChargingOrder::getRechargePaymentStatus, 2).eq(TChargingOrder::getDelFlag, 0).orderByDesc(TChargingOrder::getEndTime).last(" limit 0, 1"));
if(null == one){
return null;
}
@@ -967,7 +965,93 @@
chargingOrder.setStatus(4);
chargingOrder.setEndMode(1);
this.updateById(chargingOrder);
+ //计算用户标签
+ editUserTag(chargingOrder);
+ //用户推荐奖励
+ referralReward(chargingOrder);
+ //计算费用,处理退款
+ endCharge(chargingOrder);
+ TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData();
+ // 将枪状态重置为空闲
+ chargingGun.setStatus(2);
+ chargingGunClient.updateChargingGunById(chargingGun);
+ String code1 = chargingOrder.getCode();
+
+ //异步线程处理停机
+ ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1);
+ cachedThreadPool.execute(()->{
+ //调用硬件停止充电,停止成功后开始计算费用退款
+ TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingOrder.getChargingPileId()).getData();
+ PlatformStopCharging platformStopCharging = new PlatformStopCharging();
+ platformStopCharging.setCharging_pile_code(chargingPile.getCode());
+ platformStopCharging.setCharging_gun_code(chargingGun.getCode());
+ sendMessageClient.platformStopCharging(platformStopCharging);
+ log.error(code1 + ":-------------------远程停止充电请求-------------------");
+ log.error(platformStopCharging.toString());
+ //开始查询停机应答,成功后开始计费费用
+ for (int i = 0; i < 60; i++) {
+ TChargingOrder chargingOrder1 = this.getById(id);
+ if(chargingOrder1.getStatus() != 3){
+ break;
+ }
+ GetPlatformStopChargingReply query = new GetPlatformStopChargingReply();
+ query.setCharging_gun_code(chargingGun.getCode());
+ query.setCharging_pile_code(chargingPile.getCode());
+ query.setEnd_time(chargingOrder.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
+ PlatformStopChargingReply reply = platformStopChargingReplyClient.getPlatformStopChargingReply(query).getData();
+ log.error(code1 + ":-------------------查询远程停止充电应答-------------------");
+ if(null == reply){
+ log.error(code1 + ":-------------------远程停止充电应答无数据-------------------");
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ continue;
+ }
+ log.error(reply.toString());
+
+ if(0 == reply.getStop_result()){
+ String failure_cause = "";
+ switch (reply.getFailure_cause()){
+ case 0:
+ failure_cause = "无";
+ break;
+ case 1:
+ failure_cause = "设备编号不匹配";
+ break;
+ case 2:
+ failure_cause = "枪未处于充电状态";
+ break;
+ case 3:
+ failure_cause = "其他";
+ break;
+ }
+ log.error(code1 + ":停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ continue;
+ }
+ log.error(code1 + ":-------------------远程停止充电请求成功-------------------");
+ break;
+ }
+
+ chargingOrder.setStatus(5);
+ this.updateById(chargingOrder);
+ });
+ return AjaxResult.success();
+ }
+
+
+ /**
+ * 结束充电后处理用户标签数据
+ * @param chargingOrder
+ */
+ public void editUserTag(TChargingOrder chargingOrder){
//处理用户标签数据
List<TUserTag> data = userTagClient.getAllUserTag().getData();
//累计充电次数
@@ -1024,79 +1108,14 @@
}
}
}
- String code1 = chargingOrder.getCode();
-
- //异步线程处理停机
- ExecutorService cachedThreadPool = Executors.newFixedThreadPool(1);
- cachedThreadPool.execute(()->{
- //调用硬件停止充电,停止成功后开始计算费用退款
- TChargingPile chargingPile = chargingPileClient.getChargingPileById(chargingOrder.getChargingPileId()).getData();
- TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData();
- PlatformStopCharging platformStopCharging = new PlatformStopCharging();
- platformStopCharging.setCharging_pile_code(chargingPile.getCode());
- platformStopCharging.setCharging_gun_code(chargingGun.getCode());
- sendMessageClient.platformStopCharging(platformStopCharging);
- log.error(code1 + ":-------------------远程停止充电请求-------------------");
- log.error(platformStopCharging.toString());
- //开始查询停机应答,成功后开始计费费用
- for (int i = 0; i < 60; i++) {
- GetPlatformStopChargingReply query = new GetPlatformStopChargingReply();
- query.setCharging_gun_code(chargingGun.getCode());
- query.setCharging_pile_code(chargingPile.getCode());
- query.setEnd_time(chargingOrder.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
- PlatformStopChargingReply reply = platformStopChargingReplyClient.getPlatformStopChargingReply(query).getData();
- log.error(code1 + ":-------------------查询远程停止充电应答-------------------");
- if(null == reply){
- log.error(code1 + ":-------------------远程停止充电应答无数据-------------------");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- continue;
- }
- log.error(reply.toString());
- TChargingOrder chargingOrder1 = this.getById(id);
- if(chargingOrder1.getStatus() != 3){
- break;
- }
-
- if(0 == reply.getStop_result()){
- String failure_cause = "";
- switch (reply.getFailure_cause()){
- case 0:
- failure_cause = "无";
- break;
- case 1:
- failure_cause = "设备编号不匹配";
- break;
- case 2:
- failure_cause = "枪未处于充电状态";
- break;
- case 3:
- failure_cause = "其他";
- break;
- }
- log.error(code1 + ":停机失败:订单号:{},失败原因:{}", chargingOrder.getCode(), failure_cause);
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- continue;
- }
-
- // 将枪状态重置为空闲
- chargingGun.setStatus(2);
- chargingGunClient.updateChargingGunById(chargingGun);
- //计算费用,处理退款
- endCharge(chargingOrder);
- log.error(code1 + ":-------------------远程停止充电请求成功-------------------");
- break;
- }
- });
-
-
+ }
+
+
+ /**
+ * 推荐奖励(被推荐首单奖励)
+ * @param chargingOrder
+ */
+ public void referralReward(TChargingOrder chargingOrder){
//处理推荐奖励(被推荐首单奖励)
TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
long count = this.count(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, chargingOrder.getAppUserId())
@@ -1140,14 +1159,12 @@
appUserIntegralChange.setHistoricalIntegral(appUser1.getPoints());
appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1);
appUserIntegralChange.setCreateTime(LocalDateTime.now());
- appUserIntegralChange.setOrderCode(code1);
+ appUserIntegralChange.setOrderCode(chargingOrder.getCode());
appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
-
+
appUser1.setPoints(appUser1.getPoints() + num1);
appUserClient.updateAppUser(appUser1);
}
-
- return AjaxResult.success();
}
@@ -1167,6 +1184,21 @@
if(null != order && order.getStatus() != 3){
return;
}
+
+ order.setEndTime(LocalDateTime.now());
+ order.setStatus(5);
+ order.setEndMode(1);
+ this.updateById(order);
+ //计算用户标签
+ editUserTag(order);
+ //用户推荐奖励
+ referralReward(order);
+ //计算费用,处理退款
+ endCharge(order);
+ // 将枪状态重置为空闲
+ chargingGun.setStatus(2);
+ chargingGunClient.updateChargingGunById(chargingGun);
+
String code1 = order.getCode();
if(0 == platformStopChargingReply.getStop_result()){
String failure_cause = "";
@@ -1185,14 +1217,7 @@
break;
}
log.error(code1 + ":停机失败:订单号:{},失败原因:{}", order.getCode(), failure_cause);
- return;
}
-
- // 将枪状态重置为空闲
- chargingGun.setStatus(2);
- chargingGunClient.updateChargingGunById(chargingGun);
- //计算费用,处理退款
- endCharge(order);
}
@@ -1946,61 +1971,19 @@
}
chargingOrder.setStatus(5);
chargingOrder.setEndMode(endMode);
+ chargingOrder.setEndTime(LocalDateTime.now());
this.updateById(chargingOrder);
-
+ // 将枪状态重置为空闲
+ TChargingGun chargingGun = chargingGunClient.getChargingGunById(chargingOrder.getChargingGunId()).getData();
+ chargingGun.setStatus(2);
+ chargingGunClient.updateChargingGunById(chargingGun);
+
+ //计算用户标签
+ editUserTag(chargingOrder);
+ //用户推荐奖励
+ referralReward(chargingOrder);
//计算费用,处理退款
endCharge(chargingOrder);
-
- //处理推荐奖励(被推荐首单奖励)
- TAppUser appUser = appUserClient.getUserById(chargingOrder.getAppUserId()).getData();
- long count = this.count(new LambdaQueryWrapper<TChargingOrder>().eq(TChargingOrder::getAppUserId, chargingOrder.getAppUserId())
- .eq(TChargingOrder::getStatus, 5).isNull(TChargingOrder::getEndMode).eq(TChargingOrder::getDelFlag, 0));
- if(null != appUser.getInviteUserId() && 1 == count){
- TIntegralRule integralRule = integralRuleClient.getSet().getData();
- String inviteUsersToEarnPoints = integralRule.getInviteUsersToEarnPoints();
- JSONObject jsonObject = JSON.parseObject(inviteUsersToEarnPoints);
- Integer num1 = jsonObject.getInteger("num1");
-
- TAppUser appUser1 = appUserClient.getUserById(appUser.getInviteUserId()).getData();
- if(null != appUser1.getVipId()){
- TVip vip = vipClient.getInfo1(appUser1.getVipId()).getData();
- Integer doubleIntegration = vip.getDoubleIntegration();
- //双倍积分
- if(1 == doubleIntegration){
- num1 *= 2;
- }
- }
-
- GetInviteUser query = new GetInviteUser();
- query.setAppUserId(appUser1.getId());
- query.setBeInvitedAppUserId(chargingOrder.getAppUserId());
- TInviteUser inviteUser = inviteUserClient.getInviteUser(query).getData();
- if(null == inviteUser){
- inviteUser = new TInviteUser();
- inviteUser.setAppUserId(appUser1.getId());
- inviteUser.setBeInvitedAppUserId(chargingOrder.getAppUserId());
- inviteUser.setAward(num1);
- inviteUser.setCreateTime(LocalDateTime.now());
- inviteUserClient.saveInviteUser(inviteUser);
- }else{
- inviteUser.setAward(num1);
- inviteUserClient.updateInviteUser(inviteUser);
- }
- TAppUserIntegralChange appUserIntegralChange = new TAppUserIntegralChange();
- String code = Double.valueOf(Math.random() * 1000).intValue() + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
- appUserIntegralChange.setCode(code);
- appUserIntegralChange.setAppUserId(appUser1.getId());
- appUserIntegralChange.setChangeType(5);
- appUserIntegralChange.setHistoricalIntegral(appUser1.getPoints());
- appUserIntegralChange.setCurrentIntegral(appUser1.getPoints() + num1);
- appUserIntegralChange.setCreateTime(LocalDateTime.now());
- appUserIntegralChange.setOrderCode(chargingOrder.getCode());
- appUserIntegralChangeClient.addAppUserIntegralChange(appUserIntegralChange);
-
- appUser1.setPoints(appUser1.getPoints() + num1);
- appUserClient.updateAppUser(appUser1);
- }
-
}
/**
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
index eef9031..6823260 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/TOrderEvaluateServiceImpl.java
@@ -2,6 +2,8 @@
import cn.hutool.db.DaoTemplate;
import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONArray;
+import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -17,6 +19,7 @@
import com.ruoyi.chargingPile.api.model.Site;
import com.ruoyi.chargingPile.api.vo.TAccountingStrategyVO;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.utils.HttpUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
@@ -267,6 +270,37 @@
TChargingOrder chargingOrder = chargingOrderService.getById(query.getOrderId());
orderEvaluate.setAppUserCarId(chargingOrder.getAppUserCarId());
}
+ TAppUser appUser = appUserClient.getUserById(userid).getData();
+
+ //检测敏感词
+ String content = orderEvaluate.getContent();
+ String token = appUserClient.getWXToken().getData();
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("content", content);
+ jsonObject.put("version", 2);
+ jsonObject.put("scene", 2);
+ jsonObject.put("openid", appUser.getWxOpenid());
+ String post = HttpUtils.post("https://api.weixin.qq.com/wxa/msg_sec_check?access_token=" + token, jsonObject.toString());
+ JSONObject object = JSONObject.parseObject(post);
+ Integer errcode = object.getInteger("errcode");
+ if(0 != errcode){
+ throw new RuntimeException(object.getString("errmsg"));
+ }
+ JSONArray detail = object.getJSONArray("detail");
+ for (int i = 0; i < detail.size(); i++) {
+ JSONObject jsonObject1 = detail.getJSONObject(i);
+ Integer errcode1 = jsonObject1.getInteger("errcode");
+ if(0 == errcode1){
+ String suggest = jsonObject1.getString("suggest");
+ Integer label = jsonObject1.getInteger("label");
+ String keyword = jsonObject1.getString("keyword");
+ Integer prob = jsonObject1.getInteger("prob");
+ if(("risky".equals(suggest) || "review".equals(suggest)) && 100 != label && StringUtils.isNotEmpty(keyword) && 80 <= prob){
+ content = content.replaceAll(keyword, "***");
+ }
+ }
+ }
+ orderEvaluate.setContent(content);
this.save(orderEvaluate);
List<Integer> tagIds = query.getTagIds();
@@ -284,7 +318,6 @@
//积分
Integer num1 = JSON.parseObject(credit).getInteger("num1");
if(null != num1 && 0 < num1){
- TAppUser appUser = appUserClient.getUserById(userid).getData();
if(null != appUser.getVipId()){
TVip vip = vipClient.getInfo1(appUser.getVipId()).getData();
Integer doubleIntegration = vip.getDoubleIntegration();
--
Gitblit v1.7.1