Merge remote-tracking branch 'origin/feature-ui-fix' into feature-ui-fix
This commit is contained in:
+10
@@ -31,4 +31,14 @@ public interface BaseCommonService {
|
||||
*/
|
||||
void addLog(String logContent, Integer logType, Integer operateType);
|
||||
|
||||
/**
|
||||
* 保存日志 耗时
|
||||
* @param logContent
|
||||
* @param logType
|
||||
* @param operatetype
|
||||
* @param user
|
||||
* @param cost_time
|
||||
*/
|
||||
void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user,Long cost_time);
|
||||
|
||||
}
|
||||
|
||||
+44
-11
@@ -1,26 +1,20 @@
|
||||
package com.jero.modules.base.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import com.jero.common.api.dto.LogDTO;
|
||||
import com.jero.common.constant.CacheConstant;
|
||||
import com.jero.modules.base.mapper.BaseCommonMapper;
|
||||
import com.jero.modules.base.service.BaseCommonService;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.system.vo.SysPermissionDataRuleModel;
|
||||
import com.jero.common.system.vo.SysUserCacheInfo;
|
||||
import com.jero.common.util.IPUtils;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import com.jero.modules.base.mapper.BaseCommonMapper;
|
||||
import com.jero.modules.base.service.BaseCommonService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.AntPathMatcher;
|
||||
import org.springframework.util.PathMatcher;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.*;
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -87,5 +81,44 @@ public class BaseCommonServiceImpl implements BaseCommonService {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addLog(String logContent, Integer logType, Integer operatetype, LoginUser user,Long cost_time) {
|
||||
LogDTO sysLog = new LogDTO();
|
||||
sysLog.setId(String.valueOf(IdWorker.getId()));
|
||||
//注解上的描述,操作日志内容
|
||||
sysLog.setLogContent(logContent);
|
||||
sysLog.setLogType(logType);
|
||||
sysLog.setOperateType(operatetype);
|
||||
sysLog.setCostTime(cost_time);
|
||||
try {
|
||||
//获取request
|
||||
HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
|
||||
//设置IP地址
|
||||
sysLog.setIp(IPUtils.getIpAddr(request));
|
||||
} catch (Exception e) {
|
||||
sysLog.setIp("127.0.0.1");
|
||||
}
|
||||
//获取登录用户信息
|
||||
if(user==null){
|
||||
try {
|
||||
user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
} catch (Exception e) {
|
||||
log.error("异常",e.getMessage());
|
||||
}
|
||||
}
|
||||
if(user!=null){
|
||||
sysLog.setUserid(user.getUsername());
|
||||
sysLog.setUsername(user.getRealname());
|
||||
}
|
||||
sysLog.setCreateTime(new Date());
|
||||
//保存日志(异常捕获处理,防止数据太大存储失败,导致业务失败)JT-238
|
||||
try {
|
||||
baseCommonMapper.saveLog(sysLog);
|
||||
} catch (Exception e) {
|
||||
log.warn(" LogContent length : "+sysLog.getLogContent().length());
|
||||
log.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -376,7 +376,7 @@ public class SysDepartController {
|
||||
return ImportExcelUtil.imporReturnRes(errorMessageList.size(), listSysDeparts.size() - errorMessageList.size(), errorMessageList);
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(),e);
|
||||
return Results.error("文件导入失败:"+e.getMessage());
|
||||
return Results.error("导入失败,请联系管理员");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
|
||||
+26
-5
@@ -224,13 +224,19 @@ public class SysUserController {
|
||||
String rsaPrivateKey = String.valueOf(redisUtil.get(rsaPublicKey));
|
||||
try {
|
||||
SysUser sysUser = sysUserService.getById(jsonObject.getString("id"));
|
||||
baseCommonService.addLog("编辑用户,id: " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2);
|
||||
if(sysUser==null) {
|
||||
return Results.error(INEXISTENCE);
|
||||
}else {
|
||||
//开始时间
|
||||
long startTime = System.currentTimeMillis();
|
||||
SysUser user = getSysUser(jsonObject, rsaPrivateKey, sysUser);
|
||||
// 修改用户走一个service 保证事务
|
||||
sysUserService.editUser(user, roles, departs);
|
||||
//结束时间
|
||||
long endTime = System.currentTimeMillis();
|
||||
long costTime = endTime - startTime;
|
||||
baseCommonService.addLog("编辑用户,id: " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2,null,
|
||||
costTime);
|
||||
return Results.OK(OPTION_SUCCESS);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
@@ -267,24 +273,31 @@ public class SysUserController {
|
||||
@PostMapping("/delete")
|
||||
@RequiresPermissions("sys:user:sel")
|
||||
public Results<T> delete(@RequestBody Map<String,String> map) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
String id = map.get("id");
|
||||
if(StringUtils.isBlank(id)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
baseCommonService.addLog("删除用户,id: " +id ,CommonConstant.LOG_TYPE_2, 3);
|
||||
this.sysUserService.deleteUser(id);
|
||||
long endTime = System.currentTimeMillis();
|
||||
long costTime = endTime - startTime;
|
||||
baseCommonService.addLog("删除用户,id: " +id ,CommonConstant.LOG_TYPE_2, 3,null,costTime);
|
||||
return Results.OK("删除用户成功");
|
||||
}
|
||||
|
||||
@PostMapping("/deleteBatch")
|
||||
@RequiresPermissions("sys:user:sel")
|
||||
public Results<T> deleteBatch(@RequestBody Map<String, String> map) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
String ids = map.get("ids");
|
||||
if(StringUtils.isBlank(ids)){
|
||||
return Results.error("参数不识别!");
|
||||
}
|
||||
baseCommonService.addLog("批量删除用户, ids: " +ids ,CommonConstant.LOG_TYPE_2, 3);
|
||||
this.sysUserService.deleteBatchUsers(ids);
|
||||
|
||||
long endTime = System.currentTimeMillis();
|
||||
long costTime = endTime - startTime;
|
||||
baseCommonService.addLog("批量删除用户, ids: " +ids ,CommonConstant.LOG_TYPE_2, 3,null,costTime);
|
||||
return Results.OK("批量删除用户成功");
|
||||
}
|
||||
|
||||
@@ -1244,9 +1257,9 @@ public class SysUserController {
|
||||
public Results<SysUser> appEdit(HttpServletRequest request, @RequestBody JSONObject jsonObject) {
|
||||
Results<SysUser> result = new Results<>();
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
String username = JwtUtil.getUserNameByToken(request);
|
||||
SysUser sysUser = sysUserService.getUserByName(username);
|
||||
baseCommonService.addLog("移动端编辑用户,id: " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2);
|
||||
String realname=jsonObject.getString("realname");
|
||||
String avatar=jsonObject.getString("avatar");
|
||||
String sex=jsonObject.getString("sex");
|
||||
@@ -1266,6 +1279,9 @@ public class SysUserController {
|
||||
setUserInfo(sysUser, realname, avatar, sex, phone, email, birthday);
|
||||
sysUserService.updateById(sysUser);
|
||||
}
|
||||
long endTime = System.currentTimeMillis();
|
||||
long costTime = endTime - startTime;
|
||||
baseCommonService.addLog("移动端编辑用户,id: " +jsonObject.getString("id") ,CommonConstant.LOG_TYPE_2, 2,null,costTime);
|
||||
} catch (Exception e) {
|
||||
SysUserController.log.error(e.getMessage(), e);
|
||||
return Results.error("操作失败!");
|
||||
@@ -1442,12 +1458,14 @@ public class SysUserController {
|
||||
@PostMapping(value = "/setRole")
|
||||
public Results<SysUser> setRole(@RequestBody JSONObject jsonObject) {
|
||||
try {
|
||||
long startTime = System.currentTimeMillis();
|
||||
String ids = jsonObject.getString("ids");
|
||||
String roles = jsonObject.getString(SELECTED_ROLES);
|
||||
List<String> idList = Arrays.asList(ids.split(","));
|
||||
long endTime;
|
||||
long costTime;
|
||||
for (String id : idList) {
|
||||
SysUser sysUser = sysUserService.getById(id);
|
||||
baseCommonService.addLog("编辑用户角色,id: " + id, CommonConstant.LOG_TYPE_2, 2);
|
||||
if (sysUser == null) {
|
||||
return Results.error(INEXISTENCE);
|
||||
} else {
|
||||
@@ -1455,6 +1473,9 @@ public class SysUserController {
|
||||
user.setId(id);
|
||||
user.setUpdateTime(new Date());
|
||||
sysUserService.addRoleToUser(user, roles);
|
||||
endTime = System.currentTimeMillis();
|
||||
costTime = endTime - startTime;
|
||||
baseCommonService.addLog("编辑用户角色,id: " + id, CommonConstant.LOG_TYPE_2, 2,null,costTime);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user