コード例 #1
0
  public void testUpdatePass2Md5() {
    GeneralCriteria criteria = new GeneralCriteria(User.class);
    GeneralCriteriaResult<User> result = criteria.executeQuery();
    for (User u : result.getData()) {
      u.setPassword(MD5Util.encode(u.getPuk()));

      criteria.getCriteriaQuery().update(u);
      System.out.println("更新MD5:" + u.getPassword());
    }
  }
コード例 #2
0
  public void testQueryView() {

    User entity = new User();
    entity.setStatus("NONEOCT");

    GeneralCriteria criteria = new GeneralCriteria(UserVO.class);
    criteria.setDataOnly(false);
    criteria.addOrder(Order.desc("activeTime"));
    if (entity != null) {
      if (entity.getUsername() != null) {
        criteria.add(Restrictions.eq("username", entity.getUsername()));
      }
      if (entity.getPassword() != null) {
        criteria.add(Restrictions.eq("bindIP", entity.getBindIP()));
      }
      if (entity.getStatus() != null) {
        if (entity.getStatus().equals("NORMAL")) { // 正常
          criteria.add(Restrictions.eq("status", "NORMAL"));
        } else if (entity.getStatus().equals("EXPIRED")) { // 过期
          criteria.add(Restrictions.gt("expiredTime", new Date()));
        } else if (entity.getStatus().equals("NONEOCT")) { // 无流量
          criteria.add(
              Restrictions.sqlRestriction("maxOctets*1024*1024>sumInputOctets+sumOutputOctets"));
        }
      }
    }
    GeneralCriteriaResult<UserVO> result = criteria.executeQuery();
    GeneralCriteriaQuery query = criteria.getCriteriaQuery();
    System.out.println("结果数:" + result.getTotal());
    Calendar c = Calendar.getInstance();
    c.clear();
    c.set(2012, 6, 1);
    Date start = c.getTime();
    c.add(Calendar.MONTH, 12);
    Date end = c.getTime();
    DecimalFormat df = new DecimalFormat(".00");
    for (UserVO vo : result.getData()) {
      System.out.println(vo.getId() + ",username:"******",sumoct:");
      User u = (User) query.get(User.class, vo.getId());

      // UserFeeCycle cycle = new UserFeeCycle();
      //			cycle.setStart(start);
      //			cycle.setEnd(end);

      // double ratio = vo.getActualFee()/(vo.getMaxOctets()*1024);
      // cycle.setCostFee(Double.valueOf(df.format(((cycle.getInputOct()+cycle.getOutputOct())*1.05/1024)*ratio)));
      // cycle.setUser(u);
      // query.save(cycle);
    }
  }
コード例 #3
0
  public void testSave() {

    User u = new User();
    u.setActiveTime(new Date());
    u.setAddress("dsfdsf");
    u.setBindIP("110");
    u.setDisabled(false);
    u.setStatus("11");
    u.setUsername("username");
    u.setRadPolicyId("11");
    u.setPassword("pwd");
    u.setPuk("puk");
    u.setJoinTime(new Date());
    u.setExpiredTime(new Date());
    u.setSumFee(1000L);

    UserService service = (UserService) this.getCtx().getBean("manage.UserService");
    service.save(u);
  }