Search in sources :

Example 6 with BusinessException

use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.

the class UserController method modifyState.

@RequestMapping(value = "/modifyState/{id}", method = RequestMethod.POST)
@ResponseBody
public ModelMap modifyState(HttpServletRequest request, @PathVariable Long userId, @RequestParam User.State state) throws BusinessException {
    ModelMap modelMap = new ModelMap("success", false);
    int i = userManager.updateState(userId, state);
    if (i > 0) {
        modelMap.put("success", true);
    } else {
        throw new BusinessException("更改状态失败");
    }
    return modelMap;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) ModelMap(org.springframework.ui.ModelMap)

Example 7 with BusinessException

use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.

the class UserController method modifyPassword.

@RequestMapping(value = "/modifyPassword", method = RequestMethod.POST)
@ResponseBody
public ModelMap modifyPassword(@CurrentUser User user, HttpServletRequest request, @RequestParam String oldPwd, @RequestParam String newPwd) throws BusinessException {
    ModelMap modelMap = new ModelMap("success", false);
    // 保持的旧密码
    String savedPwd = user.getPassword();
    // 加密接收的就密码
    String encodedOldPwd = PasswordHelper.getEncodedPassword(oldPwd, user.getCredentialsSalt());
    // 对比
    if (StringUtils.equals(savedPwd, encodedOldPwd)) {
        user.setPassword(newPwd);
        PasswordHelper.encryptPassword(user);
        int i = userManager.updatePassword(user.getId(), user.getPassword(), user.getSalt());
        if (i > 0) {
            modelMap.put("success", true);
            // 密码修改成功,需要重新登陆
            // TODO://
            tokenManager.deleteToken(user.getId());
        }
    } else {
        throw new BusinessException("原密码错误");
    }
    return modelMap;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) ModelMap(org.springframework.ui.ModelMap)

Example 8 with BusinessException

use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.

the class BriefingTaskWatcher method doAroundUpdate.

@Around("updateBriefingTask()")
public Object doAroundUpdate(ProceedingJoinPoint joinPoint) throws BusinessException {
    Object[] args = joinPoint.getArgs();
    if (args.length == 1) {
        try {
            Object proceed = joinPoint.proceed(args);
            final BriefingTask briefingTask = (BriefingTask) proceed;
            if (briefingTask != null) {
                if (briefingTask.isEnable() == true) {
                    // 如果是开启
                    scheduleJob(briefingTask);
                    LogUtil.logger.info("更新任务:" + briefingTask.getBriefingType() + "成功");
                } else {
                    // 如果是关闭
                    deleteJob(String.valueOf(briefingTask.getId()));
                }
            }
            return briefingTask;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            throw new BusinessException("更新失败");
        }
    }
    return null;
}
Also used : BusinessException(com.topcom.cms.exception.BusinessException) BriefingTask(com.topcom.cms.yuqing.domain.BriefingTask) Around(org.aspectj.lang.annotation.Around)

Example 9 with BusinessException

use of com.topcom.cms.exception.BusinessException in project topcom-cloud by 545314690.

the class BriefingJob method execute.

@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
    Long briefingTaskId = (Long) context.getMergedJobDataMap().get("briefingTaskId");
    BriefingTask briefingTask = briefingTaskManager.findById(briefingTaskId);
    logger.info("任务运行:" + briefingTask.getBriefingType() + ":" + briefingTaskId);
    /**
     * 生成月报
     */
    JSONObject briefing = null;
    try {
        briefing = (JSONObject) briefingCreator.create(briefingTask).get();
        logger.info("任务运行:生成报告成功");
    } catch (BusinessException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
        logger.info("任务运行:生成报告失败");
    }
    List<Contact> contacts = briefingTask.getContacts();
    // 过滤出email联系人
    Set<String> emailSet = contacts.stream().filter(contact -> Contact.Type.EMAIL.equals(contact.getType())).map(contact -> contact.getAccount()).collect(Collectors.toSet());
    if (emailSet.size() > 0) {
        SenderFactory emailSenderFactory = new EmailSenderFactory();
        Sender emailSender = emailSenderFactory.create();
        String[] emails = {};
        emails = emailSet.toArray(emails);
        if (briefing != null) {
            try {
                BriefingEmail briefingEmail = new BriefingEmail().create(emails, briefing);
                briefingEmail.setSubject(SUBJECT);
                emailSender.send(briefingEmail);
            } catch (IOException | TemplateException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : JobExecutionContext(org.quartz.JobExecutionContext) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) TemplateException(freemarker.template.TemplateException) Logger(org.jboss.logging.Logger) BusinessException(com.topcom.cms.exception.BusinessException) Autowired(org.springframework.beans.factory.annotation.Autowired) Set(java.util.Set) Job(org.quartz.Job) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JobExecutionException(org.quartz.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException) BriefingEmail(com.topcom.cms.yuqing.vo.email.BriefingEmail) Component(org.springframework.stereotype.Component) List(java.util.List) BriefingTask(com.topcom.cms.yuqing.domain.BriefingTask) BriefingTaskManager(com.topcom.cms.yuqing.service.BriefingTaskManager) JSONObject(net.sf.json.JSONObject) Contact(com.topcom.cms.yuqing.domain.Contact) Sender(com.topcom.cms.yuqing.task.sender.Sender) TemplateException(freemarker.template.TemplateException) IOException(java.io.IOException) BriefingEmail(com.topcom.cms.yuqing.vo.email.BriefingEmail) TemplateException(freemarker.template.TemplateException) BusinessException(com.topcom.cms.exception.BusinessException) IOException(java.io.IOException) JobExecutionException(org.quartz.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException) Contact(com.topcom.cms.yuqing.domain.Contact) Sender(com.topcom.cms.yuqing.task.sender.Sender) BusinessException(com.topcom.cms.exception.BusinessException) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) JSONObject(net.sf.json.JSONObject) SenderFactory(com.topcom.cms.yuqing.task.sender.factory.SenderFactory) EmailSenderFactory(com.topcom.cms.yuqing.task.sender.factory.EmailSenderFactory) BriefingTask(com.topcom.cms.yuqing.domain.BriefingTask) JobExecutionException(org.quartz.JobExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

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