From 2e6bb454f42a28f719e40abeeeb87e12b4efa93f Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期一, 16 三月 2020 09:58:40 +0800 Subject: [PATCH] Merge branch 'master' of https://gitee.com/y_project/RuoYi-Vue --- ruoyi/src/main/java/com/ruoyi/common/filter/XssFilter.java | 2 ruoyi/src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java | 6 ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java | 2 ruoyi/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java | 2 ruoyi-ui/src/views/system/menu/index.vue | 19 + ruoyi-ui/bin/build.bat | 12 + ruoyi-ui/src/views/dashboard/mixins/resize.js | 56 +++-- ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java | 2 ruoyi-ui/package.json | 2 ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysNoticeMapper.java | 2 ruoyi-ui/src/layout/components/TagsView/index.vue | 9 ruoyi-ui/src/router/index.js | 2 ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java | 56 +++++ ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java | 33 ++- ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue | 2 ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java | 2 ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java | 40 ++- ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java | 72 +++++++ ruoyi/src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java | 2 ruoyi-ui/bin/package.bat | 2 ruoyi-ui/src/layout/components/Navbar.vue | 6 ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java | 49 ++++ /dev/null | 93 --------- ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java | 18 + ruoyi-ui/src/views/components/icons/element-icons.js | 73 ------- ruoyi-ui/src/assets/styles/element-ui.scss | 5 26 files changed, 320 insertions(+), 249 deletions(-) diff --git a/ruoyi-ui/bin/build.bat b/ruoyi-ui/bin/build.bat new file mode 100644 index 0000000..dda590d --- /dev/null +++ b/ruoyi-ui/bin/build.bat @@ -0,0 +1,12 @@ +@echo off +echo. +echo [信息] 打包Web工程,生成dist文件。 +echo. + +%~d0 +cd %~dp0 + +cd .. +npm run build:prod + +pause \ No newline at end of file diff --git a/ruoyi-ui/bin/package.bat b/ruoyi-ui/bin/package.bat index 9997921..8281749 100644 --- a/ruoyi-ui/bin/package.bat +++ b/ruoyi-ui/bin/package.bat @@ -1,6 +1,6 @@ @echo off echo. -echo [信息] 打包Web工程,生成node_modules包文件。 +echo [信息] 安装Web工程,生成node_modules文件。 echo. %~d0 diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 326d223..7007ff1 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -44,7 +44,7 @@ "axios": "0.18.1", "clipboard": "2.0.4", "echarts": "4.2.1", - "element-ui": "2.11.1", + "element-ui": "2.13.0", "file-saver": "2.0.1", "js-beautify": "^1.10.2", "fuse.js": "3.4.4", diff --git a/ruoyi-ui/src/assets/styles/element-ui.scss b/ruoyi-ui/src/assets/styles/element-ui.scss index 9581d56..955d3ca 100644 --- a/ruoyi-ui/src/assets/styles/element-ui.scss +++ b/ruoyi-ui/src/assets/styles/element-ui.scss @@ -77,3 +77,8 @@ .el-range-editor.el-input__inner { display: inline-flex !important; } + +// to fix el-date-picker css style +.el-range-separator { + box-sizing: content-box; +} diff --git a/ruoyi-ui/src/layout/components/Navbar.vue b/ruoyi-ui/src/layout/components/Navbar.vue index d322da9..9edccc9 100644 --- a/ruoyi-ui/src/layout/components/Navbar.vue +++ b/ruoyi-ui/src/layout/components/Navbar.vue @@ -7,7 +7,7 @@ <div class="right-menu"> <template v-if="device!=='mobile'"> <search id="header-search" class="right-menu-item" /> - + <el-tooltip content="婧愮爜鍦板潃" effect="dark" placement="bottom"> <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" /> </el-tooltip> @@ -36,8 +36,8 @@ <el-dropdown-item> <span @click="setting = true">甯冨眬璁剧疆</span> </el-dropdown-item> - <el-dropdown-item divided> - <span @click="logout">閫�鍑虹櫥褰�</span> + <el-dropdown-item divided @click.native="logout"> + <span>閫�鍑虹櫥褰�</span> </el-dropdown-item> </el-dropdown-menu> </el-dropdown> diff --git a/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue b/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue index cd21d81..7289ddf 100644 --- a/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue +++ b/ruoyi-ui/src/layout/components/Sidebar/SidebarItem.vue @@ -1,5 +1,5 @@ <template> - <div v-if="!item.hidden" class="menu-wrapper"> + <div v-if="!item.hidden"> <template v-if="hasOneShowingChild(item.children,item) && (!onlyOneChild.children||onlyOneChild.noShowingChildren)&&!item.alwaysShow"> <app-link v-if="onlyOneChild.meta" :to="resolvePath(onlyOneChild.path)"> <el-menu-item :index="resolvePath(onlyOneChild.path)" :class="{'submenu-title-noDropdown':!isNest}"> diff --git a/ruoyi-ui/src/layout/components/TagsView/index.vue b/ruoyi-ui/src/layout/components/TagsView/index.vue index ea272dc..8fa0904 100644 --- a/ruoyi-ui/src/layout/components/TagsView/index.vue +++ b/ruoyi-ui/src/layout/components/TagsView/index.vue @@ -9,16 +9,16 @@ :to="{ path: tag.path, query: tag.query, fullPath: tag.fullPath }" tag="span" class="tags-view-item" - @click.middle.native="closeSelectedTag(tag)" + @click.middle.native="!isAffix(tag)?closeSelectedTag(tag):''" @contextmenu.prevent.native="openMenu(tag,$event)" > {{ tag.title }} - <span v-if="!tag.meta.affix" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" /> + <span v-if="!isAffix(tag)" class="el-icon-close" @click.prevent.stop="closeSelectedTag(tag)" /> </router-link> </scroll-pane> <ul v-show="visible" :style="{left:left+'px',top:top+'px'}" class="contextmenu"> <li @click="refreshSelectedTag(selectedTag)">鍒锋柊椤甸潰</li> - <li v-if="!(selectedTag.meta&&selectedTag.meta.affix)" @click="closeSelectedTag(selectedTag)">鍏抽棴褰撳墠</li> + <li v-if="!isAffix(selectedTag)" @click="closeSelectedTag(selectedTag)">鍏抽棴褰撳墠</li> <li @click="closeOthersTags">鍏抽棴鍏朵粬</li> <li @click="closeAllTags(selectedTag)">鍏抽棴鎵�鏈�</li> </ul> @@ -69,6 +69,9 @@ isActive(route) { return route.path === this.$route.path }, + isAffix(tag) { + return tag.meta && tag.meta.affix + }, filterAffixTags(routes, basePath = '/') { let tags = [] routes.forEach(route => { diff --git a/ruoyi-ui/src/router/index.js b/ruoyi-ui/src/router/index.js index dba21e4..633235a 100644 --- a/ruoyi-ui/src/router/index.js +++ b/ruoyi-ui/src/router/index.js @@ -32,7 +32,7 @@ hidden: true, children: [ { - path: '/redirect/:path*', + path: '/redirect/:path(.*)', component: () => import('@/views/redirect') } ] diff --git a/ruoyi-ui/src/views/components/icons/element-icons.js b/ruoyi-ui/src/views/components/icons/element-icons.js index df72201..9ea4d63 100644 --- a/ruoyi-ui/src/views/components/icons/element-icons.js +++ b/ruoyi-ui/src/views/components/icons/element-icons.js @@ -1,74 +1,3 @@ -const elementIcons = [ - 'info', - 'error', - 'success', - 'warning', - 'question', - 'back', - 'arrow-left', - 'arrow-down', - 'arrow-right', - 'arrow-up', - 'caret-left', - 'caret-bottom', - 'caret-top', - 'caret-right', - 'd-arrow-left', - 'd-arrow-right', - 'minus', - 'plus', - 'remove', - 'circle-plus', - 'remove-outline', - 'circle-plus-outline', - 'close', - 'check', - 'circle-close', - 'circle-check', - 'circle-close-outline', - 'circle-check-outline', - 'zoom-out', - 'zoom-in', - 'd-caret', - 'sort', - 'sort-down', - 'sort-up', - 'tickets', - 'document', - 'goods', - 'sold-out', - 'news', - 'message', - 'date', - 'printer', - 'time', - 'bell', - 'mobile-phone', - 'service', - 'view', - 'menu', - 'more', - 'more-outline', - 'star-on', - 'star-off', - 'location', - 'location-outline', - 'phone', - 'phone-outline', - 'picture', - 'picture-outline', - 'delete', - 'search', - 'edit', - 'edit-outline', - 'rank', - 'refresh', - 'share', - 'setting', - 'upload', - 'upload2', - 'download', - 'loading' -] +const elementIcons = ['platform-eleme', 'eleme', 'delete-solid', 'delete', 's-tools', 'setting', 'user-solid', 'user', 'phone', 'phone-outline', 'more', 'more-outline', 'star-on', 'star-off', 's-goods', 'goods', 'warning', 'warning-outline', 'question', 'info', 'remove', 'circle-plus', 'success', 'error', 'zoom-in', 'zoom-out', 'remove-outline', 'circle-plus-outline', 'circle-check', 'circle-close', 's-help', 'help', 'minus', 'plus', 'check', 'close', 'picture', 'picture-outline', 'picture-outline-round', 'upload', 'upload2', 'download', 'camera-solid', 'camera', 'video-camera-solid', 'video-camera', 'message-solid', 'bell', 's-cooperation', 's-order', 's-platform', 's-fold', 's-unfold', 's-operation', 's-promotion', 's-home', 's-release', 's-ticket', 's-management', 's-open', 's-shop', 's-marketing', 's-flag', 's-comment', 's-finance', 's-claim', 's-custom', 's-opportunity', 's-data', 's-check', 's-grid', 'menu', 'share', 'd-caret', 'caret-left', 'caret-right', 'caret-bottom', 'caret-top', 'bottom-left', 'bottom-right', 'back', 'right', 'bottom', 'top', 'top-left', 'top-right', 'arrow-left', 'arrow-right', 'arrow-down', 'arrow-up', 'd-arrow-left', 'd-arrow-right', 'video-pause', 'video-play', 'refresh', 'refresh-right', 'refresh-left', 'finished', 'sort', 'sort-up', 'sort-down', 'rank', 'loading', 'view', 'c-scale-to-original', 'date', 'edit', 'edit-outline', 'folder', 'folder-opened', 'folder-add', 'folder-remove', 'folder-delete', 'folder-checked', 'tickets', 'document-remove', 'document-delete', 'document-copy', 'document-checked', 'document', 'document-add', 'printer', 'paperclip', 'takeaway-box', 'search', 'monitor', 'attract', 'mobile', 'scissors', 'umbrella', 'headset', 'brush', 'mouse', 'coordinate', 'magic-stick', 'reading', 'data-line', 'data-board', 'pie-chart', 'data-analysis', 'collection-tag', 'film', 'suitcase', 'suitcase-1', 'receiving', 'collection', 'files', 'notebook-1', 'notebook-2', 'toilet-paper', 'office-building', 'school', 'table-lamp', 'house', 'no-smoking', 'smoking', 'shopping-cart-full', 'shopping-cart-1', 'shopping-cart-2', 'shopping-bag-1', 'shopping-bag-2', 'sold-out', 'sell', 'present', 'box', 'bank-card', 'money', 'coin', 'wallet', 'discount', 'price-tag', 'news', 'guide', 'male', 'female', 'thumb', 'cpu', 'link', 'connection', 'open', 'turn-off', 'set-up', 'chat-round', 'chat-line-round', 'chat-square', 'chat-dot-round', 'chat-dot-square', 'chat-line-square', 'message', 'postcard', 'position', 'turn-off-microphone', 'microphone', 'close-notification', 'bangzhu', 'time', 'odometer', 'crop', 'aim', 'switch-button', 'full-screen', 'copy-document', 'mic', 'stopwatch', 'medal-1', 'medal', 'trophy', 'trophy-1', 'first-aid-kit', 'discover', 'place', 'location', 'location-outline', 'location-information', 'add-location', 'delete-location', 'map-location', 'alarm-clock', 'timer', 'watch-1', 'watch', 'lock', 'unlock', 'key', 'service', 'mobile-phone', 'bicycle', 'truck', 'ship', 'basketball', 'football', 'soccer', 'baseball', 'wind-power', 'light-rain', 'lightning', 'heavy-rain', 'sunrise', 'sunrise-1', 'sunset', 'sunny', 'cloudy', 'partly-cloudy', 'cloudy-and-sunny', 'moon', 'moon-night', 'dish', 'dish-1', 'food', 'chicken', 'fork-spoon', 'knife-fork', 'burger', 'tableware', 'sugar', 'dessert', 'ice-cream', 'hot-water', 'water-cup', 'coffee-cup', 'cold-drink', 'goblet', 'goblet-full', 'goblet-square', 'goblet-square-full', 'refrigerator', 'grape', 'watermelon', 'cherry', 'apple', 'pear', 'orange', 'coffee', 'ice-tea', 'ice-drink', 'milk-tea', 'potato-strips', 'lollipop', 'ice-cream-square', 'ice-cream-round'] export default elementIcons diff --git a/ruoyi-ui/src/views/dashboard/mixins/resize.js b/ruoyi-ui/src/views/dashboard/mixins/resize.js index ae02e64..b1e76e9 100644 --- a/ruoyi-ui/src/views/dashboard/mixins/resize.js +++ b/ruoyi-ui/src/views/dashboard/mixins/resize.js @@ -3,50 +3,54 @@ export default { data() { return { - $_sidebarElm: null + $_sidebarElm: null, + $_resizeHandler: null } }, mounted() { - this.$_initResizeEvent() - this.$_initSidebarResizeEvent() - }, - beforeDestroy() { - this.$_destroyResizeEvent() - this.$_destroySidebarResizeEvent() + this.initListener() }, activated() { - this.$_initResizeEvent() - this.$_initSidebarResizeEvent() + if (!this.$_resizeHandler) { + // avoid duplication init + this.initListener() + } + + // when keep-alive chart activated, auto resize + this.resize() + }, + beforeDestroy() { + this.destroyListener() }, deactivated() { - this.$_destroyResizeEvent() - this.$_destroySidebarResizeEvent() + this.destroyListener() }, methods: { - $_resizeHandler() { - return debounce(() => { - if (this.chart) { - this.chart.resize() - } - }, 100)() - }, - $_initResizeEvent() { - window.addEventListener('resize', this.$_resizeHandler) - }, - $_destroyResizeEvent() { - window.removeEventListener('resize', this.$_resizeHandler) - }, + // use $_ for mixins properties + // https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential $_sidebarResizeHandler(e) { if (e.propertyName === 'width') { this.$_resizeHandler() } }, - $_initSidebarResizeEvent() { + initListener() { + this.$_resizeHandler = debounce(() => { + this.resize() + }, 100) + window.addEventListener('resize', this.$_resizeHandler) + this.$_sidebarElm = document.getElementsByClassName('sidebar-container')[0] this.$_sidebarElm && this.$_sidebarElm.addEventListener('transitionend', this.$_sidebarResizeHandler) }, - $_destroySidebarResizeEvent() { + destroyListener() { + window.removeEventListener('resize', this.$_resizeHandler) + this.$_resizeHandler = null + this.$_sidebarElm && this.$_sidebarElm.removeEventListener('transitionend', this.$_sidebarResizeHandler) + }, + resize() { + const { chart } = this + chart && chart.resize() } } } diff --git a/ruoyi-ui/src/views/system/menu/index.vue b/ruoyi-ui/src/views/system/menu/index.vue index 4117f31..395c616 100644 --- a/ruoyi-ui/src/views/system/menu/index.vue +++ b/ruoyi-ui/src/views/system/menu/index.vue @@ -49,16 +49,16 @@ </el-table-column> <el-table-column label="鎿嶄綔" align="center" class-name="small-padding fixed-width"> <template slot-scope="scope"> - <el-button size="mini" - type="text" - icon="el-icon-edit" + <el-button size="mini" + type="text" + icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:menu:edit']" >淇敼</el-button> - <el-button - size="mini" - type="text" - icon="el-icon-plus" + <el-button + size="mini" + type="text" + icon="el-icon-plus" @click="handleAdd(scope.row)" v-hasPermi="['system:menu:add']" >鏂板</el-button> @@ -210,6 +210,9 @@ ], orderNum: [ { required: true, message: "鑿滃崟椤哄簭涓嶈兘涓虹┖", trigger: "blur" } + ], + path: [ + { required: true, message: "璺敱鍦板潃涓嶈兘涓虹┖", trigger: "blur" } ] } }; @@ -346,4 +349,4 @@ } } }; -</script> +</script> \ No newline at end of file diff --git a/ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java b/ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java new file mode 100644 index 0000000..a1125e3 --- /dev/null +++ b/ruoyi/src/main/java/com/ruoyi/common/filter/RepeatableFilter.java @@ -0,0 +1,49 @@ +package com.ruoyi.common.filter; + +import java.io.IOException; +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; + +/** + * Repeatable 杩囨护鍣� + * + * @author ruoyi + */ +public class RepeatableFilter implements Filter +{ + @Override + public void init(FilterConfig filterConfig) throws ServletException + { + + } + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) + throws IOException, ServletException + { + ServletRequest requestWrapper = null; + if (request instanceof HttpServletRequest) + { + requestWrapper = new RepeatedlyRequestWrapper((HttpServletRequest) request, response); + } + if (null == requestWrapper) + { + chain.doFilter(request, response); + } + else + { + chain.doFilter(requestWrapper, response); + } + } + + @Override + public void destroy() + { + + } +} diff --git a/ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java b/ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java new file mode 100644 index 0000000..bd7097f --- /dev/null +++ b/ruoyi/src/main/java/com/ruoyi/common/filter/RepeatedlyRequestWrapper.java @@ -0,0 +1,72 @@ +package com.ruoyi.common.filter; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import javax.servlet.ReadListener; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import com.ruoyi.common.utils.http.HttpHelper; + +/** + * 鏋勫缓鍙噸澶嶈鍙杋nputStream鐨剅equest + * + * @author ruoyi + */ +public class RepeatedlyRequestWrapper extends HttpServletRequestWrapper +{ + private final byte[] body; + + public RepeatedlyRequestWrapper(HttpServletRequest request, ServletResponse response) throws IOException + { + super(request); + request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding("UTF-8"); + + body = HttpHelper.getBodyString(request).getBytes("UTF-8"); + } + + @Override + public BufferedReader getReader() throws IOException + { + return new BufferedReader(new InputStreamReader(getInputStream())); + } + + @Override + public ServletInputStream getInputStream() throws IOException + { + + final ByteArrayInputStream bais = new ByteArrayInputStream(body); + + return new ServletInputStream() + { + + @Override + public int read() throws IOException + { + return bais.read(); + } + + @Override + public boolean isFinished() + { + return false; + } + + @Override + public boolean isReady() + { + return false; + } + + @Override + public void setReadListener(ReadListener readListener) + { + + } + }; + } +} diff --git a/ruoyi/src/main/java/com/ruoyi/common/xss/XssFilter.java b/ruoyi/src/main/java/com/ruoyi/common/filter/XssFilter.java similarity index 98% rename from ruoyi/src/main/java/com/ruoyi/common/xss/XssFilter.java rename to ruoyi/src/main/java/com/ruoyi/common/filter/XssFilter.java index 9310402..b3df122 100644 --- a/ruoyi/src/main/java/com/ruoyi/common/xss/XssFilter.java +++ b/ruoyi/src/main/java/com/ruoyi/common/filter/XssFilter.java @@ -1,4 +1,4 @@ -package com.ruoyi.common.xss; +package com.ruoyi.common.filter; import java.io.IOException; import java.util.ArrayList; diff --git a/ruoyi/src/main/java/com/ruoyi/common/xss/XssHttpServletRequestWrapper.java b/ruoyi/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java similarity index 98% rename from ruoyi/src/main/java/com/ruoyi/common/xss/XssHttpServletRequestWrapper.java rename to ruoyi/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java index 178d759..17bfec1 100644 --- a/ruoyi/src/main/java/com/ruoyi/common/xss/XssHttpServletRequestWrapper.java +++ b/ruoyi/src/main/java/com/ruoyi/common/filter/XssHttpServletRequestWrapper.java @@ -1,4 +1,4 @@ -package com.ruoyi.common.xss; +package com.ruoyi.common.filter; import java.io.ByteArrayInputStream; import java.io.IOException; diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java b/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java new file mode 100644 index 0000000..e7f50b7 --- /dev/null +++ b/ruoyi/src/main/java/com/ruoyi/common/utils/http/HttpHelper.java @@ -0,0 +1,56 @@ +package com.ruoyi.common.utils.http; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.charset.Charset; +import javax.servlet.ServletRequest; +import org.apache.commons.lang.exception.ExceptionUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * 閫氱敤http宸ュ叿灏佽 + * + * @author ruoyi + */ +public class HttpHelper +{ + private static final Logger LOGGER = LoggerFactory.getLogger(HttpHelper.class); + + public static String getBodyString(ServletRequest request) + { + + StringBuilder sb = new StringBuilder(); + BufferedReader reader = null; + try (InputStream inputStream = request.getInputStream()) + { + reader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); + String line = ""; + while ((line = reader.readLine()) != null) + { + sb.append(line); + } + } + catch (IOException e) + { + LOGGER.warn("getBodyString鍑虹幇闂锛�"); + } + finally + { + if (reader != null) + { + try + { + reader.close(); + } + catch (IOException e) + { + LOGGER.error(ExceptionUtils.getFullStackTrace(e)); + } + } + } + return sb.toString(); + } +} diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/text/CharsetKit.java b/ruoyi/src/main/java/com/ruoyi/common/utils/text/CharsetKit.java deleted file mode 100644 index 7a463be..0000000 --- a/ruoyi/src/main/java/com/ruoyi/common/utils/text/CharsetKit.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.ruoyi.common.utils.text; - -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; -import com.ruoyi.common.utils.StringUtils; - -/** - * 瀛楃闆嗗伐鍏风被 - * - * @author ruoyi - * - */ -public class CharsetKit -{ - /** ISO-8859-1 */ - public static final String ISO_8859_1 = "ISO-8859-1"; - /** UTF-8 */ - public static final String UTF_8 = "UTF-8"; - /** GBK */ - public static final String GBK = "GBK"; - - /** ISO-8859-1 */ - public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); - /** UTF-8 */ - public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); - /** GBK */ - public static final Charset CHARSET_GBK = Charset.forName(GBK); - - /** - * 杞崲涓篊harset瀵硅薄 - * - * @param charset 瀛楃闆嗭紝涓虹┖鍒欒繑鍥為粯璁ゅ瓧绗﹂泦 - * @return Charset - */ - public static Charset charset(String charset) - { - return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); - } - - /** - * 杞崲瀛楃涓茬殑瀛楃闆嗙紪鐮� - * - * @param source 瀛楃涓� - * @param srcCharset 婧愬瓧绗﹂泦锛岄粯璁SO-8859-1 - * @param destCharset 鐩爣瀛楃闆嗭紝榛樿UTF-8 - * @return 杞崲鍚庣殑瀛楃闆� - */ - public static String convert(String source, String srcCharset, String destCharset) - { - return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); - } - - /** - * 杞崲瀛楃涓茬殑瀛楃闆嗙紪鐮� - * - * @param source 瀛楃涓� - * @param srcCharset 婧愬瓧绗﹂泦锛岄粯璁SO-8859-1 - * @param destCharset 鐩爣瀛楃闆嗭紝榛樿UTF-8 - * @return 杞崲鍚庣殑瀛楃闆� - */ - public static String convert(String source, Charset srcCharset, Charset destCharset) - { - if (null == srcCharset) - { - srcCharset = StandardCharsets.ISO_8859_1; - } - - if (null == destCharset) - { - srcCharset = StandardCharsets.UTF_8; - } - - if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) - { - return source; - } - return new String(source.getBytes(srcCharset), destCharset); - } - - /** - * @return 绯荤粺瀛楃闆嗙紪鐮� - */ - public static String systemCharset() - { - return Charset.defaultCharset().name(); - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/text/Convert.java b/ruoyi/src/main/java/com/ruoyi/common/utils/text/Convert.java deleted file mode 100644 index 2a025ba..0000000 --- a/ruoyi/src/main/java/com/ruoyi/common/utils/text/Convert.java +++ /dev/null @@ -1,999 +0,0 @@ -package com.ruoyi.common.utils.text; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.text.NumberFormat; -import java.util.Set; -import com.ruoyi.common.utils.StringUtils; - -/** - * 绫诲瀷杞崲鍣� - * - * @author ruoyi - */ -public class Convert -{ - /** - * 杞崲涓哄瓧绗︿覆<br> - * 濡傛灉缁欏畾鐨勫�间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static String toStr(Object value, String defaultValue) - { - if (null == value) - { - return defaultValue; - } - if (value instanceof String) - { - return (String) value; - } - return value.toString(); - } - - /** - * 杞崲涓哄瓧绗︿覆<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static String toStr(Object value) - { - return toStr(value, null); - } - - /** - * 杞崲涓哄瓧绗�<br> - * 濡傛灉缁欏畾鐨勫�间负null锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Character toChar(Object value, Character defaultValue) - { - if (null == value) - { - return defaultValue; - } - if (value instanceof Character) - { - return (Character) value; - } - - final String valueStr = toStr(value, null); - return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); - } - - /** - * 杞崲涓哄瓧绗�<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Character toChar(Object value) - { - return toChar(value, null); - } - - /** - * 杞崲涓篵yte<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Byte toByte(Object value, Byte defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Byte) - { - return (Byte) value; - } - if (value instanceof Number) - { - return ((Number) value).byteValue(); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return Byte.parseByte(valueStr); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篵yte<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Byte toByte(Object value) - { - return toByte(value, null); - } - - /** - * 杞崲涓篠hort<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Short toShort(Object value, Short defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Short) - { - return (Short) value; - } - if (value instanceof Number) - { - return ((Number) value).shortValue(); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return Short.parseShort(valueStr.trim()); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篠hort<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Short toShort(Object value) - { - return toShort(value, null); - } - - /** - * 杞崲涓篘umber<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Number toNumber(Object value, Number defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Number) - { - return (Number) value; - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return NumberFormat.getInstance().parse(valueStr); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篘umber<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Number toNumber(Object value) - { - return toNumber(value, null); - } - - /** - * 杞崲涓篿nt<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Integer toInt(Object value, Integer defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Integer) - { - return (Integer) value; - } - if (value instanceof Number) - { - return ((Number) value).intValue(); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return Integer.parseInt(valueStr.trim()); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篿nt<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Integer toInt(Object value) - { - return toInt(value, null); - } - - /** - * 杞崲涓篒nteger鏁扮粍<br> - * - * @param str 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Integer[] toIntArray(String str) - { - return toIntArray(",", str); - } - - /** - * 杞崲涓篖ong鏁扮粍<br> - * - * @param str 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Long[] toLongArray(String str) - { - return toLongArray(",", str); - } - - /** - * 杞崲涓篒nteger鏁扮粍<br> - * - * @param split 鍒嗛殧绗� - * @param split 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Integer[] toIntArray(String split, String str) - { - if (StringUtils.isEmpty(str)) - { - return new Integer[] {}; - } - String[] arr = str.split(split); - final Integer[] ints = new Integer[arr.length]; - for (int i = 0; i < arr.length; i++) - { - final Integer v = toInt(arr[i], 0); - ints[i] = v; - } - return ints; - } - - /** - * 杞崲涓篖ong鏁扮粍<br> - * - * @param split 鍒嗛殧绗� - * @param str 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Long[] toLongArray(String split, String str) - { - if (StringUtils.isEmpty(str)) - { - return new Long[] {}; - } - String[] arr = str.split(split); - final Long[] longs = new Long[arr.length]; - for (int i = 0; i < arr.length; i++) - { - final Long v = toLong(arr[i], null); - longs[i] = v; - } - return longs; - } - - /** - * 杞崲涓篠tring鏁扮粍<br> - * - * @param str 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static String[] toStrArray(String str) - { - return toStrArray(",", str); - } - - /** - * 杞崲涓篠tring鏁扮粍<br> - * - * @param split 鍒嗛殧绗� - * @param split 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static String[] toStrArray(String split, String str) - { - return str.split(split); - } - - /** - * 杞崲涓簂ong<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Long toLong(Object value, Long defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Long) - { - return (Long) value; - } - if (value instanceof Number) - { - return ((Number) value).longValue(); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - // 鏀寔绉戝璁℃暟娉� - return new BigDecimal(valueStr.trim()).longValue(); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓簂ong<br> - * 濡傛灉缁欏畾鐨勫�间负<code>null</code>锛屾垨鑰呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Long toLong(Object value) - { - return toLong(value, null); - } - - /** - * 杞崲涓篸ouble<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Double toDouble(Object value, Double defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Double) - { - return (Double) value; - } - if (value instanceof Number) - { - return ((Number) value).doubleValue(); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - // 鏀寔绉戝璁℃暟娉� - return new BigDecimal(valueStr.trim()).doubleValue(); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篸ouble<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Double toDouble(Object value) - { - return toDouble(value, null); - } - - /** - * 杞崲涓篎loat<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Float toFloat(Object value, Float defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Float) - { - return (Float) value; - } - if (value instanceof Number) - { - return ((Number) value).floatValue(); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return Float.parseFloat(valueStr.trim()); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篎loat<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Float toFloat(Object value) - { - return toFloat(value, null); - } - - /** - * 杞崲涓篵oolean<br> - * String鏀寔鐨勫�间负锛歵rue銆乫alse銆亂es銆乷k銆乶o锛�1,0 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static Boolean toBool(Object value, Boolean defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof Boolean) - { - return (Boolean) value; - } - String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - valueStr = valueStr.trim().toLowerCase(); - switch (valueStr) - { - case "true": - return true; - case "false": - return false; - case "yes": - return true; - case "ok": - return true; - case "no": - return false; - case "1": - return true; - case "0": - return false; - default: - return defaultValue; - } - } - - /** - * 杞崲涓篵oolean<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static Boolean toBool(Object value) - { - return toBool(value, null); - } - - /** - * 杞崲涓篍num瀵硅薄<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * - * @param clazz Enum鐨凜lass - * @param value 鍊� - * @param defaultValue 榛樿鍊� - * @return Enum - */ - public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (clazz.isAssignableFrom(value.getClass())) - { - @SuppressWarnings("unchecked") - E myE = (E) value; - return myE; - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return Enum.valueOf(clazz, valueStr); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓篍num瀵硅薄<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * - * @param clazz Enum鐨凜lass - * @param value 鍊� - * @return Enum - */ - public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) - { - return toEnum(clazz, value, null); - } - - /** - * 杞崲涓築igInteger<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static BigInteger toBigInteger(Object value, BigInteger defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof BigInteger) - { - return (BigInteger) value; - } - if (value instanceof Long) - { - return BigInteger.valueOf((Long) value); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return new BigInteger(valueStr); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓築igInteger<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<code>null</code><br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static BigInteger toBigInteger(Object value) - { - return toBigInteger(value, null); - } - - /** - * 杞崲涓築igDecimal<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @param defaultValue 杞崲閿欒鏃剁殑榛樿鍊� - * @return 缁撴灉 - */ - public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) - { - if (value == null) - { - return defaultValue; - } - if (value instanceof BigDecimal) - { - return (BigDecimal) value; - } - if (value instanceof Long) - { - return new BigDecimal((Long) value); - } - if (value instanceof Double) - { - return new BigDecimal((Double) value); - } - if (value instanceof Integer) - { - return new BigDecimal((Integer) value); - } - final String valueStr = toStr(value, null); - if (StringUtils.isEmpty(valueStr)) - { - return defaultValue; - } - try - { - return new BigDecimal(valueStr); - } - catch (Exception e) - { - return defaultValue; - } - } - - /** - * 杞崲涓築igDecimal<br> - * 濡傛灉缁欏畾鐨勫�间负绌猴紝鎴栬�呰浆鎹㈠け璐ワ紝杩斿洖榛樿鍊�<br> - * 杞崲澶辫触涓嶄細鎶ラ敊 - * - * @param value 琚浆鎹㈢殑鍊� - * @return 缁撴灉 - */ - public static BigDecimal toBigDecimal(Object value) - { - return toBigDecimal(value, null); - } - - /** - * 灏嗗璞¤浆涓哄瓧绗︿覆<br> - * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁� 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 - * - * @param obj 瀵硅薄 - * @return 瀛楃涓� - */ - public static String utf8Str(Object obj) - { - return str(obj, CharsetKit.CHARSET_UTF_8); - } - - /** - * 灏嗗璞¤浆涓哄瓧绗︿覆<br> - * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁� 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 - * - * @param obj 瀵硅薄 - * @param charsetName 瀛楃闆� - * @return 瀛楃涓� - */ - public static String str(Object obj, String charsetName) - { - return str(obj, Charset.forName(charsetName)); - } - - /** - * 灏嗗璞¤浆涓哄瓧绗︿覆<br> - * 1銆丅yte鏁扮粍鍜孊yteBuffer浼氳杞崲涓哄搴斿瓧绗︿覆鐨勬暟缁� 2銆佸璞℃暟缁勪細璋冪敤Arrays.toString鏂规硶 - * - * @param obj 瀵硅薄 - * @param charset 瀛楃闆� - * @return 瀛楃涓� - */ - public static String str(Object obj, Charset charset) - { - if (null == obj) - { - return null; - } - - if (obj instanceof String) - { - return (String) obj; - } - else if (obj instanceof byte[] || obj instanceof Byte[]) - { - return str((Byte[]) obj, charset); - } - else if (obj instanceof ByteBuffer) - { - return str((ByteBuffer) obj, charset); - } - return obj.toString(); - } - - /** - * 灏哹yte鏁扮粍杞负瀛楃涓� - * - * @param bytes byte鏁扮粍 - * @param charset 瀛楃闆� - * @return 瀛楃涓� - */ - public static String str(byte[] bytes, String charset) - { - return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); - } - - /** - * 瑙g爜瀛楄妭鐮� - * - * @param data 瀛楃涓� - * @param charset 瀛楃闆嗭紝濡傛灉姝ゅ瓧娈典负绌猴紝鍒欒В鐮佺殑缁撴灉鍙栧喅浜庡钩鍙� - * @return 瑙g爜鍚庣殑瀛楃涓� - */ - public static String str(byte[] data, Charset charset) - { - if (data == null) - { - return null; - } - - if (null == charset) - { - return new String(data); - } - return new String(data, charset); - } - - /** - * 灏嗙紪鐮佺殑byteBuffer鏁版嵁杞崲涓哄瓧绗︿覆 - * - * @param data 鏁版嵁 - * @param charset 瀛楃闆嗭紝濡傛灉涓虹┖浣跨敤褰撳墠绯荤粺瀛楃闆� - * @return 瀛楃涓� - */ - public static String str(ByteBuffer data, String charset) - { - if (data == null) - { - return null; - } - - return str(data, Charset.forName(charset)); - } - - /** - * 灏嗙紪鐮佺殑byteBuffer鏁版嵁杞崲涓哄瓧绗︿覆 - * - * @param data 鏁版嵁 - * @param charset 瀛楃闆嗭紝濡傛灉涓虹┖浣跨敤褰撳墠绯荤粺瀛楃闆� - * @return 瀛楃涓� - */ - public static String str(ByteBuffer data, Charset charset) - { - if (null == charset) - { - charset = Charset.defaultCharset(); - } - return charset.decode(data).toString(); - } - - // ----------------------------------------------------------------------- 鍏ㄨ鍗婅杞崲 - /** - * 鍗婅杞叏瑙� - * - * @param input String. - * @return 鍏ㄨ瀛楃涓�. - */ - public static String toSBC(String input) - { - return toSBC(input, null); - } - - /** - * 鍗婅杞叏瑙� - * - * @param input String - * @param notConvertSet 涓嶆浛鎹㈢殑瀛楃闆嗗悎 - * @return 鍏ㄨ瀛楃涓�. - */ - public static String toSBC(String input, Set<Character> notConvertSet) - { - char c[] = input.toCharArray(); - for (int i = 0; i < c.length; i++) - { - if (null != notConvertSet && notConvertSet.contains(c[i])) - { - // 璺宠繃涓嶆浛鎹㈢殑瀛楃 - continue; - } - - if (c[i] == ' ') - { - c[i] = '\u3000'; - } - else if (c[i] < '\177') - { - c[i] = (char) (c[i] + 65248); - - } - } - return new String(c); - } - - /** - * 鍏ㄨ杞崐瑙� - * - * @param input String. - * @return 鍗婅瀛楃涓� - */ - public static String toDBC(String input) - { - return toDBC(input, null); - } - - /** - * 鏇挎崲鍏ㄨ涓哄崐瑙� - * - * @param text 鏂囨湰 - * @param notConvertSet 涓嶆浛鎹㈢殑瀛楃闆嗗悎 - * @return 鏇挎崲鍚庣殑瀛楃 - */ - public static String toDBC(String text, Set<Character> notConvertSet) - { - char c[] = text.toCharArray(); - for (int i = 0; i < c.length; i++) - { - if (null != notConvertSet && notConvertSet.contains(c[i])) - { - // 璺宠繃涓嶆浛鎹㈢殑瀛楃 - continue; - } - - if (c[i] == '\u3000') - { - c[i] = ' '; - } - else if (c[i] > '\uFF00' && c[i] < '\uFF5F') - { - c[i] = (char) (c[i] - 65248); - } - } - String returnString = new String(c); - - return returnString; - } - - /** - * 鏁板瓧閲戦澶у啓杞崲 鍏堝啓涓畬鏁寸殑鐒跺悗灏嗗闆舵嬀鏇挎崲鎴愰浂 - * - * @param n 鏁板瓧 - * @return 涓枃澶у啓鏁板瓧 - */ - public static String digitUppercase(double n) - { - String[] fraction = { "瑙�", "鍒�" }; - String[] digit = { "闆�", "澹�", "璐�", "鍙�", "鑲�", "浼�", "闄�", "鏌�", "鎹�", "鐜�" }; - String[][] unit = { { "鍏�", "涓�", "浜�" }, { "", "鎷�", "浣�", "浠�" } }; - - String head = n < 0 ? "璐�" : ""; - n = Math.abs(n); - - String s = ""; - for (int i = 0; i < fraction.length; i++) - { - s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(闆�.)+", ""); - } - if (s.length() < 1) - { - s = "鏁�"; - } - int integerPart = (int) Math.floor(n); - - for (int i = 0; i < unit[0].length && integerPart > 0; i++) - { - String p = ""; - for (int j = 0; j < unit[1].length && n > 0; j++) - { - p = digit[integerPart % 10] + unit[1][j] + p; - integerPart = integerPart / 10; - } - s = p.replaceAll("(闆�.)*闆�$", "").replaceAll("^$", "闆�") + unit[0][i] + s; - } - return head + s.replaceAll("(闆�.)*闆跺厓", "鍏�").replaceFirst("(闆�.)+", "").replaceAll("(闆�.)+", "闆�").replaceAll("^鏁�$", "闆跺厓鏁�"); - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/common/utils/text/StrFormatter.java b/ruoyi/src/main/java/com/ruoyi/common/utils/text/StrFormatter.java deleted file mode 100644 index 40e6214..0000000 --- a/ruoyi/src/main/java/com/ruoyi/common/utils/text/StrFormatter.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.ruoyi.common.utils.text; - -import com.ruoyi.common.utils.StringUtils; - -/** - * 瀛楃涓叉牸寮忓寲 - * - * @author ruoyi - */ -public class StrFormatter -{ - public static final String EMPTY_JSON = "{}"; - public static final char C_BACKSLASH = '\\'; - public static final char C_DELIM_START = '{'; - public static final char C_DELIM_END = '}'; - - /** - * 鏍煎紡鍖栧瓧绗︿覆<br> - * 姝ゆ柟娉曞彧鏄畝鍗曞皢鍗犱綅绗� {} 鎸夌収椤哄簭鏇挎崲涓哄弬鏁�<br> - * 濡傛灉鎯宠緭鍑� {} 浣跨敤 \\杞箟 { 鍗冲彲锛屽鏋滄兂杈撳嚭 {} 涔嬪墠鐨� \ 浣跨敤鍙岃浆涔夌 \\\\ 鍗冲彲<br> - * 渚嬶細<br> - * 閫氬父浣跨敤锛歠ormat("this is {} for {}", "a", "b") -> this is a for b<br> - * 杞箟{}锛� format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> - * 杞箟\锛� format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> - * - * @param strPattern 瀛楃涓叉ā鏉� - * @param argArray 鍙傛暟鍒楄〃 - * @return 缁撴灉 - */ - public static String format(final String strPattern, final Object... argArray) - { - if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) - { - return strPattern; - } - final int strPatternLength = strPattern.length(); - - // 鍒濆鍖栧畾涔夊ソ鐨勯暱搴︿互鑾峰緱鏇村ソ鐨勬�ц兘 - StringBuilder sbuf = new StringBuilder(strPatternLength + 50); - - int handledPosition = 0; - int delimIndex;// 鍗犱綅绗︽墍鍦ㄤ綅缃� - for (int argIndex = 0; argIndex < argArray.length; argIndex++) - { - delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); - if (delimIndex == -1) - { - if (handledPosition == 0) - { - return strPattern; - } - else - { // 瀛楃涓叉ā鏉垮墿浣欓儴鍒嗕笉鍐嶅寘鍚崰浣嶇锛屽姞鍏ュ墿浣欓儴鍒嗗悗杩斿洖缁撴灉 - sbuf.append(strPattern, handledPosition, strPatternLength); - return sbuf.toString(); - } - } - else - { - if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) - { - if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) - { - // 杞箟绗︿箣鍓嶈繕鏈変竴涓浆涔夌锛屽崰浣嶇渚濇棫鏈夋晥 - sbuf.append(strPattern, handledPosition, delimIndex - 1); - sbuf.append(Convert.utf8Str(argArray[argIndex])); - handledPosition = delimIndex + 2; - } - else - { - // 鍗犱綅绗﹁杞箟 - argIndex--; - sbuf.append(strPattern, handledPosition, delimIndex - 1); - sbuf.append(C_DELIM_START); - handledPosition = delimIndex + 1; - } - } - else - { - // 姝e父鍗犱綅绗� - sbuf.append(strPattern, handledPosition, delimIndex); - sbuf.append(Convert.utf8Str(argArray[argIndex])); - handledPosition = delimIndex + 2; - } - } - } - // append the characters following the last {} pair. - // 鍔犲叆鏈�鍚庝竴涓崰浣嶇鍚庢墍鏈夌殑瀛楃 - sbuf.append(strPattern, handledPosition, strPattern.length()); - - return sbuf.toString(); - } -} diff --git a/ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java b/ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java index 478b33c..b5f03ec 100644 --- a/ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java +++ b/ruoyi/src/main/java/com/ruoyi/framework/config/FilterConfig.java @@ -7,8 +7,9 @@ import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import com.ruoyi.common.filter.RepeatableFilter; +import com.ruoyi.common.filter.XssFilter; import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.common.xss.XssFilter; /** * Filter閰嶇疆 @@ -36,11 +37,24 @@ registration.setFilter(new XssFilter()); registration.addUrlPatterns(StringUtils.split(urlPatterns, ",")); registration.setName("xssFilter"); - registration.setOrder(Integer.MAX_VALUE); + registration.setOrder(FilterRegistrationBean.HIGHEST_PRECEDENCE); Map<String, String> initParameters = new HashMap<String, String>(); initParameters.put("excludes", excludes); initParameters.put("enabled", enabled); registration.setInitParameters(initParameters); return registration; } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Bean + public FilterRegistrationBean someFilterRegistration() + { + FilterRegistrationBean registration = new FilterRegistrationBean(); + registration.setFilter(new RepeatableFilter()); + registration.addUrlPatterns("/*"); + registration.setName("repeatableFilter"); + registration.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE); + return registration; + } + } diff --git a/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java b/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java index 9d915c6..fd5fa19 100644 --- a/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java +++ b/ruoyi/src/main/java/com/ruoyi/framework/interceptor/impl/SameUrlDataInterceptor.java @@ -2,14 +2,19 @@ import java.util.HashMap; import java.util.Map; +import java.util.concurrent.TimeUnit; import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpSession; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.alibaba.fastjson.JSONObject; +import com.ruoyi.common.filter.RepeatedlyRequestWrapper; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.http.HttpHelper; import com.ruoyi.framework.interceptor.RepeatSubmitInterceptor; +import com.ruoyi.framework.redis.RedisCache; /** - * 鍒ゆ柇璇锋眰url鍜屾暟鎹槸鍚﹀拰涓婁竴娆$浉鍚岋紝 + * 鍒ゆ柇璇锋眰url鍜屾暟鎹槸鍚﹀拰涓婁竴娆$浉鍚岋紝 * 濡傛灉鍜屼笂娆$浉鍚岋紝鍒欐槸閲嶅鎻愪氦琛ㄥ崟銆� 鏈夋晥鏃堕棿涓�10绉掑唴銆� * * @author ruoyi @@ -21,7 +26,10 @@ public final String REPEAT_TIME = "repeatTime"; - public final String SESSION_REPEAT_KEY = "repeatData"; + public final String CACHE_REPEAT_KEY = "repeatData"; + + @Autowired + private RedisCache redisCache; /** * 闂撮殧鏃堕棿锛屽崟浣�:绉� 榛樿10绉� @@ -39,8 +47,14 @@ @Override public boolean isRepeatSubmit(HttpServletRequest request) { - // 鏈鍙傛暟鍙婄郴缁熸椂闂� - String nowParams = JSONObject.toJSONString(request.getParameterMap()); + RepeatedlyRequestWrapper repeatedlyRequest = (RepeatedlyRequestWrapper) request; + String nowParams = HttpHelper.getBodyString(repeatedlyRequest); + + // body鍙傛暟涓虹┖锛岃幏鍙朠arameter鐨勬暟鎹� + if (StringUtils.isEmpty(nowParams)) + { + nowParams = JSONObject.toJSONString(request.getParameterMap()); + } Map<String, Object> nowDataMap = new HashMap<String, Object>(); nowDataMap.put(REPEAT_PARAMS, nowParams); nowDataMap.put(REPEAT_TIME, System.currentTimeMillis()); @@ -48,8 +62,7 @@ // 璇锋眰鍦板潃锛堜綔涓哄瓨鏀緎ession鐨刱ey鍊硷級 String url = request.getRequestURI(); - HttpSession session = request.getSession(); - Object sessionObj = session.getAttribute(SESSION_REPEAT_KEY); + Object sessionObj = redisCache.getCacheObject(CACHE_REPEAT_KEY); if (sessionObj != null) { Map<String, Object> sessionMap = (Map<String, Object>) sessionObj; @@ -62,9 +75,9 @@ } } } - Map<String, Object> sessionMap = new HashMap<String, Object>(); - sessionMap.put(url, nowDataMap); - session.setAttribute(SESSION_REPEAT_KEY, sessionMap); + Map<String, Object> cacheMap = new HashMap<String, Object>(); + cacheMap.put(url, nowDataMap); + redisCache.setCacheObject(CACHE_REPEAT_KEY, cacheMap, intervalTime, TimeUnit.SECONDS); return false; } diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java index c96ef12..2d8d6c8 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/controller/SysNoticeController.java @@ -84,9 +84,9 @@ */ @PreAuthorize("@ss.hasPermi('system:notice:remove')") @Log(title = "閫氱煡鍏憡", businessType = BusinessType.DELETE) - @DeleteMapping("/{noticeId}") - public AjaxResult remove(@PathVariable Long noticeId) + @DeleteMapping("/{noticeIds}") + public AjaxResult remove(@PathVariable Long[] noticeIds) { - return toAjax(noticeService.deleteNoticeById(noticeId)); + return toAjax(noticeService.deleteNoticeByIds(noticeIds)); } } diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysNoticeMapper.java b/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysNoticeMapper.java index 77f0320..b80c50b 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysNoticeMapper.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/mapper/SysNoticeMapper.java @@ -56,5 +56,5 @@ * @param noticeIds 闇�瑕佸垹闄ょ殑鍏憡ID * @return 缁撴灉 */ - public int deleteNoticeByIds(Long noticeIds); + public int deleteNoticeByIds(Long[] noticeIds); } \ No newline at end of file diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java index ed60c48..3f74551 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/ISysNoticeService.java @@ -56,5 +56,5 @@ * @param noticeIds 闇�瑕佸垹闄ょ殑鍏憡ID * @return 缁撴灉 */ - public int deleteNoticeByIds(Long noticeIds); + public int deleteNoticeByIds(Long[] noticeIds); } diff --git a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java index 0f05dd5..f607b4f 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java @@ -84,7 +84,7 @@ * @param noticeIds 闇�瑕佸垹闄ょ殑鍏憡ID * @return 缁撴灉 */ - public int deleteNoticeByIds(Long noticeIds) + public int deleteNoticeByIds(Long[] noticeIds) { return noticeMapper.deleteNoticeByIds(noticeIds); } diff --git a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java index bd981aa..7d4e2d6 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java +++ b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/controller/GenController.java @@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import com.ruoyi.common.utils.text.Convert; +import com.ruoyi.common.core.text.Convert; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.controller.BaseController; diff --git a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java index 5e3a472..ee85a47 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java +++ b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/service/GenTableColumnServiceImpl.java @@ -3,7 +3,7 @@ import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.ruoyi.common.utils.text.Convert; +import com.ruoyi.common.core.text.Convert; import com.ruoyi.project.tool.gen.domain.GenTableColumn; import com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper; diff --git a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java index 9098f7c..4068643 100644 --- a/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java +++ b/ruoyi/src/main/java/com/ruoyi/project/tool/gen/util/GenUtils.java @@ -166,10 +166,30 @@ if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) { String[] searchList = StringUtils.split(tablePrefix, ","); - String[] replacementList = emptyList(searchList.length); - tableName = StringUtils.replaceEach(tableName, searchList, replacementList); + tableName = replaceFirst(tableName, searchList); } return StringUtils.convertToCamelCase(tableName); + } + + /** + * 鎵归噺鏇挎崲鍓嶇紑 + * + * @param replacementm 鏇挎崲鍊� + * @param searchList 鏇挎崲鍒楄〃 + * @return + */ + public static String replaceFirst(String replacementm, String[] searchList) + { + String text = replacementm; + for (String searchString : searchList) + { + if (replacementm.startsWith(searchString)) + { + text = replacementm.replaceFirst(searchString, ""); + break; + } + } + return text; } /** @@ -218,21 +238,5 @@ { return 0; } - } - - /** - * 鑾峰彇绌烘暟缁勫垪琛� - * - * @param length 闀垮害 - * @return 鏁扮粍淇℃伅 - */ - public static String[] emptyList(int length) - { - String[] values = new String[length]; - for (int i = 0; i < length; i++) - { - values[i] = StringUtils.EMPTY; - } - return values; } } \ No newline at end of file -- Gitblit v1.9.3