正在显示
76 个修改的文件
包含
5811 行增加
和
109 行删除
| @@ -71,6 +71,10 @@ https://www.oschina.net/project/top_cn_2019#ruoyi | @@ -71,6 +71,10 @@ https://www.oschina.net/project/top_cn_2019#ruoyi | ||
| 71 | <td><img src="https://oscimg.oschina.net/oscnet/509d2708cfd762b6e6339364cac1cc1970c.jpg"/></td> | 71 | <td><img src="https://oscimg.oschina.net/oscnet/509d2708cfd762b6e6339364cac1cc1970c.jpg"/></td> |
| 72 | </tr> | 72 | </tr> |
| 73 | <tr> | 73 | <tr> |
| 74 | + <td><img src="https://oscimg.oschina.net/oscnet/up-f1fd681cc9d295db74e85ad6d2fe4389454.png"/></td> | ||
| 75 | + <td><img src="https://oscimg.oschina.net/oscnet/up-c195234bbcd30be6927f037a6755e6ab69c.png"/></td> | ||
| 76 | + </tr> | ||
| 77 | + <tr> | ||
| 74 | <td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td> | 78 | <td><img src="https://oscimg.oschina.net/oscnet/b6115bc8c31de52951982e509930b20684a.jpg"/></td> |
| 75 | <td><img src="https://oscimg.oschina.net/oscnet/5f3d39a141f21f81b90536f391b8408f1fa.jpg"/></td> | 79 | <td><img src="https://oscimg.oschina.net/oscnet/5f3d39a141f21f81b90536f391b8408f1fa.jpg"/></td> |
| 76 | </tr> | 80 | </tr> |
| @@ -51,3 +51,11 @@ export function exportType(query) { | @@ -51,3 +51,11 @@ export function exportType(query) { | ||
| 51 | params: query | 51 | params: query |
| 52 | }) | 52 | }) |
| 53 | } | 53 | } |
| 54 | + | ||
| 55 | +// 获取字典选择框列表 | ||
| 56 | +export function optionselect() { | ||
| 57 | + return request({ | ||
| 58 | + url: '/system/dict/type/optionselect', | ||
| 59 | + method: 'get' | ||
| 60 | + }) | ||
| 61 | +} |
| 1 | import request from '@/utils/request' | 1 | import request from '@/utils/request' |
| 2 | +import { praseStrEmpty } from "@/utils/ruoyi"; | ||
| 2 | 3 | ||
| 3 | // 查询用户列表 | 4 | // 查询用户列表 |
| 4 | export function listUser(query) { | 5 | export function listUser(query) { |
| @@ -12,7 +13,7 @@ export function listUser(query) { | @@ -12,7 +13,7 @@ export function listUser(query) { | ||
| 12 | // 查询用户详细 | 13 | // 查询用户详细 |
| 13 | export function getUser(userId) { | 14 | export function getUser(userId) { |
| 14 | return request({ | 15 | return request({ |
| 15 | - url: '/system/user/' + userId, | 16 | + url: '/system/user/' + praseStrEmpty(userId), |
| 16 | method: 'get' | 17 | method: 'get' |
| 17 | }) | 18 | }) |
| 18 | } | 19 | } |
ruoyi-ui/src/api/tool/gen.js
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 查询生成表数据 | ||
| 4 | +export function listTable(query) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/tool/gen/list', | ||
| 7 | + method: 'get', | ||
| 8 | + params: query | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | +// 查询db数据库列表 | ||
| 12 | +export function listDbTable(query) { | ||
| 13 | + return request({ | ||
| 14 | + url: '/tool/gen/db/list', | ||
| 15 | + method: 'get', | ||
| 16 | + params: query | ||
| 17 | + }) | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +// 查询表详细信息 | ||
| 21 | +export function getGenTable(tableId) { | ||
| 22 | + return request({ | ||
| 23 | + url: '/tool/gen/' + tableId, | ||
| 24 | + method: 'get' | ||
| 25 | + }) | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +// 修改代码生成信息 | ||
| 29 | +export function updateGenTable(data) { | ||
| 30 | + return request({ | ||
| 31 | + url: '/tool/gen', | ||
| 32 | + method: 'put', | ||
| 33 | + data: data | ||
| 34 | + }) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// 导入表 | ||
| 38 | +export function importTable(data) { | ||
| 39 | + return request({ | ||
| 40 | + url: '/tool/gen/importTable', | ||
| 41 | + method: 'post', | ||
| 42 | + params: data | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | +// 预览生成代码 | ||
| 46 | +export function previewTable(tableId) { | ||
| 47 | + return request({ | ||
| 48 | + url: '/tool/gen/preview/' + tableId, | ||
| 49 | + method: 'get' | ||
| 50 | + }) | ||
| 51 | +} | ||
| 52 | +// 删除表数据 | ||
| 53 | +export function delTable(tableId) { | ||
| 54 | + return request({ | ||
| 55 | + url: '/tool/gen/' + tableId, | ||
| 56 | + method: 'delete' | ||
| 57 | + }) | ||
| 58 | +} | ||
| 59 | + |
| @@ -53,6 +53,10 @@ | @@ -53,6 +53,10 @@ | ||
| 53 | margin-left: 20px; | 53 | margin-left: 20px; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | +.el-dialog { | ||
| 57 | + margin-top: 6vh !important; | ||
| 58 | +} | ||
| 59 | + | ||
| 56 | .el-table .el-table__header-wrapper th { | 60 | .el-table .el-table__header-wrapper th { |
| 57 | word-break: break-word; | 61 | word-break: break-word; |
| 58 | background-color: #f8f8f9; | 62 | background-color: #f8f8f9; |
| @@ -61,6 +65,16 @@ | @@ -61,6 +65,16 @@ | ||
| 61 | font-size: 13px; | 65 | font-size: 13px; |
| 62 | } | 66 | } |
| 63 | 67 | ||
| 68 | +/** 表单布局 **/ | ||
| 69 | +.form-header { | ||
| 70 | + font-size:15px; | ||
| 71 | + color:#6379bb; | ||
| 72 | + border-bottom:1px solid #ddd; | ||
| 73 | + margin:8px 10px 25px 10px; | ||
| 74 | + padding-bottom:5px | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +/** 表格布局 **/ | ||
| 64 | .pagination-container { | 78 | .pagination-container { |
| 65 | position: relative; | 79 | position: relative; |
| 66 | height: 25px; | 80 | height: 25px; |
| @@ -27,17 +27,6 @@ import Layout from '@/layout' | @@ -27,17 +27,6 @@ import Layout from '@/layout' | ||
| 27 | // 公共路由 | 27 | // 公共路由 |
| 28 | export const constantRoutes = [ | 28 | export const constantRoutes = [ |
| 29 | { | 29 | { |
| 30 | - path: '/redirect', | ||
| 31 | - component: Layout, | ||
| 32 | - hidden: true, | ||
| 33 | - children: [ | ||
| 34 | - { | ||
| 35 | - path: '/redirect/:path*', | ||
| 36 | - component: () => import('@/views/redirect') | ||
| 37 | - } | ||
| 38 | - ] | ||
| 39 | - }, | ||
| 40 | - { | ||
| 41 | path: '/login', | 30 | path: '/login', |
| 42 | component: () => import('@/views/login'), | 31 | component: () => import('@/views/login'), |
| 43 | hidden: true | 32 | hidden: true |
| @@ -74,7 +63,7 @@ export const constantRoutes = [ | @@ -74,7 +63,7 @@ export const constantRoutes = [ | ||
| 74 | { | 63 | { |
| 75 | path: 'profile', | 64 | path: 'profile', |
| 76 | component: () => import('@/views/system/user/profile/index'), | 65 | component: () => import('@/views/system/user/profile/index'), |
| 77 | - name: '个人中心', | 66 | + name: 'Profile', |
| 78 | meta: { title: '个人中心', icon: 'user' } | 67 | meta: { title: '个人中心', icon: 'user' } |
| 79 | } | 68 | } |
| 80 | ] | 69 | ] |
| @@ -87,10 +76,23 @@ export const constantRoutes = [ | @@ -87,10 +76,23 @@ export const constantRoutes = [ | ||
| 87 | { | 76 | { |
| 88 | path: 'type/data/:dictId(\\d+)', | 77 | path: 'type/data/:dictId(\\d+)', |
| 89 | component: () => import('@/views/system/dict/data'), | 78 | component: () => import('@/views/system/dict/data'), |
| 90 | - name: '字典数据', | 79 | + name: 'Data', |
| 91 | meta: { title: '字典数据', icon: '' } | 80 | meta: { title: '字典数据', icon: '' } |
| 92 | } | 81 | } |
| 93 | ] | 82 | ] |
| 83 | + }, | ||
| 84 | + { | ||
| 85 | + path: '/gen', | ||
| 86 | + component: Layout, | ||
| 87 | + hidden: true, | ||
| 88 | + children: [ | ||
| 89 | + { | ||
| 90 | + path: 'edit', | ||
| 91 | + component: () => import('@/views/tool/gen/editTable'), | ||
| 92 | + name: 'GenEdit', | ||
| 93 | + meta: { title: '修改生成配置' } | ||
| 94 | + } | ||
| 95 | + ] | ||
| 94 | } | 96 | } |
| 95 | ] | 97 | ] |
| 96 | 98 |
| @@ -35,7 +35,7 @@ export function parseTime(time, pattern) { | @@ -35,7 +35,7 @@ export function parseTime(time, pattern) { | ||
| 35 | const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { | 35 | const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => { |
| 36 | let value = formatObj[key] | 36 | let value = formatObj[key] |
| 37 | // Note: getDay() returns 0 on Sunday | 37 | // Note: getDay() returns 0 on Sunday |
| 38 | - if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value ] } | 38 | + if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] } |
| 39 | if (result.length > 0 && value < 10) { | 39 | if (result.length > 0 && value < 10) { |
| 40 | value = '0' + value | 40 | value = '0' + value |
| 41 | } | 41 | } |
| @@ -46,7 +46,7 @@ export function parseTime(time, pattern) { | @@ -46,7 +46,7 @@ export function parseTime(time, pattern) { | ||
| 46 | 46 | ||
| 47 | // 表单重置 | 47 | // 表单重置 |
| 48 | export function resetForm(refName) { | 48 | export function resetForm(refName) { |
| 49 | - if (this.$refs[refName] !== undefined) { | 49 | + if (this.$refs[refName]) { |
| 50 | this.$refs[refName].resetFields(); | 50 | this.$refs[refName].resetFields(); |
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| @@ -54,11 +54,11 @@ export function resetForm(refName) { | @@ -54,11 +54,11 @@ export function resetForm(refName) { | ||
| 54 | // 添加日期范围 | 54 | // 添加日期范围 |
| 55 | export function addDateRange(params, dateRange) { | 55 | export function addDateRange(params, dateRange) { |
| 56 | var search = params; | 56 | var search = params; |
| 57 | - if (null != dateRange) { | ||
| 58 | - search.params = { | ||
| 59 | - beginTime: this.dateRange[0], | ||
| 60 | - endTime: this.dateRange[1] | ||
| 61 | - }; | 57 | + search.beginTime = ""; |
| 58 | + search.endTime = ""; | ||
| 59 | + if (null != dateRange && '' != dateRange) { | ||
| 60 | + search.beginTime = this.dateRange[0]; | ||
| 61 | + search.endTime = this.dateRange[1]; | ||
| 62 | } | 62 | } |
| 63 | return search; | 63 | return search; |
| 64 | } | 64 | } |
| @@ -93,3 +93,11 @@ export function sprintf(str) { | @@ -93,3 +93,11 @@ export function sprintf(str) { | ||
| 93 | }); | 93 | }); |
| 94 | return flag ? str : ''; | 94 | return flag ? str : ''; |
| 95 | } | 95 | } |
| 96 | + | ||
| 97 | +// 转换字符串,undefined,null等转化为"" | ||
| 98 | +export function praseStrEmpty(str) { | ||
| 99 | + if (!str || str == "undefined" || str == "null") { | ||
| 100 | + return ""; | ||
| 101 | + } | ||
| 102 | + return str; | ||
| 103 | +} |
ruoyi-ui/src/utils/zipdownload.js
0 → 100644
| 1 | +import axios from 'axios' | ||
| 2 | +import { getToken } from '@/utils/auth' | ||
| 3 | + | ||
| 4 | +const mimeMap = { | ||
| 5 | + xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | ||
| 6 | + zip: 'application/zip' | ||
| 7 | +} | ||
| 8 | + | ||
| 9 | +const baseUrl = process.env.VUE_APP_BASE_API | ||
| 10 | +export function downLoadZip(str, filename) { | ||
| 11 | + var url = baseUrl + str | ||
| 12 | + axios({ | ||
| 13 | + method: 'get', | ||
| 14 | + url: url, | ||
| 15 | + responseType: 'blob', | ||
| 16 | + headers: { 'Authorization': 'Bearer ' + getToken() } | ||
| 17 | + }).then(res => { | ||
| 18 | + resolveBlob(res, mimeMap.zip) | ||
| 19 | + }) | ||
| 20 | +} | ||
| 21 | +/** | ||
| 22 | + * 解析blob响应内容并下载 | ||
| 23 | + * @param {*} res blob响应内容 | ||
| 24 | + * @param {String} mimeType MIME类型 | ||
| 25 | + */ | ||
| 26 | +export function resolveBlob(res, mimeType) { | ||
| 27 | + const aLink = document.createElement('a') | ||
| 28 | + var blob = new Blob([res.data], { type: mimeType }) | ||
| 29 | + // //从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名; | ||
| 30 | + var patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*') | ||
| 31 | + var contentDisposition = decodeURI(res.headers['content-disposition']) | ||
| 32 | + var result = patt.exec(contentDisposition) | ||
| 33 | + var fileName = result[1] | ||
| 34 | + fileName = fileName.replace(/\"/g, '') | ||
| 35 | + aLink.href = URL.createObjectURL(blob) | ||
| 36 | + aLink.setAttribute('download', fileName) // 设置下载文件名称 | ||
| 37 | + document.body.appendChild(aLink) | ||
| 38 | + aLink.click() | ||
| 39 | + document.body.appendChild(aLink) | ||
| 40 | +} |
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | </template> | 5 | </template> |
| 6 | <script> | 6 | <script> |
| 7 | export default { | 7 | export default { |
| 8 | + name: "Druid", | ||
| 8 | data() { | 9 | data() { |
| 9 | return { | 10 | return { |
| 10 | src: process.env.VUE_APP_BASE_API + "/druid/index.html", | 11 | src: process.env.VUE_APP_BASE_API + "/druid/index.html", |
| @@ -117,6 +117,7 @@ | @@ -117,6 +117,7 @@ | ||
| 117 | import { list, delLogininfor, cleanLogininfor, exportLogininfor } from "@/api/monitor/logininfor"; | 117 | import { list, delLogininfor, cleanLogininfor, exportLogininfor } from "@/api/monitor/logininfor"; |
| 118 | 118 | ||
| 119 | export default { | 119 | export default { |
| 120 | + name: "Logininfor", | ||
| 120 | data() { | 121 | data() { |
| 121 | return { | 122 | return { |
| 122 | // 遮罩层 | 123 | // 遮罩层 |
| @@ -186,6 +186,7 @@ | @@ -186,6 +186,7 @@ | ||
| 186 | import { list, delOperlog, cleanOperlog, exportOperlog } from "@/api/monitor/operlog"; | 186 | import { list, delOperlog, cleanOperlog, exportOperlog } from "@/api/monitor/operlog"; |
| 187 | 187 | ||
| 188 | export default { | 188 | export default { |
| 189 | + name: "Operlog", | ||
| 189 | data() { | 190 | data() { |
| 190 | return { | 191 | return { |
| 191 | // 遮罩层 | 192 | // 遮罩层 |
ruoyi-ui/src/views/redirect.vue
已删除
100644 → 0
| @@ -168,6 +168,7 @@ | @@ -168,6 +168,7 @@ | ||
| 168 | import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig } from "@/api/system/config"; | 168 | import { listConfig, getConfig, delConfig, addConfig, updateConfig, exportConfig } from "@/api/system/config"; |
| 169 | 169 | ||
| 170 | export default { | 170 | export default { |
| 171 | + name: "Config", | ||
| 171 | data() { | 172 | data() { |
| 172 | return { | 173 | return { |
| 173 | // 遮罩层 | 174 | // 遮罩层 |
| @@ -143,6 +143,7 @@ import Treeselect from "@riophae/vue-treeselect"; | @@ -143,6 +143,7 @@ import Treeselect from "@riophae/vue-treeselect"; | ||
| 143 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | 143 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| 144 | 144 | ||
| 145 | export default { | 145 | export default { |
| 146 | + name: "Dept", | ||
| 146 | components: { Treeselect }, | 147 | components: { Treeselect }, |
| 147 | data() { | 148 | data() { |
| 148 | return { | 149 | return { |
| @@ -159,6 +159,7 @@ import { listData, getData, delData, addData, updateData, exportData } from "@/a | @@ -159,6 +159,7 @@ import { listData, getData, delData, addData, updateData, exportData } from "@/a | ||
| 159 | import { listType, getType } from "@/api/system/dict/type"; | 159 | import { listType, getType } from "@/api/system/dict/type"; |
| 160 | 160 | ||
| 161 | export default { | 161 | export default { |
| 162 | + name: "Data", | ||
| 162 | data() { | 163 | data() { |
| 163 | return { | 164 | return { |
| 164 | // 遮罩层 | 165 | // 遮罩层 |
| @@ -176,6 +176,7 @@ | @@ -176,6 +176,7 @@ | ||
| 176 | import { listType, getType, delType, addType, updateType, exportType } from "@/api/system/dict/type"; | 176 | import { listType, getType, delType, addType, updateType, exportType } from "@/api/system/dict/type"; |
| 177 | 177 | ||
| 178 | export default { | 178 | export default { |
| 179 | + name: "Dict", | ||
| 179 | data() { | 180 | data() { |
| 180 | return { | 181 | return { |
| 181 | // 遮罩层 | 182 | // 遮罩层 |
| @@ -179,6 +179,7 @@ import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | @@ -179,6 +179,7 @@ import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | ||
| 179 | import IconSelect from "@/components/IconSelect"; | 179 | import IconSelect from "@/components/IconSelect"; |
| 180 | 180 | ||
| 181 | export default { | 181 | export default { |
| 182 | + name: "Menu", | ||
| 182 | components: { Treeselect, IconSelect }, | 183 | components: { Treeselect, IconSelect }, |
| 183 | data() { | 184 | data() { |
| 184 | return { | 185 | return { |
| @@ -176,6 +176,7 @@ import { listNotice, getNotice, delNotice, addNotice, updateNotice, exportNotice | @@ -176,6 +176,7 @@ import { listNotice, getNotice, delNotice, addNotice, updateNotice, exportNotice | ||
| 176 | import Editor from '@/components/Editor'; | 176 | import Editor from '@/components/Editor'; |
| 177 | 177 | ||
| 178 | export default { | 178 | export default { |
| 179 | + name: "Notice", | ||
| 179 | components: { | 180 | components: { |
| 180 | Editor | 181 | Editor |
| 181 | }, | 182 | }, |
| @@ -153,6 +153,7 @@ | @@ -153,6 +153,7 @@ | ||
| 153 | import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post"; | 153 | import { listPost, getPost, delPost, addPost, updatePost, exportPost } from "@/api/system/post"; |
| 154 | 154 | ||
| 155 | export default { | 155 | export default { |
| 156 | + name: "Post", | ||
| 156 | data() { | 157 | data() { |
| 157 | return { | 158 | return { |
| 158 | // 遮罩层 | 159 | // 遮罩层 |
| @@ -238,6 +238,7 @@ import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/m | @@ -238,6 +238,7 @@ import { treeselect as menuTreeselect, roleMenuTreeselect } from "@/api/system/m | ||
| 238 | import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept"; | 238 | import { treeselect as deptTreeselect, roleDeptTreeselect } from "@/api/system/dept"; |
| 239 | 239 | ||
| 240 | export default { | 240 | export default { |
| 241 | + name: "Role", | ||
| 241 | data() { | 242 | data() { |
| 242 | return { | 243 | return { |
| 243 | // 遮罩层 | 244 | // 遮罩层 |
| @@ -290,12 +290,11 @@ | @@ -290,12 +290,11 @@ | ||
| 290 | <script> | 290 | <script> |
| 291 | import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus } from "@/api/system/user"; | 291 | import { listUser, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus } from "@/api/system/user"; |
| 292 | import { treeselect } from "@/api/system/dept"; | 292 | import { treeselect } from "@/api/system/dept"; |
| 293 | -import { listPost } from "@/api/system/post"; | ||
| 294 | -import { listRole } from "@/api/system/role"; | ||
| 295 | import Treeselect from "@riophae/vue-treeselect"; | 293 | import Treeselect from "@riophae/vue-treeselect"; |
| 296 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; | 294 | import "@riophae/vue-treeselect/dist/vue-treeselect.css"; |
| 297 | 295 | ||
| 298 | export default { | 296 | export default { |
| 297 | + name: "User", | ||
| 299 | components: { Treeselect }, | 298 | components: { Treeselect }, |
| 300 | data() { | 299 | data() { |
| 301 | return { | 300 | return { |
| @@ -423,18 +422,6 @@ export default { | @@ -423,18 +422,6 @@ export default { | ||
| 423 | this.queryParams.deptId = data.id; | 422 | this.queryParams.deptId = data.id; |
| 424 | this.getList(); | 423 | this.getList(); |
| 425 | }, | 424 | }, |
| 426 | - /** 查询岗位列表 */ | ||
| 427 | - getPosts() { | ||
| 428 | - listPost().then(response => { | ||
| 429 | - this.postOptions = response.rows; | ||
| 430 | - }); | ||
| 431 | - }, | ||
| 432 | - /** 查询角色列表 */ | ||
| 433 | - getRoles() { | ||
| 434 | - listRole().then(response => { | ||
| 435 | - this.roleOptions = response.rows; | ||
| 436 | - }); | ||
| 437 | - }, | ||
| 438 | // 用户状态修改 | 425 | // 用户状态修改 |
| 439 | handleStatusChange(row) { | 426 | handleStatusChange(row) { |
| 440 | let text = row.status === "0" ? "启用" : "停用"; | 427 | let text = row.status === "0" ? "启用" : "停用"; |
| @@ -494,21 +481,23 @@ export default { | @@ -494,21 +481,23 @@ export default { | ||
| 494 | handleAdd() { | 481 | handleAdd() { |
| 495 | this.reset(); | 482 | this.reset(); |
| 496 | this.getTreeselect(); | 483 | this.getTreeselect(); |
| 497 | - this.getPosts(); | ||
| 498 | - this.getRoles(); | 484 | + getUser().then(response => { |
| 485 | + this.postOptions = response.posts; | ||
| 486 | + this.roleOptions = response.roles; | ||
| 499 | this.open = true; | 487 | this.open = true; |
| 500 | this.title = "添加用户"; | 488 | this.title = "添加用户"; |
| 501 | this.form.password = this.initPassword; | 489 | this.form.password = this.initPassword; |
| 490 | + }); | ||
| 502 | }, | 491 | }, |
| 503 | /** 修改按钮操作 */ | 492 | /** 修改按钮操作 */ |
| 504 | handleUpdate(row) { | 493 | handleUpdate(row) { |
| 505 | this.reset(); | 494 | this.reset(); |
| 506 | this.getTreeselect(); | 495 | this.getTreeselect(); |
| 507 | - this.getPosts(); | ||
| 508 | - this.getRoles(); | ||
| 509 | const userId = row.userId || this.ids | 496 | const userId = row.userId || this.ids |
| 510 | getUser(userId).then(response => { | 497 | getUser(userId).then(response => { |
| 511 | this.form = response.data; | 498 | this.form = response.data; |
| 499 | + this.postOptions = response.posts; | ||
| 500 | + this.roleOptions = response.roles; | ||
| 512 | this.form.postIds = response.postIds; | 501 | this.form.postIds = response.postIds; |
| 513 | this.form.roleIds = response.roleIds; | 502 | this.form.roleIds = response.roleIds; |
| 514 | this.open = true; | 503 | this.open = true; |
| @@ -89,13 +89,3 @@ export default { | @@ -89,13 +89,3 @@ export default { | ||
| 89 | } | 89 | } |
| 90 | }; | 90 | }; |
| 91 | </script> | 91 | </script> |
| 92 | - | ||
| 93 | -<style rel="stylesheet/scss" lang="scss"> | ||
| 94 | -.avatar-uploader-icon { | ||
| 95 | - font-size: 28px; | ||
| 96 | - width: 120px; | ||
| 97 | - height: 120px; | ||
| 98 | - line-height: 120px; | ||
| 99 | - text-align: center; | ||
| 100 | -} | ||
| 101 | -</style> |
| 1 | +<template> | ||
| 2 | + <el-form ref="basicInfoForm" :model="info" :rules="rules" label-width="150px"> | ||
| 3 | + <el-row> | ||
| 4 | + <el-col :span="12"> | ||
| 5 | + <el-form-item label="表名称" prop="tableName"> | ||
| 6 | + <el-input placeholder="请输入仓库名称" v-model="info.tableName" /> | ||
| 7 | + </el-form-item> | ||
| 8 | + </el-col> | ||
| 9 | + <el-col :span="12"> | ||
| 10 | + <el-form-item label="表描述" prop="tableComment"> | ||
| 11 | + <el-input placeholder="请输入" v-model="info.tableComment" /> | ||
| 12 | + </el-form-item> | ||
| 13 | + </el-col> | ||
| 14 | + | ||
| 15 | + <el-col :span="12"> | ||
| 16 | + <el-form-item label="实体类名称" prop="className"> | ||
| 17 | + <el-input placeholder="请输入" v-model="info.className" /> | ||
| 18 | + </el-form-item> | ||
| 19 | + </el-col> | ||
| 20 | + <el-col :span="12"> | ||
| 21 | + <el-form-item label="作者" prop="functionAuthor"> | ||
| 22 | + <el-input placeholder="请输入" v-model="info.functionAuthor" /> | ||
| 23 | + </el-form-item> | ||
| 24 | + </el-col> | ||
| 25 | + <el-col :span="24"> | ||
| 26 | + <el-form-item label="备注" prop="remark"> | ||
| 27 | + <el-input type="textarea" :rows="3" v-model="info.remark"></el-input> | ||
| 28 | + </el-form-item> | ||
| 29 | + </el-col> | ||
| 30 | + </el-row> | ||
| 31 | + </el-form> | ||
| 32 | +</template> | ||
| 33 | +<script> | ||
| 34 | +export default { | ||
| 35 | + name: "BasicInfoForm", | ||
| 36 | + props: { | ||
| 37 | + info: { | ||
| 38 | + type: Object, | ||
| 39 | + default: null | ||
| 40 | + } | ||
| 41 | + }, | ||
| 42 | + data() { | ||
| 43 | + return { | ||
| 44 | + rules: { | ||
| 45 | + tableName: [ | ||
| 46 | + { required: true, message: "请输入表名称", trigger: "blur" } | ||
| 47 | + ], | ||
| 48 | + tableComment: [ | ||
| 49 | + { required: true, message: "请输入表描述", trigger: "blur" } | ||
| 50 | + ], | ||
| 51 | + className: [ | ||
| 52 | + { required: true, message: "请输入实体类名称", trigger: "blur" } | ||
| 53 | + ], | ||
| 54 | + functionAuthor: [ | ||
| 55 | + { required: true, message: "请输入作者", trigger: "blur" } | ||
| 56 | + ] | ||
| 57 | + } | ||
| 58 | + }; | ||
| 59 | + } | ||
| 60 | +}; | ||
| 61 | +</script> |
ruoyi-ui/src/views/tool/gen/editTable.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <el-card> | ||
| 3 | + <el-tabs v-model="activeName"> | ||
| 4 | + <el-tab-pane label="基本信息" name="basic"> | ||
| 5 | + <basic-info-form ref="basicInfo" :info="info" /> | ||
| 6 | + </el-tab-pane> | ||
| 7 | + <el-tab-pane label="字段信息" name="cloum"> | ||
| 8 | + <el-table :data="cloumns" :max-height="tableHeight"> | ||
| 9 | + <el-table-column label="序号" type="index" min-width="5%" /> | ||
| 10 | + <el-table-column | ||
| 11 | + label="字段列名" | ||
| 12 | + prop="columnName" | ||
| 13 | + min-width="10%" | ||
| 14 | + :show-overflow-tooltip="true" | ||
| 15 | + /> | ||
| 16 | + <el-table-column | ||
| 17 | + label="字段描述" | ||
| 18 | + prop="columnComment" | ||
| 19 | + min-width="10%" | ||
| 20 | + :show-overflow-tooltip="true" | ||
| 21 | + /> | ||
| 22 | + <el-table-column | ||
| 23 | + label="物理类型" | ||
| 24 | + prop="columnType" | ||
| 25 | + min-width="10%" | ||
| 26 | + :show-overflow-tooltip="true" | ||
| 27 | + /> | ||
| 28 | + <el-table-column label="Java类型" min-width="11%"> | ||
| 29 | + <template slot-scope="scope"> | ||
| 30 | + <el-select v-model="scope.row.javaType"> | ||
| 31 | + <el-option label="Long" value="Long" /> | ||
| 32 | + <el-option label="String" value="String" /> | ||
| 33 | + <el-option label="Ingeter" value="Ingeter" /> | ||
| 34 | + <el-option label="Double" value="Double" /> | ||
| 35 | + <el-option label="BigDecimal" value="BigDecimal" /> | ||
| 36 | + <el-option label="Date" value="Date" /> | ||
| 37 | + </el-select> | ||
| 38 | + </template> | ||
| 39 | + </el-table-column> | ||
| 40 | + <el-table-column label="java属性" min-width="10%"> | ||
| 41 | + <template slot-scope="scope"> | ||
| 42 | + <el-input v-model="scope.row.javaField"></el-input> | ||
| 43 | + </template> | ||
| 44 | + </el-table-column> | ||
| 45 | + | ||
| 46 | + <el-table-column label="插入" min-width="5%"> | ||
| 47 | + <template slot-scope="scope"> | ||
| 48 | + <el-checkbox true-label="1" v-model="scope.row.isInsert"></el-checkbox> | ||
| 49 | + </template> | ||
| 50 | + </el-table-column> | ||
| 51 | + <el-table-column label="编辑" min-width="5%"> | ||
| 52 | + <template slot-scope="scope"> | ||
| 53 | + <el-checkbox true-label="1" v-model="scope.row.isEdit"></el-checkbox> | ||
| 54 | + </template> | ||
| 55 | + </el-table-column> | ||
| 56 | + <el-table-column label="列表" min-width="5%"> | ||
| 57 | + <template slot-scope="scope"> | ||
| 58 | + <el-checkbox true-label="1" v-model="scope.row.isList"></el-checkbox> | ||
| 59 | + </template> | ||
| 60 | + </el-table-column> | ||
| 61 | + <el-table-column label="查询" min-width="5%"> | ||
| 62 | + <template slot-scope="scope"> | ||
| 63 | + <el-checkbox true-label="1" v-model="scope.row.isQuery"></el-checkbox> | ||
| 64 | + </template> | ||
| 65 | + </el-table-column> | ||
| 66 | + <el-table-column label="查询方式" min-width="10%"> | ||
| 67 | + <template slot-scope="scope"> | ||
| 68 | + <el-select v-model="scope.row.queryType"> | ||
| 69 | + <el-option label="=" value="EQ" /> | ||
| 70 | + <el-option label="!=" value="NE" /> | ||
| 71 | + <el-option label=">" value="GT" /> | ||
| 72 | + <el-option label=">=" value="GTE" /> | ||
| 73 | + <el-option label="<" value="LT" /> | ||
| 74 | + <el-option label="<=" value="LTE" /> | ||
| 75 | + <el-option label="LIKE" value="LIKE" /> | ||
| 76 | + <el-option label="BETWEEN" value="BETWEEN" /> | ||
| 77 | + </el-select> | ||
| 78 | + </template> | ||
| 79 | + </el-table-column> | ||
| 80 | + <el-table-column label="必填" min-width="5%"> | ||
| 81 | + <template slot-scope="scope"> | ||
| 82 | + <el-checkbox true-label="1" v-model="scope.row.isRequired"></el-checkbox> | ||
| 83 | + </template> | ||
| 84 | + </el-table-column> | ||
| 85 | + <el-table-column label="显示类型" min-width="12%"> | ||
| 86 | + <template slot-scope="scope"> | ||
| 87 | + <el-select v-model="scope.row.htmlType"> | ||
| 88 | + <el-option label="文本框" value="input" /> | ||
| 89 | + <el-option label="文本域" value="textarea" /> | ||
| 90 | + <el-option label="下拉框" value="select" /> | ||
| 91 | + <el-option label="单选框" value="radio" /> | ||
| 92 | + <el-option label="复选框" value="checkbox" /> | ||
| 93 | + <el-option label="日期控件" value="datetime" /> | ||
| 94 | + </el-select> | ||
| 95 | + </template> | ||
| 96 | + </el-table-column> | ||
| 97 | + <el-table-column label="字典类型" min-width="12%"> | ||
| 98 | + <template slot-scope="scope"> | ||
| 99 | + <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择"> | ||
| 100 | + <el-option | ||
| 101 | + v-for="dict in dictOptions" | ||
| 102 | + :key="dict.dictType" | ||
| 103 | + :label="dict.dictName" | ||
| 104 | + :value="dict.dictType"> | ||
| 105 | + <span style="float: left">{{ dict.dictName }}</span> | ||
| 106 | + <span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span> | ||
| 107 | + </el-option> | ||
| 108 | + </el-select> | ||
| 109 | + </template> | ||
| 110 | + </el-table-column> | ||
| 111 | + </el-table> | ||
| 112 | + </el-tab-pane> | ||
| 113 | + <el-tab-pane label="生成信息" name="genInfo"> | ||
| 114 | + <gen-info-form ref="genInfo" :info="info" /> | ||
| 115 | + </el-tab-pane> | ||
| 116 | + </el-tabs> | ||
| 117 | + <el-form label-width="100px"> | ||
| 118 | + <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;"> | ||
| 119 | + <el-button type="primary" @click="submitForm()">提交</el-button> | ||
| 120 | + <el-button @click="close()">返回</el-button> | ||
| 121 | + </el-form-item> | ||
| 122 | + </el-form> | ||
| 123 | + </el-card> | ||
| 124 | +</template> | ||
| 125 | +<script> | ||
| 126 | +import { getGenTable, updateGenTable } from "@/api/tool/gen"; | ||
| 127 | +import { optionselect as getDictOptionselect } from "@/api/system/dict/type"; | ||
| 128 | +import basicInfoForm from "./basicInfoForm"; | ||
| 129 | +import genInfoForm from "./genInfoForm"; | ||
| 130 | +export default { | ||
| 131 | + name: "GenEdit", | ||
| 132 | + components: { | ||
| 133 | + basicInfoForm, | ||
| 134 | + genInfoForm | ||
| 135 | + }, | ||
| 136 | + data() { | ||
| 137 | + return { | ||
| 138 | + // 选中选项卡的 name | ||
| 139 | + activeName: "cloum", | ||
| 140 | + // 表格的高度 | ||
| 141 | + tableHeight: document.documentElement.scrollHeight - 245 + "px", | ||
| 142 | + // 表列信息 | ||
| 143 | + cloumns: [], | ||
| 144 | + // 字典信息 | ||
| 145 | + dictOptions: [], | ||
| 146 | + // 表详细信息 | ||
| 147 | + info: {} | ||
| 148 | + }; | ||
| 149 | + }, | ||
| 150 | + beforeCreate() { | ||
| 151 | + const { tableId } = this.$route.query; | ||
| 152 | + if (tableId) { | ||
| 153 | + // 获取表详细信息 | ||
| 154 | + getGenTable(tableId).then(res => { | ||
| 155 | + this.cloumns = res.data.rows; | ||
| 156 | + this.info = res.data.info; | ||
| 157 | + }); | ||
| 158 | + /** 查询字典下拉列表 */ | ||
| 159 | + getDictOptionselect().then(response => { | ||
| 160 | + this.dictOptions = response.data; | ||
| 161 | + }); | ||
| 162 | + } | ||
| 163 | + }, | ||
| 164 | + methods: { | ||
| 165 | + /** 提交按钮 */ | ||
| 166 | + submitForm() { | ||
| 167 | + const basicForm = this.$refs.basicInfo.$refs.basicInfoForm; | ||
| 168 | + const genForm = this.$refs.genInfo.$refs.genInfoForm; | ||
| 169 | + Promise.all([basicForm, genForm].map(this.getFormPromise)).then(res => { | ||
| 170 | + const validateResult = res.every(item => !!item); | ||
| 171 | + if (validateResult) { | ||
| 172 | + const genTable = Object.assign({}, basicForm.model, genForm.model); | ||
| 173 | + genTable.columns = this.cloumns; | ||
| 174 | + genTable.params = { | ||
| 175 | + treeCode: genTable.treeCode, | ||
| 176 | + treeName: genTable.treeName, | ||
| 177 | + treeParentCode: genTable.treeParentCode | ||
| 178 | + }; | ||
| 179 | + updateGenTable(genTable).then(res => { | ||
| 180 | + this.msgSuccess(res.msg); | ||
| 181 | + if (res.code === 200) { | ||
| 182 | + this.close(); | ||
| 183 | + } | ||
| 184 | + }); | ||
| 185 | + } else { | ||
| 186 | + this.msgError("表单校验未通过,请重新检查提交内容"); | ||
| 187 | + } | ||
| 188 | + }); | ||
| 189 | + }, | ||
| 190 | + getFormPromise(form) { | ||
| 191 | + return new Promise(resolve => { | ||
| 192 | + form.validate(res => { | ||
| 193 | + resolve(res); | ||
| 194 | + }); | ||
| 195 | + }); | ||
| 196 | + }, | ||
| 197 | + /** 关闭按钮 */ | ||
| 198 | + close() { | ||
| 199 | + this.$store.dispatch("tagsView/delView", this.$route); | ||
| 200 | + this.$router.push({ path: "/tool/gen", query: { t: Date.now()}}) | ||
| 201 | + } | ||
| 202 | + } | ||
| 203 | +}; | ||
| 204 | +</script> |
ruoyi-ui/src/views/tool/gen/genInfoForm.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <el-form ref="genInfoForm" :model="info" :rules="rules" label-width="150px"> | ||
| 3 | + <el-row> | ||
| 4 | + <el-col :span="12"> | ||
| 5 | + <el-form-item prop="tplCategory"> | ||
| 6 | + <span slot="label">生成模板</span> | ||
| 7 | + <el-select v-model="info.tplCategory"> | ||
| 8 | + <el-option label="单表(增删改查)" value="crud" /> | ||
| 9 | + <el-option label="树表(增删改查)" value="tree" disabled/> | ||
| 10 | + </el-select> | ||
| 11 | + </el-form-item> | ||
| 12 | + </el-col> | ||
| 13 | + | ||
| 14 | + <el-col :span="12"> | ||
| 15 | + <el-form-item prop="packageName"> | ||
| 16 | + <span slot="label"> | ||
| 17 | + 生成包路径 | ||
| 18 | + <el-tooltip content="生成在哪个java包下,例如 com.ruoyi.system" placement="top"> | ||
| 19 | + <i class="el-icon-question"></i> | ||
| 20 | + </el-tooltip> | ||
| 21 | + </span> | ||
| 22 | + <el-input v-model="info.packageName" /> | ||
| 23 | + </el-form-item> | ||
| 24 | + </el-col> | ||
| 25 | + | ||
| 26 | + <el-col :span="12"> | ||
| 27 | + <el-form-item prop="moduleName"> | ||
| 28 | + <span slot="label"> | ||
| 29 | + 生成模块名 | ||
| 30 | + <el-tooltip content="可理解为子系统名,例如 system" placement="top"> | ||
| 31 | + <i class="el-icon-question"></i> | ||
| 32 | + </el-tooltip> | ||
| 33 | + </span> | ||
| 34 | + <el-input v-model="info.moduleName" /> | ||
| 35 | + </el-form-item> | ||
| 36 | + </el-col> | ||
| 37 | + | ||
| 38 | + <el-col :span="12"> | ||
| 39 | + <el-form-item prop="businessName"> | ||
| 40 | + <span slot="label"> | ||
| 41 | + 生成业务名 | ||
| 42 | + <el-tooltip content="可理解为功能英文名,例如 user" placement="top"> | ||
| 43 | + <i class="el-icon-question"></i> | ||
| 44 | + </el-tooltip> | ||
| 45 | + </span> | ||
| 46 | + <el-input v-model="info.businessName" /> | ||
| 47 | + </el-form-item> | ||
| 48 | + </el-col> | ||
| 49 | + | ||
| 50 | + <el-col :span="12"> | ||
| 51 | + <el-form-item prop="functionName"> | ||
| 52 | + <span slot="label"> | ||
| 53 | + 生成功能名 | ||
| 54 | + <el-tooltip content="用作类描述,例如 用户" placement="top"> | ||
| 55 | + <i class="el-icon-question"></i> | ||
| 56 | + </el-tooltip> | ||
| 57 | + </span> | ||
| 58 | + <el-input v-model="info.functionName" /> | ||
| 59 | + </el-form-item> | ||
| 60 | + </el-col> | ||
| 61 | + </el-row> | ||
| 62 | + | ||
| 63 | + <el-row v-show="info.tplCategory == 'tree'"> | ||
| 64 | + <h4 class="form-header">其他信息</h4> | ||
| 65 | + <el-col :span="12"> | ||
| 66 | + <el-form-item> | ||
| 67 | + <span slot="label"> | ||
| 68 | + 树编码字段 | ||
| 69 | + <el-tooltip content="树显示的编码字段名, 如:dept_id" placement="top"> | ||
| 70 | + <i class="el-icon-question"></i> | ||
| 71 | + </el-tooltip> | ||
| 72 | + </span> | ||
| 73 | + <el-select v-model="info.treeCode" placeholder="请选择"> | ||
| 74 | + <el-option | ||
| 75 | + v-for="column in info.columns" | ||
| 76 | + :key="column.columnName" | ||
| 77 | + :label="column.columnName + ':' + column.columnComment" | ||
| 78 | + :value="column.columnName" | ||
| 79 | + ></el-option> | ||
| 80 | + </el-select> | ||
| 81 | + </el-form-item> | ||
| 82 | + </el-col> | ||
| 83 | + <el-col :span="12"> | ||
| 84 | + <el-form-item> | ||
| 85 | + <span slot="label"> | ||
| 86 | + 树父编码字段 | ||
| 87 | + <el-tooltip content="树显示的父编码字段名, 如:parent_Id" placement="top"> | ||
| 88 | + <i class="el-icon-question"></i> | ||
| 89 | + </el-tooltip> | ||
| 90 | + </span> | ||
| 91 | + <el-select v-model="info.treeParentCode" placeholder="请选择"> | ||
| 92 | + <el-option | ||
| 93 | + v-for="column in info.columns" | ||
| 94 | + :key="column.columnName" | ||
| 95 | + :label="column.columnName + ':' + column.columnComment" | ||
| 96 | + :value="column.columnName" | ||
| 97 | + ></el-option> | ||
| 98 | + </el-select> | ||
| 99 | + </el-form-item> | ||
| 100 | + </el-col> | ||
| 101 | + <el-col :span="12"> | ||
| 102 | + <el-form-item> | ||
| 103 | + <span slot="label"> | ||
| 104 | + 树名称字段 | ||
| 105 | + <el-tooltip content="树节点的显示名称字段名, 如:dept_name" placement="top"> | ||
| 106 | + <i class="el-icon-question"></i> | ||
| 107 | + </el-tooltip> | ||
| 108 | + </span> | ||
| 109 | + <el-select v-model="info.treeName" placeholder="请选择"> | ||
| 110 | + <el-option | ||
| 111 | + v-for="column in info.columns" | ||
| 112 | + :key="column.columnName" | ||
| 113 | + :label="column.columnName + ':' + column.columnComment" | ||
| 114 | + :value="column.columnName" | ||
| 115 | + ></el-option> | ||
| 116 | + </el-select> | ||
| 117 | + </el-form-item> | ||
| 118 | + </el-col> | ||
| 119 | + </el-row> | ||
| 120 | + </el-form> | ||
| 121 | +</template> | ||
| 122 | +<script> | ||
| 123 | +export default { | ||
| 124 | + name: "BasicInfoForm", | ||
| 125 | + props: { | ||
| 126 | + info: { | ||
| 127 | + type: Object, | ||
| 128 | + default: null | ||
| 129 | + } | ||
| 130 | + }, | ||
| 131 | + data() { | ||
| 132 | + return { | ||
| 133 | + rules: { | ||
| 134 | + tplCategory: [ | ||
| 135 | + { required: true, message: "请选择生成模板", trigger: "blur" } | ||
| 136 | + ], | ||
| 137 | + packageName: [ | ||
| 138 | + { required: true, message: "请输入生成包路径", trigger: "blur" } | ||
| 139 | + ], | ||
| 140 | + moduleName: [ | ||
| 141 | + { required: true, message: "请输入生成模块名", trigger: "blur" } | ||
| 142 | + ], | ||
| 143 | + businessName: [ | ||
| 144 | + { required: true, message: "请输入生成业务名", trigger: "blur" } | ||
| 145 | + ], | ||
| 146 | + functionName: [ | ||
| 147 | + { required: true, message: "请输入生成功能名", trigger: "blur" } | ||
| 148 | + ] | ||
| 149 | + } | ||
| 150 | + }; | ||
| 151 | + }, | ||
| 152 | + created() {} | ||
| 153 | +}; | ||
| 154 | +</script> |
ruoyi-ui/src/views/tool/gen/importTable.vue
0 → 100644
| 1 | +<template> | ||
| 2 | + <!-- 导入表 --> | ||
| 3 | + <el-dialog title="导入表" :visible.sync="visible" width="800px" top="5vh"> | ||
| 4 | + <el-form :model="queryParams" ref="queryForm" :inline="true"> | ||
| 5 | + <el-form-item label="表名称" prop="tableName"> | ||
| 6 | + <el-input | ||
| 7 | + v-model="queryParams.tableName" | ||
| 8 | + placeholder="请输入表名称" | ||
| 9 | + clearable | ||
| 10 | + size="small" | ||
| 11 | + @keyup.enter.native="handleQuery" | ||
| 12 | + /> | ||
| 13 | + </el-form-item> | ||
| 14 | + <el-form-item label="表描述" prop="tableComment"> | ||
| 15 | + <el-input | ||
| 16 | + v-model="queryParams.tableComment" | ||
| 17 | + placeholder="请输入表描述" | ||
| 18 | + clearable | ||
| 19 | + size="small" | ||
| 20 | + @keyup.enter.native="handleQuery" | ||
| 21 | + /> | ||
| 22 | + </el-form-item> | ||
| 23 | + <el-form-item> | ||
| 24 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | ||
| 25 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | ||
| 26 | + </el-form-item> | ||
| 27 | + </el-form> | ||
| 28 | + <el-row> | ||
| 29 | + <el-table :data="dbTableList" @selection-change="handleSelectionChange" height="260px"> | ||
| 30 | + <el-table-column type="selection" width="55"></el-table-column> | ||
| 31 | + <el-table-column prop="tableName" label="表名称"></el-table-column> | ||
| 32 | + <el-table-column prop="tableComment" label="表描述"></el-table-column> | ||
| 33 | + <el-table-column prop="createTime" label="创建时间"></el-table-column> | ||
| 34 | + <el-table-column prop="updateTime" label="更新时间"></el-table-column> | ||
| 35 | + </el-table> | ||
| 36 | + <pagination | ||
| 37 | + v-show="total>0" | ||
| 38 | + :total="total" | ||
| 39 | + :page.sync="queryParams.pageNum" | ||
| 40 | + :limit.sync="queryParams.pageSize" | ||
| 41 | + @pagination="getList" | ||
| 42 | + /> | ||
| 43 | + </el-row> | ||
| 44 | + <div slot="footer" class="dialog-footer"> | ||
| 45 | + <el-button type="primary" @click="handleImportTable">确 定</el-button> | ||
| 46 | + <el-button @click="visible = false">取 消</el-button> | ||
| 47 | + </div> | ||
| 48 | + </el-dialog> | ||
| 49 | +</template> | ||
| 50 | + | ||
| 51 | +<script> | ||
| 52 | +import { listDbTable, importTable } from "@/api/tool/gen"; | ||
| 53 | +export default { | ||
| 54 | + data() { | ||
| 55 | + return { | ||
| 56 | + // 遮罩层 | ||
| 57 | + visible: false, | ||
| 58 | + // 选中数组值 | ||
| 59 | + tables: [], | ||
| 60 | + // 总条数 | ||
| 61 | + total: 0, | ||
| 62 | + // 表数据 | ||
| 63 | + dbTableList: [], | ||
| 64 | + // 查询参数 | ||
| 65 | + queryParams: { | ||
| 66 | + pageNum: 1, | ||
| 67 | + pageSize: 10, | ||
| 68 | + tableName: undefined, | ||
| 69 | + tableComment: undefined | ||
| 70 | + } | ||
| 71 | + }; | ||
| 72 | + }, | ||
| 73 | + methods: { | ||
| 74 | + // 显示弹框 | ||
| 75 | + show() { | ||
| 76 | + this.getList(); | ||
| 77 | + this.visible = true; | ||
| 78 | + }, | ||
| 79 | + // 多选框选中数据 | ||
| 80 | + handleSelectionChange(selection) { | ||
| 81 | + this.tables = selection.map(item => item.tableName); | ||
| 82 | + }, | ||
| 83 | + // 查询表数据 | ||
| 84 | + getList() { | ||
| 85 | + listDbTable(this.queryParams).then(res => { | ||
| 86 | + if (res.code === 200) { | ||
| 87 | + this.dbTableList = res.rows; | ||
| 88 | + this.total = res.total; | ||
| 89 | + } | ||
| 90 | + }); | ||
| 91 | + }, | ||
| 92 | + /** 搜索按钮操作 */ | ||
| 93 | + handleQuery() { | ||
| 94 | + this.queryParams.pageNum = 1; | ||
| 95 | + this.getList(); | ||
| 96 | + }, | ||
| 97 | + /** 重置按钮操作 */ | ||
| 98 | + resetQuery() { | ||
| 99 | + this.resetForm("queryForm"); | ||
| 100 | + this.handleQuery(); | ||
| 101 | + }, | ||
| 102 | + /** 导入按钮操作 */ | ||
| 103 | + handleImportTable() { | ||
| 104 | + importTable({ tables: this.tables.join(",") }).then(res => { | ||
| 105 | + this.msgSuccess(res.msg); | ||
| 106 | + if (res.code === 200) { | ||
| 107 | + this.visible = false; | ||
| 108 | + this.$emit("ok"); | ||
| 109 | + } | ||
| 110 | + }); | ||
| 111 | + } | ||
| 112 | + } | ||
| 113 | +}; | ||
| 114 | +</script> |
| 1 | <template> | 1 | <template> |
| 2 | <div class="app-container"> | 2 | <div class="app-container"> |
| 3 | - 代码生成 | 3 | + <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"> |
| 4 | + <el-form-item label="表名称" prop="tableName"> | ||
| 5 | + <el-input | ||
| 6 | + v-model="queryParams.tableName" | ||
| 7 | + placeholder="请输入表名称" | ||
| 8 | + clearable | ||
| 9 | + size="small" | ||
| 10 | + @keyup.enter.native="handleQuery" | ||
| 11 | + /> | ||
| 12 | + </el-form-item> | ||
| 13 | + <el-form-item label="表描述" prop="tableComment"> | ||
| 14 | + <el-input | ||
| 15 | + v-model="queryParams.tableComment" | ||
| 16 | + placeholder="请输入表描述" | ||
| 17 | + clearable | ||
| 18 | + size="small" | ||
| 19 | + @keyup.enter.native="handleQuery" | ||
| 20 | + /> | ||
| 21 | + </el-form-item> | ||
| 22 | + <el-form-item label="创建时间"> | ||
| 23 | + <el-date-picker | ||
| 24 | + v-model="dateRange" | ||
| 25 | + size="small" | ||
| 26 | + style="width: 240px" | ||
| 27 | + value-format="yyyy-MM-dd" | ||
| 28 | + type="daterange" | ||
| 29 | + range-separator="-" | ||
| 30 | + start-placeholder="开始日期" | ||
| 31 | + end-placeholder="结束日期" | ||
| 32 | + ></el-date-picker> | ||
| 33 | + </el-form-item> | ||
| 34 | + <el-form-item> | ||
| 35 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | ||
| 36 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | ||
| 37 | + </el-form-item> | ||
| 38 | + </el-form> | ||
| 39 | + | ||
| 40 | + <el-row :gutter="10" class="mb8"> | ||
| 41 | + <el-col :span="1.5"> | ||
| 42 | + <el-button | ||
| 43 | + type="primary" | ||
| 44 | + icon="el-icon-download" | ||
| 45 | + size="mini" | ||
| 46 | + @click="handleGenTable" | ||
| 47 | + v-hasPermi="['tool:gen:code']" | ||
| 48 | + >生成</el-button> | ||
| 49 | + </el-col> | ||
| 50 | + <el-col :span="1.5"> | ||
| 51 | + <el-button | ||
| 52 | + type="info" | ||
| 53 | + icon="el-icon-upload" | ||
| 54 | + size="mini" | ||
| 55 | + @click="openImportTable" | ||
| 56 | + v-hasPermi="['tool:gen:import']" | ||
| 57 | + >导入</el-button> | ||
| 58 | + </el-col> | ||
| 59 | + <el-col :span="1.5"> | ||
| 60 | + <el-button | ||
| 61 | + type="success" | ||
| 62 | + icon="el-icon-edit" | ||
| 63 | + size="mini" | ||
| 64 | + :disabled="single" | ||
| 65 | + @click="handleEditTable" | ||
| 66 | + v-hasPermi="['tool:gen:edit']" | ||
| 67 | + >修改</el-button> | ||
| 68 | + </el-col> | ||
| 69 | + <el-col :span="1.5"> | ||
| 70 | + <el-button | ||
| 71 | + type="danger" | ||
| 72 | + icon="el-icon-delete" | ||
| 73 | + size="mini" | ||
| 74 | + :disabled="multiple" | ||
| 75 | + @click="handleDelete" | ||
| 76 | + v-hasPermi="['tool:gen:remove']" | ||
| 77 | + >删除</el-button> | ||
| 78 | + </el-col> | ||
| 79 | + </el-row> | ||
| 80 | + | ||
| 81 | + <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange"> | ||
| 82 | + <el-table-column type="selection" width="55"></el-table-column> | ||
| 83 | + <el-table-column label="序号" align="center" prop="tableId" width="50px" /> | ||
| 84 | + <el-table-column | ||
| 85 | + label="表名称" | ||
| 86 | + align="center" | ||
| 87 | + prop="tableName" | ||
| 88 | + :show-overflow-tooltip="true" | ||
| 89 | + width="130" | ||
| 90 | + /> | ||
| 91 | + <el-table-column | ||
| 92 | + label="表描述" | ||
| 93 | + align="center" | ||
| 94 | + prop="tableComment" | ||
| 95 | + :show-overflow-tooltip="true" | ||
| 96 | + width="130" | ||
| 97 | + /> | ||
| 98 | + <el-table-column | ||
| 99 | + label="实体" | ||
| 100 | + align="center" | ||
| 101 | + prop="className" | ||
| 102 | + :show-overflow-tooltip="true" | ||
| 103 | + width="130" | ||
| 104 | + /> | ||
| 105 | + <el-table-column label="创建时间" align="center" prop="createTime" width="160" /> | ||
| 106 | + <el-table-column label="更新时间" align="center" prop="updateTime" width="160" /> | ||
| 107 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 108 | + <template slot-scope="scope"> | ||
| 109 | + <el-button | ||
| 110 | + type="text" | ||
| 111 | + size="small" | ||
| 112 | + icon="el-icon-view" | ||
| 113 | + @click="handlePreview(scope.row)" | ||
| 114 | + v-hasPermi="['tool:gen:preview']" | ||
| 115 | + >预览</el-button> | ||
| 116 | + <el-button | ||
| 117 | + type="text" | ||
| 118 | + size="small" | ||
| 119 | + icon="el-icon-edit" | ||
| 120 | + @click="handleEditTable(scope.row)" | ||
| 121 | + v-hasPermi="['tool:gen:edit']" | ||
| 122 | + >编辑</el-button> | ||
| 123 | + <el-button | ||
| 124 | + type="text" | ||
| 125 | + size="small" | ||
| 126 | + icon="el-icon-delete" | ||
| 127 | + @click="handleDelete(scope.row)" | ||
| 128 | + v-hasPermi="['tool:gen:remove']" | ||
| 129 | + >删除</el-button> | ||
| 130 | + <el-button | ||
| 131 | + type="text" | ||
| 132 | + size="small" | ||
| 133 | + icon="el-icon-download" | ||
| 134 | + @click="handleGenTable(scope.row)" | ||
| 135 | + v-hasPermi="['tool:gen:code']" | ||
| 136 | + >生成代码</el-button> | ||
| 137 | + </template> | ||
| 138 | + </el-table-column> | ||
| 139 | + </el-table> | ||
| 140 | + <pagination | ||
| 141 | + v-show="total>0" | ||
| 142 | + :total="total" | ||
| 143 | + :page.sync="queryParams.pageNum" | ||
| 144 | + :limit.sync="queryParams.pageSize" | ||
| 145 | + @pagination="getList" | ||
| 146 | + /> | ||
| 147 | + <!-- 预览界面 --> | ||
| 148 | + <el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh"> | ||
| 149 | + <el-tabs v-model="preview.activeName"> | ||
| 150 | + <el-tab-pane | ||
| 151 | + v-for="(value, key) in preview.data" | ||
| 152 | + :label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" | ||
| 153 | + :name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.vm'))" | ||
| 154 | + :key="key" | ||
| 155 | + > | ||
| 156 | + <pre>{{ value }}</pre> | ||
| 157 | + </el-tab-pane> | ||
| 158 | + </el-tabs> | ||
| 159 | + </el-dialog> | ||
| 160 | + <import-table ref="import" @ok="handleQuery" /> | ||
| 4 | </div> | 161 | </div> |
| 5 | </template> | 162 | </template> |
| 163 | + | ||
| 164 | +<script> | ||
| 165 | +import { listTable, previewTable, delTable } from "@/api/tool/gen"; | ||
| 166 | +import importTable from "./importTable"; | ||
| 167 | +import { downLoadZip } from "@/utils/zipdownload"; | ||
| 168 | +export default { | ||
| 169 | + name: "Gen", | ||
| 170 | + components: { importTable }, | ||
| 171 | + data() { | ||
| 172 | + return { | ||
| 173 | + // 遮罩层 | ||
| 174 | + loading: true, | ||
| 175 | + // 唯一标识符 | ||
| 176 | + uniqueId: "", | ||
| 177 | + // 选中数组 | ||
| 178 | + ids: [], | ||
| 179 | + // 选中表数组 | ||
| 180 | + tableNames: [], | ||
| 181 | + // 非单个禁用 | ||
| 182 | + single: true, | ||
| 183 | + // 非多个禁用 | ||
| 184 | + multiple: true, | ||
| 185 | + // 总条数 | ||
| 186 | + total: 0, | ||
| 187 | + // 表数据 | ||
| 188 | + tableList: [], | ||
| 189 | + // 日期范围 | ||
| 190 | + dateRange: "", | ||
| 191 | + // 查询参数 | ||
| 192 | + queryParams: { | ||
| 193 | + pageNum: 1, | ||
| 194 | + pageSize: 10, | ||
| 195 | + tableName: undefined, | ||
| 196 | + tableComment: undefined | ||
| 197 | + }, | ||
| 198 | + // 预览参数 | ||
| 199 | + preview: { | ||
| 200 | + open: false, | ||
| 201 | + title: "代码预览", | ||
| 202 | + data: {}, | ||
| 203 | + activeName: "domain.java" | ||
| 204 | + } | ||
| 205 | + }; | ||
| 206 | + }, | ||
| 207 | + created() { | ||
| 208 | + this.getList(); | ||
| 209 | + }, | ||
| 210 | + activated() { | ||
| 211 | + const time = this.$route.query.t; | ||
| 212 | + if (time != null && time != this.uniqueId) { | ||
| 213 | + this.uniqueId = time; | ||
| 214 | + this.resetQuery(); | ||
| 215 | + } | ||
| 216 | + }, | ||
| 217 | + methods: { | ||
| 218 | + /** 查询表集合 */ | ||
| 219 | + getList() { | ||
| 220 | + this.loading = true; | ||
| 221 | + listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => { | ||
| 222 | + this.tableList = response.rows; | ||
| 223 | + this.total = response.total; | ||
| 224 | + this.loading = false; | ||
| 225 | + } | ||
| 226 | + ); | ||
| 227 | + }, | ||
| 228 | + /** 搜索按钮操作 */ | ||
| 229 | + handleQuery() { | ||
| 230 | + this.queryParams.pageNum = 1; | ||
| 231 | + this.getList(); | ||
| 232 | + }, | ||
| 233 | + /** 生成代码操作 */ | ||
| 234 | + handleGenTable(row) { | ||
| 235 | + const tableNames = row.tableName || this.tableNames; | ||
| 236 | + if (tableNames == "") { | ||
| 237 | + this.msgError("请选择要生成的数据"); | ||
| 238 | + return; | ||
| 239 | + } | ||
| 240 | + downLoadZip("/tool/gen/batchGenCode?tables=" + tableNames, "ruoyi"); | ||
| 241 | + }, | ||
| 242 | + /** 打开导入表弹窗 */ | ||
| 243 | + openImportTable() { | ||
| 244 | + this.$refs.import.show(); | ||
| 245 | + }, | ||
| 246 | + /** 重置按钮操作 */ | ||
| 247 | + resetQuery() { | ||
| 248 | + this.dateRange = []; | ||
| 249 | + this.resetForm("queryForm"); | ||
| 250 | + this.handleQuery(); | ||
| 251 | + }, | ||
| 252 | + /** 预览按钮 */ | ||
| 253 | + handlePreview(row) { | ||
| 254 | + previewTable(row.tableId).then(response => { | ||
| 255 | + this.preview.data = response.data; | ||
| 256 | + this.preview.open = true; | ||
| 257 | + }); | ||
| 258 | + }, | ||
| 259 | + // 多选框选中数据 | ||
| 260 | + handleSelectionChange(selection) { | ||
| 261 | + this.ids = selection.map(item => item.tableId); | ||
| 262 | + this.tableNames = selection.map(item => item.tableName); | ||
| 263 | + this.single = selection.length != 1; | ||
| 264 | + this.multiple = !selection.length; | ||
| 265 | + }, | ||
| 266 | + /** 修改按钮操作 */ | ||
| 267 | + handleEditTable(row) { | ||
| 268 | + const tableId = row.tableId || this.ids[0]; | ||
| 269 | + this.$router.push({ path: "/gen/edit", query: { tableId: tableId } }); | ||
| 270 | + }, | ||
| 271 | + /** 删除按钮操作 */ | ||
| 272 | + handleDelete(row) { | ||
| 273 | + const tableIds = row.tableId || this.ids; | ||
| 274 | + this.$confirm('是否确认删除表编号为"' + tableIds + '"的数据项?', "警告", { | ||
| 275 | + confirmButtonText: "确定", | ||
| 276 | + cancelButtonText: "取消", | ||
| 277 | + type: "warning" | ||
| 278 | + }).then(function() { | ||
| 279 | + return delTable(tableIds); | ||
| 280 | + }).then(() => { | ||
| 281 | + this.getList(); | ||
| 282 | + this.msgSuccess("删除成功"); | ||
| 283 | + }).catch(function() {}); | ||
| 284 | + } | ||
| 285 | + } | ||
| 286 | +}; | ||
| 287 | +</script> |
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | </template> | 5 | </template> |
| 6 | <script> | 6 | <script> |
| 7 | export default { | 7 | export default { |
| 8 | + name: "Swagger", | ||
| 8 | data() { | 9 | data() { |
| 9 | return { | 10 | return { |
| 10 | src: process.env.VUE_APP_BASE_API + "/swagger-ui.html", | 11 | src: process.env.VUE_APP_BASE_API + "/swagger-ui.html", |
| @@ -5,7 +5,7 @@ | @@ -5,7 +5,7 @@ | ||
| 5 | 5 | ||
| 6 | <groupId>com.ruoyi</groupId> | 6 | <groupId>com.ruoyi</groupId> |
| 7 | <artifactId>ruoyi</artifactId> | 7 | <artifactId>ruoyi</artifactId> |
| 8 | - <version>1.1</version> | 8 | + <version>2.0.0</version> |
| 9 | <packaging>jar</packaging> | 9 | <packaging>jar</packaging> |
| 10 | 10 | ||
| 11 | <name>ruoyi</name> | 11 | <name>ruoyi</name> |
| @@ -34,6 +34,7 @@ | @@ -34,6 +34,7 @@ | ||
| 34 | <swagger.version>2.9.2</swagger.version> | 34 | <swagger.version>2.9.2</swagger.version> |
| 35 | <poi.version>3.17</poi.version> | 35 | <poi.version>3.17</poi.version> |
| 36 | <oshi.version>3.9.1</oshi.version> | 36 | <oshi.version>3.9.1</oshi.version> |
| 37 | + <velocity.version>1.7</velocity.version> | ||
| 37 | </properties> | 38 | </properties> |
| 38 | 39 | ||
| 39 | <dependencies> | 40 | <dependencies> |
| @@ -231,6 +232,12 @@ | @@ -231,6 +232,12 @@ | ||
| 231 | <artifactId>poi-ooxml</artifactId> | 232 | <artifactId>poi-ooxml</artifactId> |
| 232 | <version>${poi.version}</version> | 233 | <version>${poi.version}</version> |
| 233 | </dependency> | 234 | </dependency> |
| 235 | + <!--velocity代码生成使用模板 --> | ||
| 236 | + <dependency> | ||
| 237 | + <groupId>org.apache.velocity</groupId> | ||
| 238 | + <artifactId>velocity</artifactId> | ||
| 239 | + <version>${velocity.version}</version> | ||
| 240 | + </dependency> | ||
| 234 | 241 | ||
| 235 | </dependencies> | 242 | </dependencies> |
| 236 | 243 |
| @@ -246,8 +246,9 @@ insert into sys_menu values('1054', '任务导出', '110', '7', '#', '', 1, 'F', | @@ -246,8 +246,9 @@ insert into sys_menu values('1054', '任务导出', '110', '7', '#', '', 1, 'F', | ||
| 246 | insert into sys_menu values('1055', '生成查询', '114', '1', '#', '', 1, 'F', '0', 'tool:gen:query', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | 246 | insert into sys_menu values('1055', '生成查询', '114', '1', '#', '', 1, 'F', '0', 'tool:gen:query', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); |
| 247 | insert into sys_menu values('1056', '生成修改', '114', '2', '#', '', 1, 'F', '0', 'tool:gen:edit', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | 247 | insert into sys_menu values('1056', '生成修改', '114', '2', '#', '', 1, 'F', '0', 'tool:gen:edit', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); |
| 248 | insert into sys_menu values('1057', '生成删除', '114', '3', '#', '', 1, 'F', '0', 'tool:gen:remove', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | 248 | insert into sys_menu values('1057', '生成删除', '114', '3', '#', '', 1, 'F', '0', 'tool:gen:remove', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); |
| 249 | -insert into sys_menu values('1058', '预览代码', '114', '4', '#', '', 1, 'F', '0', 'tool:gen:preview', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | ||
| 250 | -insert into sys_menu values('1059', '生成代码', '114', '5', '#', '', 1, 'F', '0', 'tool:gen:code', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | 249 | +insert into sys_menu values('1058', '导入代码', '114', '2', '#', '', 1, 'F', '0', 'tool:gen:import', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); |
| 250 | +insert into sys_menu values('1059', '预览代码', '114', '4', '#', '', 1, 'F', '0', 'tool:gen:preview', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | ||
| 251 | +insert into sys_menu values('1060', '生成代码', '114', '5', '#', '', 1, 'F', '0', 'tool:gen:code', '#', 'admin', '2018-03-16 11-33-00', 'ry', '2018-03-16 11-33-00', ''); | ||
| 251 | 252 | ||
| 252 | 253 | ||
| 253 | -- ---------------------------- | 254 | -- ---------------------------- |
| @@ -362,6 +363,7 @@ insert into sys_role_menu values ('2', '1056'); | @@ -362,6 +363,7 @@ insert into sys_role_menu values ('2', '1056'); | ||
| 362 | insert into sys_role_menu values ('2', '1057'); | 363 | insert into sys_role_menu values ('2', '1057'); |
| 363 | insert into sys_role_menu values ('2', '1058'); | 364 | insert into sys_role_menu values ('2', '1058'); |
| 364 | insert into sys_role_menu values ('2', '1059'); | 365 | insert into sys_role_menu values ('2', '1059'); |
| 366 | +insert into sys_role_menu values ('2', '1060'); | ||
| 365 | 367 | ||
| 366 | -- ---------------------------- | 368 | -- ---------------------------- |
| 367 | -- 8、角色和部门关联表 角色1-N部门 | 369 | -- 8、角色和部门关联表 角色1-N部门 |
| 1 | +package com.ruoyi.common.constant; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 代码生成通用常量 | ||
| 5 | + * | ||
| 6 | + * @author ruoyi | ||
| 7 | + */ | ||
| 8 | +public class GenConstants | ||
| 9 | +{ | ||
| 10 | + /** 单表(增删改查) */ | ||
| 11 | + public static final String TPL_CRUD = "crud"; | ||
| 12 | + | ||
| 13 | + /** 树表(增删改查) */ | ||
| 14 | + public static final String TPL_TREE = "tree"; | ||
| 15 | + | ||
| 16 | + /** 树编码字段 */ | ||
| 17 | + public static final String TREE_CODE = "treeCode"; | ||
| 18 | + | ||
| 19 | + /** 树父编码字段 */ | ||
| 20 | + public static final String TREE_PARENT_CODE = "treeParentCode"; | ||
| 21 | + | ||
| 22 | + /** 树名称字段 */ | ||
| 23 | + public static final String TREE_NAME = "treeName"; | ||
| 24 | + | ||
| 25 | + /** 数据库字符串类型 */ | ||
| 26 | + public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text", | ||
| 27 | + "mediumtext", "longtext" }; | ||
| 28 | + | ||
| 29 | + /** 数据库时间类型 */ | ||
| 30 | + public static final String[] COLUMNTYPE_TIME = { "datetime", "time", "date", "timestamp" }; | ||
| 31 | + | ||
| 32 | + /** 数据库数字类型 */ | ||
| 33 | + public static final String[] COLUMNTYPE_NUMBER = { "tinyint", "smallint", "mediumint", "int", "number", "integer", | ||
| 34 | + "bigint", "float", "float", "double", "decimal" }; | ||
| 35 | + | ||
| 36 | + /** 页面不需要编辑字段 */ | ||
| 37 | + public static final String[] COLUMNNAME_NOT_EDIT = { "id", "create_by", "create_time", "del_flag" }; | ||
| 38 | + | ||
| 39 | + /** 页面不需要显示的列表字段 */ | ||
| 40 | + public static final String[] COLUMNNAME_NOT_LIST = { "id", "create_by", "create_time", "del_flag", "update_by", | ||
| 41 | + "update_time" }; | ||
| 42 | + | ||
| 43 | + /** 页面不需要查询字段 */ | ||
| 44 | + public static final String[] COLUMNNAME_NOT_QUERY = { "id", "create_by", "create_time", "del_flag", "update_by", | ||
| 45 | + "update_time", "remark" }; | ||
| 46 | + | ||
| 47 | + /** Entity基类字段 */ | ||
| 48 | + public static final String[] BASE_ENTITY = { "createBy", "createTime", "updateBy", "updateTime", "remark" }; | ||
| 49 | + | ||
| 50 | + /** Tree基类字段 */ | ||
| 51 | + public static final String[] TREE_ENTITY = { "parentName", "parentId", "orderNum", "ancestors" }; | ||
| 52 | + | ||
| 53 | + /** 文本框 */ | ||
| 54 | + public static final String HTML_INPUT = "input"; | ||
| 55 | + | ||
| 56 | + /** 文本域 */ | ||
| 57 | + public static final String HTML_TEXTAREA = "textarea"; | ||
| 58 | + | ||
| 59 | + /** 下拉框 */ | ||
| 60 | + public static final String HTML_SELECT = "select"; | ||
| 61 | + | ||
| 62 | + /** 单选框 */ | ||
| 63 | + public static final String HTML_RADIO = "radio"; | ||
| 64 | + | ||
| 65 | + /** 复选框 */ | ||
| 66 | + public static final String HTML_CHECKBOX = "checkbox"; | ||
| 67 | + | ||
| 68 | + /** 日期控件 */ | ||
| 69 | + public static final String HTML_DATETIME = "datetime"; | ||
| 70 | + | ||
| 71 | + /** 字符串类型 */ | ||
| 72 | + public static final String TYPE_STRING = "String"; | ||
| 73 | + | ||
| 74 | + /** 整型 */ | ||
| 75 | + public static final String TYPE_INTEGER = "Integer"; | ||
| 76 | + | ||
| 77 | + /** 长整型 */ | ||
| 78 | + public static final String TYPE_LONG = "Long"; | ||
| 79 | + | ||
| 80 | + /** 浮点型 */ | ||
| 81 | + public static final String TYPE_DOUBLE = "Double"; | ||
| 82 | + | ||
| 83 | + /** 高精度计算类型 */ | ||
| 84 | + public static final String TYPE_BIGDECIMAL = "BigDecimal"; | ||
| 85 | + | ||
| 86 | + /** 时间类型 */ | ||
| 87 | + public static final String TYPE_DATE = "Date"; | ||
| 88 | + | ||
| 89 | + /** 模糊查询 */ | ||
| 90 | + public static final String QUERY_LIKE = "LIKE"; | ||
| 91 | + | ||
| 92 | + /** 需要 */ | ||
| 93 | + public static final String REQUIRE = "1"; | ||
| 94 | +} |
| 1 | +package com.ruoyi.common.utils.text; | ||
| 2 | + | ||
| 3 | +import java.nio.charset.Charset; | ||
| 4 | +import java.nio.charset.StandardCharsets; | ||
| 5 | +import com.ruoyi.common.utils.StringUtils; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 字符集工具类 | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + * | ||
| 12 | + */ | ||
| 13 | +public class CharsetKit | ||
| 14 | +{ | ||
| 15 | + /** ISO-8859-1 */ | ||
| 16 | + public static final String ISO_8859_1 = "ISO-8859-1"; | ||
| 17 | + /** UTF-8 */ | ||
| 18 | + public static final String UTF_8 = "UTF-8"; | ||
| 19 | + /** GBK */ | ||
| 20 | + public static final String GBK = "GBK"; | ||
| 21 | + | ||
| 22 | + /** ISO-8859-1 */ | ||
| 23 | + public static final Charset CHARSET_ISO_8859_1 = Charset.forName(ISO_8859_1); | ||
| 24 | + /** UTF-8 */ | ||
| 25 | + public static final Charset CHARSET_UTF_8 = Charset.forName(UTF_8); | ||
| 26 | + /** GBK */ | ||
| 27 | + public static final Charset CHARSET_GBK = Charset.forName(GBK); | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 转换为Charset对象 | ||
| 31 | + * | ||
| 32 | + * @param charset 字符集,为空则返回默认字符集 | ||
| 33 | + * @return Charset | ||
| 34 | + */ | ||
| 35 | + public static Charset charset(String charset) | ||
| 36 | + { | ||
| 37 | + return StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 转换字符串的字符集编码 | ||
| 42 | + * | ||
| 43 | + * @param source 字符串 | ||
| 44 | + * @param srcCharset 源字符集,默认ISO-8859-1 | ||
| 45 | + * @param destCharset 目标字符集,默认UTF-8 | ||
| 46 | + * @return 转换后的字符集 | ||
| 47 | + */ | ||
| 48 | + public static String convert(String source, String srcCharset, String destCharset) | ||
| 49 | + { | ||
| 50 | + return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset)); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 转换字符串的字符集编码 | ||
| 55 | + * | ||
| 56 | + * @param source 字符串 | ||
| 57 | + * @param srcCharset 源字符集,默认ISO-8859-1 | ||
| 58 | + * @param destCharset 目标字符集,默认UTF-8 | ||
| 59 | + * @return 转换后的字符集 | ||
| 60 | + */ | ||
| 61 | + public static String convert(String source, Charset srcCharset, Charset destCharset) | ||
| 62 | + { | ||
| 63 | + if (null == srcCharset) | ||
| 64 | + { | ||
| 65 | + srcCharset = StandardCharsets.ISO_8859_1; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + if (null == destCharset) | ||
| 69 | + { | ||
| 70 | + srcCharset = StandardCharsets.UTF_8; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + if (StringUtils.isEmpty(source) || srcCharset.equals(destCharset)) | ||
| 74 | + { | ||
| 75 | + return source; | ||
| 76 | + } | ||
| 77 | + return new String(source.getBytes(srcCharset), destCharset); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + /** | ||
| 81 | + * @return 系统字符集编码 | ||
| 82 | + */ | ||
| 83 | + public static String systemCharset() | ||
| 84 | + { | ||
| 85 | + return Charset.defaultCharset().name(); | ||
| 86 | + } | ||
| 87 | +} |
| 1 | +package com.ruoyi.common.utils.text; | ||
| 2 | + | ||
| 3 | +import java.math.BigDecimal; | ||
| 4 | +import java.math.BigInteger; | ||
| 5 | +import java.nio.ByteBuffer; | ||
| 6 | +import java.nio.charset.Charset; | ||
| 7 | +import java.text.NumberFormat; | ||
| 8 | +import java.util.Set; | ||
| 9 | +import com.ruoyi.common.utils.StringUtils; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 类型转换器 | ||
| 13 | + * | ||
| 14 | + * @author ruoyi | ||
| 15 | + */ | ||
| 16 | +public class Convert | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * 转换为字符串<br> | ||
| 20 | + * 如果给定的值为null,或者转换失败,返回默认值<br> | ||
| 21 | + * 转换失败不会报错 | ||
| 22 | + * | ||
| 23 | + * @param value 被转换的值 | ||
| 24 | + * @param defaultValue 转换错误时的默认值 | ||
| 25 | + * @return 结果 | ||
| 26 | + */ | ||
| 27 | + public static String toStr(Object value, String defaultValue) | ||
| 28 | + { | ||
| 29 | + if (null == value) | ||
| 30 | + { | ||
| 31 | + return defaultValue; | ||
| 32 | + } | ||
| 33 | + if (value instanceof String) | ||
| 34 | + { | ||
| 35 | + return (String) value; | ||
| 36 | + } | ||
| 37 | + return value.toString(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 转换为字符串<br> | ||
| 42 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 43 | + * 转换失败不会报错 | ||
| 44 | + * | ||
| 45 | + * @param value 被转换的值 | ||
| 46 | + * @return 结果 | ||
| 47 | + */ | ||
| 48 | + public static String toStr(Object value) | ||
| 49 | + { | ||
| 50 | + return toStr(value, null); | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 转换为字符<br> | ||
| 55 | + * 如果给定的值为null,或者转换失败,返回默认值<br> | ||
| 56 | + * 转换失败不会报错 | ||
| 57 | + * | ||
| 58 | + * @param value 被转换的值 | ||
| 59 | + * @param defaultValue 转换错误时的默认值 | ||
| 60 | + * @return 结果 | ||
| 61 | + */ | ||
| 62 | + public static Character toChar(Object value, Character defaultValue) | ||
| 63 | + { | ||
| 64 | + if (null == value) | ||
| 65 | + { | ||
| 66 | + return defaultValue; | ||
| 67 | + } | ||
| 68 | + if (value instanceof Character) | ||
| 69 | + { | ||
| 70 | + return (Character) value; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + final String valueStr = toStr(value, null); | ||
| 74 | + return StringUtils.isEmpty(valueStr) ? defaultValue : valueStr.charAt(0); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 转换为字符<br> | ||
| 79 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 80 | + * 转换失败不会报错 | ||
| 81 | + * | ||
| 82 | + * @param value 被转换的值 | ||
| 83 | + * @return 结果 | ||
| 84 | + */ | ||
| 85 | + public static Character toChar(Object value) | ||
| 86 | + { | ||
| 87 | + return toChar(value, null); | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * 转换为byte<br> | ||
| 92 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br> | ||
| 93 | + * 转换失败不会报错 | ||
| 94 | + * | ||
| 95 | + * @param value 被转换的值 | ||
| 96 | + * @param defaultValue 转换错误时的默认值 | ||
| 97 | + * @return 结果 | ||
| 98 | + */ | ||
| 99 | + public static Byte toByte(Object value, Byte defaultValue) | ||
| 100 | + { | ||
| 101 | + if (value == null) | ||
| 102 | + { | ||
| 103 | + return defaultValue; | ||
| 104 | + } | ||
| 105 | + if (value instanceof Byte) | ||
| 106 | + { | ||
| 107 | + return (Byte) value; | ||
| 108 | + } | ||
| 109 | + if (value instanceof Number) | ||
| 110 | + { | ||
| 111 | + return ((Number) value).byteValue(); | ||
| 112 | + } | ||
| 113 | + final String valueStr = toStr(value, null); | ||
| 114 | + if (StringUtils.isEmpty(valueStr)) | ||
| 115 | + { | ||
| 116 | + return defaultValue; | ||
| 117 | + } | ||
| 118 | + try | ||
| 119 | + { | ||
| 120 | + return Byte.parseByte(valueStr); | ||
| 121 | + } | ||
| 122 | + catch (Exception e) | ||
| 123 | + { | ||
| 124 | + return defaultValue; | ||
| 125 | + } | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * 转换为byte<br> | ||
| 130 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 131 | + * 转换失败不会报错 | ||
| 132 | + * | ||
| 133 | + * @param value 被转换的值 | ||
| 134 | + * @return 结果 | ||
| 135 | + */ | ||
| 136 | + public static Byte toByte(Object value) | ||
| 137 | + { | ||
| 138 | + return toByte(value, null); | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + /** | ||
| 142 | + * 转换为Short<br> | ||
| 143 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<br> | ||
| 144 | + * 转换失败不会报错 | ||
| 145 | + * | ||
| 146 | + * @param value 被转换的值 | ||
| 147 | + * @param defaultValue 转换错误时的默认值 | ||
| 148 | + * @return 结果 | ||
| 149 | + */ | ||
| 150 | + public static Short toShort(Object value, Short defaultValue) | ||
| 151 | + { | ||
| 152 | + if (value == null) | ||
| 153 | + { | ||
| 154 | + return defaultValue; | ||
| 155 | + } | ||
| 156 | + if (value instanceof Short) | ||
| 157 | + { | ||
| 158 | + return (Short) value; | ||
| 159 | + } | ||
| 160 | + if (value instanceof Number) | ||
| 161 | + { | ||
| 162 | + return ((Number) value).shortValue(); | ||
| 163 | + } | ||
| 164 | + final String valueStr = toStr(value, null); | ||
| 165 | + if (StringUtils.isEmpty(valueStr)) | ||
| 166 | + { | ||
| 167 | + return defaultValue; | ||
| 168 | + } | ||
| 169 | + try | ||
| 170 | + { | ||
| 171 | + return Short.parseShort(valueStr.trim()); | ||
| 172 | + } | ||
| 173 | + catch (Exception e) | ||
| 174 | + { | ||
| 175 | + return defaultValue; | ||
| 176 | + } | ||
| 177 | + } | ||
| 178 | + | ||
| 179 | + /** | ||
| 180 | + * 转换为Short<br> | ||
| 181 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 182 | + * 转换失败不会报错 | ||
| 183 | + * | ||
| 184 | + * @param value 被转换的值 | ||
| 185 | + * @return 结果 | ||
| 186 | + */ | ||
| 187 | + public static Short toShort(Object value) | ||
| 188 | + { | ||
| 189 | + return toShort(value, null); | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + /** | ||
| 193 | + * 转换为Number<br> | ||
| 194 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 195 | + * 转换失败不会报错 | ||
| 196 | + * | ||
| 197 | + * @param value 被转换的值 | ||
| 198 | + * @param defaultValue 转换错误时的默认值 | ||
| 199 | + * @return 结果 | ||
| 200 | + */ | ||
| 201 | + public static Number toNumber(Object value, Number defaultValue) | ||
| 202 | + { | ||
| 203 | + if (value == null) | ||
| 204 | + { | ||
| 205 | + return defaultValue; | ||
| 206 | + } | ||
| 207 | + if (value instanceof Number) | ||
| 208 | + { | ||
| 209 | + return (Number) value; | ||
| 210 | + } | ||
| 211 | + final String valueStr = toStr(value, null); | ||
| 212 | + if (StringUtils.isEmpty(valueStr)) | ||
| 213 | + { | ||
| 214 | + return defaultValue; | ||
| 215 | + } | ||
| 216 | + try | ||
| 217 | + { | ||
| 218 | + return NumberFormat.getInstance().parse(valueStr); | ||
| 219 | + } | ||
| 220 | + catch (Exception e) | ||
| 221 | + { | ||
| 222 | + return defaultValue; | ||
| 223 | + } | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + /** | ||
| 227 | + * 转换为Number<br> | ||
| 228 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 229 | + * 转换失败不会报错 | ||
| 230 | + * | ||
| 231 | + * @param value 被转换的值 | ||
| 232 | + * @return 结果 | ||
| 233 | + */ | ||
| 234 | + public static Number toNumber(Object value) | ||
| 235 | + { | ||
| 236 | + return toNumber(value, null); | ||
| 237 | + } | ||
| 238 | + | ||
| 239 | + /** | ||
| 240 | + * 转换为int<br> | ||
| 241 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 242 | + * 转换失败不会报错 | ||
| 243 | + * | ||
| 244 | + * @param value 被转换的值 | ||
| 245 | + * @param defaultValue 转换错误时的默认值 | ||
| 246 | + * @return 结果 | ||
| 247 | + */ | ||
| 248 | + public static Integer toInt(Object value, Integer defaultValue) | ||
| 249 | + { | ||
| 250 | + if (value == null) | ||
| 251 | + { | ||
| 252 | + return defaultValue; | ||
| 253 | + } | ||
| 254 | + if (value instanceof Integer) | ||
| 255 | + { | ||
| 256 | + return (Integer) value; | ||
| 257 | + } | ||
| 258 | + if (value instanceof Number) | ||
| 259 | + { | ||
| 260 | + return ((Number) value).intValue(); | ||
| 261 | + } | ||
| 262 | + final String valueStr = toStr(value, null); | ||
| 263 | + if (StringUtils.isEmpty(valueStr)) | ||
| 264 | + { | ||
| 265 | + return defaultValue; | ||
| 266 | + } | ||
| 267 | + try | ||
| 268 | + { | ||
| 269 | + return Integer.parseInt(valueStr.trim()); | ||
| 270 | + } | ||
| 271 | + catch (Exception e) | ||
| 272 | + { | ||
| 273 | + return defaultValue; | ||
| 274 | + } | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + /** | ||
| 278 | + * 转换为int<br> | ||
| 279 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 280 | + * 转换失败不会报错 | ||
| 281 | + * | ||
| 282 | + * @param value 被转换的值 | ||
| 283 | + * @return 结果 | ||
| 284 | + */ | ||
| 285 | + public static Integer toInt(Object value) | ||
| 286 | + { | ||
| 287 | + return toInt(value, null); | ||
| 288 | + } | ||
| 289 | + | ||
| 290 | + /** | ||
| 291 | + * 转换为Integer数组<br> | ||
| 292 | + * | ||
| 293 | + * @param str 被转换的值 | ||
| 294 | + * @return 结果 | ||
| 295 | + */ | ||
| 296 | + public static Integer[] toIntArray(String str) | ||
| 297 | + { | ||
| 298 | + return toIntArray(",", str); | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + /** | ||
| 302 | + * 转换为Long数组<br> | ||
| 303 | + * | ||
| 304 | + * @param str 被转换的值 | ||
| 305 | + * @return 结果 | ||
| 306 | + */ | ||
| 307 | + public static Long[] toLongArray(String str) | ||
| 308 | + { | ||
| 309 | + return toLongArray(",", str); | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + /** | ||
| 313 | + * 转换为Integer数组<br> | ||
| 314 | + * | ||
| 315 | + * @param split 分隔符 | ||
| 316 | + * @param split 被转换的值 | ||
| 317 | + * @return 结果 | ||
| 318 | + */ | ||
| 319 | + public static Integer[] toIntArray(String split, String str) | ||
| 320 | + { | ||
| 321 | + if (StringUtils.isEmpty(str)) | ||
| 322 | + { | ||
| 323 | + return new Integer[] {}; | ||
| 324 | + } | ||
| 325 | + String[] arr = str.split(split); | ||
| 326 | + final Integer[] ints = new Integer[arr.length]; | ||
| 327 | + for (int i = 0; i < arr.length; i++) | ||
| 328 | + { | ||
| 329 | + final Integer v = toInt(arr[i], 0); | ||
| 330 | + ints[i] = v; | ||
| 331 | + } | ||
| 332 | + return ints; | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + /** | ||
| 336 | + * 转换为Long数组<br> | ||
| 337 | + * | ||
| 338 | + * @param split 分隔符 | ||
| 339 | + * @param str 被转换的值 | ||
| 340 | + * @return 结果 | ||
| 341 | + */ | ||
| 342 | + public static Long[] toLongArray(String split, String str) | ||
| 343 | + { | ||
| 344 | + if (StringUtils.isEmpty(str)) | ||
| 345 | + { | ||
| 346 | + return new Long[] {}; | ||
| 347 | + } | ||
| 348 | + String[] arr = str.split(split); | ||
| 349 | + final Long[] longs = new Long[arr.length]; | ||
| 350 | + for (int i = 0; i < arr.length; i++) | ||
| 351 | + { | ||
| 352 | + final Long v = toLong(arr[i], null); | ||
| 353 | + longs[i] = v; | ||
| 354 | + } | ||
| 355 | + return longs; | ||
| 356 | + } | ||
| 357 | + | ||
| 358 | + /** | ||
| 359 | + * 转换为String数组<br> | ||
| 360 | + * | ||
| 361 | + * @param str 被转换的值 | ||
| 362 | + * @return 结果 | ||
| 363 | + */ | ||
| 364 | + public static String[] toStrArray(String str) | ||
| 365 | + { | ||
| 366 | + return toStrArray(",", str); | ||
| 367 | + } | ||
| 368 | + | ||
| 369 | + /** | ||
| 370 | + * 转换为String数组<br> | ||
| 371 | + * | ||
| 372 | + * @param split 分隔符 | ||
| 373 | + * @param split 被转换的值 | ||
| 374 | + * @return 结果 | ||
| 375 | + */ | ||
| 376 | + public static String[] toStrArray(String split, String str) | ||
| 377 | + { | ||
| 378 | + return str.split(split); | ||
| 379 | + } | ||
| 380 | + | ||
| 381 | + /** | ||
| 382 | + * 转换为long<br> | ||
| 383 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 384 | + * 转换失败不会报错 | ||
| 385 | + * | ||
| 386 | + * @param value 被转换的值 | ||
| 387 | + * @param defaultValue 转换错误时的默认值 | ||
| 388 | + * @return 结果 | ||
| 389 | + */ | ||
| 390 | + public static Long toLong(Object value, Long defaultValue) | ||
| 391 | + { | ||
| 392 | + if (value == null) | ||
| 393 | + { | ||
| 394 | + return defaultValue; | ||
| 395 | + } | ||
| 396 | + if (value instanceof Long) | ||
| 397 | + { | ||
| 398 | + return (Long) value; | ||
| 399 | + } | ||
| 400 | + if (value instanceof Number) | ||
| 401 | + { | ||
| 402 | + return ((Number) value).longValue(); | ||
| 403 | + } | ||
| 404 | + final String valueStr = toStr(value, null); | ||
| 405 | + if (StringUtils.isEmpty(valueStr)) | ||
| 406 | + { | ||
| 407 | + return defaultValue; | ||
| 408 | + } | ||
| 409 | + try | ||
| 410 | + { | ||
| 411 | + // 支持科学计数法 | ||
| 412 | + return new BigDecimal(valueStr.trim()).longValue(); | ||
| 413 | + } | ||
| 414 | + catch (Exception e) | ||
| 415 | + { | ||
| 416 | + return defaultValue; | ||
| 417 | + } | ||
| 418 | + } | ||
| 419 | + | ||
| 420 | + /** | ||
| 421 | + * 转换为long<br> | ||
| 422 | + * 如果给定的值为<code>null</code>,或者转换失败,返回默认值<code>null</code><br> | ||
| 423 | + * 转换失败不会报错 | ||
| 424 | + * | ||
| 425 | + * @param value 被转换的值 | ||
| 426 | + * @return 结果 | ||
| 427 | + */ | ||
| 428 | + public static Long toLong(Object value) | ||
| 429 | + { | ||
| 430 | + return toLong(value, null); | ||
| 431 | + } | ||
| 432 | + | ||
| 433 | + /** | ||
| 434 | + * 转换为double<br> | ||
| 435 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 436 | + * 转换失败不会报错 | ||
| 437 | + * | ||
| 438 | + * @param value 被转换的值 | ||
| 439 | + * @param defaultValue 转换错误时的默认值 | ||
| 440 | + * @return 结果 | ||
| 441 | + */ | ||
| 442 | + public static Double toDouble(Object value, Double defaultValue) | ||
| 443 | + { | ||
| 444 | + if (value == null) | ||
| 445 | + { | ||
| 446 | + return defaultValue; | ||
| 447 | + } | ||
| 448 | + if (value instanceof Double) | ||
| 449 | + { | ||
| 450 | + return (Double) value; | ||
| 451 | + } | ||
| 452 | + if (value instanceof Number) | ||
| 453 | + { | ||
| 454 | + return ((Number) value).doubleValue(); | ||
| 455 | + } | ||
| 456 | + final String valueStr = toStr(value, null); | ||
| 457 | + if (StringUtils.isEmpty(valueStr)) | ||
| 458 | + { | ||
| 459 | + return defaultValue; | ||
| 460 | + } | ||
| 461 | + try | ||
| 462 | + { | ||
| 463 | + // 支持科学计数法 | ||
| 464 | + return new BigDecimal(valueStr.trim()).doubleValue(); | ||
| 465 | + } | ||
| 466 | + catch (Exception e) | ||
| 467 | + { | ||
| 468 | + return defaultValue; | ||
| 469 | + } | ||
| 470 | + } | ||
| 471 | + | ||
| 472 | + /** | ||
| 473 | + * 转换为double<br> | ||
| 474 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 475 | + * 转换失败不会报错 | ||
| 476 | + * | ||
| 477 | + * @param value 被转换的值 | ||
| 478 | + * @return 结果 | ||
| 479 | + */ | ||
| 480 | + public static Double toDouble(Object value) | ||
| 481 | + { | ||
| 482 | + return toDouble(value, null); | ||
| 483 | + } | ||
| 484 | + | ||
| 485 | + /** | ||
| 486 | + * 转换为Float<br> | ||
| 487 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 488 | + * 转换失败不会报错 | ||
| 489 | + * | ||
| 490 | + * @param value 被转换的值 | ||
| 491 | + * @param defaultValue 转换错误时的默认值 | ||
| 492 | + * @return 结果 | ||
| 493 | + */ | ||
| 494 | + public static Float toFloat(Object value, Float defaultValue) | ||
| 495 | + { | ||
| 496 | + if (value == null) | ||
| 497 | + { | ||
| 498 | + return defaultValue; | ||
| 499 | + } | ||
| 500 | + if (value instanceof Float) | ||
| 501 | + { | ||
| 502 | + return (Float) value; | ||
| 503 | + } | ||
| 504 | + if (value instanceof Number) | ||
| 505 | + { | ||
| 506 | + return ((Number) value).floatValue(); | ||
| 507 | + } | ||
| 508 | + final String valueStr = toStr(value, null); | ||
| 509 | + if (StringUtils.isEmpty(valueStr)) | ||
| 510 | + { | ||
| 511 | + return defaultValue; | ||
| 512 | + } | ||
| 513 | + try | ||
| 514 | + { | ||
| 515 | + return Float.parseFloat(valueStr.trim()); | ||
| 516 | + } | ||
| 517 | + catch (Exception e) | ||
| 518 | + { | ||
| 519 | + return defaultValue; | ||
| 520 | + } | ||
| 521 | + } | ||
| 522 | + | ||
| 523 | + /** | ||
| 524 | + * 转换为Float<br> | ||
| 525 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 526 | + * 转换失败不会报错 | ||
| 527 | + * | ||
| 528 | + * @param value 被转换的值 | ||
| 529 | + * @return 结果 | ||
| 530 | + */ | ||
| 531 | + public static Float toFloat(Object value) | ||
| 532 | + { | ||
| 533 | + return toFloat(value, null); | ||
| 534 | + } | ||
| 535 | + | ||
| 536 | + /** | ||
| 537 | + * 转换为boolean<br> | ||
| 538 | + * String支持的值为:true、false、yes、ok、no,1,0 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 539 | + * 转换失败不会报错 | ||
| 540 | + * | ||
| 541 | + * @param value 被转换的值 | ||
| 542 | + * @param defaultValue 转换错误时的默认值 | ||
| 543 | + * @return 结果 | ||
| 544 | + */ | ||
| 545 | + public static Boolean toBool(Object value, Boolean defaultValue) | ||
| 546 | + { | ||
| 547 | + if (value == null) | ||
| 548 | + { | ||
| 549 | + return defaultValue; | ||
| 550 | + } | ||
| 551 | + if (value instanceof Boolean) | ||
| 552 | + { | ||
| 553 | + return (Boolean) value; | ||
| 554 | + } | ||
| 555 | + String valueStr = toStr(value, null); | ||
| 556 | + if (StringUtils.isEmpty(valueStr)) | ||
| 557 | + { | ||
| 558 | + return defaultValue; | ||
| 559 | + } | ||
| 560 | + valueStr = valueStr.trim().toLowerCase(); | ||
| 561 | + switch (valueStr) | ||
| 562 | + { | ||
| 563 | + case "true": | ||
| 564 | + return true; | ||
| 565 | + case "false": | ||
| 566 | + return false; | ||
| 567 | + case "yes": | ||
| 568 | + return true; | ||
| 569 | + case "ok": | ||
| 570 | + return true; | ||
| 571 | + case "no": | ||
| 572 | + return false; | ||
| 573 | + case "1": | ||
| 574 | + return true; | ||
| 575 | + case "0": | ||
| 576 | + return false; | ||
| 577 | + default: | ||
| 578 | + return defaultValue; | ||
| 579 | + } | ||
| 580 | + } | ||
| 581 | + | ||
| 582 | + /** | ||
| 583 | + * 转换为boolean<br> | ||
| 584 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 585 | + * 转换失败不会报错 | ||
| 586 | + * | ||
| 587 | + * @param value 被转换的值 | ||
| 588 | + * @return 结果 | ||
| 589 | + */ | ||
| 590 | + public static Boolean toBool(Object value) | ||
| 591 | + { | ||
| 592 | + return toBool(value, null); | ||
| 593 | + } | ||
| 594 | + | ||
| 595 | + /** | ||
| 596 | + * 转换为Enum对象<br> | ||
| 597 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 598 | + * | ||
| 599 | + * @param clazz Enum的Class | ||
| 600 | + * @param value 值 | ||
| 601 | + * @param defaultValue 默认值 | ||
| 602 | + * @return Enum | ||
| 603 | + */ | ||
| 604 | + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value, E defaultValue) | ||
| 605 | + { | ||
| 606 | + if (value == null) | ||
| 607 | + { | ||
| 608 | + return defaultValue; | ||
| 609 | + } | ||
| 610 | + if (clazz.isAssignableFrom(value.getClass())) | ||
| 611 | + { | ||
| 612 | + @SuppressWarnings("unchecked") | ||
| 613 | + E myE = (E) value; | ||
| 614 | + return myE; | ||
| 615 | + } | ||
| 616 | + final String valueStr = toStr(value, null); | ||
| 617 | + if (StringUtils.isEmpty(valueStr)) | ||
| 618 | + { | ||
| 619 | + return defaultValue; | ||
| 620 | + } | ||
| 621 | + try | ||
| 622 | + { | ||
| 623 | + return Enum.valueOf(clazz, valueStr); | ||
| 624 | + } | ||
| 625 | + catch (Exception e) | ||
| 626 | + { | ||
| 627 | + return defaultValue; | ||
| 628 | + } | ||
| 629 | + } | ||
| 630 | + | ||
| 631 | + /** | ||
| 632 | + * 转换为Enum对象<br> | ||
| 633 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 634 | + * | ||
| 635 | + * @param clazz Enum的Class | ||
| 636 | + * @param value 值 | ||
| 637 | + * @return Enum | ||
| 638 | + */ | ||
| 639 | + public static <E extends Enum<E>> E toEnum(Class<E> clazz, Object value) | ||
| 640 | + { | ||
| 641 | + return toEnum(clazz, value, null); | ||
| 642 | + } | ||
| 643 | + | ||
| 644 | + /** | ||
| 645 | + * 转换为BigInteger<br> | ||
| 646 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 647 | + * 转换失败不会报错 | ||
| 648 | + * | ||
| 649 | + * @param value 被转换的值 | ||
| 650 | + * @param defaultValue 转换错误时的默认值 | ||
| 651 | + * @return 结果 | ||
| 652 | + */ | ||
| 653 | + public static BigInteger toBigInteger(Object value, BigInteger defaultValue) | ||
| 654 | + { | ||
| 655 | + if (value == null) | ||
| 656 | + { | ||
| 657 | + return defaultValue; | ||
| 658 | + } | ||
| 659 | + if (value instanceof BigInteger) | ||
| 660 | + { | ||
| 661 | + return (BigInteger) value; | ||
| 662 | + } | ||
| 663 | + if (value instanceof Long) | ||
| 664 | + { | ||
| 665 | + return BigInteger.valueOf((Long) value); | ||
| 666 | + } | ||
| 667 | + final String valueStr = toStr(value, null); | ||
| 668 | + if (StringUtils.isEmpty(valueStr)) | ||
| 669 | + { | ||
| 670 | + return defaultValue; | ||
| 671 | + } | ||
| 672 | + try | ||
| 673 | + { | ||
| 674 | + return new BigInteger(valueStr); | ||
| 675 | + } | ||
| 676 | + catch (Exception e) | ||
| 677 | + { | ||
| 678 | + return defaultValue; | ||
| 679 | + } | ||
| 680 | + } | ||
| 681 | + | ||
| 682 | + /** | ||
| 683 | + * 转换为BigInteger<br> | ||
| 684 | + * 如果给定的值为空,或者转换失败,返回默认值<code>null</code><br> | ||
| 685 | + * 转换失败不会报错 | ||
| 686 | + * | ||
| 687 | + * @param value 被转换的值 | ||
| 688 | + * @return 结果 | ||
| 689 | + */ | ||
| 690 | + public static BigInteger toBigInteger(Object value) | ||
| 691 | + { | ||
| 692 | + return toBigInteger(value, null); | ||
| 693 | + } | ||
| 694 | + | ||
| 695 | + /** | ||
| 696 | + * 转换为BigDecimal<br> | ||
| 697 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 698 | + * 转换失败不会报错 | ||
| 699 | + * | ||
| 700 | + * @param value 被转换的值 | ||
| 701 | + * @param defaultValue 转换错误时的默认值 | ||
| 702 | + * @return 结果 | ||
| 703 | + */ | ||
| 704 | + public static BigDecimal toBigDecimal(Object value, BigDecimal defaultValue) | ||
| 705 | + { | ||
| 706 | + if (value == null) | ||
| 707 | + { | ||
| 708 | + return defaultValue; | ||
| 709 | + } | ||
| 710 | + if (value instanceof BigDecimal) | ||
| 711 | + { | ||
| 712 | + return (BigDecimal) value; | ||
| 713 | + } | ||
| 714 | + if (value instanceof Long) | ||
| 715 | + { | ||
| 716 | + return new BigDecimal((Long) value); | ||
| 717 | + } | ||
| 718 | + if (value instanceof Double) | ||
| 719 | + { | ||
| 720 | + return new BigDecimal((Double) value); | ||
| 721 | + } | ||
| 722 | + if (value instanceof Integer) | ||
| 723 | + { | ||
| 724 | + return new BigDecimal((Integer) value); | ||
| 725 | + } | ||
| 726 | + final String valueStr = toStr(value, null); | ||
| 727 | + if (StringUtils.isEmpty(valueStr)) | ||
| 728 | + { | ||
| 729 | + return defaultValue; | ||
| 730 | + } | ||
| 731 | + try | ||
| 732 | + { | ||
| 733 | + return new BigDecimal(valueStr); | ||
| 734 | + } | ||
| 735 | + catch (Exception e) | ||
| 736 | + { | ||
| 737 | + return defaultValue; | ||
| 738 | + } | ||
| 739 | + } | ||
| 740 | + | ||
| 741 | + /** | ||
| 742 | + * 转换为BigDecimal<br> | ||
| 743 | + * 如果给定的值为空,或者转换失败,返回默认值<br> | ||
| 744 | + * 转换失败不会报错 | ||
| 745 | + * | ||
| 746 | + * @param value 被转换的值 | ||
| 747 | + * @return 结果 | ||
| 748 | + */ | ||
| 749 | + public static BigDecimal toBigDecimal(Object value) | ||
| 750 | + { | ||
| 751 | + return toBigDecimal(value, null); | ||
| 752 | + } | ||
| 753 | + | ||
| 754 | + /** | ||
| 755 | + * 将对象转为字符串<br> | ||
| 756 | + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 | ||
| 757 | + * | ||
| 758 | + * @param obj 对象 | ||
| 759 | + * @return 字符串 | ||
| 760 | + */ | ||
| 761 | + public static String utf8Str(Object obj) | ||
| 762 | + { | ||
| 763 | + return str(obj, CharsetKit.CHARSET_UTF_8); | ||
| 764 | + } | ||
| 765 | + | ||
| 766 | + /** | ||
| 767 | + * 将对象转为字符串<br> | ||
| 768 | + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 | ||
| 769 | + * | ||
| 770 | + * @param obj 对象 | ||
| 771 | + * @param charsetName 字符集 | ||
| 772 | + * @return 字符串 | ||
| 773 | + */ | ||
| 774 | + public static String str(Object obj, String charsetName) | ||
| 775 | + { | ||
| 776 | + return str(obj, Charset.forName(charsetName)); | ||
| 777 | + } | ||
| 778 | + | ||
| 779 | + /** | ||
| 780 | + * 将对象转为字符串<br> | ||
| 781 | + * 1、Byte数组和ByteBuffer会被转换为对应字符串的数组 2、对象数组会调用Arrays.toString方法 | ||
| 782 | + * | ||
| 783 | + * @param obj 对象 | ||
| 784 | + * @param charset 字符集 | ||
| 785 | + * @return 字符串 | ||
| 786 | + */ | ||
| 787 | + public static String str(Object obj, Charset charset) | ||
| 788 | + { | ||
| 789 | + if (null == obj) | ||
| 790 | + { | ||
| 791 | + return null; | ||
| 792 | + } | ||
| 793 | + | ||
| 794 | + if (obj instanceof String) | ||
| 795 | + { | ||
| 796 | + return (String) obj; | ||
| 797 | + } | ||
| 798 | + else if (obj instanceof byte[] || obj instanceof Byte[]) | ||
| 799 | + { | ||
| 800 | + return str((Byte[]) obj, charset); | ||
| 801 | + } | ||
| 802 | + else if (obj instanceof ByteBuffer) | ||
| 803 | + { | ||
| 804 | + return str((ByteBuffer) obj, charset); | ||
| 805 | + } | ||
| 806 | + return obj.toString(); | ||
| 807 | + } | ||
| 808 | + | ||
| 809 | + /** | ||
| 810 | + * 将byte数组转为字符串 | ||
| 811 | + * | ||
| 812 | + * @param bytes byte数组 | ||
| 813 | + * @param charset 字符集 | ||
| 814 | + * @return 字符串 | ||
| 815 | + */ | ||
| 816 | + public static String str(byte[] bytes, String charset) | ||
| 817 | + { | ||
| 818 | + return str(bytes, StringUtils.isEmpty(charset) ? Charset.defaultCharset() : Charset.forName(charset)); | ||
| 819 | + } | ||
| 820 | + | ||
| 821 | + /** | ||
| 822 | + * 解码字节码 | ||
| 823 | + * | ||
| 824 | + * @param data 字符串 | ||
| 825 | + * @param charset 字符集,如果此字段为空,则解码的结果取决于平台 | ||
| 826 | + * @return 解码后的字符串 | ||
| 827 | + */ | ||
| 828 | + public static String str(byte[] data, Charset charset) | ||
| 829 | + { | ||
| 830 | + if (data == null) | ||
| 831 | + { | ||
| 832 | + return null; | ||
| 833 | + } | ||
| 834 | + | ||
| 835 | + if (null == charset) | ||
| 836 | + { | ||
| 837 | + return new String(data); | ||
| 838 | + } | ||
| 839 | + return new String(data, charset); | ||
| 840 | + } | ||
| 841 | + | ||
| 842 | + /** | ||
| 843 | + * 将编码的byteBuffer数据转换为字符串 | ||
| 844 | + * | ||
| 845 | + * @param data 数据 | ||
| 846 | + * @param charset 字符集,如果为空使用当前系统字符集 | ||
| 847 | + * @return 字符串 | ||
| 848 | + */ | ||
| 849 | + public static String str(ByteBuffer data, String charset) | ||
| 850 | + { | ||
| 851 | + if (data == null) | ||
| 852 | + { | ||
| 853 | + return null; | ||
| 854 | + } | ||
| 855 | + | ||
| 856 | + return str(data, Charset.forName(charset)); | ||
| 857 | + } | ||
| 858 | + | ||
| 859 | + /** | ||
| 860 | + * 将编码的byteBuffer数据转换为字符串 | ||
| 861 | + * | ||
| 862 | + * @param data 数据 | ||
| 863 | + * @param charset 字符集,如果为空使用当前系统字符集 | ||
| 864 | + * @return 字符串 | ||
| 865 | + */ | ||
| 866 | + public static String str(ByteBuffer data, Charset charset) | ||
| 867 | + { | ||
| 868 | + if (null == charset) | ||
| 869 | + { | ||
| 870 | + charset = Charset.defaultCharset(); | ||
| 871 | + } | ||
| 872 | + return charset.decode(data).toString(); | ||
| 873 | + } | ||
| 874 | + | ||
| 875 | + // ----------------------------------------------------------------------- 全角半角转换 | ||
| 876 | + /** | ||
| 877 | + * 半角转全角 | ||
| 878 | + * | ||
| 879 | + * @param input String. | ||
| 880 | + * @return 全角字符串. | ||
| 881 | + */ | ||
| 882 | + public static String toSBC(String input) | ||
| 883 | + { | ||
| 884 | + return toSBC(input, null); | ||
| 885 | + } | ||
| 886 | + | ||
| 887 | + /** | ||
| 888 | + * 半角转全角 | ||
| 889 | + * | ||
| 890 | + * @param input String | ||
| 891 | + * @param notConvertSet 不替换的字符集合 | ||
| 892 | + * @return 全角字符串. | ||
| 893 | + */ | ||
| 894 | + public static String toSBC(String input, Set<Character> notConvertSet) | ||
| 895 | + { | ||
| 896 | + char c[] = input.toCharArray(); | ||
| 897 | + for (int i = 0; i < c.length; i++) | ||
| 898 | + { | ||
| 899 | + if (null != notConvertSet && notConvertSet.contains(c[i])) | ||
| 900 | + { | ||
| 901 | + // 跳过不替换的字符 | ||
| 902 | + continue; | ||
| 903 | + } | ||
| 904 | + | ||
| 905 | + if (c[i] == ' ') | ||
| 906 | + { | ||
| 907 | + c[i] = '\u3000'; | ||
| 908 | + } | ||
| 909 | + else if (c[i] < '\177') | ||
| 910 | + { | ||
| 911 | + c[i] = (char) (c[i] + 65248); | ||
| 912 | + | ||
| 913 | + } | ||
| 914 | + } | ||
| 915 | + return new String(c); | ||
| 916 | + } | ||
| 917 | + | ||
| 918 | + /** | ||
| 919 | + * 全角转半角 | ||
| 920 | + * | ||
| 921 | + * @param input String. | ||
| 922 | + * @return 半角字符串 | ||
| 923 | + */ | ||
| 924 | + public static String toDBC(String input) | ||
| 925 | + { | ||
| 926 | + return toDBC(input, null); | ||
| 927 | + } | ||
| 928 | + | ||
| 929 | + /** | ||
| 930 | + * 替换全角为半角 | ||
| 931 | + * | ||
| 932 | + * @param text 文本 | ||
| 933 | + * @param notConvertSet 不替换的字符集合 | ||
| 934 | + * @return 替换后的字符 | ||
| 935 | + */ | ||
| 936 | + public static String toDBC(String text, Set<Character> notConvertSet) | ||
| 937 | + { | ||
| 938 | + char c[] = text.toCharArray(); | ||
| 939 | + for (int i = 0; i < c.length; i++) | ||
| 940 | + { | ||
| 941 | + if (null != notConvertSet && notConvertSet.contains(c[i])) | ||
| 942 | + { | ||
| 943 | + // 跳过不替换的字符 | ||
| 944 | + continue; | ||
| 945 | + } | ||
| 946 | + | ||
| 947 | + if (c[i] == '\u3000') | ||
| 948 | + { | ||
| 949 | + c[i] = ' '; | ||
| 950 | + } | ||
| 951 | + else if (c[i] > '\uFF00' && c[i] < '\uFF5F') | ||
| 952 | + { | ||
| 953 | + c[i] = (char) (c[i] - 65248); | ||
| 954 | + } | ||
| 955 | + } | ||
| 956 | + String returnString = new String(c); | ||
| 957 | + | ||
| 958 | + return returnString; | ||
| 959 | + } | ||
| 960 | + | ||
| 961 | + /** | ||
| 962 | + * 数字金额大写转换 先写个完整的然后将如零拾替换成零 | ||
| 963 | + * | ||
| 964 | + * @param n 数字 | ||
| 965 | + * @return 中文大写数字 | ||
| 966 | + */ | ||
| 967 | + public static String digitUppercase(double n) | ||
| 968 | + { | ||
| 969 | + String[] fraction = { "角", "分" }; | ||
| 970 | + String[] digit = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" }; | ||
| 971 | + String[][] unit = { { "元", "万", "亿" }, { "", "拾", "佰", "仟" } }; | ||
| 972 | + | ||
| 973 | + String head = n < 0 ? "负" : ""; | ||
| 974 | + n = Math.abs(n); | ||
| 975 | + | ||
| 976 | + String s = ""; | ||
| 977 | + for (int i = 0; i < fraction.length; i++) | ||
| 978 | + { | ||
| 979 | + s += (digit[(int) (Math.floor(n * 10 * Math.pow(10, i)) % 10)] + fraction[i]).replaceAll("(零.)+", ""); | ||
| 980 | + } | ||
| 981 | + if (s.length() < 1) | ||
| 982 | + { | ||
| 983 | + s = "整"; | ||
| 984 | + } | ||
| 985 | + int integerPart = (int) Math.floor(n); | ||
| 986 | + | ||
| 987 | + for (int i = 0; i < unit[0].length && integerPart > 0; i++) | ||
| 988 | + { | ||
| 989 | + String p = ""; | ||
| 990 | + for (int j = 0; j < unit[1].length && n > 0; j++) | ||
| 991 | + { | ||
| 992 | + p = digit[integerPart % 10] + unit[1][j] + p; | ||
| 993 | + integerPart = integerPart / 10; | ||
| 994 | + } | ||
| 995 | + s = p.replaceAll("(零.)*零$", "").replaceAll("^$", "零") + unit[0][i] + s; | ||
| 996 | + } | ||
| 997 | + return head + s.replaceAll("(零.)*零元", "元").replaceFirst("(零.)+", "").replaceAll("(零.)+", "零").replaceAll("^整$", "零元整"); | ||
| 998 | + } | ||
| 999 | +} |
| 1 | +package com.ruoyi.common.utils.text; | ||
| 2 | + | ||
| 3 | +import com.ruoyi.common.utils.StringUtils; | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 字符串格式化 | ||
| 7 | + * | ||
| 8 | + * @author ruoyi | ||
| 9 | + */ | ||
| 10 | +public class StrFormatter | ||
| 11 | +{ | ||
| 12 | + public static final String EMPTY_JSON = "{}"; | ||
| 13 | + public static final char C_BACKSLASH = '\\'; | ||
| 14 | + public static final char C_DELIM_START = '{'; | ||
| 15 | + public static final char C_DELIM_END = '}'; | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 格式化字符串<br> | ||
| 19 | + * 此方法只是简单将占位符 {} 按照顺序替换为参数<br> | ||
| 20 | + * 如果想输出 {} 使用 \\转义 { 即可,如果想输出 {} 之前的 \ 使用双转义符 \\\\ 即可<br> | ||
| 21 | + * 例:<br> | ||
| 22 | + * 通常使用:format("this is {} for {}", "a", "b") -> this is a for b<br> | ||
| 23 | + * 转义{}: format("this is \\{} for {}", "a", "b") -> this is \{} for a<br> | ||
| 24 | + * 转义\: format("this is \\\\{} for {}", "a", "b") -> this is \a for b<br> | ||
| 25 | + * | ||
| 26 | + * @param strPattern 字符串模板 | ||
| 27 | + * @param argArray 参数列表 | ||
| 28 | + * @return 结果 | ||
| 29 | + */ | ||
| 30 | + public static String format(final String strPattern, final Object... argArray) | ||
| 31 | + { | ||
| 32 | + if (StringUtils.isEmpty(strPattern) || StringUtils.isEmpty(argArray)) | ||
| 33 | + { | ||
| 34 | + return strPattern; | ||
| 35 | + } | ||
| 36 | + final int strPatternLength = strPattern.length(); | ||
| 37 | + | ||
| 38 | + // 初始化定义好的长度以获得更好的性能 | ||
| 39 | + StringBuilder sbuf = new StringBuilder(strPatternLength + 50); | ||
| 40 | + | ||
| 41 | + int handledPosition = 0; | ||
| 42 | + int delimIndex;// 占位符所在位置 | ||
| 43 | + for (int argIndex = 0; argIndex < argArray.length; argIndex++) | ||
| 44 | + { | ||
| 45 | + delimIndex = strPattern.indexOf(EMPTY_JSON, handledPosition); | ||
| 46 | + if (delimIndex == -1) | ||
| 47 | + { | ||
| 48 | + if (handledPosition == 0) | ||
| 49 | + { | ||
| 50 | + return strPattern; | ||
| 51 | + } | ||
| 52 | + else | ||
| 53 | + { // 字符串模板剩余部分不再包含占位符,加入剩余部分后返回结果 | ||
| 54 | + sbuf.append(strPattern, handledPosition, strPatternLength); | ||
| 55 | + return sbuf.toString(); | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + else | ||
| 59 | + { | ||
| 60 | + if (delimIndex > 0 && strPattern.charAt(delimIndex - 1) == C_BACKSLASH) | ||
| 61 | + { | ||
| 62 | + if (delimIndex > 1 && strPattern.charAt(delimIndex - 2) == C_BACKSLASH) | ||
| 63 | + { | ||
| 64 | + // 转义符之前还有一个转义符,占位符依旧有效 | ||
| 65 | + sbuf.append(strPattern, handledPosition, delimIndex - 1); | ||
| 66 | + sbuf.append(Convert.utf8Str(argArray[argIndex])); | ||
| 67 | + handledPosition = delimIndex + 2; | ||
| 68 | + } | ||
| 69 | + else | ||
| 70 | + { | ||
| 71 | + // 占位符被转义 | ||
| 72 | + argIndex--; | ||
| 73 | + sbuf.append(strPattern, handledPosition, delimIndex - 1); | ||
| 74 | + sbuf.append(C_DELIM_START); | ||
| 75 | + handledPosition = delimIndex + 1; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + else | ||
| 79 | + { | ||
| 80 | + // 正常占位符 | ||
| 81 | + sbuf.append(strPattern, handledPosition, delimIndex); | ||
| 82 | + sbuf.append(Convert.utf8Str(argArray[argIndex])); | ||
| 83 | + handledPosition = delimIndex + 2; | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + // append the characters following the last {} pair. | ||
| 88 | + // 加入最后一个占位符后所有的字符 | ||
| 89 | + sbuf.append(strPattern, handledPosition, strPattern.length()); | ||
| 90 | + | ||
| 91 | + return sbuf.toString(); | ||
| 92 | + } | ||
| 93 | +} |
| 1 | +package com.ruoyi.framework.config; | ||
| 2 | + | ||
| 3 | +import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 4 | +import org.springframework.stereotype.Component; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 读取代码生成相关配置 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +@Component | ||
| 12 | +@ConfigurationProperties(prefix = "gen") | ||
| 13 | +public class GenConfig | ||
| 14 | +{ | ||
| 15 | + /** 作者 */ | ||
| 16 | + public static String author; | ||
| 17 | + | ||
| 18 | + /** 生成包路径 */ | ||
| 19 | + public static String packageName; | ||
| 20 | + | ||
| 21 | + /** 自动去除表前缀,默认是true */ | ||
| 22 | + public static boolean autoRemovePre; | ||
| 23 | + | ||
| 24 | + /** 表前缀(类名不会包含表前缀) */ | ||
| 25 | + public static String tablePrefix; | ||
| 26 | + | ||
| 27 | + public static String getAuthor() | ||
| 28 | + { | ||
| 29 | + return author; | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + public void setAuthor(String author) | ||
| 33 | + { | ||
| 34 | + GenConfig.author = author; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public static String getPackageName() | ||
| 38 | + { | ||
| 39 | + return packageName; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public void setPackageName(String packageName) | ||
| 43 | + { | ||
| 44 | + GenConfig.packageName = packageName; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public static boolean getAutoRemovePre() | ||
| 48 | + { | ||
| 49 | + return autoRemovePre; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public void setAutoRemovePre(boolean autoRemovePre) | ||
| 53 | + { | ||
| 54 | + GenConfig.autoRemovePre = autoRemovePre; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public static String getTablePrefix() | ||
| 58 | + { | ||
| 59 | + return tablePrefix; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + public void setTablePrefix(String tablePrefix) | ||
| 63 | + { | ||
| 64 | + GenConfig.tablePrefix = tablePrefix; | ||
| 65 | + } | ||
| 66 | +} |
| @@ -4,7 +4,6 @@ import java.io.Serializable; | @@ -4,7 +4,6 @@ import java.io.Serializable; | ||
| 4 | import java.util.Date; | 4 | import java.util.Date; |
| 5 | import java.util.HashMap; | 5 | import java.util.HashMap; |
| 6 | import java.util.Map; | 6 | import java.util.Map; |
| 7 | -import com.alibaba.fastjson.JSON; | ||
| 8 | import com.fasterxml.jackson.annotation.JsonFormat; | 7 | import com.fasterxml.jackson.annotation.JsonFormat; |
| 9 | import com.fasterxml.jackson.annotation.JsonIgnore; | 8 | import com.fasterxml.jackson.annotation.JsonIgnore; |
| 10 | 9 | ||
| @@ -40,9 +39,16 @@ public class BaseEntity implements Serializable | @@ -40,9 +39,16 @@ public class BaseEntity implements Serializable | ||
| 40 | /** 数据权限 */ | 39 | /** 数据权限 */ |
| 41 | private String dataScope; | 40 | private String dataScope; |
| 42 | 41 | ||
| 43 | - /** 请求参数 */ | 42 | + /** 开始时间 */ |
| 43 | + @JsonIgnore | ||
| 44 | + private String beginTime; | ||
| 45 | + | ||
| 46 | + /** 结束时间 */ | ||
| 44 | @JsonIgnore | 47 | @JsonIgnore |
| 45 | - private String params; | 48 | + private String endTime; |
| 49 | + | ||
| 50 | + /** 请求参数 */ | ||
| 51 | + private Map<String, Object> params; | ||
| 46 | 52 | ||
| 47 | public String getSearchValue() | 53 | public String getSearchValue() |
| 48 | { | 54 | { |
| @@ -114,17 +120,36 @@ public class BaseEntity implements Serializable | @@ -114,17 +120,36 @@ public class BaseEntity implements Serializable | ||
| 114 | this.dataScope = dataScope; | 120 | this.dataScope = dataScope; |
| 115 | } | 121 | } |
| 116 | 122 | ||
| 117 | - @SuppressWarnings("unchecked") | 123 | + public String getBeginTime() |
| 124 | + { | ||
| 125 | + return beginTime; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public void setBeginTime(String beginTime) | ||
| 129 | + { | ||
| 130 | + this.beginTime = beginTime; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public String getEndTime() | ||
| 134 | + { | ||
| 135 | + return endTime; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public void setEndTime(String endTime) | ||
| 139 | + { | ||
| 140 | + this.endTime = endTime; | ||
| 141 | + } | ||
| 142 | + | ||
| 118 | public Map<String, Object> getParams() | 143 | public Map<String, Object> getParams() |
| 119 | { | 144 | { |
| 120 | if (params == null) | 145 | if (params == null) |
| 121 | { | 146 | { |
| 122 | - return new HashMap<>(); | 147 | + params = new HashMap<>(); |
| 123 | } | 148 | } |
| 124 | - return JSON.parseObject(params, Map.class); | 149 | + return params; |
| 125 | } | 150 | } |
| 126 | 151 | ||
| 127 | - public void setParams(String params) | 152 | + public void setParams(Map<String, Object> params) |
| 128 | { | 153 | { |
| 129 | this.params = params; | 154 | this.params = params; |
| 130 | } | 155 | } |
| @@ -70,7 +70,6 @@ public class SysConfigController extends BaseController | @@ -70,7 +70,6 @@ public class SysConfigController extends BaseController | ||
| 70 | /** | 70 | /** |
| 71 | * 根据参数键名查询参数值 | 71 | * 根据参数键名查询参数值 |
| 72 | */ | 72 | */ |
| 73 | - @PreAuthorize("@ss.hasPermi('system:config:query')") | ||
| 74 | @GetMapping(value = "/configKey/{configKey}") | 73 | @GetMapping(value = "/configKey/{configKey}") |
| 75 | public AjaxResult getConfigKey(@PathVariable String configKey) | 74 | public AjaxResult getConfigKey(@PathVariable String configKey) |
| 76 | { | 75 | { |
| @@ -57,7 +57,6 @@ public class SysDeptController extends BaseController | @@ -57,7 +57,6 @@ public class SysDeptController extends BaseController | ||
| 57 | /** | 57 | /** |
| 58 | * 获取部门下拉树列表 | 58 | * 获取部门下拉树列表 |
| 59 | */ | 59 | */ |
| 60 | - @PreAuthorize("@ss.hasPermi('system:dept:query')") | ||
| 61 | @GetMapping("/treeselect") | 60 | @GetMapping("/treeselect") |
| 62 | public AjaxResult treeselect(SysDept dept) | 61 | public AjaxResult treeselect(SysDept dept) |
| 63 | { | 62 | { |
| @@ -68,7 +67,6 @@ public class SysDeptController extends BaseController | @@ -68,7 +67,6 @@ public class SysDeptController extends BaseController | ||
| 68 | /** | 67 | /** |
| 69 | * 加载对应角色部门列表树 | 68 | * 加载对应角色部门列表树 |
| 70 | */ | 69 | */ |
| 71 | - @PreAuthorize("@ss.hasPermi('system:dept:query')") | ||
| 72 | @GetMapping(value = "/roleDeptTreeselect/{roleId}") | 70 | @GetMapping(value = "/roleDeptTreeselect/{roleId}") |
| 73 | public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) | 71 | public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId) |
| 74 | { | 72 | { |
| @@ -66,7 +66,6 @@ public class SysDictDataController extends BaseController | @@ -66,7 +66,6 @@ public class SysDictDataController extends BaseController | ||
| 66 | /** | 66 | /** |
| 67 | * 根据字典类型查询字典数据信息 | 67 | * 根据字典类型查询字典数据信息 |
| 68 | */ | 68 | */ |
| 69 | - @PreAuthorize("@ss.hasPermi('system:dict:query')") | ||
| 70 | @GetMapping(value = "/dictType/{dictType}") | 69 | @GetMapping(value = "/dictType/{dictType}") |
| 71 | public AjaxResult dictType(@PathVariable String dictType) | 70 | public AjaxResult dictType(@PathVariable String dictType) |
| 72 | { | 71 | { |
| @@ -106,4 +106,14 @@ public class SysDictTypeController extends BaseController | @@ -106,4 +106,14 @@ public class SysDictTypeController extends BaseController | ||
| 106 | { | 106 | { |
| 107 | return toAjax(dictTypeService.deleteDictTypeByIds(dictIds)); | 107 | return toAjax(dictTypeService.deleteDictTypeByIds(dictIds)); |
| 108 | } | 108 | } |
| 109 | + | ||
| 110 | + /** | ||
| 111 | + * 获取字典选择框列表 | ||
| 112 | + */ | ||
| 113 | + @GetMapping("/optionselect") | ||
| 114 | + public AjaxResult optionselect() | ||
| 115 | + { | ||
| 116 | + List<SysDictType> dictTypes = dictTypeService.selectDictTypeAll(); | ||
| 117 | + return AjaxResult.success(dictTypes); | ||
| 118 | + } | ||
| 109 | } | 119 | } |
| @@ -57,7 +57,6 @@ public class SysMenuController extends BaseController | @@ -57,7 +57,6 @@ public class SysMenuController extends BaseController | ||
| 57 | /** | 57 | /** |
| 58 | * 获取菜单下拉树列表 | 58 | * 获取菜单下拉树列表 |
| 59 | */ | 59 | */ |
| 60 | - @PreAuthorize("@ss.hasPermi('system:menu:query')") | ||
| 61 | @GetMapping("/treeselect") | 60 | @GetMapping("/treeselect") |
| 62 | public AjaxResult treeselect(SysMenu dept) | 61 | public AjaxResult treeselect(SysMenu dept) |
| 63 | { | 62 | { |
| @@ -68,7 +67,6 @@ public class SysMenuController extends BaseController | @@ -68,7 +67,6 @@ public class SysMenuController extends BaseController | ||
| 68 | /** | 67 | /** |
| 69 | * 加载对应角色菜单列表树 | 68 | * 加载对应角色菜单列表树 |
| 70 | */ | 69 | */ |
| 71 | - @PreAuthorize("@ss.hasPermi('system:menu:query')") | ||
| 72 | @GetMapping(value = "/roleMenuTreeselect/{roleId}") | 70 | @GetMapping(value = "/roleMenuTreeselect/{roleId}") |
| 73 | public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) | 71 | public AjaxResult roleMenuTreeselect(@PathVariable("roleId") Long roleId) |
| 74 | { | 72 | { |
| @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
| 14 | import org.springframework.web.bind.annotation.RestController; | 14 | import org.springframework.web.bind.annotation.RestController; |
| 15 | import com.ruoyi.common.constant.UserConstants; | 15 | import com.ruoyi.common.constant.UserConstants; |
| 16 | import com.ruoyi.common.utils.SecurityUtils; | 16 | import com.ruoyi.common.utils.SecurityUtils; |
| 17 | +import com.ruoyi.common.utils.StringUtils; | ||
| 17 | import com.ruoyi.common.utils.poi.ExcelUtil; | 18 | import com.ruoyi.common.utils.poi.ExcelUtil; |
| 18 | import com.ruoyi.framework.aspectj.lang.annotation.Log; | 19 | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| 19 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | 20 | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| @@ -69,12 +70,18 @@ public class SysUserController extends BaseController | @@ -69,12 +70,18 @@ public class SysUserController extends BaseController | ||
| 69 | * 根据用户编号获取详细信息 | 70 | * 根据用户编号获取详细信息 |
| 70 | */ | 71 | */ |
| 71 | @PreAuthorize("@ss.hasPermi('system:user:query')") | 72 | @PreAuthorize("@ss.hasPermi('system:user:query')") |
| 72 | - @GetMapping(value = "/{userId}") | ||
| 73 | - public AjaxResult getInfo(@PathVariable Long userId) | 73 | + @GetMapping(value = { "/", "/{userId}" }) |
| 74 | + public AjaxResult getInfo(@PathVariable(value = "userId", required = false) Long userId) | ||
| 74 | { | 75 | { |
| 75 | - AjaxResult ajax = AjaxResult.success(userService.selectUserById(userId)); | 76 | + AjaxResult ajax = AjaxResult.success(); |
| 77 | + ajax.put("roles", roleService.selectRoleAll()); | ||
| 78 | + ajax.put("posts", postService.selectPostAll()); | ||
| 79 | + if (StringUtils.isNotNull(userId)) | ||
| 80 | + { | ||
| 81 | + ajax.put(AjaxResult.DATA_TAG, userService.selectUserById(userId)); | ||
| 76 | ajax.put("postIds", postService.selectPostListByUserId(userId)); | 82 | ajax.put("postIds", postService.selectPostListByUserId(userId)); |
| 77 | ajax.put("roleIds", roleService.selectRoleListByUserId(userId)); | 83 | ajax.put("roleIds", roleService.selectRoleListByUserId(userId)); |
| 84 | + } | ||
| 78 | return ajax; | 85 | return ajax; |
| 79 | } | 86 | } |
| 80 | 87 |
| @@ -116,11 +116,10 @@ public class SysMenuServiceImpl implements ISysMenuService | @@ -116,11 +116,10 @@ public class SysMenuServiceImpl implements ISysMenuService | ||
| 116 | for (SysMenu menu : menus) | 116 | for (SysMenu menu : menus) |
| 117 | { | 117 | { |
| 118 | RouterVo router = new RouterVo(); | 118 | RouterVo router = new RouterVo(); |
| 119 | - router.setName(menu.getMenuName()); | 119 | + router.setName(StringUtils.capitalize(menu.getPath())); |
| 120 | router.setPath(getRouterPath(menu)); | 120 | router.setPath(getRouterPath(menu)); |
| 121 | router.setComponent(StringUtils.isEmpty(menu.getComponent()) ? "Layout" : menu.getComponent()); | 121 | router.setComponent(StringUtils.isEmpty(menu.getComponent()) ? "Layout" : menu.getComponent()); |
| 122 | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); | 122 | router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon())); |
| 123 | - router.setName(menu.getMenuName()); | ||
| 124 | List<SysMenu> cMenus = menu.getChildren(); | 123 | List<SysMenu> cMenus = menu.getChildren(); |
| 125 | if (!cMenus.isEmpty() && cMenus.size() > 0 && "M".equals(menu.getMenuType())) | 124 | if (!cMenus.isEmpty() && cMenus.size() > 0 && "M".equals(menu.getMenuType())) |
| 126 | { | 125 | { |
| 1 | +package com.ruoyi.project.tool.gen.controller; | ||
| 2 | + | ||
| 3 | +import java.io.IOException; | ||
| 4 | +import java.util.HashMap; | ||
| 5 | +import java.util.List; | ||
| 6 | +import java.util.Map; | ||
| 7 | +import javax.servlet.http.HttpServletResponse; | ||
| 8 | +import org.apache.commons.io.IOUtils; | ||
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 10 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 11 | +import org.springframework.validation.annotation.Validated; | ||
| 12 | +import org.springframework.web.bind.annotation.DeleteMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 14 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 15 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 16 | +import org.springframework.web.bind.annotation.PutMapping; | ||
| 17 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 18 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 19 | +import org.springframework.web.bind.annotation.RestController; | ||
| 20 | +import com.ruoyi.common.utils.text.Convert; | ||
| 21 | +import com.ruoyi.framework.aspectj.lang.annotation.Log; | ||
| 22 | +import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | ||
| 23 | +import com.ruoyi.framework.web.controller.BaseController; | ||
| 24 | +import com.ruoyi.framework.web.domain.AjaxResult; | ||
| 25 | +import com.ruoyi.framework.web.page.TableDataInfo; | ||
| 26 | +import com.ruoyi.project.tool.gen.domain.GenTable; | ||
| 27 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 28 | +import com.ruoyi.project.tool.gen.service.IGenTableColumnService; | ||
| 29 | +import com.ruoyi.project.tool.gen.service.IGenTableService; | ||
| 30 | + | ||
| 31 | +/** | ||
| 32 | + * 代码生成 操作处理 | ||
| 33 | + * | ||
| 34 | + * @author ruoyi | ||
| 35 | + */ | ||
| 36 | +@RestController | ||
| 37 | +@RequestMapping("/tool/gen") | ||
| 38 | +public class GenController extends BaseController | ||
| 39 | +{ | ||
| 40 | + | ||
| 41 | + @Autowired | ||
| 42 | + private IGenTableService genTableService; | ||
| 43 | + | ||
| 44 | + @Autowired | ||
| 45 | + private IGenTableColumnService genTableColumnService; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 查询代码生成列表 | ||
| 49 | + */ | ||
| 50 | + @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||
| 51 | + @GetMapping("/list") | ||
| 52 | + public TableDataInfo genList(GenTable genTable) | ||
| 53 | + { | ||
| 54 | + startPage(); | ||
| 55 | + List<GenTable> list = genTableService.selectGenTableList(genTable); | ||
| 56 | + return getDataTable(list); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 修改代码生成业务 | ||
| 61 | + */ | ||
| 62 | + @PreAuthorize("@ss.hasPermi('tool:gen:query')") | ||
| 63 | + @GetMapping(value = "/{talbleId}") | ||
| 64 | + public AjaxResult getInfo(@PathVariable Long talbleId) | ||
| 65 | + { | ||
| 66 | + GenTable table = genTableService.selectGenTableById(talbleId); | ||
| 67 | + List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId); | ||
| 68 | + Map<String, Object> map = new HashMap<String, Object>(); | ||
| 69 | + map.put("info", table); | ||
| 70 | + map.put("rows", list); | ||
| 71 | + return AjaxResult.success(map); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + /** | ||
| 75 | + * 查询数据库列表 | ||
| 76 | + */ | ||
| 77 | + @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||
| 78 | + @GetMapping("/db/list") | ||
| 79 | + public TableDataInfo dataList(GenTable genTable) | ||
| 80 | + { | ||
| 81 | + startPage(); | ||
| 82 | + List<GenTable> list = genTableService.selectDbTableList(genTable); | ||
| 83 | + return getDataTable(list); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 查询数据表字段列表 | ||
| 88 | + */ | ||
| 89 | + @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||
| 90 | + @GetMapping(value = "/column/{talbleId}") | ||
| 91 | + public TableDataInfo columnList(Long tableId) | ||
| 92 | + { | ||
| 93 | + TableDataInfo dataInfo = new TableDataInfo(); | ||
| 94 | + List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId); | ||
| 95 | + dataInfo.setRows(list); | ||
| 96 | + dataInfo.setTotal(list.size()); | ||
| 97 | + return dataInfo; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 导入表结构(保存) | ||
| 102 | + */ | ||
| 103 | + @PreAuthorize("@ss.hasPermi('tool:gen:list')") | ||
| 104 | + @Log(title = "代码生成", businessType = BusinessType.IMPORT) | ||
| 105 | + @PostMapping("/importTable") | ||
| 106 | + public AjaxResult importTableSave(String tables) | ||
| 107 | + { | ||
| 108 | + String[] tableNames = Convert.toStrArray(tables); | ||
| 109 | + // 查询表信息 | ||
| 110 | + List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames); | ||
| 111 | + genTableService.importGenTable(tableList); | ||
| 112 | + return AjaxResult.success(); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * 修改保存代码生成业务 | ||
| 117 | + */ | ||
| 118 | + @PreAuthorize("@ss.hasPermi('tool:gen:edit')") | ||
| 119 | + @Log(title = "代码生成", businessType = BusinessType.UPDATE) | ||
| 120 | + @PutMapping | ||
| 121 | + public AjaxResult editSave(@Validated @RequestBody GenTable genTable) | ||
| 122 | + { | ||
| 123 | + System.out.println(genTable.getParams().size()); | ||
| 124 | + genTableService.validateEdit(genTable); | ||
| 125 | + genTableService.updateGenTable(genTable); | ||
| 126 | + return AjaxResult.success(); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + @PreAuthorize("@ss.hasPermi('tool:gen:remove')") | ||
| 130 | + @Log(title = "代码生成", businessType = BusinessType.DELETE) | ||
| 131 | + @DeleteMapping("/{tableIds}") | ||
| 132 | + public AjaxResult remove(@PathVariable Long[] tableIds) | ||
| 133 | + { | ||
| 134 | + genTableService.deleteGenTableByIds(tableIds); | ||
| 135 | + return AjaxResult.success(); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * 预览代码 | ||
| 140 | + */ | ||
| 141 | + @PreAuthorize("@ss.hasPermi('tool:gen:preview')") | ||
| 142 | + @GetMapping("/preview/{tableId}") | ||
| 143 | + public AjaxResult preview(@PathVariable("tableId") Long tableId) throws IOException | ||
| 144 | + { | ||
| 145 | + Map<String, String> dataMap = genTableService.previewCode(tableId); | ||
| 146 | + return AjaxResult.success(dataMap); | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + /** | ||
| 150 | + * 生成代码 | ||
| 151 | + */ | ||
| 152 | + @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||
| 153 | + @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||
| 154 | + @GetMapping("/genCode/{tableName}") | ||
| 155 | + public void genCode(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException | ||
| 156 | + { | ||
| 157 | + byte[] data = genTableService.generatorCode(tableName); | ||
| 158 | + genCode(response, data); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + /** | ||
| 162 | + * 批量生成代码 | ||
| 163 | + */ | ||
| 164 | + @PreAuthorize("@ss.hasPermi('tool:gen:code')") | ||
| 165 | + @Log(title = "代码生成", businessType = BusinessType.GENCODE) | ||
| 166 | + @GetMapping("/batchGenCode") | ||
| 167 | + public void batchGenCode(HttpServletResponse response, String tables) throws IOException | ||
| 168 | + { | ||
| 169 | + String[] tableNames = Convert.toStrArray(tables); | ||
| 170 | + byte[] data = genTableService.generatorCode(tableNames); | ||
| 171 | + genCode(response, data); | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + /** | ||
| 175 | + * 生成zip文件 | ||
| 176 | + */ | ||
| 177 | + private void genCode(HttpServletResponse response, byte[] data) throws IOException | ||
| 178 | + { | ||
| 179 | + response.reset(); | ||
| 180 | + response.setHeader("Content-Disposition", "attachment; filename=\"ruoyi.zip\""); | ||
| 181 | + response.addHeader("Content-Length", "" + data.length); | ||
| 182 | + response.setContentType("application/octet-stream; charset=UTF-8"); | ||
| 183 | + IOUtils.write(data, response.getOutputStream()); | ||
| 184 | + } | ||
| 185 | +} |
| 1 | +package com.ruoyi.project.tool.gen.domain; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import javax.validation.Valid; | ||
| 5 | +import javax.validation.constraints.NotBlank; | ||
| 6 | +import com.ruoyi.common.constant.GenConstants; | ||
| 7 | +import com.ruoyi.common.utils.StringUtils; | ||
| 8 | +import com.ruoyi.framework.web.domain.BaseEntity; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 业务表 gen_table | ||
| 12 | + * | ||
| 13 | + * @author ruoyi | ||
| 14 | + */ | ||
| 15 | +public class GenTable extends BaseEntity | ||
| 16 | +{ | ||
| 17 | + private static final long serialVersionUID = 1L; | ||
| 18 | + | ||
| 19 | + /** 编号 */ | ||
| 20 | + private Long tableId; | ||
| 21 | + | ||
| 22 | + /** 表名称 */ | ||
| 23 | + @NotBlank(message = "表名称不能为空") | ||
| 24 | + private String tableName; | ||
| 25 | + | ||
| 26 | + /** 表描述 */ | ||
| 27 | + @NotBlank(message = "表描述不能为空") | ||
| 28 | + private String tableComment; | ||
| 29 | + | ||
| 30 | + /** 实体类名称(首字母大写) */ | ||
| 31 | + @NotBlank(message = "实体类名称不能为空") | ||
| 32 | + private String className; | ||
| 33 | + | ||
| 34 | + /** 使用的模板(crud单表操作 tree树表操作) */ | ||
| 35 | + private String tplCategory; | ||
| 36 | + | ||
| 37 | + /** 生成包路径 */ | ||
| 38 | + @NotBlank(message = "生成包路径不能为空") | ||
| 39 | + private String packageName; | ||
| 40 | + | ||
| 41 | + /** 生成模块名 */ | ||
| 42 | + @NotBlank(message = "生成模块名不能为空") | ||
| 43 | + private String moduleName; | ||
| 44 | + | ||
| 45 | + /** 生成业务名 */ | ||
| 46 | + @NotBlank(message = "生成业务名不能为空") | ||
| 47 | + private String businessName; | ||
| 48 | + | ||
| 49 | + /** 生成功能名 */ | ||
| 50 | + @NotBlank(message = "生成功能名不能为空") | ||
| 51 | + private String functionName; | ||
| 52 | + | ||
| 53 | + /** 生成作者 */ | ||
| 54 | + @NotBlank(message = "作者不能为空") | ||
| 55 | + private String functionAuthor; | ||
| 56 | + | ||
| 57 | + /** 主键信息 */ | ||
| 58 | + private GenTableColumn pkColumn; | ||
| 59 | + | ||
| 60 | + /** 表列信息 */ | ||
| 61 | + @Valid | ||
| 62 | + private List<GenTableColumn> columns; | ||
| 63 | + | ||
| 64 | + /** 其它生成选项 */ | ||
| 65 | + private String options; | ||
| 66 | + | ||
| 67 | + /** 树编码字段 */ | ||
| 68 | + private String treeCode; | ||
| 69 | + | ||
| 70 | + /** 树父编码字段 */ | ||
| 71 | + private String treeParentCode; | ||
| 72 | + | ||
| 73 | + /** 树名称字段 */ | ||
| 74 | + private String treeName; | ||
| 75 | + | ||
| 76 | + public Long getTableId() | ||
| 77 | + { | ||
| 78 | + return tableId; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public void setTableId(Long tableId) | ||
| 82 | + { | ||
| 83 | + this.tableId = tableId; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public String getTableName() | ||
| 87 | + { | ||
| 88 | + return tableName; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setTableName(String tableName) | ||
| 92 | + { | ||
| 93 | + this.tableName = tableName; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public String getTableComment() | ||
| 97 | + { | ||
| 98 | + return tableComment; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void setTableComment(String tableComment) | ||
| 102 | + { | ||
| 103 | + this.tableComment = tableComment; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public String getClassName() | ||
| 107 | + { | ||
| 108 | + return className; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setClassName(String className) | ||
| 112 | + { | ||
| 113 | + this.className = className; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public String getTplCategory() | ||
| 117 | + { | ||
| 118 | + return tplCategory; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void setTplCategory(String tplCategory) | ||
| 122 | + { | ||
| 123 | + this.tplCategory = tplCategory; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public String getPackageName() | ||
| 127 | + { | ||
| 128 | + return packageName; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public void setPackageName(String packageName) | ||
| 132 | + { | ||
| 133 | + this.packageName = packageName; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public String getModuleName() | ||
| 137 | + { | ||
| 138 | + return moduleName; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void setModuleName(String moduleName) | ||
| 142 | + { | ||
| 143 | + this.moduleName = moduleName; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public String getBusinessName() | ||
| 147 | + { | ||
| 148 | + return businessName; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public void setBusinessName(String businessName) | ||
| 152 | + { | ||
| 153 | + this.businessName = businessName; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public String getFunctionName() | ||
| 157 | + { | ||
| 158 | + return functionName; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public void setFunctionName(String functionName) | ||
| 162 | + { | ||
| 163 | + this.functionName = functionName; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public String getFunctionAuthor() | ||
| 167 | + { | ||
| 168 | + return functionAuthor; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + public void setFunctionAuthor(String functionAuthor) | ||
| 172 | + { | ||
| 173 | + this.functionAuthor = functionAuthor; | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public GenTableColumn getPkColumn() | ||
| 177 | + { | ||
| 178 | + return pkColumn; | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public void setPkColumn(GenTableColumn pkColumn) | ||
| 182 | + { | ||
| 183 | + this.pkColumn = pkColumn; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public List<GenTableColumn> getColumns() | ||
| 187 | + { | ||
| 188 | + return columns; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + public void setColumns(List<GenTableColumn> columns) | ||
| 192 | + { | ||
| 193 | + this.columns = columns; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public String getOptions() | ||
| 197 | + { | ||
| 198 | + return options; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + public void setOptions(String options) | ||
| 202 | + { | ||
| 203 | + this.options = options; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + public String getTreeCode() | ||
| 207 | + { | ||
| 208 | + return treeCode; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + public void setTreeCode(String treeCode) | ||
| 212 | + { | ||
| 213 | + this.treeCode = treeCode; | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + public String getTreeParentCode() | ||
| 217 | + { | ||
| 218 | + return treeParentCode; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public void setTreeParentCode(String treeParentCode) | ||
| 222 | + { | ||
| 223 | + this.treeParentCode = treeParentCode; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + public String getTreeName() | ||
| 227 | + { | ||
| 228 | + return treeName; | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + public void setTreeName(String treeName) | ||
| 232 | + { | ||
| 233 | + this.treeName = treeName; | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + public boolean isTree() | ||
| 237 | + { | ||
| 238 | + return isTree(this.tplCategory); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + public static boolean isTree(String tplCategory) | ||
| 242 | + { | ||
| 243 | + return tplCategory != null && StringUtils.equals(GenConstants.TPL_TREE, tplCategory); | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + public boolean isCrud() | ||
| 247 | + { | ||
| 248 | + return isCrud(this.tplCategory); | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + public static boolean isCrud(String tplCategory) | ||
| 252 | + { | ||
| 253 | + return tplCategory != null && StringUtils.equals(GenConstants.TPL_CRUD, tplCategory); | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + public boolean isSuperColumn(String javaField) | ||
| 257 | + { | ||
| 258 | + return isSuperColumn(this.tplCategory, javaField); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + public static boolean isSuperColumn(String tplCategory, String javaField) | ||
| 262 | + { | ||
| 263 | + if (isTree(tplCategory)) | ||
| 264 | + { | ||
| 265 | + StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.TREE_ENTITY); | ||
| 266 | + } | ||
| 267 | + return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); | ||
| 268 | + } | ||
| 269 | +} |
| 1 | +package com.ruoyi.project.tool.gen.domain; | ||
| 2 | + | ||
| 3 | +import javax.validation.constraints.NotBlank; | ||
| 4 | +import com.ruoyi.common.utils.StringUtils; | ||
| 5 | +import com.ruoyi.framework.web.domain.BaseEntity; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 代码生成业务字段表 gen_table_column | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + */ | ||
| 12 | +public class GenTableColumn extends BaseEntity | ||
| 13 | +{ | ||
| 14 | + private static final long serialVersionUID = 1L; | ||
| 15 | + | ||
| 16 | + /** 编号 */ | ||
| 17 | + private Long columnId; | ||
| 18 | + | ||
| 19 | + /** 归属表编号 */ | ||
| 20 | + private Long tableId; | ||
| 21 | + | ||
| 22 | + /** 列名称 */ | ||
| 23 | + private String columnName; | ||
| 24 | + | ||
| 25 | + /** 列描述 */ | ||
| 26 | + private String columnComment; | ||
| 27 | + | ||
| 28 | + /** 列类型 */ | ||
| 29 | + private String columnType; | ||
| 30 | + | ||
| 31 | + /** JAVA类型 */ | ||
| 32 | + private String javaType; | ||
| 33 | + | ||
| 34 | + /** JAVA字段名 */ | ||
| 35 | + @NotBlank(message = "Java属性不能为空") | ||
| 36 | + private String javaField; | ||
| 37 | + | ||
| 38 | + /** 是否主键(1是) */ | ||
| 39 | + private String isPk; | ||
| 40 | + | ||
| 41 | + /** 是否自增(1是) */ | ||
| 42 | + private String isIncrement; | ||
| 43 | + | ||
| 44 | + /** 是否必填(1是) */ | ||
| 45 | + private String isRequired; | ||
| 46 | + | ||
| 47 | + /** 是否为插入字段(1是) */ | ||
| 48 | + private String isInsert; | ||
| 49 | + | ||
| 50 | + /** 是否编辑字段(1是) */ | ||
| 51 | + private String isEdit; | ||
| 52 | + | ||
| 53 | + /** 是否列表字段(1是) */ | ||
| 54 | + private String isList; | ||
| 55 | + | ||
| 56 | + /** 是否查询字段(1是) */ | ||
| 57 | + private String isQuery; | ||
| 58 | + | ||
| 59 | + /** 查询方式(EQ等于、NE不等于、GT大于、LT小于、LIKE模糊、BETWEEN范围) */ | ||
| 60 | + private String queryType; | ||
| 61 | + | ||
| 62 | + /** 显示类型(input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件) */ | ||
| 63 | + private String htmlType; | ||
| 64 | + | ||
| 65 | + /** 字典类型 */ | ||
| 66 | + private String dictType; | ||
| 67 | + | ||
| 68 | + /** 排序 */ | ||
| 69 | + private Integer sort; | ||
| 70 | + | ||
| 71 | + public void setColumnId(Long columnId) | ||
| 72 | + { | ||
| 73 | + this.columnId = columnId; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public Long getColumnId() | ||
| 77 | + { | ||
| 78 | + return columnId; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public void setTableId(Long tableId) | ||
| 82 | + { | ||
| 83 | + this.tableId = tableId; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public Long getTableId() | ||
| 87 | + { | ||
| 88 | + return tableId; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public void setColumnName(String columnName) | ||
| 92 | + { | ||
| 93 | + this.columnName = columnName; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + public String getColumnName() | ||
| 97 | + { | ||
| 98 | + return columnName; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void setColumnComment(String columnComment) | ||
| 102 | + { | ||
| 103 | + this.columnComment = columnComment; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public String getColumnComment() | ||
| 107 | + { | ||
| 108 | + return columnComment; | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + public void setColumnType(String columnType) | ||
| 112 | + { | ||
| 113 | + this.columnType = columnType; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + public String getColumnType() | ||
| 117 | + { | ||
| 118 | + return columnType; | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + public void setJavaType(String javaType) | ||
| 122 | + { | ||
| 123 | + this.javaType = javaType; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public String getJavaType() | ||
| 127 | + { | ||
| 128 | + return javaType; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + public void setJavaField(String javaField) | ||
| 132 | + { | ||
| 133 | + this.javaField = javaField; | ||
| 134 | + } | ||
| 135 | + | ||
| 136 | + public String getJavaField() | ||
| 137 | + { | ||
| 138 | + return javaField; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + public void setIsPk(String isPk) | ||
| 142 | + { | ||
| 143 | + this.isPk = isPk; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public String getIsPk() | ||
| 147 | + { | ||
| 148 | + return isPk; | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + public boolean isPk() | ||
| 152 | + { | ||
| 153 | + return isPk(this.isPk); | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + public boolean isPk(String isPk) | ||
| 157 | + { | ||
| 158 | + return isPk != null && StringUtils.equals("1", isPk); | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + public String getIsIncrement() | ||
| 162 | + { | ||
| 163 | + return isIncrement; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public void setIsIncrement(String isIncrement) | ||
| 167 | + { | ||
| 168 | + this.isIncrement = isIncrement; | ||
| 169 | + } | ||
| 170 | + | ||
| 171 | + public boolean isIncrement() | ||
| 172 | + { | ||
| 173 | + return isIncrement(this.isIncrement); | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + public boolean isIncrement(String isIncrement) | ||
| 177 | + { | ||
| 178 | + return isIncrement != null && StringUtils.equals("1", isIncrement); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + public void setIsRequired(String isRequired) | ||
| 182 | + { | ||
| 183 | + this.isRequired = isRequired; | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + public String getIsRequired() | ||
| 187 | + { | ||
| 188 | + return isRequired; | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + public boolean isRequired() | ||
| 192 | + { | ||
| 193 | + return isRequired(this.isRequired); | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + public boolean isRequired(String isRequired) | ||
| 197 | + { | ||
| 198 | + return isRequired != null && StringUtils.equals("1", isRequired); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + public void setIsInsert(String isInsert) | ||
| 202 | + { | ||
| 203 | + this.isInsert = isInsert; | ||
| 204 | + } | ||
| 205 | + | ||
| 206 | + public String getIsInsert() | ||
| 207 | + { | ||
| 208 | + return isInsert; | ||
| 209 | + } | ||
| 210 | + | ||
| 211 | + public boolean isInsert() | ||
| 212 | + { | ||
| 213 | + return isInsert(this.isInsert); | ||
| 214 | + } | ||
| 215 | + | ||
| 216 | + public boolean isInsert(String isInsert) | ||
| 217 | + { | ||
| 218 | + return isInsert != null && StringUtils.equals("1", isInsert); | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + public void setIsEdit(String isEdit) | ||
| 222 | + { | ||
| 223 | + this.isEdit = isEdit; | ||
| 224 | + } | ||
| 225 | + | ||
| 226 | + public String getIsEdit() | ||
| 227 | + { | ||
| 228 | + return isEdit; | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + public boolean isEdit() | ||
| 232 | + { | ||
| 233 | + return isInsert(this.isEdit); | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + public boolean isEdit(String isEdit) | ||
| 237 | + { | ||
| 238 | + return isEdit != null && StringUtils.equals("1", isEdit); | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + public void setIsList(String isList) | ||
| 242 | + { | ||
| 243 | + this.isList = isList; | ||
| 244 | + } | ||
| 245 | + | ||
| 246 | + public String getIsList() | ||
| 247 | + { | ||
| 248 | + return isList; | ||
| 249 | + } | ||
| 250 | + | ||
| 251 | + public boolean isList() | ||
| 252 | + { | ||
| 253 | + return isList(this.isList); | ||
| 254 | + } | ||
| 255 | + | ||
| 256 | + public boolean isList(String isList) | ||
| 257 | + { | ||
| 258 | + return isList != null && StringUtils.equals("1", isList); | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + public void setIsQuery(String isQuery) | ||
| 262 | + { | ||
| 263 | + this.isQuery = isQuery; | ||
| 264 | + } | ||
| 265 | + | ||
| 266 | + public String getIsQuery() | ||
| 267 | + { | ||
| 268 | + return isQuery; | ||
| 269 | + } | ||
| 270 | + | ||
| 271 | + public boolean isQuery() | ||
| 272 | + { | ||
| 273 | + return isQuery(this.isQuery); | ||
| 274 | + } | ||
| 275 | + | ||
| 276 | + public boolean isQuery(String isQuery) | ||
| 277 | + { | ||
| 278 | + return isQuery != null && StringUtils.equals("1", isQuery); | ||
| 279 | + } | ||
| 280 | + | ||
| 281 | + public void setQueryType(String queryType) | ||
| 282 | + { | ||
| 283 | + this.queryType = queryType; | ||
| 284 | + } | ||
| 285 | + | ||
| 286 | + public String getQueryType() | ||
| 287 | + { | ||
| 288 | + return queryType; | ||
| 289 | + } | ||
| 290 | + | ||
| 291 | + public String getHtmlType() | ||
| 292 | + { | ||
| 293 | + return htmlType; | ||
| 294 | + } | ||
| 295 | + | ||
| 296 | + public void setHtmlType(String htmlType) | ||
| 297 | + { | ||
| 298 | + this.htmlType = htmlType; | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + public void setDictType(String dictType) | ||
| 302 | + { | ||
| 303 | + this.dictType = dictType; | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + public String getDictType() | ||
| 307 | + { | ||
| 308 | + return dictType; | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + public void setSort(Integer sort) | ||
| 312 | + { | ||
| 313 | + this.sort = sort; | ||
| 314 | + } | ||
| 315 | + | ||
| 316 | + public Integer getSort() | ||
| 317 | + { | ||
| 318 | + return sort; | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + public boolean isSuperColumn() | ||
| 322 | + { | ||
| 323 | + return isSuperColumn(this.javaField); | ||
| 324 | + } | ||
| 325 | + | ||
| 326 | + public static boolean isSuperColumn(String javaField) | ||
| 327 | + { | ||
| 328 | + return StringUtils.equalsAnyIgnoreCase(javaField, | ||
| 329 | + // BaseEntity | ||
| 330 | + "createBy", "createTime", "updateBy", "updateTime", "remark", | ||
| 331 | + // TreeEntity | ||
| 332 | + "parentName", "parentId", "orderNum", "ancestors"); | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + public boolean isUsableColumn() | ||
| 336 | + { | ||
| 337 | + return isUsableColumn(javaField); | ||
| 338 | + } | ||
| 339 | + | ||
| 340 | + public static boolean isUsableColumn(String javaField) | ||
| 341 | + { | ||
| 342 | + // isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单 | ||
| 343 | + return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum"); | ||
| 344 | + } | ||
| 345 | + | ||
| 346 | + public String readConverterExp() | ||
| 347 | + { | ||
| 348 | + String remarks = StringUtils.substringBetween(this.columnComment, "(", ")"); | ||
| 349 | + StringBuffer sb = new StringBuffer(); | ||
| 350 | + if (StringUtils.isNotEmpty(remarks)) | ||
| 351 | + { | ||
| 352 | + for (String value : remarks.split(" ")) | ||
| 353 | + { | ||
| 354 | + if (StringUtils.isNotEmpty(value)) | ||
| 355 | + { | ||
| 356 | + Object startStr = value.subSequence(0, 1); | ||
| 357 | + String endStr = value.substring(1); | ||
| 358 | + sb.append("").append(startStr).append("=").append(endStr).append(","); | ||
| 359 | + } | ||
| 360 | + } | ||
| 361 | + return sb.deleteCharAt(sb.length() - 1).toString(); | ||
| 362 | + } | ||
| 363 | + else | ||
| 364 | + { | ||
| 365 | + return this.columnComment; | ||
| 366 | + } | ||
| 367 | + } | ||
| 368 | +} |
| 1 | +package com.ruoyi.project.tool.gen.mapper; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 业务字段 数据层 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public interface GenTableColumnMapper | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * 根据表名称查询列信息 | ||
| 15 | + * | ||
| 16 | + * @param tableName 表名称 | ||
| 17 | + * @return 列信息 | ||
| 18 | + */ | ||
| 19 | + public List<GenTableColumn> selectDbTableColumnsByName(String tableName); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 查询业务字段列表 | ||
| 23 | + * | ||
| 24 | + * @param tableId 业务字段编号 | ||
| 25 | + * @return 业务字段集合 | ||
| 26 | + */ | ||
| 27 | + public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 新增业务字段 | ||
| 31 | + * | ||
| 32 | + * @param genTableColumn 业务字段信息 | ||
| 33 | + * @return 结果 | ||
| 34 | + */ | ||
| 35 | + public int insertGenTableColumn(GenTableColumn genTableColumn); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 修改业务字段 | ||
| 39 | + * | ||
| 40 | + * @param genTableColumn 业务字段信息 | ||
| 41 | + * @return 结果 | ||
| 42 | + */ | ||
| 43 | + public int updateGenTableColumn(GenTableColumn genTableColumn); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 批量删除业务字段 | ||
| 47 | + * | ||
| 48 | + * @param ids 需要删除的数据ID | ||
| 49 | + * @return 结果 | ||
| 50 | + */ | ||
| 51 | + public int deleteGenTableColumnByIds(Long[] ids); | ||
| 52 | +} |
| 1 | +package com.ruoyi.project.tool.gen.mapper; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import com.ruoyi.project.tool.gen.domain.GenTable; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 业务 数据层 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public interface GenTableMapper | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * 查询业务列表 | ||
| 15 | + * | ||
| 16 | + * @param genTable 业务信息 | ||
| 17 | + * @return 业务集合 | ||
| 18 | + */ | ||
| 19 | + public List<GenTable> selectGenTableList(GenTable genTable); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 查询据库列表 | ||
| 23 | + * | ||
| 24 | + * @param genTable 业务信息 | ||
| 25 | + * @return 数据库表集合 | ||
| 26 | + */ | ||
| 27 | + public List<GenTable> selectDbTableList(GenTable genTable); | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 查询据库列表 | ||
| 31 | + * | ||
| 32 | + * @param tableNames 表名称组 | ||
| 33 | + * @return 数据库表集合 | ||
| 34 | + */ | ||
| 35 | + public List<GenTable> selectDbTableListByNames(String[] tableNames); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 查询表ID业务信息 | ||
| 39 | + * | ||
| 40 | + * @param id 业务ID | ||
| 41 | + * @return 业务信息 | ||
| 42 | + */ | ||
| 43 | + public GenTable selectGenTableById(Long id); | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 查询表名称业务信息 | ||
| 47 | + * | ||
| 48 | + * @param tableName 表名称 | ||
| 49 | + * @return 业务信息 | ||
| 50 | + */ | ||
| 51 | + public GenTable selectGenTableByName(String tableName); | ||
| 52 | + | ||
| 53 | + /** | ||
| 54 | + * 新增业务 | ||
| 55 | + * | ||
| 56 | + * @param genTable 业务信息 | ||
| 57 | + * @return 结果 | ||
| 58 | + */ | ||
| 59 | + public int insertGenTable(GenTable genTable); | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 修改业务 | ||
| 63 | + * | ||
| 64 | + * @param genTable 业务信息 | ||
| 65 | + * @return 结果 | ||
| 66 | + */ | ||
| 67 | + public int updateGenTable(GenTable genTable); | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 批量删除业务 | ||
| 71 | + * | ||
| 72 | + * @param ids 需要删除的数据ID | ||
| 73 | + * @return 结果 | ||
| 74 | + */ | ||
| 75 | + public int deleteGenTableByIds(Long[] ids); | ||
| 76 | +} |
| 1 | +package com.ruoyi.project.tool.gen.service; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | +import org.springframework.stereotype.Service; | ||
| 6 | +import com.ruoyi.common.utils.text.Convert; | ||
| 7 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 8 | +import com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper; | ||
| 9 | + | ||
| 10 | +/** | ||
| 11 | + * 业务字段 服务层实现 | ||
| 12 | + * | ||
| 13 | + * @author ruoyi | ||
| 14 | + */ | ||
| 15 | +@Service | ||
| 16 | +public class GenTableColumnServiceImpl implements IGenTableColumnService | ||
| 17 | +{ | ||
| 18 | + @Autowired | ||
| 19 | + private GenTableColumnMapper genTableColumnMapper; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 查询业务字段列表 | ||
| 23 | + * | ||
| 24 | + * @param genTableColumn 业务字段编号 | ||
| 25 | + * @return 业务字段集合 | ||
| 26 | + */ | ||
| 27 | + @Override | ||
| 28 | + public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId) | ||
| 29 | + { | ||
| 30 | + return genTableColumnMapper.selectGenTableColumnListByTableId(tableId); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * 新增业务字段 | ||
| 35 | + * | ||
| 36 | + * @param genTableColumn 业务字段信息 | ||
| 37 | + * @return 结果 | ||
| 38 | + */ | ||
| 39 | + @Override | ||
| 40 | + public int insertGenTableColumn(GenTableColumn genTableColumn) | ||
| 41 | + { | ||
| 42 | + return genTableColumnMapper.insertGenTableColumn(genTableColumn); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 修改业务字段 | ||
| 47 | + * | ||
| 48 | + * @param genTableColumn 业务字段信息 | ||
| 49 | + * @return 结果 | ||
| 50 | + */ | ||
| 51 | + @Override | ||
| 52 | + public int updateGenTableColumn(GenTableColumn genTableColumn) | ||
| 53 | + { | ||
| 54 | + return genTableColumnMapper.updateGenTableColumn(genTableColumn); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 删除业务字段对象 | ||
| 59 | + * | ||
| 60 | + * @param ids 需要删除的数据ID | ||
| 61 | + * @return 结果 | ||
| 62 | + */ | ||
| 63 | + @Override | ||
| 64 | + public int deleteGenTableColumnByIds(String ids) | ||
| 65 | + { | ||
| 66 | + return genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids)); | ||
| 67 | + } | ||
| 68 | +} |
| 1 | +package com.ruoyi.project.tool.gen.service; | ||
| 2 | + | ||
| 3 | +import java.io.ByteArrayOutputStream; | ||
| 4 | +import java.io.IOException; | ||
| 5 | +import java.io.StringWriter; | ||
| 6 | +import java.util.LinkedHashMap; | ||
| 7 | +import java.util.List; | ||
| 8 | +import java.util.Map; | ||
| 9 | +import java.util.zip.ZipEntry; | ||
| 10 | +import java.util.zip.ZipOutputStream; | ||
| 11 | +import org.apache.commons.io.IOUtils; | ||
| 12 | +import org.apache.velocity.Template; | ||
| 13 | +import org.apache.velocity.VelocityContext; | ||
| 14 | +import org.apache.velocity.app.Velocity; | ||
| 15 | +import org.slf4j.Logger; | ||
| 16 | +import org.slf4j.LoggerFactory; | ||
| 17 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 18 | +import org.springframework.stereotype.Service; | ||
| 19 | +import org.springframework.transaction.annotation.Transactional; | ||
| 20 | +import com.alibaba.fastjson.JSON; | ||
| 21 | +import com.alibaba.fastjson.JSONObject; | ||
| 22 | +import com.ruoyi.common.constant.Constants; | ||
| 23 | +import com.ruoyi.common.constant.GenConstants; | ||
| 24 | +import com.ruoyi.common.exception.CustomException; | ||
| 25 | +import com.ruoyi.common.utils.SecurityUtils; | ||
| 26 | +import com.ruoyi.common.utils.StringUtils; | ||
| 27 | +import com.ruoyi.project.tool.gen.domain.GenTable; | ||
| 28 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 29 | +import com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper; | ||
| 30 | +import com.ruoyi.project.tool.gen.mapper.GenTableMapper; | ||
| 31 | +import com.ruoyi.project.tool.gen.util.GenUtils; | ||
| 32 | +import com.ruoyi.project.tool.gen.util.VelocityInitializer; | ||
| 33 | +import com.ruoyi.project.tool.gen.util.VelocityUtils; | ||
| 34 | + | ||
| 35 | +/** | ||
| 36 | + * 业务 服务层实现 | ||
| 37 | + * | ||
| 38 | + * @author ruoyi | ||
| 39 | + */ | ||
| 40 | +@Service | ||
| 41 | +public class GenTableServiceImpl implements IGenTableService | ||
| 42 | +{ | ||
| 43 | + private static final Logger log = LoggerFactory.getLogger(GenTableServiceImpl.class); | ||
| 44 | + | ||
| 45 | + @Autowired | ||
| 46 | + private GenTableMapper genTableMapper; | ||
| 47 | + | ||
| 48 | + @Autowired | ||
| 49 | + private GenTableColumnMapper genTableColumnMapper; | ||
| 50 | + | ||
| 51 | + /** | ||
| 52 | + * 查询业务信息 | ||
| 53 | + * | ||
| 54 | + * @param id 业务ID | ||
| 55 | + * @return 业务信息 | ||
| 56 | + */ | ||
| 57 | + @Override | ||
| 58 | + public GenTable selectGenTableById(Long id) | ||
| 59 | + { | ||
| 60 | + GenTable genTable = genTableMapper.selectGenTableById(id); | ||
| 61 | + setTableFromOptions(genTable); | ||
| 62 | + return genTable; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + /** | ||
| 66 | + * 查询业务列表 | ||
| 67 | + * | ||
| 68 | + * @param genTable 业务信息 | ||
| 69 | + * @return 业务集合 | ||
| 70 | + */ | ||
| 71 | + @Override | ||
| 72 | + public List<GenTable> selectGenTableList(GenTable genTable) | ||
| 73 | + { | ||
| 74 | + return genTableMapper.selectGenTableList(genTable); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 查询据库列表 | ||
| 79 | + * | ||
| 80 | + * @param genTable 业务信息 | ||
| 81 | + * @return 数据库表集合 | ||
| 82 | + */ | ||
| 83 | + public List<GenTable> selectDbTableList(GenTable genTable) | ||
| 84 | + { | ||
| 85 | + return genTableMapper.selectDbTableList(genTable); | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * 查询据库列表 | ||
| 90 | + * | ||
| 91 | + * @param tableNames 表名称组 | ||
| 92 | + * @return 数据库表集合 | ||
| 93 | + */ | ||
| 94 | + public List<GenTable> selectDbTableListByNames(String[] tableNames) | ||
| 95 | + { | ||
| 96 | + return genTableMapper.selectDbTableListByNames(tableNames); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 修改业务 | ||
| 101 | + * | ||
| 102 | + * @param genTable 业务信息 | ||
| 103 | + * @return 结果 | ||
| 104 | + */ | ||
| 105 | + @Override | ||
| 106 | + @Transactional | ||
| 107 | + public void updateGenTable(GenTable genTable) | ||
| 108 | + { | ||
| 109 | + String options = JSON.toJSONString(genTable.getParams()); | ||
| 110 | + genTable.setOptions(options); | ||
| 111 | + int row = genTableMapper.updateGenTable(genTable); | ||
| 112 | + if (row > 0) | ||
| 113 | + { | ||
| 114 | + for (GenTableColumn cenTableColumn : genTable.getColumns()) | ||
| 115 | + { | ||
| 116 | + genTableColumnMapper.updateGenTableColumn(cenTableColumn); | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + | ||
| 121 | + /** | ||
| 122 | + * 删除业务对象 | ||
| 123 | + * | ||
| 124 | + * @param ids 需要删除的数据ID | ||
| 125 | + * @return 结果 | ||
| 126 | + */ | ||
| 127 | + @Override | ||
| 128 | + @Transactional | ||
| 129 | + public void deleteGenTableByIds(Long[] tableIds) | ||
| 130 | + { | ||
| 131 | + genTableMapper.deleteGenTableByIds(tableIds); | ||
| 132 | + genTableColumnMapper.deleteGenTableColumnByIds(tableIds); | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + /** | ||
| 136 | + * 导入表结构 | ||
| 137 | + * | ||
| 138 | + * @param tableList 导入表列表 | ||
| 139 | + */ | ||
| 140 | + @Override | ||
| 141 | + @Transactional | ||
| 142 | + public void importGenTable(List<GenTable> tableList) | ||
| 143 | + { | ||
| 144 | + String operName = SecurityUtils.getUsername(); | ||
| 145 | + for (GenTable table : tableList) | ||
| 146 | + { | ||
| 147 | + try | ||
| 148 | + { | ||
| 149 | + String tableName = table.getTableName(); | ||
| 150 | + GenUtils.initTable(table, operName); | ||
| 151 | + int row = genTableMapper.insertGenTable(table); | ||
| 152 | + if (row > 0) | ||
| 153 | + { | ||
| 154 | + // 保存列信息 | ||
| 155 | + List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName); | ||
| 156 | + for (GenTableColumn column : genTableColumns) | ||
| 157 | + { | ||
| 158 | + GenUtils.initColumnField(column, table); | ||
| 159 | + genTableColumnMapper.insertGenTableColumn(column); | ||
| 160 | + } | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + catch (Exception e) | ||
| 164 | + { | ||
| 165 | + log.error("表名 " + table.getTableName() + " 导入失败:", e); | ||
| 166 | + } | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + /** | ||
| 171 | + * 预览代码 | ||
| 172 | + * | ||
| 173 | + * @param tableId 表编号 | ||
| 174 | + * @return 预览数据列表 | ||
| 175 | + */ | ||
| 176 | + public Map<String, String> previewCode(Long tableId) | ||
| 177 | + { | ||
| 178 | + Map<String, String> dataMap = new LinkedHashMap<>(); | ||
| 179 | + // 查询表信息 | ||
| 180 | + GenTable table = genTableMapper.selectGenTableById(tableId); | ||
| 181 | + // 查询列信息 | ||
| 182 | + List<GenTableColumn> columns = table.getColumns(); | ||
| 183 | + setPkColumn(table, columns); | ||
| 184 | + VelocityInitializer.initVelocity(); | ||
| 185 | + | ||
| 186 | + VelocityContext context = VelocityUtils.prepareContext(table); | ||
| 187 | + | ||
| 188 | + // 获取模板列表 | ||
| 189 | + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | ||
| 190 | + for (String template : templates) | ||
| 191 | + { | ||
| 192 | + // 渲染模板 | ||
| 193 | + StringWriter sw = new StringWriter(); | ||
| 194 | + Template tpl = Velocity.getTemplate(template, Constants.UTF8); | ||
| 195 | + tpl.merge(context, sw); | ||
| 196 | + dataMap.put(template, sw.toString()); | ||
| 197 | + } | ||
| 198 | + return dataMap; | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + /** | ||
| 202 | + * 生成代码 | ||
| 203 | + * | ||
| 204 | + * @param tableName 表名称 | ||
| 205 | + * @return 数据 | ||
| 206 | + */ | ||
| 207 | + @Override | ||
| 208 | + public byte[] generatorCode(String tableName) | ||
| 209 | + { | ||
| 210 | + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
| 211 | + ZipOutputStream zip = new ZipOutputStream(outputStream); | ||
| 212 | + generatorCode(tableName, zip); | ||
| 213 | + IOUtils.closeQuietly(zip); | ||
| 214 | + return outputStream.toByteArray(); | ||
| 215 | + } | ||
| 216 | + | ||
| 217 | + /** | ||
| 218 | + * 批量生成代码 | ||
| 219 | + * | ||
| 220 | + * @param tableNames 表数组 | ||
| 221 | + * @return 数据 | ||
| 222 | + */ | ||
| 223 | + @Override | ||
| 224 | + public byte[] generatorCode(String[] tableNames) | ||
| 225 | + { | ||
| 226 | + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); | ||
| 227 | + ZipOutputStream zip = new ZipOutputStream(outputStream); | ||
| 228 | + for (String tableName : tableNames) | ||
| 229 | + { | ||
| 230 | + generatorCode(tableName, zip); | ||
| 231 | + } | ||
| 232 | + IOUtils.closeQuietly(zip); | ||
| 233 | + return outputStream.toByteArray(); | ||
| 234 | + } | ||
| 235 | + | ||
| 236 | + /** | ||
| 237 | + * 查询表信息并生成代码 | ||
| 238 | + */ | ||
| 239 | + private void generatorCode(String tableName, ZipOutputStream zip) | ||
| 240 | + { | ||
| 241 | + // 查询表信息 | ||
| 242 | + GenTable table = genTableMapper.selectGenTableByName(tableName); | ||
| 243 | + // 查询列信息 | ||
| 244 | + List<GenTableColumn> columns = table.getColumns(); | ||
| 245 | + setPkColumn(table, columns); | ||
| 246 | + | ||
| 247 | + VelocityInitializer.initVelocity(); | ||
| 248 | + | ||
| 249 | + VelocityContext context = VelocityUtils.prepareContext(table); | ||
| 250 | + | ||
| 251 | + // 获取模板列表 | ||
| 252 | + List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory()); | ||
| 253 | + for (String template : templates) | ||
| 254 | + { | ||
| 255 | + // 渲染模板 | ||
| 256 | + StringWriter sw = new StringWriter(); | ||
| 257 | + Template tpl = Velocity.getTemplate(template, Constants.UTF8); | ||
| 258 | + tpl.merge(context, sw); | ||
| 259 | + try | ||
| 260 | + { | ||
| 261 | + // 添加到zip | ||
| 262 | + zip.putNextEntry(new ZipEntry(VelocityUtils.getFileName(template, table))); | ||
| 263 | + IOUtils.write(sw.toString(), zip, Constants.UTF8); | ||
| 264 | + IOUtils.closeQuietly(sw); | ||
| 265 | + zip.closeEntry(); | ||
| 266 | + } | ||
| 267 | + catch (IOException e) | ||
| 268 | + { | ||
| 269 | + log.error("渲染模板失败,表名:" + table.getTableName(), e); | ||
| 270 | + } | ||
| 271 | + } | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + /** | ||
| 275 | + * 修改保存参数校验 | ||
| 276 | + * | ||
| 277 | + * @param genTable 业务信息 | ||
| 278 | + */ | ||
| 279 | + public void validateEdit(GenTable genTable) | ||
| 280 | + { | ||
| 281 | + if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) | ||
| 282 | + { | ||
| 283 | + String options = JSON.toJSONString(genTable.getParams()); | ||
| 284 | + JSONObject paramsObj = JSONObject.parseObject(options); | ||
| 285 | + if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_CODE))) | ||
| 286 | + { | ||
| 287 | + throw new CustomException("树编码字段不能为空"); | ||
| 288 | + } | ||
| 289 | + else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_PARENT_CODE))) | ||
| 290 | + { | ||
| 291 | + throw new CustomException("树父编码字段不能为空"); | ||
| 292 | + } | ||
| 293 | + else if (StringUtils.isEmpty(paramsObj.getString(GenConstants.TREE_NAME))) | ||
| 294 | + { | ||
| 295 | + throw new CustomException("树名称字段不能为空"); | ||
| 296 | + } | ||
| 297 | + } | ||
| 298 | + } | ||
| 299 | + | ||
| 300 | + /** | ||
| 301 | + * 设置主键列信息 | ||
| 302 | + * | ||
| 303 | + * @param genTable 业务表信息 | ||
| 304 | + * @param columns 业务字段列表 | ||
| 305 | + */ | ||
| 306 | + public void setPkColumn(GenTable table, List<GenTableColumn> columns) | ||
| 307 | + { | ||
| 308 | + for (GenTableColumn column : columns) | ||
| 309 | + { | ||
| 310 | + if (column.isPk()) | ||
| 311 | + { | ||
| 312 | + table.setPkColumn(column); | ||
| 313 | + break; | ||
| 314 | + } | ||
| 315 | + } | ||
| 316 | + if (StringUtils.isNull(table.getPkColumn())) | ||
| 317 | + { | ||
| 318 | + table.setPkColumn(columns.get(0)); | ||
| 319 | + } | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + /** | ||
| 323 | + * 设置代码生成其他选项值 | ||
| 324 | + * | ||
| 325 | + * @param genTable 设置后的生成对象 | ||
| 326 | + */ | ||
| 327 | + public void setTableFromOptions(GenTable genTable) | ||
| 328 | + { | ||
| 329 | + JSONObject paramsObj = JSONObject.parseObject(genTable.getOptions()); | ||
| 330 | + if (StringUtils.isNotNull(paramsObj)) | ||
| 331 | + { | ||
| 332 | + String treeCode = paramsObj.getString(GenConstants.TREE_CODE); | ||
| 333 | + String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); | ||
| 334 | + String treeName = paramsObj.getString(GenConstants.TREE_NAME); | ||
| 335 | + genTable.setTreeCode(treeCode); | ||
| 336 | + genTable.setTreeParentCode(treeParentCode); | ||
| 337 | + genTable.setTreeName(treeName); | ||
| 338 | + } | ||
| 339 | + } | ||
| 340 | +} |
| 1 | +package com.ruoyi.project.tool.gen.service; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * 业务字段 服务层 | ||
| 8 | + * | ||
| 9 | + * @author ruoyi | ||
| 10 | + */ | ||
| 11 | +public interface IGenTableColumnService | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * 查询业务字段列表 | ||
| 15 | + * | ||
| 16 | + * @param genTableColumn 业务字段编号 | ||
| 17 | + * @return 业务字段集合 | ||
| 18 | + */ | ||
| 19 | + public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId); | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * 新增业务字段 | ||
| 23 | + * | ||
| 24 | + * @param genTableColumn 业务字段信息 | ||
| 25 | + * @return 结果 | ||
| 26 | + */ | ||
| 27 | + public int insertGenTableColumn(GenTableColumn genTableColumn); | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * 修改业务字段 | ||
| 31 | + * | ||
| 32 | + * @param genTableColumn 业务字段信息 | ||
| 33 | + * @return 结果 | ||
| 34 | + */ | ||
| 35 | + public int updateGenTableColumn(GenTableColumn genTableColumn); | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * 删除业务字段信息 | ||
| 39 | + * | ||
| 40 | + * @param ids 需要删除的数据ID | ||
| 41 | + * @return 结果 | ||
| 42 | + */ | ||
| 43 | + public int deleteGenTableColumnByIds(String ids); | ||
| 44 | +} |
| 1 | +package com.ruoyi.project.tool.gen.service; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import java.util.Map; | ||
| 5 | +import com.ruoyi.project.tool.gen.domain.GenTable; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * 业务 服务层 | ||
| 9 | + * | ||
| 10 | + * @author ruoyi | ||
| 11 | + */ | ||
| 12 | +public interface IGenTableService | ||
| 13 | +{ | ||
| 14 | + /** | ||
| 15 | + * 查询业务列表 | ||
| 16 | + * | ||
| 17 | + * @param genTable 业务信息 | ||
| 18 | + * @return 业务集合 | ||
| 19 | + */ | ||
| 20 | + public List<GenTable> selectGenTableList(GenTable genTable); | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 查询据库列表 | ||
| 24 | + * | ||
| 25 | + * @param genTable 业务信息 | ||
| 26 | + * @return 数据库表集合 | ||
| 27 | + */ | ||
| 28 | + public List<GenTable> selectDbTableList(GenTable genTable); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 查询据库列表 | ||
| 32 | + * | ||
| 33 | + * @param tableNames 表名称组 | ||
| 34 | + * @return 数据库表集合 | ||
| 35 | + */ | ||
| 36 | + public List<GenTable> selectDbTableListByNames(String[] tableNames); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 查询业务信息 | ||
| 40 | + * | ||
| 41 | + * @param id 业务ID | ||
| 42 | + * @return 业务信息 | ||
| 43 | + */ | ||
| 44 | + public GenTable selectGenTableById(Long id); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 修改业务 | ||
| 48 | + * | ||
| 49 | + * @param genTable 业务信息 | ||
| 50 | + * @return 结果 | ||
| 51 | + */ | ||
| 52 | + public void updateGenTable(GenTable genTable); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 删除业务信息 | ||
| 56 | + * | ||
| 57 | + * @param tableIds 需要删除的表数据ID | ||
| 58 | + * @return 结果 | ||
| 59 | + */ | ||
| 60 | + public void deleteGenTableByIds(Long[] tableIds); | ||
| 61 | + | ||
| 62 | + /** | ||
| 63 | + * 导入表结构 | ||
| 64 | + * | ||
| 65 | + * @param tableList 导入表列表 | ||
| 66 | + */ | ||
| 67 | + public void importGenTable(List<GenTable> tableList); | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 预览代码 | ||
| 71 | + * | ||
| 72 | + * @param tableId 表编号 | ||
| 73 | + * @return 预览数据列表 | ||
| 74 | + */ | ||
| 75 | + public Map<String, String> previewCode(Long tableId); | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * 生成代码 | ||
| 79 | + * | ||
| 80 | + * @param tableName 表名称 | ||
| 81 | + * @return 数据 | ||
| 82 | + */ | ||
| 83 | + public byte[] generatorCode(String tableName); | ||
| 84 | + | ||
| 85 | + /** | ||
| 86 | + * 批量生成代码 | ||
| 87 | + * | ||
| 88 | + * @param tableNames 表数组 | ||
| 89 | + * @return 数据 | ||
| 90 | + */ | ||
| 91 | + public byte[] generatorCode(String[] tableNames); | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 修改保存参数校验 | ||
| 95 | + * | ||
| 96 | + * @param genTable 业务信息 | ||
| 97 | + */ | ||
| 98 | + public void validateEdit(GenTable genTable); | ||
| 99 | +} |
| 1 | +package com.ruoyi.project.tool.gen.util; | ||
| 2 | + | ||
| 3 | +import java.util.Arrays; | ||
| 4 | +import org.apache.commons.lang3.RegExUtils; | ||
| 5 | +import com.ruoyi.common.constant.GenConstants; | ||
| 6 | +import com.ruoyi.common.utils.StringUtils; | ||
| 7 | +import com.ruoyi.framework.config.GenConfig; | ||
| 8 | +import com.ruoyi.project.tool.gen.domain.GenTable; | ||
| 9 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * 代码生成器 工具类 | ||
| 13 | + * | ||
| 14 | + * @author ruoyi | ||
| 15 | + */ | ||
| 16 | +public class GenUtils | ||
| 17 | +{ | ||
| 18 | + /** | ||
| 19 | + * 初始化表信息 | ||
| 20 | + */ | ||
| 21 | + public static void initTable(GenTable genTable, String operName) | ||
| 22 | + { | ||
| 23 | + genTable.setClassName(convertClassName(genTable.getTableName())); | ||
| 24 | + genTable.setPackageName(GenConfig.getPackageName()); | ||
| 25 | + genTable.setModuleName(getModuleName(GenConfig.getPackageName())); | ||
| 26 | + genTable.setBusinessName(getBusinessName(genTable.getTableName())); | ||
| 27 | + genTable.setFunctionName(replaceText(genTable.getTableComment())); | ||
| 28 | + genTable.setFunctionAuthor(GenConfig.getAuthor()); | ||
| 29 | + genTable.setCreateBy(operName); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + /** | ||
| 33 | + * 初始化列属性字段 | ||
| 34 | + */ | ||
| 35 | + public static void initColumnField(GenTableColumn column, GenTable table) | ||
| 36 | + { | ||
| 37 | + String dataType = getDbType(column.getColumnType()); | ||
| 38 | + String columnName = column.getColumnName(); | ||
| 39 | + column.setTableId(table.getTableId()); | ||
| 40 | + column.setCreateBy(table.getCreateBy()); | ||
| 41 | + // 设置java字段名 | ||
| 42 | + column.setJavaField(StringUtils.toCamelCase(columnName)); | ||
| 43 | + | ||
| 44 | + if (arraysContains(GenConstants.COLUMNTYPE_STR, dataType)) | ||
| 45 | + { | ||
| 46 | + column.setJavaType(GenConstants.TYPE_STRING); | ||
| 47 | + // 字符串长度超过500设置为文本域 | ||
| 48 | + Integer columnLength = getColumnLength(column.getColumnType()); | ||
| 49 | + String htmlType = columnLength >= 500 ? GenConstants.HTML_TEXTAREA : GenConstants.HTML_INPUT; | ||
| 50 | + column.setHtmlType(htmlType); | ||
| 51 | + } | ||
| 52 | + else if (arraysContains(GenConstants.COLUMNTYPE_TIME, dataType)) | ||
| 53 | + { | ||
| 54 | + column.setJavaType(GenConstants.TYPE_DATE); | ||
| 55 | + column.setHtmlType(GenConstants.HTML_DATETIME); | ||
| 56 | + } | ||
| 57 | + else if (arraysContains(GenConstants.COLUMNTYPE_NUMBER, dataType)) | ||
| 58 | + { | ||
| 59 | + column.setHtmlType(GenConstants.HTML_INPUT); | ||
| 60 | + | ||
| 61 | + // 如果是浮点型 | ||
| 62 | + String[] str = StringUtils.split(StringUtils.substringBetween(column.getColumnType(), "(", ")"), ","); | ||
| 63 | + if (str != null && str.length == 2 && Integer.parseInt(str[1]) > 0) | ||
| 64 | + { | ||
| 65 | + column.setJavaType(GenConstants.TYPE_DOUBLE); | ||
| 66 | + } | ||
| 67 | + // 如果是整形 | ||
| 68 | + else if (str != null && str.length == 1 && Integer.parseInt(str[0]) <= 10) | ||
| 69 | + { | ||
| 70 | + column.setJavaType(GenConstants.TYPE_INTEGER); | ||
| 71 | + } | ||
| 72 | + // 长整形 | ||
| 73 | + else | ||
| 74 | + { | ||
| 75 | + column.setJavaType(GenConstants.TYPE_LONG); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + // 插入字段(默认所有字段都需要插入) | ||
| 80 | + column.setIsInsert(GenConstants.REQUIRE); | ||
| 81 | + | ||
| 82 | + // 编辑字段 | ||
| 83 | + if (!arraysContains(GenConstants.COLUMNNAME_NOT_EDIT, columnName) && !column.isPk()) | ||
| 84 | + { | ||
| 85 | + column.setIsEdit(GenConstants.REQUIRE); | ||
| 86 | + } | ||
| 87 | + // 列表字段 | ||
| 88 | + if (!arraysContains(GenConstants.COLUMNNAME_NOT_LIST, columnName) && !column.isPk()) | ||
| 89 | + { | ||
| 90 | + column.setIsList(GenConstants.REQUIRE); | ||
| 91 | + } | ||
| 92 | + // 查询字段 | ||
| 93 | + if (!arraysContains(GenConstants.COLUMNNAME_NOT_QUERY, columnName) && !column.isPk()) | ||
| 94 | + { | ||
| 95 | + column.setIsQuery(GenConstants.REQUIRE); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + // 查询字段类型 | ||
| 99 | + if (StringUtils.endsWithIgnoreCase(columnName, "name")) | ||
| 100 | + { | ||
| 101 | + column.setQueryType(GenConstants.QUERY_LIKE); | ||
| 102 | + } | ||
| 103 | + // 状态字段设置单选框 | ||
| 104 | + if (StringUtils.endsWithIgnoreCase(columnName, "status")) | ||
| 105 | + { | ||
| 106 | + column.setHtmlType(GenConstants.HTML_RADIO); | ||
| 107 | + } | ||
| 108 | + // 类型&性别字段设置下拉框 | ||
| 109 | + else if (StringUtils.endsWithIgnoreCase(columnName, "type") | ||
| 110 | + || StringUtils.endsWithIgnoreCase(columnName, "sex")) | ||
| 111 | + { | ||
| 112 | + column.setHtmlType(GenConstants.HTML_SELECT); | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + /** | ||
| 117 | + * 校验数组是否包含指定值 | ||
| 118 | + * | ||
| 119 | + * @param arr 数组 | ||
| 120 | + * @param targetValue 值 | ||
| 121 | + * @return 是否包含 | ||
| 122 | + */ | ||
| 123 | + public static boolean arraysContains(String[] arr, String targetValue) | ||
| 124 | + { | ||
| 125 | + return Arrays.asList(arr).contains(targetValue); | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + /** | ||
| 129 | + * 获取模块名 | ||
| 130 | + * | ||
| 131 | + * @param packageName 包名 | ||
| 132 | + * @return 模块名 | ||
| 133 | + */ | ||
| 134 | + public static String getModuleName(String packageName) | ||
| 135 | + { | ||
| 136 | + int lastIndex = packageName.lastIndexOf("."); | ||
| 137 | + int nameLength = packageName.length(); | ||
| 138 | + String moduleName = StringUtils.substring(packageName, lastIndex + 1, nameLength); | ||
| 139 | + return moduleName; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + /** | ||
| 143 | + * 获取业务名 | ||
| 144 | + * | ||
| 145 | + * @param tableName 表名 | ||
| 146 | + * @return 业务名 | ||
| 147 | + */ | ||
| 148 | + public static String getBusinessName(String tableName) | ||
| 149 | + { | ||
| 150 | + int lastIndex = tableName.lastIndexOf("_"); | ||
| 151 | + int nameLength = tableName.length(); | ||
| 152 | + String businessName = StringUtils.substring(tableName, lastIndex + 1, nameLength); | ||
| 153 | + return businessName; | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + /** | ||
| 157 | + * 表名转换成Java类名 | ||
| 158 | + * | ||
| 159 | + * @param tableName 表名称 | ||
| 160 | + * @return 类名 | ||
| 161 | + */ | ||
| 162 | + public static String convertClassName(String tableName) | ||
| 163 | + { | ||
| 164 | + boolean autoRemovePre = GenConfig.getAutoRemovePre(); | ||
| 165 | + String tablePrefix = GenConfig.getTablePrefix(); | ||
| 166 | + if (autoRemovePre && StringUtils.isNotEmpty(tablePrefix)) | ||
| 167 | + { | ||
| 168 | + String[] searchList = StringUtils.split(tablePrefix, ","); | ||
| 169 | + String[] replacementList = emptyList(searchList.length); | ||
| 170 | + tableName = StringUtils.replaceEach(tableName, searchList, replacementList); | ||
| 171 | + } | ||
| 172 | + return StringUtils.convertToCamelCase(tableName); | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * 关键字替换 | ||
| 177 | + * | ||
| 178 | + * @param name 需要被替换的名字 | ||
| 179 | + * @return 替换后的名字 | ||
| 180 | + */ | ||
| 181 | + public static String replaceText(String text) | ||
| 182 | + { | ||
| 183 | + return RegExUtils.replaceAll(text, "(?:表|若依)", ""); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + /** | ||
| 187 | + * 获取数据库类型字段 | ||
| 188 | + * | ||
| 189 | + * @param columnType 列类型 | ||
| 190 | + * @return 截取后的列类型 | ||
| 191 | + */ | ||
| 192 | + public static String getDbType(String columnType) | ||
| 193 | + { | ||
| 194 | + if (StringUtils.indexOf(columnType, "(") > 0) | ||
| 195 | + { | ||
| 196 | + return StringUtils.substringBefore(columnType, "("); | ||
| 197 | + } | ||
| 198 | + else | ||
| 199 | + { | ||
| 200 | + return columnType; | ||
| 201 | + } | ||
| 202 | + } | ||
| 203 | + | ||
| 204 | + /** | ||
| 205 | + * 获取字段长度 | ||
| 206 | + * | ||
| 207 | + * @param columnType 列类型 | ||
| 208 | + * @return 截取后的列类型 | ||
| 209 | + */ | ||
| 210 | + public static Integer getColumnLength(String columnType) | ||
| 211 | + { | ||
| 212 | + if (StringUtils.indexOf(columnType, "(") > 0) | ||
| 213 | + { | ||
| 214 | + String length = StringUtils.substringBetween(columnType, "(", ")"); | ||
| 215 | + return Integer.valueOf(length); | ||
| 216 | + } | ||
| 217 | + else | ||
| 218 | + { | ||
| 219 | + return 0; | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | + /** | ||
| 224 | + * 获取空数组列表 | ||
| 225 | + * | ||
| 226 | + * @param length 长度 | ||
| 227 | + * @return 数组信息 | ||
| 228 | + */ | ||
| 229 | + public static String[] emptyList(int length) | ||
| 230 | + { | ||
| 231 | + String[] values = new String[length]; | ||
| 232 | + for (int i = 0; i < length; i++) | ||
| 233 | + { | ||
| 234 | + values[i] = StringUtils.EMPTY; | ||
| 235 | + } | ||
| 236 | + return values; | ||
| 237 | + } | ||
| 238 | +} |
| 1 | +package com.ruoyi.project.tool.gen.util; | ||
| 2 | + | ||
| 3 | +import java.util.Properties; | ||
| 4 | +import org.apache.velocity.app.Velocity; | ||
| 5 | +import com.ruoyi.common.constant.Constants; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * VelocityEngine工厂 | ||
| 9 | + * | ||
| 10 | + * @author RuoYi | ||
| 11 | + */ | ||
| 12 | +public class VelocityInitializer | ||
| 13 | +{ | ||
| 14 | + /** | ||
| 15 | + * 初始化vm方法 | ||
| 16 | + */ | ||
| 17 | + public static void initVelocity() | ||
| 18 | + { | ||
| 19 | + Properties p = new Properties(); | ||
| 20 | + try | ||
| 21 | + { | ||
| 22 | + // 加载classpath目录下的vm文件 | ||
| 23 | + p.setProperty("file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); | ||
| 24 | + // 定义字符集 | ||
| 25 | + p.setProperty(Velocity.ENCODING_DEFAULT, Constants.UTF8); | ||
| 26 | + p.setProperty(Velocity.OUTPUT_ENCODING, Constants.UTF8); | ||
| 27 | + // 初始化Velocity引擎,指定配置Properties | ||
| 28 | + Velocity.init(p); | ||
| 29 | + } | ||
| 30 | + catch (Exception e) | ||
| 31 | + { | ||
| 32 | + throw new RuntimeException(e); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | +} |
| 1 | +package com.ruoyi.project.tool.gen.util; | ||
| 2 | + | ||
| 3 | +import java.util.ArrayList; | ||
| 4 | +import java.util.HashSet; | ||
| 5 | +import java.util.List; | ||
| 6 | +import org.apache.velocity.VelocityContext; | ||
| 7 | +import com.alibaba.fastjson.JSONObject; | ||
| 8 | +import com.ruoyi.common.constant.GenConstants; | ||
| 9 | +import com.ruoyi.common.utils.DateUtils; | ||
| 10 | +import com.ruoyi.common.utils.StringUtils; | ||
| 11 | +import com.ruoyi.project.tool.gen.domain.GenTable; | ||
| 12 | +import com.ruoyi.project.tool.gen.domain.GenTableColumn; | ||
| 13 | + | ||
| 14 | +public class VelocityUtils | ||
| 15 | +{ | ||
| 16 | + /** 项目空间路径 */ | ||
| 17 | + private static final String PROJECT_PATH = "main/java"; | ||
| 18 | + | ||
| 19 | + /** mybatis空间路径 */ | ||
| 20 | + private static final String MYBATIS_PATH = "main/resources/mybatis"; | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 设置模板变量信息 | ||
| 24 | + * | ||
| 25 | + * @return 模板列表 | ||
| 26 | + */ | ||
| 27 | + public static VelocityContext prepareContext(GenTable genTable) | ||
| 28 | + { | ||
| 29 | + String moduleName = genTable.getModuleName(); | ||
| 30 | + String businessName = genTable.getBusinessName(); | ||
| 31 | + String packageName = genTable.getPackageName(); | ||
| 32 | + String tplCategory = genTable.getTplCategory(); | ||
| 33 | + String functionName = genTable.getFunctionName(); | ||
| 34 | + | ||
| 35 | + VelocityContext velocityContext = new VelocityContext(); | ||
| 36 | + velocityContext.put("tplCategory", genTable.getTplCategory()); | ||
| 37 | + velocityContext.put("tableName", genTable.getTableName()); | ||
| 38 | + velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】"); | ||
| 39 | + velocityContext.put("ClassName", genTable.getClassName()); | ||
| 40 | + velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName())); | ||
| 41 | + velocityContext.put("moduleName", genTable.getModuleName()); | ||
| 42 | + velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName())); | ||
| 43 | + velocityContext.put("businessName", genTable.getBusinessName()); | ||
| 44 | + velocityContext.put("basePackage", getPackagePrefix(packageName)); | ||
| 45 | + velocityContext.put("packageName", packageName); | ||
| 46 | + velocityContext.put("author", genTable.getFunctionAuthor()); | ||
| 47 | + velocityContext.put("datetime", DateUtils.getDate()); | ||
| 48 | + velocityContext.put("pkColumn", genTable.getPkColumn()); | ||
| 49 | + velocityContext.put("importList", getImportList(genTable.getColumns())); | ||
| 50 | + velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); | ||
| 51 | + velocityContext.put("columns", genTable.getColumns()); | ||
| 52 | + velocityContext.put("table", genTable); | ||
| 53 | + if (GenConstants.TPL_TREE.equals(tplCategory)) | ||
| 54 | + { | ||
| 55 | + setTreeVelocityContext(velocityContext, genTable); | ||
| 56 | + } | ||
| 57 | + return velocityContext; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) | ||
| 61 | + { | ||
| 62 | + String options = genTable.getOptions(); | ||
| 63 | + JSONObject paramsObj = JSONObject.parseObject(options); | ||
| 64 | + String treeCode = getTreecode(paramsObj); | ||
| 65 | + String treeParentCode = getTreeParentCode(paramsObj); | ||
| 66 | + String treeName = getTreeName(paramsObj); | ||
| 67 | + | ||
| 68 | + context.put("treeCode", treeCode); | ||
| 69 | + context.put("treeParentCode", treeParentCode); | ||
| 70 | + context.put("treeName", treeName); | ||
| 71 | + context.put("expandColumn", getExpandColumn(genTable)); | ||
| 72 | + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) | ||
| 73 | + { | ||
| 74 | + context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE)); | ||
| 75 | + } | ||
| 76 | + if (paramsObj.containsKey(GenConstants.TREE_NAME)) | ||
| 77 | + { | ||
| 78 | + context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME)); | ||
| 79 | + } | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 获取模板信息 | ||
| 84 | + * | ||
| 85 | + * @return 模板列表 | ||
| 86 | + */ | ||
| 87 | + public static List<String> getTemplateList(String tplCategory) | ||
| 88 | + { | ||
| 89 | + List<String> templates = new ArrayList<String>(); | ||
| 90 | + templates.add("vm/java/domain.java.vm"); | ||
| 91 | + templates.add("vm/java/mapper.java.vm"); | ||
| 92 | + templates.add("vm/java/service.java.vm"); | ||
| 93 | + templates.add("vm/java/serviceImpl.java.vm"); | ||
| 94 | + templates.add("vm/java/controller.java.vm"); | ||
| 95 | + templates.add("vm/xml/mapper.xml.vm"); | ||
| 96 | + templates.add("vm/sql/sql.vm"); | ||
| 97 | + templates.add("vm/js/api.js.vm"); | ||
| 98 | + templates.add("vm/vue/index.vue.vm"); | ||
| 99 | + return templates; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + /** | ||
| 103 | + * 获取文件名 | ||
| 104 | + */ | ||
| 105 | + public static String getFileName(String template, GenTable genTable) | ||
| 106 | + { | ||
| 107 | + // 文件名称 | ||
| 108 | + String fileName = ""; | ||
| 109 | + // 包路径 | ||
| 110 | + String packageName = genTable.getPackageName(); | ||
| 111 | + // 模块名 | ||
| 112 | + String moduleName = genTable.getModuleName(); | ||
| 113 | + // 大写类名 | ||
| 114 | + String className = genTable.getClassName(); | ||
| 115 | + // 业务名称 | ||
| 116 | + String businessName = genTable.getBusinessName(); | ||
| 117 | + | ||
| 118 | + String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/"); | ||
| 119 | + String mybatisPath = MYBATIS_PATH + "/" + moduleName; | ||
| 120 | + String vuePath = "vue"; | ||
| 121 | + | ||
| 122 | + if (template.contains("domain.java.vm")) | ||
| 123 | + { | ||
| 124 | + fileName = StringUtils.format("{}/domain/{}.java", javaPath, className); | ||
| 125 | + } | ||
| 126 | + else if (template.contains("mapper.java.vm")) | ||
| 127 | + { | ||
| 128 | + fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className); | ||
| 129 | + } | ||
| 130 | + else if (template.contains("service.java.vm")) | ||
| 131 | + { | ||
| 132 | + fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className); | ||
| 133 | + } | ||
| 134 | + else if (template.contains("serviceImpl.java.vm")) | ||
| 135 | + { | ||
| 136 | + fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className); | ||
| 137 | + } | ||
| 138 | + else if (template.contains("controller.java.vm")) | ||
| 139 | + { | ||
| 140 | + fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className); | ||
| 141 | + } | ||
| 142 | + else if (template.contains("mapper.xml.vm")) | ||
| 143 | + { | ||
| 144 | + fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className); | ||
| 145 | + } | ||
| 146 | + else if (template.contains("sql.vm")) | ||
| 147 | + { | ||
| 148 | + fileName = businessName + "Menu.sql"; | ||
| 149 | + } | ||
| 150 | + else if (template.contains("js.vm")) | ||
| 151 | + { | ||
| 152 | + fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName); | ||
| 153 | + } | ||
| 154 | + else if (template.contains("vue.vm")) | ||
| 155 | + { | ||
| 156 | + fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName); | ||
| 157 | + } | ||
| 158 | + return fileName; | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + /** | ||
| 162 | + * 获取包前缀 | ||
| 163 | + * | ||
| 164 | + * @param packageName 包名称 | ||
| 165 | + * @return 包前缀名称 | ||
| 166 | + */ | ||
| 167 | + public static String getPackagePrefix(String packageName) | ||
| 168 | + { | ||
| 169 | + int lastIndex = packageName.lastIndexOf("."); | ||
| 170 | + String basePackage = StringUtils.substring(packageName, 0, lastIndex); | ||
| 171 | + return basePackage; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + /** | ||
| 175 | + * 根据列类型获取导入包 | ||
| 176 | + * | ||
| 177 | + * @param column 列集合 | ||
| 178 | + * @return 返回需要导入的包列表 | ||
| 179 | + */ | ||
| 180 | + public static HashSet<String> getImportList(List<GenTableColumn> columns) | ||
| 181 | + { | ||
| 182 | + HashSet<String> importList = new HashSet<String>(); | ||
| 183 | + for (GenTableColumn column : columns) | ||
| 184 | + { | ||
| 185 | + if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) | ||
| 186 | + { | ||
| 187 | + importList.add("java.util.Date"); | ||
| 188 | + } | ||
| 189 | + else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) | ||
| 190 | + { | ||
| 191 | + importList.add("java.math.BigDecimal"); | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + return importList; | ||
| 195 | + } | ||
| 196 | + | ||
| 197 | + /** | ||
| 198 | + * 获取权限前缀 | ||
| 199 | + * | ||
| 200 | + * @param moduleName 模块名称 | ||
| 201 | + * @param businessName 业务名称 | ||
| 202 | + * @return 返回权限前缀 | ||
| 203 | + */ | ||
| 204 | + public static String getPermissionPrefix(String moduleName, String businessName) | ||
| 205 | + { | ||
| 206 | + return StringUtils.format("{}:{}", moduleName, businessName); | ||
| 207 | + | ||
| 208 | + } | ||
| 209 | + | ||
| 210 | + /** | ||
| 211 | + * 获取树编码 | ||
| 212 | + * | ||
| 213 | + * @param options 生成其他选项 | ||
| 214 | + * @return 树编码 | ||
| 215 | + */ | ||
| 216 | + public static String getTreecode(JSONObject paramsObj) | ||
| 217 | + { | ||
| 218 | + if (paramsObj.containsKey(GenConstants.TREE_CODE)) | ||
| 219 | + { | ||
| 220 | + return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); | ||
| 221 | + } | ||
| 222 | + return ""; | ||
| 223 | + } | ||
| 224 | + | ||
| 225 | + /** | ||
| 226 | + * 获取树父编码 | ||
| 227 | + * | ||
| 228 | + * @param options 生成其他选项 | ||
| 229 | + * @return 树父编码 | ||
| 230 | + */ | ||
| 231 | + public static String getTreeParentCode(JSONObject paramsObj) | ||
| 232 | + { | ||
| 233 | + if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) | ||
| 234 | + { | ||
| 235 | + return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); | ||
| 236 | + } | ||
| 237 | + return ""; | ||
| 238 | + } | ||
| 239 | + | ||
| 240 | + /** | ||
| 241 | + * 获取树名称 | ||
| 242 | + * | ||
| 243 | + * @param options 生成其他选项 | ||
| 244 | + * @return 树名称 | ||
| 245 | + */ | ||
| 246 | + public static String getTreeName(JSONObject paramsObj) | ||
| 247 | + { | ||
| 248 | + if (paramsObj.containsKey(GenConstants.TREE_NAME)) | ||
| 249 | + { | ||
| 250 | + return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); | ||
| 251 | + } | ||
| 252 | + return ""; | ||
| 253 | + } | ||
| 254 | + | ||
| 255 | + /** | ||
| 256 | + * 获取需要在哪一列上面显示展开按钮 | ||
| 257 | + * | ||
| 258 | + * @param genTable 业务表对象 | ||
| 259 | + * @return 展开按钮列序号 | ||
| 260 | + */ | ||
| 261 | + public static int getExpandColumn(GenTable genTable) | ||
| 262 | + { | ||
| 263 | + String options = genTable.getOptions(); | ||
| 264 | + JSONObject paramsObj = JSONObject.parseObject(options); | ||
| 265 | + String treeName = paramsObj.getString(GenConstants.TREE_NAME); | ||
| 266 | + int num = 0; | ||
| 267 | + for (GenTableColumn column : genTable.getColumns()) | ||
| 268 | + { | ||
| 269 | + if (column.isList()) | ||
| 270 | + { | ||
| 271 | + num++; | ||
| 272 | + String columnName = column.getColumnName(); | ||
| 273 | + if (columnName.equals(treeName)) | ||
| 274 | + { | ||
| 275 | + break; | ||
| 276 | + } | ||
| 277 | + } | ||
| 278 | + } | ||
| 279 | + return num; | ||
| 280 | + } | ||
| 281 | +} |
| @@ -3,7 +3,7 @@ ruoyi: | @@ -3,7 +3,7 @@ ruoyi: | ||
| 3 | # 名称 | 3 | # 名称 |
| 4 | name: RuoYi | 4 | name: RuoYi |
| 5 | # 版本 | 5 | # 版本 |
| 6 | - version: 1.1.0 | 6 | + version: 2.0.0 |
| 7 | # 版权年份 | 7 | # 版权年份 |
| 8 | copyrightYear: 2019 | 8 | copyrightYear: 2019 |
| 9 | # 实例演示开关 | 9 | # 实例演示开关 |
| @@ -107,3 +107,14 @@ xss: | @@ -107,3 +107,14 @@ xss: | ||
| 107 | excludes: /system/notice/* | 107 | excludes: /system/notice/* |
| 108 | # 匹配链接 | 108 | # 匹配链接 |
| 109 | urlPatterns: /system/*,/monitor/*,/tool/* | 109 | urlPatterns: /system/*,/monitor/*,/tool/* |
| 110 | + | ||
| 111 | +# 代码生成 | ||
| 112 | +gen: | ||
| 113 | + # 作者 | ||
| 114 | + author: ruoyi | ||
| 115 | + # 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool | ||
| 116 | + packageName: com.ruoyi.project.system | ||
| 117 | + # 自动去除表前缀,默认是true | ||
| 118 | + autoRemovePre: false | ||
| 119 | + # 表前缀(生成类名不会包含表前缀,多个用逗号分隔) | ||
| 120 | + tablePrefix: sys_ |
| @@ -33,11 +33,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -33,11 +33,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 33 | <if test="userName != null and userName != ''"> | 33 | <if test="userName != null and userName != ''"> |
| 34 | AND user_name like concat('%', #{userName}, '%') | 34 | AND user_name like concat('%', #{userName}, '%') |
| 35 | </if> | 35 | </if> |
| 36 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | ||
| 37 | - and date_format(login_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | 36 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| 37 | + and date_format(login_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 38 | </if> | 38 | </if> |
| 39 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | ||
| 40 | - and date_format(login_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | 39 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| 40 | + and date_format(login_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 41 | </if> | 41 | </if> |
| 42 | </where> | 42 | </where> |
| 43 | </select> | 43 | </select> |
| @@ -54,11 +54,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -54,11 +54,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 54 | <if test="operName != null and operName != ''"> | 54 | <if test="operName != null and operName != ''"> |
| 55 | AND oper_name like concat('%', #{operName}, '%') | 55 | AND oper_name like concat('%', #{operName}, '%') |
| 56 | </if> | 56 | </if> |
| 57 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | ||
| 58 | - and date_format(oper_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | 57 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| 58 | + and date_format(oper_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 59 | </if> | 59 | </if> |
| 60 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | ||
| 61 | - and date_format(oper_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | 60 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| 61 | + and date_format(oper_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 62 | </if> | 62 | </if> |
| 63 | </where> | 63 | </where> |
| 64 | </select> | 64 | </select> |
| @@ -50,11 +50,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -50,11 +50,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 50 | <if test="configKey != null and configKey != ''"> | 50 | <if test="configKey != null and configKey != ''"> |
| 51 | AND config_key like concat('%', #{configKey}, '%') | 51 | AND config_key like concat('%', #{configKey}, '%') |
| 52 | </if> | 52 | </if> |
| 53 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | ||
| 54 | - and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | 53 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| 54 | + and date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 55 | </if> | 55 | </if> |
| 56 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | ||
| 57 | - and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | 56 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| 57 | + and date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 58 | </if> | 58 | </if> |
| 59 | </where> | 59 | </where> |
| 60 | </select> | 60 | </select> |
| @@ -32,11 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -32,11 +32,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 32 | <if test="dictType != null and dictType != ''"> | 32 | <if test="dictType != null and dictType != ''"> |
| 33 | AND dict_type like concat('%', #{dictType}, '%') | 33 | AND dict_type like concat('%', #{dictType}, '%') |
| 34 | </if> | 34 | </if> |
| 35 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | ||
| 36 | - and date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | 35 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| 36 | + and date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 37 | </if> | 37 | </if> |
| 38 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | ||
| 39 | - and date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | 38 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| 39 | + and date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 40 | </if> | 40 | </if> |
| 41 | </where> | 41 | </where> |
| 42 | </select> | 42 | </select> |
| @@ -40,11 +40,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -40,11 +40,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 40 | <if test="roleKey != null and roleKey != ''"> | 40 | <if test="roleKey != null and roleKey != ''"> |
| 41 | AND r.role_key like concat('%', #{roleKey}, '%') | 41 | AND r.role_key like concat('%', #{roleKey}, '%') |
| 42 | </if> | 42 | </if> |
| 43 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | ||
| 44 | - and date_format(r.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | 43 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| 44 | + and date_format(r.create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 45 | </if> | 45 | </if> |
| 46 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | ||
| 47 | - and date_format(r.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | 46 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| 47 | + and date_format(r.create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 48 | </if> | 48 | </if> |
| 49 | <!-- 数据范围过滤 --> | 49 | <!-- 数据范围过滤 --> |
| 50 | ${dataScope} | 50 | ${dataScope} |
| @@ -67,11 +67,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | @@ -67,11 +67,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 67 | <if test="phonenumber != null and phonenumber != ''"> | 67 | <if test="phonenumber != null and phonenumber != ''"> |
| 68 | AND u.phonenumber like concat('%', #{phonenumber}, '%') | 68 | AND u.phonenumber like concat('%', #{phonenumber}, '%') |
| 69 | </if> | 69 | </if> |
| 70 | - <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | ||
| 71 | - AND date_format(u.create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d') | 70 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> |
| 71 | + AND date_format(u.create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 72 | </if> | 72 | </if> |
| 73 | - <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | ||
| 74 | - AND date_format(u.create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d') | 73 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> |
| 74 | + AND date_format(u.create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 75 | </if> | 75 | </if> |
| 76 | <if test="deptId != null and deptId != 0"> | 76 | <if test="deptId != null and deptId != 0"> |
| 77 | AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) )) | 77 | AND (u.dept_id = #{deptId} OR u.dept_id IN ( SELECT t.dept_id FROM sys_dept t WHERE FIND_IN_SET (#{deptId},ancestors) )) |
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper"> | ||
| 6 | + | ||
| 7 | + <resultMap type="GenTableColumn" id="GenTableColumnResult"> | ||
| 8 | + <id property="columnId" column="column_id" /> | ||
| 9 | + <result property="tableId" column="table_id" /> | ||
| 10 | + <result property="columnName" column="column_name" /> | ||
| 11 | + <result property="columnComment" column="column_comment" /> | ||
| 12 | + <result property="columnType" column="column_type" /> | ||
| 13 | + <result property="javaType" column="java_type" /> | ||
| 14 | + <result property="javaField" column="java_field" /> | ||
| 15 | + <result property="isPk" column="is_pk" /> | ||
| 16 | + <result property="isIncrement" column="is_increment" /> | ||
| 17 | + <result property="isRequired" column="is_required" /> | ||
| 18 | + <result property="isInsert" column="is_insert" /> | ||
| 19 | + <result property="isEdit" column="is_edit" /> | ||
| 20 | + <result property="isList" column="is_list" /> | ||
| 21 | + <result property="isQuery" column="is_query" /> | ||
| 22 | + <result property="queryType" column="query_type" /> | ||
| 23 | + <result property="htmlType" column="html_type" /> | ||
| 24 | + <result property="dictType" column="dict_type" /> | ||
| 25 | + <result property="sort" column="sort" /> | ||
| 26 | + <result property="createBy" column="create_by" /> | ||
| 27 | + <result property="createTime" column="create_time" /> | ||
| 28 | + <result property="updateBy" column="update_by" /> | ||
| 29 | + <result property="updateTime" column="update_time" /> | ||
| 30 | + </resultMap> | ||
| 31 | + | ||
| 32 | + <sql id="selectGenTableColumnVo"> | ||
| 33 | + select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column | ||
| 34 | + </sql> | ||
| 35 | + | ||
| 36 | + <select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult"> | ||
| 37 | + <include refid="selectGenTableColumnVo"/> | ||
| 38 | + where table_id = #{tableId} | ||
| 39 | + order by sort | ||
| 40 | + </select> | ||
| 41 | + | ||
| 42 | + <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> | ||
| 43 | + select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type | ||
| 44 | + from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) | ||
| 45 | + order by ordinal_position | ||
| 46 | + </select> | ||
| 47 | + | ||
| 48 | + <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> | ||
| 49 | + insert into gen_table_column ( | ||
| 50 | + <if test="tableId != null and tableId != ''">table_id,</if> | ||
| 51 | + <if test="columnName != null and columnName != ''">column_name,</if> | ||
| 52 | + <if test="columnComment != null and columnComment != ''">column_comment,</if> | ||
| 53 | + <if test="columnType != null and columnType != ''">column_type,</if> | ||
| 54 | + <if test="javaType != null and javaType != ''">java_type,</if> | ||
| 55 | + <if test="javaField != null and javaField != ''">java_field,</if> | ||
| 56 | + <if test="isPk != null and isPk != ''">is_pk,</if> | ||
| 57 | + <if test="isIncrement != null and isIncrement != ''">is_increment,</if> | ||
| 58 | + <if test="isRequired != null and isRequired != ''">is_required,</if> | ||
| 59 | + <if test="isInsert != null and isInsert != ''">is_insert,</if> | ||
| 60 | + <if test="isEdit != null and isEdit != ''">is_edit,</if> | ||
| 61 | + <if test="isList != null and isList != ''">is_list,</if> | ||
| 62 | + <if test="isQuery != null and isQuery != ''">is_query,</if> | ||
| 63 | + <if test="queryType != null and queryType != ''">query_type,</if> | ||
| 64 | + <if test="htmlType != null and htmlType != ''">html_type,</if> | ||
| 65 | + <if test="dictType != null and dictType != ''">dict_type,</if> | ||
| 66 | + <if test="sort != null">sort,</if> | ||
| 67 | + <if test="createBy != null and createBy != ''">create_by,</if> | ||
| 68 | + create_time | ||
| 69 | + )values( | ||
| 70 | + <if test="tableId != null and tableId != ''">#{tableId},</if> | ||
| 71 | + <if test="columnName != null and columnName != ''">#{columnName},</if> | ||
| 72 | + <if test="columnComment != null and columnComment != ''">#{columnComment},</if> | ||
| 73 | + <if test="columnType != null and columnType != ''">#{columnType},</if> | ||
| 74 | + <if test="javaType != null and javaType != ''">#{javaType},</if> | ||
| 75 | + <if test="javaField != null and javaField != ''">#{javaField},</if> | ||
| 76 | + <if test="isPk != null and isPk != ''">#{isPk},</if> | ||
| 77 | + <if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if> | ||
| 78 | + <if test="isRequired != null and isRequired != ''">#{isRequired},</if> | ||
| 79 | + <if test="isInsert != null and isInsert != ''">#{isInsert},</if> | ||
| 80 | + <if test="isEdit != null and isEdit != ''">#{isEdit},</if> | ||
| 81 | + <if test="isList != null and isList != ''">#{isList},</if> | ||
| 82 | + <if test="isQuery != null and isQuery != ''">#{isQuery},</if> | ||
| 83 | + <if test="queryType != null and queryType != ''">#{queryType},</if> | ||
| 84 | + <if test="htmlType != null and htmlType != ''">#{htmlType},</if> | ||
| 85 | + <if test="dictType != null and dictType != ''">#{dictType},</if> | ||
| 86 | + <if test="sort != null">#{sort},</if> | ||
| 87 | + <if test="createBy != null and createBy != ''">#{createBy},</if> | ||
| 88 | + sysdate() | ||
| 89 | + ) | ||
| 90 | + </insert> | ||
| 91 | + | ||
| 92 | + <update id="updateGenTableColumn" parameterType="GenTableColumn"> | ||
| 93 | + update gen_table_column | ||
| 94 | + <set> | ||
| 95 | + column_comment = #{columnComment}, | ||
| 96 | + java_type = #{javaType}, | ||
| 97 | + java_field = #{javaField}, | ||
| 98 | + is_insert = #{isInsert}, | ||
| 99 | + is_edit = #{isEdit}, | ||
| 100 | + is_list = #{isList}, | ||
| 101 | + is_query = #{isQuery}, | ||
| 102 | + is_required = #{isRequired}, | ||
| 103 | + query_type = #{queryType}, | ||
| 104 | + html_type = #{htmlType}, | ||
| 105 | + dict_type = #{dictType}, | ||
| 106 | + sort = #{sort}, | ||
| 107 | + update_by = #{updateBy}, | ||
| 108 | + update_time = sysdate() | ||
| 109 | + </set> | ||
| 110 | + where column_id = #{columnId} | ||
| 111 | + </update> | ||
| 112 | + | ||
| 113 | + <delete id="deleteGenTableColumnByIds" parameterType="Long"> | ||
| 114 | + delete from gen_table_column where table_id in | ||
| 115 | + <foreach collection="array" item="tableId" open="(" separator="," close=")"> | ||
| 116 | + #{tableId} | ||
| 117 | + </foreach> | ||
| 118 | + </delete> | ||
| 119 | + | ||
| 120 | +</mapper> |
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="com.ruoyi.project.tool.gen.mapper.GenTableMapper"> | ||
| 6 | + | ||
| 7 | + <resultMap type="GenTable" id="GenTableResult"> | ||
| 8 | + <id property="tableId" column="table_id" /> | ||
| 9 | + <result property="tableName" column="table_name" /> | ||
| 10 | + <result property="tableComment" column="table_comment" /> | ||
| 11 | + <result property="className" column="class_name" /> | ||
| 12 | + <result property="tplCategory" column="tpl_category" /> | ||
| 13 | + <result property="packageName" column="package_name" /> | ||
| 14 | + <result property="moduleName" column="module_name" /> | ||
| 15 | + <result property="businessName" column="business_name" /> | ||
| 16 | + <result property="functionName" column="function_name" /> | ||
| 17 | + <result property="functionAuthor" column="function_author" /> | ||
| 18 | + <result property="options" column="options" /> | ||
| 19 | + <result property="createBy" column="create_by" /> | ||
| 20 | + <result property="createTime" column="create_time" /> | ||
| 21 | + <result property="updateBy" column="update_by" /> | ||
| 22 | + <result property="updateTime" column="update_time" /> | ||
| 23 | + <result property="remark" column="remark" /> | ||
| 24 | + <collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" /> | ||
| 25 | + </resultMap> | ||
| 26 | + | ||
| 27 | + <resultMap type="GenTableColumn" id="GenTableColumnResult"> | ||
| 28 | + <id property="columnId" column="column_id" /> | ||
| 29 | + <result property="tableId" column="table_id" /> | ||
| 30 | + <result property="columnName" column="column_name" /> | ||
| 31 | + <result property="columnComment" column="column_comment" /> | ||
| 32 | + <result property="columnType" column="column_type" /> | ||
| 33 | + <result property="javaType" column="java_type" /> | ||
| 34 | + <result property="javaField" column="java_field" /> | ||
| 35 | + <result property="isPk" column="is_pk" /> | ||
| 36 | + <result property="isIncrement" column="is_increment" /> | ||
| 37 | + <result property="isRequired" column="is_required" /> | ||
| 38 | + <result property="isInsert" column="is_insert" /> | ||
| 39 | + <result property="isEdit" column="is_edit" /> | ||
| 40 | + <result property="isList" column="is_list" /> | ||
| 41 | + <result property="isQuery" column="is_query" /> | ||
| 42 | + <result property="queryType" column="query_type" /> | ||
| 43 | + <result property="htmlType" column="html_type" /> | ||
| 44 | + <result property="dictType" column="dict_type" /> | ||
| 45 | + <result property="sort" column="sort" /> | ||
| 46 | + <result property="createBy" column="create_by" /> | ||
| 47 | + <result property="createTime" column="create_time" /> | ||
| 48 | + <result property="updateBy" column="update_by" /> | ||
| 49 | + <result property="updateTime" column="update_time" /> | ||
| 50 | + </resultMap> | ||
| 51 | + | ||
| 52 | + <sql id="selectGenTableVo"> | ||
| 53 | + select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, options, create_by, create_time, update_by, update_time, remark from gen_table | ||
| 54 | + </sql> | ||
| 55 | + | ||
| 56 | + <select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult"> | ||
| 57 | + <include refid="selectGenTableVo"/> | ||
| 58 | + <where> | ||
| 59 | + <if test="tableName != null and tableName != ''"> | ||
| 60 | + AND lower(table_name) like lower(concat('%', #{tableName}, '%')) | ||
| 61 | + </if> | ||
| 62 | + <if test="tableComment != null and tableComment != ''"> | ||
| 63 | + AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) | ||
| 64 | + </if> | ||
| 65 | +<!-- <if test="beginTime != null and beginTime != ''">开始时间检索 --> | ||
| 66 | +<!-- AND date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') --> | ||
| 67 | +<!-- </if> --> | ||
| 68 | +<!-- <if test="endTime != null and endTime != ''">结束时间检索 --> | ||
| 69 | +<!-- AND date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') --> | ||
| 70 | +<!-- </if> --> | ||
| 71 | + </where> | ||
| 72 | + </select> | ||
| 73 | + | ||
| 74 | + <select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> | ||
| 75 | + select table_name, table_comment, create_time, update_time from information_schema.tables | ||
| 76 | + where table_schema = (select database()) | ||
| 77 | + AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' | ||
| 78 | + AND table_name NOT IN (select table_name from gen_table) | ||
| 79 | + <if test="tableName != null and tableName != ''"> | ||
| 80 | + AND lower(table_name) like lower(concat('%', #{tableName}, '%')) | ||
| 81 | + </if> | ||
| 82 | + <if test="tableComment != null and tableComment != ''"> | ||
| 83 | + AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) | ||
| 84 | + </if> | ||
| 85 | + <if test="beginTime != null and beginTime != ''"><!-- 开始时间检索 --> | ||
| 86 | + AND date_format(create_time,'%y%m%d') >= date_format(#{beginTime},'%y%m%d') | ||
| 87 | + </if> | ||
| 88 | + <if test="endTime != null and endTime != ''"><!-- 结束时间检索 --> | ||
| 89 | + AND date_format(create_time,'%y%m%d') <= date_format(#{endTime},'%y%m%d') | ||
| 90 | + </if> | ||
| 91 | + </select> | ||
| 92 | + | ||
| 93 | + <select id="selectDbTableListByNames" resultMap="GenTableResult"> | ||
| 94 | + select table_name, table_comment, create_time, update_time from information_schema.tables | ||
| 95 | + where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database()) | ||
| 96 | + and table_name in | ||
| 97 | + <foreach collection="array" item="name" open="(" separator="," close=")"> | ||
| 98 | + #{name} | ||
| 99 | + </foreach> | ||
| 100 | + </select> | ||
| 101 | + | ||
| 102 | + <select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> | ||
| 103 | + select table_name, table_comment, create_time, update_time from information_schema.tables | ||
| 104 | + where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database()) | ||
| 105 | + and table_name = #{tableName} | ||
| 106 | + </select> | ||
| 107 | + | ||
| 108 | + <select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult"> | ||
| 109 | + SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, | ||
| 110 | + c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | ||
| 111 | + FROM gen_table t | ||
| 112 | + LEFT JOIN gen_table_column c ON t.table_id = c.table_id | ||
| 113 | + where t.table_id = #{tableId} | ||
| 114 | + </select> | ||
| 115 | + | ||
| 116 | + <select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult"> | ||
| 117 | + SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.options, t.remark, | ||
| 118 | + c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort | ||
| 119 | + FROM gen_table t | ||
| 120 | + LEFT JOIN gen_table_column c ON t.table_id = c.table_id | ||
| 121 | + where t.table_name = #{tableName} | ||
| 122 | + </select> | ||
| 123 | + | ||
| 124 | + <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> | ||
| 125 | + insert into gen_table ( | ||
| 126 | + <if test="tableName != null">table_name,</if> | ||
| 127 | + <if test="tableComment != null and tableComment != ''">table_comment,</if> | ||
| 128 | + <if test="className != null and className != ''">class_name,</if> | ||
| 129 | + <if test="tplCategory != null and tplCategory != ''">tpl_category,</if> | ||
| 130 | + <if test="packageName != null and packageName != ''">package_name,</if> | ||
| 131 | + <if test="moduleName != null and moduleName != ''">module_name,</if> | ||
| 132 | + <if test="businessName != null and businessName != ''">business_name,</if> | ||
| 133 | + <if test="functionName != null and functionName != ''">function_name,</if> | ||
| 134 | + <if test="functionAuthor != null and functionAuthor != ''">function_author,</if> | ||
| 135 | + <if test="remark != null and remark != ''">remark,</if> | ||
| 136 | + <if test="createBy != null and createBy != ''">create_by,</if> | ||
| 137 | + create_time | ||
| 138 | + )values( | ||
| 139 | + <if test="tableName != null">#{tableName},</if> | ||
| 140 | + <if test="tableComment != null and tableComment != ''">#{tableComment},</if> | ||
| 141 | + <if test="className != null and className != ''">#{className},</if> | ||
| 142 | + <if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if> | ||
| 143 | + <if test="packageName != null and packageName != ''">#{packageName},</if> | ||
| 144 | + <if test="moduleName != null and moduleName != ''">#{moduleName},</if> | ||
| 145 | + <if test="businessName != null and businessName != ''">#{businessName},</if> | ||
| 146 | + <if test="functionName != null and functionName != ''">#{functionName},</if> | ||
| 147 | + <if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if> | ||
| 148 | + <if test="remark != null and remark != ''">#{remark},</if> | ||
| 149 | + <if test="createBy != null and createBy != ''">#{createBy},</if> | ||
| 150 | + sysdate() | ||
| 151 | + ) | ||
| 152 | + </insert> | ||
| 153 | + | ||
| 154 | + <update id="updateGenTable" parameterType="GenTable"> | ||
| 155 | + update gen_table | ||
| 156 | + <set> | ||
| 157 | + <if test="tableName != null">table_name = #{tableName},</if> | ||
| 158 | + <if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if> | ||
| 159 | + <if test="className != null and className != ''">class_name = #{className},</if> | ||
| 160 | + <if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if> | ||
| 161 | + <if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if> | ||
| 162 | + <if test="packageName != null and packageName != ''">package_name = #{packageName},</if> | ||
| 163 | + <if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if> | ||
| 164 | + <if test="businessName != null and businessName != ''">business_name = #{businessName},</if> | ||
| 165 | + <if test="functionName != null and functionName != ''">function_name = #{functionName},</if> | ||
| 166 | + <if test="options != null and options != ''">options = #{options},</if> | ||
| 167 | + <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> | ||
| 168 | + <if test="remark != null">remark = #{remark},</if> | ||
| 169 | + update_time = sysdate() | ||
| 170 | + </set> | ||
| 171 | + where table_id = #{tableId} | ||
| 172 | + </update> | ||
| 173 | + | ||
| 174 | + <delete id="deleteGenTableByIds" parameterType="Long"> | ||
| 175 | + delete from gen_table where table_id in | ||
| 176 | + <foreach collection="array" item="tableId" open="(" separator="," close=")"> | ||
| 177 | + #{tableId} | ||
| 178 | + </foreach> | ||
| 179 | + </delete> | ||
| 180 | + | ||
| 181 | +</mapper> |
| 1 | +package ${packageName}.controller; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +import org.springframework.security.access.prepost.PreAuthorize; | ||
| 5 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 6 | +import org.springframework.web.bind.annotation.GetMapping; | ||
| 7 | +import org.springframework.web.bind.annotation.PostMapping; | ||
| 8 | +import org.springframework.web.bind.annotation.PutMapping; | ||
| 9 | +import org.springframework.web.bind.annotation.DeleteMapping; | ||
| 10 | +import org.springframework.web.bind.annotation.PathVariable; | ||
| 11 | +import org.springframework.web.bind.annotation.RequestBody; | ||
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; | ||
| 13 | +import org.springframework.web.bind.annotation.RestController; | ||
| 14 | +import com.ruoyi.framework.aspectj.lang.annotation.Log; | ||
| 15 | +import com.ruoyi.framework.aspectj.lang.enums.BusinessType; | ||
| 16 | +import ${packageName}.domain.${ClassName}; | ||
| 17 | +import ${packageName}.service.I${ClassName}Service; | ||
| 18 | +import com.ruoyi.framework.web.controller.BaseController; | ||
| 19 | +import com.ruoyi.framework.web.domain.AjaxResult; | ||
| 20 | +import com.ruoyi.common.utils.poi.ExcelUtil; | ||
| 21 | +import com.ruoyi.framework.web.page.TableDataInfo; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * ${functionName}Controller | ||
| 25 | + * | ||
| 26 | + * @author ${author} | ||
| 27 | + * @date ${datetime} | ||
| 28 | + */ | ||
| 29 | +@RestController | ||
| 30 | +@RequestMapping("/${moduleName}/${businessName}") | ||
| 31 | +public class ${ClassName}Controller extends BaseController | ||
| 32 | +{ | ||
| 33 | + @Autowired | ||
| 34 | + private I${ClassName}Service ${className}Service; | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 查询${functionName}列表 | ||
| 38 | + */ | ||
| 39 | + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:list')") | ||
| 40 | + @GetMapping("/list") | ||
| 41 | + public TableDataInfo list(${ClassName} ${className}) | ||
| 42 | + { | ||
| 43 | + startPage(); | ||
| 44 | + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); | ||
| 45 | + return getDataTable(list); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 导出${functionName}列表 | ||
| 50 | + */ | ||
| 51 | + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:export')") | ||
| 52 | + @Log(title = "${functionName}", businessType = BusinessType.EXPORT) | ||
| 53 | + @GetMapping("/export") | ||
| 54 | + public AjaxResult export(${ClassName} ${className}) | ||
| 55 | + { | ||
| 56 | + List<${ClassName}> list = ${className}Service.select${ClassName}List(${className}); | ||
| 57 | + ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class); | ||
| 58 | + return util.exportExcel(list, "${businessName}"); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * 获取${functionName}详细信息 | ||
| 63 | + */ | ||
| 64 | + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:query')") | ||
| 65 | + @GetMapping(value = "/{${pkColumn.javaField}}") | ||
| 66 | + public AjaxResult getInfo(@PathVariable("${pkColumn.javaField}") ${pkColumn.javaType} ${pkColumn.javaField}) | ||
| 67 | + { | ||
| 68 | + return AjaxResult.success(${className}Service.select${ClassName}ById(${pkColumn.javaField})); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 新增${functionName} | ||
| 73 | + */ | ||
| 74 | + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:add')") | ||
| 75 | + @Log(title = "${functionName}", businessType = BusinessType.INSERT) | ||
| 76 | + @PostMapping | ||
| 77 | + public AjaxResult add(@RequestBody ${ClassName} ${className}) | ||
| 78 | + { | ||
| 79 | + return toAjax(${className}Service.insert${ClassName}(${className})); | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 修改${functionName} | ||
| 84 | + */ | ||
| 85 | + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:edit')") | ||
| 86 | + @Log(title = "${functionName}", businessType = BusinessType.UPDATE) | ||
| 87 | + @PutMapping | ||
| 88 | + public AjaxResult edit(@RequestBody ${ClassName} ${className}) | ||
| 89 | + { | ||
| 90 | + return toAjax(${className}Service.update${ClassName}(${className})); | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * 删除${functionName} | ||
| 95 | + */ | ||
| 96 | + @PreAuthorize("@ss.hasPermi('${permissionPrefix}:remove')") | ||
| 97 | + @Log(title = "${functionName}", businessType = BusinessType.DELETE) | ||
| 98 | + @DeleteMapping("/{${pkColumn.javaField}s}") | ||
| 99 | + public AjaxResult remove(@PathVariable ${pkColumn.javaType}[] ${pkColumn.javaField}s) | ||
| 100 | + { | ||
| 101 | + return toAjax(${className}Service.delete${ClassName}ByIds(${pkColumn.javaField}s)); | ||
| 102 | + } | ||
| 103 | +} |
| 1 | +package ${packageName}.domain; | ||
| 2 | + | ||
| 3 | +import org.apache.commons.lang3.builder.ToStringBuilder; | ||
| 4 | +import org.apache.commons.lang3.builder.ToStringStyle; | ||
| 5 | +import com.ruoyi.framework.aspectj.lang.annotation.Excel; | ||
| 6 | +import com.ruoyi.framework.web.domain.BaseEntity; | ||
| 7 | +#foreach ($import in $importList) | ||
| 8 | +import ${import}; | ||
| 9 | +#end | ||
| 10 | + | ||
| 11 | +/** | ||
| 12 | + * ${functionName}对象 ${tableName} | ||
| 13 | + * | ||
| 14 | + * @author ${author} | ||
| 15 | + * @date ${datetime} | ||
| 16 | + */ | ||
| 17 | +#set($Entity="BaseEntity") | ||
| 18 | +public class ${ClassName} extends ${Entity} | ||
| 19 | +{ | ||
| 20 | + private static final long serialVersionUID = 1L; | ||
| 21 | + | ||
| 22 | +#foreach ($column in $columns) | ||
| 23 | +#if(!$table.isSuperColumn($column.javaField)) | ||
| 24 | + /** $column.columnComment */ | ||
| 25 | +#if($column.list) | ||
| 26 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 27 | +#if($parentheseIndex != -1) | ||
| 28 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 29 | +#else | ||
| 30 | +#set($comment=$column.columnComment) | ||
| 31 | +#end | ||
| 32 | +#if($parentheseIndex != -1) | ||
| 33 | + @Excel(name = "${comment}", readConverterExp = "$column.readConverterExp()") | ||
| 34 | +#elseif($column.javaType == 'Date') | ||
| 35 | + @Excel(name = "${comment}", width = 30, dateFormat = "yyyy-MM-dd") | ||
| 36 | +#else | ||
| 37 | + @Excel(name = "${comment}") | ||
| 38 | +#end | ||
| 39 | +#end | ||
| 40 | + private $column.javaType $column.javaField; | ||
| 41 | + | ||
| 42 | +#end | ||
| 43 | +#end | ||
| 44 | +#foreach ($column in $columns) | ||
| 45 | +#if(!$table.isSuperColumn($column.javaField)) | ||
| 46 | +#if($column.javaField.substring(1,2).matches("[A-Z]")) | ||
| 47 | +#set($AttrName=$column.javaField) | ||
| 48 | +#else | ||
| 49 | +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | ||
| 50 | +#end | ||
| 51 | + public void set${AttrName}($column.javaType $column.javaField) | ||
| 52 | + { | ||
| 53 | + this.$column.javaField = $column.javaField; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + public $column.javaType get${AttrName}() | ||
| 57 | + { | ||
| 58 | + return $column.javaField; | ||
| 59 | + } | ||
| 60 | +#end | ||
| 61 | +#end | ||
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public String toString() { | ||
| 65 | + return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) | ||
| 66 | +#foreach ($column in $columns) | ||
| 67 | +#if($column.javaField.substring(1,2).matches("[A-Z]")) | ||
| 68 | +#set($AttrName=$column.javaField) | ||
| 69 | +#else | ||
| 70 | +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | ||
| 71 | +#end | ||
| 72 | + .append("${column.javaField}", get${AttrName}()) | ||
| 73 | +#end | ||
| 74 | + .toString(); | ||
| 75 | + } | ||
| 76 | +} |
| 1 | +package ${packageName}.mapper; | ||
| 2 | + | ||
| 3 | +import ${packageName}.domain.${ClassName}; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * ${functionName}Mapper接口 | ||
| 8 | + * | ||
| 9 | + * @author ${author} | ||
| 10 | + * @date ${datetime} | ||
| 11 | + */ | ||
| 12 | +public interface ${ClassName}Mapper | ||
| 13 | +{ | ||
| 14 | + /** | ||
| 15 | + * 查询${functionName} | ||
| 16 | + * | ||
| 17 | + * @param ${pkColumn.javaField} ${functionName}ID | ||
| 18 | + * @return ${functionName} | ||
| 19 | + */ | ||
| 20 | + public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 查询${functionName}列表 | ||
| 24 | + * | ||
| 25 | + * @param ${className} ${functionName} | ||
| 26 | + * @return ${functionName}集合 | ||
| 27 | + */ | ||
| 28 | + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 新增${functionName} | ||
| 32 | + * | ||
| 33 | + * @param ${className} ${functionName} | ||
| 34 | + * @return 结果 | ||
| 35 | + */ | ||
| 36 | + public int insert${ClassName}(${ClassName} ${className}); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 修改${functionName} | ||
| 40 | + * | ||
| 41 | + * @param ${className} ${functionName} | ||
| 42 | + * @return 结果 | ||
| 43 | + */ | ||
| 44 | + public int update${ClassName}(${ClassName} ${className}); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 删除${functionName} | ||
| 48 | + * | ||
| 49 | + * @param ${pkColumn.javaField} ${functionName}ID | ||
| 50 | + * @return 结果 | ||
| 51 | + */ | ||
| 52 | + public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 批量删除${functionName} | ||
| 56 | + * | ||
| 57 | + * @param ${pkColumn.javaField}s 需要删除的数据ID | ||
| 58 | + * @return 结果 | ||
| 59 | + */ | ||
| 60 | + public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); | ||
| 61 | +} |
| 1 | +package ${packageName}.service; | ||
| 2 | + | ||
| 3 | +import ${packageName}.domain.${ClassName}; | ||
| 4 | +import java.util.List; | ||
| 5 | + | ||
| 6 | +/** | ||
| 7 | + * ${functionName}Service接口 | ||
| 8 | + * | ||
| 9 | + * @author ${author} | ||
| 10 | + * @date ${datetime} | ||
| 11 | + */ | ||
| 12 | +public interface I${ClassName}Service | ||
| 13 | +{ | ||
| 14 | + /** | ||
| 15 | + * 查询${functionName} | ||
| 16 | + * | ||
| 17 | + * @param ${pkColumn.javaField} ${functionName}ID | ||
| 18 | + * @return ${functionName} | ||
| 19 | + */ | ||
| 20 | + public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * 查询${functionName}列表 | ||
| 24 | + * | ||
| 25 | + * @param ${className} ${functionName} | ||
| 26 | + * @return ${functionName}集合 | ||
| 27 | + */ | ||
| 28 | + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}); | ||
| 29 | + | ||
| 30 | + /** | ||
| 31 | + * 新增${functionName} | ||
| 32 | + * | ||
| 33 | + * @param ${className} ${functionName} | ||
| 34 | + * @return 结果 | ||
| 35 | + */ | ||
| 36 | + public int insert${ClassName}(${ClassName} ${className}); | ||
| 37 | + | ||
| 38 | + /** | ||
| 39 | + * 修改${functionName} | ||
| 40 | + * | ||
| 41 | + * @param ${className} ${functionName} | ||
| 42 | + * @return 结果 | ||
| 43 | + */ | ||
| 44 | + public int update${ClassName}(${ClassName} ${className}); | ||
| 45 | + | ||
| 46 | + /** | ||
| 47 | + * 批量删除${functionName} | ||
| 48 | + * | ||
| 49 | + * @param ${pkColumn.javaField}s 需要删除的${functionName}ID | ||
| 50 | + * @return 结果 | ||
| 51 | + */ | ||
| 52 | + public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s); | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 删除${functionName}信息 | ||
| 56 | + * | ||
| 57 | + * @param ${pkColumn.javaField} ${functionName}ID | ||
| 58 | + * @return 结果 | ||
| 59 | + */ | ||
| 60 | + public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}); | ||
| 61 | +} |
| 1 | +package ${packageName}.service.impl; | ||
| 2 | + | ||
| 3 | +import java.util.List; | ||
| 4 | +#foreach ($column in $columns) | ||
| 5 | +#if($column.javaField == 'createTime' || $column.javaField == 'updateTime') | ||
| 6 | +import com.ruoyi.common.utils.DateUtils; | ||
| 7 | +#break | ||
| 8 | +#end | ||
| 9 | +#end | ||
| 10 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 11 | +import org.springframework.stereotype.Service; | ||
| 12 | +import ${packageName}.mapper.${ClassName}Mapper; | ||
| 13 | +import ${packageName}.domain.${ClassName}; | ||
| 14 | +import ${packageName}.service.I${ClassName}Service; | ||
| 15 | + | ||
| 16 | +/** | ||
| 17 | + * ${functionName}Service业务层处理 | ||
| 18 | + * | ||
| 19 | + * @author ${author} | ||
| 20 | + * @date ${datetime} | ||
| 21 | + */ | ||
| 22 | +@Service | ||
| 23 | +public class ${ClassName}ServiceImpl implements I${ClassName}Service | ||
| 24 | +{ | ||
| 25 | + @Autowired | ||
| 26 | + private ${ClassName}Mapper ${className}Mapper; | ||
| 27 | + | ||
| 28 | + /** | ||
| 29 | + * 查询${functionName} | ||
| 30 | + * | ||
| 31 | + * @param ${pkColumn.javaField} ${functionName}ID | ||
| 32 | + * @return ${functionName} | ||
| 33 | + */ | ||
| 34 | + @Override | ||
| 35 | + public ${ClassName} select${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) | ||
| 36 | + { | ||
| 37 | + return ${className}Mapper.select${ClassName}ById(${pkColumn.javaField}); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 查询${functionName}列表 | ||
| 42 | + * | ||
| 43 | + * @param ${className} ${functionName} | ||
| 44 | + * @return ${functionName} | ||
| 45 | + */ | ||
| 46 | + @Override | ||
| 47 | + public List<${ClassName}> select${ClassName}List(${ClassName} ${className}) | ||
| 48 | + { | ||
| 49 | + return ${className}Mapper.select${ClassName}List(${className}); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + /** | ||
| 53 | + * 新增${functionName} | ||
| 54 | + * | ||
| 55 | + * @param ${className} ${functionName} | ||
| 56 | + * @return 结果 | ||
| 57 | + */ | ||
| 58 | + @Override | ||
| 59 | + public int insert${ClassName}(${ClassName} ${className}) | ||
| 60 | + { | ||
| 61 | +#foreach ($column in $columns) | ||
| 62 | +#if($column.javaField == 'createTime') | ||
| 63 | + ${className}.setCreateTime(DateUtils.getNowDate()); | ||
| 64 | +#end | ||
| 65 | +#end | ||
| 66 | + return ${className}Mapper.insert${ClassName}(${className}); | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + /** | ||
| 70 | + * 修改${functionName} | ||
| 71 | + * | ||
| 72 | + * @param ${className} ${functionName} | ||
| 73 | + * @return 结果 | ||
| 74 | + */ | ||
| 75 | + @Override | ||
| 76 | + public int update${ClassName}(${ClassName} ${className}) | ||
| 77 | + { | ||
| 78 | +#foreach ($column in $columns) | ||
| 79 | +#if($column.javaField == 'updateTime') | ||
| 80 | + ${className}.setUpdateTime(DateUtils.getNowDate()); | ||
| 81 | +#end | ||
| 82 | +#end | ||
| 83 | + return ${className}Mapper.update${ClassName}(${className}); | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + /** | ||
| 87 | + * 批量删除${functionName} | ||
| 88 | + * | ||
| 89 | + * @param ${pkColumn.javaField}s 需要删除的${functionName}ID | ||
| 90 | + * @return 结果 | ||
| 91 | + */ | ||
| 92 | + @Override | ||
| 93 | + public int delete${ClassName}ByIds(${pkColumn.javaType}[] ${pkColumn.javaField}s) | ||
| 94 | + { | ||
| 95 | + return ${className}Mapper.delete${ClassName}ByIds(${pkColumn.javaField}s); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * 删除${functionName}信息 | ||
| 100 | + * | ||
| 101 | + * @param ${pkColumn.javaField} ${functionName}ID | ||
| 102 | + * @return 结果 | ||
| 103 | + */ | ||
| 104 | + @Override | ||
| 105 | + public int delete${ClassName}ById(${pkColumn.javaType} ${pkColumn.javaField}) | ||
| 106 | + { | ||
| 107 | + return ${className}Mapper.delete${ClassName}ById(${pkColumn.javaField}); | ||
| 108 | + } | ||
| 109 | +} |
ruoyi/src/main/resources/vm/js/api.js.vm
0 → 100644
| 1 | +import request from '@/utils/request' | ||
| 2 | + | ||
| 3 | +// 查询${functionName}列表 | ||
| 4 | +export function list${BusinessName}(query) { | ||
| 5 | + return request({ | ||
| 6 | + url: '/${moduleName}/${businessName}/list', | ||
| 7 | + method: 'get', | ||
| 8 | + params: query | ||
| 9 | + }) | ||
| 10 | +} | ||
| 11 | + | ||
| 12 | +// 查询${functionName}详细 | ||
| 13 | +export function get${BusinessName}(${pkColumn.javaField}) { | ||
| 14 | + return request({ | ||
| 15 | + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, | ||
| 16 | + method: 'get' | ||
| 17 | + }) | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +// 新增${functionName} | ||
| 21 | +export function add${BusinessName}(data) { | ||
| 22 | + return request({ | ||
| 23 | + url: '/${moduleName}/${businessName}', | ||
| 24 | + method: 'post', | ||
| 25 | + data: data | ||
| 26 | + }) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// 修改${functionName} | ||
| 30 | +export function update${BusinessName}(data) { | ||
| 31 | + return request({ | ||
| 32 | + url: '/${moduleName}/${businessName}', | ||
| 33 | + method: 'put', | ||
| 34 | + data: data | ||
| 35 | + }) | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +// 删除${functionName} | ||
| 39 | +export function del${BusinessName}(${pkColumn.javaField}) { | ||
| 40 | + return request({ | ||
| 41 | + url: '/${moduleName}/${businessName}/' + ${pkColumn.javaField}, | ||
| 42 | + method: 'delete' | ||
| 43 | + }) | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +// 导出${functionName} | ||
| 47 | +export function export${BusinessName}(query) { | ||
| 48 | + return request({ | ||
| 49 | + url: '/${moduleName}/${businessName}/export', | ||
| 50 | + method: 'get', | ||
| 51 | + params: query | ||
| 52 | + }) | ||
| 53 | +} |
ruoyi/src/main/resources/vm/sql/sql.vm
0 → 100644
| 1 | +-- 菜单 SQL | ||
| 2 | +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) | ||
| 3 | +values('${functionName}', '3', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '${permissionPrefix}:view', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}菜单'); | ||
| 4 | + | ||
| 5 | +-- 按钮父菜单ID | ||
| 6 | +SELECT @parentId := LAST_INSERT_ID(); | ||
| 7 | + | ||
| 8 | +-- 按钮 SQL | ||
| 9 | +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) | ||
| 10 | +values('${functionName}查询', @parentId, '1', '#', '', 1, 'F', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', ''); | ||
| 11 | + | ||
| 12 | +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) | ||
| 13 | +values('${functionName}新增', @parentId, '2', '#', '', 1, 'F', '0', '${permissionPrefix}:add', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', ''); | ||
| 14 | + | ||
| 15 | +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) | ||
| 16 | +values('${functionName}修改', @parentId, '3', '#', '', 1, 'F', '0', '${permissionPrefix}:edit', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', ''); | ||
| 17 | + | ||
| 18 | +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) | ||
| 19 | +values('${functionName}删除', @parentId, '4', '#', '', 1, 'F', '0', '${permissionPrefix}:remove', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', ''); | ||
| 20 | + | ||
| 21 | +insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, perms, icon, create_by, create_time, update_by, update_time, remark) | ||
| 22 | +values('${functionName}导出', @parentId, '5', '#', '', 1, 'F', '0', '${permissionPrefix}:export', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', ''); |
ruoyi/src/main/resources/vm/vue/index.vue.vm
0 → 100644
| 1 | +<template> | ||
| 2 | + <div class="app-container"> | ||
| 3 | + <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"> | ||
| 4 | +#foreach($column in $columns) | ||
| 5 | +#if($column.query) | ||
| 6 | +#set($dictType=$column.dictType) | ||
| 7 | +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | ||
| 8 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 9 | +#if($parentheseIndex != -1) | ||
| 10 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 11 | +#else | ||
| 12 | +#set($comment=$column.columnComment) | ||
| 13 | +#end | ||
| 14 | +#if($column.htmlType == "input") | ||
| 15 | + <el-form-item label="${comment}" prop="${column.javaField}"> | ||
| 16 | + <el-input | ||
| 17 | + v-model="queryParams.${column.javaField}" | ||
| 18 | + placeholder="请输入${comment}" | ||
| 19 | + clearable | ||
| 20 | + size="small" | ||
| 21 | + @keyup.enter.native="handleQuery" | ||
| 22 | + /> | ||
| 23 | + </el-form-item> | ||
| 24 | +#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && "" != $dictType) | ||
| 25 | + <el-form-item label="${comment}" prop="${column.javaField}"> | ||
| 26 | + <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> | ||
| 27 | + <el-option | ||
| 28 | + v-for="dict in ${column.javaField}Options" | ||
| 29 | + :key="dict.dictValue" | ||
| 30 | + :label="dict.dictLabel" | ||
| 31 | + :value="dict.dictValue" | ||
| 32 | + /> | ||
| 33 | + </el-select> | ||
| 34 | + </el-form-item> | ||
| 35 | +#elseif(($column.htmlType == "select" || $column.htmlType == "radio") && $dictType) | ||
| 36 | + <el-form-item label="${comment}" prop="${column.javaField}"> | ||
| 37 | + <el-select v-model="queryParams.${column.javaField}" placeholder="请选择${comment}" clearable size="small"> | ||
| 38 | + <el-option label="请选择字典生成" value="" /> | ||
| 39 | + </el-select> | ||
| 40 | + </el-form-item> | ||
| 41 | +#elseif($column.htmlType == "datetime") | ||
| 42 | + <el-form-item label="${comment}" prop="${column.javaField}"> | ||
| 43 | + <el-date-picker clearable size="small" style="width: 200px" | ||
| 44 | + v-model="queryParams.${column.javaField}" | ||
| 45 | + type="date" | ||
| 46 | + value-format="yyyy-MM-dd" | ||
| 47 | + placeholder="选择${comment}"> | ||
| 48 | + </el-date-picker> | ||
| 49 | + </el-form-item> | ||
| 50 | + <el-form-item> | ||
| 51 | +#end | ||
| 52 | +#end | ||
| 53 | +#end | ||
| 54 | + <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button> | ||
| 55 | + <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> | ||
| 56 | + </el-form-item> | ||
| 57 | + </el-form> | ||
| 58 | + | ||
| 59 | + <el-row :gutter="10" class="mb8"> | ||
| 60 | + <el-col :span="1.5"> | ||
| 61 | + <el-button | ||
| 62 | + type="primary" | ||
| 63 | + icon="el-icon-plus" | ||
| 64 | + size="mini" | ||
| 65 | + @click="handleAdd" | ||
| 66 | + v-hasPermi="['${moduleName}:${businessName}:add']" | ||
| 67 | + >新增</el-button> | ||
| 68 | + </el-col> | ||
| 69 | + <el-col :span="1.5"> | ||
| 70 | + <el-button | ||
| 71 | + type="success" | ||
| 72 | + icon="el-icon-edit" | ||
| 73 | + size="mini" | ||
| 74 | + :disabled="single" | ||
| 75 | + @click="handleUpdate" | ||
| 76 | + v-hasPermi="['${moduleName}:${businessName}:edit']" | ||
| 77 | + >修改</el-button> | ||
| 78 | + </el-col> | ||
| 79 | + <el-col :span="1.5"> | ||
| 80 | + <el-button | ||
| 81 | + type="danger" | ||
| 82 | + icon="el-icon-delete" | ||
| 83 | + size="mini" | ||
| 84 | + :disabled="multiple" | ||
| 85 | + @click="handleDelete" | ||
| 86 | + v-hasPermi="['${moduleName}:${businessName}:remove']" | ||
| 87 | + >删除</el-button> | ||
| 88 | + </el-col> | ||
| 89 | + <el-col :span="1.5"> | ||
| 90 | + <el-button | ||
| 91 | + type="warning" | ||
| 92 | + icon="el-icon-download" | ||
| 93 | + size="mini" | ||
| 94 | + @click="handleExport" | ||
| 95 | + v-hasPermi="['${moduleName}:${businessName}:export']" | ||
| 96 | + >导出</el-button> | ||
| 97 | + </el-col> | ||
| 98 | + </el-row> | ||
| 99 | + | ||
| 100 | + <el-table v-loading="loading" :data="${businessName}List" @selection-change="handleSelectionChange"> | ||
| 101 | + <el-table-column type="selection" width="55" align="center" /> | ||
| 102 | +#foreach($column in $columns) | ||
| 103 | +#set($javaField=$column.javaField) | ||
| 104 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 105 | +#if($parentheseIndex != -1) | ||
| 106 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 107 | +#else | ||
| 108 | +#set($comment=$column.columnComment) | ||
| 109 | +#end | ||
| 110 | +#if($column.pk) | ||
| 111 | + <el-table-column label="${comment}" align="center" prop="${javaField}" /> | ||
| 112 | +#elseif($column.list && $column.htmlType == "datetime") | ||
| 113 | + <el-table-column label="${comment}" align="center" prop="${javaField}" width="180"> | ||
| 114 | + <template slot-scope="scope"> | ||
| 115 | + <span>{{ parseTime(scope.row.${javaField}) }}</span> | ||
| 116 | + </template> | ||
| 117 | + </el-table-column> | ||
| 118 | +#elseif($column.list && "" != $column.dictType) | ||
| 119 | + <el-table-column label="${comment}" align="center" prop="${javaField}" :formatter="${javaField}Format" /> | ||
| 120 | +#elseif($column.list && "" != $javaField) | ||
| 121 | + <el-table-column label="${comment}" align="center" prop="${javaField}" /> | ||
| 122 | +#end | ||
| 123 | +#end | ||
| 124 | + <el-table-column label="操作" align="center" class-name="small-padding fixed-width"> | ||
| 125 | + <template slot-scope="scope"> | ||
| 126 | + <el-button | ||
| 127 | + size="mini" | ||
| 128 | + type="text" | ||
| 129 | + icon="el-icon-edit" | ||
| 130 | + @click="handleUpdate(scope.row)" | ||
| 131 | + v-hasPermi="['${moduleName}:${businessName}:edit']" | ||
| 132 | + >修改</el-button> | ||
| 133 | + <el-button | ||
| 134 | + size="mini" | ||
| 135 | + type="text" | ||
| 136 | + icon="el-icon-delete" | ||
| 137 | + @click="handleDelete(scope.row)" | ||
| 138 | + v-hasPermi="['${moduleName}:${businessName}:remove']" | ||
| 139 | + >删除</el-button> | ||
| 140 | + </template> | ||
| 141 | + </el-table-column> | ||
| 142 | + </el-table> | ||
| 143 | + | ||
| 144 | + <pagination | ||
| 145 | + v-show="total>0" | ||
| 146 | + :total="total" | ||
| 147 | + :page.sync="queryParams.pageNum" | ||
| 148 | + :limit.sync="queryParams.pageSize" | ||
| 149 | + @pagination="getList" | ||
| 150 | + /> | ||
| 151 | + | ||
| 152 | + <!-- 添加或修改${functionName}对话框 --> | ||
| 153 | + <el-dialog :title="title" :visible.sync="open" width="500px"> | ||
| 154 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | ||
| 155 | +#foreach($column in $columns) | ||
| 156 | +#set($field=$column.javaField) | ||
| 157 | +#if($column.insert && !$column.pk) | ||
| 158 | +#if(($column.usableColumn) || (!$column.superColumn)) | ||
| 159 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 160 | +#if($parentheseIndex != -1) | ||
| 161 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 162 | +#else | ||
| 163 | +#set($comment=$column.columnComment) | ||
| 164 | +#end | ||
| 165 | +#set($dictType=$column.dictType) | ||
| 166 | +#if($column.htmlType == "input") | ||
| 167 | + <el-form-item label="${comment}" prop="${field}"> | ||
| 168 | + <el-input v-model="form.${field}" placeholder="请输入${comment}" /> | ||
| 169 | + </el-form-item> | ||
| 170 | +#elseif($column.htmlType == "select" && "" != $dictType) | ||
| 171 | + <el-form-item label="${comment}"> | ||
| 172 | + <el-select v-model="form.${field}" placeholder="请选择${comment}"> | ||
| 173 | + <el-option | ||
| 174 | + v-for="dict in ${field}Options" | ||
| 175 | + :key="dict.dictValue" | ||
| 176 | + :label="dict.dictLabel" | ||
| 177 | + :value="dict.dictValue" | ||
| 178 | + ></el-option> | ||
| 179 | + </el-select> | ||
| 180 | + </el-form-item> | ||
| 181 | +#elseif($column.htmlType == "select" && $dictType) | ||
| 182 | + <el-form-item label="${comment}"> | ||
| 183 | + <el-select v-model="form.${field}" placeholder="请选择${comment}"> | ||
| 184 | + <el-option label="请选择字典生成" value="" /> | ||
| 185 | + </el-select> | ||
| 186 | + </el-form-item> | ||
| 187 | +#elseif($column.htmlType == "radio" && "" != $dictType) | ||
| 188 | + <el-form-item label="${comment}"> | ||
| 189 | + <el-radio-group v-model="form.${field}"> | ||
| 190 | + <el-radio | ||
| 191 | + v-for="dict in ${field}Options" | ||
| 192 | + :key="dict.dictValue" | ||
| 193 | + :label="dict.dictValue" | ||
| 194 | + >{{dict.dictLabel}}</el-radio> | ||
| 195 | + </el-radio-group> | ||
| 196 | + </el-form-item> | ||
| 197 | +#elseif($column.htmlType == "radio" && $dictType) | ||
| 198 | + <el-form-item label="${comment}"> | ||
| 199 | + <el-radio-group v-model="form.${field}"> | ||
| 200 | + <el-radio label="1">请选择字典生成</el-radio> | ||
| 201 | + </el-radio-group> | ||
| 202 | + </el-form-item> | ||
| 203 | +#elseif($column.htmlType == "datetime") | ||
| 204 | + <el-form-item label="${comment}" prop="${field}"> | ||
| 205 | + <el-date-picker clearable size="small" style="width: 200px" | ||
| 206 | + v-model="form.${field}" | ||
| 207 | + type="date" | ||
| 208 | + value-format="yyyy-MM-dd" | ||
| 209 | + placeholder="选择${comment}"> | ||
| 210 | + </el-date-picker> | ||
| 211 | + </el-form-item> | ||
| 212 | +#elseif($column.htmlType == "textarea") | ||
| 213 | + <el-form-item label="${comment}" prop="${field}"> | ||
| 214 | + <el-input v-model="form.${field}" type="textarea" placeholder="请输入内容" /> | ||
| 215 | + </el-form-item> | ||
| 216 | + </el-form> | ||
| 217 | +#end | ||
| 218 | +#end | ||
| 219 | +#end | ||
| 220 | +#end | ||
| 221 | + </el-form> | ||
| 222 | + <div slot="footer" class="dialog-footer"> | ||
| 223 | + <el-button type="primary" @click="submitForm">确 定</el-button> | ||
| 224 | + <el-button @click="cancel">取 消</el-button> | ||
| 225 | + </div> | ||
| 226 | + </el-dialog> | ||
| 227 | + </div> | ||
| 228 | +</template> | ||
| 229 | + | ||
| 230 | +<script> | ||
| 231 | +import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${BusinessName}, update${BusinessName}, export${BusinessName} } from "@/api/${moduleName}/${businessName}"; | ||
| 232 | + | ||
| 233 | +export default { | ||
| 234 | + data() { | ||
| 235 | + return { | ||
| 236 | + // 遮罩层 | ||
| 237 | + loading: true, | ||
| 238 | + // 选中数组 | ||
| 239 | + ids: [], | ||
| 240 | + // 非单个禁用 | ||
| 241 | + single: true, | ||
| 242 | + // 非多个禁用 | ||
| 243 | + multiple: true, | ||
| 244 | + // 总条数 | ||
| 245 | + total: 0, | ||
| 246 | + // ${functionName}表格数据 | ||
| 247 | + ${businessName}List: [], | ||
| 248 | + // 弹出层标题 | ||
| 249 | + title: "", | ||
| 250 | + // 是否显示弹出层 | ||
| 251 | + open: false, | ||
| 252 | +#foreach ($column in $columns) | ||
| 253 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 254 | +#if($parentheseIndex != -1) | ||
| 255 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 256 | +#else | ||
| 257 | +#set($comment=$column.columnComment) | ||
| 258 | +#end | ||
| 259 | +#if(${column.dictType} != '') | ||
| 260 | + // $comment字典 | ||
| 261 | + ${column.javaField}Options: []#if($velocityCount != $columns.size()),#end | ||
| 262 | + | ||
| 263 | +#end | ||
| 264 | +#end | ||
| 265 | + // 查询参数 | ||
| 266 | + queryParams: { | ||
| 267 | + pageNum: 1, | ||
| 268 | + pageSize: 10, | ||
| 269 | +#foreach ($column in $columns) | ||
| 270 | +#if($column.query) | ||
| 271 | + $column.javaField: undefined#if($velocityCount != $columns.size()),#end | ||
| 272 | + | ||
| 273 | +#end | ||
| 274 | +#end | ||
| 275 | + }, | ||
| 276 | + // 表单参数 | ||
| 277 | + form: {}, | ||
| 278 | + // 表单校验 | ||
| 279 | + rules: { | ||
| 280 | +#foreach ($column in $columns) | ||
| 281 | +#if($column.required) | ||
| 282 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 283 | +#if($parentheseIndex != -1) | ||
| 284 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 285 | +#else | ||
| 286 | +#set($comment=$column.columnComment) | ||
| 287 | +#end | ||
| 288 | +#set($comment=$column.columnComment) | ||
| 289 | + studentName: [ | ||
| 290 | + { required: true, message: "$comment不能为空", trigger: "blur" } | ||
| 291 | + ]#if($velocityCount != $columns.size()),#end | ||
| 292 | +#end | ||
| 293 | +#end | ||
| 294 | + } | ||
| 295 | + }; | ||
| 296 | + }, | ||
| 297 | + created() { | ||
| 298 | + this.getList(); | ||
| 299 | +#foreach ($column in $columns) | ||
| 300 | +#if(${column.dictType} != '') | ||
| 301 | + this.getDicts("${column.dictType}").then(response => { | ||
| 302 | + this.${column.javaField}Options = response.data; | ||
| 303 | + }); | ||
| 304 | +#end | ||
| 305 | +#end | ||
| 306 | + }, | ||
| 307 | + methods: { | ||
| 308 | + /** 查询${functionName}列表 */ | ||
| 309 | + getList() { | ||
| 310 | + this.loading = true; | ||
| 311 | + list${BusinessName}(this.queryParams).then(response => { | ||
| 312 | + this.${businessName}List = response.rows; | ||
| 313 | + this.total = response.total; | ||
| 314 | + this.loading = false; | ||
| 315 | + }); | ||
| 316 | + }, | ||
| 317 | +#foreach ($column in $columns) | ||
| 318 | +#if(${column.dictType} != '') | ||
| 319 | +#set($parentheseIndex=$column.columnComment.indexOf("(")) | ||
| 320 | +#if($parentheseIndex != -1) | ||
| 321 | +#set($comment=$column.columnComment.substring(0, $parentheseIndex)) | ||
| 322 | +#else | ||
| 323 | +#set($comment=$column.columnComment) | ||
| 324 | +#end | ||
| 325 | + // $comment字典翻译 | ||
| 326 | + ${column.javaField}Format(row, column) { | ||
| 327 | + return this.selectDictLabel(this.${column.javaField}Options, row.${column.javaField}); | ||
| 328 | + }, | ||
| 329 | +#end | ||
| 330 | +#end | ||
| 331 | + // 取消按钮 | ||
| 332 | + cancel() { | ||
| 333 | + this.open = false; | ||
| 334 | + this.reset(); | ||
| 335 | + }, | ||
| 336 | + // 表单重置 | ||
| 337 | + reset() { | ||
| 338 | + this.form = { | ||
| 339 | +#foreach ($column in $columns) | ||
| 340 | +#if($column.htmlType == "radio") | ||
| 341 | + $column.javaField: "0"#if($velocityCount != $columns.size()),#end | ||
| 342 | + | ||
| 343 | +#else | ||
| 344 | + $column.javaField: undefined#if($velocityCount != $columns.size()),#end | ||
| 345 | + | ||
| 346 | +#end | ||
| 347 | +#end | ||
| 348 | + }; | ||
| 349 | + this.resetForm("form"); | ||
| 350 | + }, | ||
| 351 | + /** 搜索按钮操作 */ | ||
| 352 | + handleQuery() { | ||
| 353 | + this.queryParams.pageNum = 1; | ||
| 354 | + this.getList(); | ||
| 355 | + }, | ||
| 356 | + /** 重置按钮操作 */ | ||
| 357 | + resetQuery() { | ||
| 358 | + this.resetForm("queryForm"); | ||
| 359 | + this.handleQuery(); | ||
| 360 | + }, | ||
| 361 | + // 多选框选中数据 | ||
| 362 | + handleSelectionChange(selection) { | ||
| 363 | + this.ids = selection.map(item => item.${pkColumn.javaField}) | ||
| 364 | + this.single = selection.length!=1 | ||
| 365 | + this.multiple = !selection.length | ||
| 366 | + }, | ||
| 367 | + /** 新增按钮操作 */ | ||
| 368 | + handleAdd() { | ||
| 369 | + this.reset(); | ||
| 370 | + this.open = true; | ||
| 371 | + this.title = "添加${functionName}"; | ||
| 372 | + }, | ||
| 373 | + /** 修改按钮操作 */ | ||
| 374 | + handleUpdate(row) { | ||
| 375 | + this.reset(); | ||
| 376 | + const ${pkColumn.javaField} = row.${pkColumn.javaField} || this.ids | ||
| 377 | + get${BusinessName}(${pkColumn.javaField}).then(response => { | ||
| 378 | + this.form = response.data; | ||
| 379 | + this.open = true; | ||
| 380 | + this.title = "修改${functionName}"; | ||
| 381 | + }); | ||
| 382 | + }, | ||
| 383 | + /** 提交按钮 */ | ||
| 384 | + submitForm: function() { | ||
| 385 | + this.#[[$]]#refs["form"].validate(valid => { | ||
| 386 | + if (valid) { | ||
| 387 | + if (this.form.${pkColumn.javaField} != undefined) { | ||
| 388 | + update${BusinessName}(this.form).then(response => { | ||
| 389 | + if (response.code === 200) { | ||
| 390 | + this.msgSuccess("修改成功"); | ||
| 391 | + this.open = false; | ||
| 392 | + this.getList(); | ||
| 393 | + } else { | ||
| 394 | + this.msgError(response.msg); | ||
| 395 | + } | ||
| 396 | + }); | ||
| 397 | + } else { | ||
| 398 | + add${BusinessName}(this.form).then(response => { | ||
| 399 | + if (response.code === 200) { | ||
| 400 | + this.msgSuccess("新增成功"); | ||
| 401 | + this.open = false; | ||
| 402 | + this.getList(); | ||
| 403 | + } else { | ||
| 404 | + this.msgError(response.msg); | ||
| 405 | + } | ||
| 406 | + }); | ||
| 407 | + } | ||
| 408 | + } | ||
| 409 | + }); | ||
| 410 | + }, | ||
| 411 | + /** 删除按钮操作 */ | ||
| 412 | + handleDelete(row) { | ||
| 413 | + const ${pkColumn.javaField}s = row.${pkColumn.javaField} || this.ids; | ||
| 414 | + this.$confirm('是否确认删除${functionName}编号为"' + ${pkColumn.javaField}s + '"的数据项?', "警告", { | ||
| 415 | + confirmButtonText: "确定", | ||
| 416 | + cancelButtonText: "取消", | ||
| 417 | + type: "warning" | ||
| 418 | + }).then(function() { | ||
| 419 | + return del${BusinessName}(${pkColumn.javaField}s); | ||
| 420 | + }).then(() => { | ||
| 421 | + this.getList(); | ||
| 422 | + this.msgSuccess("删除成功"); | ||
| 423 | + }).catch(function() {}); | ||
| 424 | + }, | ||
| 425 | + /** 导出按钮操作 */ | ||
| 426 | + handleExport() { | ||
| 427 | + const queryParams = this.queryParams; | ||
| 428 | + this.$confirm('是否确认导出所有${functionName}数据项?', "警告", { | ||
| 429 | + confirmButtonText: "确定", | ||
| 430 | + cancelButtonText: "取消", | ||
| 431 | + type: "warning" | ||
| 432 | + }).then(function() { | ||
| 433 | + return export${BusinessName}(queryParams); | ||
| 434 | + }).then(response => { | ||
| 435 | + this.download(response.msg); | ||
| 436 | + }).catch(function() {}); | ||
| 437 | + } | ||
| 438 | + } | ||
| 439 | +}; | ||
| 440 | +</script> |
| 1 | +<?xml version="1.0" encoding="UTF-8" ?> | ||
| 2 | +<!DOCTYPE mapper | ||
| 3 | +PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" | ||
| 4 | +"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | ||
| 5 | +<mapper namespace="${packageName}.mapper.${ClassName}Mapper"> | ||
| 6 | + | ||
| 7 | + <resultMap type="${ClassName}" id="${ClassName}Result"> | ||
| 8 | +#foreach ($column in $columns) | ||
| 9 | + <result property="${column.javaField}" column="${column.columnName}" /> | ||
| 10 | +#end | ||
| 11 | + </resultMap> | ||
| 12 | + | ||
| 13 | + <sql id="select${ClassName}Vo"> | ||
| 14 | + select#foreach($column in $columns) $column.columnName#if($velocityCount != $columns.size()),#end#end from ${tableName} | ||
| 15 | + </sql> | ||
| 16 | + | ||
| 17 | + <select id="select${ClassName}List" parameterType="${ClassName}" resultMap="${ClassName}Result"> | ||
| 18 | + <include refid="select${ClassName}Vo"/> | ||
| 19 | + <where> | ||
| 20 | +#foreach($column in $columns) | ||
| 21 | +#set($queryType=$column.queryType) | ||
| 22 | +#set($javaField=$column.javaField) | ||
| 23 | +#set($javaType=$column.javaType) | ||
| 24 | +#set($columnName=$column.columnName) | ||
| 25 | +#set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | ||
| 26 | +#if($column.query) | ||
| 27 | +#if($column.queryType == "EQ") | ||
| 28 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName = #{$javaField}</if> | ||
| 29 | +#elseif($queryType == "NE") | ||
| 30 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName != #{$javaField}</if> | ||
| 31 | +#elseif($queryType == "GT") | ||
| 32 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName > #{$javaField}</if> | ||
| 33 | +#elseif($queryType == "GTE") | ||
| 34 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName >= #{$javaField}</if> | ||
| 35 | +#elseif($queryType == "LT") | ||
| 36 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName < #{$javaField}</if> | ||
| 37 | +#elseif($queryType == "LTE") | ||
| 38 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName <= #{$javaField}</if> | ||
| 39 | +#elseif($queryType == "LIKE") | ||
| 40 | + <if test="$javaField != null #if($javaType == 'String' ) and $javaField.trim() != ''#end"> and $columnName like concat('%', #{$javaField}, '%')</if> | ||
| 41 | +#elseif($queryType == "BETWEEN") | ||
| 42 | + <if test="params.begin$AttrName != null and params.begin$AttrName != '' and params.end$AttrName != null and params.end$AttrName != ''"> and $columnName between #{params.begin$AttrName} and #{params.end$AttrName}</if> | ||
| 43 | +#end | ||
| 44 | +#end | ||
| 45 | +#end | ||
| 46 | + </where> | ||
| 47 | + </select> | ||
| 48 | + | ||
| 49 | + <select id="select${ClassName}ById" parameterType="${pkColumn.javaType}" resultMap="${ClassName}Result"> | ||
| 50 | + <include refid="select${ClassName}Vo"/> | ||
| 51 | + where ${pkColumn.columnName} = #{${pkColumn.javaField}} | ||
| 52 | + </select> | ||
| 53 | + | ||
| 54 | + <insert id="insert${ClassName}" parameterType="${ClassName}"#if($pkColumn.increment) useGeneratedKeys="true" keyProperty="$pkColumn.javaField"#end> | ||
| 55 | + insert into ${tableName} | ||
| 56 | + <trim prefix="(" suffix=")" suffixOverrides=","> | ||
| 57 | +#foreach($column in $columns) | ||
| 58 | +#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) | ||
| 59 | + <if test="$column.javaField != null #if($column.javaType == 'String' ) and $column.javaField != ''#end">$column.columnName,</if> | ||
| 60 | +#end | ||
| 61 | +#end | ||
| 62 | + </trim> | ||
| 63 | + <trim prefix="values (" suffix=")" suffixOverrides=","> | ||
| 64 | +#foreach($column in $columns) | ||
| 65 | +#if($column.columnName != $pkColumn.columnName || !$pkColumn.increment) | ||
| 66 | + <if test="$column.javaField != null #if($column.javaType == 'String' ) and $column.javaField != ''#end">#{$column.javaField},</if> | ||
| 67 | +#end | ||
| 68 | +#end | ||
| 69 | + </trim> | ||
| 70 | + </insert> | ||
| 71 | + | ||
| 72 | + <update id="update${ClassName}" parameterType="${ClassName}"> | ||
| 73 | + update ${tableName} | ||
| 74 | + <trim prefix="SET" suffixOverrides=","> | ||
| 75 | +#foreach($column in $columns) | ||
| 76 | +#if($column.columnName != $pkColumn.columnName) | ||
| 77 | + <if test="$column.javaField != null #if($column.javaType == 'String' ) and $column.javaField != ''#end">$column.columnName = #{$column.javaField},</if> | ||
| 78 | +#end | ||
| 79 | +#end | ||
| 80 | + </trim> | ||
| 81 | + where ${pkColumn.columnName} = #{${pkColumn.javaField}} | ||
| 82 | + </update> | ||
| 83 | + | ||
| 84 | + <delete id="delete${ClassName}ById" parameterType="${pkColumn.javaType}"> | ||
| 85 | + delete from ${tableName} where ${pkColumn.columnName} = #{${pkColumn.javaField}} | ||
| 86 | + </delete> | ||
| 87 | + | ||
| 88 | + <delete id="delete${ClassName}ByIds" parameterType="String"> | ||
| 89 | + delete from ${tableName} where ${pkColumn.columnName} in | ||
| 90 | + <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")"> | ||
| 91 | + #{${pkColumn.javaField}} | ||
| 92 | + </foreach> | ||
| 93 | + </delete> | ||
| 94 | + | ||
| 95 | +</mapper> |
-
请 注册 或 登录 后发表评论