Przeglądaj źródła

更新store查询sql;新增用户导入功能

luoaoxuan 1 rok temu
rodzic
commit
c68269342f

+ 6 - 1
src/store/getters.js

@@ -92,4 +92,9 @@ export default {
         state.ibps.param && state.ibps.param.deptList
             ? state.ibps.param.deptList
             : [],
-};
+    // 获取所有岗位信息
+    positionList: (state) =>
+        state.ibps.param && state.ibps.param.positionList
+            ? state.ibps.param.positionList
+            : []
+}

+ 10 - 1
src/store/modules/ibps/modules/param.js

@@ -10,7 +10,9 @@ export default {
         // 所有用户信息
         userList: [],
         // 所有部门信息
-        deptList: []
+        deptList: [],
+        // 所有岗位信息
+        positionList: []
     },
     mutations: {
         jianCeDuiXiangIdSet (state, jianCeDuiXiang) {
@@ -31,6 +33,9 @@ export default {
         deptList (state, data) {
             state.deptList = data.length ? data : []
         },
+        positionList (state, data) {
+            state.positionList = data.length ? data : []
+        },
         level (state, data) {
             state.level = data || { first: '', second: '' }
         }
@@ -44,6 +49,10 @@ export default {
         },
         setDeptList ({ commit }, data) {
             commit('deptList', data)
+        },
+        setPositionList ({ commit }, data) {
+            commit('positionList', data)
         }
+
     }
 }

+ 38 - 5
src/store/modules/ibps/modules/user.js

@@ -6,7 +6,7 @@ import request from '@/business/platform/form/utils/custom/joinCURD.js'
 export default {
     namespaced: true,
     state: {
-    // 用户信息
+        // 用户信息
         info: {},
         // 帐号
         account: '',
@@ -91,6 +91,7 @@ export default {
                         console.log(info)
 
                         await dispatch('getDeptList', levelID)
+                        await dispatch('getPositionList')
                         // 获取当前子系统
                         await dispatch('ibps/system/loadSystem', null, {
                             root: true
@@ -184,12 +185,19 @@ export default {
          * 获取所有系统部门信息
          */
         getDeptList ({ state, dispatch }, levelID) {
-            const sql = `select ID_ as positionId,NAME_ as positionName FROM ibps_party_org WHERE LEVEL_ID_='${levelID}'`
-            console.log(sql)
+            const sql = `select a.ID_ as positionId,a.NAME_ as positionName,b.PATH_ as path_id FROM ibps_party_org a left join ibps_party_entity b on a.ORG_ALIAS_=b.PARTY_ALIAS_ WHERE a.LEVEL_ID_='${levelID}' and b.PARTY_TYPE_='org'`
             request('sql', sql).then(res => {
                 const { data = [] } = res.variables || {}
-                console.log(data)
-
+                // 将路径id 转 路径名
+                data.forEach(i => {
+                    const pathIdArr = i.path_id.split('.').filter(item => item) || []
+                    const pathNameArr = []
+                    pathIdArr.forEach(id => {
+                        const t = data.find(item => item.positionId === id)
+                        t && pathNameArr.push(t.positionName)
+                    })
+                    i.path_name = pathNameArr.join('.')
+                })
                 dispatch('ibps/param/setDeptList', data, {
                     root: true
                 })
@@ -198,6 +206,31 @@ export default {
                 alert('获取所有部门信息失败!')
             })
         },
+        /**
+         * 获取所有系统岗位信息
+         */
+        getPositionList ({ state, dispatch }) {
+            const sql = `select a.ID_ as positionId,a.NAME_ as positionName,a.POS_ALIAS_ as alias,b.PATH_ as path_id FROM ibps_party_position a left join ibps_party_entity b on a.POS_ALIAS_=b.PARTY_ALIAS_ WHERE b.PARTY_TYPE_='position'`
+            request('sql', sql).then(res => {
+                const { data = [] } = res.variables || {}
+                // 将路径id 转 路径名
+                data.forEach(i => {
+                    const pathIdArr = i.path_id.split('.').filter(item => item) || []
+                    const pathNameArr = []
+                    pathIdArr.forEach(id => {
+                        const t = data.find(item => item.positionId === id)
+                        t && pathNameArr.push(t.positionName)
+                    })
+                    i.path_name = pathNameArr.join('.')
+                })
+                dispatch('ibps/param/setPositionList', data, {
+                    root: true
+                })
+            }).catch(error => {
+                console.log(error)
+                alert('获取所有岗位信息失败!')
+            })
+        },
         /**
          * 获取切换用户账号
          * @param {*} param0

+ 4 - 4
src/views/platform/org/employee/edit/index.vue

@@ -26,14 +26,14 @@
                     @input="data => employee = data"
                 />
             </el-tab-pane>
-            <!-- <el-tab-pane label="扩展属性" name="ext-attr">
+            <el-tab-pane label="扩展属性" name="ext-attr">
                 <ext-attr
                     ref="attrInfo"
                     :readonly="readonly"
                     :data="employee.attrItemList"
                     @input="data => employee.attrItemList = data"
                 />
-            </el-tab-pane> -->
+            </el-tab-pane>
             <el-tab-pane
                 v-if="!infoIncludes('org-info')"
                 label="组织信息"
@@ -49,7 +49,7 @@
                 />
             </el-tab-pane>
 
-            <!-- <el-tab-pane label="岗位信息" name="position-info">
+            <el-tab-pane label="岗位信息" name="position-info">
                 <position-info
                     ref="positionInfo"
                     :span="span"
@@ -58,7 +58,7 @@
                     :data="employee.posItemList"
                     @input="data => employee.posItemList = data"
                 />
-            </el-tab-pane> -->
+            </el-tab-pane>
             <el-tab-pane v-if="!infoIncludes('role-info')"  label="角色信息" name="role-info">
                 <!-- <span slot="label">角色信息
                     <el-tooltip

+ 2 - 1
src/views/platform/org/employee/edit/position-info.vue

@@ -111,7 +111,8 @@ export default {
       treeData: [],
       posItemList: [],
       height: document.clientHeight,
-      checkStrictly: true
+      checkStrictly: true,
+      defaultTreeData: []
     }
   },
   computed: {

+ 303 - 32
src/views/platform/org/employee/list.vue

@@ -1,11 +1,36 @@
 <template>
     <ibps-container type="full" class="page">
-        <ibps-crud ref="crud" style="width: 100%" :height="height" :data="listData" :toolbars="listConfig.toolbars" :search-form="listConfig.searchForm" :pk-key="pkKey" :columns="listConfig.columns" :row-handle="listConfig.rowHandle" :pagination="pagination" :loading="loading" display-field="用户管理" :display-field-data="listConfig.displayFieldData" @display-field-change="handleDisplayField" @header-dragend="handleHeaderDragend" @action-event="handleAction" @sort-change="handleSortChange" @pagination-change="handlePaginationChange" />
+        <ibps-crud
+            ref="crud"
+            style="width: 100%"
+            :height="height"
+            :data="listData"
+            :toolbars="listConfig.toolbars"
+            :search-form="listConfig.searchForm"
+            :pk-key="pkKey"
+            :columns="listConfig.columns"
+            :row-handle="listConfig.rowHandle"
+            :pagination="pagination"
+            :loading="loading"
+            display-field="用户管理"
+            :display-field-data="listConfig.displayFieldData"
+            @display-field-change="handleDisplayField"
+            @header-dragend="handleHeaderDragend"
+            @action-event="handleAction"
+            @sort-change="handleSortChange"
+            @pagination-change="handlePaginationChange"
+        />
         <!-- 新增、编辑、明细 -->
-        <edit :id="editId" :title="title" :formType="formType" :visible="dialogFormVisible" :readonly="readonly" :span="span" @dialog-callback="search" @close="(visible) => (dialogFormVisible = visible)" />
+        <edit :id="editId" :title="title" :form-type="formType" :visible="dialogFormVisible" :readonly="readonly" :span="span" @dialog-callback="search" @close="(visible) => (dialogFormVisible = visible)" />
         <!-- 重置密码 -->
         <change-password :ids="changePasswordIds" :visible="changePasswordVisible" :title="$t('platform.org.employee.change-password.resetPassword')" is-reset :reg-open="true" @dialog-callback="search" @close="(visible) => (changePasswordVisible = visible)" />
         <more-search ref="moreSearch" :title="moreSearchTitle" :visible="dialogMoreSearchVisible" party-type="employee" @callback="search" @close="(visible) => (dialogMoreSearchVisible = visible)" @action-event="handleMoreSearchAction" />
+        <import-table
+            :visible="importTableDialogVisible"
+            title="导入"
+            @close="(visible) => (importTableDialogVisible = visible)"
+            @action-event="handleImportTableActionEvent"
+        />
     </ibps-container>
 </template>
 
@@ -19,15 +44,23 @@ import ChangePassword from './change-password'
 import CustomDataDisplayMixin from '@/business/platform/system/mixins/customDataDisplay'
 import MoreSearch from './more-search'
 import curdPost from '@/business/platform/form/utils/custom/joinCURD.js'
+import importTable from '@/business/platform/form/formrender/dynamic-form/components/import-table'
+import IbpsImport from '@/plugins/import'
+import { queryRoleScope } from '@/api/platform/org/role'
+import { create } from '@/api/platform/org/employee'
+import { encryptByAes } from '@/utils/encrypt'
 export default {
     components: {
         Edit,
         ChangePassword,
-        MoreSearch
+        MoreSearch,
+        importTable
     },
     mixins: [CustomDataDisplayMixin],
-    data() {
+    data () {
         return {
+            defaultPwd: 'ISO17025',
+            importTableDialogVisible: false,
             height: document.clientHeight,
             title: '',
             moreSearchTitle: '更多查询',
@@ -52,7 +85,8 @@ export default {
                     { key: 'add' },
                     { key: 'edit' },
                     { key: 'remove' },
-                    { key: 'changePassword', label: this.$t('platform.org.employee.button.changePassword'), icon: 'el-icon-refresh' }
+                    { key: 'changePassword', label: this.$t('platform.org.employee.button.changePassword'), icon: 'el-icon-refresh' },
+                    { key: 'import' }
                     // { key: 'more', icon: 'ibps-icon-ellipsis-h' }
                 ],
                 searchForm: {
@@ -90,7 +124,7 @@ export default {
                 columns: [
                     { prop: 'name', label: this.$t('platform.org.employee.prop.name'), width: 120 },
                     { prop: 'account', label: this.$t('platform.org.employee.prop.account'), width: 150 },
-                    //{ prop: 'wcAccount', label: this.$t('platform.org.employee.prop.wcAccount'),width:120},
+                    // { prop: 'wcAccount', label: this.$t('platform.org.employee.prop.wcAccount'),width:120},
                     { prop: 'orgName', label: this.$t('platform.org.employee.prop.orgPath'), sortable: false, width: 250 },
                     { prop: 'qq', label: '客户单位名称', width: 250 },
                     { prop: 'status', label: this.$t('platform.org.employee.prop.status'), tags: statusOptions, width: 100 },
@@ -197,7 +231,7 @@ export default {
             dialogMoreSearchVisible: false
         }
     },
-    created() {
+    created () {
         this.getOrg()
         this.loadData()
         this.loadDisplayField()
@@ -210,7 +244,7 @@ export default {
             switchUser: 'ibps/user/switchUser'
         }),
         // 加载数据
-        loadData() {
+        loadData () {
             this.loading = true
             queryPageList(this.getSearcFormData())
                 .then((response) => {
@@ -224,7 +258,7 @@ export default {
         /**
          * 获取格式化参数
          */
-        getSearcFormData() {
+        getSearcFormData () {
             const params = this.$refs['crud'] ? this.$refs['crud'].getSearcFormData() : {}
             if (this.moreSearchParams) {
                 Object.assign(params, this.moreSearchParams)
@@ -234,14 +268,14 @@ export default {
         /**
          * 处理分页事件
          */
-        handlePaginationChange(page) {
+        handlePaginationChange (page) {
             ActionUtils.setPagination(this.pagination, page)
             this.loadData()
         },
         /**
          * 处理排序
          */
-        handleSortChange(sort) {
+        handleSortChange (sort) {
             ActionUtils.setSorts(this.sorts, sort)
             this.loadData()
         },
@@ -249,12 +283,12 @@ export default {
         /**
          * 获取显示字段
          */
-        loadDisplayField() {
+        loadDisplayField () {
             this.getCustomDataDisplay(this.listIdentity).then((data) => {
                 this.listConfig.displayFieldData = data
             })
         },
-        handleHeaderDragend(newWidth, oldWidth, column, event) {
+        handleHeaderDragend (newWidth, oldWidth, column, event) {
             const displayFieldData = this.listConfig.displayFieldData
             for (let i = 0; i < displayFieldData.length; i++) {
                 const displayField = displayFieldData[i]
@@ -273,7 +307,7 @@ export default {
         /**
          * 保存显示字段
          */
-        handleDisplayField(data, callback, hasMessage) {
+        handleDisplayField (data, callback, hasMessage) {
             this.saveCustomDataDisplay(data, this.listIdentity)
                 .then((response) => {
                     if (hasMessage) ActionUtils.success(response.message)
@@ -286,13 +320,13 @@ export default {
         /**
          * 查询
          */
-        search() {
+        search () {
             this.loadData()
         },
         /**
          * 处理按钮事件
          */
-        handleAction(buttonKey, position, selection, data) {
+        handleAction (buttonKey, position, selection, data) {
             switch (buttonKey) {
                 case 'search': // 查询
                     ActionUtils.setFirstPagination(this.pagination)
@@ -306,7 +340,7 @@ export default {
                 case 'edit': // 编辑
                     ActionUtils.selectedRecord(selection)
                         .then((id) => {
-                            this.handleEdit(id,false,'edit')
+                            this.handleEdit(id, false, 'edit')
                             this.title = this.$t('common.title.edit', { title: this.$t('platform.org.employee.title') })
                             this.span = 13
                         })
@@ -347,6 +381,9 @@ export default {
                 case 'switchUser': // 切换用户
                     this.handleSwitchUser(data.account)
                     break
+                case 'import':
+                    this.importTableDialogVisible = true
+                    break
                 default:
                     break
             }
@@ -354,10 +391,10 @@ export default {
         /**
          * 处理更多
          */
-        handleMoreSearchParams() {
+        handleMoreSearchParams () {
             this.dialogMoreSearchVisible = true
         },
-        handleMoreSearchAction(data) {
+        handleMoreSearchAction (data) {
             ActionUtils.setFirstPagination(this.pagination)
             this.moreSearchParams = data
             this.loadData()
@@ -365,7 +402,7 @@ export default {
         /**
          * 处理编辑
          */
-        handleEdit(editId, readonly = false,type = 'add') {
+        handleEdit (editId, readonly = false, type = 'add') {
             this.editId = editId || ''
             this.formType = type
             this.dialogFormVisible = true
@@ -374,30 +411,30 @@ export default {
         /**
          * 处理重置密码
          */
-        handlereChangePassword(ids) {
+        handlereChangePassword (ids) {
             this.changePasswordIds = ids
             this.changePasswordVisible = true
         },
-        handleRemove(ids) {
+        handleRemove (ids) {
             // 删除数据
             remove({ employeeIds: ids }).then((response) => {
                 ActionUtils.removeSuccessMessage()
                 this.search()
             })
         },
-        handleActived(id) {
+        handleActived (id) {
             active({ employeeId: id }).then((response) => {
                 ActionUtils.successMessage('激活成功!')
                 this.search()
             })
         },
-        handleDisable(id) {
+        handleDisable (id) {
             disable({ employeeId: id }).then((response) => {
                 ActionUtils.successMessage('禁用成功!')
                 this.search()
             })
         },
-        handleSwitchUser(username) {
+        handleSwitchUser (username) {
             this.switchUser(username).then(() => {
                 ActionUtils.successMessage('切换用户成功!')
                 // 由于已经加载过设置 需要清空缓存设置
@@ -406,19 +443,253 @@ export default {
                 this.$router.replace('/')
             })
         },
-        //获取组织的数据
-        getOrg(){
-            let sql = `select * FROM ibps_party_org ORDER BY field(ORG_ALIAS_,'szslhyyjtxbzljcsys','glc','zhgls','jcs','kh')`
+        // 获取组织的数据
+        getOrg () {
+            const sql = `select * FROM ibps_party_org ORDER BY field(ORG_ALIAS_,'szslhyyjtxbzljcsys','glc','zhgls','jcs','kh')`
             curdPost('sql', sql).then(res => {
-                if(res.state == '200'){
+                if (res.state == '200') {
                     const datas = res.variables.data
-                    datas.forEach((item,index) => {
-                        this.$set(item,'value',item.ID_)
-                        this.$set(item,'label',item.NAME_)
+                    datas.forEach((item, index) => {
+                        this.$set(item, 'value', item.ID_)
+                        this.$set(item, 'label', item.NAME_)
                     })
                     this.listConfig.searchForm.forms[3].options = datas
                 }
             })
+        },
+        setValue (data) {
+            return Object.values(data).reduce((obj, item) => {
+                obj[item] = ''
+                return obj
+            }, {})
+        },
+        getKeys (data) {
+            return data.reduce((obj, item) => {
+                obj[item.label] = item.name
+                return obj
+            }, {})
+        },
+        // 导入用户
+        handleImportTableActionEvent (file, options) {
+            this.loading = false
+            const column = {
+                account: '账号',
+                username: '姓名',
+                gender: '性别',
+                post: '职称',
+                number: '工号',
+                dept: '组织',
+                role: '角色',
+                position: '岗位',
+                email: '邮箱',
+                mobile: '手机号码',
+                address: '地址',
+                unit: '单位名称'
+                // mainDept: '主部门'
+            }
+            const importColumn = Object.keys(column).map(key => {
+                return {
+                    label: column[key],
+                    name: key
+                }
+            })
+            const importKeys = this.getKeys(importColumn)
+            const importValue = this.setValue(importKeys)
+            IbpsImport.xlsx(file, options).then(({ header, results }) => {
+                const list = []
+                results.forEach((item) => {
+                    const data = JSON.parse(JSON.stringify(importValue))
+                    for (const key in item) {
+                        if (importKeys[key]) {
+                            data[importKeys[key]] = item[key]
+                        }
+                    }
+                    list.push(data)
+                })
+                this.importTableDialogVisible = false
+                this.handleImportData(list)
+            })
+        },
+        getRoleList () {
+            return new Promise((resolve, reject) => {
+                queryRoleScope({
+                    parameters: [],
+                    requestPage: {
+                        pageNo: 1,
+                        limit: 2000
+                    },
+                    sorts: []
+                }).then(response => {
+                    resolve(response.data.dataResult || [])
+                }).catch(error => {
+                    reject(error)
+                })
+            })
+        },
+        // 组装导入数据
+        async handleImportData (list) {
+            const { deptList = [], positionList = [] } = this.$store.getters || {}
+            // const hasError = list.some(i => !i.dept || !i.role)
+            // if (hasError) {
+            //     return this.$message.error('存在【组织】或【角色】异常的数据,请检查后再尝试!')
+            // }
+            console.log(list)
+            const roleList = await this.getRoleList()
+            const roleItem = {
+                pk: '',
+                ip: null,
+                createBy: null,
+                createTime: null,
+                updateBy: null,
+                updateTime: null,
+                tenantId: null,
+                dataStatus: null,
+                dbType: null,
+                dsAlias: null,
+                partyType: null,
+                alias: null,
+                parentId: '266946423468851203',
+                path: null,
+                depth: null,
+                sn: null,
+                roleType: '普通员工',
+                subSystemId: '266946423468851203',
+                subSystemName: '深圳市金源信通17025实验室',
+                subSystemAlias: null,
+                icon: null,
+                type: 'role',
+                nocheck: false,
+                chkDisabled: false,
+                click: true,
+                title: '',
+                open: 'true',
+                source: '自有'
+            }
+            const posItem = {
+                'pk': '',
+                'ip': null,
+                'createBy': null,
+                'createTime': null,
+                'updateBy': null,
+                'updateTime': null,
+                'tenantId': null,
+                'dataStatus': null,
+                'dbType': null,
+                'dsAlias': null,
+                'partyType': null,
+                'parentId': null,
+                'depth': null,
+                'sn': null,
+                'icon': null,
+                'type': 'position',
+                'nocheck': false,
+                'chkDisabled': false,
+                'click': true,
+                'open': 'true',
+                'hasChild': false
+            }
+            const createParams = []
+
+            for (let i = 0; i < list.length; i++) {
+                const item = list[i]
+                const temp = deptList.find(i => i.positionName === item.dept.trim().replace(/\r/g, ''))
+                const userItem = {
+                    id: '',
+                    account: item.account,
+                    password: encryptByAes(this.defaultPwd, 'pwd'),
+                    isSuper: 'N',
+                    name: item.username,
+                    status: 'actived',
+                    gender: item.gender === '男' ? 'male' : 'female',
+                    email: item.email,
+                    photo: '',
+                    mobile: item.mobile,
+                    createTime: '',
+                    attrItemList: [],
+                    groupID: temp?.positionId || '',
+                    userGroupItemList: [],
+                    orgItem: {
+                        id: temp?.positionId || '',
+                        name: temp?.positionName || '',
+                        pathName: temp?.path_name || ''
+                    },
+                    wxyhId: '',
+                    jiNengZhiCheng: 'inside',
+                    qq: item.unit,
+                    jianDingZiGeZ: item.number,
+                    address: item.address
+                }
+                const roleName = item.role.split('\n')
+                const deptName = item.position.split('\n')
+                const roleItemList = []
+                const posItemList = []
+                roleName.forEach(r => {
+                    const temp = roleList.find(i => i.name === r.trim().replace(/\r/g, ''))
+                    if (temp) {
+                        roleItemList.push({
+                            ...roleItem,
+                            name: r,
+                            id: temp.id,
+                            roleNote: temp.roleNote,
+                            roleAlias: temp.roleAlias
+                        })
+                    }
+                })
+                deptName.map(d => {
+                    const temp = positionList.find(i => i.positionName === d.trim().replace(/\r/g, ''))
+                    if (temp) {
+                        posItemList.push({
+                            ...posItem,
+                            name: temp.positionName || '',
+                            id: temp.positionId || '',
+                            alias: temp.alias || '',
+                            path: temp.path_id || '',
+                            title: temp.positionName || ''
+                        })
+                    }
+                })
+                const user = {
+                    ...userItem,
+                    positions: posItemList.map(i => i.id).join(','),
+                    job: roleItemList.map(i => i.id).join(','),
+                    posItemList,
+                    roleItemList
+                }
+                const employee = {
+                    partyEmployeePo: user,
+                    user,
+                    positionVoList: posItemList.map(p => ({
+                        id: p.id,
+                        name: p.name,
+                        isMainPost: false,
+                        isPrincipal: false
+                    })),
+                    roleVoList: roleItemList.map(r => ({
+                        id: r.id,
+                        name: r.name,
+                        subSystemName: r.subSystemName,
+                        source: r.source,
+                        canDelete: true
+                    })),
+                    attrValueVoList: [],
+                    userGroupPoList: []
+                }
+                createParams.push(employee)
+            }
+            console.log(createParams)
+            this.createEmployee(createParams)
+        },
+        createEmployee (paramList) {
+            if (!paramList || !paramList.length) {
+                this.search()
+                return
+            }
+            create(paramList.shift()).then(res => {
+                this.createEmployee(paramList)
+            })
+            // paramList.forEach(vo => {
+            //     create(vo)
+            // })
         }
     }
 }