Search in sources :

Example 1 with BusinessException

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;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User) PublicResource(com.topcom.cms.perm.annotation.PublicResource) Resource(com.topcom.cms.domain.Resource) Application(com.topcom.cms.domain.Application) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with BusinessException

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;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) Date(java.util.Date)

Example 3 with BusinessException

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;
}
Also used : Keywords(com.topcom.cms.yuqing.domain.Keywords) Briefing(com.topcom.cms.yuqing.domain.Briefing) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) BusinessException(com.topcom.cms.exception.BusinessException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BasicDBObject(com.mongodb.BasicDBObject) BusinessException(com.topcom.cms.exception.BusinessException) JSONObject(net.sf.json.JSONObject)

Example 4 with BusinessException

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;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) CustomSubject(com.topcom.cms.yuqing.domain.CustomSubject) Around(org.aspectj.lang.annotation.Around)

Example 5 with BusinessException

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;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) CurrentUser(com.topcom.cms.web.bind.annotation.CurrentUser) User(com.topcom.cms.domain.User)

Aggregations

BusinessException (com.topcom.cms.exception.BusinessException)9 User (com.topcom.cms.domain.User)2 CurrentUser (com.topcom.cms.web.bind.annotation.CurrentUser)2 BriefingTask (com.topcom.cms.yuqing.domain.BriefingTask)2 JSONObject (net.sf.json.JSONObject)2 Around (org.aspectj.lang.annotation.Around)2 ModelMap (org.springframework.ui.ModelMap)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 Application (com.topcom.cms.domain.Application)1 Resource (com.topcom.cms.domain.Resource)1 PublicResource (com.topcom.cms.perm.annotation.PublicResource)1 Briefing (com.topcom.cms.yuqing.domain.Briefing)1 Contact (com.topcom.cms.yuqing.domain.Contact)1 CustomSubject (com.topcom.cms.yuqing.domain.CustomSubject)1 Keywords (com.topcom.cms.yuqing.domain.Keywords)1 BriefingTaskManager (com.topcom.cms.yuqing.service.BriefingTaskManager)1 Sender (com.topcom.cms.yuqing.task.sender.Sender)1 EmailSenderFactory (com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory)1 SenderFactory (com.topcom.cms.yuqing.task.sender.factory.SenderFactory)1