ソースを参照

人事组织结构同步

qiuenguang 1 年間 前
コミット
e9ff588a3b
1 ファイル変更82 行追加0 行削除
  1. 82 0
      application/api/controller/Synchronization.php

+ 82 - 0
application/api/controller/Synchronization.php

@@ -438,4 +438,86 @@ class Synchronization extends Api
             $this->success('人事资料同步成功');
         }
     }
+
+    /**
+     * 人事组织结构
+     * @return void
+     * @throws \think\Exception
+     * @throws \think\db\exception\BindParamException
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     * @throws \think\exception\PDOException
+     */
+    public function OrganizationalStructureData()
+    {
+        if ($this->request->isGet() === false){
+            $this->error('请求错误');
+        }
+        $db3 = \db()->connect(config('database.db3'));
+        $OrganizationalDataList = $db3->name('U8_01组织结构')
+            ->where('MES接收时间',null)
+            ->where('MES接收状态','0')
+            ->select();
+        if (empty($OrganizationalDataList)){
+            $this->success('未找到新的组织结构');
+        }
+        $i = 0;
+        foreach ($OrganizationalDataList as $key=>$value){
+            $data = [
+                '编号'=>$value['编号'],
+                '名称'=>$value['名称'],
+                '状态'=>$value['状态'],
+                'Sys_id'=>'[272/超级用户]',
+                'Sys_rq'=>date('Y-m-d H:i:s',time()),
+                'Mod_rq'=>'1900-01-01 00:00:00',
+                'U8UID'=>$value['U8_UID'],
+                'UNIQID'=>$value['UniqId'],
+            ];
+            $number = \db('人事_组织结构')
+                ->where('Uniqid',$value['UniqId'])
+                ->count();
+            if ($number === 0){
+                $sql = \db('人事_组织结构')->fetchSql(true)->insert($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+                    $sqlString = $db3->name('U8_01组织结构')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+                }
+            }else{
+                $sql = \db('人事_组织结构')
+                    ->fetchSql(true)
+                    ->where('UniqId',$value['UniqId'])
+                    ->update($data);
+                $res = \db()->query($sql);
+                if ($res === false){
+                    $i++;
+                }else{
+
+                    $sqlString = $db3->name('U8_01组织结构')
+                        ->where('UniqId', $value['UniqId'])
+                        ->fetchSql(true)
+                        ->update([
+                            'MES接收时间' => date('Y-m-d H:i:s', time()),
+                            'MES接收状态' => '1'
+                        ]);
+                    $db3->execute($sqlString);
+
+                }
+            }
+        }
+        if ($i !== 0){
+            $this->error('人事组织结构同步失败');
+        }else{
+            $this->success('人事组织结构同步成功');
+        }
+    }
 }