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. 252
      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()) ; //JSONObject functionJSONObject = (JSONObject) JSON.toJSON(function.toString()) ;
String functionId = functionJSONObject.getString("functionId"); String functionId = functionJSONObject.getString("functionId");
JSONObject jsonObject = functionJSONObject.getJSONObject("params") != null ? functionJSONObject.getJSONObject("params") : new JSONObject(); 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); return AjaxResult.success(resultArray);
@ -506,6 +512,7 @@ public class DcDeviceController extends BaseController {
}); });
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("device", device.getString("id")); result.put("device", device.getString("id"));
result.put("functionId",functionId);
if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) { if (device.getInteger("deviceType").equals(DeviceTypeConstants.ROAD_SECTION_VOICE_BROADCASTING)) {
result.put("result", broadcastController.nearCamListDistance(jsonObject)); result.put("result", broadcastController.nearCamListDistance(jsonObject));
} else { } else {
@ -606,8 +613,8 @@ public class DcDeviceController extends BaseController {
} }
@OperationLog(operUrl = "/business/device/batchFunctions") @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); 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; private Integer status;
@ApiModelProperty("操作时间") @ApiModelProperty("操作时间")
private Date operTime; private Date operTime;
@ApiModelProperty("描述")
private String remark;
} }

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

@ -1,8 +1,10 @@
package com.zc.business.interfaces; package com.zc.business.interfaces;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; 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.entity.SysDept;
import com.ruoyi.common.core.domain.model.LoginUser; import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
@ -108,7 +110,7 @@ public class OperationLogAspect {
IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class); IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class);
try { try {
DcOperLog dcOperLog = new DcOperLog(); DcOperLog operLog = new DcOperLog();
String operUrl = operationLog.operUrl(); String operUrl = operationLog.operUrl();
LoginUser loginUser; LoginUser loginUser;
try { try {
@ -127,7 +129,7 @@ public class OperationLogAspect {
request = null; request = null;
} }
//Object proceed = joinPoint.proceed(pointArgs); AjaxResult proceed = (AjaxResult) joinPoint.proceed(pointArgs);
//String jsonResultString = ""; //String jsonResultString = "";
//JSONArray jsonArray = (JSONArray) proceed; //JSONArray jsonArray = (JSONArray) proceed;
//for (Object o : jsonArray) { //for (Object o : jsonArray) {
@ -147,108 +149,196 @@ public class OperationLogAspect {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = df.format(new Date()); String date = df.format(new Date());
String sta = ""; String sta = "";
if (Objects.equals(state, "0")) { if (Objects.equals(state, "0")&&Objects.equals(String.valueOf(proceed.get("code")), "200")) {
dcOperLog.setStatus(0); //if (Objects.equals(String.valueOf(proceed.get("code")), "200")) {
sta = "成功"; operLog.setStatus(0);
sta = "成功";
//} else {
// operLog.setStatus(1);
// sta = "失败";
//}
} else { } else {
dcOperLog.setStatus(1); operLog.setStatus(1);
sta = "失败"; 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<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")) {
//批量调用
HashMap<String, ArrayList<JSONObject>> pointArg = (HashMap<String, ArrayList<JSONObject>>) pointArgs[0]; //if (loginUser != null) {
ArrayList<JSONObject> devices = pointArg.get("devices"); // SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
ArrayList<JSONObject> functions = pointArg.get("functions"); //
// 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<String> deviceIds = new ArrayList<>(); for (int i = 0; i < devices.size(); i++) {
//ArrayList<String> functionIds = new ArrayList<>();
String deviceType = "";
JSONObject device = (JSONObject) JSON.toJSON(devices.get(i));
for (Object dev : devices) {
JSONObject device = (JSONObject) JSON.toJSON(dev);
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getId, device.get("id")); lambdaQueryWrapper.eq(DcDevice::getId, device.get("id"));
List<DcDevice> list = dcDeviceService.list(lambdaQueryWrapper); DcDevice dcDevice = dcDeviceService.getById(device.getString("id"));
if (list.size() > 0) {
DcDevice dcDevice = list.get(0); if (!Objects.isNull(dcDevice)) {
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); Long deviceId = dcDevice.getId();
dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); String deviceName = dcDevice.getDeviceName();
deviceType = dcDevice.getDeviceType(); deviceType = dcDevice.getDeviceType();
dcOperLog.setDcDeviceType(deviceType);
//deviceIds.add(String.valueOf(dcDevice.getId())); deviceIds.add(String.valueOf(deviceId));
for (Object fun : functions) { deviceNames.add(deviceName);
JSONObject function = (JSONObject) JSON.toJSON(fun);
dcOperLog.setOperParam(function.getString("params")); remark.append(deviceName).append("的");
String functionId = function.getString("functionId");
//functionIds.add(functionId); for (int i1 = 0; i1 < functions.size(); i1++) {
String hashMap = Objects.equals(deviceType, "5") ?"发布语音广播":String.valueOf(((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
dcOperLog.setJsonResult("设备" + dcDevice.getDeviceName() + "在" + date + "调用了" + hashMap + "功能并且调用" + sta + "了"); JSONObject function = (JSONObject) JSON.toJSON(functions.get(i1));
dcOperLogService.addDcOperLog(dcOperLog);
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(",");
}
} }
} }
//String jsonResult1 = "设备在" + date + "调用" + sta + "ID为" + deviceIds + "的设备功能标识为" + functionIds + "的方法";
//System.out.println(jsonResult1);
//System.out.println(deviceIds.toString()); if (loginUser != null) {
//System.out.println(functionIds.toString()); SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
//DcOperLog operLog = new DcOperLog();
//SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); operLog.setOperName(loginUser.getUsername());
//operLog.setOperParam((Arrays.toString(pointArgs))); operLog.setDeptName(sysDept.getDeptName());
//operLog.setOperLocation(loginUser.getLoginLocation()); operLog.setOperLocation(loginUser.getLoginLocation());
//operLog.setOperName(loginUser.getUsername()); operLog.setOperType("2");
//operLog.setDeptName(sysDept.getDeptName()); } else {
//operLog.setDcDeviceId(deviceIds.toString()); operLog.setOperType("1");
//operLog.setOperType("2"); }
//operLog.setOperIp(IpUtils.getIpAddr(request)); operLog.setOperParam((Arrays.toString(pointArgs)));
//operLog.setOperTime(new Date()); operLog.setDcDeviceId(deviceIds.toString());
//operLog.setDcDeviceType(deviceType); operLog.setDcDeviceName(deviceNames.toString());
//operLog.setJsonResult(jsonResult1); operLog.setOperIp(IpUtils.getIpAddr(request));
//if (Objects.equals(state, "0")) { operLog.setOperTime(new Date());
// operLog.setStatus(0); operLog.setDcDeviceType(deviceType);
//} else { operLog.setRemark(remark.toString());
// operLog.setStatus(1); operLog.setJsonResult(String.valueOf(proceed));
//} dcOperLogService.addDcOperLog(operLog);
//dcOperLogService.addDcOperLog(operLog);
} else if (operUrl.contains("functions")) { } else if (operUrl.contains("functions")) {
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]); lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[0]);
List<DcDevice> list = dcDeviceService.list(lambdaQueryWrapper); DcDevice dcDevice = dcDeviceService.getById(Long.valueOf(String.valueOf(pointArgs[0])));
if (list.size() > 0) { if (!Objects.isNull(dcDevice)) {
DcDevice dcDevice = list.get(0);
dcOperLog.setDcDeviceId(String.valueOf(dcDevice.getId())); Long deviceId = dcDevice.getId();
dcOperLog.setDcDeviceName(dcDevice.getDeviceName()); String deviceName = dcDevice.getDeviceName();
dcOperLog.setDcDeviceType(dcDevice.getDeviceType());
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<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
remark.append(deviceName).append("的").append(hashMap).append("功能并且调用").append(sta).append("了");
if (loginUser != null) { if (loginUser != null) {
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId()); SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
operLog.setOperName(loginUser.getUsername());
dcOperLog.setOperName(loginUser.getUsername()); operLog.setDeptName(sysDept.getDeptName());
dcOperLog.setDeptName(sysDept.getDeptName()); operLog.setOperLocation(loginUser.getLoginLocation());
dcOperLog.setOperLocation(loginUser.getLoginLocation()); operLog.setOperType("2");
dcOperLog.setOperType("0");
} else { } else {
dcOperLog.setOperType("1"); operLog.setOperType("1");
} }
dcOperLog.setOperIp(IpUtils.getIpAddr(request)); operLog.setOperParam((Arrays.toString(pointArgs)));
dcOperLog.setOperParam(Arrays.toString(pointArgs)); operLog.setDcDeviceId(deviceIds.toString());
dcOperLog.setJsonResult(dcDevice.getDeviceName() + "设备在" + date + "调用" + sta + "ID为" + dcDevice.getId() + "的设备功能标识为" + pointArgs[1].toString() + "的方法"); operLog.setDcDeviceName(deviceNames.toString());
dcOperLog.setOperTime(new Date()); operLog.setOperIp(IpUtils.getIpAddr(request));
dcOperLogService.addDcOperLog(dcOperLog); 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);
} }
} }

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

Loading…
Cancel
Save