From 0aeff81103d111aaf002ebad0530f66774f3f0b7 Mon Sep 17 00:00:00 2001 From: zhaoxianglong Date: Sun, 28 Apr 2024 18:41:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=AE=A1=E6=8E=A7=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceController.java | 13 +- .../com/zc/business/domain/DcOperLog.java | 2 + .../interfaces/OperationLogAspect.java | 252 ++++++++++++------ .../service/impl/DcOperLogServiceImpl.java | 27 +- 4 files changed, 204 insertions(+), 90 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java index fbb92c93..bb41e2b5 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java @@ -495,7 +495,13 @@ public class DcDeviceController extends BaseController { //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ; String functionId = functionJSONObject.getString("functionId"); JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); - resultArray.add(getResult(device, iotDeviceId, functionId, jsonObject)); + JSONObject result = getResult(device, iotDeviceId, functionId, jsonObject); + resultArray.add(result); + AjaxResult ajaxResult = (AjaxResult) result.get("result"); + if (!Objects.equals(String.valueOf(ajaxResult.get("code")), "200")) { + return AjaxResult.error(); + } + } } return AjaxResult.success(resultArray); @@ -506,6 +512,7 @@ public class DcDeviceController extends BaseController { }); JSONObject result = new JSONObject(); result.put("device", device.getString("id")); + result.put("functionId",functionId); if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { result.put("result", broadcastController.nearCamListDistance(jsonObject)); } else { @@ -606,8 +613,8 @@ public class DcDeviceController extends BaseController { } @OperationLog(operUrl = "/business/device/batchFunctions") - public void batchInvokedFunction(Object object) throws HttpException, IOException, InterruptedException { + public AjaxResult batchInvokedFunction(Object object) throws HttpException, IOException, InterruptedException { Map map = new ObjectMapper().convertValue(object, Map.class); - batchInvokedFunction(map); + return batchInvokedFunction(map); } } diff --git a/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java b/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java index dfdc4397..c6956eca 100644 --- a/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java +++ b/zc-business/src/main/java/com/zc/business/domain/DcOperLog.java @@ -38,5 +38,7 @@ public class DcOperLog { private Integer status; @ApiModelProperty("操作时间") private Date operTime; + @ApiModelProperty("描述") + private String remark; } diff --git a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java index 8929f7f4..d2b38529 100644 --- a/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java +++ b/zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java @@ -1,8 +1,10 @@ package com.zc.business.interfaces; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.entity.SysDept; import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.utils.SecurityUtils; @@ -108,7 +110,7 @@ public class OperationLogAspect { IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class); try { - DcOperLog dcOperLog = new DcOperLog(); + DcOperLog operLog = new DcOperLog(); String operUrl = operationLog.operUrl(); LoginUser loginUser; try { @@ -127,7 +129,7 @@ public class OperationLogAspect { request = null; } - //Object proceed = joinPoint.proceed(pointArgs); + AjaxResult proceed = (AjaxResult) joinPoint.proceed(pointArgs); //String jsonResultString = ""; //JSONArray jsonArray = (JSONArray) proceed; //for (Object o : jsonArray) { @@ -147,108 +149,196 @@ public class OperationLogAspect { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String date = df.format(new Date()); String sta = ""; - if (Objects.equals(state, "0")) { - dcOperLog.setStatus(0); - sta = "成功"; + if (Objects.equals(state, "0")&&Objects.equals(String.valueOf(proceed.get("code")), "200")) { + //if (Objects.equals(String.valueOf(proceed.get("code")), "200")) { + operLog.setStatus(0); + sta = "成功"; + //} else { + // operLog.setStatus(1); + // sta = "失败"; + //} } else { - dcOperLog.setStatus(1); + operLog.setStatus(1); sta = "失败"; } - if (operUrl.contains("batchFunctions")) { - if (loginUser != null) { - SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); - - dcOperLog.setOperName(loginUser.getUsername()); - dcOperLog.setDeptName(sysDept.getDeptName()); - dcOperLog.setOperLocation(loginUser.getLoginLocation()); - dcOperLog.setOperType("2"); - } else { - dcOperLog.setOperType("1"); - } - dcOperLog.setOperIp(IpUtils.getIpAddr(request)); - dcOperLog.setOperTime(new Date()); + ArrayList deviceIds = new ArrayList<>(); + ArrayList deviceNames = new ArrayList<>(); + //ArrayList functionIds = new ArrayList<>(); + String deviceType = ""; + StringBuilder remark = new StringBuilder("在" + date + "调用"); + if (operUrl.contains("batchFunctions")) { + //批量调用 - HashMap> pointArg = (HashMap>) pointArgs[0]; - ArrayList devices = pointArg.get("devices"); - ArrayList functions = pointArg.get("functions"); + //if (loginUser != null) { + // SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); + // + // dcOperLog.setOperName(loginUser.getUsername()); + // dcOperLog.setDeptName(sysDept.getDeptName()); + // dcOperLog.setOperLocation(loginUser.getLoginLocation()); + // dcOperLog.setOperType("2"); + //} else { + // dcOperLog.setOperType("1"); + //} + //dcOperLog.setOperIp(IpUtils.getIpAddr(request)); + //dcOperLog.setOperTime(new Date()); + JSONObject pointArg = (JSONObject) pointArgs[0]; + JSONArray devices = pointArg.getJSONArray("devices"); + JSONArray functions = pointArg.getJSONArray("functions"); - //ArrayList deviceIds = new ArrayList<>(); - //ArrayList functionIds = new ArrayList<>(); - String deviceType = ""; + for (int i = 0; i < devices.size(); i++) { + JSONObject device = (JSONObject) JSON.toJSON(devices.get(i)); - for (Object dev : devices) { - JSONObject device = (JSONObject) JSON.toJSON(dev); LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(DcDevice::getId, device.get("id")); - List list = dcDeviceService.list(lambdaQueryWrapper); - if (list.size() > 0) { - DcDevice dcDevice = list.get(0); - dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); - dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); + DcDevice dcDevice = dcDeviceService.getById(device.getString("id")); + + if (!Objects.isNull(dcDevice)) { + Long deviceId = dcDevice.getId(); + String deviceName = dcDevice.getDeviceName(); + deviceType = dcDevice.getDeviceType(); - dcOperLog.setDcDeviceType(deviceType); - //deviceIds.add(String.valueOf(dcDevice.getId())); - for (Object fun : functions) { - JSONObject function = (JSONObject) JSON.toJSON(fun); - dcOperLog.setOperParam(function.getString("params")); - String functionId = function.getString("functionId"); - //functionIds.add(functionId); - String hashMap = Objects.equals(deviceType, "5") ?"发布语音广播":String.valueOf(((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId)); - dcOperLog.setJsonResult("设备" + dcDevice.getDeviceName() + "在" + date + "调用了" + hashMap + "功能并且调用" + sta + "了"); - dcOperLogService.addDcOperLog(dcOperLog); + + deviceIds.add(String.valueOf(deviceId)); + deviceNames.add(deviceName); + + remark.append(deviceName).append("的"); + + for (int i1 = 0; i1 < functions.size(); i1++) { + + JSONObject function = (JSONObject) JSON.toJSON(functions.get(i1)); + + String hashMap = Objects.equals(deviceType, "5") ? + "发布语音广播" : + String.valueOf( + ((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))) + .get(function.getString("functionId"))); + + remark.append("调用").append(hashMap).append("功能").append(sta); + + if (i1 < functions.size() - 1) { + remark.append("、"); + } } + + if (i < (devices.size() - 1)) { + remark.append(","); + } + } } - //String jsonResult1 = "设备在" + date + "调用" + sta + "ID为" + deviceIds + "的设备功能标识为" + functionIds + "的方法"; - //System.out.println(jsonResult1); - //System.out.println(deviceIds.toString()); - //System.out.println(functionIds.toString()); - //DcOperLog operLog = new DcOperLog(); - //SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); - //operLog.setOperParam((Arrays.toString(pointArgs))); - //operLog.setOperLocation(loginUser.getLoginLocation()); - //operLog.setOperName(loginUser.getUsername()); - //operLog.setDeptName(sysDept.getDeptName()); - //operLog.setDcDeviceId(deviceIds.toString()); - //operLog.setOperType("2"); - //operLog.setOperIp(IpUtils.getIpAddr(request)); - //operLog.setOperTime(new Date()); - //operLog.setDcDeviceType(deviceType); - //operLog.setJsonResult(jsonResult1); - //if (Objects.equals(state, "0")) { - // operLog.setStatus(0); - //} else { - // operLog.setStatus(1); - //} - //dcOperLogService.addDcOperLog(operLog); + + + if (loginUser != null) { + SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); + + operLog.setOperName(loginUser.getUsername()); + operLog.setDeptName(sysDept.getDeptName()); + operLog.setOperLocation(loginUser.getLoginLocation()); + operLog.setOperType("2"); + } else { + operLog.setOperType("1"); + } + operLog.setOperParam((Arrays.toString(pointArgs))); + operLog.setDcDeviceId(deviceIds.toString()); + operLog.setDcDeviceName(deviceNames.toString()); + operLog.setOperIp(IpUtils.getIpAddr(request)); + operLog.setOperTime(new Date()); + operLog.setDcDeviceType(deviceType); + operLog.setRemark(remark.toString()); + operLog.setJsonResult(String.valueOf(proceed)); + dcOperLogService.addDcOperLog(operLog); + } else if (operUrl.contains("functions")) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]); - List list = dcDeviceService.list(lambdaQueryWrapper); - if (list.size() > 0) { - DcDevice dcDevice = list.get(0); - dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); - dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); - dcOperLog.setDcDeviceType(dcDevice.getDeviceType()); + DcDevice dcDevice = dcDeviceService.getById(Long.valueOf(String.valueOf(pointArgs[0]))); + if (!Objects.isNull(dcDevice)) { + + Long deviceId = dcDevice.getId(); + String deviceName = dcDevice.getDeviceName(); + + deviceType = dcDevice.getDeviceType(); + + deviceIds.add(String.valueOf(deviceId)); + deviceNames.add(deviceName); + + String functionId = String.valueOf(pointArgs[1]); + String hashMap = Objects.equals(deviceType, "5") ? "发布语音广播" : String.valueOf(((HashMap) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId)); + + remark.append(deviceName).append("的").append(hashMap).append("功能并且调用").append(sta).append("了"); + + if (loginUser != null) { SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); - - dcOperLog.setOperName(loginUser.getUsername()); - dcOperLog.setDeptName(sysDept.getDeptName()); - dcOperLog.setOperLocation(loginUser.getLoginLocation()); - dcOperLog.setOperType("0"); + operLog.setOperName(loginUser.getUsername()); + operLog.setDeptName(sysDept.getDeptName()); + operLog.setOperLocation(loginUser.getLoginLocation()); + operLog.setOperType("2"); } else { - dcOperLog.setOperType("1"); + operLog.setOperType("1"); } - dcOperLog.setOperIp(IpUtils.getIpAddr(request)); - dcOperLog.setOperParam(Arrays.toString(pointArgs)); - dcOperLog.setJsonResult(dcDevice.getDeviceName() + "设备在" + date + "调用" + sta + "ID为" + dcDevice.getId() + "的设备功能标识为" + pointArgs[1].toString() + "的方法"); - dcOperLog.setOperTime(new Date()); - dcOperLogService.addDcOperLog(dcOperLog); + operLog.setOperParam((Arrays.toString(pointArgs))); + operLog.setDcDeviceId(deviceIds.toString()); + operLog.setDcDeviceName(deviceNames.toString()); + operLog.setOperIp(IpUtils.getIpAddr(request)); + operLog.setOperTime(new Date()); + operLog.setDcDeviceType(deviceType); + operLog.setJsonResult(remark.toString()); + dcOperLogService.addDcOperLog(operLog); + + + // + ////DcDevice dcDevice = list.get(0); + //operLog.setDcDeviceId(String.valueOf(dcDevice.getId())); + //operLog.setDcDeviceName(dcDevice.getDeviceName()); + //deviceType = dcDevice.getDeviceType(); + //operLog.setDcDeviceType(deviceType); + //if (loginUser != null) { + // SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); + // + // dcOperLog.setOperName(loginUser.getUsername()); + // dcOperLog.setDeptName(sysDept.getDeptName()); + // dcOperLog.setOperLocation(loginUser.getLoginLocation()); + // dcOperLog.setOperType("0"); + //} else { + // dcOperLog.setOperType("1"); + //} + //dcOperLog.setOperIp(IpUtils.getIpAddr(request)); + //dcOperLog.setOperParam(Arrays.toString(pointArgs)); + //dcOperLog.setJsonResult("设备" + dcDevice.getDeviceName() + "在" + date + "调用了" + hashMap + "功能并且调用" + sta + "了"); + ////dcOperLog.setJsonResult(dcDevice.getDeviceName() + "设备在" + date + "调用" + sta + "ID为" + dcDevice.getId() + "的设备功能标识为" + pointArgs[1].toString() + "的方法"); + //dcOperLog.setOperTime(new Date()); + //dcOperLogService.addDcOperLog(dcOperLog); + // + // + //String remark = "设备在" + date + "调用" + sta + "ID为" + deviceIds + "的设备功能标识为" + functionIds + "的方法"; + //System.out.println(remark); + //System.out.println(deviceIds.toString()); + //System.out.println(functionIds.toString()); + //DcOperLog operLog = new DcOperLog(); + //SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); + //operLog.setOperParam((Arrays.toString(pointArgs))); + //operLog.setOperLocation(loginUser.getLoginLocation()); + //operLog.setOperName(loginUser.getUsername()); + //operLog.setDeptName(sysDept.getDeptName()); + //operLog.setDcDeviceId(deviceIds.toString()); + //operLog.setOperType("2"); + //operLog.setOperIp(IpUtils.getIpAddr(request)); + //operLog.setOperTime(new Date()); + //operLog.setDcDeviceType(deviceType); + //operLog.setJsonResult(remark); + //if (Objects.equals(state, "0")) { + // operLog.setStatus(0); + //} else { + // operLog.setStatus(1); + //} + //dcOperLogService.addDcOperLog(operLog); + + } } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java index 96362b29..4972cf88 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java @@ -38,15 +38,15 @@ public class DcOperLogServiceImpl extends ServiceImpl pageDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime) { PageUtils.startPage(); - return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime)); + return list(getDcOperLogLambdaQueryWrapper(dcOperLog, endTime, startTime)); } @Override - public List listDcOperLog(DcOperLog dcOperLog,Date endTime,Date startTime) { - return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime)); + public List listDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime) { + return list(getDcOperLogLambdaQueryWrapper(dcOperLog, endTime, startTime)); } - private static LambdaQueryWrapper getDcOperLogLambdaQueryWrapper(DcOperLog dcOperLog,Date endTime,Date startTime) { + private static LambdaQueryWrapper getDcOperLogLambdaQueryWrapper(DcOperLog dcOperLog, Date endTime, Date startTime) { LambdaQueryWrapper lambdaQueryWrapper = new LambdaQueryWrapper<>(); if (dcOperLog.getId() != null) { lambdaQueryWrapper.eq(DcOperLog::getId, dcOperLog.getId()); @@ -66,10 +66,25 @@ public class DcOperLogServiceImpl extends ServiceImpl