use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.
the class UserController method appResource.
/**
* 返回登录用户指定app的resource
*/
@ApiOperation("获取指定app的resource")
@RequestMapping(value = { "appResource" }, method = { RequestMethod.GET })
@ResponseBody
public Set<Resource> appResource(@CurrentUser User user, @RequestParam(required = false) Long appId, @RequestParam(required = false) String appName) throws Exception {
if (appId == null && StringUtils.isBlank(appName)) {
throw new BusinessException("appId 和 appName 不能同时为空!");
}
if (appId == null) {
Application app = applicationManager.findByName(appName);
appId = app.getId();
}
// 缓存user懒加载,没有resource,需要在数据库查询
User user1 = this.manager.findById(user.getId());
Set<Resource> resourceSet = user1.getResource();
if (resourceSet == null || resourceSet.size() == 0) {
return null;
}
Set<Resource> filteredResourceSet = new LinkedHashSet<>();
for (Resource resource : resourceSet) {
if (appId.equals(resource.getAppId())) {
filteredResourceSet.add(resource);
}
}
for (Resource resource : filteredResourceSet) {
resource.sortByChildId();
}
return filteredResourceSet;
}
use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.
the class RoleController method create.
/**
* 重写父类post方法
*/
@Override
@RequestMapping(value = { "/" }, method = { RequestMethod.POST }, produces = { "application/json" }, consumes = { "application/json" })
@ResponseBody
public Role create(@RequestBody Role model) throws BusinessException {
if (roleManager.findByName(model.getName()) != null) {
throw new BusinessException("角色已存在");
}
Date date = new Date();
model.setDateCreated(date);
model.setDateModified(date);
model = roleManager.saveRole(model);
return model;
}
use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.
the class BriefingCreatorImpl method sendRequestAndCreateBriefing.
/**
* 根据报告类型和开始结束时间发送请求生成json,并创建附件,保存到数据库
*
* @param briefingTask
* @param startTime
* @param endTime
* @return
* @throws BusinessException
*/
private Future sendRequestAndCreateBriefing(BriefingTask briefingTask, long startTime, long endTime) throws BusinessException {
FutureTask<JSONObject> futureTask = new FutureTask<>(() -> {
Briefing.BriefingType type = briefingTask.getBriefingType();
List<Keywords> keywordList = keywordsManager.findByUserIdAndType(briefingTask.getUserId(), Keywords.Type.BASIC);
if (keywordList.size() > 0) {
Keywords keyword = keywordList.get(0);
String mustWord = keyword.getMustWord();
String shouldWord = keyword.getShouldWord();
String mustNotWord = keyword.getMustNotWord();
try {
String object = requestBriefingString(type, mustWord, shouldWord, mustNotWord, startTime, endTime, null);
DBObject dbObject = (BasicDBObject) JSON.parse(object);
dbObject.put("userId", briefingTask.getUserId());
dbObject.put("type", type.name());
dbObject.put("issue", briefingTask.getIssue());
JSONObject json = JSONObject.fromObject(dbObject);
json.put("dateCreated", endTime);
saveBriefingToMongo(json);
String message = "生成报告成功@" + new Date() + "@" + type.name();
LogUtil.logger.info(message);
return json;
} catch (Exception e) {
e.printStackTrace();
String message = "生成报告失败@" + new Date() + "@" + type.name();
LogUtil.logger.error(message);
throw new BusinessException(message);
}
}
return null;
});
executorService.submit(futureTask);
return futureTask;
}
use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.
the class WarningTaskWatcher method doAroundUpdate.
@Around("saveOrUpdateMethod()")
public Object doAroundUpdate(ProceedingJoinPoint joinPoint) throws BusinessException {
Object[] args = joinPoint.getArgs();
if (args.length >= 1) {
try {
Object proceed = joinPoint.proceed(args);
final CustomSubject subject = (CustomSubject) proceed;
if (subject != null) {
/**
* 如果是调用新增方法(1个参数,update是两个参数),调用生成专报方法
*/
if (args.length == 1) {
briefingCreator.createSpecial(subject);
}
/**
* 预警任务调度
*/
if (subject.isEnableWarning() == true) {
// 如果是开启
scheduleJob(subject);
LogUtil.logger.info("更新任务:" + subject.getName() + "成功");
} else {
// 如果是关闭
deleteJob(String.valueOf(subject.getId()));
}
/**
*发送到kafka
*/
sendToKafka(subject);
}
return subject;
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new BusinessException("更新失败");
}
}
return null;
}
use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.
the class UserController method updateState.
/**
* 改变用户状态
*/
@RequestMapping(value = { "/updateState/{id}" }, method = { RequestMethod.PUT }, produces = { "application/json" })
@ResponseBody
public boolean updateState(@PathVariable Long id, @RequestParam User.State state) throws BusinessException {
User user = userManager.findById(id);
if (user == null) {
throw new BusinessException("用户不存在");
}
int i = userManager.updateState(id, state);
return i > 0;
}
Aggregations