屋顶上的骑兵

首页 新随笔 聚合 管理
  5 Posts :: 0 Stories :: 0 Comments :: 0 Trackbacks

通过一个integer类型属性来表示对象所处的状态:

CASE:
Invitor:邀请者对象模型
Integer Invitor.joinstatus:邀请者所处参加状态
当前存在状态声明:是否被邀请,是否注册用户,是否拒绝,是否审批

设计思路:
bit0: 1-invited  , 0-not invited
bit1: 1-registed , 0-not registed
bit2: 1-refused  , 0-not refused
bit3: 1-approved , 0-not approved

Example:0111(7)=the invitor is invited ,and is registed ,and has been refused without approved.

//判断joinstatus状态
public static String theStatusOfApplicant(Invitor iv) throws TrainingAppException {
  String status = "default";
  if (((iv.getJoinStatus() & 0x8) == 0) && ((iv.getJoinStatus() & 0x4) == 0)) {
   status = "default";// 待批准(0x0)
  }
  if (((iv.getJoinStatus() & 0x8) == 0x8) && ((iv.getJoinStatus() & 0x4) == 0)) {
   status = "approved";// 已审批(0x4)
  }
  if (((iv.getJoinStatus() & 0x4) > 0) && ((iv.getJoinStatus() & 0x8) == 0)) {
   status = "refused";// 已拒绝(0x8)
  }
  return status;
 }
//更新joinstatus状态(审批和拒绝为互斥)
private void updateJoinstatus(MainTrainingInfo mtrInfo, List<Invitor> invitors, Integer opertorType) {
  for (Iterator it = invitors.iterator(); it.hasNext();) {
   Invitor iv = (Invitor) it.next();
   if (APPLY_OPERTORTYPE_APPROVE == opertorType.intValue()) { // approve
    iv.setJoinStatus((iv.getJoinStatus() | 0x8) & 0x8);
   } else {
    iv.setJoinStatus((iv.getJoinStatus() | 0x4) & 0x4); // refuse
   }
   iv.setMainId(mtrInfo);
   mtrInfo.getInvitor().add(iv);
  }

  persistence.update(mtrInfo);
  if (APPLY_OPERTORTYPE_APPROVE == opertorType.intValue()) { // approve
   log.info(" ### 申请已获批准,发送邀请邮件.");
   // Send Mails.
   try {
    instanceMailSendService.approveInvitorSendMail(mtrInfo, invitors, getHostEmail(mtrInfo),
      MainTrainingInfoUtil.getLocale(mtrInfo), true, true);
   } catch (Exception e) {
    log.error(e.toString());
   }

  }
 }

posted on 2007-04-23 19:39 alex-0927 阅读(394) 评论(0)  编辑  收藏 所属分类: 技术小结

只有注册用户登录后才能发表评论。


网站导航: