{"id":2173,"date":"2025-08-06T11:52:16","date_gmt":"2025-08-06T03:52:16","guid":{"rendered":"https:\/\/note.ui11.cc\/?p=2173"},"modified":"2025-08-06T11:52:17","modified_gmt":"2025-08-06T03:52:17","slug":"%e5%b9%b4%e4%bb%bd%e6%a0%a1%e9%aa%8c%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/note.ui11.cc\/index.php\/2025\/08\/06\/%e5%b9%b4%e4%bb%bd%e6%a0%a1%e9%aa%8c%e4%bb%a3%e7%a0%81%e5%88%86%e6%9e%90\/","title":{"rendered":"\u5e74\u4efd\u6821\u9a8c\u4ee3\u7801\u5206\u6790"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>package com.yonyou.ucf.mdf.sample.bill.plugin;\n\n\nimport com.yonyou.iuap.log.exception.BusinessException;\nimport com.yonyou.ucf.mdd.ext.dao.meta.MetaDaoHelper;\nimport com.yonyou.ucf.mdf.sample.bill.entity.EmployeeTravelApplication;\nimport com.yonyou.ypd.bill.annotation.BillPlugin;\nimport com.yonyou.ypd.bill.context.YpdBillContext;\nimport com.yonyou.ypd.bill.plugin.AbstractBillPlugin;\nimport lombok.extern.slf4j.Slf4j;\nimport org.apache.commons.collections4.CollectionUtils;\n\nimport java.time.LocalDate;\nimport java.util.List;\nimport java.util.Map;\n\n@Slf4j\n@BillPlugin(busiObj = \"employeeTravelApplication\")  \/\/\u5458\u5de5\u65c5\u6e38\u4fe1\u606f\u8868\npublic class EmployeeTravelApplicationPlugin extends AbstractBillPlugin {\n    @Override\n    public void beforeSave(YpdBillContext billContext) throws Exception {\n        \/\/ \u8bbe\u7f6e\u4fdd\u5b58\u524d\u7684\u6821\u9a8c\u89c4\u5219\n        \/\/ \u8bbe\u7f6e\u81ea\u5b9a\u4e49\u6863\u6848\uff0c\u83b7\u53d6\u5f53\u524d\u65c5\u6e38\u65f6\u95f4\u6bb5\n        EmployeeTravelApplication billDO = (EmployeeTravelApplication)billContext.getBillDO();\n\/\/EmployeeTravelApplication\u8fd9\u4e2a\u662f\n        int year = LocalDate.now().getYear();\/\/\u62ff\u5230\u5f53\u524d\u65f6\u95f4\n        \/\/ \u83b7\u53d6\u81ea\u5b9a\u4e49\u6863\u6848\u7ef4\u62a4\u7684\u4fe1\u606f\n        String docSql = \" select bcd.id,bcd.name,bcd.code from\\n\" +\n                \"   iuap_apdoc_basedoc.bd_cust_doc_def  bcdd \" +\n                \" left join   iuap_apdoc_basedoc.bd_cust_doc bcd on bcdd.id = bcd.custdocdefid \" +\n                \"  where bcd.dr=0 and bcd.enable=1   and bcd.code='\"+year+\"' and bcdd.code='traveltimeperiod' and bcdd.ytenant_id='avhwpwua' and bcd.ytenant_id='avhwpwua' \";\n\/\/\u5230\u8fd9\u5c31\u7b97\u62ff\u5230\u81ea\u5b9a\u4e49\u6863\u6848\u4fe1\u606f\u4e86\n\n        List&lt;Map&lt;String, Object&gt;&gt; info = MetaDaoHelper.selectSql(docSql, null);\n        \/\/\u6267\u884c\u540e\u62ff\u5230info,\nif(CollectionUtils.isNotEmpty(info)){\n            Map&lt;String, Object&gt; infoMap = info.get(0);\n            String name = (String)infoMap.get(\"name\");\n            String&#91;] dateArr = name.split(\",\");\n\n\/\/\u4f8b\u5982\uff1a\u5982\u679c name \u662f \"2024,2024\"\uff0c\u5206\u5272\u540e dateArr&#91;0] = \"2024\"\uff0cdateArr&#91;1] = \"2024\"\uff08\u5206\u522b\u8868\u793a\u65f6\u95f4\u6bb5\u7684\u5f00\u59cb\u5e74\u4efd\u548c\u7ed3\u675f\u5e74\u4efd\uff09\/\/\n\n            String startDate = dateArr&#91;0]+\"-01-01\";\n            String endDate = dateArr&#91;1]+\"-12-31\";\n            String employee = billDO.getEmployee();\n            \/\/ \u8fd9\u4e2a\u5458\u5de5\u4e2d\u5ba1\u6279\u4e2d\u548c\u5ba1\u6279\u901a\u8fc7\u7684\u6570\u636e\n            String sqlcount =\"select count(*) countNum from xlx001_db.t_employeetravelapplication where dr=0 and ytenant_id='avhwpwua' and DATE_FORMAT(create_time,'%Y-%m-%d') &gt;='\"+startDate+\"'\\n\" +\n                    \"and DATE_FORMAT(create_time,'%Y-%m-%d') &lt;='\"+endDate+\"' and verifystate in (1,2) and employee='\"+employee+\"' \";\n            List&lt;Map&lt;String, Object&gt;&gt; countList = MetaDaoHelper.selectSql(sqlcount, null);\n            if(CollectionUtils.isNotEmpty(countList)){\n                Long countNum = (Long)countList.get(0).get(\"countNum\");\n                if(countNum&gt;=1){\n                    throw new BusinessException(\"\u60a8\u597d\uff0c\u60a8\u5df2\u53c2\u4e0e\u8fc7\u672c\u8f6e\u65c5\u6e38\uff0c\u672c\u6b21\u6682\u65e0\u6cd5\u5b89\u6392\uff0c\u8c22\u7406\u89e3\uff5e\");\n                }\n            }\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u5730\u65b9\u5982\u679c\u6709\u95ee\u9898\u63d0\u793a\u7ed9\u524d\u7aef\u76f4\u63a5\u7528\u5f02\u5e38\u629b\u51fa\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>throw new BusinessException(\"\u60a8\u597d\uff0c\u60a8\u5df2\u53c2\u4e0e\u8fc7\u672c\u8f6e\u65c5\u6e38\uff0c\u672c\u6b21\u6682\u65e0\u6cd5\u5b89\u6392\uff0c\u8c22\u7406\u89e3\uff5e\");<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u4e5f\u662f\u7ee7\u627f\u4e86AbstractBillPlugin \uff0c\u91cc\u9762\u6709\u5f88\u591a\u63a5\u53e3\uff0c\u6bd4\u5982before\uff0cafter\u7b49\u7b49<\/p>\n\n\n\n<p>YpdBillContext billContext  \u53c2\u6570 billContext   \u8fd9\u4e2a<\/p>\n\n\n\n<p>\u8fc7&nbsp;<code>billContext.getBillDO()<\/code>&nbsp;\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u64cd\u4f5c\u7684\u5355\u636e\u6570\u636e\u5bf9\u8c61\uff08<code>Bill Data Object<\/code>\uff09\uff0c\u4e5f\u5c31\u662f\u4ee3\u7801\u4e2d\u7684&nbsp;<code>EmployeeTravelApplication<\/code>&nbsp;\u5b9e\u4f53\u3002\u8fd9\u4e2a\u5bf9\u8c61\u5305\u542b\u4e86\u8868\u5355\u4e2d\u586b\u5199\u7684\u6240\u6709\u4e1a\u52a1\u6570\u636e\uff08\u5982&nbsp;<code>employee<\/code>&nbsp;\u5458\u5de5\u4fe1\u606f\u3001\u884c\u7a0b\u4fe1\u606f\u7b49\uff09\uff0c\u662f\u63d2\u4ef6\u83b7\u53d6\u4e1a\u52a1\u6570\u636e\u7684\u4e3b\u8981\u5165\u53e3\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code has-black-color has-text-color has-link-color wp-elements-80ebb9cda136e22ff3c9185411bd1623\"><code>billDO\u7684\u4f5c\u7528\uff1a\n\u901a\u8fc7\u8fd9\u4e2a\u65b9\u6cd5\u62ff\u5230\u7684 BillDO \u5bf9\u8c61\uff08\u5728\u4f60\u7684\u4ee3\u7801\u4e2d\u662f EmployeeTravelApplication \u5b9e\u4f8b\uff09\uff0c\u5305\u542b\u4e86\u8be5\u5355\u636e\u7684\u6240\u6709\u5b57\u6bb5\u503c\u3002\u4f8b\u5982\uff1a\njava\n\u8fd0\u884c\n\/\/ \u83b7\u53d6\u5f53\u524d\u65c5\u6e38\u7533\u8bf7\u5355\u636e\u7684\u5168\u90e8\u6570\u636e\nEmployeeTravelApplication billDO = (EmployeeTravelApplication) billContext.getBillDO();\n\/\/ \u4ece\u5355\u636e\u6570\u636e\u4e2d\u63d0\u53d6\u5177\u4f53\u5b57\u6bb5\uff08\u5982\u5458\u5de5ID\u3001\u7533\u8bf7\u65e5\u671f\u7b49\uff09\nString employeeId = billDO.getEmployee(); \nLocalDate applyDate = billDO.getApplyDate();\n\n<strong>\u53ef\u4ee5\u7406\u89e3\u4e3a\uff1agetBillDO() \u5e2e\u4f60\u628a\u524d\u7aef\u63d0\u4ea4\u7684\u8868\u5355\u6570\u636e\uff0c\u6216\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u7684\u5355\u636e\u6570\u636e\uff0c\u8f6c\u6362\u6210\u4e86\u4e00\u4e2a\u53ef\u76f4\u63a5\u64cd\u4f5c\u7684 Java \u5bf9\u8c61\u3002\n<\/strong>\u4fee\u6539\u5355\u636e\u6570\u636e\n\u62ff\u5230 BillDO \u5bf9\u8c61\u540e\uff0c\u4e0d\u4ec5\u53ef\u4ee5\u8bfb\u53d6\u5b57\u6bb5\u503c\uff0c\u8fd8\u80fd\u4fee\u6539\u5b83\u7684\u5b57\u6bb5\uff08\u5728\u4fdd\u5b58\u524d\u7684\u63d2\u4ef6\u4e2d\u4fee\u6539\u4f1a\u751f\u6548\uff09\u3002\u4f8b\u5982\uff1a\njava\n\u8fd0\u884c\n<strong>billDO.setApplyStatus(\"\u5f85\u90e8\u95e8\u5ba1\u6279\"); \/\/ \u4fee\u6539\u5355\u636e\u72b6\u6001\nbillDO.setUpdateTime(new Date());   \/\/ \u66f4\u65b0\u4fee\u6539\u65f6\u95f4<\/strong>\n\n\n\u8fd9\u4e9b\u4fee\u6539\u4f1a\u88ab\u6846\u67b6\u81ea\u52a8\u540c\u6b65\u5230\u5e95\u5c42\u6570\u636e\u5b58\u50a8\uff08\u5982\u6570\u636e\u5e93\uff09\u3002\n\u9002\u914d\u4e0d\u540c\u5355\u636e\u7c7b\u578b\n\u6846\u67b6\u4e2d\u6240\u6709\u5355\u636e\uff08\u5982\u8bf7\u5047\u5355\u3001\u62a5\u9500\u5355\u3001\u65c5\u6e38\u7533\u8bf7\u5355\uff09\u7684\u5904\u7406\u903b\u8f91\u90fd\u4f9d\u8d56\u8fd9\u4e2a\u65b9\u6cd5\uff0c\u5b83\u4f1a\u6839\u636e\u5f53\u524d\u64cd\u4f5c\u7684\u5355\u636e\u7c7b\u578b\uff08\u5982\u4f60\u7684 employeeTravelApplication\uff09\uff0c\u8fd4\u56de\u5bf9\u5e94\u7684\u5177\u4f53 BillDO \u5b9e\u73b0\u7c7b\uff0c\u4fdd\u8bc1\u7c7b\u578b\u5339\u914d\u3002<\/code><\/pre>\n\n\n\n<p><code>ectionUtils<\/code>\uff08Apache Commons Collections \u5de5\u5177\u7c7b\uff09\u4e3b\u8981\u7528\u4e8e\u64cd\u4f5c&nbsp;<strong><code>java.util.Collection<\/code>&nbsp;\u63a5\u53e3\u7684\u6240\u6709\u5b9e\u73b0\u7c7b<\/strong>\uff0c\u8986\u76d6\u4e86 Java \u4e2d\u7edd\u5927\u591a\u6570\u5e38\u7528\u96c6\u5408\u7c7b\u578b\uff0c\u4f46\u5e76\u975e \u201c\u6240\u6709\u96c6\u5408\u201d\uff08\u6709\u7279\u5b9a\u8303\u56f4\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5177\u4f53\u53ef\u64cd\u4f5c\u7684\u96c6\u5408\u7c7b\u578b\uff1a<\/h3>\n\n\n\n<p>\u53ea\u8981\u662f\u5b9e\u73b0\u4e86&nbsp;<code>java.util.Collection<\/code>&nbsp;\u63a5\u53e3\u7684\u96c6\u5408\uff0c\u90fd\u53ef\u4ee5\u7528&nbsp;<code>CollectionUtils<\/code>&nbsp;\u64cd\u4f5c\uff0c\u5305\u62ec\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>List \u7cfb\u5217<\/strong>\uff1a<code>ArrayList<\/code>\u3001<code>LinkedList<\/code>\u3001<code>Vector<\/code>&nbsp;\u7b49<\/li>\n\n\n\n<li><strong>Set \u7cfb\u5217<\/strong>\uff1a<code>HashSet<\/code>\u3001<code>TreeSet<\/code>\u3001<code>LinkedHashSet<\/code>&nbsp;\u7b49<\/li>\n\n\n\n<li><strong>\u961f\u5217 \/ \u6808<\/strong>\uff1a<code>ArrayDeque<\/code>\u3001<code>PriorityQueue<\/code>&nbsp;\u7b49\uff08\u5b83\u4eec\u4e5f\u5b9e\u73b0\u4e86&nbsp;<code>Collection<\/code>\uff09<\/li>\n\n\n\n<li><strong>\u5176\u4ed6\u81ea\u5b9a\u4e49\u96c6\u5408<\/strong>\uff1a\u53ea\u8981\u81ea\u5b9a\u4e49\u7c7b\u5b9e\u73b0\u4e86&nbsp;<code>Collection<\/code>&nbsp;\u63a5\u53e3\uff0c\u5c31\u80fd\u88ab\u652f\u6301<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u4e0d\u9002\u7528\u7684\u60c5\u51b5\uff1a<\/h3>\n\n\n\n<p><code>CollectionUtils<\/code>&nbsp;\u4e0d\u80fd\u76f4\u63a5\u64cd\u4f5c&nbsp;<strong>\u975e&nbsp;<code>Collection<\/code>&nbsp;\u63a5\u53e3\u7684\u5bb9\u5668\u7c7b<\/strong>\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Map \u7cfb\u5217<\/strong>\uff08<code>HashMap<\/code>\u3001<code>TreeMap<\/code>&nbsp;\u7b49\uff09\uff1a<code>Map<\/code>&nbsp;\u4e0d\u7ee7\u627f&nbsp;<code>Collection<\/code>\uff0c\u9700\u7528\u4e13\u95e8\u7684&nbsp;<code>MapUtils<\/code>&nbsp;\u5de5\u5177\u7c7b\u5904\u7406\u3002<\/li>\n\n\n\n<li><strong>\u6570\u7ec4<\/strong>\uff08<code>int[]<\/code>\u3001<code>String[]<\/code>&nbsp;\u7b49\uff09\uff1a\u6570\u7ec4\u4e0d\u662f&nbsp;<code>Collection<\/code>&nbsp;\u5b9e\u73b0\u7c7b\uff0c\u9700\u7528&nbsp;<code>ArrayUtils<\/code>&nbsp;\u5de5\u5177\u7c7b\u3002<\/li>\n\n\n\n<li><strong>\u7279\u6b8a\u5bb9\u5668<\/strong>\uff1a\u5982&nbsp;<code>String<\/code>\uff08\u672c\u8d28\u662f\u5b57\u7b26\u5e8f\u5217\uff09\u3001<code>Enumeration<\/code>&nbsp;\u7b49\uff0c\u9700\u7528\u5bf9\u5e94\u5de5\u5177\u7c7b\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u5730\u65b9\u5982\u679c\u6709\u95ee\u9898\u63d0\u793a\u7ed9\u524d\u7aef\u76f4\u63a5\u7528\u5f02\u5e38\u629b\u51fa\u5373\u53ef \u8fd9\u4e2a\u4e5f\u662f\u7ee7\u627f\u4e86AbstractBillPlugin \uff0c\u91cc\u9762\u6709\u5f88 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-2173","post","type-post","status-publish","format-standard","hentry","category-yonyou"],"_links":{"self":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2173","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/comments?post=2173"}],"version-history":[{"count":1,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2173\/revisions"}],"predecessor-version":[{"id":2174,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/posts\/2173\/revisions\/2174"}],"wp:attachment":[{"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/media?parent=2173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/categories?post=2173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/note.ui11.cc\/index.php\/wp-json\/wp\/v2\/tags?post=2173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}