异常封装之系统配置信息后台修改

This commit is contained in:
qiankunpingtai
2019-04-19 14:36:12 +08:00
parent 05fb1e38c7
commit b7694fa4d8
2 changed files with 121 additions and 29 deletions

View File

@@ -21,16 +21,16 @@ public class SystemConfigComponent implements ICommonQuery {
private SystemConfigService systemConfigService; private SystemConfigService systemConfigService;
@Override @Override
public Object selectOne(String condition) { public Object selectOne(String condition)throws Exception {
return null; return null;
} }
@Override @Override
public List<?> select(Map<String, String> map) { public List<?> select(Map<String, String> map)throws Exception {
return getSystemConfigList(map); return getSystemConfigList(map);
} }
private List<?> getSystemConfigList(Map<String, String> map) { private List<?> getSystemConfigList(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH); String search = map.get(Constants.SEARCH);
String companyName = StringUtil.getInfo(search, "companyName"); String companyName = StringUtil.getInfo(search, "companyName");
String order = QueryUtils.order(map); String order = QueryUtils.order(map);
@@ -38,34 +38,34 @@ public class SystemConfigComponent implements ICommonQuery {
} }
@Override @Override
public Long counts(Map<String, String> map) { public Long counts(Map<String, String> map)throws Exception {
String search = map.get(Constants.SEARCH); String search = map.get(Constants.SEARCH);
String companyName = StringUtil.getInfo(search, "companyName"); String companyName = StringUtil.getInfo(search, "companyName");
return systemConfigService.countSystemConfig(companyName); return systemConfigService.countSystemConfig(companyName);
} }
@Override @Override
public int insert(String beanJson, HttpServletRequest request) { public int insert(String beanJson, HttpServletRequest request)throws Exception {
return systemConfigService.insertSystemConfig(beanJson, request); return systemConfigService.insertSystemConfig(beanJson, request);
} }
@Override @Override
public int update(String beanJson, Long id) { public int update(String beanJson, Long id)throws Exception {
return systemConfigService.updateSystemConfig(beanJson, id); return systemConfigService.updateSystemConfig(beanJson, id);
} }
@Override @Override
public int delete(Long id) { public int delete(Long id)throws Exception {
return systemConfigService.deleteSystemConfig(id); return systemConfigService.deleteSystemConfig(id);
} }
@Override @Override
public int batchDelete(String ids) { public int batchDelete(String ids)throws Exception {
return systemConfigService.batchDeleteSystemConfig(ids); return systemConfigService.batchDeleteSystemConfig(ids);
} }
@Override @Override
public int checkIsNameExist(Long id, String name) { public int checkIsNameExist(Long id, String name)throws Exception {
return systemConfigService.checkIsNameExist(id, name); return systemConfigService.checkIsNameExist(id, name);
} }

View File

@@ -2,11 +2,14 @@ package com.jsh.erp.service.systemConfig;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.constants.BusinessConstants; import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.Supplier;
import com.jsh.erp.datasource.entities.SystemConfig; import com.jsh.erp.datasource.entities.SystemConfig;
import com.jsh.erp.datasource.entities.SystemConfigExample; import com.jsh.erp.datasource.entities.SystemConfigExample;
import com.jsh.erp.datasource.entities.User; import com.jsh.erp.datasource.entities.User;
import com.jsh.erp.datasource.mappers.SystemConfigMapper; import com.jsh.erp.datasource.mappers.SystemConfigMapper;
import com.jsh.erp.datasource.mappers.SystemConfigMapperEx; import com.jsh.erp.datasource.mappers.SystemConfigMapperEx;
import com.jsh.erp.exception.BusinessRunTimeException;
import com.jsh.erp.service.log.LogService; import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.user.UserService; import com.jsh.erp.service.user.UserService;
import com.jsh.erp.utils.StringUtil; import com.jsh.erp.utils.StringUtil;
@@ -36,54 +39,134 @@ public class SystemConfigService {
@Resource @Resource
private LogService logService; private LogService logService;
public SystemConfig getSystemConfig(long id) { public SystemConfig getSystemConfig(long id)throws Exception {
return systemConfigMapper.selectByPrimaryKey(id); SystemConfig result=null;
try{
result=systemConfigMapper.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<SystemConfig> getSystemConfig() { public List<SystemConfig> getSystemConfig()throws Exception {
SystemConfigExample example = new SystemConfigExample(); SystemConfigExample example = new SystemConfigExample();
example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); example.createCriteria().andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
return systemConfigMapper.selectByExample(example); List<SystemConfig> list=null;
try{
list=systemConfigMapper.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);
} }
public List<SystemConfig> select(String companyName, int offset, int rows) { return list;
return systemConfigMapperEx.selectByConditionSystemConfig(companyName, offset, rows); }
public List<SystemConfig> select(String companyName, int offset, int rows)throws Exception {
List<SystemConfig> list=null;
try{
list=systemConfigMapperEx.selectByConditionSystemConfig(companyName, 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 countSystemConfig(String companyName) { public Long countSystemConfig(String companyName)throws Exception {
return systemConfigMapperEx.countsBySystemConfig(companyName); Long result=null;
try{
result=systemConfigMapperEx.countsBySystemConfig(companyName);
}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) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int insertSystemConfig(String beanJson, HttpServletRequest request) { public int insertSystemConfig(String beanJson, HttpServletRequest request) throws Exception{
SystemConfig systemConfig = JSONObject.parseObject(beanJson, SystemConfig.class); SystemConfig systemConfig = JSONObject.parseObject(beanJson, SystemConfig.class);
return systemConfigMapper.insertSelective(systemConfig); int result=0;
try{
result=systemConfigMapper.insertSelective(systemConfig);
}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) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int updateSystemConfig(String beanJson, Long id) { public int updateSystemConfig(String beanJson, Long id) throws Exception{
SystemConfig systemConfig = JSONObject.parseObject(beanJson, SystemConfig.class); SystemConfig systemConfig = JSONObject.parseObject(beanJson, SystemConfig.class);
systemConfig.setId(id); systemConfig.setId(id);
return systemConfigMapper.updateByPrimaryKeySelective(systemConfig); int result=0;
try{
result=systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
}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) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int deleteSystemConfig(Long id) { public int deleteSystemConfig(Long id)throws Exception {
return systemConfigMapper.deleteByPrimaryKey(id); int result=0;
try{
result=systemConfigMapper.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) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
public int batchDeleteSystemConfig(String ids) { public int batchDeleteSystemConfig(String ids)throws Exception {
List<Long> idList = StringUtil.strToLongList(ids); List<Long> idList = StringUtil.strToLongList(ids);
SystemConfigExample example = new SystemConfigExample(); SystemConfigExample example = new SystemConfigExample();
example.createCriteria().andIdIn(idList); example.createCriteria().andIdIn(idList);
return systemConfigMapper.deleteByExample(example); int result=0;
try{
result=systemConfigMapper.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;
} }
public int checkIsNameExist(Long id, String name) { public int checkIsNameExist(Long id, String name) throws Exception{
SystemConfigExample example = new SystemConfigExample(); SystemConfigExample example = new SystemConfigExample();
example.createCriteria().andIdNotEqualTo(id).andCompanyNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED); example.createCriteria().andIdNotEqualTo(id).andCompanyNameEqualTo(name).andDeleteFlagNotEqualTo(BusinessConstants.DELETE_FLAG_DELETED);
List<SystemConfig> list = systemConfigMapper.selectByExample(example); List<SystemConfig> list =null;
return list.size(); try{
list=systemConfigMapper.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==null?0:list.size();
} }
@Transactional(value = "transactionManager", rollbackFor = Exception.class) @Transactional(value = "transactionManager", rollbackFor = Exception.class)
@@ -93,6 +176,15 @@ public class SystemConfigService {
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest()); ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest());
User userInfo=userService.getCurrentUser(); User userInfo=userService.getCurrentUser();
String [] idArray=ids.split(","); String [] idArray=ids.split(",");
return systemConfigMapperEx.batchDeleteSystemConfigByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray); int result=0;
try{
result=systemConfigMapperEx.batchDeleteSystemConfigByIds(new Date(),userInfo==null?null:userInfo.getId(),idArray);
}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;
} }
} }