Example #1
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;
  }
Example #2
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;
  }
Example #3
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;
    }
  }
Example #4
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;
  }
Example #5
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;
  }
Example #6
0
  /**
   * 添加
   *
   * @param info 信息值
   * @return ? > 0 : success; ? < 0 : fail
   */
  public void create(ErrorInfo error) {
    error.clear();

    t_products product = new t_products();
    product.is_use = Constants.ENABLE;
    product.is_agency = Constants.NOT_IS_AGENCY;
    // product.fee_description = this.feeDescription; // 手续费描述(常量值读取拼接,无需编辑)

    /* 添加基本信息 */
    error.code = this.addOrEdit(product);

    if (error.code < 0) {
      error.code = -1;
      error.msg = error.FRIEND_INFO + "添加基本信息失败!";

      return;
    }

    /* 添加对应的审核资料 */
    error.code = this.addProductAudit(product.id, product.mark);

    if (error.code < 0) {
      error.code = -2;
      error.msg = error.FRIEND_INFO + "添加审核资料失败!";

      return;
    }

    /* 添加标签和字段 */
    error.code = this.addProductLableAndFiled(product.id, error);

    if (error.code < 0) {
      error.code = -3;
      error.msg = error.FRIEND_INFO + "添加产品标签/字段失败!";

      return;
    }

    /* 添加事件 */
    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.CREATE_PRODUCT, "添加产品", error);

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

      return;
    }
  }
Example #7
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;
  }
Example #8
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;
  }
Example #9
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;
  }
Example #10
0
  /**
   * 删除类别
   *
   * @param supervisorId
   * @param type
   * @param error
   */
  public static void deleteType(long supervisorId, Long[] types, ErrorInfo error) {
    error.clear();

    if (types == null || types.length == 0) {
      error.code = -1;
      error.msg = "请选择要删除的类别";

      return;
    }

    StringBuffer typeString = new StringBuffer("(");

    for (int i = 0; i < types.length; i++) {
      typeString.append("?,");
    }

    typeString.replace(typeString.length() - 1, typeString.length(), ")");

    String sql =
        "delete from t_content_news_types as type where type.id in " + typeString.toString();
    String sql2 =
        "delete from t_content_news as news where news.type_id in " + typeString.toString();

    Query query = JPA.em().createQuery(sql);
    Query query2 = JPA.em().createQuery(sql2);

    for (int i = 0; i < types.length; i++) {
      query.setParameter(i + 1, types[i]);
      query2.setParameter(i + 1, types[i]);
    }

    int rows1 = 0;

    try {
      rows1 = query.executeUpdate();
      query2.executeUpdate();
    } catch (Exception e) {
      JPA.setRollbackOnly();
      e.printStackTrace();
      Logger.info("删除类别时:" + e.getMessage());
      error.code = -1;
      error.msg = "删除类别时出现异常";

      return;
    }

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

      return;
    }

    DealDetail.supervisorEvent(supervisorId, SupervisorEvent.DEL_NEWSTYPE, "删除类别", error);

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

      return;
    }

    error.code = 0;
    error.msg = "类别删除成功";
  }
Example #11
0
  /**
   * 显示类别(该类别的子类别也跟着显示)
   *
   * @param supvisorId 管理员id
   * @param typeId 隐藏类别的id
   * @param error
   * @return
   */
  public static int showType(long supvisorId, long typeId, ErrorInfo error) {
    error.clear();

    //		String sql = "select status from t_content_news_types where id = ?";
    //		boolean status = false;
    //
    //		try {
    //			status = t_content_news_types.find(sql, typeId).first();
    //		} catch(Exception e) {
    //			e.printStackTrace();
    //			error.msg = "查询类别状态失败";
    //			return -1;
    //		}
    //
    //		if(status) {
    //			error.msg = "该类别已是显示状态";
    //			return -1;
    //		}

    EntityManager em = JPA.em();
    String mySql = "update t_content_news_types set status = ? where id = ?";

    int rows = 0;

    try {
      rows = em.createQuery(mySql).setParameter(1, true).setParameter(2, typeId).executeUpdate();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("显示类别,更新类别状态时:" + e.getMessage());
      error.code = -1;
      error.msg = "更新类别状态失败";

      return error.code;
    }

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

      return error.code;
    }

    /*
     * 递归修改子类别的属性
     */
    String sql2 = "select id from t_content_news_types where parent_id = ?";
    List<Long> ids = null;

    try {
      ids = t_content_news_types.find(sql2, typeId).fetch();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("显示类别,查询子类别时:" + e.getMessage());
      error.code = -2;
      error.msg = "更新类别状态失败";

      return error.code;
    }

    if (ids != null && ids.size() != 0) {

      for (long id : ids) {
        showType(supvisorId, id, error);
      }
    }

    DealDetail.supervisorEvent(supvisorId, SupervisorEvent.SHOW_NEWSTYPE, "显示类别", error);

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

      return error.code;
    }

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

    return 0;
  }
Example #12
0
  /**
   * 添加类别
   *
   * @param supvisorId 管理员id
   * @param error
   * @return
   */
  public int addChildType(long supervisorId, ErrorInfo error) {
    error.clear();

    if (this._parentId <= 0) {
      error.code = -1;
      error.msg = "请选择父类别";

      return error.code;
    }

    if (StringUtils.isBlank(name)) {
      error.code = -1;
      error.msg = "请输入类别名称";

      return error.code;
    }

    if (this.order <= 0) {
      error.code = -1;
      error.msg = "请输入排序";

      return error.code;
    }

    if (NewsType.orderExist(this._parentId, order, error)) {
      return error.code;
    }

    t_content_news_types childType = new t_content_news_types();

    childType.parent_id = this._parentId;
    childType.name = this.name;
    childType.description = this.description;
    childType.status = Constants.TRUE;
    childType._order = this.order;

    try {
      childType.save();
    } catch (Exception e) {
      e.printStackTrace();
      Logger.info("添加添加类别时,保存添加的类别时:" + e.getMessage());
      error.code = -1;
      error.msg = "添加类别失败";

      return -1;
    }

    DealDetail.supervisorEvent(supervisorId, SupervisorEvent.ADD_NEWSTYPE, "添加类别", error);

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

      return error.code;
    }

    error.code = 0;
    error.msg = "添加类别成功";
    this._id = childType.id;

    return 0;
  }
Example #13
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;
  }
Example #14
0
  /**
   * 编辑
   *
   * @param id 产品ID
   * @param error 信息值
   * @return ? > 0 : success; ? < 0 : fail
   */
  public void edit(long id, ErrorInfo error) {
    error.clear();

    t_products product = null;

    try {
      product = t_products.findById(id);
    } catch (Exception e) {
      e.printStackTrace();
      Logger.error("产品->编辑:" + e.getMessage());
      error.code = -1;
      error.msg = error.FRIEND_INFO + "编辑失败!";

      return;
    }

    if (null == product) {
      error.code = -2;
      error.msg = error.FRIEND_INFO + "编辑失败!";

      return;
    }

    /* 添加基本信息 */
    error.code = this.addOrEdit(product);

    if (error.code < 0) {
      error.code = -3;
      error.msg = error.FRIEND_INFO + "编辑失败!";

      return;
    }

    /* 删除作废的审核资料 */
    error.code = ProductAuditItem.deleteProductAudit(id);

    if (error.code < 0) {
      error.code = -4;
      error.msg = error.FRIEND_INFO + "编辑失败!";

      return;
    }

    /* 添加对应的审核资料 */
    error.code = this.addProductAudit(id, product.mark);

    if (error.code < 0) {
      error.code = -5;
      error.msg = error.FRIEND_INFO + "编辑失败!";

      return;
    }

    /* 编辑标签和字段 */
    error.code = this.editFiledConten();

    if (error.code < 0) {
      error.code = -6;
      error.msg = error.FRIEND_INFO + "编辑失败!";

      return;
    }

    /* 添加事件 */
    DealDetail.supervisorEvent(
        Supervisor.currSupervisor().id, SupervisorEvent.EDIT_PRODUCT, "编辑产品", error);

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

      return;
    }
  }