Search in sources :

Example 1 with CustomSubject

use of com.topcom.cms.yuqing.domain.CustomSubject 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 2 with CustomSubject

use of com.topcom.cms.yuqing.domain.CustomSubject in project topcom-cloud by 545314690.

the class KafkaTest method sendSubject.

@Test
public void sendSubject() {
    KafkaSender kafkaSender = new KafkaSender();
    kafkaSender.setProps(props);
    CustomSubject subject = new CustomSubject();
    subject.setMustWord("江苏@幼儿园@爆炸");
    subject.setName("江苏幼儿园爆炸");
    subject.setShouldWord("爆炸");
    subject.setStartDate(DateUtils.addDays(new Date(), -5));
    subject.setEndDate(DateUtils.addDays(new Date(), 30));
    for (int i = 0; i < 1000; i++) {
        if (i % 2 == 0)
            subject.setDeleted(true);
        else
            subject.setDeleted(false);
        kafkaSender.getProducer().send(new ProducerRecord<String, String>(SUBJECT_TOPIC, net.sf.json.JSONObject.fromObject(subject).toString()));
    }
}
Also used : CustomSubject(com.topcom.cms.yuqing.domain.CustomSubject) KafkaSender(com.topcom.cms.yuqing.task.kafka.KafkaSender) BaseKafkaSender(com.topcom.cms.yuqing.task.kafka.BaseKafkaSender) Date(java.util.Date) Test(org.junit.Test)

Example 3 with CustomSubject

use of com.topcom.cms.yuqing.domain.CustomSubject in project topcom-cloud by 545314690.

the class BriefingCreatorImpl method updateSpecial.

/**
 * 根据专题id,更新专报
 *
 * @param id
 * @return
 * @throws Exception
 */
@Override
public Future updateSpecial(String id) throws Exception {
    CustomSubject customSubject = subjectManager.findById(Long.valueOf(id));
    // 更新状态
    subjectManager.updateState(Long.valueOf(id), CustomSubject.State.CREATING);
    return createSpecial(customSubject);
}
Also used : CustomSubject(com.topcom.cms.yuqing.domain.CustomSubject)

Example 4 with CustomSubject

use of com.topcom.cms.yuqing.domain.CustomSubject in project topcom-cloud by 545314690.

the class WarningTaskWatcher method doAroundDeleteWarning.

@Around("deleteSubject()")
public void doAroundDeleteWarning(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    if (args.length == 1) {
        Long subjectId = (Long) args[0];
        /**
         * 为了给kafak发送消息,查询一次,并标记为删除
         */
        CustomSubject subject = subjectManager.findById(subjectId);
        /**
         * 执行删除
         */
        joinPoint.proceed(args);
        subject.setDeleted(true);
        // 发送到kafka
        sendToKafka(subject);
        // 删除任务
        deleteJob(String.valueOf(subjectId));
        /**
         * 发送结束
         */
        LogUtil.logger.info("删除任务:" + subjectId + "成功");
    }
}
Also used : CustomSubject(com.topcom.cms.yuqing.domain.CustomSubject) Around(org.aspectj.lang.annotation.Around)

Aggregations

CustomSubject (com.topcom.cms.yuqing.domain.CustomSubject)4 Around (org.aspectj.lang.annotation.Around)2 BusinessException (com.topcom.cms.exception.BusinessException)1 BaseKafkaSender (com.topcom.cms.yuqing.task.kafka.BaseKafkaSender)1 KafkaSender (com.topcom.cms.yuqing.task.kafka.KafkaSender)1 Date (java.util.Date)1 Test (org.junit.Test)1