Пример #1
0
  public Pager queryForPager(ProductCondition condition) {
    Region region = condition.getRegion();
    Admin admin = condition.getAdmin();
    Set<Region> regions = new HashSet<Region>();

    // 如果是管理员,则需要根据管理员所管辖的地区进行过滤
    if (admin != null) {
      if (region != null) {
        List<Region> list = regionService.getAllChildRegionByRegionId(region.getId());
        for (Region region2 : list) {
          if (admin.getRegionSet().contains(region2)) regions.add(region2);
        }
      } else regions.addAll(admin.getRegionSet()); // 为空则搜索该管理员所管理的所有区域中的数据
    } else {
      if (region != null) {
        regions.addAll(regionService.getAllChildRegionByRegionId(region.getId()));
      }
    }
    condition.setRegions(regions);

    return productDao.queryForPager(condition);
  }
Пример #2
0
 /** 初始化新的店铺管理员 */
 private Admin initStoreAdmin(Store store) {
   Admin admin = new Admin();
   admin.setCreateDate(new Date()); // 设置创建日期
   admin.setEntcode("macro"); // 设置企业号
   admin.setIsEnabled(true); // 设置是否启用:启用
   admin.setIsLocked(false); // 设置是否锁定:否
   admin.setStore(store); // 设置店铺属性
   Role role = roleDao.findByName("店铺管理员"); // 根据角色名称,查找角色
   admin.setLoginFailureCount(0); // 设置连续登录失败次数
   Set<Role> roles = new HashSet<Role>();
   roles.add(role);
   admin.setRoles(roles); // 设置角色属性
   admin.setEmail(store.getEmail()); // 设置申请邮箱为管理员邮箱
   admin.setPassword(DigestUtils.md5Hex("888888")); // 初始密码 888888(md5加密)
   admin.setName(store.getApplyMan()); // 默认申请开店人名称为管理员名称
   String userName = admin.getName();
   String tempStr = userName;
   while (adminDao.usernameExists(userName)) {
     userName = tempStr + "_" + (int) (Math.random() * 1000); // 生成三位随机数
   }
   admin.setUsername(userName); // 用户名 为管理员名称(或 (如果用户名已存在)管理员名称 + "_" +  三位随机数)
   return admin;
 }