济菏高速数据中心代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

403 lines
22 KiB

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;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.ip.IpUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.system.service.ISysDeptService;
import com.zc.business.domain.DcDevice;
import com.zc.business.domain.DcOperLog;
import com.zc.business.domain.DcPublishManage;
import com.zc.business.enums.UniversalEnum;
import com.zc.business.service.IDcDeviceService;
import com.zc.business.service.IDcOperLogService;
import com.zc.business.service.IDcPublishManageService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
11 months ago
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@Aspect
@Component
public class OperationLogAspect {
private final static Map<String, Object> DEVICEFUNCTIONNAME = new HashMap<String, Object>() {{
put(UniversalEnum.ONE.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.TWO.getValue(), new HashMap<String, Object>() {{
put(UniversalEnum.ELEVEN.getValue(), UniversalEnum.FILE_NAME_SENDING.getValue());
put(UniversalEnum.THIRTEEN.getValue(), UniversalEnum.FILE_SENDING.getValue());
put(UniversalEnum.ONE_B.getValue(), UniversalEnum.SPECIFIES_THE_LIST_THAT_CURRENTLY_NEEDS_TO_BE_PLAYED.getValue());
}});
put(UniversalEnum.THREE.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.FOUR.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.FIVE.getValue(), new HashMap<String, Object>() {{
put(UniversalEnum.EMPTY_STRING.getValue(), UniversalEnum.RELEASE_VOICE_BROADCAST.getValue());
}});
put(UniversalEnum.SIX.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.SEVEN.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.EIGHT.getValue(), new HashMap<String, Object>() {{
put(UniversalEnum.ZERO_ONE.getValue(), UniversalEnum.COMMUNICATION_CONNECTION_CHECK.getValue());
put(UniversalEnum.ZERO_B.getValue(), UniversalEnum.CONFIGURATION_DEVICE_PARAMETER.getValue());
put(UniversalEnum.ZERO_D.getValue(), UniversalEnum.READ_DEVICE_PARAMETER.getValue());
put(UniversalEnum.ZERO_F.getValue(), UniversalEnum.READ_DEVICE_STATUS_DATA.getValue());
}});
put(UniversalEnum.NINE.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.TEN.getValue(), new HashMap<String, Object>() {{
put(UniversalEnum.SETMD.getValue(), UniversalEnum.MODE_SETTING_COMMAND.getValue());
put(UniversalEnum.ASKMD.getValue(), UniversalEnum.PATTERN_QUERY_COMMAND.getValue());
put(UniversalEnum.SETTM.getValue(), UniversalEnum.WORK_TIME_SETTING_COMMAND.getValue());
put(UniversalEnum.ASKTM.getValue(), UniversalEnum.THIS_COMMAND_IS_USED_TO_QUERY_WORKING_HOURS.getValue());
put(UniversalEnum.SETDF.getValue(), UniversalEnum.CUSTOMIZE_MODE_SETTINGS.getValue());
put(UniversalEnum.ASKDF.getValue(), UniversalEnum.USER_DEFINED_MODE_QUERY_COMMAND.getValue());
}});
put(UniversalEnum.ELEVEN.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.TWELVE.getValue(), new HashMap<String, Object>() {{
put(UniversalEnum.FIFTY_ONE.getValue(), UniversalEnum.DEVICE_CONTROL_MODE.getValue());
put(UniversalEnum.FIFTY_TWO.getValue(), UniversalEnum.READ_THE_DEVICE_CONTROL_MODE.getValue());
put(UniversalEnum.THIRTY.getValue(), UniversalEnum.SET_THE_WORKING_STATE_OF_AUTOMATIC_CONTROL_MODE.getValue());
put(UniversalEnum.THREE_D.getValue(), UniversalEnum.READ_THE_WORKING_STATUS_OF_AUTOMATIC_CONTROL_MODE.getValue());
put(UniversalEnum.THREE_C.getValue(), UniversalEnum.READ_THE_CURRENT_DEVICE_STATUS.getValue());
}});
put(UniversalEnum.THIRTEEN.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.FOURTEEN.getValue(), new HashMap<String, Object>() {{
}});
put(UniversalEnum.FIFTEEN.getValue(), new HashMap<String, Object>() {{
put(UniversalEnum.A_ONE.getValue(), UniversalEnum.QUERY_DATA.getValue());
put(UniversalEnum.A_TWO.getValue(), UniversalEnum.QUERY_DATA.getValue());
put(UniversalEnum.A_THREE.getValue(), UniversalEnum.QUERY_DATA.getValue());
put(UniversalEnum.A_FOUR.getValue(), UniversalEnum.QUERY_DATA.getValue());
put(UniversalEnum.A_FIVE.getValue(), UniversalEnum.QUERY_DATA.getValue());
put(UniversalEnum.A_SIX.getValue(), UniversalEnum.QUERY_DATA.getValue());
}});
put(UniversalEnum.SIXTEEN.getValue(), new HashMap<String, Object>() {{
}});
}};
@AfterReturning(pointcut = "@annotation(operationLog)", returning = "jsonResult")
public void AfterReturning(JoinPoint joinPoint, OperationLog operationLog, Object jsonResult) throws Throwable {
around((ProceedingJoinPoint) joinPoint, operationLog, UniversalEnum.ZERO.getValue(), jsonResult, null);
}
@AfterThrowing(value = "@annotation(operationLog)", throwing = "e")
public void AfterThrowing(JoinPoint joinPoint, OperationLog operationLog, Exception e) throws Throwable {
around((ProceedingJoinPoint) joinPoint, operationLog, UniversalEnum.ONE.getValue(), null, e);
}
public void around(ProceedingJoinPoint joinPoint, OperationLog operationLog, String state, Object jsonResult, Exception exception) throws Throwable {
ISysDeptService deptService = SpringUtils.getBean(ISysDeptService.class);
IDcDeviceService dcDeviceService = SpringUtils.getBean(IDcDeviceService.class);
IDcPublishManageService dcPublishManageService = SpringUtils.getBean(IDcPublishManageService.class);
try {
DcOperLog operLog = new DcOperLog();
String operUrl = operationLog.operUrl();
LoginUser loginUser;
try {
loginUser = SecurityUtils.getLoginUser();
11 months ago
} catch (Exception e) {
loginUser = null;
}
Object[] pointArgs = joinPoint.getArgs();
//String operType = String.valueOf(pointArgs[pointArgs.length - 1]);
//operLog.setOperType(operType);
HttpServletRequest request;
try {
request = ServletUtils.getRequest();
11 months ago
} catch (Exception e) {
request = null;
}
11 months ago
//SimpleDateFormat df = new SimpleDateFormat(UniversalEnum.TIME_FORMAT_ALL.getValue());
//String date = df.format(new Date());
//String sta = UniversalEnum.EMPTY_STRING.getValue();
if (Objects.equals(state, UniversalEnum.ZERO.getValue()) && Objects.equals(String.valueOf(((AjaxResult) jsonResult).get("code")), UniversalEnum.TWO_HUNDRED.getValue()) && !Objects.equals(String.valueOf(((AjaxResult) jsonResult).get("msg")), UniversalEnum.FIVE_HUNDRED.getValue())) {
operLog.setStatus(UniversalEnum.ZERO.getNumber());
//sta = UniversalEnum.SUCCESSFUL.getValue();
11 months ago
} else {
operLog.setStatus(UniversalEnum.ONE.getNumber());
//sta = UniversalEnum.LOSE.getValue();
11 months ago
}
ArrayList<String> deviceIds = new ArrayList<>();
ArrayList<String> deviceNames = new ArrayList<>();
String deviceType = UniversalEnum.EMPTY_STRING.getValue();
StringBuilder remark = new StringBuilder();
if (operUrl.contains(UniversalEnum.BATCH_FUNCTIONS.getValue())) {
//批量调用
JSONObject pointArg = null;
if (pointArgs[UniversalEnum.ZERO.getNumber()] instanceof JSONObject) {
pointArg = (JSONObject) pointArgs[UniversalEnum.ZERO.getNumber()];
} else {
pointArg = (JSONObject) JSON.toJSON(pointArgs[UniversalEnum.ZERO.getNumber()]);
}
//String contentDetails = UniversalEnum.EMPTY_STRING.getValue();
JSONArray devices = pointArg.getJSONArray("devices");
JSONArray functions = pointArg.getJSONArray("functions");
for (int i = UniversalEnum.ZERO.getNumber(); 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);
for (int i1 = UniversalEnum.ZERO.getNumber(); i1 < functions.size(); i1++) {
JSONObject function = (JSONObject) JSON.toJSON(functions.get(i1));
String functionId = function.getString("functionId");
if (Objects.equals(functionId, UniversalEnum.A_ONE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_TWO.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_THREE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_FOUR.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_FIVE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_SIX.getValue()) ||
Objects.equals(functionId, UniversalEnum.ASKMD.getValue()) ||
Objects.equals(functionId, UniversalEnum.ASKTM.getValue()) ||
Objects.equals(functionId, UniversalEnum.ASKDF.getValue()) ||
Objects.equals(functionId, UniversalEnum.FIFTY_TWO.getValue()) ||
Objects.equals(functionId, UniversalEnum.THREE_D.getValue()) ||
Objects.equals(functionId, UniversalEnum.THREE_C.getValue())) {
return;
}
remark.append(deviceName);
String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ?
UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() :
String.valueOf(
((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType)))
.get(functionId) == null ?
UniversalEnum.UNKNOWN_METHOD.getValue() :
((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType)))
.get(functionId));
remark.append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue());
if (i1 < functions.size() - UniversalEnum.ONE.getNumber()) {
remark.append(UniversalEnum.SEMICOLON.getValue());
}
//if (Objects.equals(function.getString("functionId"), UniversalEnum.THIRTEEN.getValue()) && Objects.equals(deviceType, UniversalEnum.TWO.getValue())) {
// JSONArray parameters = function.getJSONObject("params").getJSONArray("parameters");
// List<String> content = parameters.stream().map(item -> ((JSONObject) item).getString("CONTENT")).collect(Collectors.toList());
// contentDetails = content.toString().replace(UniversalEnum.LEFT_CENTER_BRACKET.getValue(), UniversalEnum.EMPTY_STRING.getValue()).replace(UniversalEnum.CLOSE_CENTER_BRACKET.getValue(), UniversalEnum.EMPTY_STRING.getValue());
//}
//
//
//if (Objects.equals(deviceType, UniversalEnum.FIVE.getValue())) {
// contentDetails = function.getJSONObject("params").getString("text");
//}
11 months ago
}
if (i < (devices.size() - UniversalEnum.ONE.getNumber())) {
remark.append(UniversalEnum.COMMA.getValue());
}
}
}
if (loginUser != null) {
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
operLog.setOperName(loginUser.getUsername());
operLog.setDeptName(sysDept.getDeptName());
operLog.setOperLocation(loginUser.getLoginLocation());
operLog.setOperType(UniversalEnum.TWO.getValue());
} else {
operLog.setOperName(UniversalEnum.SERVER.getValue());
operLog.setDeptName(UniversalEnum.SERVER.getValue());
operLog.setOperLocation(UniversalEnum.SERVER.getValue());
operLog.setOperType(UniversalEnum.ONE.getValue());
}
//if (Objects.equals(deviceType, UniversalEnum.FIFTEEN.getValue())) {
// return;
//}
saveOperLog(jsonResult, operLog, pointArgs, request, deviceIds, deviceNames, deviceType, remark);
if ((Objects.equals(deviceType, UniversalEnum.TWO.getValue()) || Objects.equals(deviceType, UniversalEnum.FIVE.getValue())) && Objects.nonNull(operLog.getId())) {
for (int i = UniversalEnum.ZERO.getNumber(); i < devices.size(); i++) {
10 months ago
DcPublishManage dcPublishManage = new DcPublishManage();
if (Objects.equals(state, UniversalEnum.ZERO.getValue()) && Objects.equals(String.valueOf(((AjaxResult) jsonResult).get("code")), UniversalEnum.TWO_HUNDRED.getValue())) {
dcPublishManage.setPublishStatus(UniversalEnum.ONE.getNumber());//发布状态1-成功2-失败
10 months ago
} else {
dcPublishManage.setPublishStatus(UniversalEnum.TWO.getNumber());//发布状态1-成功2-失败
10 months ago
}
10 months ago
if (loginUser != null) {
dcPublishManage.setPublisher(loginUser.getUsername());//发布人
} else {
dcPublishManage.setPublisher(UniversalEnum.SYSTEM_TIMING_CALL.getValue());//发布人
10 months ago
}
dcPublishManage.setPublishTime(new Date());//发布时间
dcPublishManage.setCreateTime(new Date());//创建时间
dcPublishManage.setLogId(Long.valueOf(operLog.getId()));//发布的如果的情报板传对应id
if (Objects.equals(deviceType, UniversalEnum.TWO.getValue())) {
dcPublishManage.setPublishChannels(UniversalEnum.FOUR.getNumber());
10 months ago
} else {
dcPublishManage.setPublishChannels(UniversalEnum.SEVEN.getNumber());
10 months ago
}
dcPublishManage.setContentDetails(JSON.toJSONString(pointArgs));
10 months ago
dcPublishManageService.insertDcPublishManage(dcPublishManage);
}
}
} else if (operUrl.contains(UniversalEnum.FUNCTIONS.getValue())) {
LambdaQueryWrapper<DcDevice> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DcDevice::getIotDeviceId, pointArgs[UniversalEnum.ZERO.getNumber()]);
List<DcDevice> list = dcDeviceService.list(lambdaQueryWrapper);
DcDevice dcDevice = list.get(UniversalEnum.ZERO.getNumber());
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[UniversalEnum.ONE.getNumber()]);
if (Objects.equals(functionId, UniversalEnum.A_ONE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_TWO.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_THREE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_FOUR.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_FIVE.getValue()) ||
Objects.equals(functionId, UniversalEnum.A_SIX.getValue()) ||
Objects.equals(functionId, UniversalEnum.ASKMD.getValue()) ||
Objects.equals(functionId, UniversalEnum.ASKTM.getValue()) ||
Objects.equals(functionId, UniversalEnum.ASKDF.getValue()) ||
Objects.equals(functionId, UniversalEnum.FIFTY_TWO.getValue()) ||
Objects.equals(functionId, UniversalEnum.THREE_D.getValue()) ||
Objects.equals(functionId, UniversalEnum.THREE_C.getValue())) {
return;
}
String hashMap = Objects.equals(deviceType, UniversalEnum.FIVE.getValue()) ? UniversalEnum.RELEASE_VOICE_BROADCAST.getValue() : String.valueOf(((HashMap<String, Object>) (DEVICEFUNCTIONNAME.get(deviceType))).get(functionId));
remark.append(deviceName).append(UniversalEnum.INVOKE.getValue()).append(hashMap).append(UniversalEnum.FEATURE.getValue());
11 months ago
if (loginUser != null) {
SysDept sysDept = deptService.selectDeptById(loginUser.getDeptId());
operLog.setOperName(loginUser.getUsername());
operLog.setDeptName(sysDept.getDeptName());
operLog.setOperLocation(loginUser.getLoginLocation());
operLog.setOperType(UniversalEnum.ZERO.getValue());
11 months ago
} else {
operLog.setOperType(UniversalEnum.ONE.getValue());
11 months ago
}
saveOperLog(jsonResult, operLog, pointArgs, request, deviceIds, deviceNames, deviceType, remark);
//if ((Objects.equals(deviceType, "2") || Objects.equals(deviceType, "5")) && Objects.nonNull(operLog.getId())) {
// DcPublishManage dcPublishManage = new DcPublishManage();
//
// if (Objects.equals(state, "0") && Objects.equals(String.valueOf(((AjaxResult) jsonResult).get("code")), "200")) {
// dcPublishManage.setPublishStatus(1);//发布状态1-成功2-失败
// } else {
// dcPublishManage.setPublishStatus(2);//发布状态1-成功2-失败
// }
//
// if (loginUser != null) {
// dcPublishManage.setPublisher(loginUser.getUsername());//发布人
// } else {
// dcPublishManage.setPublisher("系统定时调用");//发布人
// }
// dcPublishManage.setPublishTime(new Date());//发布时间
// dcPublishManage.setCreateTime(new Date());//创建时间
//
// dcPublishManage.setLogId(Long.valueOf(operLog.getId()));//发布的如果的情报板传对应id
// if (Objects.equals(deviceType, "2")) {
// dcPublishManage.setPublishChannels(4);
// } else {
// dcPublishManage.setPublishChannels(7);
// }
//
// dcPublishManage.setContentDetails(remark.toString());
// dcPublishManageService.insertDcPublishManage(dcPublishManage);
//}
}
}
} catch (Exception e) {
throw e;
}
}
private void saveOperLog(Object jsonResult, DcOperLog operLog, Object[] pointArgs, HttpServletRequest request, ArrayList<String> deviceIds, ArrayList<String> deviceNames, String deviceType, StringBuilder remark) {
IDcOperLogService dcOperLogService = SpringUtils.getBean(IDcOperLogService.class);
JSONArray jsonArray = (JSONArray) JSON.toJSON(pointArgs);
operLog.setOperParam(String.valueOf(jsonArray));
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(jsonResult.toString());
dcOperLogService.save(operLog);
}
}