From 91433732dca5476e0cd1c72e38747b223748bc61 Mon Sep 17 00:00:00 2001 From: 18650502300 <18650502300@163.com> Date: Mon, 15 Jul 2024 10:02:56 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=9C=A8=E7=BA=BF/=E7=A6=BB=E7=BA=BF?= =?UTF-8?q?=E6=97=A5=E5=BF=97=202.=E8=BF=98=E8=BD=A6=E5=AE=A1=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/app/AppVerifyController.java | 12 +- .../iot/receive/ReceiveController.java | 26 ++++- .../system/EtOnlineLogController.java | 104 ++++++++++++++++++ .../com/ruoyi/common/constant/HttpStatus.java | 8 ++ .../common/constant/ServiceConstants.java | 2 +- .../com/ruoyi/common/enums/BusinessType.java | 13 +++ .../ruoyi/common/utils/onenet/IotUtil.java | 2 + .../com/ruoyi/system/domain/EtCommandLog.java | 15 +++ .../com/ruoyi/system/domain/EtOnlineLog.java | 44 ++++++++ .../system/mapper/EtOnlineLogMapper.java | 61 ++++++++++ .../system/service/IAsDeviceService.java | 4 +- .../system/service/IEtOnlineLogService.java | 61 ++++++++++ .../service/impl/AsDeviceServiceImpl.java | 65 +++++++---- .../service/impl/EtModelServiceImpl.java | 4 +- .../service/impl/EtOnlineLogServiceImpl.java | 95 ++++++++++++++++ .../mapper/system/EtCommandLogMapper.xml | 20 +++- .../mapper/system/EtOnlineLogMapper.xml | 78 +++++++++++++ .../mapper/system/SysOperLogMapper.xml | 20 ++-- 18 files changed, 586 insertions(+), 48 deletions(-) create mode 100644 electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOnlineLogController.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/domain/EtOnlineLog.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/mapper/EtOnlineLogMapper.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/service/IEtOnlineLogService.java create mode 100644 electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOnlineLogServiceImpl.java create mode 100644 electripper-system/src/main/resources/mapper/system/EtOnlineLogMapper.xml diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java index b28e33f..ffca01a 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppVerifyController.java @@ -737,6 +737,7 @@ public class AppVerifyController extends BaseController /** * 实名认证 */ + @Log(title = "实名认证", businessType = BusinessType.AUTHENTICATION) @GetMapping("/user/authentication") public AjaxResult partnerBillList(AuthenticationVo authenticationVo) { @@ -781,6 +782,7 @@ public class AppVerifyController extends BaseController /** * sn和mac号绑定 */ + @Log(title = "设备绑定", businessType = BusinessType.BAND) @PostMapping("/band") public AjaxResult bandSn(String sn,String mac) { @@ -846,11 +848,12 @@ public class AppVerifyController extends BaseController public AjaxResult getAreaList() { AsUser asUser = getLoginUser().getAsUser(); - logger.info("获取到当前app登录用户:【{}】", JSON.toJSON(asUser)); - if(ObjectUtil.isNull(asUser.getSysUserId())){ - throw new RuntimeException("用户【"+asUser.getUserName()+"】未绑定系统用户"); + AsUser asUser1 = asUserMapper.selectUserById(asUser.getUserId()); + logger.info("获取到当前app登录用户:【{}】", JSON.toJSON(asUser1)); + if(ObjectUtil.isNull(asUser1.getSysUserId())){ + throw new RuntimeException("用户【"+asUser1.getUserName()+"】未绑定系统用户"); } - SysUser sysUser = userService.selectUserById(asUser.getSysUserId()); + SysUser sysUser = userService.selectUserById(asUser1.getSysUserId()); Long deptId; if(sysUser.isAdmin()){ deptId = null; @@ -899,6 +902,7 @@ public class AppVerifyController extends BaseController /** * 重启设备 */ + @Log(title = "重启设备", businessType = BusinessType.REBOOT) @PostMapping("/device/reboot") public AjaxResult reboot(String sn) { diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java index ed72641..2b36933 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java @@ -74,6 +74,9 @@ public class ReceiveController { @Autowired private ScheduledExecutorService scheduledExecutorService; + @Autowired + private IEtOnlineLogService etOnlineLogService; + private final Object lock = new Object(); @@ -216,7 +219,7 @@ public class ReceiveController { String noRidingOutage = area.getNoRidingOutage(); if (noRidingOutage.equals("1") && value.getStatus() != 3 && !isAdminUnlocking.equals("1")) { // 禁行区内断电 log.info("禁行区内断电命令--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "禁行区内断电"); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "禁行区内断电",null); device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); int updateAsDevice = asDeviceService.updateAsDevice(device); if (updateAsDevice > 0) { @@ -228,7 +231,7 @@ public class ReceiveController { boolean inPolygon = asDeviceService.isNoRidingAreaWithTolerance(device.getSn(), device.getAreaId(),20); if (inPolygon) { log.info("距离禁行区20米内发送警告命令--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY2, "距离禁行区20米内"); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY2, "距离禁行区20米内",null); } } /** 3.超出运营区外断电*/ @@ -239,14 +242,14 @@ public class ReceiveController { if(inPolygon){ //在20米范围内,发报警 log.info("超出运营区30米内发送警告命令--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "超出运营区30米内"); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_PLAY3, "超出运营区30米内",null); }else{ //超出运营区外断电 String isAdminUnlocking = device.getIsAdminUnlocking();// 是否管理员开锁 String areaOutOutage = area.getAreaOutOutage(); if (areaOutOutage.equals("1") && value.getStatus() != 3 && !isAdminUnlocking.equals("1")) { // 超出营运区断电 log.info("超出营运区断电命令--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "超出营运区断电"); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_QLOSE+IotConstants.COMMAND_FREQUENCY_5, "超出营运区断电",null); device.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); int updateAsDevice = asDeviceService.updateAsDevice(device); if (updateAsDevice > 0) { @@ -259,7 +262,7 @@ public class ReceiveController { Boolean inOrderBySn = etOrderService.isInOrderBySn(device.getSn()); if (inOrderBySn && ServiceConstants.VEHICLE_STATUS_IN_USING.equals(device.getStatus()) && ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())) { // 有正在骑行的订单,给车辆上电 log.info("返回营运区上电,有正在骑行的订单,给车辆上电--SN:" + device.getSn()); - asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "返回营运区上电"); + asDeviceService.sendCommand(device.getMac(), Token.getToken(), IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "返回营运区上电",null); // 更新车辆状态和锁状态 /** 3.更新车辆状态*/ device.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); @@ -383,7 +386,7 @@ public class ReceiveController { if(StrUtil.isNotBlank(verStr)){ device.setVersion(verStr); } - //开异步线程保存回调参数 + //开异步线程:1.更新在线状态 2.记录在线、离线日志 scheduledExecutorService.schedule(() -> { if(device.getOnlineStatus().equals(ServiceConstants.VEHICLE_STATUS_OFFLINE)){ log.info("【接收onenet推送】异步更新在线状态"+JSON.toJSONString(device)); @@ -392,6 +395,17 @@ public class ReceiveController { if(i>0){ log.info("【接收onenet推送】异步保存在线状态成功"); } + EtOnlineLog etOnlineLog = new EtOnlineLog(); + etOnlineLog.setMac(device.getMac()); + etOnlineLog.setSn(device.getSn()); + etOnlineLog.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_ONLINE); + etOnlineLog.setLongitude(device.getLongitude()); + etOnlineLog.setLatitude(device.getLatitude()); + etOnlineLog.setCreateTime(DateUtils.getNowDate()); + int i1 = etOnlineLogService.insertEtOnlineLog(etOnlineLog); + if(i1>0){ + log.info("【接收onenet推送】异步保存在线日志成功"); + } } }, 0, TimeUnit.SECONDS); } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOnlineLogController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOnlineLogController.java new file mode 100644 index 0000000..1994e0b --- /dev/null +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/EtOnlineLogController.java @@ -0,0 +1,104 @@ +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.EtOnlineLog; +import com.ruoyi.system.service.IEtOnlineLogService; +import com.ruoyi.common.utils.poi.ExcelUtil; +import com.ruoyi.common.core.page.TableDataInfo; + +/** + * 在线/离线日志Controller + * + * @author 邱贞招 + * @date 2024-07-13 + */ +@RestController +@RequestMapping("/system/onlineLog") +public class EtOnlineLogController extends BaseController +{ + @Autowired + private IEtOnlineLogService etOnlineLogService; + + /** + * 查询在线/离线日志列表 + */ + @PreAuthorize("@ss.hasPermi('system:onlineLog:list')") + @GetMapping("/list") + public TableDataInfo list(EtOnlineLog etOnlineLog) + { + startPage(); + List list = etOnlineLogService.selectEtOnlineLogList(etOnlineLog); + return getDataTable(list); + } + + /** + * 导出在线/离线日志列表 + */ + @PreAuthorize("@ss.hasPermi('system:onlineLog:export')") + @Log(title = "在线/离线日志", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, EtOnlineLog etOnlineLog) + { + List list = etOnlineLogService.selectEtOnlineLogList(etOnlineLog); + ExcelUtil util = new ExcelUtil(EtOnlineLog.class); + util.exportExcel(response, list, "在线/离线日志数据"); + } + + /** + * 获取在线/离线日志详细信息 + */ + @PreAuthorize("@ss.hasPermi('system:onlineLog:query')") + @GetMapping(value = "/{id}") + public AjaxResult getInfo(@PathVariable("id") Long id) + { + return success(etOnlineLogService.selectEtOnlineLogById(id)); + } + + /** + * 新增在线/离线日志 + */ + @PreAuthorize("@ss.hasPermi('system:onlineLog:add')") + @Log(title = "在线/离线日志", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@RequestBody EtOnlineLog etOnlineLog) + { + return toAjax(etOnlineLogService.insertEtOnlineLog(etOnlineLog)); + } + + /** + * 修改在线/离线日志 + */ + @PreAuthorize("@ss.hasPermi('system:onlineLog:edit')") + @Log(title = "在线/离线日志", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@RequestBody EtOnlineLog etOnlineLog) + { + return toAjax(etOnlineLogService.updateEtOnlineLog(etOnlineLog)); + } + + /** + * 删除在线/离线日志 + */ + @PreAuthorize("@ss.hasPermi('system:onlineLog:remove')") + @Log(title = "在线/离线日志", businessType = BusinessType.DELETE) + @DeleteMapping("/{ids}") + public AjaxResult remove(@PathVariable Long[] ids) + { + return toAjax(etOnlineLogService.deleteEtOnlineLogByIds(ids)); + } +} diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java b/electripper-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java index 8bad774..fda5df1 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/HttpStatus.java @@ -153,6 +153,10 @@ public class HttpStatus */ public static final String ERROR_CODE_DEVICE_NOT_ONLINE = "10421"; + /** + * 错误码 请求超时 + */ + public static final String ERROR_CODE_TIMEOUT = "10500"; /** * 错误码 新增设备失败:设备已存在 */ @@ -206,6 +210,10 @@ public class HttpStatus * 错误码 设备不在线 */ public static final String ERROR_CODE_DEVICE_NOT_ONLINE_MSG = "设备不在线"; + /** + * 错误码 请求超时 + */ + public static final String ERROR_CODE_TIMEOUT_MSG = "请求超时"; /**----------------------------IOT错误码end----------------------------*/ } diff --git a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java index 5cc99d0..ebb2fd0 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java +++ b/electripper-common/src/main/java/com/ruoyi/common/constant/ServiceConstants.java @@ -60,7 +60,7 @@ public class ServiceConstants { /**----------------------------支付场景end----------------------------*/ /**----------------------------订单状态start----------------------------*/ - /** 订单状态:0-预约中,1-取消预约,2-开始骑行,3-结束 4-订单结束*/ + /** 订单状态:0-预约中,1-取消预约,2-开始骑行,3-结束 4-订单结束 5-待审核 6-车辆有损坏 */ /** * 订单状态:0-预约中 */ diff --git a/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java b/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java index af805fa..60697df 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java +++ b/electripper-common/src/main/java/com/ruoyi/common/enums/BusinessType.java @@ -150,5 +150,18 @@ public enum BusinessType * 保存视频 */ VIDEO, + /** + * 重启设备 + */ + REBOOT, + + /** + * 绑定 + */ + BAND, + /** + * 实名认证 + */ + AUTHENTICATION, } diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/IotUtil.java b/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/IotUtil.java index f4740e1..d03817b 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/IotUtil.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/onenet/IotUtil.java @@ -37,6 +37,8 @@ public class IotUtil { return HttpStatus.ERROR_CODE_DEVICE_EVENT_HISTORY_DATA_QUERY_FAIL_MSG; }else if(HttpStatus.ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL.equals(code)){ return HttpStatus.ERROR_CODE_DEVICE_OPERATE_RECORD_QUERY_FAIL_MSG; + }else if(HttpStatus.ERROR_CODE_TIMEOUT.equals(code)){ + return HttpStatus.ERROR_CODE_TIMEOUT_MSG; } return ""; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java index 094cd44..20b5070 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtCommandLog.java @@ -44,5 +44,20 @@ public class EtCommandLog extends BaseEntity @Excel(name = "响应") private String result; + /** 经度 */ + @Excel(name = "经度") + private String longitude; + + /** 纬度 */ + @Excel(name = "纬度") + private String latitude; + + /** 回调状态 */ + @Excel(name = "回调状态") + private String callStatus; + + /** 订单号 */ + @Excel(name = "订单号") + private String orderNo; } diff --git a/electripper-system/src/main/java/com/ruoyi/system/domain/EtOnlineLog.java b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOnlineLog.java new file mode 100644 index 0000000..4ed8dce --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/domain/EtOnlineLog.java @@ -0,0 +1,44 @@ +package com.ruoyi.system.domain; + +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; + +/** + * 在线/离线日志对象 et_online_log + * + * @author 邱贞招 + * @date 2024-07-13 + */ +@Data +public class EtOnlineLog extends BaseEntity +{ + private static final long serialVersionUID = 1L; + + /** 主键 */ + @Excel(name = "主键") + private Long id; + + /** MAC */ + @Excel(name = "MAC") + private String mac; + + /** SN */ + @Excel(name = "SN") + private String sn; + + /** 在线状态 */ + @Excel(name = "在线状态") + private String onlineStatus; + + /** 经度 */ + @Excel(name = "经度") + private String longitude; + + /** 纬度 */ + @Excel(name = "纬度") + private String latitude; + +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOnlineLogMapper.java b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOnlineLogMapper.java new file mode 100644 index 0000000..4a589e1 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/mapper/EtOnlineLogMapper.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.mapper; + +import java.util.List; +import com.ruoyi.system.domain.EtOnlineLog; + +/** + * 在线/离线日志Mapper接口 + * + * @author 邱贞招 + * @date 2024-07-13 + */ +public interface EtOnlineLogMapper +{ + /** + * 查询在线/离线日志 + * + * @param id 在线/离线日志主键 + * @return 在线/离线日志 + */ + public EtOnlineLog selectEtOnlineLogById(Long id); + + /** + * 查询在线/离线日志列表 + * + * @param etOnlineLog 在线/离线日志 + * @return 在线/离线日志集合 + */ + public List selectEtOnlineLogList(EtOnlineLog etOnlineLog); + + /** + * 新增在线/离线日志 + * + * @param etOnlineLog 在线/离线日志 + * @return 结果 + */ + public int insertEtOnlineLog(EtOnlineLog etOnlineLog); + + /** + * 修改在线/离线日志 + * + * @param etOnlineLog 在线/离线日志 + * @return 结果 + */ + public int updateEtOnlineLog(EtOnlineLog etOnlineLog); + + /** + * 删除在线/离线日志 + * + * @param id 在线/离线日志主键 + * @return 结果 + */ + public int deleteEtOnlineLogById(Long id); + + /** + * 批量删除在线/离线日志 + * + * @param ids 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteEtOnlineLogByIds(Long[] ids); +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java index f1f9b8e..d336a99 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IAsDeviceService.java @@ -151,12 +151,12 @@ public interface IAsDeviceService extends IService /** * 发送命令 */ - public void sendCommand(String mac, String token,String command,String type); + public void sendCommand(String mac, String token,String command,String type,String orderNo); /** * 发送命令(带响应) */ - public ResponseVo sendCommandWithResp(String mac, String token, String command, String type); + public ResponseVo sendCommandWithResp(String mac, String token, String command, String type,String orderNo); /** * 查询数据点 diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/IEtOnlineLogService.java b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOnlineLogService.java new file mode 100644 index 0000000..d4357d9 --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/service/IEtOnlineLogService.java @@ -0,0 +1,61 @@ +package com.ruoyi.system.service; + +import java.util.List; +import com.ruoyi.system.domain.EtOnlineLog; + +/** + * 在线/离线日志Service接口 + * + * @author 邱贞招 + * @date 2024-07-13 + */ +public interface IEtOnlineLogService +{ + /** + * 查询在线/离线日志 + * + * @param id 在线/离线日志主键 + * @return 在线/离线日志 + */ + public EtOnlineLog selectEtOnlineLogById(Long id); + + /** + * 查询在线/离线日志列表 + * + * @param etOnlineLog 在线/离线日志 + * @return 在线/离线日志集合 + */ + public List selectEtOnlineLogList(EtOnlineLog etOnlineLog); + + /** + * 新增在线/离线日志 + * + * @param etOnlineLog 在线/离线日志 + * @return 结果 + */ + public int insertEtOnlineLog(EtOnlineLog etOnlineLog); + + /** + * 修改在线/离线日志 + * + * @param etOnlineLog 在线/离线日志 + * @return 结果 + */ + public int updateEtOnlineLog(EtOnlineLog etOnlineLog); + + /** + * 批量删除在线/离线日志 + * + * @param ids 需要删除的在线/离线日志主键集合 + * @return 结果 + */ + public int deleteEtOnlineLogByIds(Long[] ids); + + /** + * 删除在线/离线日志信息 + * + * @param id 在线/离线日志主键 + * @return 结果 + */ + public int deleteEtOnlineLogById(Long id); +} diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index 569d58d..fe33fa2 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -100,6 +100,9 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Resource private EtCommandLogMapper etCommandLogMapper; + @Autowired + private IEtOnlineLogService etOnlineLogService; + @Value(value = "${iot.iotUrl}") private String iotUrl; @@ -610,9 +613,8 @@ public class AsDeviceServiceImpl extends ServiceImpl i String finalOrderNo = orderNo; if(!"true".equals(orderVo.getIsBluetooth())){ /** 2.发送命令*/ - ResponseVo responseVo = sendCommandWithResp(asDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "编号开锁"); + ResponseVo responseVo = sendCommandWithResp(asDevice.getMac(), token, IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5, "编号开锁", finalOrderNo); if(responseVo.getCode() != 0){ -// asynchronousUpdateOnlineStatus(asDevice.getMac()); throw new ServiceException("【扫码/编号开锁骑行】发送开锁命令失败"); } }else{ @@ -681,7 +683,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_20,"管理员开锁"); + sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_20,"管理员开锁",null); asDevice.setIsAdminUnlocking("1"); asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_SCHEDULING); asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); @@ -706,7 +708,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ - sendCommand(mac, token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_20,"管理员开锁"); + sendCommand(mac, token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_20,"管理员开锁",null); asDevice.setIsAdminUnlocking("1"); asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_SCHEDULING); asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_OPEN); @@ -846,14 +848,14 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Transactional @Override /** 发送命令*/ - public void sendCommand(String mac, String token,String command,String type) { + public void sendCommand(String mac, String token,String command,String type,String orderNo) { String param = "device_name=" + mac + "&product_id=" + productId +"&timeout=" + timeout; String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND + "?"+param; String result = HttpUtils.sendPostWithToken(sendUrl, command, token); log.info("【"+type+"】===>IOT请求调用结果:【{}】",result); JSONObject paramsObj = JSON.parseObject(result); String code = paramsObj.getString("code"); - asynchronousSaveLog(sendUrl,command,mac,result,type); + asynchronousSaveLog(sendUrl,command,mac,result,type,orderNo); //记录命令 if (!HttpStatus.IOT_SUCCESS.equals(code)) { @@ -875,12 +877,22 @@ public class AsDeviceServiceImpl extends ServiceImpl i log.info("【接收onenet推送】异步保存在线状态成功"); } } - + EtOnlineLog etOnlineLog = new EtOnlineLog(); + etOnlineLog.setMac(device.getMac()); + etOnlineLog.setSn(device.getSn()); + etOnlineLog.setOnlineStatus(ServiceConstants.VEHICLE_STATUS_OFFLINE); + etOnlineLog.setLongitude(device.getLongitude()); + etOnlineLog.setLatitude(device.getLatitude()); + etOnlineLog.setCreateTime(DateUtils.getNowDate()); + int i1 = etOnlineLogService.insertEtOnlineLog(etOnlineLog); + if(i1>0){ + log.info("【接收onenet推送】异步保存在线日志成功"); + } }, 0, TimeUnit.SECONDS); } /* 异步保存发送命令日志*/ - private void asynchronousSaveLog(String url,String command,String mac,String result,String type) { + private void asynchronousSaveLog(String url,String command,String mac,String result,String type,String orderNo) { //异步保存发送命令日志 scheduledExecutorService.schedule(() -> { EtCommandLog etCommandLog = new EtCommandLog(); @@ -888,9 +900,16 @@ public class AsDeviceServiceImpl extends ServiceImpl i etCommandLog.setCommand(command); etCommandLog.setType(type); etCommandLog.setMac(mac); - etCommandLog.setSn(asDeviceMapper.selectAsDeviceByMac(mac).getSn()); + AsDevice device = asDeviceMapper.selectAsDeviceByMac(mac); + etCommandLog.setSn(device.getSn()); etCommandLog.setResult(result); + etCommandLog.setLongitude(device.getLongitude()); + etCommandLog.setLatitude(device.getLatitude()); etCommandLog.setCreateTime(DateUtils.getNowDate()); + JSONObject paramsObj = JSON.parseObject(result); + String code = paramsObj.getString("code"); + etCommandLog.setCallStatus(code); + etCommandLog.setOrderNo(orderNo); int i = etCommandLogMapper.insertEtCommandLog(etCommandLog); if(i>0){ log.info("【发送命令】异步保存发送命令日志"); @@ -900,7 +919,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Override /** 发送命令*/ - public ResponseVo sendCommandWithResp(String mac, String token,String command,String type) { + public ResponseVo sendCommandWithResp(String mac, String token,String command,String type,String orderNo) { String param = "device_name=" + mac + "&product_id=" + productId +"&timeout=" + timeout; String sendUrl = iotUrl+ IotConstants.ADDS_COMMAND + "?"+param; String result = HttpUtils.sendPostWithToken(sendUrl, command, token); @@ -909,7 +928,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(responseVo.getCode() != 0){ asynchronousUpdateOnlineStatus(mac); } - asynchronousSaveLog(sendUrl,command,mac,result,type); + asynchronousSaveLog(sendUrl,command,mac,result,type,orderNo); return JSON.parseObject(result,ResponseVo.class); } @@ -936,7 +955,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY1,"响铃寻车"); + sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY1,"响铃寻车",null); return Boolean.TRUE; }); if(!execute)throw new ServiceException("响铃寻车失败"); @@ -956,7 +975,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY1,"重启设备"); + sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_PLAY1,"重启设备",null); return Boolean.TRUE; }); if(!execute)throw new ServiceException("重启设备失败"); @@ -975,7 +994,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ - sendCommand(mac, token,IotConstants.COMMAND_REBOOT,"重启设备"); + sendCommand(mac, token,IotConstants.COMMAND_REBOOT,"重启设备",null); return Boolean.TRUE; }); if(!execute)throw new ServiceException("重启设备失败"); @@ -994,7 +1013,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); Boolean execute = transactionTemplate.execute(e -> { /** 2.发送命令*/ - sendCommand(mac, token,IotConstants.COMMAND_PLAY1,"响铃寻车"); + sendCommand(mac, token,IotConstants.COMMAND_PLAY1,"响铃寻车",null); return Boolean.TRUE; }); if(!execute)throw new ServiceException("响铃寻车失败"); @@ -1019,7 +1038,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String token = Token.getToken(); if(!"true".equals(isBluetooth)){ /** 2.发送命令*/ - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_LLOSE+IotConstants.COMMAND_FREQUENCY_3600,"临时锁车"); + sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_LLOSE+IotConstants.COMMAND_FREQUENCY_3600,"临时锁车",orderNo); }else{ asDevice.setLongitude(lon); asDevice.setLatitude(lat); @@ -1056,8 +1075,9 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(StrUtil.isBlank(sn))throw new ServiceException("sn不能为空"); AsDevice asDevice = asDeviceMapper.selectAsDeviceBySn(sn); /** 2.发送命令*/ - sendCommand(asDevice.getMac(), Token.getToken(),IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"管理员锁车"); + sendCommand(asDevice.getMac(), Token.getToken(),IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"管理员锁车",null); asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); + asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL); asDevice.setIsAdminUnlocking("0"); int device = asDeviceMapper.updateAsDevice(asDevice); if(device==0){ @@ -1079,8 +1099,9 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(StrUtil.isBlank(mac))throw new ServiceException("mac不能为空"); AsDevice asDevice = asDeviceMapper.selectAsDeviceByMac(mac); /** 2.发送命令*/ - sendCommand(asDevice.getMac(), Token.getToken(),IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"管理员锁车"); + sendCommand(asDevice.getMac(), Token.getToken(),IotConstants.COMMAND_CLOSE+IotConstants.COMMAND_FREQUENCY_3600,"管理员锁车",null); asDevice.setLockStatus(ServiceConstants.LOCK_STATUS_CLOSE); + asDevice.setStatus(ServiceConstants.VEHICLE_STATUS_NORMAL); asDevice.setIsAdminUnlocking("0"); int device = asDeviceMapper.updateAsDevice(asDevice); if(device==0){ @@ -1108,7 +1129,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i String finalSn = sn; if(!"true".equals(isBluetooth)){ /** 2.发送命令*/ - sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5,"临时解锁"); + sendCommand(asDevice.getMac(), token,IotConstants.COMMAND_OPEN+IotConstants.COMMAND_FREQUENCY_5,"临时解锁",orderNo); }else{ asDevice.setLongitude(lon); asDevice.setLatitude(lat); @@ -1320,7 +1341,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i if(ServiceConstants.RETURN_TYPE_NORMAL.equals(returnType)){ if(!"true".equals(isBluetooth)){ /** 2. 车辆远程关锁*/ - ResponseVo responseVo = sendCommandWithResp(device.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "还车关锁"); + ResponseVo responseVo = sendCommandWithResp(device.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "还车关锁",orderNo); if(responseVo.getCode()!=0){ log.info("【还车关锁】远程关锁失败"); throw new ServiceException("远程关锁失败"); @@ -1344,7 +1365,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i device.setLastTime(DateUtils.getNowDate()); } }else{ - ResponseVo responseVo = sendCommandWithResp(device.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "还车关锁"); + ResponseVo responseVo = sendCommandWithResp(device.getMac(), token, IotConstants.COMMAND_CLOSE + IotConstants.COMMAND_FREQUENCY_3600, "辅助还车关锁",orderNo); if(responseVo.getCode()!=0){ log.info("【还车关锁】远程关锁失败"); } @@ -1876,7 +1897,7 @@ public class AsDeviceServiceImpl extends ServiceImpl i @Override public boolean isOnline(String sn) { AsDevice device = asDeviceMapper.selectAsDeviceBySn(sn); - ResponseVo responseVo = sendCommandWithResp(device.getMac(), Token.getToken(), "111", "是否在线"); + ResponseVo responseVo = sendCommandWithResp(device.getMac(), Token.getToken(), "111", "是否在线",null); if(responseVo.getCode() == 0){ return true; } 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 1e72470..6bf78d7 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 @@ -137,7 +137,7 @@ public class EtModelServiceImpl implements IEtModelService Integer quantityByPercentage = CommonUtil.getElectricQuantityByPercentage(lowBatteryReminder, etModel.getFullVoltage(), etModel.getLowVoltage()); String lowVoltageCommand = IotConstants.COMMAND_BAT + quantityByPercentage * 10 + "@"; log.info("发送低电压命令:" + lowVoltageCommand); - asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报"); + asDeviceService.sendCommand(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报",null); } } return i; @@ -173,7 +173,7 @@ public class EtModelServiceImpl implements IEtModelService Integer quantityByPercentage = CommonUtil.getElectricQuantityByPercentage(lowBatteryReminder, etModel.getFullVoltage(), etModel.getLowVoltage()); String lowVoltageCommand = IotConstants.COMMAND_BAT + quantityByPercentage * 10 + "@"; log.info("发送低电压命令:" + lowVoltageCommand); - ResponseVo responseVo = asDeviceService.sendCommandWithResp(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报"); + ResponseVo responseVo = asDeviceService.sendCommandWithResp(asDevice.getMac(), Token.getToken(), lowVoltageCommand,"发送低电压播报",null); if(responseVo.getCode()!=0){ log.info("【还车关锁】设备【{}】远程关锁失败", asDevice.getMac()); } diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOnlineLogServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOnlineLogServiceImpl.java new file mode 100644 index 0000000..0f0c23d --- /dev/null +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/EtOnlineLogServiceImpl.java @@ -0,0 +1,95 @@ +package com.ruoyi.system.service.impl; + +import java.util.List; +import com.ruoyi.common.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.system.mapper.EtOnlineLogMapper; +import com.ruoyi.system.domain.EtOnlineLog; +import com.ruoyi.system.service.IEtOnlineLogService; + +/** + * 在线/离线日志Service业务层处理 + * + * @author 邱贞招 + * @date 2024-07-13 + */ +@Service +public class EtOnlineLogServiceImpl implements IEtOnlineLogService +{ + @Autowired + private EtOnlineLogMapper etOnlineLogMapper; + + /** + * 查询在线/离线日志 + * + * @param id 在线/离线日志主键 + * @return 在线/离线日志 + */ + @Override + public EtOnlineLog selectEtOnlineLogById(Long id) + { + return etOnlineLogMapper.selectEtOnlineLogById(id); + } + + /** + * 查询在线/离线日志列表 + * + * @param etOnlineLog 在线/离线日志 + * @return 在线/离线日志 + */ + @Override + public List selectEtOnlineLogList(EtOnlineLog etOnlineLog) + { + return etOnlineLogMapper.selectEtOnlineLogList(etOnlineLog); + } + + /** + * 新增在线/离线日志 + * + * @param etOnlineLog 在线/离线日志 + * @return 结果 + */ + @Override + public int insertEtOnlineLog(EtOnlineLog etOnlineLog) + { + etOnlineLog.setCreateTime(DateUtils.getNowDate()); + return etOnlineLogMapper.insertEtOnlineLog(etOnlineLog); + } + + /** + * 修改在线/离线日志 + * + * @param etOnlineLog 在线/离线日志 + * @return 结果 + */ + @Override + public int updateEtOnlineLog(EtOnlineLog etOnlineLog) + { + return etOnlineLogMapper.updateEtOnlineLog(etOnlineLog); + } + + /** + * 批量删除在线/离线日志 + * + * @param ids 需要删除的在线/离线日志主键 + * @return 结果 + */ + @Override + public int deleteEtOnlineLogByIds(Long[] ids) + { + return etOnlineLogMapper.deleteEtOnlineLogByIds(ids); + } + + /** + * 删除在线/离线日志信息 + * + * @param id 在线/离线日志主键 + * @return 结果 + */ + @Override + public int deleteEtOnlineLogById(Long id) + { + return etOnlineLogMapper.deleteEtOnlineLogById(id); + } +} diff --git a/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml b/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml index 53692cb..34fb4a7 100644 --- a/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/EtCommandLogMapper.xml @@ -12,11 +12,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + - select id, url, command, type, mac, sn, result, create_time from et_command_log + select id, url, command, type, mac, sn, result, longitude, latitude, call_status, create_time, order_no from et_command_log @@ -46,6 +52,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mac, sn, result, + latitude, + longitude, + call_status, + order_no, create_time @@ -55,6 +65,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{mac}, #{sn}, #{result}, + #{latitude}, + #{longitude}, + #{callStatus}, + #{orderNo}, sysdate() @@ -68,6 +82,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" mac = #{mac}, sn = #{sn}, result = #{result}, + latitude = #{latitude}, + longitude = #{longitude}, + call_status = #{callStatus}, + order_no = #{orderNo}, where id = #{id} diff --git a/electripper-system/src/main/resources/mapper/system/EtOnlineLogMapper.xml b/electripper-system/src/main/resources/mapper/system/EtOnlineLogMapper.xml new file mode 100644 index 0000000..d903472 --- /dev/null +++ b/electripper-system/src/main/resources/mapper/system/EtOnlineLogMapper.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + select id, mac, sn, online_status, longitude, latitude, create_time from et_online_log + + + + + + + + insert into et_online_log + + mac, + sn, + online_status, + longitude, + latitude, + create_time, + + + #{mac}, + #{sn}, + #{onlineStatus}, + #{longitude}, + #{latitude}, + #{createTime}, + + + + + update et_online_log + + mac = #{mac}, + sn = #{sn}, + online_status = #{onlineStatus}, + longitude = #{longitude}, + latitude = #{latitude}, + create_time = #{createTime}, + + where id = #{id} + + + + delete from et_online_log where id = #{id} + + + + delete from et_online_log where id in + + #{id} + + + \ No newline at end of file diff --git a/electripper-system/src/main/resources/mapper/system/SysOperLogMapper.xml b/electripper-system/src/main/resources/mapper/system/SysOperLogMapper.xml index 201db07..9a31535 100644 --- a/electripper-system/src/main/resources/mapper/system/SysOperLogMapper.xml +++ b/electripper-system/src/main/resources/mapper/system/SysOperLogMapper.xml @@ -28,17 +28,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" select oper_id, title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, oper_time, cost_time from sys_oper_log - + insert into sys_oper_log(title, business_type, method, request_method, operator_type, oper_name, dept_name, oper_url, oper_ip, oper_location, oper_param, json_result, status, error_msg, cost_time, oper_time) values (#{title}, #{businessType}, #{method}, #{requestMethod}, #{operatorType}, #{operName}, #{deptName}, #{operUrl}, #{operIp}, #{operLocation}, #{operParam}, #{jsonResult}, #{status}, #{errorMsg}, #{costTime}, sysdate()) - + - + delete from sys_oper_log where oper_id in #{operId} - + - + - + truncate table sys_oper_log - \ No newline at end of file +