diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java index 81a574a..cfc72b3 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java @@ -251,7 +251,7 @@ public class AppController extends BaseController @GetMapping("/fee/list") public AjaxResult feeList(EtFeeRule etFeeRule) { - List list = etFeeRuleService.selectRuleInfoListByModelId(etFeeRule.getModelId()); + List list = etFeeRuleService.selectEtFeeRuleListByAreaId(etFeeRule.getAreaId()); return success(list); } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtLocationLogController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtLocationLogController.java new file mode 100644 index 0000000..f996005 --- /dev/null +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtLocationLogController.java @@ -0,0 +1,105 @@ +package com.ruoyi.web.controller.system; + +import java.util.List; +import javax.servlet.http.HttpServletResponse; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import com.ruoyi.common.annotation.Log; +import com.ruoyi.common.core.controller.BaseController; +import com.ruoyi.common.core.domain.AjaxResult; +import com.ruoyi.common.enums.BusinessType; +import com.ruoyi.system.domain.EtLocationLog; +import com.ruoyi.system.service.IEtLocationLogService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 定位日志Controller + * + * @author ruoyi + * @date 2024-09-12 + */ +@RestController +@RequestMapping("/system/locationLog") +public class EtLocationLogController extends BaseController +{ + @Autowired + private IEtLocationLogService etLocationLogService; + + /** + * 查询定位日志列表 + */ + @PreAuthorize("@ss.hasPermi('system:locationLog:list')") + @GetMapping("/list") + public TableDataInfo list(EtLocationLog etLocationLog) + { + startPage(); + List list = etLocationLogService.selectEtLocationLogList(etLocationLog); + etLocationLogService.analytic(list); + return getDataTable(list); + } + + /** + * 导出定位日志列表 + */ + @PreAuthorize("@ss.hasPermi('system:locationLog:export')") + @Log(title = "定位日志", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, EtLocationLog etLocationLog) + { + List list = etLocationLogService.selectEtLocationLogList(etLocationLog); + ExcelUtil util = new ExcelUtil(EtLocationLog.class); + util.exportExcel(response, list, "定位日志数据"); + } + + /** + * 获取定位日志详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:locationLog:query')") + @GetMapping(value = "/{locationId}") + public AjaxResult getInfo(@PathVariable("locationId") Long locationId) + { + return success(etLocationLogService.selectEtLocationLogByLocationId(locationId)); + } + + /** + * 新增定位日志 + */ + @PreAuthorize("@ss.hasPermi('system:locationLog:add')") + @Log(title = "定位日志", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody EtLocationLog etLocationLog) + { + return toAjax(etLocationLogService.insertEtLocationLog(etLocationLog)); + } + + /** + * 修改定位日志 + */ + @PreAuthorize("@ss.hasPermi('system:locationLog:edit')") + @Log(title = "定位日志", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody EtLocationLog etLocationLog) + { + return toAjax(etLocationLogService.updateEtLocationLog(etLocationLog)); + } + + /** + * 删除定位日志 + */ + @PreAuthorize("@ss.hasPermi('system:locationLog:remove')") + @Log(title = "定位日志", businessType = BusinessType.DELETE) + @DeleteMapping("/{locationIds}") + public AjaxResult remove(@PathVariable Long[] locationIds) + { + return toAjax(etLocationLogService.deleteEtLocationLogByLocationIds(locationIds)); + } +} diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/LocationVo.java b/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/LocationVo.java index 468aa3f..91d3d40 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/LocationVo.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/LocationVo.java @@ -9,7 +9,7 @@ public class LocationVo { private String lat;//纬度 - private Integer status;//电动车状态 0断电,1上电运行 2轮动抱死 3超出区域断电(远程下发了qlose) + private Integer status;//电动车状态 0断电,1上电运行 2轮动抱死 3超出区域断电(远程下发了qlose) 解析参数 private Integer bat;//电池电压 "bat":571 ==> 57.1V diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java b/electripper-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java index f5d8e5b..94be35f 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/wx/AccessTokenUtil.java @@ -44,4 +44,25 @@ public class AccessTokenUtil { Long expirationTime = tokenExpirationTimes.get(cacheKey); return expirationTime == null || System.currentTimeMillis() > expirationTime; } + + /** + * 强制刷新token + * */ + @SneakyThrows + public static String getForceRefreshToken(String appid, String appsecret) { + String cacheKey = appid + ":" + appsecret; + log.info("强制获取token"); + WxMaService wxMaService = new WxMaServiceImpl(); + WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); + config.setAppid(appid); + config.setSecret(appsecret); + wxMaService.setWxMaConfig(config); + String accessToken = wxMaService.getAccessToken(true); + + // 更新缓存 + cachedTokens.put(cacheKey, accessToken); + tokenExpirationTimes.put(cacheKey, System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(3600L)); + + return accessToken; + } } diff --git a/electripper-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java b/electripper-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java index 6aaa231..acf9cf7 100644 --- a/electripper-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java +++ b/electripper-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java @@ -33,7 +33,7 @@ import com.ruoyi.system.domain.SysOperLog; /** * 操作日志记录处理 - * + * * @author ruoyi */ @Aspect @@ -54,6 +54,7 @@ public class LogAspect @Before(value = "@annotation(controllerLog)") public void boBefore(JoinPoint joinPoint, Log controllerLog) { + log.info("设置TIME_THREADLOCAL时间"); TIME_THREADLOCAL.set(System.currentTimeMillis()); } @@ -70,7 +71,7 @@ public class LogAspect /** * 拦截异常操作 - * + * * @param joinPoint 切点 * @param e 异常 */ @@ -117,8 +118,13 @@ public class LogAspect operLog.setRequestMethod(ServletUtils.getRequest().getMethod()); // 处理设置注解上的参数 getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult); - // 设置消耗时间 - operLog.setCostTime(System.currentTimeMillis() - TIME_THREADLOCAL.get()); + Long startTime = TIME_THREADLOCAL.get(); + if (startTime != null) { + operLog.setCostTime(System.currentTimeMillis() - startTime); + } else { + log.warn("TIME_THREADLOCAL为空,无法设置消耗时间。"); + operLog.setCostTime(0L); // 你可以设置为0或其他合适的默认值 + } // 保存数据库 AsyncManager.me().execute(AsyncFactory.recordOper(operLog)); } @@ -136,7 +142,7 @@ public class LogAspect /** * 获取注解中对方法的描述信息 用于Controller层注解 - * + * * @param log 日志 * @param operLog 操作日志 * @throws Exception @@ -164,7 +170,7 @@ public class LogAspect /** * 获取请求的参数,放到log中 - * + * * @param operLog 操作日志 * @throws Exception 异常 */ @@ -220,7 +226,7 @@ public class LogAspect /** * 判断是否需要过滤的对象。 - * + * * @param o 对象信息。 * @return 如果是需要过滤的对象,则返回true;否则返回false。 */ diff --git a/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index bfa26a3..b2e3999 100644 --- a/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/electripper-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -225,6 +225,12 @@ public class SysLoginService String post = HttpUtils.sendPost(url,jsonObject.toString()); JSONObject jsonObject1 = JSONObject.parseObject(post); + if(jsonObject1.getInteger("errcode")!=0){// 如果token无效则重新获取一次最新的token + token = AccessTokenUtil.getForceRefreshToken(dept.getAppid(), dept.getAppSecret()); + url = url+token; + post = HttpUtils.sendPost(url,jsonObject.toString()); + jsonObject1 = JSONObject.parseObject(post); + } String phoneInfo = jsonObject1.getString("phone_info"); WxMaPhoneNumberInfo wxMaPhoneNumberInfo = JSONObject.parseObject(phoneInfo, WxMaPhoneNumberInfo.class); if(StringUtils.isEmpty(wxMaPhoneNumberInfo.getPhoneNumber())){ diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtLocationLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtLocationLog.java index 23cb486..c85a2f4 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtLocationLog.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtLocationLog.java @@ -1,11 +1,8 @@ package com.ruoyi.system.domain; -import com.ruoyi.common.constant.ServiceConstants; -import lombok.Data; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.core.domain.BaseEntity; +import lombok.Data; import java.util.Date; @@ -50,4 +47,19 @@ public class EtLocationLog extends BaseEntity @Excel(name = "锁状态") private String lockStatus; + @Excel(name = "电动车状态") + private Integer status2;//电动车状态 0断电,1上电运行 2轮动抱死 3超出区域断电(远程下发了qlose) 解析参数 + + @Excel(name = "电池电压") + private Integer bat;//电池电压 "bat":571 ==> 57.1V + + @Excel(name = "信号强度") + private Integer csq;//信号强度 + + @Excel(name = "卫星数量") + private Integer s;//卫星数量 + + @Excel(name = "钥匙") + private Integer q;//钥匙 + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java index 75caac6..24c1e2f 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtModel.java @@ -61,6 +61,10 @@ public class EtModel extends BaseEntity @Excel(name = "骑行低电量提醒") private Integer lowBatteryReminder; + /** 骑行低电量提醒开关 */ + @Excel(name = "骑行低电量提醒开关") + private Boolean lowBatteryReminderSwitch; + /** 已投放车辆数 */ private Integer deviceNum; diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java index 050daf0..787e2ce 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOrder.java @@ -94,6 +94,10 @@ public class EtOrder extends BaseEntity @TableField(exist = false) private List etRefunds; + /** 总退款金额 */ + @TableField(exist = false) + private BigDecimal totalRefundFee; + /** 设备sn编码 */ @Excel(name = "设备sn编码") private String sn; @@ -348,4 +352,7 @@ public class EtOrder extends BaseEntity @Excel(name = "可退停车点外调度费退款") @TableField(exist = false) private BigDecimal refundableManageFee; + + @Excel(name = "描述") + private String description; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtLocationLogService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtLocationLogService.java index 156c77f..78534f4 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IEtLocationLogService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtLocationLogService.java @@ -5,15 +5,15 @@ import com.ruoyi.system.domain.EtLocationLog; /** * 定位日志Service接口 - * + * * @author ruoyi * @date 2024-08-20 */ -public interface IEtLocationLogService +public interface IEtLocationLogService { /** * 查询定位日志 - * + * * @param locationId 定位日志主键 * @return 定位日志 */ @@ -21,7 +21,7 @@ public interface IEtLocationLogService /** * 查询定位日志列表 - * + * * @param etLocationLog 定位日志 * @return 定位日志集合 */ @@ -29,7 +29,7 @@ public interface IEtLocationLogService /** * 新增定位日志 - * + * * @param etLocationLog 定位日志 * @return 结果 */ @@ -37,7 +37,7 @@ public interface IEtLocationLogService /** * 修改定位日志 - * + * * @param etLocationLog 定位日志 * @return 结果 */ @@ -45,7 +45,7 @@ public interface IEtLocationLogService /** * 批量删除定位日志 - * + * * @param locationIds 需要删除的定位日志主键集合 * @return 结果 */ @@ -53,9 +53,17 @@ public interface IEtLocationLogService /** * 删除定位日志信息 - * + * * @param locationId 定位日志主键 * @return 结果 */ public int deleteEtLocationLogByLocationId(Long locationId); + + /** + * 解析参数 + * + * @param list + * @return 结果 + */ + public List analytic(List list); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtLocationLogServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtLocationLogServiceImpl.java index d1c6117..5bffc97 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtLocationLogServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtLocationLogServiceImpl.java @@ -1,28 +1,32 @@ package com.ruoyi.system.service.impl; import java.util.List; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.ruoyi.common.utils.DateUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.ruoyi.system.mapper.EtLocationLogMapper; import com.ruoyi.system.domain.EtLocationLog; import com.ruoyi.system.service.IEtLocationLogService; +import javax.annotation.Resource; + /** * 定位日志Service业务层处理 - * + * * @author ruoyi * @date 2024-08-20 */ @Service -public class EtLocationLogServiceImpl implements IEtLocationLogService +public class EtLocationLogServiceImpl implements IEtLocationLogService { - @Autowired + @Resource private EtLocationLogMapper etLocationLogMapper; /** * 查询定位日志 - * + * * @param locationId 定位日志主键 * @return 定位日志 */ @@ -34,7 +38,7 @@ public class EtLocationLogServiceImpl implements IEtLocationLogService /** * 查询定位日志列表 - * + * * @param etLocationLog 定位日志 * @return 定位日志 */ @@ -46,7 +50,7 @@ public class EtLocationLogServiceImpl implements IEtLocationLogService /** * 新增定位日志 - * + * * @param etLocationLog 定位日志 * @return 结果 */ @@ -59,7 +63,7 @@ public class EtLocationLogServiceImpl implements IEtLocationLogService /** * 修改定位日志 - * + * * @param etLocationLog 定位日志 * @return 结果 */ @@ -71,7 +75,7 @@ public class EtLocationLogServiceImpl implements IEtLocationLogService /** * 批量删除定位日志 - * + * * @param locationIds 需要删除的定位日志主键 * @return 结果 */ @@ -83,7 +87,7 @@ public class EtLocationLogServiceImpl implements IEtLocationLogService /** * 删除定位日志信息 - * + * * @param locationId 定位日志主键 * @return 结果 */ @@ -92,4 +96,51 @@ public class EtLocationLogServiceImpl implements IEtLocationLogService { return etLocationLogMapper.deleteEtLocationLogByLocationId(locationId); } + + /** + * 解析参数 + * + * @param list + * @return 结果 + */ + @Override + public List analytic(List list) { + // 创建 ObjectMapper 实例用于解析 JSON + ObjectMapper objectMapper = new ObjectMapper(); + + for (EtLocationLog log : list) { + try { + // 解析 onenetMsg 字段中的 JSON 字符串 + JsonNode rootNode = objectMapper.readTree(log.getOnenetMsg()); + JsonNode valueNode = rootNode.path("value"); + + // 提取各个字段的值并填充到 EtLocationLog 对象中 + if (valueNode.has("status")) { + log.setStatus2(valueNode.get("status").asInt()); + } + if (valueNode.has("bat")) { + // 电池电压,例如 bat: 511 表示 51.1V + log.setBat(valueNode.get("bat").asInt()); + } + if (valueNode.has("csq")) { + // 信号强度 + log.setCsq(valueNode.get("csq").asInt()); + } + if (valueNode.has("s")) { + // 卫星数量 + log.setS(valueNode.get("s").asInt()); + } + if (valueNode.has("q")) { + // 钥匙状态 + log.setQ(valueNode.get("q").asInt()); + } + + } catch (Exception e) { + // 捕获并打印解析异常信息 + e.printStackTrace(); + } + } + return list; + } + } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java index 9b454c8..e3d7efb 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtModelServiceImpl.java @@ -1,8 +1,10 @@ package com.ruoyi.system.service.impl; import cn.hutool.core.util.ObjectUtil; +import com.alibaba.fastjson2.JSON; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.IotConstants; +import com.ruoyi.common.constant.ServiceConstants; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.utils.CommonUtil; @@ -10,10 +12,7 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.onenet.ResponseVo; import com.ruoyi.common.utils.onenet.Token; -import com.ruoyi.system.domain.AsDevice; -import com.ruoyi.system.domain.EtModel; -import com.ruoyi.system.domain.EtModelRule; -import com.ruoyi.system.domain.EtOperatingArea; +import com.ruoyi.system.domain.*; import com.ruoyi.system.mapper.AsDeviceMapper; import com.ruoyi.system.mapper.EtModelMapper; import com.ruoyi.system.mapper.EtModelRuleMapper; @@ -28,7 +27,12 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.io.UnsupportedEncodingException; +import java.security.InvalidKeyException; +import java.security.NoSuchAlgorithmException; import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; /** * 车辆型号Service业务层处理 @@ -55,6 +59,12 @@ public class EtModelServiceImpl implements IEtModelService @Resource private EtModelRuleMapper etModelRuleMapper; + @Resource + private AsDeviceMapper asDeviceMapper; + + @Autowired + private ScheduledExecutorService scheduledExecutorService; + /** * 查询车辆型号 @@ -128,6 +138,10 @@ public class EtModelServiceImpl implements IEtModelService etModelRuleMapper.insert(EtModelRule.builder().modelId(etModel.getModelId()).ruleId(ruleId).build()); } } + // Java报错:No appropriate protocol (protocol is disabled or cipher suites are inappropriate) + if(!etModel.getLowBatteryReminderSwitch()){// 提醒关闭时,发送低电压命令 为0 + asynchronousSendCommand(etModel.getModelId()); + } // // 发送设置低电压命令 // Integer lowBatteryReminder = etModel.getLowBatteryReminder(); @@ -174,6 +188,9 @@ public class EtModelServiceImpl implements IEtModelService } } } + if(!etModel.getLowBatteryReminderSwitch()){// 提醒关闭时,发送低电压命令 为0 + asynchronousSendCommand(etModel.getModelId()); + } // 发送设置低电压命令 // Integer lowBatteryReminder = etModel.getLowBatteryReminder(); // if(ObjectUtil.isNotNull(lowBatteryReminder) && lowBatteryReminder > 0){ @@ -194,6 +211,36 @@ public class EtModelServiceImpl implements IEtModelService return i; } + /** + * 异步发送低电压命令 + */ + private void asynchronousSendCommand(Long modelId) { + //开异步线程: + scheduledExecutorService.schedule(() -> { + AsDevice device = new AsDevice(); + device.setModelId(modelId); + List asDevices = asDeviceMapper.selectAsDeviceList(device); + for(AsDevice asDevice: asDevices){ + // 根据百分比计算提醒电压值 + String lowVoltageCommand = IotConstants.COMMAND_BAT + 0 + "@"; + log.info("发送低电压命令:" + lowVoltageCommand); + ResponseVo responseVo = null; + try { + responseVo = asDeviceService.sendCommandWithResp(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报",null); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (InvalidKeyException e) { + e.printStackTrace(); + } + if(responseVo.getCode()!=0){ + log.info("【还车关锁】设备【{}】远程关锁失败", asDevice.getMac()); + } + } + }, 0, TimeUnit.SECONDS); + } + /** * 批量删除车辆型号 * diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java index 9962f20..6748a78 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOrderServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.annotation.DataScope; import com.ruoyi.common.constant.Constants; import com.ruoyi.common.constant.IotConstants; @@ -141,6 +142,7 @@ public class EtOrderServiceImpl implements IEtOrderService AsDevice device = asDeviceMapper.selectAsDeviceBySn(order.getSn()); order.setDevice(device); EtFeeRule etFeeRule = etFeeRuleService.selectEtFeeRuleByRuleIdIncludeDelete(order.getRuleId()); + setDescription(order); String endTime; if(ObjectUtil.isNull(order.getReturnTime())){ endTime = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, DateUtils.getNowDate()); @@ -166,6 +168,24 @@ public class EtOrderServiceImpl implements IEtOrderService return order; } + private void setDescription(EtOrder order) { + StringBuilder sb = new StringBuilder(); + String ridingRuleJson = order.getRidingRuleJson(); + String unit = ""; + if(order.getRidingRule() != null && order.getRidingRule().equals("1")){ + StartingRuleVo startingRule = JSONObject.parseObject(ridingRuleJson, StartingRuleVo.class); + String rentalUnit = order.getRentalUnit(); + if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_MINUTES)){ + unit = "分钟"; + }else if(rentalUnit.equals(ServiceConstants.RENTAL_UNIT_HOURS)){ + unit = "小时"; + } + sb.append("起步价:"+startingRule.getStartingPrice()+"元(含"+startingRule.getStartingTime()+unit+"),"); + sb.append("超出价:"+startingRule.getTimeoutPrice()+"元/"+startingRule.getTimeoutTime()+unit); + } + order.setDescription(sb.toString()); + } + /** * 根据订单号查询订单 * @@ -310,14 +330,18 @@ public class EtOrderServiceImpl implements IEtOrderService } List etOrders = etOrderMapper.selectEtOrderList(etOrder); //如果查询押金则增加退款记录 - if(ServiceConstants.ORDER_TYPE_DEPOSIT.equals(etOrder.getType())){ - etOrders.forEach(etOrder1 -> { - List refund = etRefundService.selectEtRefundByOrderNo(etOrder1.getOrderNo()); - if(ObjectUtil.isNotNull(refund) && refund.size() > 0){ - etOrder1.setEtRefund(refund.get(0)); - } - }); - } + etOrders.forEach(etOrder1 -> { + List refunds = etRefundService.selectEtRefundByOrderNo(etOrder1.getOrderNo()); + if(ObjectUtil.isNotNull(refunds) && refunds.size() > 0){ + etOrder1.setEtRefund(refunds.get(0)); + etOrder1.setEtRefunds(refunds); + // 计算总的退款金额 + BigDecimal totalRefundFee = refunds.stream() + .map(EtRefund::getAmount) + .reduce(BigDecimal.ZERO, BigDecimal::add); + etOrder1.setTotalRefundFee(totalRefundFee); + } + }); return etOrders; } @@ -532,6 +556,7 @@ public class EtOrderServiceImpl implements IEtOrderService if(deposit.compareTo(ridingFee) <= 0){ afterDeductionFee = BigDecimal.ZERO; mark = "押金抵扣成功,骑行费【"+ridingFee+"】大于押金【"+deposit+"】"; + order.setPayFee(deposit);//实际支付金额等于押金 }else{ // 押金大于订单金额 扣除后 afterDeductionFee = deposit.subtract(ridingFee); @@ -1832,6 +1857,19 @@ public class EtOrderServiceImpl implements IEtOrderService if(ObjectUtil.isNotNull(etCoupon)){ order.setCoupon(etCoupon); } + // 骑行结束并且订单金额等于0,并且未支付 + if(ServiceConstants.ORDER_STATUS_RIDING_END.equals(order.getStatus()) && order.getTotalFee().compareTo(BigDecimal.ZERO) == 0 && order.getPaid().equals(ServiceConstants.ORDER_PAY_STATUS_NON_PAYMENT)){ + order.setPaid(ServiceConstants.ORDER_PAY_STATUS_PAID); + order.setPayTime(new Date()); + order.setPayType(ServiceConstants.PAY_TYPE_SYS); + order.setStatus(ServiceConstants.ORDER_STATUS_ORDER_END); + int updateEtOrder = etOrderMapper.updateEtOrder(order); + if(updateEtOrder == 0){ + throw new ServiceException("更新订单outTradeNo失败"); + }else { + log.info("【isInOrder接口】更新订单outTradeNo成功"); + } + } } return inOrder; } diff --git a/electripper-system/src/main/resources/mapper/system/EtModelMapper.xml b/electripper-system/src/main/resources/mapper/system/EtModelMapper.xml index 9d1171c..b71092b 100644 --- a/electripper-system/src/main/resources/mapper/system/EtModelMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtModelMapper.xml @@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -22,12 +23,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select model_id, model, brand, operator, area_id, full_voltage, low_voltage, full_endurance, low_battery_reminder, create_by, create_time, update_by, update_time, remark from et_model + select model_id, model, brand, operator, area_id, full_voltage, low_voltage, full_endurance, low_battery_reminder, low_battery_reminder_switch, create_by, create_time, update_by, update_time, remark from et_model select m.model_id, m.model, m.brand, m.operator, d.dept_name, m.full_voltage, m.low_voltage,m.area_id, - m.full_endurance, m.low_battery_reminder, m.create_by, m.create_time, + m.full_endurance, m.low_battery_reminder, m.low_battery_reminder_switch, m.create_by, m.create_time, m.update_by, m.update_time, m.remark from et_model m left join sys_dept d on d.dept_id = m.operator where m.model_id = #{modelId} @@ -64,6 +65,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" low_voltage, full_endurance, low_battery_reminder, + low_battery_reminder_switch, create_by, create_time, update_by, @@ -80,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{lowVoltage}, #{fullEndurance}, #{lowBatteryReminder}, + #{lowBatteryReminderSwitch}, #{createBy}, #{createTime}, #{updateBy}, @@ -99,6 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" low_voltage = #{lowVoltage}, full_endurance = #{fullEndurance}, low_battery_reminder = #{lowBatteryReminder}, + low_battery_reminder_switch = #{lowBatteryReminderSwitch}, create_by = #{createBy}, create_time = #{createTime}, update_by = #{updateBy},