Пример #1
0
  /**
   * 添加操作记录
   *
   * @param type
   * @param fileName
   * @param error
   * @return
   */
  private static int createOperation(int type, String fileName, ErrorInfo error) {
    error.clear();
    t_db_operations op = new t_db_operations();
    op.supervisor_id = Supervisor.currSupervisor().id;
    op.time = new Date();
    op.ip = DataUtil.getIp();
    op.type = type;
    op.filename = fileName;

    try {
      op.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info(e.getMessage());
      error.code = -1;
      error.msg = "数据库异常";
      JPA.setRollbackOnly();

      return error.code;
    }

    error.code = 0;

    return error.code;
  }
Пример #2
0
  /**
   * 重置(还原出厂设置)
   *
   * @param error
   * @return
   */
  public static int reset(ErrorInfo error) {
    error.clear();

    String backupFileName = backup(false, error);

    if (null == backupFileName) {
      return error.code;
    }

    if (0 != createOperation(DBOperationType.RESET, backupFileName, error)) {
      return error.code;
    }

    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.DB_RESET, "还原出厂初始数据", error);

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

      return error.code;
    }

    if (0
        != MySQLTool.executeSqlFile(
            username, password, host, port, database, resetFileName, error)) {
      JPA.setRollbackOnly();

      return error.code;
    }

    error.code = 0;
    error.msg = "还原出厂设置成功";

    return error.code;
  }
Пример #3
0
  /**
   * 查询机构产品
   *
   * @param error 信息值
   * @return Product
   */
  public static Product queryAgencyProduct(ErrorInfo error) {
    error.clear();

    String hql = "select id from t_products where is_agency = ?";
    Long id = null;

    try {
      id = t_products.find(hql, Constants.ENABLE).first();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("产品->查询机构产品:" + e.getMessage());
      error.msg = error.FRIEND_INFO + ">查询机构产品失败!";

      return null;
    }

    if (null == id || id == 0) {
      error.msg = "没有检测到合作机构产品!";

      return null;
    }

    Product product = new Product();
    product.createBid = true;
    product.id = id;

    return product;
  }
Пример #4
0
  /**
   * 查询最顶级的类别
   *
   * @param supervisorId
   * @param error
   * @return
   */
  public static List<NewsType> queryTopTypes(ErrorInfo error) {
    error.clear();

    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 = -1 order by _order").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;
  }
Пример #5
0
  /**
   * 查询类别包含数量
   *
   * @param parentId
   * @param error
   * @return
   */
  public static List<v_news_types> queryTypeAndCount(long parentId, ErrorInfo error) {
    error.clear();

    List<v_news_types> types = new ArrayList<v_news_types>();
    StringBuffer sql = new StringBuffer("");
    sql.append(SQLTempletes.SELECT);
    sql.append(SQLTempletes.V_NEWS_TYPES);
    sql.append(" and parent_id = ? and status = true order by _order");

    try {
      // types = v_news_types.find("parent_id = ? and status = true order by _order",
      // parentId).fetch();
      EntityManager em = JPA.em();
      Query query = em.createNativeQuery(sql.toString(), v_news_types.class);
      query.setParameter(1, parentId);
      types = query.getResultList();

    } catch (Exception e) {
      e.printStackTrace();
      error.code = -1;
      error.msg = "查询类别失败";
      return null;
    }

    error.code = 0;

    return types;
  }
Пример #6
0
  /**
   * 我要借款,产品列表
   *
   * @param isAgency 是否合作机构标
   * @param error 信息值
   * @return List<Product>
   */
  public static List<Product> queryProduct(int showType, ErrorInfo error) {
    error.clear();

    List<Product> poducts = new ArrayList<Product>();
    List<t_products> tpoducts = null;

    String hql =
        "select new t_products"
            + "(id, name, name_image_filename, small_image_filename, min_amount, max_amount, fit_crowd, applicant_condition)"
            + " from t_products where is_use=? and is_agency=? and show_type in(?, ?) order by _order, time desc";

    try {
      tpoducts =
          t_products
              .find(
                  hql,
                  Constants.ENABLE,
                  Constants.NOT_IS_AGENCY,
                  showType == Constants.SHOW_TYPE_1 ? Constants.PC : Constants.APP,
                  Constants.PC_APP)
              .fetch(Constants.HOME_SHOW_AMOUNT);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("产品->我要借款,产品列表部分字段查询:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "产品列表加载失败!" + error.PROCESS_INFO;

      return null;
    }

    if (null == tpoducts) return poducts;

    Product product = null;

    for (t_products pro : tpoducts) {
      product = new Product();

      product._id = pro.id;
      product.name = pro.name;
      product.nameImageFilename = pro.name_image_filename;
      product.smallImageFilename = pro.small_image_filename;
      product.time = pro.time;
      product.minAmount = pro.min_amount;
      product.maxAmount = pro.max_amount;
      product.fitCrowd = pro.fit_crowd;
      product.applicantCondition =
          pro.applicant_condition.length() > 75
              ? pro.applicant_condition.substring(0, 75)
              : pro.applicant_condition;
      poducts.add(product);
    }

    error.code = 0;

    return poducts;
  }
Пример #7
0
  /**
   * 还原数据库
   *
   * @param fileName
   * @param error
   * @return
   */
  public static int recover(String fileName, ErrorInfo error) {
    error.clear();

    if (StringUtils.isBlank(fileName)) {
      error.code = -1;
      error.msg = "恢复文件不能为空";

      return error.code;
    }

    String backupFileName = backup(false, error);

    if (null == backupFileName) {
      return error.code;
    }

    if (0 != createOperation(DBOperationType.RECOVER, backupFileName, error)) {
      return error.code;
    }

    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.DB_RECOVER, "还原运营数据", error);

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

      return error.code;
    }

    String decryptFileName = Constants.SQL_PATH + UUID.randomUUID().toString() + ".sql";

    if (!FileEncrypt.decrypt(fileName, decryptFileName, Constants.ENCRYPTION_KEY)) {
      error.code = -1;
      error.msg = "还原数据库失败";

      return error.code;
    }

    if (0
        != MySQLTool.executeSqlFile(
            username, password, host, port, database, decryptFileName, error)) {
      JPA.setRollbackOnly();

      return error.code;
    }

    if (!new File(decryptFileName).delete()) {
      error.code = -1;
      error.msg = "还原数据库失败";

      return error.code;
    }

    error.code = 0;
    error.msg = "还原数据库成功";

    return error.code;
  }
Пример #8
0
  /**
   * 获取产品中净值和秒还的属性值
   *
   * @param error 信息值
   * @return List<Integer>
   */
  public static List<Integer> queryLoanType(ErrorInfo error) {
    error.clear();

    String hql = "select loan_type from t_products where loan_type in (?, ?)";

    try {
      return t_products.find(hql, Constants.NET_VALUE_BID, Constants.S_REPAYMENT_BID).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("产品->获取所有产品属性值:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "加载产品属性值失败!" + error.PROCESS_INFO;

      return null;
    }
  }
Пример #9
0
  /** 完善邮箱 */
  public static void doFinishEmail(String email) {

    User user = User.currUser();
    if (user.getIpsStatus() != IpsCheckStatus.EMAILISNULL) {
      check();
    }

    flash.put("email", email);
    user.email = email;

    if (StringUtils.isBlank(email)) {
      flash.error("邮箱不能为空");

      finishEmail();
    }
    if (!RegexUtils.isEmail(email)) {
      flash.error("请填写正确的邮箱地址");
      finishEmail();
    }
    ErrorInfo error = new ErrorInfo();
    User.isEmailExist(email, error);

    String sql = "update t_users set email = ? where id = ?";

    int rows = 0;

    try {
      rows = JpaHelper.execute(sql, email, user.id).executeUpdate();
    } catch (Exception e) {
      JPA.setRollbackOnly();
      e.printStackTrace();
      Logger.info("更新用户邮箱时:" + e.getMessage());
      error.code = -1;
      error.msg = "对不起,由于平台出现故障,此次更新邮箱失败!";
    }
    if (rows == 0) {
      JPA.setRollbackOnly();
      error.code = -1;
      error.msg = "数据未更新";
    }
    if (error.code < 0) {
      flash.error(error.msg);

      finishEmail();
    }
    checkEmail();
  }
Пример #10
0
  /**
   * 根据ID查询4大安全保障信息
   *
   * @param supervisorId
   * @param adsId
   * @param error
   * @return
   */
  public static t_content_advertisements_ensure querySecurityForId(long adsId, ErrorInfo error) {
    t_content_advertisements_ensure security = null;
    error.clear();

    try {
      security = t_content_advertisements_ensure.findById(adsId);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑4大安全保障,根据ID查询4大安全保障信息时:" + e.getMessage());
      error.code = -1;
      error.msg = "查询4大安全保障失败";
    }

    error.code = 0;

    return security;
  }
Пример #11
0
  /**
   * 上架/下架
   *
   * @param pid 产品ID
   * @param isUse 状态值
   * @param error 信息值
   * @return ? > 0 : success; ? < 0 : fail
   */
  public static void editStatus(long pid, boolean isUse, ErrorInfo error) {
    error.clear();

    String hql = "update t_products set is_use=? where id=?";

    Query query = JPA.em().createQuery(hql);
    query.setParameter(1, isUse);
    query.setParameter(2, pid);

    int rows = 0;

    try {
      rows = query.executeUpdate();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("产品->上架/下架:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "上架/下架失败!";

      return;
    }

    if (rows == 0) {
      JPA.setRollbackOnly();
      error.code = -1;
      error.msg = "设置失败!";

      return;
    }

    /* 添加事件 */
    if (isUse) {
      DealDetail.supervisorEvent(
          Supervisor.currSupervisor().id, SupervisorEvent.ENABLE_PRODUCT, "启用借款标产品", error);
    } else {
      DealDetail.supervisorEvent(
          Supervisor.currSupervisor().id, SupervisorEvent.ENABLE_PRODUCT, "暂停借款标产品", error);
    }

    if (error.code < 0) {
      JPA.setRollbackOnly();
      error.msg = "设置失败!";

      return;
    }
  }
Пример #12
0
  /**
   * 查询数据库操作记录
   *
   * @param error
   * @return
   */
  public static PageBean<v_db_operations> queryOperations(
      int currPage, int pageSize, ErrorInfo error) {
    error.clear();

    if (currPage < 1) {
      currPage = 1;
    }

    if (pageSize < 1) {
      pageSize = 10;
    }

    StringBuffer sql = new StringBuffer("");
    sql.append(SQLTempletes.PAGE_SELECT);
    sql.append(SQLTempletes.V_DB_OPERATIONS);

    List<v_db_operations> page = null;
    int count = 0;

    try {
      EntityManager em = JPA.em();
      Query query = em.createNativeQuery(sql.toString(), v_db_operations.class);
      query.setFirstResult((currPage - 1) * pageSize);
      query.setMaxResults(pageSize);
      page = query.getResultList();
      count = QueryUtil.getQueryCount(em);
    } catch (Exception e) {
      Logger.error(e.getMessage());
      error.code = -1;
      error.msg = "数据库异常";

      return null;
    }

    PageBean<v_db_operations> bean = new PageBean<v_db_operations>();
    bean.pageSize = pageSize;
    bean.currPage = currPage;
    bean.page = page;
    bean.totalCount = count;

    error.code = 0;

    return bean;
  }
Пример #13
0
  /** 发送激活邮件 */
  public void sendActiveEmail() {
    ErrorInfo error = new ErrorInfo();

    if (User.currUser().getIpsStatus() != IpsCheckStatus.NONE) {
      error.code = -1;
      error.msg = "非法请求";

      renderJSON(error);
    }

    User user = User.currUser();
    TemplateEmail.activeEmail(user, error);

    if (error.code >= 0) {
      error.msg = "激活邮件发送成功!";
    }

    renderJSON(error);
  }
Пример #14
0
  /**
   * 搜素部分字段查询
   *
   * @param error 信息值
   * @return List<Product>
   */
  public static List<Product> queryProductNames(boolean flag, ErrorInfo error) {
    error.clear();

    List<Product> products = new ArrayList<Product>();
    List<t_products> tproducts = null;

    String hql =
        "select new t_products(id, name, small_image_filename) from t_products where is_use = ?";

    if (!flag) {
      hql += " and is_agency = " + flag;
    }

    try {
      tproducts = t_products.find(hql, Constants.ENABLE).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("产品->搜素部分字段查询:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "产品列表加载失败!" + error.PROCESS_INFO;

      return null;
    }

    if (null == tproducts) {
      return products;
    }

    Product product = null;

    for (t_products pro : tproducts) {
      product = new Product();

      product._id = pro.id;
      product.name = pro.name;
      product.smallImageFilename = pro.small_image_filename;

      products.add(product);
    }

    return products;
  }
Пример #15
0
  /** 获取净值产品的保证金比例 */
  public static double queryNetValueBailScale(ErrorInfo error) {
    error.clear();

    String hql = "select bail_scale from t_products where loan_type = ?";
    Double bailScale = null;

    try {
      bailScale = t_products.find(hql, Constants.NET_VALUE_BID).first();
    } catch (Exception e) {
      Logger.error("产品->获取净值产品的保证金比例:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "获取净值产品的保证金比例失败!";

      return 1;
    }

    if (null == bailScale) {
      return 1;
    } else {
      return bailScale;
    }
  }
Пример #16
0
  /**
   * 查询用户的vip记录
   *
   * @param userId
   * @return
   */
  public static List<t_user_vip_records> queryVipRecord(long userId, ErrorInfo error) {
    error.clear();

    List<t_user_vip_records> vipRecords = null;

    try {
      vipRecords = t_user_vip_records.find("user_id = ?", userId).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("查询vip记录时:" + e.getMessage());

      error.code = -1;
      error.msg = "查询用户的vip记录时出现异常";

      return null;
    }

    error.code = 0;

    return vipRecords;
  }
Пример #17
0
  public static List<AdsEnsure> queryEnsureForFront(ErrorInfo error) {
    error.clear();

    List<AdsEnsure> adsEnsures = new ArrayList<AdsEnsure>();
    List<t_content_advertisements_ensure> ensure = new ArrayList<t_content_advertisements_ensure>();

    String sql =
        "select new t_content_advertisements_ensure(id, title, url, image_filename,"
            + "is_link_enabled, target) from t_content_advertisements_ensure ensure "
            + "where ensure.is_use = 1";
    try {
      ensure = t_content_advertisements_ensure.find(sql).fetch(1, 4);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("查找安全保障,查找安全保障信息时:" + e.getMessage());
      error.msg = "保存安全保障失败";

      return null;
    }

    AdsEnsure adsEnsure = null;

    for (t_content_advertisements_ensure myAdvertisements : ensure) {

      adsEnsure = new AdsEnsure();

      adsEnsure._id = myAdvertisements.id;
      adsEnsure.title = myAdvertisements.title;
      adsEnsure.imageFileName = myAdvertisements.image_filename;
      adsEnsure.url = myAdvertisements.url;
      adsEnsure.isLinkEnabled = myAdvertisements.is_link_enabled;
      adsEnsure.target = myAdvertisements.target;

      adsEnsures.add(adsEnsure);
    }

    error.code = 0;

    return adsEnsures;
  }
Пример #18
0
  /** 添加合作机构 */
  public void createAgency(ErrorInfo error) {
    t_agencies agency = new t_agencies();
    agency.time = new Date(); // 当前时间
    agency.name = this.name;
    agency.credit_level = this.creditLevel;
    agency.introduction = this.introduction;
    agency.id_number = this.id_number;
    agency.imageFilenames = this.imageFilenames; // 借款图片
    agency.is_use = Constants.ENABLE; // 默认为启动

    try {
      agency.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("合作机构->添加合作机构:" + e.getMessage());
      error.msg = "添加失败!";
      this._id = -1;

      return;
    }

    if (agency.id < 0) {
      error.msg = "添加失败!";

      return;
    }

    /* 添加事件 */
    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.CREATE_AGENCY, "添加合作机构", error);

    if (error.code < 0) {
      JPA.setRollbackOnly();
      error.msg = "添加失败!";

      return;
    }

    error.code = 0;
  }
Пример #19
0
  /**
   * 根据父类别id查询子类别信息(用于下拉显示)
   *
   * @param parentId 父类别id
   * @param error
   * @return
   */
  public static t_content_news_types queryParentType(long typeId, ErrorInfo error) {
    error.clear();

    t_content_news_types parentType = new t_content_news_types();

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

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

    if (parentType == null) {
      error.code = -1;
      error.msg = "父类别不存在";

      return null;
    }

    error.code = 0;

    return parentType;
  }
Пример #20
0
  /**
   * 用于前台
   *
   * @param supervisorId
   * @param parentId
   * @param error
   * @return
   */
  public static List<NewsType> queryChildTypes(long parentId, ErrorInfo error) {
    error.clear();

    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.parent_id = ? and type.status = true 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);
    }

    NewsType latestNewsType = new NewsType();
    latestNewsType.setParentId(3L);
    latestNewsType.name = "最新动态";
    childTypes.add(latestNewsType);
    error.code = 0;

    return childTypes;
  }
Пример #21
0
  /**
   * 查询安全保障
   *
   * @return
   */
  public static List<AdsEnsure> queryAdsEnsure(ErrorInfo error) {
    error.clear();

    List<AdsEnsure> adsEnsures = new ArrayList<AdsEnsure>();
    List<t_content_advertisements_ensure> ensure = new ArrayList<t_content_advertisements_ensure>();

    try {
      ensure = t_content_advertisements_ensure.findAll();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("查找安全保障,查找安全保障信息时:" + e.getMessage());
      error.msg = "保存安全保障失败";

      return null;
    }

    AdsEnsure adsEnsure = null;

    for (t_content_advertisements_ensure myAdvertisements : ensure) {

      adsEnsure = new AdsEnsure();

      adsEnsure._id = myAdvertisements.id;
      adsEnsure.title = myAdvertisements.title;
      adsEnsure.location = myAdvertisements.location;
      adsEnsure.resolution = myAdvertisements.resolution;
      adsEnsure.fileSize = myAdvertisements.file_size;
      adsEnsure.fileFormat = myAdvertisements.file_format;
      adsEnsure.url = myAdvertisements.url;
      adsEnsure.isLinkEnabled = myAdvertisements.is_link_enabled;
      adsEnsure.status = myAdvertisements.is_use;

      adsEnsures.add(adsEnsure);
    }

    error.code = 0;

    return adsEnsures;
  }
Пример #22
0
  /** 获取所有产品的id和name */
  public static List<t_products> queryAllProducts(ErrorInfo error) {
    error.clear();

    List<t_products> products;
    String sql = "select new t_products(p.id, p.name) from t_products p";

    Query query = JPA.em().createQuery(sql, t_products.class);
    try {
      products = query.getResultList();
    } catch (Exception e) {
      Logger.error("" + e.getMessage());

      error.code = -1;
      error.msg = "查询所有产品时有误!";

      return null;
    }

    error.code = 0;

    return products;
  }
Пример #23
0
  /**
   * 从操作记录还原
   *
   * @param operationId
   * @param error
   * @return
   */
  public static int recoverFromOperation(int operationId, ErrorInfo error) {
    error.clear();
    String fileName = null;

    try {
      fileName =
          t_db_operations
              .find("select filename from t_db_operations where id = ?", (long) operationId)
              .first();
    } catch (Exception e) {
      Logger.error(e.getMessage());
      e.printStackTrace();
      error.code = -1;
      error.msg = "数据库异常";

      return error.code;
    }

    recover(fileName, error);

    return error.code;
  }
Пример #24
0
  /**
   * 合作机构标,机构列表
   *
   * @param error 信息值
   * @return List<Agency>
   */
  public static List<Agency> queryAgencys(ErrorInfo error) {
    error.clear();

    List<t_agencies> tagencies = null;
    List<Agency> agencys = new ArrayList<Agency>();

    String hql =
        "select new t_agencies(id, name) from t_agencies where is_use =? order by time desc";

    try {
      tagencies = t_agencies.find(hql, Constants.ENABLE).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("合作机构->布合作机构标,机构列表:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "加载合作机构失败!";

      return null;
    }

    if (null == tagencies) {
      return agencys;
    }

    Agency agency = null;

    for (t_agencies tagency : tagencies) {
      agency = new Agency();

      agency._id = tagency.id;
      agency.name = tagency.name;

      agencys.add(agency);
    }

    error.code = 0;

    return agencys;
  }
Пример #25
0
  /**
   * 根据时间算出vip费用
   *
   * @param info
   * @return
   */
  public double vipMoney(ErrorInfo error) {
    error.clear();

    String sql =
        "select _value from t_system_options where _key = ? or _key =? or _key = ? order by id";
    List<String> keys = null;

    try {
      keys =
          t_system_options
              .find(sql, OptionKeys.VIP_MIN_TIME, OptionKeys.VIP_FEE, OptionKeys.VIP_TIME_TYPE)
              .fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("申请vip时,查询系统设置中的vip设置时" + e.getMessage());
      error.code = -1;
      error.msg = "申请vip失败";

      return error.code;
    }

    if (keys == null || keys.size() == 0) {
      error.code = -2;
      error.msg = "读取系统参数失败";

      return error.code;
    }

    if (keys.get(2).equals(Constants.YEAR + "")) {
      this.serviceTime *= 12;
    }

    int vipMinTime = Integer.parseInt(keys.get(1));

    if (this.serviceTime <= vipMinTime) {
      error.code = -3;
      error.msg = "至少开通" + vipMinTime + "月";

      return error.code;
    }

    double vipFee = Double.parseDouble(keys.get(0));
    double fee = Arith.mul(vipFee, serviceTime);

    error.code = 0;

    return fee;
  }
Пример #26
0
  /**
   * 备份数据库
   *
   * @param isVisual 是否在数据库操作记录表中可见
   * @param error
   * @return
   */
  public static String backup(boolean isVisual, ErrorInfo error) {
    error.clear();

    String fileName = Constants.SQL_PATH + UUID.randomUUID().toString();
    FileUtil.getStore(Constants.SQL_PATH);

    if (0 != MySQLTool.dumpSqlFile(username, password, host, port, database, fileName, error)) {
      return null;
    }

    if (!FileEncrypt.encrypt(fileName, Constants.ENCRYPTION_KEY)) {
      error.code = -1;
      error.msg = "备份数据库失败";

      return null;
    }

    if (isVisual) {
      if (0 != createOperation(DBOperationType.BACKUP, fileName, error)) {
        return null;
      }

      DealDetail.supervisorEvent(
          Supervisor.currSupervisor().id, SupervisorEvent.DB_BACKUP, "备份数据", error);

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

        return null;
      }
    }

    error.code = 0;
    error.msg = "备份数据库成功";

    return fileName;
  }
Пример #27
0
  /**
   * 编辑安全保障
   *
   * @param supervisorId
   * @param error
   * @return
   */
  public int updateAdsEnsure(long supervisorId, long adsId, ErrorInfo error) {
    error.clear();

    t_content_advertisements_ensure ensure = null;

    try {
      ensure = t_content_advertisements_ensure.findById(adsId);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑广告条,根据广告ID查询广告信息时:" + e.getMessage());
      error.code = -1;
      error.msg = "查询广告条失败";

      return error.code;
    }

    ensure.title = this.title;
    ensure.location = this.location;
    ensure.file_size = "不超过2M";
    ensure.resolution = this.resolution;
    ensure.file_size = this.fileSize;
    ensure.file_format = this.fileFormat;
    ensure.url = this.url;
    ensure.is_link_enabled = this.isLinkEnabled;
    ensure.target = this.target;
    ensure.image_filename = this.imageFileName;
    ensure.is_use = this.status;

    try {
      ensure.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑安全保障,保存编辑安全保障信息时:" + e.getMessage());
      error.msg = "编辑安全保障失败";

      return -1;
    }

    DealDetail.supervisorEvent(supervisorId, SupervisorEvent.EDIT_ENSURE, "编辑安全保障", error);

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

      return error.code;
    }

    error.code = 0;
    error.msg = "编辑安全保障成功";

    return 0;
  }
Пример #28
0
  /**
   * 编辑类别
   *
   * @param supvisorId
   * @param typeId
   * @param error
   * @return
   */
  public int editType(long supervisorId, long id, ErrorInfo error) {
    error.clear();

    t_content_news_types type = null;

    try {
      type = t_content_news_types.findById(id);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑类别,查询类别时:" + e.getMessage());
      error.code = -1;
      error.msg = "编辑类别失败";

      return error.code;
    }

    type.name = this.name;
    type.description = this.description;
    type._order = this.order;

    try {
      type.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("编辑类别,更新类别时:" + e.getMessage());
      error.code = -2;
      error.msg = "编辑类别失败";

      return error.code;
    }

    DealDetail.supervisorEvent(supervisorId, SupervisorEvent.EDIT_NEWSTYPE, "编辑类别", error);

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

      return error.code;
    }

    error.code = 0;
    error.msg = "更新类别成功";

    return 0;
  }
Пример #29
0
  /**
   * 判断排序是否存在
   *
   * @param typeId
   * @param order
   * @param error
   * @return true存在 false不存在
   */
  public static boolean orderExist(long typeId, int order, ErrorInfo error) {
    error.clear();

    //		if(typeId <= 0) {
    // 			error.code = -1;
    // 			error.msg = "传入参数有误!";
    //
    // 			return true;
    // 		}
    //
    // 		if(!NumberUtil.isNumericInt(orderStr)) {
    // 			error.code = -2;
    // 			error.msg = "传入参数有误!";
    //
    // 			return true;
    // 		}
    //
    // 		long typeId = Long.parseLong(typeIdStr);
    // 		int order = Integer.parseInt(orderStr);

    long count = 0;

    try {
      count = t_content_news_types.count("parent_id = ? and _order = ?", typeId, order);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("查询类别的排序是否存在时:" + e.getMessage());

      error.code = -2;
      error.msg = "数据库查询失败!";

      return true;
    }

    if (count > 0) {
      error.code = -2;
      error.msg = "该排序已存在";

      return true;
    }

    error.code = 0;

    return false;
  }
Пример #30
0
  /**
   * 改变合作机构状态(正常/暂停)
   *
   * @param aid 机构ID
   * @param isUse 正常/暂停
   * @param error 信息值
   */
  public static void editStatus(long aid, boolean isUse, ErrorInfo error) {
    error.clear();

    String hql = "update t_agencies set is_use=? where id=?";
    Query query = JPA.em().createQuery(hql);
    query.setParameter(1, isUse);
    query.setParameter(2, aid);

    int rows = 0;

    try {
      rows = query.executeUpdate();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("合作机构->正常/暂停:" + e.getMessage());
      error.msg = error.FRIEND_INFO + "设置失败!";

      return;
    }

    if (rows == 0) {
      JPA.setRollbackOnly();
      error.code = -1;
      error.msg = "设置失败!";

      return;
    }

    /* 添加事件 */
    if (isUse)
      DealDetail.supervisorEvent(
          Supervisor.currSupervisor().id, SupervisorEvent.ENABLE_AGENCY, "启用合作机构", error);
    else
      DealDetail.supervisorEvent(
          Supervisor.currSupervisor().id, SupervisorEvent.NOT_ENABLE_AGENCY, "暂停合作机构", error);
    if (error.code < 0) {
      JPA.setRollbackOnly();
      error.msg = "设置失败!";

      return;
    }

    error.code = 0;
  }