|
@@ -43,8 +43,12 @@ async function syncOrganizationsFromAuthing(){
|
|
|
// console.log(departList)
|
|
|
console.log(departList?.length)
|
|
|
// return
|
|
|
- let insertRes = await InsertAllDepartment(departList)
|
|
|
+ let insertRes = await InsertAllDepartment(departList);
|
|
|
console.log(insertRes)
|
|
|
+ // 将所有不存在的部门,设置为isDeleted删除状态
|
|
|
+ try{
|
|
|
+ let deleteRes = await UpdateAllDeleteDepartment(departList);
|
|
|
+ }catch(err){}
|
|
|
return {code:200,count:departList?.length,message:`成功导入${departList?.length}条`}
|
|
|
}
|
|
|
|
|
@@ -57,6 +61,17 @@ async function syncOrganizationsFromAuthing(){
|
|
|
}
|
|
|
module.exports.syncOrganizationsFromAuthing = syncOrganizationsFromAuthing
|
|
|
|
|
|
+
|
|
|
+async function UpdateAllDeleteDepartment(departList){
|
|
|
+ let existsIdList = departList.map(depart=>depart?.departmentId)
|
|
|
+ existsIdList = existsIdList.filter(item=>item)
|
|
|
+ let sql = `
|
|
|
+ UPDATE "Department" SET "isDeleted" = true
|
|
|
+ WHERE "objectId" <> ALL ($1);
|
|
|
+ `
|
|
|
+ let result = await pgClient().any(sql,[existsIdList]);
|
|
|
+ return result
|
|
|
+}
|
|
|
async function InsertAllDepartment(departList){
|
|
|
// {
|
|
|
// departmentId: '66868df17adf199d1c77875d',
|