浏览代码

Merge branch 'refs/heads/dev' into R1

peterguo 2 月之前
父节点
当前提交
f384cdbdc3

+ 49 - 0
app/Admin/Controllers/AuthController.php

@@ -3,8 +3,57 @@
 namespace App\Admin\Controllers;
 
 use Encore\Admin\Controllers\AuthController as BaseAuthController;
+use GuzzleHttp\Client;
+use Illuminate\Support\Facades\Auth;
 
 class AuthController extends BaseAuthController
 {
+    /**
+     * 获取4s系统的访问令牌
+     *
+     * @return \Illuminate\Http\JsonResponse
+     */
+    public function get4sAccessToken()
+    {
+        try {
+            $user = Auth::user();
+            
+            $client = new Client();
+            $response = $client->post('http://newlinker.net:18001/login/pc', [
+                'query' => [
+                    'username' => $user->username,
+                    'password' => $user->password
+                ],
+                'http_errors' => false
+            ]);
 
+            $result = json_decode($response->getBody()->getContents(), true);
+
+            if ($result['success'] && $result['code'] == 200) {
+                return response()->json([
+                    'success' => true,
+                    'code' => 200,
+                    'message' => '成功',
+                    'data' => [
+                        'token' => $result['data']['token']
+                    ]
+                ]);
+            }
+
+            return response()->json([
+                'success' => false,
+                'code' => $result['code'] ?? 500,
+                'message' => $result['message'] ?? '获取token失败',
+                'data' => null
+            ]);
+
+        } catch (\Exception $e) {
+            return response()->json([
+                'success' => false,
+                'code' => 500,
+                'message' => '获取token失败: ' . $e->getMessage(),
+                'data' => null
+            ]);
+        }
+    }
 }

+ 25 - 7
app/Http/Controllers/API/FolderController.php

@@ -408,29 +408,47 @@ class FolderController extends Controller
         $objectType = $request->get("object_type");
         $objectId = $request->get("object_id");
         $name=$request->get('name');
+        $docStages = $request->get('doc_stage', []); // 支持多选
+        $docTypes = $request->get('doc_type', []); // 支持多选
+        $namingRuleIds = $request->get('naming_rule_id', []); // 支持多选
 
         $folderObjectType = FolderObjectType::from($objectType);
 
         $folderObjectType->modelBuilderAllowed()->findOrFail($objectId);
 
-        $objectWhere = ['object_type' => $objectType, 'object_id' => $objectId,];
+        $objectWhere = ['object_type' => $objectType, 'object_id' => $objectId];
 
         $folders = Folder::query()
             ->where($objectWhere)
             ->where('name','like',"%$name%")
             ->get();
 
-        $newFolders=$folders?$service->folderFormat($folders):[];
+        $newFolders = $folders ? $service->folderFormat($folders) : [];
 
-        $file=File::query()
+        $fileQuery = File::query()
             ->with('bimFile')
             ->where($objectWhere)
             ->where('title','like',"%$name%")
-            ->where("is_latest_version", 1)
-            ->get();
-        $folderCount=count($newFolders)+1;
-        $newFiles=$file?$service->filesFormat($file,$folderCount):[];
+            ->where("is_latest_version", 1);
+        
+        // 添加doc_stage多选过滤
+        if (!empty($docStages)) {
+            $fileQuery->whereIn('doc_stage', $docStages);
+        }
+
+        // 添加doc_type多选过滤
+        if (!empty($docTypes)) {
+            $fileQuery->whereIn('doc_type', $docTypes);
+        }
+
+        // 添加naming_rule_id多选过滤
+        if (!empty($namingRuleIds)) {
+            $fileQuery->whereIn('naming_rule_id', $namingRuleIds);
+        }
 
+        $file = $fileQuery->get();
+        $folderCount = count($newFolders) + 1;
+        $newFiles = $file ? $service->filesFormat($file, $folderCount) : [];
 
         return $this->success([
             'data' => [

+ 34 - 0
app/Http/Controllers/API/UserController.php

@@ -18,6 +18,8 @@ use App\Models\Permission;
 use App\Models\Role;
 use App\Models\Scopes\CompanyScope;
 use App\Models\User;
+use GuzzleHttp\Client;
+use hisorange\BrowserDetect\Exceptions\Exception;
 use Illuminate\Contracts\Encryption\DecryptException;
 use Illuminate\Database\Query\Builder;
 use Illuminate\Http\Request;
@@ -206,6 +208,38 @@ class UserController extends Controller
 
     }
 
+    /**
+     * 获取4s系统的访问令牌
+     *
+     * @return \Illuminate\Http\JsonResponse
+     * @throws Exception
+     */
+    public function get4sAccessToken()
+    {
+        $user = Auth::user();
+        if (!$user->fs_password) {
+            return $this->badRequest('The user has not set a 4s password');
+        }
+        try {
+            $client = new Client();
+            $url = env("4sLoginUrl", "http://newlinker.net:18001/login/pc");
+            $response = $client->post($url, [
+                'query' => [
+                    'username' => $user->username,
+                    'password' => $user->fs_password
+                ],
+                'http_errors' => false
+            ]);
+            $result = json_decode($response->getBody()->getContents(), true);
+            if ($result['code'] == 200 && $result['data']['token']) {
+                return $this->success(['token' => $result['data']['token']]);
+            } else {
+                return $this->badRequest('get 4s token error: '. $result['message']);
+            }
+        } catch (\Exception $e) {
+            return $this->badRequest('get 4s token error: ' . $e->getMessage());
+        }
+    }
 
 
 //    public function byDepartment(Request $request){

+ 2 - 1
routes/api.php

@@ -45,8 +45,9 @@ Route::middleware((function() {
         Route::post("/logout", [API\AuthController::class, "logout"]);
         Route::get("user/details", [API\UserController::class, 'details']);
         Route::get("user-items", [API\UserController::class, 'publicSearch']);
+        Route::get("user/get4sAccessToken", [API\UserController::class, 'get4sAccessToken']);
         Route::get("asset-tree",[API\AssetController::class, 'tree']);
-        Route::get("asset/{asset_id}/report",[API\AssetController::class, 'report']);
+        Route::get("asset/{asset_id}/reporst",[API\AssetController::class, 'report']);
         Route::get("asset-items",[API\AssetController::class, "publicSearch"]);
         Route::get("asset-group-items",[API\AssetGroupController::class, "publicSearch"]);
         Route::get("requirement-group-items",[API\RequirementGroupController::class, "publicSearch"]);