Browse Source

优化管控记录

develop
zhaoxianglong 7 months ago
parent
commit
ad5fd50528
  1. 95
      zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java
  2. 2
      zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java

95
zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java

@ -20,6 +20,7 @@ import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.*;
@Aspect
@ -51,7 +52,7 @@ public class OperationLogAspect {
try {
loginUser = SecurityUtils.getLoginUser();
}catch (Exception e){
} catch (Exception e) {
loginUser = null;
}
Object[] pointArgs = joinPoint.getArgs();
@ -60,9 +61,37 @@ public class OperationLogAspect {
try {
request = ServletUtils.getRequest();
}catch (Exception e){
} catch (Exception e) {
request = null;
}
//Object proceed = joinPoint.proceed(pointArgs);
//String jsonResultString = "";
//JSONArray jsonArray = (JSONArray) proceed;
//for (Object o : jsonArray) {
// JSONObject jsonObject = (JSONObject) o;
// if (Objects.equals(jsonObject.getString("code"), "200")) {
// JSONArray data = jsonObject.getJSONArray("data");
// for (Object datum : data) {
// JSONObject results = (JSONObject) datum;
// JSONObject result = results.getJSONObject("result");
// if (Objects.equals(result.getString("code"), "200")) {
// jsonResultString = "设备"+d+"";
// }
// }
// }
//}
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 = "成功";
} else {
dcOperLog.setStatus(1);
sta = "失败";
}
if (operUrl.contains("batchFunctions")) {
if (loginUser != null) {
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
@ -70,16 +99,21 @@ public class OperationLogAspect {
dcOperLog.setOperName(loginUser.getUsername());
dcOperLog.setDeptName(sysDept.getDeptName());
dcOperLog.setOperLocation(loginUser.getLoginLocation());
dcOperLog.setOperType("2");
} else {
dcOperLog.setOperType("1");
}
dcOperLog.setOperType("2");
dcOperLog.setOperIp(IpUtils.getIpAddr(request));
dcOperLog.setJsonResult(String.valueOf(joinPoint.proceed(pointArgs)));
dcOperLog.setOperTime(new Date());
HashMap<String, ArrayList<JSONObject>> pointArg = (HashMap<String, ArrayList<JSONObject>>) pointArgs[0];
ArrayList<JSONObject> devices = pointArg.get("devices");
ArrayList<JSONObject> functions = pointArg.get("functions");
//StringBuilder deviceIds = new StringBuilder();
//StringBuilder functionIds = new StringBuilder();
//ArrayList<String> deviceIds = new ArrayList<>();
ArrayList<String> functionIds = new ArrayList<>();
for (Object dev : devices) {
JSONObject device = (JSONObject) JSON.toJSON(dev);
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
@ -90,13 +124,21 @@ public class OperationLogAspect {
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId()));
dcOperLog.setDcDeviceName(dcDevice.getDeviceName());
dcOperLog.setDcDeviceType(dcDevice.getDeviceType());
}
for (Object fun : functions) {
JSONObject function = (JSONObject) JSON.toJSON(fun);
dcOperLog.setOperParam(function.getString("params"));
dcOperLogService.addDcOperLog(dcOperLog);
//deviceIds.add(String.valueOf(dcDevice.getId()));
for (Object fun : functions) {
JSONObject function = (JSONObject) JSON.toJSON(fun);
dcOperLog.setOperParam(function.getString("params"));
//functionIds.add(function.getString("functionId"));
dcOperLog.setJsonResult(dcDevice.getDeviceName() + "设备在" + date + "调用" + sta + "ID为" + dcDevice.getId() + "的设备功能标识为" + function.getString("functionId") + "的方法");
dcOperLogService.addDcOperLog(dcOperLog);
}
}
}
//String jsonResult1 = "设备在" + date + "调用" + sta + "ID为" + deviceIds + "的设备功能标识为" + functionIds + "的方法";
//System.out.println(deviceIds.toString());
//System.out.println(functionIds.toString());
//System.out.println(jsonResult1);
} else if (operUrl.contains("functions")) {
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]);
@ -106,27 +148,22 @@ public class OperationLogAspect {
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId()));
dcOperLog.setDcDeviceName(dcDevice.getDeviceName());
dcOperLog.setDcDeviceType(dcDevice.getDeviceType());
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 + "调用" + sta + "ID为" + dcDevice.getId() + "的设备功能标识为" + pointArgs[1].toString() + "的方法");
dcOperLog.setOperTime(new Date());
dcOperLogService.addDcOperLog(dcOperLog);
}
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(joinPoint.getArgs()));
dcOperLog.setJsonResult(String.valueOf(joinPoint.proceed(pointArgs)));
if (Objects.equals(state, "0")) {
dcOperLog.setStatus(0);
} else {
dcOperLog.setStatus(1);
}
dcOperLog.setOperTime(new Date());
dcOperLogService.addDcOperLog(dcOperLog);
}
} catch (Exception e) {

2
zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java

@ -66,7 +66,7 @@ public class DcOperLogServiceImpl extends ServiceImpl<DcOperLogMapper, DcOperLog
if (endTime!=null&&startTime!=null) {
lambdaQueryWrapper.between(DcOperLog::getOperTime, startTime, endTime);
}
lambdaQueryWrapper.select(DcOperLog::getId, DcOperLog::getDcDeviceId, DcOperLog::getDcDeviceType, DcOperLog::getDcDeviceType, DcOperLog::getOperName,DcOperLog::getDeptName, DcOperLog::getOperType, DcOperLog::getOperIp, DcOperLog::getOperLocation,DcOperLog::getOperParam, DcOperLog::getJsonResult, DcOperLog::getStatus, DcOperLog::getOperTime);
lambdaQueryWrapper.select(DcOperLog::getId, DcOperLog::getDcDeviceId, DcOperLog::getDcDeviceType,DcOperLog::getDcDeviceName, DcOperLog::getDcDeviceType, DcOperLog::getOperName,DcOperLog::getDeptName, DcOperLog::getOperType, DcOperLog::getOperIp, DcOperLog::getOperLocation,DcOperLog::getOperParam, DcOperLog::getJsonResult, DcOperLog::getStatus, DcOperLog::getOperTime);
return lambdaQueryWrapper;
}
}

Loading…
Cancel
Save