Java Code Examples for com.jeesuite.common.JeesuiteBaseException

The following examples show how to use com.jeesuite.common.JeesuiteBaseException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: oneplatform   Source File: DepartmentController.java    License: Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "保存")
@RequestMapping(value = "save", method = RequestMethod.POST)
public @ResponseBody WrapperResponse<String> addDepartment(@RequestBody DepartmentParam param) {
	if(param.getCompanyId() == null || param.getCompanyId() == 0){
		throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请先选择公司");
	}
	DepartmentEntity entity = BeanUtils.copy(param, DepartmentEntity.class);
	if (param.getId() == null || param.getId() == 0) {
		entity.setCreatedAt(new Date());
		entity.setCreatedBy(LoginContext.getIntFormatUserId());
		departmentService.addDepartment(entity);
	} else {
		entity.setUpdatedAt(new Date());
		entity.setUpdatedBy(LoginContext.getIntFormatUserId());
		departmentService.updateDepartment(entity);
	}

	return new WrapperResponse<>();
}
 
Example 2
Source Project: oneplatform   Source File: EmployeeController.java    License: Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "新增")
@RequestMapping(value = "add", method = RequestMethod.POST)
   public @ResponseBody WrapperResponse<String> addEmployee(@RequestBody EmployeeParam param) {
	if(param.getDepartmentId() == null || param.getDepartmentId() == 0){
		throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请先选择所在部门");
	}
	if(param.getPositionId() == null || param.getPositionId() == 0){
		throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请先选择职位");
	}
	EmployeeEntity entity = BeanUtils.copy(param, EmployeeEntity.class);
	entity.setCreatedAt(new Date());
	entity.setCreatedBy(LoginContext.getIntFormatUserId());
	
	employeeService.addEmployee(entity,param.getDepartmentId(),param.getPositionId());
	
	return new WrapperResponse<>();
}
 
Example 3
Source Project: oneplatform   Source File: CompanyService.java    License: Apache License 2.0 6 votes vote down vote up
public void addCompany(CompanyEntity entity) {
	CompanyEntity headCompany = companyMapper.findHeadCompany();
	if(headCompany == null){
		entity.setIsBranch(false);
	}else{
		entity.setIsBranch(true);
		CompanyEntity sameNameCompany = companyMapper.findByName(entity.getName());
		if(sameNameCompany != null){
			if(sameNameCompany.getInActive())throw new JeesuiteBaseException(ExceptionCode.RECORD_EXISTED.code,"该子公司已存在");
			BeanUtils.copy(entity, sameNameCompany);
			sameNameCompany.setInActive(true);
			companyMapper.updateByPrimaryKeySelective(sameNameCompany);
			return ;
		}
	}
	companyMapper.insertSelective(entity);
}
 
Example 4
Source Project: oneplatform   Source File: PermissionController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "perm/batch_create", method = RequestMethod.POST)
public @ResponseBody WrapperResponse<String> batchCreatePermResources(HttpServletRequest request,@RequestBody BatchCreateResourceParam param){
	String[] menuNames = StringUtils.splitByWholeSeparator(param.getMenuName(), ">");
	if(param.getApis() == null)throw new JeesuiteBaseException(400,"请填写关联接口");
	for (int i = 0; i < param.getApis().size(); i++) {
		ApiDefine apiDefine = param.getApis().get(i);
		if(StringUtils.isAnyBlank(apiDefine.getMethod(),apiDefine.getName(),apiDefine.getUri())){
			param.getApis().remove(i);
			i--;
		}
	}
	if(param.getApis().isEmpty())throw new JeesuiteBaseException(400,"请完整填写关联接口");
	
	permissionService.batchCreatePermResources(param.getPlatformType(), menuNames, param.getMenuUri(), param.getApis());
	
	boolean jsonSubmit = Boolean.parseBoolean(request.getParameter("jsonSubmit"));
	return new WrapperResponse<>(jsonSubmit == false ? JsonUtils.toPrettyJson(param) : null);
}
 
Example 5
Source Project: jeesuite-config   Source File: AppAdminController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "add", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> addApp(@RequestBody AddOrEditAppRequest addAppRequest){
	SecurityUtil.requireSuperAdmin();
	if(addAppRequest.getMasterUid() == null || addAppRequest.getMasterUid() == 0){
		throw new JeesuiteBaseException(1002, "请选择项目负责人");
	}
	if(appMapper.findByName(addAppRequest.getName()) != null){
		throw new JeesuiteBaseException(1002, "应用["+addAppRequest.getName()+"]已存在");
	}
	AppEntity appEntity = BeanUtils.copy(addAppRequest, AppEntity.class);
	//
	UserEntity master = userMapper.selectByPrimaryKey(addAppRequest.getMasterUid());
	appEntity.setMaster(master.getName());
	appMapper.insertSelective(appEntity);
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
}
 
Example 6
Source Project: jeesuite-config   Source File: AppAdminController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "update", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> updateApp(@RequestBody AddOrEditAppRequest addAppRequest){
	SecurityUtil.requireSuperAdmin();
	AppEntity app = appMapper.selectByPrimaryKey(addAppRequest.getId());
	if(app == null){
		throw new JeesuiteBaseException(1002, "应用不存在");
	}
	AppEntity appEntity = BeanUtils.copy(addAppRequest, AppEntity.class);
	
	if(addAppRequest.getMasterUid() != null && addAppRequest.getMasterUid() > 0 
			&& !addAppRequest.getMasterUid().equals(app.getMasterUid())){
		UserEntity master = userMapper.selectByPrimaryKey(addAppRequest.getMasterUid());
		appEntity.setMaster(master.getName());
	}
	
	appMapper.updateByPrimaryKeySelective(appEntity);
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
}
 
Example 7
Source Project: jeesuite-config   Source File: UserAdminController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "add", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> addUser(@RequestBody UserEntity param){
	SecurityUtil.requireSuperAdmin();
	if(StringUtils.isAnyBlank(param.getName(),param.getMobile())){
		throw new JeesuiteBaseException(1001, "用户名/手机号不能为空");
	}
	if(userMapper.findByName(param.getName()) != null){
		throw new JeesuiteBaseException(1001, "用户名已存在");
	}
	if(userMapper.findByMobile(param.getMobile()) != null){
		throw new JeesuiteBaseException(1001, "手机号已存在");
	}
	param.setPassword(UserEntity.encryptPassword(param.getMobile().substring(3)));
	param.setStatus((short)1);
	param.setType((short)2);
	param.setCreatedAt(new Date());
	userMapper.insertSelective(param);
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(param),HttpStatus.OK);
}
 
Example 8
Source Project: jeesuite-config   Source File: UserAdminController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "update", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> modifyPassword(@RequestBody UpdateUserRequest param){
	UserEntity entity = userMapper.selectByPrimaryKey(SecurityUtil.getLoginUserInfo().getId());
	if(entity.getName().equals("test")){
		throw new JeesuiteBaseException(1001, "测试账号不允许编辑");
	}
	if(StringUtils.isNotBlank(param.getEmail()))entity.setEmail(param.getEmail());
	if(StringUtils.isNotBlank(param.getMobile()))entity.setMobile(param.getMobile());
	if(StringUtils.isNotBlank(param.getPassword())){
		
		String oldPassword = UserEntity.encryptPassword(param.getOldPassword());
		if(!StringUtils.equals(entity.getPassword(), oldPassword)){
			throw new JeesuiteBaseException(1001, "原密码不正确");
		}
		entity.setPassword(UserEntity.encryptPassword(param.getPassword()));
	}
	entity.setUpdatedAt(new Date());
	userMapper.updateByPrimaryKeySelective(entity);
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
}
 
Example 9
Source Project: jeesuite-config   Source File: ConfigAdminController.java    License: Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "upload", method = RequestMethod.POST)
public ResponseEntity<Object> uploadConfigFile(@RequestParam("file") MultipartFile file){
	
	String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
	if(!allow_upload_suffix.contains(suffix)){
		throw new JeesuiteBaseException(9999, "支持上传文件类型:"+Arrays.toString(allow_upload_suffix.toArray()));
	}
	try {
		Map<String, String> result = new HashMap<>();
		result.put("fileName", file.getOriginalFilename());
		result.put("content", new String(file.getBytes(), StandardCharsets.UTF_8));
		return new ResponseEntity<Object>(new WrapperResponseEntity(result),HttpStatus.OK);
	} catch (Exception e) {
		throw new JeesuiteBaseException(9999, "上传失败");
	}
}
 
Example 10
Source Project: jeesuite-config   Source File: GlobalExceptionHandler.java    License: Apache License 2.0 6 votes vote down vote up
@ExceptionHandler(Exception.class)
@ResponseBody
public ResponseEntity<WrapperResponseEntity> exceptionHandler(Exception e, HttpServletResponse response) {
	WrapperResponseEntity resp = new WrapperResponseEntity();
	while(e.getCause() != null){
		e = (Exception) e.getCause();
	}
	if (e instanceof JeesuiteBaseException) {
		JeesuiteBaseException e1 = (JeesuiteBaseException) e;
		resp.setCode(e1.getCode());
		resp.setMsg(e1.getMessage());
	} else if(e instanceof org.springframework.web.HttpRequestMethodNotSupportedException){
		resp.setCode(HttpStatus.METHOD_NOT_ALLOWED.value());
		resp.setMsg(e.getMessage()); 
	}else if(e instanceof org.springframework.web.HttpMediaTypeException){
		resp.setCode(HttpStatus.UNSUPPORTED_MEDIA_TYPE.value());
		resp.setMsg(e.getMessage()); 
	}else {
		resp.setCode(500);
		resp.setMsg("系统繁忙");
		logger.error("",e);
	}
	return new ResponseEntity<WrapperResponseEntity>(resp,HttpStatus.OK);
}
 
Example 11
Source Project: oneplatform   Source File: WxUserController.java    License: Apache License 2.0 5 votes vote down vote up
@PostMapping("/code2userid")
@ApiPermOptions(perms = PermissionType.Anonymous)
public WrapperResponse<IdParam> codeToUser(HttpServletRequest request,@RequestBody WxappLoginParam param) {
    if (StringUtils.isBlank(param.getGroup())) {
        throw new JeesuiteBaseException(4001, "参数group必填");
    }
    Integer userId = winxinUserSerivce.findUserIdByWeAppCode(param.getGroup(), param.getCode());
    return new WrapperResponse<>(new IdParam(userId));
}
 
Example 12
Source Project: oneplatform   Source File: WinxinUserSerivce.java    License: Apache License 2.0 5 votes vote down vote up
public Integer findUserIdByWeAppCode(String group,String code){
	final WxMaService wxService = weixinAppManager.getMaService(group);
       try {
           WxMaJscode2SessionResult wxsession = wxService.getUserService().getSessionInfo(code);
           Integer userId = findUserIdByOpenId(wxsession.getOpenid());
           return userId;
       } catch (WxErrorException e) {
           throw new JeesuiteBaseException(500, e.getMessage());
       }
}
 
Example 13
Source Project: oneplatform   Source File: FileController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "/upload", method = RequestMethod.POST)
@ApiOperation(value="上传文件")
@ApiImplicitParams({
	@ApiImplicitParam(paramType="query",name="appId",dataType="String",required=true,value="应用ID"),
	 @ApiImplicitParam(paramType="form",name="group",dataType="String",required=true,value="对应配置中心配置上传组名(如:public,private等)"),
	 @ApiImplicitParam(paramType="form",name="fileName",dataType="String",required=true,value="文件原名称"),
	 @ApiImplicitParam(paramType="form",name="file",dataType="File",required=true,value="文件内容")
})
public @ResponseBody UploadResult uploadConfigFile(@RequestParam("file") MultipartFile file,@RequestParam(value="appId") String appId,@RequestParam("group") String group,@RequestParam("fileName") String originFileName){
	try {
		
		String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".") + 1).toLowerCase();
		if(!allow_upload_suffix.contains(suffix)){
			throw new JeesuiteBaseException(9999, "不允许上传该文件类型");
		}
		String fileKey = UUID.randomUUID().toString() + "."+suffix;
		//file.transferTo(new File("/Users/jiangwei/"+fileKey));
		
		FileSystemClient client = FileSystemClient.getClient(group);
		String url = client.upload(fileKey, file.getBytes());
		
		UploadFileEntity entity = new UploadFileEntity();
		entity.setAppId(appId);
		entity.setGroupName(group);
		entity.setFileName(originFileName);
		entity.setFileUrl(url);
		entity.setMimeType(file.getContentType());
		entity.setProvider(client.getProvider().name());
		entity.setCreatedAt(new Date());
		uploadFileMapper.insertSelective(entity);
           
		return new UploadResult(url, originFileName);
	} catch (Exception e) {
		e.printStackTrace();
		throw new JeesuiteBaseException(ExceptionCode.SYSTEM_ERROR.code, "上传失败");
	}
}
 
Example 14
Source Project: oneplatform   Source File: FileController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "获取文件地址", notes = "获取文件地址")
@RequestMapping(value = "geturl/{id}", method = RequestMethod.GET)
public @ResponseBody WrapperResponse<String> getUploadFileUrlById(@PathVariable("id") int id) {
	UploadFileEntity uploadFileEntity = uploadFileMapper.selectByPrimaryKey(id);
	String downloadUrl = null;
	if(uploadFileEntity != null){			
		downloadUrl = FileSystemClient.getClient(uploadFileEntity.getGroupName()).getDownloadUrl(uploadFileEntity.getFileUrl());
	}else{
		throw new JeesuiteBaseException(4001, "文件不存在");
	}
	return new WrapperResponse<>(downloadUrl);
}
 
Example 15
Source Project: oneplatform   Source File: PositionsController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "新增")
@RequestMapping(value = "add", method = RequestMethod.POST)
public @ResponseBody WrapperResponse<String> addPosition(@RequestBody PositionParam param) {
	if(StringUtils.isBlank(param.getName())){
		throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_REQUIRED.code, "请填写公司名");
	}
	PositionEntity entity = new PositionEntity();
	entity.setName(param.getName());
	entity.setCreatedAt(new Date());
	entity.setCreatedBy(LoginContext.getIntFormatUserId());
	positionsService.addPositions(entity);

	return new WrapperResponse<>();
}
 
Example 16
Source Project: oneplatform   Source File: CompanyService.java    License: Apache License 2.0 5 votes vote down vote up
public void deleteCompany(Integer id) {
	CompanyEntity entity = companyMapper.selectByPrimaryKey(id);
	AssertUtil.notNull(entity);
	if(!entity.getIsBranch()){
		throw new JeesuiteBaseException(ExceptionCode.OPTER_NOT_ALLOW.code, "分公司才能删除");
	}
	entity.setInActive(false);
	companyMapper.updateByPrimaryKeySelective(entity);
}
 
Example 17
Source Project: oneplatform   Source File: SsensitiveOperProtectHandler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Object onInterceptor(Invocation invocation) throws Throwable {
	Object[] objects = invocation.getArgs();
	MappedStatement ms = (MappedStatement) objects[0];
	if(ms.getSqlCommandType().equals(SqlCommandType.DELETE)){
		throw new JeesuiteBaseException(ExceptionCode.OPTER_NOT_ALLOW.code, "当前已开启敏感操作保护");
	}
	return null;
}
 
Example 18
Source Project: oneplatform   Source File: SecurityCryptUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static void validateAuthCode(String authCode,boolean validateExpire){
	long timestamp = 0;
	try {
		timestamp = Long.parseLong(SecurityCryptUtils.decrypt(authCode).substring(6));
	} catch (Exception e) {
		throw new JeesuiteBaseException(4005, "authToken格式不正确");
	}
	if(validateExpire && System.currentTimeMillis() - timestamp > EXPIRE){
		throw new JeesuiteBaseException(4005, "authToken过期");
	}
}
 
Example 19
Source Project: oneplatform   Source File: AccountController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "新增账号")
@RequestMapping(value = "add", method = RequestMethod.POST)
   public @ResponseBody WrapperResponse<String> addAccount(@RequestBody AccountParam param) {
	if(StringUtils.isAnyBlank(param.getMobile(),param.getEmail(),param.getUsername())){
		throw new JeesuiteBaseException(4001, "用户名、手机、邮箱必填");
	}
	accountService.addAccount(LoginContext.getIntFormatUserId(), param);
	return new WrapperResponse<>();
}
 
Example 20
Source Project: oneplatform   Source File: AccountController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "删除账户")
@RequestMapping(value = "delete/{id}", method = RequestMethod.POST)
   public @ResponseBody WrapperResponse<String> deleteAccount(@PathVariable("id") int id) {
	if(id == 0)throw new JeesuiteBaseException(500, "超级管理员不能删除");
	accountService.deleteAccount(LoginContext.getIntFormatUserId(), id);
	return new WrapperResponse<>();
}
 
Example 21
Source Project: oneplatform   Source File: AccountController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "启用/停止账号")
@RequestMapping(value = "switch", method = RequestMethod.POST)
   public @ResponseBody WrapperResponse<String> switchAccount(@RequestBody SwitchParam param) {
	if(param.getId() == 0)throw new JeesuiteBaseException(500, "超级管理员不能删除");
	accountService.switchAccount(LoginContext.getIntFormatUserId(), param.getId(),param.getValue());
	return new WrapperResponse<>();
}
 
Example 22
Source Project: oneplatform   Source File: UserContextController.java    License: Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "更新密码")
@RequestMapping(value = "updatepwd", method = RequestMethod.POST)
   public @ResponseBody WrapperResponse<String> updatePassword(@RequestBody UpdatepasswordParam param) {
	if(StringUtils.isAnyBlank(param.getPassword(),param.getOldPassword())){
		throw new JeesuiteBaseException(4001, "新旧密码必填");
	}
	Integer loginUserId = LoginContext.getIntFormatUserId();
	param.setUserId(loginUserId);
	accountService.updatePassword(loginUserId, param);
	return new WrapperResponse<>();
}
 
Example 23
Source Project: oneplatform   Source File: PermissionController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "permgroup/update", method = RequestMethod.POST)
@ApiOperation(value = "更新权限组", httpMethod = "POST")
public @ResponseBody WrapperResponse<String> updatePermGroup(@RequestBody UpdatePermGroupParam param){
	if(param.getApiIds() == null || param.getApiIds().isEmpty())throw new JeesuiteBaseException(400,"关联接口[apiIds]必填");
	permissionService.updatePermGroup(LoginContext.getIntFormatUserId(), param);
	return new WrapperResponse<>();
}
 
Example 24
Source Project: oneplatform   Source File: AccountService.java    License: Apache License 2.0 5 votes vote down vote up
public void updatePassword(int operUserId, UpdatepasswordParam param) {
	AccountEntity entity = findById(param.getUserId());
	String oldPass = AccountEntity.encryptPassword(param.getOldPassword());
	if(!StringUtils.equals(oldPass, entity.getPassword())){
		throw new JeesuiteBaseException(ExceptionCode.REQUEST_PARAM_ERROR.code, "原密码错误");
	}
	entity.setPassword(AccountEntity.encryptPassword(param.getPassword()));
	entity.setUpdatedAt(new Date());
	entity.setUpdatedBy(operUserId);
	
	accountMapper.updateByPrimaryKeySelective(entity);
}
 
Example 25
Source Project: oneplatform   Source File: ModuleService.java    License: Apache License 2.0 5 votes vote down vote up
public ModuleEntity getmoduleDetails(int moduleId){
	Optional<ModuleEntity> optional = ModuleMetadataUpdateTask.getActiveModules().values()
			.stream()
			.filter(m -> (m.getId().intValue() == moduleId))
			.findFirst();
	if(!optional.isPresent())throw new JeesuiteBaseException(ExceptionCode.RECORD_NOT_EXIST.code, "模块不存在或者未运行");
   	return optional.get();
}
 
Example 26
Source Project: oneplatform   Source File: ModuleService.java    License: Apache License 2.0 5 votes vote down vote up
public void switchModule(int operUserId,Integer id,boolean enable){
	if(id == 1){
		throw new JeesuiteBaseException(ExceptionCode.OPTER_NOT_ALLOW.code, "系统模块不允许禁用");
	}
	ModuleEntity entity = moduleMapper.selectByPrimaryKey(id);
	AssertUtil.notNull(entity);
	if(entity.getEnabled() == enable)return;
	entity.setEnabled(enable);
	
	entity.setUpdatedAt(new Date());
	entity.setUpdatedBy(operUserId);
	
	moduleMapper.updateByPrimaryKeySelective(entity);
	
}
 
Example 27
Source Project: oneplatform   Source File: ModuleService.java    License: Apache License 2.0 5 votes vote down vote up
public void deleteModule(int operUserId,int id){
  	if(id == 1){
  		throw new JeesuiteBaseException(ExceptionCode.OPTER_NOT_ALLOW.code, "系统模块不允许禁用");
  	}
  	ModuleEntity moduleEntity = moduleMapper.selectByPrimaryKey(id);
  	if(moduleEntity == null)return;
  	Optional<ModuleEntity> optional = ModuleMetadataUpdateTask.getActiveModules().values().stream().filter(m -> (m.getId().intValue() == id)).findFirst();
if(optional.isPresent()){
  		throw new JeesuiteBaseException(ExceptionCode.OPTER_NOT_ALLOW.code, "该模块在运行中不允许删除");
      }
  	moduleMapper.deleteByPrimaryKey(id);
  }
 
Example 28
Source Project: jeesuite-config   Source File: ConfigAdminController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "add", method = RequestMethod.POST)
	@Transactional
	public ResponseEntity<WrapperResponseEntity> addConfig(@RequestBody AddOrEditConfigRequest addRequest){
		
		if(!addRequest.getGlobal() && addRequest.getAppIds() == null){
			throw new JeesuiteBaseException(4001,"非全局绑定应用不能为空");
		}
		
		if(StringUtils.isBlank(addRequest.getEnv())){
			throw new JeesuiteBaseException(4001,"绑定环境profile不能为空");
		}
		
		if(addRequest.getType().intValue() == 2 && StringUtils.isBlank(addRequest.getName())){
			throw new JeesuiteBaseException(4001,"配置项名称不能空");
		}
		
		if(addRequest.getGlobal()){
			SecurityUtil.requireSuperAdmin();
		}else{			
			SecurityUtil.requireAllPermission(addRequest.getEnv(),addRequest.getAppIds(),GrantOperate.RW);
		}
		
//       if(StringUtils.isNotBlank(addRequest.getName()) 
//    		   && appconfigMapper.findSameByName(addRequest.getEnv(), appId, addRequest.getName()) != null){
//    	   throw new JeesuiteBaseException(4001,"配置名称已经存在");
//       }

		AppconfigEntity entity = BeanUtils.copy(addRequest, AppconfigEntity.class);
		entity.setAppIds(StringUtils.join(addRequest.getAppIds(),","));
		entity.setCreatedBy(SecurityUtil.getLoginUserInfo().getName());
		entity.setCreatedAt(new Date());
		entity.setUpdatedAt(entity.getCreatedAt());
		entity.setUpdatedBy(entity.getCreatedBy());
		
		encryptPropItemIfRequired(entity);
		//
		appconfigMapper.insertSelective(entity);

		return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
	}
 
Example 29
Source Project: jeesuite-config   Source File: ConfigAdminController.java    License: Apache License 2.0 5 votes vote down vote up
@Transactional
@RequestMapping(value = "update", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> updateConfig(@RequestBody AddOrEditConfigRequest addRequest){
	if(addRequest.getId() == null || addRequest.getId() == 0){
		throw new JeesuiteBaseException(1003, "id参数缺失");
	}
	AppconfigEntity entity = appconfigMapper.selectByPrimaryKey(addRequest.getId());
	if(!entity.getGlobal() && addRequest.getAppIds() == null){
		throw new JeesuiteBaseException(4001,"非全局绑定应用不能为空");
	}
	
	if(entity.getGlobal()){
		SecurityUtil.requireSuperAdmin();
	}else{			
		SecurityUtil.requireAllPermission(entity.getEnv(),addRequest.getAppIds(),GrantOperate.RW);
	}
	//
	saveAppConfigHistory(entity);
	
	entity.setAppIds(StringUtils.join(addRequest.getAppIds(),","));
	entity.setVersion(addRequest.getVersion());
	
	String orignContents = entity.getContents();
	entity.setContents(addRequest.getContents());
	//
	encryptPropItemIfRequired(entity);
	entity.setUpdatedBy(SecurityUtil.getLoginUserInfo().getName());
	entity.setUpdatedAt(new Date());
	appconfigMapper.updateByPrimaryKeySelective(entity);
	//
	publishConfigChangeEvent(orignContents,entity);
	
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
}
 
Example 30
Source Project: jeesuite-config   Source File: ProfileAdminController.java    License: Apache License 2.0 5 votes vote down vote up
@RequestMapping(value = "add", method = RequestMethod.POST)
public ResponseEntity<WrapperResponseEntity> addProfile(@RequestBody ProfileEntity param){
	SecurityUtil.requireSuperAdmin();
	ProfileEntity entity = profileMapper.findByName(param.getName());
	if(entity != null)throw new JeesuiteBaseException(1002, "Profile["+param.getName()+"]已存在");
	profileMapper.insertSelective(param);
	return new ResponseEntity<WrapperResponseEntity>(new WrapperResponseEntity(true),HttpStatus.OK);
}