完善记录日志的功能

This commit is contained in:
季圣华
2019-01-20 23:14:40 +08:00
parent 249961ab76
commit 0ceb925bf4
4 changed files with 98 additions and 7 deletions

View File

@@ -122,7 +122,9 @@
{title: '操作IP', field: 'clientip', width: 90, align: "center"},
{title: '操作时间', field: 'createtime', width: 130, align: "center"},
{title: '操作详情', field: 'remark', width: 380},
{title: '操作状态', field: 'status', width: 70},
{title: '操作状态',field: 'status',width:70,align:"center",formatter:function(value){
return value? "失败":"成功";
}},
{title: '备注', field: 'remark', width: 180}
]],
onLoadError: function () {

View File

@@ -74,7 +74,7 @@ public class ResourceController {
@RequestParam("info") String beanJson,
@RequestParam("id") Long id, HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int update = configResourceManager.update(apiName, beanJson, id);
int update = configResourceManager.update(apiName, beanJson, id, request);
if(update > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
@@ -86,7 +86,7 @@ public class ResourceController {
public String deleteResource(@PathVariable("apiName") String apiName,
@PathVariable Long id, HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int delete = configResourceManager.delete(apiName, id);
int delete = configResourceManager.delete(apiName, id, request);
if(delete > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
@@ -98,7 +98,7 @@ public class ResourceController {
public String batchDeleteResource(@PathVariable("apiName") String apiName,
@RequestParam("ids") String ids, HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int delete = configResourceManager.batchDelete(apiName, ids);
int delete = configResourceManager.batchDelete(apiName, ids, request);
if(delete > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {

View File

@@ -1,5 +1,8 @@
package com.jsh.erp.service;
import com.jsh.erp.datasource.entities.Log;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.LogMapper;
import com.jsh.erp.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -7,9 +10,12 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.Tools.getLocalIp;
/**
* @author jishenghua 752718920 2018-10-7 15:25:58
*/
@@ -19,6 +25,9 @@ public class CommonQueryManager {
@Resource
private InterfaceContainer container;
@Resource
private LogMapper logMapper;
/**
* 查询单条
*
@@ -67,6 +76,7 @@ public class CommonQueryManager {
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insert(String apiName, String beanJson, HttpServletRequest request) {
if (StringUtil.isNotEmpty(apiName)) {
insertLog(apiName, "新增", request);
return container.getCommonQuery(apiName).insert(beanJson, request);
}
return 0;
@@ -80,8 +90,9 @@ public class CommonQueryManager {
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int update(String apiName, String beanJson, Long id) {
public int update(String apiName, String beanJson, Long id, HttpServletRequest request) {
if (StringUtil.isNotEmpty(apiName)) {
insertLog(apiName, "更新,id:" + id, request);
return container.getCommonQuery(apiName).update(beanJson, id);
}
return 0;
@@ -94,8 +105,9 @@ public class CommonQueryManager {
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int delete(String apiName, Long id) {
public int delete(String apiName, Long id, HttpServletRequest request) {
if (StringUtil.isNotEmpty(apiName)) {
insertLog(apiName, "删除,id:" + id, request);
return container.getCommonQuery(apiName).delete(id);
}
return 0;
@@ -108,8 +120,9 @@ public class CommonQueryManager {
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDelete(String apiName, String ids) {
public int batchDelete(String apiName, String ids, HttpServletRequest request) {
if (StringUtil.isNotEmpty(apiName)) {
insertLog(apiName, "批量删除,id集:" + ids, request);
return container.getCommonQuery(apiName).batchDelete(ids);
}
return 0;
@@ -129,4 +142,78 @@ public class CommonQueryManager {
return 0;
}
/**
* 获取用户id
* @param request
* @return
*/
public Long getUserId(HttpServletRequest request) {
Object userInfo = request.getSession().getAttribute("user");
if(userInfo!=null) {
User user = (User) userInfo;
return user.getId();
} else {
return null;
}
}
public String getModule(String apiName){
String moduleName = null;
switch (apiName) {
case "user":
moduleName = "用户"; break;
case "role":
moduleName = "角色"; break;
case "app":
moduleName = "应用"; break;
case "depot":
moduleName = "仓库"; break;
case "functions":
moduleName = "功能"; break;
case "inOutItem":
moduleName = "收支项目"; break;
case "unit":
moduleName = "计量单位"; break;
case "person":
moduleName = "经手人"; break;
case "userBusiness":
moduleName = "关联关系"; break;
case "systemConfig":
moduleName = "系统配置"; break;
case "materialProperty":
moduleName = "商品属性"; break;
case "account":
moduleName = "账户"; break;
case "supplier":
moduleName = "商家"; break;
case "materialCategory":
moduleName = "商品类型"; break;
case "material":
moduleName = "商品"; break;
case "depotHead":
moduleName = "单据表头"; break;
case "depotItem":
moduleName = "单据明细"; break;
case "accountHead":
moduleName = "财务表头"; break;
case "accountItem":
moduleName = "财务明细"; break;
}
return moduleName;
}
public void insertLog(String apiName, String type, HttpServletRequest request){
Log log = new Log();
log.setUserid(getUserId(request));
log.setOperation(getModule(apiName));
log.setClientip(getLocalIp(request));
log.setCreatetime(new Date());
Byte status = 0;
log.setStatus(status);
log.setContentdetails(type + getModule(apiName));
log.setRemark(type + getModule(apiName));
logMapper.insertSelective(log);
}
}

View File

@@ -1,5 +1,7 @@
package com.jsh.erp.utils;
import com.alibaba.druid.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.UnsupportedEncodingException;