plugin.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml"
  3. xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
  4. <div class="container-fluid">
  5. <div class="row">
  6. <div class="col-md-12">
  7. <!-- 插件文档 -->
  8. <div class="col-md-5">
  9. <blockquote>
  10. <p>插件有什么用?</p>
  11. <small class="text-muted">插件是一种可扩展全量同步和增量同步实现数据转换的技术方式。通过插件可以接收同步数据,自定义同步到目标源的行数据,也能消费数据并实现更多业务场景。</small>
  12. </blockquote>
  13. <p>如何开发插件?</p>
  14. <ol>
  15. <li>新建java或maven工程,比如app</li>
  16. <li>导入开发包:
  17. <ul>
  18. <li>方式1:导入jar <a onClick="downLoad()" href="javascript:;" title="下载开发包">dbsyncer-common-[[${version}]].jar</a></li>
  19. <li>方式2:引入pom(需要安装到本地)
  20. <pre>&lt;dependency&gt;<br/>&nbsp;&nbsp;&lt;groupId>org.ghi&lt;/groupId&gt;<br/>&nbsp;&nbsp;&lt;artifactId>dbsyncer-common&lt;/artifactId&gt;<br/>&nbsp;&nbsp;&lt;version>[[${version}]]&lt;/version&gt;<br/>&lt;/dependency&gt;</pre>
  21. </li>
  22. </ul>
  23. </li>
  24. <li>
  25. <simple>新建一个类,比如MyPlugin,实现接口ConvertService方法</simple>
  26. <pre>package org.test;
  27. import org.dbsyncer.common.spi.ConvertService;
  28. import java.util.List;
  29. import java.util.Map;
  30. public class MyPlugin implements ConvertService{
  31. /**
  32. * 全量同步
  33. *
  34. * @param source 数据源
  35. * @param target 目标源
  36. */
  37. @Override
  38. public void convert(List&lt;Map&gt; source, List&lt;Map&gt; target) {
  39. // TODO 消费或处理数据
  40. }
  41. /**
  42. * 增量同步
  43. *
  44. * @param event 事件(INSERT/UPDATE/DELETE)
  45. * @param source 数据源
  46. * @param target 目标源
  47. */
  48. @Override
  49. public void convert(String event, Map source, Map target) {
  50. // TODO 消费或处理数据
  51. }
  52. /**
  53. * 重写方法:设置版本号
  54. *
  55. * @return
  56. */
  57. @Override
  58. public String getVersion() {
  59. return "1.0.0";
  60. }
  61. /**
  62. * 重写方法:设置插件名称
  63. *
  64. * @return
  65. */
  66. @Override
  67. public String getName() {
  68. return "MyPlugin";
  69. }
  70. }</pre>
  71. </li>
  72. <li>
  73. <simple>/META-INF/新建services文件夹,并在services下新建一个文件,命名为org.dbsyncer.common.spi.ConvertService,文件写入实现类路径org.test.MyPlugin,如果有多个实现就换行再写入</simple>
  74. <p><img draggable="false" th:src="@{'/img/plugin/spi.png'}"></p>
  75. </li>
  76. <li>
  77. <simple>打包jar</simple>
  78. <p><img draggable="false" th:src="@{'/img/plugin/jar.png'}"></p>
  79. </li>
  80. </ol>
  81. </div>
  82. <!-- 插件列表 -->
  83. <div class="col-md-7">
  84. <form id="uploadForm" class="form-horizontal" role="form">
  85. <div class="page-header">
  86. <h3>上传插件 <small>只支持 "jar" 的文件扩展名.</small></h3>
  87. </div>
  88. <div class="form-group">
  89. <div class="file-loading">
  90. <input id="filePlugin" type="file" name="files" multiple="multiple" />
  91. </div>
  92. </div>
  93. <div class="form-group">
  94. <table class="table table-hover">
  95. <caption>插件列表([[${plugins?.size()} ?: 0]])</caption>
  96. <thead>
  97. <tr>
  98. <th>名称</th>
  99. <th>运行驱动</th>
  100. <th>类名</th>
  101. <th>版本</th>
  102. <th>文件</th>
  103. </tr>
  104. </thead>
  105. <tbody id="pluginList">
  106. <tr th:id="${p?.name}" th:each="p,state : ${plugins}">
  107. <td th:title="内置插件" th:if="${p?.unmodifiable}"><i class="fa fa-plug fa_gray" aria-hidden="true"></i> [[${p?.name}]]</td>
  108. <td th:title="普通插件" th:if="${not p?.unmodifiable}"><i class="fa fa-star fa_blueviolet" aria-hidden="true"></i> [[${p?.name}]]</td>
  109. <td th:text="${p?.mappingName}"/>
  110. <td th:text="${p?.className}"/>
  111. <td th:text="${p?.version}"/>
  112. <td th:text="${p?.fileName}"/>
  113. </tr>
  114. </tbody>
  115. </table>
  116. </div>
  117. </form>
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. <script type="text/javascript">
  123. $("#filePlugin").fileinput({
  124. theme: 'fas',
  125. language: 'zh',
  126. uploadUrl: $basePath + '/plugin/plugin',
  127. enctype: 'multipart/form-data',
  128. removeFromPreviewOnError: true, //当选择的文件不符合规则时,例如不是指定后缀文件、大小超出配置等,选择的文件不会出现在预览框中,只会显示错误信息
  129. allowedFileExtensions: ['jar'],
  130. minFileCount: 0, //每次多次上载允许的最小文件数。如果设置为0,则表示文件数是可选的
  131. maxFileCount: 5, //表示允许同时上传的最大文件个数 如果设置为0,则表示允许的文件数不受限制
  132. showPreview: true,
  133. showUpload: true,//不展示上传按钮
  134. validateInitialCount: true,//是否在验证minFileCount和包含初始预览文件计数(服务器上载文件)maxFileCount
  135. }).on("fileuploaded", function(event, data, previewId, index) {
  136. if (!data.response.success) {
  137. bootGrowl(data.response.resultValue, "danger");
  138. }
  139. doLoader("/plugin");
  140. });
  141. function downLoad(){
  142. window.open($basePath + "/plugin/download");
  143. }
  144. </script>
  145. </html>