新增 用户UI操作日志开关功能
This commit is contained in:
+63
-22
@@ -6,6 +6,7 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
|
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -22,12 +23,14 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.gzzn.omms.adminapi.domain.primary.dao.settings.UisettingsDao;
|
import com.gzzn.omms.adminapi.domain.primary.dao.settings.UisettingsDao;
|
||||||
import com.gzzn.omms.adminapi.domain.primary.entity.settings.Uisettings;
|
import com.gzzn.omms.adminapi.domain.primary.entity.settings.Uisettings;
|
||||||
|
import com.gzzn.omms.adminapi.dto.OpLogSwitchDto;
|
||||||
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
||||||
import com.gzzn.omms.adminapi.dto.settings.UisettingsDto;
|
import com.gzzn.omms.adminapi.dto.settings.UisettingsDto;
|
||||||
import com.gzzn.omms.adminapi.dto.settings.convert.UisettingsConvert;
|
import com.gzzn.omms.adminapi.dto.settings.convert.UisettingsConvert;
|
||||||
import com.gzzn.omms.adminapi.elasticsearch.CommCode;
|
import com.gzzn.omms.adminapi.elasticsearch.CommCode;
|
||||||
import com.gzzn.omms.adminapi.elasticsearch.ElasticsearchUtil;
|
import com.gzzn.omms.adminapi.elasticsearch.ElasticsearchUtil;
|
||||||
import com.gzzn.omms.adminapi.elasticsearch.UserOptLog;
|
import com.gzzn.omms.adminapi.elasticsearch.UserOptLog;
|
||||||
|
import com.gzzn.omms.adminapi.service.IOplogSwithcInfoService;
|
||||||
import com.gzzn.omms.adminapi.service.IUserService;
|
import com.gzzn.omms.adminapi.service.IUserService;
|
||||||
import com.gzzn.omms.adminapi.utils.CommonUtils;
|
import com.gzzn.omms.adminapi.utils.CommonUtils;
|
||||||
import com.gzzn.omms.adminapi.utils.JsonUtil;
|
import com.gzzn.omms.adminapi.utils.JsonUtil;
|
||||||
@@ -60,7 +63,9 @@ public class UISettingsController {
|
|||||||
*/
|
*/
|
||||||
@Autowired
|
@Autowired
|
||||||
private IUserService userService;
|
private IUserService userService;
|
||||||
|
@Autowired
|
||||||
|
private IOplogSwithcInfoService oplogSwithcInfoService;
|
||||||
|
private List<OpLogSwitchDto> opLogSwitchInfos = null;
|
||||||
/**
|
/**
|
||||||
* 根据条件查找当前用户所有UI设置
|
* 根据条件查找当前用户所有UI设置
|
||||||
* @return
|
* @return
|
||||||
@@ -127,31 +132,67 @@ public class UISettingsController {
|
|||||||
uisettings.setUserid(userService.getCurrentUserId());
|
uisettings.setUserid(userService.getCurrentUserId());
|
||||||
uisettings = uisettingsDao.save(uisettings);
|
uisettings = uisettingsDao.save(uisettings);
|
||||||
|
|
||||||
try {
|
if(ifNeedMarkLog(CommCode.OPLOG_LOG_TYPE_LEVEL,CommCode.LOG_TYPE_UISETTING)){ //操作日志开关控制
|
||||||
if (!ElasticsearchUtil.isIndexExist(INDEX_NAME)) {
|
try {
|
||||||
ElasticsearchUtil.createIndex(INDEX_NAME);
|
if (!ElasticsearchUtil.isIndexExist(INDEX_NAME)) {
|
||||||
}
|
ElasticsearchUtil.createIndex(INDEX_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
InetSocketAddress remoteAddress = userService.getUserRemoteAddress();
|
InetSocketAddress remoteAddress = userService.getUserRemoteAddress();
|
||||||
UserOptLog oplog = new UserOptLog(userService.getCurrentUserId(),userService.getCurrentUserName(),
|
UserOptLog oplog = new UserOptLog(userService.getCurrentUserId(),userService.getCurrentUserName(),
|
||||||
userService.getCurrentUserRealName(), null==remoteAddress?"未知":remoteAddress.getHostString(),
|
userService.getCurrentUserRealName(), null==remoteAddress?"未知":remoteAddress.getHostString(),
|
||||||
System.currentTimeMillis());
|
System.currentTimeMillis());
|
||||||
oplog.setOpt_type(optType);
|
oplog.setOpt_type(optType);
|
||||||
oplog.setLog_type(CommCode.LOG_TYPE_UISETTING);
|
oplog.setLog_type(CommCode.LOG_TYPE_UISETTING);
|
||||||
oplog.setSummary("保存用户{"+userService.getCurrentUserName()+"}的UI设置");
|
oplog.setSummary("保存用户{"+userService.getCurrentUserName()+"}的UI设置");
|
||||||
//设置日志类容 jsonarry 历史及最新的
|
//设置日志类容 jsonarry 历史及最新的
|
||||||
JSONObject log_content = new JSONObject();
|
JSONObject log_content = new JSONObject();
|
||||||
log_content.put("newData", JsonUtil.getString(uisettings));
|
log_content.put("newData", JsonUtil.getString(uisettings));
|
||||||
log_content.put("oldData", oldData);
|
log_content.put("oldData", oldData);
|
||||||
oplog.setLog_content(log_content.toString());
|
oplog.setLog_content(log_content.toString());
|
||||||
JSONObject logJson = JSONObject.parseObject(JsonUtil.getString(oplog));
|
JSONObject logJson = JSONObject.parseObject(JsonUtil.getString(oplog));
|
||||||
String id = ElasticsearchUtil.addData(logJson, INDEX_NAME, OPLOG_ES_TYPE);
|
String id = ElasticsearchUtil.addData(logJson, INDEX_NAME, OPLOG_ES_TYPE);
|
||||||
logger.info("保存用户设置UI操作日志至Elatsticsearch成功:id="+id);
|
logger.info("保存用户设置UI操作日志至Elatsticsearch成功:id="+id);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("保存用户设置UI操作日志至Elatsticsearch异常:", e);
|
logger.error("保存用户设置UI操作日志至Elatsticsearch异常:", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResponseDto.success(uisettings.getId());
|
return ResponseDto.success(uisettings.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化日志开关信息
|
||||||
|
*/
|
||||||
|
private void intOpLogSwitchInfos(){
|
||||||
|
if(null==this.opLogSwitchInfos || this.opLogSwitchInfos.size()<=0){
|
||||||
|
UserOptLog userOptLog = new UserOptLog();
|
||||||
|
this.opLogSwitchInfos = oplogSwithcInfoService.getOpLogSwitchByLevleAndName(CommCode.OPLOG_MODEL_LEVEL, userOptLog.getModel_name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 通过level 和name 查询是否需要进行日志记录
|
||||||
|
* @param level
|
||||||
|
* @param name
|
||||||
|
* @return true:需要 false:不需要
|
||||||
|
*/
|
||||||
|
private Boolean ifNeedMarkLog(Byte level,String name){
|
||||||
|
this.intOpLogSwitchInfos();
|
||||||
|
Boolean needMark = true;
|
||||||
|
for(Object obj:this.opLogSwitchInfos){
|
||||||
|
LinkedHashMap<String, Object> linkMap = (LinkedHashMap<String, Object>) obj;
|
||||||
|
Integer objLevel = (Integer) linkMap.get("level");
|
||||||
|
String objName = (String) linkMap.get("name");
|
||||||
|
Boolean objIfSwitch = (Boolean) linkMap.get("ifSwitch");
|
||||||
|
if(objLevel<level.intValue() && !objIfSwitch){ //父级直接比较level
|
||||||
|
needMark = false;
|
||||||
|
break;
|
||||||
|
}else if(objLevel==level.intValue() && objName.equals(name) && !objIfSwitch){ //统计必须还得比较name
|
||||||
|
needMark = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return needMark;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.gzzn.omms.adminapi.dto;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author fhc
|
||||||
|
* @Description: 操作日志开关DTO
|
||||||
|
* @date 2018年11月13日
|
||||||
|
*/
|
||||||
|
public class OpLogSwitchDto {
|
||||||
|
/**
|
||||||
|
* 主键
|
||||||
|
*/
|
||||||
|
private String id ;
|
||||||
|
/**
|
||||||
|
* 自身类关联的附件
|
||||||
|
*/
|
||||||
|
private String pid;
|
||||||
|
/**
|
||||||
|
* 级别,0:应用类别、1:模块类别、2:业务类别、3:操作类别
|
||||||
|
*/
|
||||||
|
private Byte level;
|
||||||
|
/**
|
||||||
|
* 英文名(level=1,2,3 的name 请最好保持唯一)
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
/**
|
||||||
|
* 中文名
|
||||||
|
*/
|
||||||
|
private String zhName;
|
||||||
|
/**
|
||||||
|
* 是否开启
|
||||||
|
*/
|
||||||
|
private Boolean ifSwitch;
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
public String getPid() {
|
||||||
|
return pid;
|
||||||
|
}
|
||||||
|
public void setPid(String pid) {
|
||||||
|
this.pid = pid;
|
||||||
|
}
|
||||||
|
public Byte getLevel() {
|
||||||
|
return level;
|
||||||
|
}
|
||||||
|
public void setLevel(Byte level) {
|
||||||
|
this.level = level;
|
||||||
|
}
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
public String getZhName() {
|
||||||
|
return zhName;
|
||||||
|
}
|
||||||
|
public void setZhName(String zhName) {
|
||||||
|
this.zhName = zhName;
|
||||||
|
}
|
||||||
|
public Boolean getIfSwitch() {
|
||||||
|
return ifSwitch;
|
||||||
|
}
|
||||||
|
public void setIfSwitch(Boolean ifSwitch) {
|
||||||
|
this.ifSwitch = ifSwitch;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "OpLogSwitchDto [id=" + id + ", pid=" + pid + ", level=" + level
|
||||||
|
+ ", name=" + name + ", zhName=" + zhName + ", ifSwitch="
|
||||||
|
+ ifSwitch + "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,4 +31,22 @@ public class CommCode {
|
|||||||
* 新增修改删除用户信息
|
* 新增修改删除用户信息
|
||||||
*/
|
*/
|
||||||
public static final String LOG_TYPE_USEROPT = "USER_INFO_OPT";
|
public static final String LOG_TYPE_USEROPT = "USER_INFO_OPT";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作日志级别:应用
|
||||||
|
*/
|
||||||
|
public static final Byte OPLOG_APP_LEVEL = 0;
|
||||||
|
/**
|
||||||
|
* 操作日志级别:模块
|
||||||
|
*/
|
||||||
|
public static final Byte OPLOG_MODEL_LEVEL = 1;
|
||||||
|
/**
|
||||||
|
* 操作日志级别:业务
|
||||||
|
*/
|
||||||
|
public static final Byte OPLOG_LOG_TYPE_LEVEL = 1;
|
||||||
|
/**
|
||||||
|
* 操作日志级别:操作
|
||||||
|
*/
|
||||||
|
public static final Byte OPLOG_OPT_TYPE_LEVEL = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class UserOptLog {
|
|||||||
/**
|
/**
|
||||||
* 模块名
|
* 模块名
|
||||||
*/
|
*/
|
||||||
private String model_name = "sysapi";
|
private String model_name = "adminapi";
|
||||||
/**
|
/**
|
||||||
* 日志详情
|
* 日志详情
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.gzzn.omms.adminapi.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.gzzn.omms.adminapi.dto.OpLogSwitchDto;
|
||||||
|
|
||||||
|
|
||||||
|
public interface IOplogSwithcInfoService {
|
||||||
|
|
||||||
|
public List<OpLogSwitchDto> getOpLogSwitchByLevleAndName(Byte level,String name);
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.gzzn.omms.adminapi.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
|
import com.gzzn.omms.adminapi.dto.OpLogSwitchDto;
|
||||||
|
import com.gzzn.omms.adminapi.dto.ResponseDto;
|
||||||
|
import com.gzzn.omms.adminapi.service.IOplogSwithcInfoService;
|
||||||
|
import com.gzzn.omms.adminapi.utils.JsonUtil;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class OplogSwithcInfoServiceImpl implements IOplogSwithcInfoService{
|
||||||
|
|
||||||
|
@Value("${sysApi.getOpLogSwitchByLevleAndNameUrl}")
|
||||||
|
private String getOpLogSwitchByLevleAndNameUrl;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RestTemplate restTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OpLogSwitchDto> getOpLogSwitchByLevleAndName(Byte level,String name) {
|
||||||
|
String url = getOpLogSwitchByLevleAndNameUrl;
|
||||||
|
url = url.replace("{level}", level.toString())
|
||||||
|
.replace("{name}", name);
|
||||||
|
ResponseEntity<ResponseDto> responseEntity = restTemplate
|
||||||
|
.getForEntity(url, ResponseDto.class);
|
||||||
|
|
||||||
|
if(!responseEntity.getStatusCode().equals(HttpStatus.OK))
|
||||||
|
{
|
||||||
|
throw new RuntimeException("获取公共url信息失败:" + responseEntity.getStatusCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
ResponseDto responseDto = responseEntity.getBody();
|
||||||
|
|
||||||
|
if(responseDto.getIs_success() == false)
|
||||||
|
{
|
||||||
|
throw new RuntimeException("获取公共url信息失败::" + responseDto.getErr_code() + ",msg:"+responseDto.getErr_msg());
|
||||||
|
}
|
||||||
|
|
||||||
|
String srtJson = JsonUtil.getString(responseDto.getBody());
|
||||||
|
List<OpLogSwitchDto> result = JsonUtil.getObject(srtJson, List.class);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user