异常封装之日志信息后台修改

This commit is contained in:
qiankunpingtai
2019-04-18 21:09:37 +08:00
parent 94c64dd905
commit fd7df68740
18 changed files with 141 additions and 63 deletions

View File

@@ -19,16 +19,16 @@ public class LogComponent implements ICommonQuery {
private LogService logService;
@Override
public Object selectOne(String condition) {
public Object selectOne(String condition)throws Exception {
return null;
}
@Override
public List<?> select(Map<String, String> map) {
public List<?> select(Map<String, String> map)throws Exception {
return getUserList(map);
}
private List<?> getUserList(Map<String, String> map) {
private List<?> getUserList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String operation = StringUtil.getInfo(search, "operation");
Integer usernameID = StringUtil.parseInteger(StringUtil.getInfo(search, "usernameID"));
@@ -43,7 +43,7 @@ public class LogComponent implements ICommonQuery {
}
@Override
public Long counts(Map<String, String> map) {
public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH);
String operation = StringUtil.getInfo(search, "operation");
Integer usernameID = StringUtil.parseInteger(StringUtil.getInfo(search, "usernameID"));
@@ -56,27 +56,27 @@ public class LogComponent implements ICommonQuery {
}
@Override
public int insert(String beanJson, HttpServletRequest request) {
public int insert(String beanJson, HttpServletRequest request)throws Exception {
return logService.insertLog(beanJson, request);
}
@Override
public int update(String beanJson, Long id) {
public int update(String beanJson, Long id)throws Exception {
return logService.updateLog(beanJson, id);
}
@Override
public int delete(Long id) {
public int delete(Long id)throws Exception {
return logService.deleteLog(id);
}
@Override
public int batchDelete(String ids) {
public int batchDelete(String ids)throws Exception {
return logService.batchDeleteLog(ids);
}
@Override
public int checkIsNameExist(Long id, String name) {
public int checkIsNameExist(Long id, String name)throws Exception {
return 0;
}

View File

@@ -2,16 +2,15 @@ package com.jsh.erp.service.log;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Log;
import com.jsh.erp.datasource.entities.LogExample;
import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.LogMapper;
import com.jsh.erp.datasource.mappers.LogMapperEx;
import com.jsh.erp.datasource.vo.LogVo4List;
import com.jsh.erp.utils.ExceptionCodeConstants;
import com.jsh.erp.utils.JshException;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.utils.StringUtil;
import com.jsh.erp.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
@@ -19,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.List;
@@ -34,50 +32,122 @@ public class LogService {
@Resource
private LogMapperEx logMapperEx;
public Log getLog(long id) {
return logMapper.selectByPrimaryKey(id);
public Log getLog(long id)throws Exception {
Log result=null;
try{
result=logMapper.selectByPrimaryKey(id);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
public List<Log> getLog() {
public List<Log> getLog()throws Exception {
LogExample example = new LogExample();
return logMapper.selectByExample(example);
List<Log> list=null;
try{
list=logMapper.selectByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
public List<LogVo4List> select(String operation, Integer usernameID, String clientIp, Integer status, String beginTime, String endTime,
String contentdetails, int offset, int rows) {
return logMapperEx.selectByConditionLog(operation, usernameID, clientIp, status, beginTime, endTime,
contentdetails, offset, rows);
String contentdetails, int offset, int rows)throws Exception {
List<LogVo4List> list=null;
try{
list=logMapperEx.selectByConditionLog(operation, usernameID, clientIp, status, beginTime, endTime,
contentdetails, offset, rows);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return list;
}
public Long countLog(String operation, Integer usernameID, String clientIp, Integer status, String beginTime, String endTime,
String contentdetails) {
return logMapperEx.countsByLog(operation, usernameID, clientIp, status, beginTime, endTime, contentdetails);
String contentdetails)throws Exception {
Long result=null;
try{
result=logMapperEx.countsByLog(operation, usernameID, clientIp, status, beginTime, endTime, contentdetails);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_READ_FAIL_CODE,ExceptionConstants.DATA_READ_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_READ_FAIL_CODE,
ExceptionConstants.DATA_READ_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertLog(String beanJson, HttpServletRequest request) {
public int insertLog(String beanJson, HttpServletRequest request) throws Exception{
Log log = JSONObject.parseObject(beanJson, Log.class);
return logMapper.insertSelective(log);
int result=0;
try{
result=logMapper.insertSelective(log);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateLog(String beanJson, Long id) {
public int updateLog(String beanJson, Long id)throws Exception {
Log log = JSONObject.parseObject(beanJson, Log.class);
log.setId(id);
return logMapper.updateByPrimaryKeySelective(log);
int result=0;
try{
result=logMapper.updateByPrimaryKeySelective(log);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteLog(Long id) {
return logMapper.deleteByPrimaryKey(id);
public int deleteLog(Long id)throws Exception {
int result=0;
try{
result=logMapper.deleteByPrimaryKey(id);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteLog(String ids) {
public int batchDeleteLog(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids);
LogExample example = new LogExample();
example.createCriteria().andIdIn(idList);
return logMapper.deleteByExample(example);
int result=0;
try{
result=logMapper.deleteByExample(example);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
return result;
}
/**
@@ -85,7 +155,7 @@ public class LogService {
* @param request
* @return
*/
public Long getUserId(HttpServletRequest request) {
public Long getUserId(HttpServletRequest request) throws Exception{
Object userInfo = request.getSession().getAttribute("user");
if(userInfo!=null) {
User user = (User) userInfo;
@@ -95,7 +165,7 @@ public class LogService {
}
}
public String getModule(String apiName){
public String getModule(String apiName)throws Exception{
String moduleName = null;
switch (apiName) {
case BusinessConstants.LOG_INTERFACE_NAME_USER:
@@ -144,7 +214,7 @@ public class LogService {
return moduleName;
}
public void insertLog(String apiName, String type, HttpServletRequest request){
public void insertLog(String apiName, String type, HttpServletRequest request)throws Exception{
Log log = new Log();
log.setUserid(getUserId(request));
log.setOperation(getModule(apiName));
@@ -154,7 +224,15 @@ public class LogService {
log.setStatus(status);
log.setContentdetails(type + getModule(apiName));
log.setRemark(type + getModule(apiName));
logMapper.insertSelective(log);
try{
logMapper.insertSelective(log);
}catch(Exception e){
logger.error("异常码[{}],异常提示[{}],异常[{}]",
ExceptionConstants.DATA_WRITE_FAIL_CODE,ExceptionConstants.DATA_WRITE_FAIL_MSG,e);
throw new BusinessRunTimeException(ExceptionConstants.DATA_WRITE_FAIL_CODE,
ExceptionConstants.DATA_WRITE_FAIL_MSG);
}
}
}

View File

@@ -150,7 +150,7 @@ public class MaterialService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetEnable(Boolean enabled, String materialIDs) {
public int batchSetEnable(Boolean enabled, String materialIDs)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_MATERIAL,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(materialIDs).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -217,7 +217,7 @@ public class MaterialService {
return materialMapperEx.getMaterialEnableSerialNumberList(parameterMap);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialByIds(String ids) {
public int batchDeleteMaterialByIds(String ids) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_MATERIAL,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -164,7 +164,7 @@ public class MaterialCategoryService {
return materialCategoryMapperEx.batchDeleteMaterialCategoryByIds(updateDate,updater,strArray);
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int editMaterialCategory(MaterialCategory mc) {
public int editMaterialCategory(MaterialCategory mc) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_MATERIAL_CATEGORY,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(mc.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -84,7 +84,7 @@ public class MaterialPropertyService {
return 0;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteMaterialPropertyByIds(String ids) {
public int batchDeleteMaterialPropertyByIds(String ids) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_MATERIAL_PROPERTY,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -117,7 +117,7 @@ public class PersonService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeletePersonByIds(String ids) {
public int batchDeletePersonByIds(String ids)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_PERSON,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -98,7 +98,7 @@ public class RoleService {
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteRoleByIds(String ids) {
public int batchDeleteRoleByIds(String ids) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -51,7 +51,7 @@ public class SerialNumberComponent implements ICommonQuery {
}
@Override
public int insert(String beanJson, HttpServletRequest request) {
public int insert(String beanJson, HttpServletRequest request)throws Exception {
return serialNumberService.insertSerialNumber(beanJson, request);
}

View File

@@ -67,7 +67,7 @@ public class SerialNumberService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSerialNumber(String beanJson, HttpServletRequest request) {
public int insertSerialNumber(String beanJson, HttpServletRequest request)throws Exception {
SerialNumber serialNumber = JSONObject.parseObject(beanJson, SerialNumber.class);
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER, BusinessConstants.LOG_OPERATION_TYPE_ADD, request);
return serialNumberMapper.insertSelective(serialNumber);
@@ -169,7 +169,7 @@ public class SerialNumberService {
* 新增序列号信息
* */
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public SerialNumberEx addSerialNumber(SerialNumberEx serialNumberEx) {
public SerialNumberEx addSerialNumber(SerialNumberEx serialNumberEx) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER,BusinessConstants.LOG_OPERATION_TYPE_ADD,
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
if(serialNumberEx==null){
@@ -194,7 +194,7 @@ public class SerialNumberService {
return null;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public SerialNumberEx updateSerialNumber(SerialNumberEx serialNumberEx) {
public SerialNumberEx updateSerialNumber(SerialNumberEx serialNumberEx)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(serialNumberEx.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -351,7 +351,7 @@ public class SerialNumberService {
* @return java.lang.Object
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void batAddSerialNumber(String materialName, String serialNumberPrefix, Integer batAddTotal, String remark) {
public void batAddSerialNumber(String materialName, String serialNumberPrefix, Integer batAddTotal, String remark)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_BATCH_ADD).append(batAddTotal).append(BusinessConstants.LOG_DATA_UNIT).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -401,7 +401,7 @@ public class SerialNumberService {
* @return
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSerialNumberByIds(String ids) {
public int batchDeleteSerialNumberByIds(String ids) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SERIAL_NUMBER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -99,7 +99,7 @@ public class SupplierService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateAdvanceIn(Long supplierId, BigDecimal advanceIn){
public int updateAdvanceIn(Long supplierId, BigDecimal advanceIn)throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SUPPLIER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(supplierId).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -145,7 +145,7 @@ public class SupplierService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchSetEnable(Boolean enabled, String supplierIDs) {
public int batchSetEnable(Boolean enabled, String supplierIDs)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SUPPLIER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(supplierIDs).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -191,7 +191,7 @@ public class SupplierService {
return info;
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSupplierByIds(String ids) {
public int batchDeleteSupplierByIds(String ids)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SUPPLIER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -87,7 +87,7 @@ public class SystemConfigService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSystemConfigByIds(String ids) {
public int batchDeleteSystemConfigByIds(String ids)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_SYSTEM_CONFIG,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -94,7 +94,7 @@ public class UnitService {
return list.size();
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUnitByIds(String ids) {
public int batchDeleteUnitByIds(String ids)throws Exception {
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_UNIT,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -114,7 +114,7 @@ public class UserService {
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateUserByObj(User user) {
public int updateUserByObj(User user) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(user.getId()).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -130,7 +130,7 @@ public class UserService {
* @return int
*/
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int resetPwd(String md5Pwd, Long id) {
public int resetPwd(String md5Pwd, Long id) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(id).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -467,7 +467,7 @@ public class UserService {
* 批量删除用户
* */
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public void batDeleteUser(String ids) {
public void batDeleteUser(String ids) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());

View File

@@ -142,7 +142,7 @@ public class UserBusinessService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateBtnStr(Long userBusinessId, String btnStr) {
public int updateBtnStr(Long userBusinessId, String btnStr) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER_BUSINESS,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(userBusinessId).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
@@ -171,7 +171,7 @@ public class UserBusinessService {
}
@Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteUserBusinessByIds(String ids) {
public int batchDeleteUserBusinessByIds(String ids) throws Exception{
logService.insertLog(BusinessConstants.LOG_INTERFACE_NAME_USER_BUSINESS,
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_DELETE).append(ids).toString(),
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());