优化系统配置模块
This commit is contained in:
@@ -385,6 +385,10 @@ public class ExceptionConstants {
|
||||
public static final int ORGA_USER_REL_EDIT_FAILED_CODE = 11500002;
|
||||
public static final String ORGA_USER_REL_EDIT_FAILED_MSG = "修改机构用户关联关系失败";
|
||||
|
||||
//演示用户禁止操作
|
||||
public static final int SYSTEM_CONFIG_TEST_USER_CODE = -1;
|
||||
public static final String SYSTEM_CONFIG_TEST_USER_MSG = "演示用户禁止操作";
|
||||
|
||||
|
||||
/**
|
||||
* 标准正常返回/操作成功返回
|
||||
|
||||
@@ -82,6 +82,8 @@ public class ResourceController {
|
||||
int insert = configResourceManager.insert(apiName, beanJson, request);
|
||||
if(insert > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else if(insert == -1) {
|
||||
return returnJson(objectMap, ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
@@ -95,6 +97,8 @@ public class ResourceController {
|
||||
int update = configResourceManager.update(apiName, beanJson, id, request);
|
||||
if(update > 0) {
|
||||
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
|
||||
} else if(update == -1) {
|
||||
return returnJson(objectMap, ErpInfo.TEST_USER.name, ErpInfo.TEST_USER.code);
|
||||
} else {
|
||||
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.jsh.erp.constants.ExceptionConstants;
|
||||
import com.jsh.erp.exception.BusinessRunTimeException;
|
||||
import com.jsh.erp.service.systemConfig.SystemConfigService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -21,21 +22,30 @@ import javax.annotation.Resource;
|
||||
@RequestMapping(value = "/systemConfig")
|
||||
public class SystemConfigController {
|
||||
private Logger logger = LoggerFactory.getLogger(SystemConfigController.class);
|
||||
|
||||
@Resource
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
/**
|
||||
* 批量删除系统配置信息
|
||||
*/
|
||||
@RequestMapping(value = "/batchDeleteSystemConfigByIds")
|
||||
public Object batchDeleteSystemConfigByIds(@RequestParam("ids") String ids) throws Exception {
|
||||
JSONObject result = ExceptionConstants.standardSuccess();
|
||||
int i= systemConfigService.batchDeleteSystemConfigByIds(ids);
|
||||
if(i<1){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,ids[{}]",
|
||||
ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_CODE,ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_MSG,ids);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_CODE,
|
||||
ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_MSG);
|
||||
int i= 0;
|
||||
if(userService.checkIsTestUser()) {
|
||||
throw new BusinessRunTimeException(ExceptionConstants.SYSTEM_CONFIG_TEST_USER_CODE,
|
||||
ExceptionConstants.SYSTEM_CONFIG_TEST_USER_MSG);
|
||||
} else {
|
||||
i = systemConfigService.batchDeleteSystemConfigByIds(ids);
|
||||
if(i<1){
|
||||
logger.error("异常码[{}],异常提示[{}],参数,ids[{}]",
|
||||
ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_CODE,ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_MSG,ids);
|
||||
throw new BusinessRunTimeException(ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_CODE,
|
||||
ExceptionConstants.SYSTEM_CONFIG_DELETE_FAILED_MSG);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -43,9 +43,6 @@ public class UserController {
|
||||
@Value("${manage.roleId}")
|
||||
private Integer manageRoleId;
|
||||
|
||||
@Value("${demonstrate.open}")
|
||||
private boolean demonstrateOpen;
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
|
||||
@@ -59,27 +56,6 @@ public class UserController {
|
||||
private static final String HTTP = "http://";
|
||||
private static final String CODE_OK = "200";
|
||||
|
||||
/**
|
||||
* 是否开启演示状态,默认关闭
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/getDemonstrateOpen")
|
||||
public BaseResponseInfo getDemonstrateOpen(HttpServletRequest request) {
|
||||
BaseResponseInfo res = new BaseResponseInfo();
|
||||
try {
|
||||
Map<String, Object> data = new HashMap<String, Object>();
|
||||
data.put("demonstrateOpen", demonstrateOpen);
|
||||
res.code = 200;
|
||||
res.data = data;
|
||||
} catch(Exception e){
|
||||
e.printStackTrace();
|
||||
res.code = 500;
|
||||
res.data = "获取失败";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@PostMapping(value = "/login")
|
||||
public BaseResponseInfo login(@RequestParam(value = "loginName", required = false) String loginName,
|
||||
@RequestParam(value = "password", required = false) String password,
|
||||
|
||||
@@ -86,9 +86,13 @@ public class SystemConfigService {
|
||||
SystemConfig systemConfig = JSONObject.parseObject(beanJson, SystemConfig.class);
|
||||
int result=0;
|
||||
try{
|
||||
result=systemConfigMapper.insertSelective(systemConfig);
|
||||
logService.insertLog("系统配置",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(systemConfig.getCompanyName()).toString(), request);
|
||||
if(userService.checkIsTestUser()) {
|
||||
result=-1;
|
||||
} else {
|
||||
result=systemConfigMapper.insertSelective(systemConfig);
|
||||
logService.insertLog("系统配置",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_ADD).append(systemConfig.getCompanyName()).toString(), request);
|
||||
}
|
||||
}catch(Exception e){
|
||||
JshException.writeFail(logger, e);
|
||||
}
|
||||
@@ -101,9 +105,13 @@ public class SystemConfigService {
|
||||
systemConfig.setId(id);
|
||||
int result=0;
|
||||
try{
|
||||
result=systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
|
||||
logService.insertLog("系统配置",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(systemConfig.getCompanyName()).toString(), request);
|
||||
if(userService.checkIsTestUser()) {
|
||||
result=-1;
|
||||
} else {
|
||||
result = systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
|
||||
logService.insertLog("系统配置",
|
||||
new StringBuffer(BusinessConstants.LOG_OPERATION_TYPE_EDIT).append(systemConfig.getCompanyName()).toString(), request);
|
||||
}
|
||||
}catch(Exception e){
|
||||
JshException.writeFail(logger, e);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
@@ -39,6 +40,12 @@ import java.util.Objects;
|
||||
@Service
|
||||
public class UserService {
|
||||
private Logger logger = LoggerFactory.getLogger(UserService.class);
|
||||
|
||||
private static final String TEST_USER = "jsh";
|
||||
|
||||
@Value("${demonstrate.open}")
|
||||
private boolean demonstrateOpen;
|
||||
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
@@ -55,7 +62,6 @@ public class UserService {
|
||||
@Resource
|
||||
private UserBusinessService userBusinessService;
|
||||
|
||||
|
||||
public User getUser(long id)throws Exception {
|
||||
User result=null;
|
||||
try{
|
||||
@@ -314,6 +320,25 @@ public class UserService {
|
||||
return (User)request.getSession().getAttribute("user");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查当前用户是否是演示用户
|
||||
* @return
|
||||
*/
|
||||
public Boolean checkIsTestUser() throws Exception{
|
||||
Boolean result = false;
|
||||
try {
|
||||
if (demonstrateOpen) {
|
||||
User user = getCurrentUser();
|
||||
if (TEST_USER.equals(user.getLoginName())) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
JshException.readFail(logger, e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户名查询id
|
||||
* @param loginName
|
||||
|
||||
@@ -13,7 +13,8 @@ public enum ErpInfo {
|
||||
WARING_MSG(201, "提醒信息"),
|
||||
REDIRECT(301, "session失效,重定向"),
|
||||
FORWARD_REDIRECT(302, "转发请求session失效"),
|
||||
FORWARD_FAILED(303, "转发请求失败!");
|
||||
FORWARD_FAILED(303, "转发请求失败!"),
|
||||
TEST_USER(-1, "演示用户禁止操作");
|
||||
|
||||
public final int code;
|
||||
public final String name;
|
||||
|
||||
Reference in New Issue
Block a user