Пример #1
0
  // 取得需要发送订阅的用户名单
  private List<Actor> findActors(List<Actor> actors, List<Actor> _actors) {
    if (actors == null) actors = new ArrayList<Actor>();
    // 声明部门 单位 岗位下的用户临时变量
    List<Actor> juniorActors;
    for (Actor actor : _actors) {
      // 用户
      if (actor.getType() == Actor.TYPE_USER) {
        if (!actors.contains(actor)) {
          actors.add(actor);
        }
      } else if (actor.getType() == Actor.TYPE_GROUP) { // 岗位
        juniorActors =
            this.actorService.findFollower(
                actor.getId(),
                new Integer[] {ActorRelation.TYPE_BELONG},
                new Integer[] {Actor.TYPE_USER});
        // 递归处理
        if (juniorActors != null && juniorActors.size() > 0) findActors(actors, juniorActors);
      } else { // 部门 或 单位
        juniorActors =
            this.actorService.findDescendantUser(
                actor.getId(),
                new Integer[] {BCConstants.STATUS_ENABLED},
                Actor.TYPE_UNIT,
                Actor.TYPE_DEPARTMENT);
        // 递归处理
        if (juniorActors != null && juniorActors.size() > 0) findActors(actors, juniorActors);
      }
    }

    return actors;
  }
  @Override
  protected Condition getGridSpecalCondition() {
    AndCondition ac = new AndCondition();
    // 查找当前登录用户条件
    SystemContext context = (SystemContext) this.getContext();
    // 当前用户
    Actor actor = context.getUser();

    // 定义id集合
    List<Long> ids = new ArrayList<Long>();

    // 查找属于当前用户
    ids.add(actor.getId());

    // 查找拥有的上级订阅
    List<Actor> uppers =
        this.actorService.findAncestorOrganization(
            actor.getId(),
            new Integer[] {Actor.TYPE_GROUP, Actor.TYPE_DEPARTMENT, Actor.TYPE_UNIT});

    for (Actor upper : uppers) {
      ids.add(upper.getId());
    }

    // 使用in条件
    ac.add(new InCondition("e.aid", ids));

    // 不显示草稿的
    ac.add(new NotEqualsCondition("s.status_", -1));

    return ac;
  }
Пример #3
0
  private void sendEmail(SubscribeEvent event, List<Actor> actors, OperateLog worklog) {
    // 工作日志的详细内容
    String worklog_content = worklog.getContent();
    Email email = new Email();
    worklog_content += "发送方式:邮件[";

    String emailUid = this.idGeneratorService.nexttvak(Email.ATTACH_TYPE);
    email.setUid(emailUid);
    email.setStatus(Email.STATUS_SENDED);
    email.setType(Email.TYPE_NEW);
    email.setFileDate(Calendar.getInstance());
    email.setSendDate(Calendar.getInstance());
    email.setSubject(event.getSubject());
    worklog_content += "邮件主题: " + event.getSubject();

    Map<String, Object> args = new HashMap<String, Object>();
    args.put("content", event.getContent());

    // 根据事件的CODE 加上 “-EMAIL”后缀 查找模板中是否有配置 自定义的模板
    Template custom = this.templateService.loadByCode(event.getCode() + "-EMAIL");

    if (custom != null) {
      email.setContent(this.templateService.format(custom.getCode(), args));
    } else { // 使用默认的邮件模板
      email.setContent(this.templateService.format("BC-EMAIL-SYSTEMAUTOFORWARD", args));
    }
    worklog_content += ",邮件内容: " + event.getContent();
    // 系统管理员发送
    Actor admin = this.actorService.loadByCode("admin");
    email.setSender(admin);

    if (event.getAttachs() != null) {
      for (Attach attach : event.getAttachs()) {
        // 复制附件
        this.attachService.doCopy(
            attach.getPtype(), attach.getPuid(), Email.ATTACH_TYPE, emailUid, true);
      }
    }

    // 设置发送人
    Set<EmailTo> emailTos = new HashSet<EmailTo>();
    worklog_content += ",邮件接收人:";
    EmailTo et;
    int i = 0;
    for (Actor a : actors) {
      et = new EmailTo();
      et.setEmail(email);
      et.setRead(false);
      et.setReceiver(a);
      // 正常发送
      et.setType(EmailTo.TYPE_TO);
      et.setOrderNo(i);
      emailTos.add(et);

      if (i > 0) worklog_content += "、";
      worklog_content += a.getName();
      i++;
    }
    worklog_content += "]";
    worklog.setContent(worklog_content);
    email.setTos(emailTos);

    this.emailService.save(email);
  }