Skip to content

Commit

Permalink
feat: 添加sql数据补偿能力 (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
eryajf authored Feb 22, 2023
1 parent 42847c9 commit cd45da1
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 23 deletions.
8 changes: 8 additions & 0 deletions src/api/personnel/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,11 @@ export function syncOpenLdapDeptsApi(data) {
data
})
}
// 同步数据库的分组到ldap
export function syncSqlGroups(data) {
return request({
url: '/api/group/syncSqlGroups',
method: 'post',
data
})
}
9 changes: 9 additions & 0 deletions src/api/personnel/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,12 @@ export function syncOpenLdapUsersApi(data) {
data
})
}

// 同步Sql中的用户到ldap
export function syncSqlUsers(data) {
return request({
url: '/api/user/syncSqlUsers',
method: 'post',
data
})
}
2 changes: 1 addition & 1 deletion src/layout/components/AppMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default {
bottom: 0;
left: 0;
right: 0;
line-height: 45px;
line-height: 58px;
text-align: center;
border-top: 1px dashed #dcdfe6;
}
Expand Down
81 changes: 70 additions & 11 deletions src/views/personnel/group/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
<el-card class="container-card" shadow="always">
<el-form size="mini" :inline="true" :model="params" class="demo-form-inline">
<el-form-item label="名称">
<el-input v-model.trim="params.groupName" clearable placeholder="名称" @clear="search" />
<el-input style="width: 100px;" v-model.trim="params.groupName" clearable placeholder="名称" @clear="search" />
</el-form-item>
<el-form-item label="描述">
<el-input v-model.trim="params.remark" clearable placeholder="描述" @clear="search" />
<el-input style="width: 100px;" v-model.trim="params.remark" clearable placeholder="描述" @clear="search" />
</el-form-item>
<el-form-item label="同步状态">
<el-select style="width: 110px;" v-model.trim="params.syncState" clearable placeholder="同步状态" @change="search" @clear="search">
<el-option label="已同步" value="1" />
<el-option label="未同步" value="2" />
</el-select>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-search" type="primary" @click="search">查询</el-button>
Expand All @@ -20,18 +26,21 @@
<el-form-item>
<el-button :disabled="multipleSelection.length === 0" :loading="loading" icon="el-icon-delete" type="danger" @click="batchDelete">批量删除</el-button>
</el-form-item>
<el-form-item>
<el-button :disabled="multipleSelection.length === 0" :loading="loading" icon="el-icon-upload2" type="success" @click="batchSync">批量同步</el-button>
</el-form-item>
<br>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncOpenLdapDepts">同步原ldap部门</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncOpenLdapDepts">同步原ldap部门</el-button>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncDingTalkDepts">同步钉钉部门</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncDingTalkDepts">同步钉钉部门</el-button>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncFeiShuDepts">同步飞书部门</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncFeiShuDepts">同步飞书部门</el-button>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncWeComDepts">同步企业微信部门</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncWeComDepts">同步企业微信部门</el-button>
</el-form-item>
</el-form>

Expand All @@ -56,6 +65,11 @@
<el-button slot="reference" size="mini" icon="el-icon-delete" circle type="danger" />
</el-popconfirm>
</el-tooltip>
<el-tooltip v-if="scope.row.syncState == 2" class="delete-popover" content="同步" effect="dark" placement="top">
<el-popconfirm title="确定同步吗?" @onConfirm="singleSync(scope.row.ID)">
<el-button slot="reference" size="mini" icon="el-icon-upload2" circle type="success" />
</el-popconfirm>
</el-tooltip>
</template>
</el-table-column>
</el-table>
Expand All @@ -66,7 +80,10 @@
<el-input v-model.trim="dialogFormData.groupName" placeholder="名称(拼音)" />
</el-form-item>
<el-form-item label="分组类型" prop="groupType">
<el-input v-model.trim="dialogFormData.groupType" placeholder="分组类型:ou或cn(建议仅第一层为ou)" />
<el-select v-model.trim="dialogFormData.groupType" placeholder="建议仅第一层为ou,如果不确定,就用cn" style="width:100%">
<el-option label="cn[分组]" value="cn" />
<el-option label="ou[组织]" value="ou" />
</el-select>
</el-form-item>
<el-form-item label="上级分组" prop="parentId">
<treeselect
Expand Down Expand Up @@ -108,7 +125,7 @@
<script>
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { getGroupTree, groupAdd, groupUpdate, groupDel, syncDingTalkDeptsApi, syncWeComDeptsApi, syncFeiShuDeptsApi, syncOpenLdapDeptsApi } from '@/api/personnel/group'
import { getGroupTree, groupAdd, groupUpdate, groupDel, syncDingTalkDeptsApi, syncWeComDeptsApi, syncFeiShuDeptsApi, syncOpenLdapDeptsApi, syncSqlGroups } from '@/api/personnel/group'
import { Message } from 'element-ui'
export default {
Expand All @@ -133,6 +150,7 @@ export default {
params: {
groupName: undefined,
remark: undefined,
syncState: undefined,
pageNum: 1,
pageSize: 1000// 平常百姓人家应该不会有这么多数据吧,后台限制最大单次获取1000条
},
Expand All @@ -154,7 +172,8 @@ export default {
ID: '',
groupName: '',
parentId: 0,
groupType: undefined,
syncState:1,
groupType: '',
remark: ''
},
dialogFormRules: {
Expand Down Expand Up @@ -211,11 +230,11 @@ export default {
this.getTableData()
},
methods: {
// 查询
// // 查询
search() {
// 初始化表格数据
this.infoTableData = JSON.parse(JSON.stringify(this.tableData))
this.infoTableData = this.deal(this.infoTableData, node => node.groupName.includes(this.params.groupName) || node.remark.includes(this.params.remark))
this.infoTableData = this.deal(this.infoTableData, node => node.groupName.includes(this.params.groupName) || node.remark.includes(this.params.remark) || node.syncState.toString().includes(this.params.syncState))
},
resetData() {
this.infoTableData = JSON.parse(JSON.stringify(this.tableData))
Expand Down Expand Up @@ -363,6 +382,34 @@ export default {
})
})
},
// 批量同步
batchSync() {
this.$confirm('此操作批量同步数据到Ldap, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async res => {
this.loading = true
const groupIds = []
this.multipleSelection.forEach(x => {
groupIds.push(x.ID)
})
try {
await syncSqlGroups({ groupIds: groupIds }).then(res => {
this.judgeResult(res)
})
} finally {
this.loading = false
}
this.getTableData()
}).catch(() => {
Message({
showClose: true,
type: 'info',
message: '已取消同步'
})
})
},
// 表格多选
handleSelectionChange(val) {
Expand All @@ -381,6 +428,18 @@ export default {
}
this.getTableData()
},
// 单个同步
async singleSync(Id) {
this.loading = true
try {
await syncSqlGroups({ groupIds: [Id] }).then(res =>{
this.judgeResult(res)
})
} finally {
this.loading = false
}
this.getTableData()
},
// 分页
handleSizeChange(val) {
Expand Down
77 changes: 66 additions & 11 deletions src/views/personnel/user/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
<el-card class="container-card" shadow="always">
<el-form size="mini" :inline="true" :model="params" class="demo-form-inline">
<el-form-item label="用户名">
<el-input v-model.trim="params.username" clearable placeholder="用户名" @clear="search" />
<el-input style="width: 100px;" v-model.trim="params.username" clearable placeholder="用户名" @clear="search" />
</el-form-item>
<el-form-item label="昵称">
<el-input v-model.trim="params.nickname" clearable placeholder="昵称" @clear="search" />
<el-input style="width: 100px;" v-model.trim="params.nickname" clearable placeholder="昵称" @clear="search" />
</el-form-item>
<el-form-item label="手机号">
<el-input style="width: 120px;" v-model.trim="params.mobile" clearable placeholder="手机号" @clear="search" />
</el-form-item>
<el-form-item label="状态">
<el-select v-model.trim="params.status" clearable placeholder="状态" @change="search" @clear="search">
<el-select style="width: 100px;" v-model.trim="params.status" clearable placeholder="状态" @change="search" @clear="search">
<el-option label="正常" value="1" />
<el-option label="禁用" value="2" />
</el-select>
</el-form-item>
<el-form-item label="手机号">
<el-input v-model.trim="params.mobile" clearable placeholder="手机号" @clear="search" />
<el-form-item label="同步状态">
<el-select style="width: 100px;" v-model.trim="params.syncState" clearable placeholder="同步状态" @change="search" @clear="search">
<el-option label="已同步" value="1" />
<el-option label="未同步" value="2" />
</el-select>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-search" type="primary" @click="search">查询</el-button>
Expand All @@ -26,18 +32,21 @@
<el-form-item>
<el-button :disabled="multipleSelection.length === 0" :loading="loading" icon="el-icon-delete" type="danger" @click="batchDelete">批量删除</el-button>
</el-form-item>
<el-form-item>
<el-button :disabled="multipleSelection.length === 0" :loading="loading" icon="el-icon-upload2" type="success" @click="batchSync">批量同步</el-button>
</el-form-item>
<br>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncOpenLdapUsers">同步原ldap用户信息</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncOpenLdapUsers">同步原ldap用户信息</el-button>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncDingTalkUsers">同步钉钉用户信息</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncDingTalkUsers">同步钉钉用户信息</el-button>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncFeiShuUsers">同步飞书用户信息</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncFeiShuUsers">同步飞书用户信息</el-button>
</el-form-item>
<el-form-item>
<el-button :loading="loading" icon="el-icon-share" type="danger" @click="syncWeComUsers">同步企业微信用户信息</el-button>
<el-button :loading="loading" icon="el-icon-download" type="warning" @click="syncWeComUsers">同步企业微信用户信息</el-button>
</el-form-item>
</el-form>

Expand Down Expand Up @@ -67,7 +76,7 @@
<el-table-column show-overflow-tooltip sortable prop="userDn" label="DN" />
<el-table-column show-overflow-tooltip sortable prop="CreatedAt" label="创建时间" />
<el-table-column show-overflow-tooltip sortable prop="UpdatedAt" label="更新时间" />
<el-table-column fixed="right" label="操作" align="center" width="120">
<el-table-column fixed="right" label="操作" align="center" width="150">
<template slot-scope="scope">
<el-tooltip content="编辑" effect="dark" placement="top">
<el-button size="mini" icon="el-icon-edit" circle type="primary" @click="update(scope.row)" />
Expand All @@ -77,6 +86,11 @@
<el-button slot="reference" size="mini" icon="el-icon-delete" circle type="danger" />
</el-popconfirm>
</el-tooltip>
<el-tooltip v-if="scope.row.syncState == 2" class="delete-popover" content="同步" effect="dark" placement="top">
<el-popconfirm title="确定同步吗?" @onConfirm="singleSync(scope.row.ID)">
<el-button slot="reference" size="mini" icon="el-icon-upload2" circle type="success" />
</el-popconfirm>
</el-tooltip>
</template>
</el-table-column>
</el-table>
Expand Down Expand Up @@ -201,7 +215,7 @@
import JSEncrypt from 'jsencrypt'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import { getUsers, createUser, updateUserById, batchDeleteUserByIds, changeUserStatus, syncDingTalkUsersApi, syncWeComUsersApi, syncFeiShuUsersApi, syncOpenLdapUsersApi } from '@/api/personnel/user'
import { getUsers, createUser, updateUserById, batchDeleteUserByIds, changeUserStatus, syncDingTalkUsersApi, syncWeComUsersApi, syncFeiShuUsersApi, syncOpenLdapUsersApi, syncSqlUsers } from '@/api/personnel/user'
import { getRoles } from '@/api/system/role'
import { getGroupTree } from '@/api/personnel/group'
import { Message } from 'element-ui'
Expand Down Expand Up @@ -236,6 +250,7 @@ export default {
username: '',
nickname: '',
status: '',
syncState: '',
mobile: '',
pageNum: 1,
pageSize: 10
Expand Down Expand Up @@ -604,6 +619,34 @@ export default {
})
})
},
// 批量同步
batchSync() {
this.$confirm('此操作批量将数据库的用户同步到Ldap, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(async res => {
this.loading = true
const userIds = []
this.multipleSelection.forEach(x => {
userIds.push(x.ID)
})
try {
await syncSqlUsers({ userIds: userIds }).then(res =>{
this.judgeResult(res)
})
} finally {
this.loading = false
}
this.getTableData()
}).catch(() => {
Message({
showClose: true,
type: 'info',
message: '已取消同步'
})
})
},
// 监听 switch 开关 状态改变
async userStateChanged(userInfo) {
Expand Down Expand Up @@ -634,6 +677,18 @@ export default {
}
this.getTableData()
},
// 单个同步
async singleSync(Id) {
this.loading = true
try {
await syncSqlUsers({ userIds: [Id] }).then(res =>{
this.judgeResult(res)
})
} finally {
this.loading = false
}
this.getTableData()
},
showPwd() {
if (this.passwordType === 'password') {
Expand Down

0 comments on commit cd45da1

Please sign in to comment.