{"id":83809,"date":"2020-05-08T14:18:24","date_gmt":"2020-05-08T06:18:24","guid":{"rendered":"http:\/\/4563.org\/?p=83809"},"modified":"2020-05-08T14:18:24","modified_gmt":"2020-05-08T06:18:24","slug":"%e5%9f%ba%e4%ba%8e-groovy-%e5%ae%9e%e7%8e%b0%e5%85%ac%e5%bc%8f%e5%ba%93","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=83809","title":{"rendered":"\u57fa\u4e8e groovy \u5b9e\u73b0\u516c\u5f0f\u5e93"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u57fa\u4e8e groovy \u5b9e\u73b0\u516c\u5f0f\u5e93               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : xinQing <\/span>  <span><i><\/i> 1<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u5de5\u4f5c\u4e2d\u57fa\u4e8e groovy \u8bbe\u8ba1\u7684\u516c\u5f0f\u5e93\uff0c\u5e0c\u671b\u80fd\u5e26\u7ed9\u5927\u5bb6\u5e2e\u52a9\u3002<\/p>\n<h2>\u9879\u76ee\u5730\u5740<\/h2>\n<p>Github<\/p>\n<h2>\u8bed\u6cd5<\/h2>\n<pre><code>\u516c\u5f0f\u540d(\u53c2\u6570) <\/code><\/pre>\n<p>\u6bd4\u5982\uff1a<\/p>\n<pre><code>ECHO(\u5927\u4fa0\u738b\u6ce2\u6ce2) <\/code><\/pre>\n<p>\u652f\u6301\u516c\u5f0f\u5d4c\u5957\uff1a<\/p>\n<pre><code>\u516c\u5f0f\u540d 1(\u516c\u5f0f\u540d 2(\u53c2\u6570), \u53c2\u6570) <\/code><\/pre>\n<p>\u6bd4\u5982\uff1a<\/p>\n<pre><code>ECHO(UUID()) <\/code><\/pre>\n<h2>\u5feb\u901f\u5f00\u59cb<\/h2>\n<ol>\n<li>\u521b\u5efa Formula \u5bf9\u8c61 formula<\/li>\n<li>\u8fd0\u884c formula.run(&#8220;script&#8221;)<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u662f\u4f8b\u5b50\uff1a<\/p>\n<pre><code>package tk.fishfish.formula;  import org.junit.Assert; import org.junit.Before; import org.junit.Test;  \/**  * \u516c\u5f0f\u6d4b\u8bd5  *  * @author \u5954\u6ce2\u513f\u705e  * @since 1.0  *\/ public class FormulaTest {      private Formula formula;      @Before     public void setup() {         formula = new Formula();     }      @Test     public void lower() {         Object result = formula.run(\"LOWER(ABC)\");         Assert.assertEquals(\"abc\", result);     }  }  <\/code><\/pre>\n<h2>\u9ed8\u8ba4\u516c\u5f0f<\/h2>\n<p>\u8fd9\u91cc\u53ea\u662f\u629b\u7816\u5f15\u7389\uff0c\u5b9e\u73b0\u4e86\u5982\u4e0b\u6587\u672c\u516c\u5f0f\uff1a<\/p>\n<ul>\n<li>UUID() \u8fd4\u56de uuid<\/li>\n<li>LOWER(xxx) \u8f6c\u5c0f\u5199<\/li>\n<li>UPPER(xxx) \u8f6c\u5927\u5199<\/li>\n<\/ul>\n<p>\u8fd9\u91cc\u672a\u5b9e\u73b0\u4e30\u5bcc\u6587\u672c\u3001\u65f6\u95f4\u3001\u6570\u5b66\u3001\u903b\u8f91\u7b49\u516c\u5f0f\uff0c\u53ea\u662f\u63d0\u4f9b\u4e00\u4e2a\u6269\u5c55\u673a\u5236\uff0c\u65b9\u4fbf\u5927\u5bb6\u5b9a\u5236\u81ea\u5df1\u7684\u516c\u5f0f\u5e93\u3002<\/p>\n<h2>\u5f00\u53d1\u81ea\u5df1\u7684\u516c\u5f0f<\/h2>\n<ul>\n<li>\n<p>\u7ee7\u627f Plugin \u63a5\u53e3<\/p>\n<pre><code>package tk.fishfish.formula.plugin;  import tk.fishfish.formula.annotation.FormulaMapping;  \/**  * \u81ea\u5b9a\u4e49\u516c\u5f0f  *  * @author \u5954\u6ce2\u513f\u705e  * @since 1.0  *\/ public class CustomPlugin implements Plugin {      \/**      * \u5b9e\u73b0\u81ea\u5df1\u7684\u516c\u5f0f      *      * @param name \u53c2\u6570      * @return \u7ed3\u679c      *\/     @FormulaMapping(\"ECHO\")     public String echo(String name) {         return \"echo: \" + name;     }  }  <\/code><\/pre>\n<\/li>\n<li>\n<p>\u81ea\u5b9a\u4e49\u65b9\u6cd5\uff0c\u589e\u52a0 @FormulaMapping \u6ce8\u89e3 \u6620\u5c04\u516c\u5f0f\u540d\u79f0<\/p>\n<\/li>\n<li>\n<p>\u5b89\u88c5\u63d2\u4ef6\u7c7b\uff0cFormulaScript.installPlugin(CustomPlugin.class)<\/p>\n<pre><code>package tk.fishfish.formula;  import org.junit.Assert; import org.junit.Before; import org.junit.Test; import tk.fishfish.formula.plugin.CustomPlugin; import tk.fishfish.formula.script.FormulaScript;  import java.math.BigDecimal;  \/**  * \u516c\u5f0f\u6d4b\u8bd5  *  * @author \u5954\u6ce2\u513f\u705e  * @since 1.0  *\/ public class FormulaTest {      private Formula formula;      @BeforeClass     public static void init() {         \/\/ \u5b89\u88c5\u81ea\u5df1\u7684\u516c\u5f0f\u63d2\u4ef6         FormulaScript.installPlugin(CustomPlugin.class);     }      @Before     public void setup() {         formula = new Formula();     }      @Test     public void plugin() {         Object result = formula.run(\"ECHO(xxx)\");         System.out.println(result);     }  }  <\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u5148\u5b89\u88c5\u81ea\u5df1\u7684\u516c\u5f0f\uff0c\u518d\u521b\u5efa Formula \u5bf9\u8c61<\/li>\n<li>\u516c\u5f0f\u540d\u5168\u5c40\u4e0d\u53ef\u91cd\u590d<\/li>\n<\/ul>\n<h2>SPI \u6269\u5c55<\/h2>\n<p>\u9664\u4e86\u53ef\u4ee5\u624b\u52a8 FormulaScript.installPlugin(CustomPlugin.class) \u5b89\u88c5\u81ea\u5b9a\u4e49\u516c\u5f0f\u4ee5\u5916\uff0c\u8fd8\u80fd\u901a\u8fc7 SPI \u6ce8\u518c\u3002<\/p>\n<p>\u5728 src\/main\/resources\/META-INF\/services \u76ee\u5f55\u4e0b\u521b\u5efa\u540d\u79f0\u4e3a tk.fishfish.formula.plugin.Plugin \u7684\u6587\u4ef6\uff0c\u91cc\u9762\u662f\u5b9e\u73b0\u7c7b\u7684\u5168\u7c7b\u540d\uff1a<\/p>\n<pre><code># custom plugin tk.fishfish.formula.plugin.CustomPlugin <\/code><\/pre>\n<p>\u6b64\u65f6\uff0c\u4f1a\u81ea\u52a8\u901a\u8fc7 SPI \u673a\u5236\u53d1\u73b0\u5b9e\u73b0\u7c7b\uff0c\u81ea\u52a8\u5b89\u88c5\uff0c\u5b9e\u73b0\u89e3\u5076\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>5<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"1532377\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pkwenda <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u770b\u7740\uff0c\u5982\u679c\u505a\u8d22\u52a1\u76f8\u5173\u8fd9\u6837\u7528\u4f1a\u65b9\u4fbf\u4e00\u4e9b\uff0c\u53ef\u8bfb\u6027\u66f4\u597d\uff0c\u6027\u80fd\u65b9\u9762 [eg\uff1a\u52a8\u6001\u7f16\u8bd1] \u6709\u6d4b\u8bd5\u635f\u8017\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532378\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pkwenda <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @pkwenda #1 \u770b\u7740\u4e0d\u9519\uff0c\u5403\u5b57\u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532379\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : w292614191 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u4eec\u5b9e\u73b0\u4e86 Excel \u516c\u5f0f\u8ba1\u7b97\u3001\u884c\u5217\u53d8\u6362\u3001\u5355\u5143\u683c\u5f15\u7528\u8ba1\u7b97\u3001\u51fd\u6570\u89e3\u6790\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532380\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : xinQing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @pkwenda \u521d\u7565\u6d4b\u8bd5\u4e0b\u6765\uff0c\u5355\u6b21\u516c\u5f0f\u8ba1\u7b97\u5728 10ms \u4ee5\u4e0b\uff08\u4e3b\u8981\u770b\u5b9e\u73b0\u7684\u4ee3\u7801\uff0c\u5185\u5b58\u8ba1\u7b97\u90fd\u76f8\u5f53\u5feb\uff09\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"1532381\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : xinQing <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @w292614191 \u6211\u4eec\u4e3b\u8981\u662f\u5b9e\u73b0\u8868\u5355\u516c\u5f0f\uff08\u6bd4\u5982\uff0c\u8868\u5355\u5b57\u6bb5\u6d89\u53ca\u6570\u636e\u53d8\u6362\u3001\u4f9d\u8d56\uff09\uff0cexcel \u8fd9\u5757\u5230\u6ca1\u6709\u6d89\u7565\u5662                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u4e8e groovy \u5b9e\u73b0\u516c\u5f0f\u5e93 \u8cc7&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/83809"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=83809"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/83809\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=83809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=83809"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=83809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}