类 SohelpBootResourceFileServiceImpl

java.lang.Object
net.sohelp.boot.admin.core.service.resource.SohelpBootResourceFileServiceImpl
所有已实现的接口:
ISohelpBootResourceService

public class SohelpBootResourceFileServiceImpl extends Object implements ISohelpBootResourceService
资源配置文件服务实现类,提供基于本地文件系统的资源配置管理功能。
从以下版本开始:
2024/6/4 9:58
作者:
AaronFung
  • 构造器详细资料

    • SohelpBootResourceFileServiceImpl

      public SohelpBootResourceFileServiceImpl()
  • 方法详细资料

    • getResourcePath

      public String getResourcePath(String path)
      获取资源的完整路径(拼接基础路径与传入路径)
      参数:
      path - 相对于资源根目录的相对路径
      返回:
      完整的资源路径字符串
    • getByPath

      @Comment("\u6839\u636e\u6587\u4ef6\u540d\u83b7\u53d6\u6587\u4ef6\u5185\u5bb9") public com.alibaba.fastjson.JSONObject getByPath(String path)
      根据文件路径读取并解析为JSONObject对象
      指定者:
      getByPath 在接口中 ISohelpBootResourceService
      参数:
      path - 文件路径
      返回:
      解析后的JSONObject对象;如果文件不存在则返回null
      抛出:
      BusiException - 业务异常
    • getByPath

      @Comment("\u6839\u636e\u8def\u5f84\u83b7\u53d6\u5bf9\u8c61") public <T> T getByPath(String path, Class<T> cls) throws SQLException
      根据文件路径读取并反序列化为指定类型的Java对象
      指定者:
      getByPath 在接口中 ISohelpBootResourceService
      类型参数:
      T - 泛型参数表示目标类类型
      参数:
      path - 文件路径
      cls - 反序列化的目标类类型
      返回:
      反序列化后的对象实例;如果文件不存在或解析失败则返回null
      抛出:
      SQLException - 数据库访问异常
    • save

      @Comment("\u4fdd\u5b58\u914d\u7f6e\u8d44\u6e90") public Map<String,Object> save(String path, Map<String,Object> formMap) throws SQLException, BusiException
      将表单数据保存到指定路径对应的资源文件中
      指定者:
      save 在接口中 ISohelpBootResourceService
      参数:
      path - 资源文件路径
      formMap - 表单数据映射
      返回:
      包含文件路径和内容的Map结构
      抛出:
      SQLException - 数据库访问异常
      BusiException - 业务逻辑异常
    • importAll

      public void importAll(List<Map<String,Object>> list) throws BusiException
      批量导入所有资源文件数据
      指定者:
      importAll 在接口中 ISohelpBootResourceService
      参数:
      list - 包含资源文件数据的Map列表,每个Map代表一个资源文件的属性键值对
      抛出:
      BusiException - 当导入过程中出现业务异常时抛出
    • exportAll

      public List<Map<String,Object>> exportAll()
      导出指定目录下的所有文件信息

      函数首先从配置中获取资源目录路径,然后遍历该目录下的所有文件(忽略子目录), 将每个文件的文件名和内容读取后存入Map,最终返回包含所有文件信息的List。

      指定者:
      exportAll 在接口中 ISohelpBootResourceService
      返回:
      包含文件信息的List,每个元素是一个Map,包含"file_path"(文件名)和 "file_content"(文件内容)两个键值对。如果目录为空则返回空List。
    • exists

      @Comment("\u5224\u65ad\u8d44\u6e90\u662f\u5426\u5b58\u5728") public boolean exists(String path)
      判断指定路径下的资源是否已存在
      指定者:
      exists 在接口中 ISohelpBootResourceService
      参数:
      path - 资源路径
      返回:
      true表示存在,false表示不存在
    • save

      @Comment("\u4fdd\u5b58\u914d\u7f6e\u8d44\u6e90") public Map<String,Object> save(String path, String context) throws SQLException, BusiException
      保存资源文件:若文件存在则更新,否则新增
      指定者:
      save 在接口中 ISohelpBootResourceService
      参数:
      path - 资源路径
      context - 写入的内容
      返回:
      包含文件路径和内容的Map结构
      抛出:
      SQLException - 数据库访问异常
      BusiException - 业务逻辑异常
    • add

      @Comment("\u521b\u5efa\u914d\u7f6e\u8d44\u6e90") public Map<String,Object> add(String path, String content) throws SQLException, BusiException
      创建新的资源文件
      指定者:
      add 在接口中 ISohelpBootResourceService
      参数:
      path - 资源路径
      content - 文件内容
      返回:
      包含文件路径和内容的Map结构
      抛出:
      SQLException - 数据库访问异常
      BusiException - 业务逻辑异常(如只读模式、文件已存在等)
    • renamePath

      @Comment("\u91cd\u547d\u540d\u8def\u5f84") public void renamePath(String srcFilePath, String newFilePath) throws SQLException, BusiException
      重命名资源文件路径
      指定者:
      renamePath 在接口中 ISohelpBootResourceService
      参数:
      srcFilePath - 原始文件路径
      newFilePath - 新文件路径
      抛出:
      SQLException - 数据库访问异常
      BusiException - 业务逻辑异常(如只读模式)
    • updateByPath

      @Comment("\u66f4\u65b0\u6587\u4ef6\u5185\u5bb9") public Map<String,Object> updateByPath(String path, String content) throws SQLException, BusiException
      更新已有资源文件的内容
      指定者:
      updateByPath 在接口中 ISohelpBootResourceService
      参数:
      path - 文件路径
      content - 需要更新的文件内容
      返回:
      包含文件路径和内容的Map结构
      抛出:
      SQLException - 数据库访问异常
      BusiException - 业务逻辑异常(如只读模式)
    • listByPath

      @Comment("\u6839\u636e\u6307\u5b9a\u8def\u5f84\u8bfb\u53d6\u914d\u7f6e\u8d44\u6e90\u5217\u8868") public List<com.alibaba.fastjson.JSONObject> listByPath(String path)
      根据指定路径读取该目录下所有资源文件,并封装成JSONObject列表
      指定者:
      listByPath 在接口中 ISohelpBootResourceService
      参数:
      path - 指定的资源目录路径
      返回:
      资源文件对应的JSONObject列表;若路径无效或无文件则返回空列表
    • listByPath

      @Comment("\u8bfb\u53d6\u914d\u7f6e\u8d44\u6e90\u5217\u8868") public <T> List<T> listByPath(String filePath, Class<T> cls) throws SQLException
      根据指定路径读取资源文件,并将其转换为目标类型的对象列表
      指定者:
      listByPath 在接口中 ISohelpBootResourceService
      类型参数:
      T - 泛型参数表示目标类型
      参数:
      filePath - 指定的资源目录路径
      cls - 目标类型Class对象
      返回:
      转换后的目标类型对象列表
      抛出:
      SQLException - 数据库访问异常
    • listByRegex

      public List<com.alibaba.fastjson.JSONObject> listByRegex(String filePath, String regex) throws SQLException
      使用正则表达式过滤符合规则的资源文件并返回其对应的JSONObject列表
      指定者:
      listByRegex 在接口中 ISohelpBootResourceService
      参数:
      filePath - 指定的资源目录路径
      regex - 过滤用的正则表达式
      返回:
      符合条件的资源文件对应的JSONObject列表
      抛出:
      SQLException - 数据库访问异常
    • listByRegex

      public <T> List<T> listByRegex(String filePath, String regex, Class<T> cls) throws SQLException
      使用正则表达式过滤符合规则的资源文件,并将其转换为目标类型的对象列表
      指定者:
      listByRegex 在接口中 ISohelpBootResourceService
      类型参数:
      T - 泛型参数表示目标类型
      参数:
      filePath - 指定的资源目录路径
      regex - 过滤用的正则表达式
      cls - 目标类型Class对象
      返回:
      符合条件且成功转换的目标类型对象列表
      抛出:
      SQLException - 数据库访问异常
    • deleteByPath

      @Comment("\u5220\u9664\u914d\u7f6e\u8d44\u6e90") public void deleteByPath(String path) throws BusiException
      删除指定路径的资源文件
      指定者:
      deleteByPath 在接口中 ISohelpBootResourceService
      参数:
      path - 待删除的资源文件路径
      抛出:
      BusiException - 业务逻辑异常(如只读模式)
    • deleteBatch

      @Comment("\u6279\u91cf\u5220\u9664\u914d\u7f6e") public void deleteBatch(String path) throws BusiException
      批量删除指定路径下的资源文件
      指定者:
      deleteBatch 在接口中 ISohelpBootResourceService
      参数:
      path - 待删除的资源目录路径
      抛出:
      BusiException - 业务逻辑异常(如只读模式、路径格式错误)