Browse Source

Merge branch 'develop' of http://39.106.31.193:9211/mengff/jihe-dc into develop

develop
lau572 7 months ago
parent
commit
e7e1add443
  1. 13
      zc-business/src/main/java/com/zc/business/controller/DcDeviceController.java
  2. 2
      zc-business/src/main/java/com/zc/business/domain/DcOperLog.java
  3. 222
      zc-business/src/main/java/com/zc/business/interfaces/OperationLogAspect.java
  4. 27
      zc-business/src/main/java/com/zc/business/service/impl/DcOperLogServiceImpl.java

13
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<String, Object> map = new ObjectMapper().convertValue(object, Map.class);
batchInvokedFunction(map);
return batchInvokedFunction(map);
}
}

2
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;
}

222
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,63 +149,174 @@ 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);
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 = "失败";
}
ArrayList<String> deviceIds = new ArrayList<>();
ArrayList<String> deviceNames = new ArrayList<>();
//ArrayList<String> functionIds = new ArrayList<>();
String deviceType = "";
StringBuilder remark = new StringBuilder("在" + date + "调用");
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());
JSONObject pointArg = (JSONObject) pointArgs[0];
JSONArray devices = pointArg.getJSONArray("devices");
JSONArray functions = pointArg.getJSONArray("functions");
for (int i = 0; i < devices.size(); i++) {
JSONObject device = (JSONObject) JSON.toJSON(devices.get(i));
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getId, device.get("id"));
DcDevice dcDevice = dcDeviceService.getById(device.getString("id"));
if (!Objects.isNull(dcDevice)) {
Long deviceId = dcDevice.getId();
String deviceName = dcDevice.getDeviceName();
deviceType = dcDevice.getDeviceType();
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<String, Object>) (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(",");
}
}
}
if (loginUser != null) {
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
dcOperLog.setOperName(loginUser.getUsername());
dcOperLog.setDeptName(sysDept.getDeptName());
dcOperLog.setOperLocation(loginUser.getLoginLocation());
dcOperLog.setOperType("2");
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.setOperTime(new Date());
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);
HashMap<String, ArrayList<JSONObject>> pointArg = (HashMap<String, ArrayList<JSONObject>>) pointArgs[0];
ArrayList<JSONObject> devices = pointArg.get("devices");
ArrayList<JSONObject> functions = pointArg.get("functions");
} else if (operUrl.contains("functions")) {
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]);
DcDevice dcDevice = dcDeviceService.getById(Long.valueOf(String.valueOf(pointArgs[0])));
if (!Objects.isNull(dcDevice)) {
Long deviceId = dcDevice.getId();
String deviceName = dcDevice.getDeviceName();
//ArrayList<String> deviceIds = new ArrayList<>();
//ArrayList<String> functionIds = new ArrayList<>();
String deviceType = "";
deviceType = dcDevice.getDeviceType();
deviceIds.add(String.valueOf(deviceId));
deviceNames.add(deviceName);
for (Object dev : devices) {
JSONObject device = (JSONObject) JSON.toJSON(dev);
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getId, device.get("id"));
List<DcDevice> list = dcDeviceService.list(lambdaQueryWrapper);
if (list.size() > 0) {
DcDevice dcDevice = list.get(0);
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId()));
dcOperLog.setDcDeviceName(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<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
dcOperLog.setJsonResult("设备" + dcDevice.getDeviceName() + "在" + date + "调用了" + hashMap + "功能并且调用" + sta + "了");
dcOperLogService.addDcOperLog(dcOperLog);
}
}
String functionId = String.valueOf(pointArgs[1]);
String hashMap = Objects.equals(deviceType, "5") ? "发布语音广播" : String.valueOf(((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
remark.append(deviceName).append("的").append(hashMap).append("功能并且调用").append(sta).append("了");
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");
}
//String jsonResult1 = "设备在" + date + "调用" + sta + "ID为" + deviceIds + "的设备功能标识为" + functionIds + "的方法";
//System.out.println(jsonResult1);
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();
@ -217,7 +330,7 @@ public class OperationLogAspect {
//operLog.setOperIp(IpUtils.getIpAddr(request));
//operLog.setOperTime(new Date());
//operLog.setDcDeviceType(deviceType);
//operLog.setJsonResult(jsonResult1);
//operLog.setJsonResult(remark);
//if (Objects.equals(state, "0")) {
// operLog.setStatus(0);
//} else {
@ -225,30 +338,7 @@ public class OperationLogAspect {
//}
//dcOperLogService.addDcOperLog(operLog);
} else if (operUrl.contains("functions")) {
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]);
List<DcDevice> 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());
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);
}
}

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

@ -38,15 +38,15 @@ public class DcOperLogServiceImpl extends ServiceImpl<DcOperLogMapper, DcOperLog
@Override
public List<DcOperLog> pageDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime) {
PageUtils.startPage();
return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime));
return list(getDcOperLogLambdaQueryWrapper(dcOperLog, endTime, startTime));
}
@Override
public List<DcOperLog> listDcOperLog(DcOperLog dcOperLog,Date endTime,Date startTime) {
return list(getDcOperLogLambdaQueryWrapper(dcOperLog,endTime,startTime));
public List<DcOperLog> listDcOperLog(DcOperLog dcOperLog, Date endTime, Date startTime) {
return list(getDcOperLogLambdaQueryWrapper(dcOperLog, endTime, startTime));
}
private static LambdaQueryWrapper<DcOperLog> getDcOperLogLambdaQueryWrapper(DcOperLog dcOperLog,Date endTime,Date startTime) {
private static LambdaQueryWrapper<DcOperLog> getDcOperLogLambdaQueryWrapper(DcOperLog dcOperLog, Date endTime, Date startTime) {
LambdaQueryWrapper<DcOperLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
if (dcOperLog.getId() != null) {
lambdaQueryWrapper.eq(DcOperLog::getId, dcOperLog.getId());
@ -66,10 +66,25 @@ public class DcOperLogServiceImpl extends ServiceImpl<DcOperLogMapper, DcOperLog
if (dcOperLog.getDeptName() != null) {
lambdaQueryWrapper.like(DcOperLog::getDeptName, dcOperLog.getDeptName());
}
if (endTime!=null&&startTime!=null) {
if (endTime != null && startTime != null) {
lambdaQueryWrapper.between(DcOperLog::getOperTime, startTime, endTime);
}
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);
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)
.orderByDesc(DcOperLog::getOperTime);
return lambdaQueryWrapper;
}
}

Loading…
Cancel
Save