| @@ -63,7 +63,7 @@ | |||||
| <v-select v-model="insertItem.department" outlined rounded :items="departments" | <v-select v-model="insertItem.department" outlined rounded :items="departments" | ||||
| label="部門"/> | label="部門"/> | ||||
| <v-text-field v-model="insertItem.account" outlined rounded label="帳號"/> | <v-text-field v-model="insertItem.account" outlined rounded label="帳號"/> | ||||
| <v-text-field v-model="insertItem.pwd" outlined rounded label="密碼"/> | |||||
| <v-text-field v-model="insertItem.pwd" outlined type='password' rounded label="密碼"/> | |||||
| <v-select v-model="insertItem.level" outlined rounded label="權限" | <v-select v-model="insertItem.level" outlined rounded label="權限" | ||||
| :items="levelSelectItem"/> | :items="levelSelectItem"/> | ||||
| </v-container> | </v-container> | ||||
| @@ -89,6 +89,9 @@ | |||||
| </v-dialog> | </v-dialog> | ||||
| </v-toolbar> | </v-toolbar> | ||||
| </template> | </template> | ||||
| <template v-slot:item.pwd="{ item }"> | |||||
| <v-text-field hide-details dense type="password" disabled :value="item.pwd" class="" /> | |||||
| </template> | |||||
| <template v-slot:item.level="{ item }"> | <template v-slot:item.level="{ item }"> | ||||
| <p>{{item.level === '0' ? '超級管理員' : ''}}</p> | <p>{{item.level === '0' ? '超級管理員' : ''}}</p> | ||||
| <p>{{item.level === '1' ? '一般管理員' : ''}}</p> | <p>{{item.level === '1' ? '一般管理員' : ''}}</p> | ||||
| @@ -129,7 +132,7 @@ | |||||
| <v-text-field v-model="modifyItem.username" outlined rounded label="姓名"/> | <v-text-field v-model="modifyItem.username" outlined rounded label="姓名"/> | ||||
| <v-select v-model="modifyItem.department" outlined rounded :items="departments" label="部門"/> | <v-select v-model="modifyItem.department" outlined rounded :items="departments" label="部門"/> | ||||
| <v-text-field v-model="modifyItem.account" disabled outlined rounded label="帳號"/> | <v-text-field v-model="modifyItem.account" disabled outlined rounded label="帳號"/> | ||||
| <v-text-field v-model="modifyItem.pwd" outlined rounded label="密碼"/> | |||||
| <v-text-field v-model="modifyItem.pwd" outlined type='password' rounded label="密碼"/> | |||||
| <v-select v-model="modifyItem.level" outlined rounded label="權限" :items="levelSelectItem"/> | <v-select v-model="modifyItem.level" outlined rounded label="權限" :items="levelSelectItem"/> | ||||
| </v-container> | </v-container> | ||||
| </v-card-text> | </v-card-text> | ||||
| @@ -411,12 +411,12 @@ | |||||
| :item-text="selectColItem.boolean.text" | :item-text="selectColItem.boolean.text" | ||||
| :item-value="selectColItem.boolean.value" | :item-value="selectColItem.boolean.value" | ||||
| /> | /> | ||||
| <v-btn | |||||
| v-if="header.value === 'isselect' && modifyColItem.isselect === 'true'" | |||||
| @click='dialogModifySelectItem = true' | |||||
| > | |||||
| 編輯選項 | |||||
| </v-btn> | |||||
| <!-- <v-btn--> | |||||
| <!-- v-if="header.value === 'isselect' && modifyColItem.isselect === 'true'"--> | |||||
| <!-- @click='dialogModifySelectItem = true'--> | |||||
| <!-- >--> | |||||
| <!-- 編輯選項--> | |||||
| <!-- </v-btn>--> | |||||
| <!--欄位說明欄位--> | <!--欄位說明欄位--> | ||||
| <v-textarea v-if="header.text === '欄位說明'" | <v-textarea v-if="header.text === '欄位說明'" | ||||
| :label='header.text' hint='必填' | :label='header.text' hint='必填' | ||||
| @@ -449,7 +449,6 @@ | |||||
| </v-dialog> | </v-dialog> | ||||
| <!--修改資產群組欄位選項對話--> | <!--修改資產群組欄位選項對話--> | ||||
| <v-dialog | <v-dialog | ||||
| width="40%" | |||||
| v-model='dialogModifySelectItem' | v-model='dialogModifySelectItem' | ||||
| @click:outside='closeDialogModifySelectItem' | @click:outside='closeDialogModifySelectItem' | ||||
| :retain-focus="false" | :retain-focus="false" | ||||
| @@ -462,12 +461,12 @@ | |||||
| <v-card-text> | <v-card-text> | ||||
| <v-container> | <v-container> | ||||
| <v-row> | <v-row> | ||||
| <v-col cols="11" class="d-flex align-center"> | |||||
| <v-col cols="10" class="d-flex align-center"> | |||||
| <v-text-field v-if="modifyColItem.colname === 'type'" | <v-text-field v-if="modifyColItem.colname === 'type'" | ||||
| outlined rounded | outlined rounded | ||||
| label="代號" | label="代號" | ||||
| hint="Ex:H7" | hint="Ex:H7" | ||||
| v-model="modifyTypeSelectItem"/> | |||||
| v-model="modifyTypeSelectItem" /> | |||||
| <v-text-field class="col-12" outlined rounded | <v-text-field class="col-12" outlined rounded | ||||
| label="名稱" | label="名稱" | ||||
| hint="Ex:個人電腦" | hint="Ex:個人電腦" | ||||
| @@ -577,16 +576,6 @@ | |||||
| modifySelectItems: [], | modifySelectItems: [], | ||||
| modifySelectItem: '', | modifySelectItem: '', | ||||
| dialogModifySelectItem: false, | dialogModifySelectItem: false, | ||||
| tags: [{ | |||||
| name: 'Shoping', | |||||
| }, { | |||||
| name: 'Art', | |||||
| }, { | |||||
| name: 'Tech', | |||||
| }, { | |||||
| name: 'Creative Writing' | |||||
| } | |||||
| ], | |||||
| oldIndex: '', | oldIndex: '', | ||||
| modifyTypeSelectItem: '', | modifyTypeSelectItem: '', | ||||
| } | } | ||||
| @@ -711,13 +700,22 @@ | |||||
| insertCol() { | insertCol() { | ||||
| this.insertColItem.issearch = 'true'; | this.insertColItem.issearch = 'true'; | ||||
| this.insertColItem.isexport = 'true'; | this.insertColItem.isexport = 'true'; | ||||
| let stop; | |||||
| for (const key in this.insertColItem) { | for (const key in this.insertColItem) { | ||||
| if (this.insertColItem[key] === '' && key !== 'tablename') { | if (this.insertColItem[key] === '' && key !== 'tablename') { | ||||
| console.log(key); | |||||
| alert('所有資料不可為空'); | alert('所有資料不可為空'); | ||||
| stop = true; | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| this.allCols[this.assertGroup[this.currentTab].value].forEach((col) => { | |||||
| if (this.insertColItem.colname === col.colname) { | |||||
| alert('資料庫欄位名不可重複'); | |||||
| stop = true; | |||||
| return; | |||||
| } | |||||
| }); | |||||
| if (stop === true) return; | |||||
| this.insertColItem.tablename = this.assertGroup[this.currentTab].value; | this.insertColItem.tablename = this.assertGroup[this.currentTab].value; | ||||
| this.insertColItem.insertSelectItems = this.insertSelectItems; | this.insertColItem.insertSelectItems = this.insertSelectItems; | ||||
| this.$axios.post(`/assert/col`, this.insertColItem).then(() => { | this.$axios.post(`/assert/col`, this.insertColItem).then(() => { | ||||
| @@ -726,6 +724,9 @@ | |||||
| this.insertSelectItems = []; | this.insertSelectItems = []; | ||||
| delete this.insertColItem.tablename; | delete this.insertColItem.tablename; | ||||
| delete this.insertColItem.insertselectItems; | delete this.insertColItem.insertselectItems; | ||||
| Object.keys(this.insertColItem).forEach((key) => { | |||||
| this.insertColItem[key] = ''; | |||||
| }); | |||||
| } | } | ||||
| ); | ); | ||||
| @@ -755,12 +756,15 @@ | |||||
| }); | }); | ||||
| }, | }, | ||||
| modifyCol() { | modifyCol() { | ||||
| let stop; | |||||
| for (const key in this.modifyColItem) { | for (const key in this.modifyColItem) { | ||||
| if (this.modifyColItem[key] === '') { | if (this.modifyColItem[key] === '') { | ||||
| alert('所有資料不可為空'); | alert('所有資料不可為空'); | ||||
| stop = true; | |||||
| return; | return; | ||||
| } | } | ||||
| } | } | ||||
| if (stop === true) return; | |||||
| this.modifyColItem.tablename = this.assertGroup[this.currentTab].value; | this.modifyColItem.tablename = this.assertGroup[this.currentTab].value; | ||||
| this.modifyColItem.modifySelectItems = this.modifySelectItems; | this.modifyColItem.modifySelectItems = this.modifySelectItems; | ||||
| this.modifyColItem.oldIndex = this.oldIndex; | this.modifyColItem.oldIndex = this.oldIndex; | ||||
| @@ -771,6 +775,9 @@ | |||||
| delete this.modifyColItem.tablename; | delete this.modifyColItem.tablename; | ||||
| delete this.modifyColItem.modifySelectItems; | delete this.modifyColItem.modifySelectItems; | ||||
| delete this.modifyColItem.oldIndex; | delete this.modifyColItem.oldIndex; | ||||
| Object.keys(this.modifyColItem).forEach((key) => { | |||||
| this.modifyColItem[key] = ''; | |||||
| }); | |||||
| } | } | ||||
| ); | ); | ||||
| @@ -778,7 +785,7 @@ | |||||
| deleteCol(item) { | deleteCol(item) { | ||||
| let yes = confirm('確定刪除'); | let yes = confirm('確定刪除'); | ||||
| if (yes) { | if (yes) { | ||||
| this.$axios.delete(`/assert/deleteCol?tablename=${item.tablename}&&colname=${item.colname}`).then(() => { | |||||
| this.$axios.delete(`/assert/deleteCol?tablename=${item.tablename}&&colname=${item.colname}&&index=${item.index}`).then(() => { | |||||
| this.getCols(); | this.getCols(); | ||||
| alert('已刪除'); | alert('已刪除'); | ||||
| }); | }); | ||||
| @@ -224,6 +224,7 @@ | |||||
| if (level === '0') { | if (level === '0') { | ||||
| this.items.push({'text': '資訊資產群組', 'route': '/asset_group'}); | this.items.push({'text': '資訊資產群組', 'route': '/asset_group'}); | ||||
| this.items.push({'text': '帳號與權限管理', 'route': '/account'}); | this.items.push({'text': '帳號與權限管理', 'route': '/account'}); | ||||
| this.items.push({'text': '資產類別管理', 'route': '/type'}); | |||||
| } | } | ||||
| //一般管理員 | //一般管理員 | ||||
| if (level === '1') { | if (level === '1') { | ||||
| @@ -0,0 +1,355 @@ | |||||
| <template> | |||||
| <div> | |||||
| <v-dialog | |||||
| v-model="progress" | |||||
| persistent | |||||
| width="300" | |||||
| > | |||||
| <v-card | |||||
| color="primary" | |||||
| dark | |||||
| > | |||||
| <v-card-text> | |||||
| 查詢中... | |||||
| <v-progress-linear | |||||
| indeterminate | |||||
| color="white" | |||||
| class="mb-0" | |||||
| ></v-progress-linear> | |||||
| </v-card-text> | |||||
| </v-card> | |||||
| </v-dialog> | |||||
| <v-tabs | |||||
| v-model='currentTab' | |||||
| centered | |||||
| fixed-tabs | |||||
| background-color='grey lighten-4' | |||||
| show-arrows | |||||
| > | |||||
| <v-tab | |||||
| v-for='(item, index) in assertGroup' | |||||
| :key='index' | |||||
| class=' font-weight-bold' | |||||
| > | |||||
| <v-icon small>{{ item.text }}</v-icon> | |||||
| </v-tab> | |||||
| <v-tabs-items v-model='currentTab'> | |||||
| <v-tab-item | |||||
| v-for='(item, index) in assertGroup' | |||||
| :key='index' | |||||
| > | |||||
| <v-data-table | |||||
| :items='cols' | |||||
| :headers='headers' | |||||
| :height="fullHeight*7/9" | |||||
| fixed-header | |||||
| :footer-props="{'items-per-page-options': [30, 40, 50, 60]}" | |||||
| :items-per-page="30" | |||||
| > | |||||
| <template v-slot:item.actions='{ item }'> | |||||
| <v-btn | |||||
| icon | |||||
| @click='openDialogModifyCol(item)' | |||||
| > | |||||
| <v-icon>mdi-pencil</v-icon> | |||||
| </v-btn> | |||||
| <v-icon | |||||
| small | |||||
| @click='deleteCol(item)' | |||||
| > | |||||
| mdi-delete | |||||
| </v-icon> | |||||
| </template> | |||||
| <template v-slot:footer> | |||||
| <div class='d-flex ma-2'> | |||||
| <v-spacer/> | |||||
| <!--新增類別對話--> | |||||
| <v-dialog | |||||
| v-model='dialogInsert' | |||||
| @click:outside='close' | |||||
| :retain-focus="false" | |||||
| overlay-opacity="0" | |||||
| > | |||||
| <template v-slot:activator='{ on, attrs }'> | |||||
| <v-btn | |||||
| v-bind='attrs' | |||||
| v-on='on' | |||||
| color='primary' | |||||
| > | |||||
| 新增類別 | |||||
| </v-btn> | |||||
| </template> | |||||
| <v-card> | |||||
| <v-card-title> | |||||
| <span class='headline font-weight-bold'>新增類別</span> | |||||
| </v-card-title> | |||||
| <v-card-text> | |||||
| <v-container> | |||||
| <v-row> | |||||
| <v-col | |||||
| v-for='(header, index) in headers' | |||||
| :key='index' | |||||
| cols='12' | |||||
| sm='6' | |||||
| md='4' | |||||
| class='d-flex' | |||||
| > | |||||
| <!--文字型欄位--> | |||||
| <v-text-field | |||||
| v-if="!(header.text === '說明' || header.text === '範例' || header.text === '')" | |||||
| :label='header.text' | |||||
| :value="insertColItem[header.value]" | |||||
| hint='必填' | |||||
| v-on:input='oninput(insertColItem, header.value, $event)' | |||||
| /> | |||||
| <!--欄位說明欄位--> | |||||
| <v-textarea v-if="header.text === '說明' || header.text === '範例'" | |||||
| :label='header.text' hint='必填' | |||||
| v-on:input='oninput(insertColItem, header.value, $event)' | |||||
| auto-grow | |||||
| rows="1" /> | |||||
| </v-col> | |||||
| </v-row> | |||||
| </v-container> | |||||
| </v-card-text> | |||||
| <v-card-actions> | |||||
| <v-spacer></v-spacer> | |||||
| <v-btn | |||||
| color='blue darken-1' | |||||
| text | |||||
| @click='close' | |||||
| > | |||||
| 取消 | |||||
| </v-btn> | |||||
| <v-btn | |||||
| color='blue darken-1' | |||||
| text | |||||
| @click='insertCol(item)' | |||||
| > | |||||
| 新增 | |||||
| </v-btn> | |||||
| </v-card-actions> | |||||
| </v-card> | |||||
| </v-dialog> | |||||
| </div> | |||||
| </template> | |||||
| </v-data-table> | |||||
| </v-tab-item> | |||||
| </v-tabs-items> | |||||
| <!--修改資產群駔欄位對話--> | |||||
| <v-dialog | |||||
| v-model='dialogModify' | |||||
| @click:outside='close' | |||||
| :retain-focus="false" | |||||
| overlay-opacity="0" | |||||
| > | |||||
| <v-card> | |||||
| <v-card-title> | |||||
| <span class='headline font-weight-bold'>修改類別</span> | |||||
| </v-card-title> | |||||
| <v-card-text> | |||||
| <v-container> | |||||
| <v-row> | |||||
| <v-col | |||||
| v-for='(header, index) in headers' | |||||
| :key='index' | |||||
| cols='12' | |||||
| sm='6' | |||||
| md='4' | |||||
| class='d-flex' | |||||
| > | |||||
| <!--文字型欄位--> | |||||
| <v-text-field | |||||
| v-if="!(header.text === '說明' || header.text === '範例' || header.text == '')" | |||||
| :label='header.text' | |||||
| :value="modifyColItem[header.value]" | |||||
| :disabled="header.text === '項次'" | |||||
| hint='必填' | |||||
| v-on:input='oninput(modifyColItem, header.value, $event)' | |||||
| /> | |||||
| <!--欄位說明欄位--> | |||||
| <v-textarea v-if="header.text === '說明' || header.text === '範例'" | |||||
| :label='header.text' hint='必填' | |||||
| :value="modifyColItem[header.value]" | |||||
| v-on:input='oninput(modifyColItem, header.value, $event)' | |||||
| auto-grow | |||||
| rows="1" /> | |||||
| </v-col> | |||||
| </v-row> | |||||
| </v-container> | |||||
| </v-card-text> | |||||
| <v-card-actions> | |||||
| <v-spacer></v-spacer> | |||||
| <v-btn | |||||
| color='blue darken-1' | |||||
| text | |||||
| @click='close' | |||||
| > | |||||
| 取消 | |||||
| </v-btn> | |||||
| <v-btn | |||||
| color='blue darken-1' | |||||
| text | |||||
| @click='modifyCol' | |||||
| > | |||||
| 修改 | |||||
| </v-btn> | |||||
| </v-card-actions> | |||||
| </v-card> | |||||
| </v-dialog> | |||||
| </v-tabs> | |||||
| </div> | |||||
| </template> | |||||
| <script> | |||||
| export default { | |||||
| name: '', | |||||
| components: { | |||||
| }, | |||||
| data() { | |||||
| return { | |||||
| fullHeight: 0, | |||||
| dialogInsert: false, | |||||
| dialogModify: false, | |||||
| progress: false, | |||||
| assertGroup: [], | |||||
| headers: [ | |||||
| {'text': '', 'value': 'actions', fixed: true, sortable: false}, | |||||
| {'text': '項次', 'value': 'type'}, | |||||
| {'text': '分類', 'value': 'name'}, | |||||
| {'text': '說明', 'value': 'descript'}, | |||||
| {'text': '範例', 'value': 'example'}, | |||||
| {'text': 'C', 'value': 'c'}, | |||||
| {'text': 'I', 'value': 'i'}, | |||||
| {'text': 'A', 'value': 'a'}, | |||||
| {'text': '順序', 'value': 'id'}, | |||||
| // {'text': '可匯出', 'value': 'isexport'}, | |||||
| // {'text': '可搜尋', 'value': 'issearch'}, | |||||
| ], | |||||
| types: [], | |||||
| insertColItem: {}, | |||||
| modifyColItem: {}, | |||||
| currentTab: 0, | |||||
| cols: [], | |||||
| oldId: '', | |||||
| } | |||||
| }, | |||||
| async mounted() { | |||||
| this.progress = true; | |||||
| this.getTabs(); | |||||
| this.getTypes(); | |||||
| this.getCols(); | |||||
| this.fullHeight = window.innerHeight; | |||||
| window.onresize = () => { | |||||
| this.fullHeight = window.innerHeight; | |||||
| }; | |||||
| }, | |||||
| computed: {}, | |||||
| watch: { | |||||
| currentTab() { | |||||
| this.progress = true; | |||||
| this.getTypes(); | |||||
| this.getCols(); | |||||
| }, | |||||
| dialogInsert() { | |||||
| this.insertColItem.id = this.cols.length + 1; | |||||
| }, | |||||
| dialogModify() { | |||||
| this.oldId = this.modifyColItem.id; | |||||
| } | |||||
| }, | |||||
| methods: { | |||||
| openDialogModifyCol(item) { | |||||
| this.modifyColItem = JSON.parse(JSON.stringify(item)); | |||||
| this.dialogModify = true; | |||||
| }, | |||||
| oninput(item, key, val) { | |||||
| this.$set(item, key, val); | |||||
| }, | |||||
| async getTabs() { | |||||
| await this.$axios.get(`/assert/assertGroups`).then((resp) => { | |||||
| this.assertGroup = []; | |||||
| resp.data.data.forEach((item) => { | |||||
| let header = {'text': null, 'value': null}; | |||||
| header.text = item.descript; | |||||
| header.value = item.tablename; | |||||
| this.assertGroup.push(header); | |||||
| }); | |||||
| }); | |||||
| }, | |||||
| getTypes() { | |||||
| const tablename = this.assertGroup[this.currentTab] ? this.assertGroup[this.currentTab].value : 'hardware'; | |||||
| this.$axios.get(`/assert/Types?tablename=${tablename}`).then((resp) => { | |||||
| this.types = resp.data.data; | |||||
| }); | |||||
| }, | |||||
| getCols() { | |||||
| const tablename = this.assertGroup[this.currentTab] ? this.assertGroup[this.currentTab].value : 'hardware'; | |||||
| this.$axios.get(`/type?tablename=${tablename}`).then((resp) => { | |||||
| this.cols = resp.data.data; | |||||
| this.progress = false; | |||||
| }); | |||||
| }, | |||||
| insertCol() { | |||||
| let stop; | |||||
| this.cols.forEach((col) => { | |||||
| if (col.type === this.insertColItem.type) { | |||||
| alert('項次不可重複'); | |||||
| stop = true; | |||||
| return; | |||||
| } | |||||
| }); | |||||
| if (stop === true) return; | |||||
| this.insertColItem.tablename = this.assertGroup[this.currentTab].value; | |||||
| this.$axios.post(`/type`, this.insertColItem).then(() => { | |||||
| this.getCols(); | |||||
| this.close(); | |||||
| delete this.insertColItem.tablename; | |||||
| Object.keys(this.insertColItem).forEach((key) => { | |||||
| this.insertColItem[key] = ''; | |||||
| }); | |||||
| } | |||||
| ); | |||||
| }, | |||||
| close() { | |||||
| this.dialogInsert = false; | |||||
| this.dialogModify = false; | |||||
| }, | |||||
| modifyCol() { | |||||
| // let repatCount = 0; | |||||
| // this.cols.forEach((col) => { | |||||
| // if (col.type === this.modifyColItem.type) { | |||||
| // repatCount++; | |||||
| // } | |||||
| // }); | |||||
| // if (repatCount >= 1) { | |||||
| // alert('項次不可重複'); | |||||
| // return; | |||||
| // } | |||||
| this.modifyColItem.tablename = this.assertGroup[this.currentTab].value; | |||||
| this.modifyColItem.oldId = this.oldId; | |||||
| this.$axios.put(`/type`, this.modifyColItem).then(() => { | |||||
| this.getCols(); | |||||
| this.close(); | |||||
| delete this.modifyColItem.tablename; | |||||
| delete this.modifyColItem.oldId; | |||||
| Object.keys(this.modifyColItem).forEach((key) => { | |||||
| this.modifyColItem[key] = ''; | |||||
| }); | |||||
| } | |||||
| ); | |||||
| }, | |||||
| deleteCol(item) { | |||||
| let yes = confirm('確定刪除'); | |||||
| if (yes) { | |||||
| item.tablename = this.assertGroup[this.currentTab].value; | |||||
| this.$axios.delete(`/type?tablename=${item.tablename}&&id=${item.id}`).then(() => { | |||||
| this.getCols(); | |||||
| alert('已刪除'); | |||||
| }); | |||||
| } | |||||
| }, | |||||
| } | |||||
| } | |||||
| </script> | |||||
| @@ -7,6 +7,7 @@ import Inventory from '../components/Inventory'; | |||||
| import Search from '../components/Search'; | import Search from '../components/Search'; | ||||
| import ServerList from '../components/ServerList'; | import ServerList from '../components/ServerList'; | ||||
| import account from '../components/AccountManage'; | import account from '../components/AccountManage'; | ||||
| import type from '../components/TypeManage'; | |||||
| Vue.use(Router); | Vue.use(Router); | ||||
| export const constantRoutes = [ | export const constantRoutes = [ | ||||
| @@ -31,6 +32,11 @@ export const constantRoutes = [ | |||||
| component: Inventory | component: Inventory | ||||
| }, | }, | ||||
| { | { | ||||
| path: 'type', | |||||
| name: 'type', | |||||
| component: type | |||||
| }, | |||||
| { | |||||
| path: 'search', | path: 'search', | ||||
| name: 'search', | name: 'search', | ||||
| component: Search | component: Search | ||||
| @@ -80,4 +80,9 @@ public class JdbiFactory { | |||||
| return jdbi.onDemand(SearchDAO.class); | return jdbi.onDemand(SearchDAO.class); | ||||
| } | } | ||||
| @Bean | |||||
| public TypeDAO typeDAO(Jdbi jdbi) { | |||||
| return jdbi.onDemand(TypeDAO.class); | |||||
| } | |||||
| } | } | ||||
| @@ -82,6 +82,7 @@ public class AssertGroupController { | |||||
| System.out.println(mappingCol); | System.out.println(mappingCol); | ||||
| assertDAO.addColToTable(mappingCol); | assertDAO.addColToTable(mappingCol); | ||||
| assertDAO.sortBeforeInsert(mappingCol.getIndex(), mappingCol.getTablename()); | |||||
| assertDAO.insertColToMappingCol(mappingCol); | assertDAO.insertColToMappingCol(mappingCol); | ||||
| assertDAO.insertSelectItems(mappingCol); | assertDAO.insertSelectItems(mappingCol); | ||||
| @@ -104,10 +105,11 @@ public class AssertGroupController { | |||||
| } | } | ||||
| @DeleteMapping("/deleteCol") | @DeleteMapping("/deleteCol") | ||||
| public JsonResult deleteCol(@RequestParam String tablename, @RequestParam String colname) { | |||||
| public JsonResult deleteCol(@RequestParam String tablename, @RequestParam String colname, @RequestParam String index) { | |||||
| assertDAO.deleteColFromTable(tablename, colname); | assertDAO.deleteColFromTable(tablename, colname); | ||||
| assertDAO.deleteColFromMappingCol(tablename, colname); | assertDAO.deleteColFromMappingCol(tablename, colname); | ||||
| assertDAO.sortAfterDelete(index, tablename); | |||||
| assertDAO.deleteFromSelectItem(tablename, colname); | assertDAO.deleteFromSelectItem(tablename, colname); | ||||
| return new JsonResult(StatusCode.SUCCESS, null); | return new JsonResult(StatusCode.SUCCESS, null); | ||||
| } | } | ||||
| @@ -1,10 +1,7 @@ | |||||
| package com.moze.rms.controller; | package com.moze.rms.controller; | ||||
| import com.moze.rms.dao.InventoryDAO; | |||||
| import com.moze.rms.dao.MappingColDAO; | |||||
| import com.moze.rms.dao.MappingTableDAO; | |||||
| import com.moze.rms.dao.SearchDAO; | |||||
| import com.moze.rms.dao.*; | |||||
| import com.moze.rms.entity.dto.SelectItemDTO; | import com.moze.rms.entity.dto.SelectItemDTO; | ||||
| import com.moze.rms.entity.model.MappingCol; | import com.moze.rms.entity.model.MappingCol; | ||||
| import com.moze.rms.utils.ExcelExpoter; | import com.moze.rms.utils.ExcelExpoter; | ||||
| @@ -37,6 +34,9 @@ public class InventoryController { | |||||
| @Autowired | @Autowired | ||||
| SearchDAO searchDAO; | SearchDAO searchDAO; | ||||
| @Autowired | |||||
| AssertDAO assertDAO; | |||||
| @GetMapping("/routes") | @GetMapping("/routes") | ||||
| public JsonResult getRoutes() { | public JsonResult getRoutes() { | ||||
| @@ -142,7 +142,7 @@ public class InventoryController { | |||||
| } | } | ||||
| ExcelExpoter excelExpoter = new ExcelExpoter(""); | ExcelExpoter excelExpoter = new ExcelExpoter(""); | ||||
| String sheetName = mappingTableDAO.findTitle(info.get("tablename")); | String sheetName = mappingTableDAO.findTitle(info.get("tablename")); | ||||
| excelExpoter.expoerDataExcel(resp, titleKeyList, titleMap, descriptMap, items, info.get("tablename"), sheetName); | |||||
| excelExpoter.expoerDataExcel(resp, titleKeyList, titleMap, descriptMap, items, info.get("tablename"), sheetName, mappingTableDAO, assertDAO); | |||||
| } | } | ||||
| @GetMapping("/allHeaders") | @GetMapping("/allHeaders") | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.moze.rms.controller; | package com.moze.rms.controller; | ||||
| import com.moze.rms.dao.AssertDAO; | |||||
| import com.moze.rms.dao.MappingColDAO; | import com.moze.rms.dao.MappingColDAO; | ||||
| import com.moze.rms.dao.MappingTableDAO; | import com.moze.rms.dao.MappingTableDAO; | ||||
| import com.moze.rms.dao.SearchDAO; | import com.moze.rms.dao.SearchDAO; | ||||
| @@ -30,6 +31,9 @@ public class SearchController { | |||||
| @Autowired | @Autowired | ||||
| MappingColDAO mappingColDAO; | MappingColDAO mappingColDAO; | ||||
| @Autowired | |||||
| AssertDAO assertDAO; | |||||
| @GetMapping("/search") | @GetMapping("/search") | ||||
| public JsonResult search(@RequestParam String text) { | public JsonResult search(@RequestParam String text) { | ||||
| @@ -109,6 +113,6 @@ public class SearchController { | |||||
| } | } | ||||
| } | } | ||||
| ExcelExpoter excelExpoter = new ExcelExpoter(""); | ExcelExpoter excelExpoter = new ExcelExpoter(""); | ||||
| excelExpoter.expoerDataExcelMultiSheet(resp, titleKeyLists, titleMaps, descriptMaps, data, "", mappingSheetNames); | |||||
| excelExpoter.expoerDataExcelMultiSheet(resp, titleKeyLists, titleMaps, descriptMaps, data, "", mappingSheetNames, mappingTableDAO, assertDAO); | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,61 @@ | |||||
| package com.moze.rms.controller; | |||||
| import com.fasterxml.jackson.core.JsonProcessingException; | |||||
| import com.moze.rms.dao.AssertDAO; | |||||
| import com.moze.rms.dao.MappingColDAO; | |||||
| import com.moze.rms.dao.MappingTableDAO; | |||||
| import com.moze.rms.dao.TypeDAO; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/api/type") | |||||
| public class TypeController { | |||||
| @Autowired | |||||
| MappingTableDAO mappingTableDAO; | |||||
| @Autowired | |||||
| AssertDAO assertDAO; | |||||
| @Autowired | |||||
| TypeDAO typeDAO; | |||||
| @Autowired | |||||
| MappingColDAO mappingColDAO; | |||||
| @GetMapping("") | |||||
| JsonResult GetType(@RequestParam String tablename) { | |||||
| return new JsonResult(StatusCode.SUCCESS, assertDAO.findTypesByTable(tablename)); | |||||
| } | |||||
| @PostMapping("") | |||||
| JsonResult insertType(@RequestBody Map<String, Object> type) { | |||||
| typeDAO.sortTypeBeforeInsert( type.get("id").toString(), (String) type.get("tablename")); | |||||
| typeDAO.insertType(type); | |||||
| mappingColDAO.insertType(type.get("type") + " " + type.get("name"), type.get("tablename").toString(), type.get("id").toString()); | |||||
| return new JsonResult(StatusCode.SUCCESS, null); | |||||
| } | |||||
| @PutMapping("") | |||||
| JsonResult modifyType(@RequestBody Map<String, Object> type) { | |||||
| if (type.get("id") != type.get("oldId")) { | |||||
| typeDAO.sortType1( type.get("oldId").toString(), type.get("id").toString(), (String)type.get("tablename")); | |||||
| typeDAO.sortType2( type.get("oldId").toString(), type.get("id").toString(), (String)type.get("tablename")); | |||||
| } | |||||
| typeDAO.updateType(type); | |||||
| mappingColDAO.updateType(type.get("type").toString(),type.get("type") + " " + type.get("name"), type.get("tablename").toString(), type.get("id").toString()); | |||||
| return new JsonResult(StatusCode.SUCCESS, null); | |||||
| } | |||||
| @DeleteMapping("") | |||||
| JsonResult deleteType(@RequestParam String tablename, @RequestParam String id) { | |||||
| typeDAO.deleteType(tablename, id); | |||||
| mappingColDAO.deleteType(id, tablename); | |||||
| typeDAO.sortTypeAfterDelete(id, tablename); | |||||
| return new JsonResult(StatusCode.SUCCESS, null); | |||||
| } | |||||
| } | |||||
| @@ -27,13 +27,14 @@ public interface AssertDAO extends SqlObject { | |||||
| default List<Map<String, Object>> findTypesByTable(String tablename) { | default List<Map<String, Object>> findTypesByTable(String tablename) { | ||||
| List<Map<String, Object>> assertGroup = findAssertGroups(); | |||||
| // List<Map<String, Object>> assertGroup = findAssertGroups(); | |||||
| Handle handle = this.getHandle(); | Handle handle = this.getHandle(); | ||||
| String sql = "select * from mapping.mapping_" + tablename + " order by type"; | |||||
| String sql = "select * from mapping.mapping_" + tablename + " order by id"; | |||||
| return handle.createQuery(sql).mapToMap().list(); | return handle.createQuery(sql).mapToMap().list(); | ||||
| } | } | ||||
| @RegisterBeanMapper(MappingCol.class) | @RegisterBeanMapper(MappingCol.class) | ||||
| @SqlQuery("select * from mapping.mapping_col order by convert(int, [index]);") | @SqlQuery("select * from mapping.mapping_col order by convert(int, [index]);") | ||||
| List<MappingCol> findAllCols(); | List<MappingCol> findAllCols(); | ||||
| @@ -60,7 +61,11 @@ public interface AssertDAO extends SqlObject { | |||||
| sql += " constraint mapping_" + data.get("assertGroupTablename") + "_pk primary key,"; | sql += " constraint mapping_" + data.get("assertGroupTablename") + "_pk primary key,"; | ||||
| sql += " name nvarchar(256),"; | sql += " name nvarchar(256),"; | ||||
| sql += " descript nvarchar(256),"; | sql += " descript nvarchar(256),"; | ||||
| sql += " example nvarchar(256)"; | |||||
| sql += " example nvarchar(256),"; | |||||
| sql += " [ ] int,"; | |||||
| sql += " C int,"; | |||||
| sql += " I int,"; | |||||
| sql += " A int"; | |||||
| sql += ")"; | sql += ")"; | ||||
| handle.createUpdate(sql).execute(); | handle.createUpdate(sql).execute(); | ||||
| @@ -178,6 +183,9 @@ public interface AssertDAO extends SqlObject { | |||||
| String name2 = name.substring(0, 1).toUpperCase() + name.substring(1); | String name2 = name.substring(0, 1).toUpperCase() + name.substring(1); | ||||
| Method method = m.getClass().getMethod("get" + name2); | Method method = m.getClass().getMethod("get" + name2); | ||||
| String value = (String) method.invoke(m); | String value = (String) method.invoke(m); | ||||
| if (value == null) { | |||||
| value = ""; | |||||
| } | |||||
| values += "'" + value + "'"; | values += "'" + value + "'"; | ||||
| if (i < fields.length - 1) { | if (i < fields.length - 1) { | ||||
| values += ","; | values += ","; | ||||
| @@ -299,12 +307,24 @@ public interface AssertDAO extends SqlObject { | |||||
| handle.createUpdate(sql).execute(); | handle.createUpdate(sql).execute(); | ||||
| } | } | ||||
| default void sortBeforeInsert(String index, String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_col set [index] = [index] + 1 where [index] >= " + index + " and tablename = '" + tablename + "'"; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| @SqlUpdate("update mapping.mapping_col set [index] = [index] + 1 where [index] < CAST(? as int) and [index] >= CAST(? as int) and tablename = ?") | @SqlUpdate("update mapping.mapping_col set [index] = [index] + 1 where [index] < CAST(? as int) and [index] >= CAST(? as int) and tablename = ?") | ||||
| void sortCol1(String oldIndex ,String index, String tablename); | void sortCol1(String oldIndex ,String index, String tablename); | ||||
| @SqlUpdate("update mapping.mapping_col set [index] = [index] - 1 where [index] > CAST(? as int) and [index] <= CAST(? as int) and tablename = ?") | @SqlUpdate("update mapping.mapping_col set [index] = [index] - 1 where [index] > CAST(? as int) and [index] <= CAST(? as int) and tablename = ?") | ||||
| void sortCol2(String oldIndex ,String index, String tablename); | void sortCol2(String oldIndex ,String index, String tablename); | ||||
| default void sortAfterDelete(String index, String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_col set [index] = [index] - 1 where [index] > " + index + " and tablename = '" + tablename + "'"; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| @SqlUpdate("select [index] from mapping.mapping_col where tablename = ? order by [index] desc limit 1;") | @SqlUpdate("select [index] from mapping.mapping_col where tablename = ? order by [index] desc limit 1;") | ||||
| Integer getLastIndex(String tablename); | Integer getLastIndex(String tablename); | ||||
| @@ -2,6 +2,8 @@ package com.moze.rms.dao; | |||||
| import com.moze.rms.entity.model.MappingCol; | import com.moze.rms.entity.model.MappingCol; | ||||
| import org.jdbi.v3.core.Handle; | |||||
| import org.jdbi.v3.sqlobject.SqlObject; | |||||
| import org.jdbi.v3.sqlobject.config.RegisterBeanMapper; | import org.jdbi.v3.sqlobject.config.RegisterBeanMapper; | ||||
| import org.jdbi.v3.sqlobject.statement.SqlQuery; | import org.jdbi.v3.sqlobject.statement.SqlQuery; | ||||
| @@ -9,7 +11,7 @@ import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RegisterBeanMapper(MappingCol.class) | @RegisterBeanMapper(MappingCol.class) | ||||
| public interface MappingColDAO { | |||||
| public interface MappingColDAO extends SqlObject { | |||||
| @SqlQuery("select * from mapping.mapping_col where tablename = ? order by convert(int, [index]);") | @SqlQuery("select * from mapping.mapping_col where tablename = ? order by convert(int, [index]);") | ||||
| @@ -18,4 +20,33 @@ public interface MappingColDAO { | |||||
| @SqlQuery("select * from mapping.mapping_col order by convert(int, [index]);") | @SqlQuery("select * from mapping.mapping_col order by convert(int, [index]);") | ||||
| List<MappingCol> findAll(); | List<MappingCol> findAll(); | ||||
| default void insertType(String typeAndName, String tablename, String index) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "insert into mapping.selectItem values("; | |||||
| sql += "'"+ tablename +"',"; | |||||
| sql += "'type',"; | |||||
| sql += "'"+ typeAndName +"',"; | |||||
| sql += index +")"; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void updateType(String type, String typeAndName, String tablename, String index){ | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.selectItem set "; | |||||
| sql += "item = '" + typeAndName + "',"; | |||||
| sql += "[index] = " + index; | |||||
| sql += " where item like '" + type + "%' and colname = 'type' and tablename = '" + tablename + "'"; | |||||
| System.out.println(sql); | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void deleteType(String index, String tablename){ | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "delete from mapping.selectItem where [index] = '" + index + "'"; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,103 @@ | |||||
| package com.moze.rms.dao; | |||||
| import org.jdbi.v3.core.Handle; | |||||
| import org.jdbi.v3.sqlobject.SqlObject; | |||||
| import org.jdbi.v3.sqlobject.statement.SqlUpdate; | |||||
| import java.util.Map; | |||||
| public interface TypeDAO extends SqlObject { | |||||
| default void insertType(Map<String, Object> type) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "insert into mapping.mapping_" + type.get("tablename"); | |||||
| sql += "(type, name, descript, example, C, I, A, id) values ("; | |||||
| sql += "'" + type.get("type") + "',"; | |||||
| sql += "'" + type.get("name") + "',"; | |||||
| sql += "'" + type.get("descript") + "',"; | |||||
| sql += "'" + type.get("example") + "',"; | |||||
| if (type.get("c") != "") { | |||||
| sql += type.get("c") + ","; | |||||
| } else { | |||||
| sql += "null,"; | |||||
| } | |||||
| if (type.get("i") != "") { | |||||
| sql += type.get("i") + ","; | |||||
| } else { | |||||
| sql += "null,"; | |||||
| } | |||||
| if (type.get("a") != "") { | |||||
| sql += type.get("a") + ","; | |||||
| } else { | |||||
| sql += "null,"; | |||||
| } | |||||
| sql += type.get("id") + ")"; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void updateType(Map<String, Object> type) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_" + type.get("tablename"); | |||||
| sql += " set name = '" + type.get("name") + "',"; | |||||
| sql += " descript = '" + type.get("descript") + "',"; | |||||
| sql += "example = '" + type.get("example") + "',"; | |||||
| if (type.get("c") != "") { | |||||
| sql += " C = " + type.get("c") + ","; | |||||
| } else { | |||||
| sql += " C = null,"; | |||||
| } | |||||
| if (type.get("i") != "") { | |||||
| sql += " I = " + type.get("i") + ","; | |||||
| } else { | |||||
| sql += " I = null,"; | |||||
| } | |||||
| if (type.get("a") != "") { | |||||
| sql += " A = " + type.get("a") + ","; | |||||
| } else { | |||||
| sql += " A = null,"; | |||||
| } | |||||
| sql += " id = " + type.get("id"); | |||||
| sql += " where type = '" + type.get("type") + "'"; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void deleteType(String tablename, String id) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "delete from mapping.mapping_" + tablename + " where id = " + id; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void sortTypeBeforeInsert(String id, String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_" + tablename + " set id = id + 1 where id >= " + id; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void sortType1(String oldId ,String id, String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_" + tablename + " set id = id + 1 where id >= " + id + " and id < " + oldId; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void sortType2(String oldId ,String id, String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_" + tablename + " set id = id - 1 where id > " + oldId + " and id <= " + id; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| default void sortTypeAfterDelete(String id, String tablename) { | |||||
| Handle handle = this.getHandle(); | |||||
| String sql = "update mapping.mapping_" + tablename + " set id = id - 1 where id > " + id; | |||||
| handle.createUpdate(sql).execute(); | |||||
| } | |||||
| } | |||||
| @@ -1,8 +1,7 @@ | |||||
| package com.moze.rms.utils; | package com.moze.rms.utils; | ||||
| import java.io.*; | |||||
| import java.util.*; | |||||
| import com.moze.rms.dao.AssertDAO; | |||||
| import com.moze.rms.dao.MappingTableDAO; | |||||
| import com.moze.rms.entity.model.MappingTable; | import com.moze.rms.entity.model.MappingTable; | ||||
| import org.apache.poi.hssf.usermodel.HSSFCellStyle; | import org.apache.poi.hssf.usermodel.HSSFCellStyle; | ||||
| import org.apache.poi.hssf.usermodel.HSSFFont; | import org.apache.poi.hssf.usermodel.HSSFFont; | ||||
| @@ -10,15 +9,17 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||||
| import org.apache.poi.hssf.util.HSSFColor; | import org.apache.poi.hssf.util.HSSFColor; | ||||
| import org.apache.poi.ss.usermodel.*; | import org.apache.poi.ss.usermodel.*; | ||||
| import org.apache.poi.ss.util.CellRangeAddress; | import org.apache.poi.ss.util.CellRangeAddress; | ||||
| import org.apache.poi.ss.util.RegionUtil; | |||||
| import org.apache.poi.xssf.streaming.SXSSFWorkbook; | |||||
| import org.apache.poi.xssf.usermodel.XSSFSheet; | import org.apache.poi.xssf.usermodel.XSSFSheet; | ||||
| import org.apache.poi.xssf.usermodel.XSSFWorkbook; | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import java.io.IOException; | |||||
| import java.io.OutputStream; | |||||
| import java.util.*; | |||||
| public class ExcelExpoter { | public class ExcelExpoter { | ||||
| private String outputPath; | private String outputPath; | ||||
| private String nullString; | private String nullString; | ||||
| private Set<String> columnAutoSized = new HashSet<>(); | private Set<String> columnAutoSized = new HashSet<>(); | ||||
| @@ -180,11 +181,14 @@ public class ExcelExpoter { | |||||
| } | } | ||||
| public void expoerDataExcel(HttpServletResponse response, ArrayList<String> titleKeyList, Map<String, String> titleMap, Map<String, String> descriptMap, List<Map<String, Object>> src_list, String filename, String sheetName) throws IOException { | |||||
| public void expoerDataExcel(HttpServletResponse response, ArrayList<String> titleKeyList, Map<String, String> titleMap, Map<String, String> descriptMap, List<Map<String, Object>> src_list, String filename, String sheetName, MappingTableDAO mappingTableDAO, AssertDAO assertDAO) throws IOException { | |||||
| String xlsFile_name = filename + ".xls"; //輸出xls檔名稱 | String xlsFile_name = filename + ".xls"; //輸出xls檔名稱 | ||||
| //記憶體中只建立100個物件 | //記憶體中只建立100個物件 | ||||
| Workbook wb = new HSSFWorkbook(); //關鍵語句 | Workbook wb = new HSSFWorkbook(); //關鍵語句 | ||||
| writeFirstPage( mappingTableDAO, assertDAO, wb); | |||||
| Sheet sheet = null; //工作表物件 | Sheet sheet = null; //工作表物件 | ||||
| Row nRow = null; //行物件 | Row nRow = null; //行物件 | ||||
| Cell nCell = null; //列物件 | Cell nCell = null; //列物件 | ||||
| @@ -203,7 +207,7 @@ public class ExcelExpoter { | |||||
| if (rowNo % 300000 == 0) { | if (rowNo % 300000 == 0) { | ||||
| System.out.println("Current Sheet:" + rowNo / 300000); | System.out.println("Current Sheet:" + rowNo / 300000); | ||||
| sheet = wb.createSheet(sheetName);//建立新的sheet物件 | sheet = wb.createSheet(sheetName);//建立新的sheet物件 | ||||
| sheet = wb.getSheetAt(rowNo / 300000); //動態指定當前的工作表 | |||||
| sheet = wb.getSheetAt(rowNo / 300000 + 1); //動態指定當前的工作表 | |||||
| pageRowNo = 0; //新建了工作表,重置工作表的行號為0 | pageRowNo = 0; //新建了工作表,重置工作表的行號為0 | ||||
| // -----------定義表頭----------- | // -----------定義表頭----------- | ||||
| nRow = sheet.createRow(pageRowNo++); | nRow = sheet.createRow(pageRowNo++); | ||||
| @@ -212,14 +216,14 @@ public class ExcelExpoter { | |||||
| Cell cell_tem_title = nRow.createCell(0); | Cell cell_tem_title = nRow.createCell(0); | ||||
| cell_tem_title.setCellStyle(titleStyle); | cell_tem_title.setCellStyle(titleStyle); | ||||
| cell_tem_title.setCellValue("資訊資產清冊 " + sheetName + "類"); | cell_tem_title.setCellValue("資訊資產清冊 " + sheetName + "類"); | ||||
| CellRangeAddress cra =new CellRangeAddress(0, 0, 0, titleKeyList.size() - 1); | |||||
| CellRangeAddress cra = new CellRangeAddress(0, 0, 0, titleKeyList.size() - 1); | |||||
| sheet.addMergedRegion(cra); | sheet.addMergedRegion(cra); | ||||
| rowNo++; | rowNo++; | ||||
| nRow = sheet.createRow(pageRowNo++); | nRow = sheet.createRow(pageRowNo++); | ||||
| HSSFCellStyle headerStyle = (HSSFCellStyle) wb.createCellStyle(); | HSSFCellStyle headerStyle = (HSSFCellStyle) wb.createCellStyle(); | ||||
| headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_BLUE.getIndex()); | headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_BLUE.getIndex()); | ||||
| headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | ||||
| HSSFFont headerFont= (HSSFFont) wb.createFont(); | |||||
| HSSFFont headerFont = (HSSFFont) wb.createFont(); | |||||
| headerFont.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex()); | headerFont.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex()); | ||||
| headerStyle.setFont(headerFont); | headerStyle.setFont(headerFont); | ||||
| headerStyle.setBorderBottom(BorderStyle.THIN); | headerStyle.setBorderBottom(BorderStyle.THIN); | ||||
| @@ -241,7 +245,7 @@ public class ExcelExpoter { | |||||
| HSSFCellStyle descriptStyle = (HSSFCellStyle) wb.createCellStyle(); | HSSFCellStyle descriptStyle = (HSSFCellStyle) wb.createCellStyle(); | ||||
| descriptStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.LIGHT_CORNFLOWER_BLUE.getIndex()); | descriptStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.LIGHT_CORNFLOWER_BLUE.getIndex()); | ||||
| descriptStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | descriptStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | ||||
| HSSFFont descriptFont= (HSSFFont) wb.createFont(); | |||||
| HSSFFont descriptFont = (HSSFFont) wb.createFont(); | |||||
| descriptFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex()); | descriptFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex()); | ||||
| descriptStyle.setFont(descriptFont); | descriptStyle.setFont(descriptFont); | ||||
| descriptStyle.setBorderBottom(BorderStyle.THIN); | descriptStyle.setBorderBottom(BorderStyle.THIN); | ||||
| @@ -266,15 +270,15 @@ public class ExcelExpoter { | |||||
| nCell = nRow.createCell(j); | nCell = nRow.createCell(j); | ||||
| nCell.setCellStyle(dataStyle); | nCell.setCellStyle(dataStyle); | ||||
| if (srcMap.get(titleKeyList.get(j)) != null) { | if (srcMap.get(titleKeyList.get(j)) != null) { | ||||
| nCell.setCellValue(srcMap.get(titleKeyList.get(j)).toString()); | |||||
| nCell.setCellValue(srcMap.get(titleKeyList.get(j)).toString().replaceAll("\\?", "")); | |||||
| } else { | } else { | ||||
| nCell.setCellValue(""); | nCell.setCellValue(""); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| response.setContentType("application/vnd.ms-excel;charset=utf-8"); | response.setContentType("application/vnd.ms-excel;charset=utf-8"); | ||||
| response.setHeader("filename" , xlsFile_name); | |||||
| response.setHeader("Content-disposition" , "attachment;filename=" + xlsFile_name); | |||||
| response.setHeader("filename", xlsFile_name); | |||||
| response.setHeader("Content-disposition", "attachment;filename=" + xlsFile_name); | |||||
| response.flushBuffer(); | response.flushBuffer(); | ||||
| OutputStream outputStream = response.getOutputStream(); | OutputStream outputStream = response.getOutputStream(); | ||||
| wb.write(response.getOutputStream()); | wb.write(response.getOutputStream()); | ||||
| @@ -284,20 +288,24 @@ public class ExcelExpoter { | |||||
| } | } | ||||
| public void expoerDataExcelMultiSheet(HttpServletResponse response, Map<String, ArrayList<String>> titleKeyLists, Map<String, Map<String, String>> titleMaps, Map<String, Map<String, String>> descriptMaps, Map<String, List<Map<String, Object>>> src_lists, String filename, Map<String, String> sheetNames) throws IOException { | |||||
| public void expoerDataExcelMultiSheet(HttpServletResponse response, Map<String, ArrayList<String>> titleKeyLists, Map<String, Map<String, String>> titleMaps, Map<String, Map<String, String>> descriptMaps, Map<String, List<Map<String, Object>>> src_lists, String filename, Map<String, String> sheetNames, MappingTableDAO mappingTableDAO, AssertDAO assertDAO) throws IOException { | |||||
| String xlsFile_name = "SeverList.xls"; //輸出xls檔名稱 | String xlsFile_name = "SeverList.xls"; //輸出xls檔名稱 | ||||
| //記憶體中只建立100個物件 | //記憶體中只建立100個物件 | ||||
| Workbook wb = new HSSFWorkbook(); //關鍵語句 | Workbook wb = new HSSFWorkbook(); //關鍵語句 | ||||
| writeFirstPage( mappingTableDAO, assertDAO, wb); | |||||
| // Iterator<Map.Entry<String, List<Map<String, Object>>>> iterator = src_lists.entrySet().iterator(); | // Iterator<Map.Entry<String, List<Map<String, Object>>>> iterator = src_lists.entrySet().iterator(); | ||||
| Iterator<Map.Entry<String, String>> iterator = sheetNames.entrySet().iterator(); | Iterator<Map.Entry<String, String>> iterator = sheetNames.entrySet().iterator(); | ||||
| while (iterator.hasNext()) { | while (iterator.hasNext()) { | ||||
| Sheet sheet = null; //工作表物件 | |||||
| Row nRow = null; //行物件 | |||||
| Cell nCell = null; //列物件 | |||||
| Sheet sheet = null; //工作表物件 | |||||
| Row nRow = null; //行物件 | |||||
| Cell nCell = null; //列物件 | |||||
| int rowNo = 0; //總行號 | |||||
| int pageRowNo = 0; //頁行號 | |||||
| int rowNo = 0; //總行號 | |||||
| int pageRowNo = 0; //頁行號 | |||||
| Map.Entry<String, String> next = iterator.next(); | Map.Entry<String, String> next = iterator.next(); | ||||
| @@ -325,14 +333,14 @@ public class ExcelExpoter { | |||||
| Cell cell_tem_title = nRow.createCell(0); | Cell cell_tem_title = nRow.createCell(0); | ||||
| cell_tem_title.setCellStyle(titleStyle); | cell_tem_title.setCellStyle(titleStyle); | ||||
| cell_tem_title.setCellValue("資訊資產清冊 " + sheetNames.get(key) + "類"); | cell_tem_title.setCellValue("資訊資產清冊 " + sheetNames.get(key) + "類"); | ||||
| CellRangeAddress cra =new CellRangeAddress(0, 0, 0, titleKeyLists.get(key).size() - 1); | |||||
| CellRangeAddress cra = new CellRangeAddress(0, 0, 0, titleKeyLists.get(key).size() - 1); | |||||
| sheet.addMergedRegion(cra); | sheet.addMergedRegion(cra); | ||||
| rowNo++; | rowNo++; | ||||
| nRow = sheet.createRow(pageRowNo++); | nRow = sheet.createRow(pageRowNo++); | ||||
| HSSFCellStyle headerStyle = (HSSFCellStyle) wb.createCellStyle(); | HSSFCellStyle headerStyle = (HSSFCellStyle) wb.createCellStyle(); | ||||
| headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_BLUE.getIndex()); | headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_BLUE.getIndex()); | ||||
| headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | ||||
| HSSFFont headerFont= (HSSFFont) wb.createFont(); | |||||
| HSSFFont headerFont = (HSSFFont) wb.createFont(); | |||||
| headerFont.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex()); | headerFont.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex()); | ||||
| headerStyle.setFont(headerFont); | headerStyle.setFont(headerFont); | ||||
| headerStyle.setBorderBottom(BorderStyle.THIN); | headerStyle.setBorderBottom(BorderStyle.THIN); | ||||
| @@ -354,7 +362,7 @@ public class ExcelExpoter { | |||||
| HSSFCellStyle descriptStyle = (HSSFCellStyle) wb.createCellStyle(); | HSSFCellStyle descriptStyle = (HSSFCellStyle) wb.createCellStyle(); | ||||
| descriptStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.LIGHT_CORNFLOWER_BLUE.getIndex()); | descriptStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.LIGHT_CORNFLOWER_BLUE.getIndex()); | ||||
| descriptStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | descriptStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | ||||
| HSSFFont descriptFont= (HSSFFont) wb.createFont(); | |||||
| HSSFFont descriptFont = (HSSFFont) wb.createFont(); | |||||
| descriptFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex()); | descriptFont.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex()); | ||||
| descriptStyle.setFont(descriptFont); | descriptStyle.setFont(descriptFont); | ||||
| descriptStyle.setBorderBottom(BorderStyle.THIN); | descriptStyle.setBorderBottom(BorderStyle.THIN); | ||||
| @@ -379,7 +387,7 @@ public class ExcelExpoter { | |||||
| nCell = nRow.createCell(j); | nCell = nRow.createCell(j); | ||||
| nCell.setCellStyle(dataStyle); | nCell.setCellStyle(dataStyle); | ||||
| if (srcMap.get(titleKeyLists.get(key).get(j)) != null) { | if (srcMap.get(titleKeyLists.get(key).get(j)) != null) { | ||||
| nCell.setCellValue(srcMap.get(titleKeyLists.get(key).get(j)).toString()); | |||||
| nCell.setCellValue(srcMap.get(titleKeyLists.get(key).get(j)).toString().replaceAll("\\?", "")); | |||||
| } else { | } else { | ||||
| nCell.setCellValue(""); | nCell.setCellValue(""); | ||||
| } | } | ||||
| @@ -394,14 +402,206 @@ public class ExcelExpoter { | |||||
| } | } | ||||
| response.setContentType("application/vnd.ms-excel;charset=utf-8"); | response.setContentType("application/vnd.ms-excel;charset=utf-8"); | ||||
| response.setHeader("filename" ,xlsFile_name); | |||||
| response.setHeader("Content-disposition" ,"attachment;filename="+xlsFile_name); | |||||
| response.setHeader("filename", xlsFile_name); | |||||
| response.setHeader("Content-disposition", "attachment;filename=" + xlsFile_name); | |||||
| response.flushBuffer(); | response.flushBuffer(); | ||||
| OutputStream outputStream = response.getOutputStream(); | |||||
| OutputStream outputStream = response.getOutputStream(); | |||||
| wb.write(response.getOutputStream()); | wb.write(response.getOutputStream()); | ||||
| wb.close(); | wb.close(); | ||||
| outputStream.flush(); | outputStream.flush(); | ||||
| outputStream.close(); | outputStream.close(); | ||||
| } | |||||
| } | |||||
| public void writeFirstPage(MappingTableDAO mappingTableDAO, AssertDAO assertDAO, Workbook wb) { | |||||
| Sheet sheet = null; //工作表物件 | |||||
| Row nRow = null; //行物件 | |||||
| Cell nCell = null; | |||||
| int pageRowNo = 0; | |||||
| sheet = wb.createSheet("資訊資產群組"); | |||||
| nRow = sheet.createRow(pageRowNo++); | |||||
| HSSFCellStyle titleStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| HSSFFont titleFont = (HSSFFont) wb.createFont(); | |||||
| titleFont.setBold(true); | |||||
| titleStyle.setFont(titleFont); | |||||
| titleStyle.setAlignment(HorizontalAlignment.CENTER); | |||||
| Cell cell_tem_title = nRow.createCell(0); | |||||
| cell_tem_title.setCellStyle(titleStyle); | |||||
| cell_tem_title.setCellValue("資訊資產清冊分級建議"); | |||||
| CellRangeAddress cra = new CellRangeAddress(0, 0, 0, 7); | |||||
| sheet.addMergedRegion(cra); | |||||
| nRow = sheet.createRow(pageRowNo++); | |||||
| HSSFFont headerFont = (HSSFFont) wb.createFont(); | |||||
| headerFont.setColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex()); | |||||
| HSSFCellStyle headerStartStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| headerStartStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.AQUA.getIndex()); | |||||
| headerStartStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
| headerStartStyle.setFont(headerFont); | |||||
| headerStartStyle.setBorderBottom(BorderStyle.MEDIUM); | |||||
| headerStartStyle.setBorderLeft(BorderStyle.MEDIUM); | |||||
| headerStartStyle.setBorderTop(BorderStyle.MEDIUM); | |||||
| headerStartStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| HSSFCellStyle headerEndStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| headerEndStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.AQUA.getIndex()); | |||||
| headerEndStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
| headerEndStyle.setFont(headerFont); | |||||
| headerEndStyle.setBorderBottom(BorderStyle.MEDIUM); | |||||
| headerEndStyle.setBorderTop(BorderStyle.MEDIUM); | |||||
| headerEndStyle.setBorderRight(BorderStyle.MEDIUM); | |||||
| headerEndStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| HSSFCellStyle headerStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.AQUA.getIndex()); | |||||
| headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
| headerStyle.setFont(headerFont); | |||||
| headerStyle.setBorderBottom(BorderStyle.MEDIUM); | |||||
| headerStyle.setBorderTop(BorderStyle.MEDIUM); | |||||
| headerStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| Cell cell_tem0 = nRow.createCell(0); | |||||
| cell_tem0.setCellValue("項次"); | |||||
| cell_tem0.setCellStyle(headerStartStyle); | |||||
| Cell cell_tem1 = nRow.createCell(1); | |||||
| cell_tem1.setCellValue("分類"); | |||||
| cell_tem1.setCellStyle(headerStyle); | |||||
| Cell cell_tem2 = nRow.createCell(2); | |||||
| cell_tem2.setCellValue("說明"); | |||||
| cell_tem2.setCellStyle(headerStyle); | |||||
| Cell cell_tem3 = nRow.createCell(3); | |||||
| cell_tem3.setCellValue("範例"); | |||||
| cell_tem3.setCellStyle(headerEndStyle); | |||||
| Cell cell_tem4 = nRow.createCell(4); | |||||
| cell_tem3.setCellValue(""); | |||||
| Cell cell_tem5 = nRow.createCell(5); | |||||
| cell_tem5.setCellValue("C"); | |||||
| cell_tem5.setCellStyle(headerStartStyle); | |||||
| Cell cell_tem6 = nRow.createCell(6); | |||||
| cell_tem6.setCellValue("I"); | |||||
| cell_tem6.setCellStyle(headerStyle); | |||||
| Cell cell_tem7 = nRow.createCell(7); | |||||
| cell_tem7.setCellValue("A"); | |||||
| cell_tem7.setCellStyle(headerEndStyle); | |||||
| sheet.setColumnWidth(1, 4500); | |||||
| sheet.setColumnWidth(2, 4500); | |||||
| sheet.setColumnWidth(3, 4500); | |||||
| sheet.setColumnWidth(4, 900); | |||||
| sheet.setColumnWidth(5, 900); | |||||
| sheet.setColumnWidth(6, 900); | |||||
| sheet.setColumnWidth(7, 900); | |||||
| sheet.createFreezePane(0, 2); | |||||
| HSSFCellStyle subheaderStartStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| subheaderStartStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_TEAL.getIndex()); | |||||
| subheaderStartStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
| subheaderStartStyle.setFont(headerFont); | |||||
| subheaderStartStyle.setBorderBottom(BorderStyle.MEDIUM); | |||||
| subheaderStartStyle.setBorderLeft(BorderStyle.MEDIUM); | |||||
| subheaderStartStyle.setBorderTop(BorderStyle.MEDIUM); | |||||
| subheaderStartStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| HSSFCellStyle subheaderEndStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| subheaderEndStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_TEAL.getIndex()); | |||||
| subheaderEndStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
| subheaderEndStyle.setFont(headerFont); | |||||
| subheaderEndStyle.setBorderBottom(BorderStyle.MEDIUM); | |||||
| subheaderEndStyle.setBorderTop(BorderStyle.MEDIUM); | |||||
| subheaderEndStyle.setBorderRight(BorderStyle.MEDIUM); | |||||
| subheaderEndStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| HSSFCellStyle subheaderStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| subheaderStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.DARK_TEAL.getIndex()); | |||||
| subheaderStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); | |||||
| subheaderStyle.setFont(headerFont); | |||||
| subheaderStyle.setBorderBottom(BorderStyle.MEDIUM); | |||||
| subheaderStyle.setBorderTop(BorderStyle.MEDIUM); | |||||
| subheaderStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| List<MappingTable> mappingTables = mappingTableDAO.findAll(); | |||||
| for (MappingTable mappingTable : mappingTables) { | |||||
| List<Map<String, Object>> datas = assertDAO.findTypesByTable(mappingTable.getTablename()); | |||||
| nRow = sheet.createRow(pageRowNo++); | |||||
| Cell cell_subheader0 = nRow.createCell(0); | |||||
| cell_subheader0.setCellStyle(subheaderStartStyle); | |||||
| cell_subheader0.setCellValue(mappingTable.getDescript() + "類"); | |||||
| Cell cell_subheader1 = nRow.createCell(1); | |||||
| cell_subheader1.setCellStyle(subheaderStyle); | |||||
| Cell cell_subheader2 = nRow.createCell(2); | |||||
| cell_subheader2.setCellStyle(subheaderStyle); | |||||
| Cell cell_subheader3 = nRow.createCell(3); | |||||
| cell_subheader3.setCellStyle(subheaderEndStyle); | |||||
| Cell cell_subheader4 = nRow.createCell(4); | |||||
| Cell cell_subheader5 = nRow.createCell(5); | |||||
| // cell_subheader5.setCellStyle(subheaderStartStyle); | |||||
| Cell cell_subheader6 = nRow.createCell(6); | |||||
| // cell_subheader6.setCellStyle(subheaderStyle); | |||||
| Cell cell_subheader7 = nRow.createCell(7); | |||||
| // cell_subheader7.setCellStyle(subheaderEndStyle); | |||||
| HSSFCellStyle valStyle = (HSSFCellStyle) wb.createCellStyle(); | |||||
| valStyle.setBorderRight(BorderStyle.THIN); | |||||
| valStyle.setBorderLeft(BorderStyle.THIN); | |||||
| valStyle.setBorderBottom(BorderStyle.THIN); | |||||
| valStyle.setBorderTop(BorderStyle.THIN); | |||||
| valStyle.setVerticalAlignment(VerticalAlignment.TOP); | |||||
| valStyle.setWrapText(true); | |||||
| for (Map<String, Object> data : datas) { | |||||
| nRow = sheet.createRow(pageRowNo++); | |||||
| Cell cell_val0 = nRow.createCell(0); | |||||
| cell_val0.setCellValue(data.get("type").toString()); | |||||
| cell_val0.setCellStyle(valStyle); | |||||
| Cell cell_val1 = nRow.createCell(1); | |||||
| cell_val1.setCellValue(data.get("name").toString()); | |||||
| cell_val1.setCellStyle(valStyle); | |||||
| Cell cell_val2 = nRow.createCell(2); | |||||
| cell_val2.setCellValue(data.get("descript").toString()); | |||||
| cell_val2.setCellStyle(valStyle); | |||||
| Cell cell_val3 = nRow.createCell(3); | |||||
| cell_val3.setCellValue(data.get("example").toString()); | |||||
| cell_val3.setCellStyle(valStyle); | |||||
| Cell cell_val4 = nRow.createCell(4); | |||||
| Cell cell_val5 = nRow.createCell(5); | |||||
| if (data.get("c") != null) { | |||||
| cell_subheader5.setCellStyle(subheaderStartStyle); | |||||
| cell_val5.setCellStyle(valStyle); | |||||
| cell_subheader5.setCellValue("C"); | |||||
| cell_val5.setCellValue(data.get("c").toString()); | |||||
| } | |||||
| Cell cell_val6 = nRow.createCell(6); | |||||
| if (data.get("i") != null) { | |||||
| cell_subheader6.setCellStyle(subheaderStyle); | |||||
| cell_val6.setCellStyle(valStyle); | |||||
| cell_subheader6.setCellValue("I"); | |||||
| cell_val6.setCellValue(data.get("i").toString()); | |||||
| } | |||||
| Cell cell_val7 = nRow.createCell(7); | |||||
| if (data.get("a") != null) { | |||||
| cell_subheader7.setCellStyle(subheaderEndStyle); | |||||
| cell_val7.setCellStyle(valStyle); | |||||
| cell_subheader7.setCellValue("A"); | |||||
| cell_val7.setCellValue(data.get("a").toString()); | |||||
| } | |||||
| } | |||||
| pageRowNo++; | |||||
| } | |||||
| } | |||||
| } | } | ||||