Browse Source

feat: sync with deleted status

ryanemax 7 months ago
parent
commit
3b32f2f991
1 changed files with 16 additions and 1 deletions
  1. 16 1
      server/cloud/authing/func-authing-org-sync.js

+ 16 - 1
server/cloud/authing/func-authing-org-sync.js

@@ -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',