Пример #1
0
  /**
   * 获取 参数值
   *
   * @param pageBean 当前模板PageBean
   * @return String [] 参数值
   */
  public static String[] getParameter(PageBean pageBean, String userId) {
    String currPage = params.get("currPage"); // 当前页
    String pageSize = params.get("pageSize"); // 分页行数
    String condition = params.get("condition"); // 条件
    String keyword = params.get("keyword"); // 关键词
    String startDate = params.get("startDate"); // 开始时间
    String endDate = params.get("endDate"); // 结束时间
    String orderIndex = params.get("orderIndex"); // 排序索引
    String orderStatus = params.get("orderStatus"); // 升降标示

    pageBean.currPage = NumberUtil.isNumericInt(currPage) ? Integer.parseInt(currPage) : 1;
    pageBean.pageSize = NumberUtil.isNumericInt(pageSize) ? Integer.parseInt(pageSize) : 10;

    /* ""/null:标示非用户ID查询  */
    return new String[] {userId, condition, keyword, startDate, endDate, orderIndex, orderStatus};
  }
Пример #2
0
  /**
   * 根据父类别id查询子类别信息(用于下拉显示)
   *
   * @param parentId 父类别id
   * @param error
   * @return
   */
  public static List<t_content_news_types> queryChildTypesForList(
      String parentIdStr, ErrorInfo error) {
    error.clear();

    if (!NumberUtil.isNumericInt(parentIdStr)) {
      error.code = -1;
      error.msg = "传入类型参数有误!";
    }

    long parentId = Long.parseLong(parentIdStr);

    List<t_content_news_types> types = new ArrayList<t_content_news_types>();
    //		List<NewsType> childTypes = new ArrayList<NewsType>();

    String sql =
        "select new t_content_news_types(id, name) from t_content_news_types type where "
            + "type.status = true and type.parent_id = ? order by _order";

    try {
      types = t_content_news_types.find(sql, parentId).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      error.code = -1;
      error.msg = "查询类别失败";
      return null;
    }

    //		NewsType childType = null;

    //		for(t_content_news_types type : types) {
    //
    //			childType = new NewsType();
    //
    //			childType._id = type.id;
    //			childType.name = type.name;
    //
    //			childTypes.add(childType);
    //		}

    error.code = 0;

    return types;
  }
Пример #3
0
  /**
   * 根据父类别id查询子类别信息(列表显示)
   *
   * @param parentId 父类别id
   * @param error
   * @return
   */
  public static List<NewsType> queryChildTypes(
      long supervisorId, String parentIdStr, ErrorInfo error) {
    error.clear();

    if (!NumberUtil.isNumericInt(parentIdStr)) {
      error.code = -1;
      error.msg = "传入类型参数有误!";
    }

    long parentId = Long.parseLong(parentIdStr);

    List<t_content_news_types> types = new ArrayList<t_content_news_types>();
    List<NewsType> childTypes = new ArrayList<NewsType>();

    try {
      types = t_content_news_types.find("parent_id = ? order by _order", parentId).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      error.code = -1;
      error.msg = "查询类别失败";
      return null;
    }

    NewsType childType = null;

    for (t_content_news_types type : types) {

      childType = new NewsType();

      childType._id = type.id;
      childType.name = type.name;
      childType.parentId = type.parent_id;
      childType.description = type.description;
      childType.status = type.status;
      childType.order = type._order;

      childTypes.add(childType);
    }

    error.code = 0;

    return childTypes;
  }
Пример #4
0
  /**
   * 启用安全保障
   *
   * @param supervisorId
   * @param id
   * @param error
   * @return
   */
  public static int updateAdsEnsureStatus(
      long supervisorId, String idStr, String statusStr, ErrorInfo error) {
    error.clear();

    if (!NumberUtil.isNumericInt(idStr)) {
      error.code = -1;
      error.msg = "传入广告条参数有误!";

      return error.code;
    }

    if (!NumberUtil.isNumericInt(statusStr)) {
      error.code = -2;
      error.msg = "传入广告条参数有误!";

      return error.code;
    }

    int statusInt = Integer.parseInt(statusStr);

    if (statusInt != 0 && statusInt != 1) {
      error.code = -2;
      error.msg = "传入广告条参数有误!";

      return error.code;
    }

    boolean status = statusInt == 0 ? false : true;
    long adsId = Long.parseLong(idStr);

    String sql = "update t_content_advertisements_ensure set is_use = ? where id = ?";
    EntityManager em = JPA.em();
    Query query = em.createQuery(sql).setParameter(1, !status).setParameter(2, adsId);

    int rows = 0;

    try {
      rows = query.executeUpdate();
    } catch (Exception e) {
      JPA.setRollbackOnly();
      e.printStackTrace();
      Logger.info("更新安全保障,更新安全保障信息时:" + e.getMessage());
      error.msg = "更新安全保障失败";

      return -1;
    }

    if (rows == 0) {
      JPA.setRollbackOnly();
      error.code = -1;
      error.msg = "数据未更新";

      return error.code;
    }

    if (status == false) {
      DealDetail.supervisorEvent(
          supervisorId, SupervisorEvent.OPEN_USE_ENSURE, "启用四大安全保障使用", error);
    } else {
      DealDetail.supervisorEvent(
          supervisorId, SupervisorEvent.CLOSE_USE_ENSURE, "关闭四大安全保障使用", error);
    }

    if (error.code < 0) {
      JPA.setRollbackOnly();

      return error.code;
    }

    error.code = 0;
    error.msg = "更新安全保障成功";

    return 0;
  }
Пример #5
0
  /**
   * 合作结构列表
   *
   * @param pageBean 分页对象
   * @param error 信息值
   * @return List<v_agencies>
   */
  public static List<v_agencies> queryAgencies(
      PageBean<v_agencies> pageBean, ErrorInfo error, String condition, String keyword) {
    error.clear();

    int count = -1;
    StringBuffer conditions = new StringBuffer(" where 1 = 1");
    List<Object> values = new ArrayList<Object>();
    Map<String, Object> conditionmap = new HashMap<String, Object>();

    /* 组装条件 */
    if (NumberUtil.isNumericInt(condition)) {

      switch (Integer.parseInt(condition)) {
          /* 编号搜索 */
        case Constants.AGENCY_SEARCH_ID:
          conditions.append(" AND no LIKE ?");
          values.add("%" + keyword + "%");

          break;

          /* 名称搜索 */
        case Constants.AGENCY_SEARCH_NAME:
          conditions.append(" AND name LIKE ?");
          values.add("%" + keyword + "%");

          break;

          /* 全部搜索 */
        case Constants.SEARCH_ALL:
          if (StringUtils.isBlank(keyword)) break;

          conditions.append(" AND (no LIKE ? OR name LIKE ?)");
          values.add("%" + keyword + "%");
          values.add("%" + keyword + "%");

          break;
      }

      conditionmap.put("condition", condition);
      conditionmap.put("keyword", keyword);
    }

    pageBean.conditions = conditionmap;

    StringBuffer sql = new StringBuffer();
    sql.append("select count(t.id) from (");
    sql.append(SQLTempletes.V_AGENCIES);
    sql.append(")");
    sql.append(SQLTempletes.TABLE_NAME);
    sql.append(conditions);

    EntityManager em = JPA.em();
    Query query = em.createNativeQuery(sql.toString());

    for (int n = 1; n <= values.size(); n++) {
      query.setParameter(n, values.get(n - 1));
    }

    List<?> list = null;

    try {
      list = query.getResultList();
    } catch (Exception e) {
      Logger.error("合作机构->合作结构列表,查询总记录数:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "加载合作结构列表失败!";
    }

    count = list == null ? 0 : Integer.parseInt(list.get(0).toString());

    if (count < 1) return new ArrayList<v_agencies>();

    pageBean.totalCount = count;

    sql = new StringBuffer();
    sql.append("select t.* from (");
    sql.append(SQLTempletes.V_AGENCIES);
    sql.append(")");
    sql.append(SQLTempletes.TABLE_NAME);
    sql.append(conditions);
    sql.append(" order by t.id desc");

    query = em.createNativeQuery(sql.toString(), v_agencies.class);

    for (int n = 1; n <= values.size(); n++) {
      query.setParameter(n, values.get(n - 1));
    }

    query.setFirstResult((pageBean.currPage - 1) * pageBean.pageSize);
    query.setMaxResults(pageBean.pageSize);

    try {
      return query.getResultList();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("标->合作结构列表:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "加载合作结构列表失败!";

      return null;
    }
  }