项目对比,完善数据用

main
yanzai 5 months ago
parent 354dcf5b0c
commit be63ae2ab2

@ -56,10 +56,6 @@ class PlanListController extends Controller
}
}
return \Yz::Return(false, '已有重复的计划明细,禁止创建!' . $msg . '已存在相同记录,</br>存在于:</br>' . $msglist . '</br>对应记录Id为' . $msgIds . '</br>请先删除后再操作', $checkList);
}
//查询勾选的时间范围内所有的节假日

@ -0,0 +1,122 @@
<?php
namespace App\Http\Controllers\API;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
class ItemDuiBiController extends Controller
{
public function compareWithTxt(Request $request)
{
try {
// 1. 读取并解析TXT文件
$filePath = storage_path('app/medical_items.txt');
if (!File::exists($filePath)) {
return view('compare-result', [
'error' => 'TXT文件不存在请检查 storage/app/medical_items.txt'
]);
}
$fileContent = File::get($filePath);
$txtItems = json_decode($fileContent, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return view('compare-result', [
'error' => 'TXT文件不是有效的JSON格式' . json_last_error_msg()
]);
}
// 提取TXT中的项目并按名称分组保留完整信息
$txtItemsGrouped = collect($txtItems)
->filter(function($item) {
return !empty($item['itemName']);
})
->groupBy('itemName')
->map(function($group) {
// 每个名称只保留第一条记录的信息
return $group->first();
});
// 提取TXT中的itemName
$txtNames = $txtItemsGrouped->keys()->sort()->values()->all();
// 2. 从数据库查询项目表名s_check_item
$dbItems = DB::table('s_check_item')
->distinct()
->where(['is_del' => 0,'item_class_id'=>4])
->whereNotNull('item_name')
->get(['id', 'item_name'])
->keyBy('item_name'); // 按名称作为键
$dbNames = $dbItems->keys()->sort()->values()->all();
// 3. 数据比对
$txtCollection = collect($txtNames);
$dbCollection = collect($dbNames);
$onlyInTxt = $txtCollection->diff($dbCollection)->all();
$onlyInDb = $dbCollection->diff($txtCollection)->all();
$inBothNames = $txtCollection->intersect($dbCollection)->all();
// 4. 处理两者都存在的项目,关联设备信息
$inBothWithDevices = [];
foreach ($inBothNames as $name) {
// 获取TXT中的scheduleName
$txtItem = $txtItemsGrouped->get($name);
$scheduleNames = !empty($txtItem['scheduleName'])
? explode(',', $txtItem['scheduleName'])
: [];
// 去除空格并过滤空值
$scheduleNames = array_filter(array_map('trim', $scheduleNames));
// 获取数据库项目ID
$checkItem = $dbItems->get($name);
$checkItemId = $checkItem ? $checkItem->id : null;
// 查询匹配的设备ID
$deviceIds = [];
if (!empty($scheduleNames)) {
$devices = DB::table('s_devices')
->whereIn('device_name', $scheduleNames)
->get(['id', 'device_name']);
$deviceIds = $devices->pluck('id')->all();
}
$inBothWithDevices[] = [
'name' => $name,
'check_item_id' => $checkItemId,
'schedule_names' => $scheduleNames,
'device_ids' => $deviceIds,
'device_count' => count($deviceIds)
];
}
// 5. 传递数据到视图
return view('compare-result', [
'summary' => [
'txt_total' => count($txtNames),
'db_total' => count($dbNames),
'only_in_txt_count' => count($onlyInTxt),
'only_in_db_count' => count($onlyInDb),
'in_both_count' => count($inBothNames)
],
'onlyInTxt' => $onlyInTxt,
'onlyInDb' => $onlyInDb,
'inBoth' => $inBothWithDevices,
'error' => null
]);
} catch (\Exception $e) {
return view('compare-result', [
'error' => '比对失败:' . $e->getMessage()
]);
}
}
}

@ -52,6 +52,10 @@ class Log
return $response;
}
public function terminate(Request $request, $response)
{
}
public static function getTrustedProxiesIp(){ //获取用户真实ip
\request()->setTrustedProxies(\request()->getClientIps(),Request::HEADER_X_FORWARDED_FOR);

@ -142,7 +142,7 @@ WHERE
$planPatientType = explode(",", $p->patient_type);
if (!empty(array_diff($commPatientType, $planPatientType))) {
continue;
}
}
//过期的排在后面
$time = $p->date . ' ' . $p->end_time;
if ($time > $nowtime) {

@ -0,0 +1,204 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>项目比对结果</title>
<script src="https://cdn.tailwindcss.com"></script>
<link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
<style>
.table-container {
overflow-x: auto;
}
table {
min-width: 600px;
}
.tooltip {
position: relative;
display: inline-block;
}
.tooltip .tooltiptext {
visibility: hidden;
width: 200px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -100px;
opacity: 0;
transition: opacity 0.3s;
font-size: 0.8em;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style>
</head>
<body class="bg-gray-50 p-4 md:p-8">
<div class="max-w-7xl mx-auto bg-white rounded-lg shadow-md p-6">
<h1 class="text-2xl font-bold text-gray-800 mb-6">项目比对结果</h1>
<!-- 错误提示 -->
@if($error)
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-6">
<i class="fa fa-exclamation-circle mr-2"></i>{{ $error }}
</div>
@else
<!-- 统计摘要 -->
<div class="bg-blue-50 border border-blue-200 rounded-lg p-4 mb-8">
<h2 class="text-lg font-semibold text-blue-800 mb-2">
<i class="fa fa-bar-chart mr-2"></i>统计摘要
</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4">
<div class="flex justify-between">
<span class="text-gray-600">TXT文件总项目数</span>
<span class="font-medium">{{ $summary['txt_total'] }}</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">数据库总项目数:</span>
<span class="font-medium">{{ $summary['db_total'] }}</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">仅TXT存在</span>
<span class="font-medium text-orange-600">{{ $summary['only_in_txt_count'] }}</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">仅数据库存在:</span>
<span class="font-medium text-purple-600">{{ $summary['only_in_db_count'] }}</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">两者都存在:</span>
<span class="font-medium text-green-600">{{ $summary['in_both_count'] }}</span>
</div>
</div>
</div>
<!-- 仅TXT存在的项目 -->
<div class="mb-8">
<h2 class="text-xl font-semibold text-orange-600 mb-3">
<i class="fa fa-file-text-o mr-2"></i>仅TXT文件中存在的项目{{ count($onlyInTxt) }}项)
</h2>
<div class="table-container">
<table class="min-w-full bg-white border border-gray-200">
<thead>
<tr class="bg-gray-100">
<th class="py-2 px-4 border-b text-left">序号</th>
<th class="py-2 px-4 border-b text-left">项目名称</th>
</tr>
</thead>
<tbody>
@foreach($onlyInTxt as $index => $name)
<tr class="{{ $index % 2 == 0 ? 'bg-white' : 'bg-gray-50' }}">
<td class="py-2 px-4 border-b">{{ $index + 1 }}</td>
<td class="py-2 px-4 border-b">{{ $name }}</td>
</tr>
@endforeach
@if(empty($onlyInTxt))
<tr>
<td colspan="2" class="py-3 px-4 text-center text-gray-500">无数据</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
<!-- 仅数据库存在的项目 -->
<div class="mb-8">
<h2 class="text-xl font-semibold text-purple-600 mb-3">
<i class="fa fa-database mr-2"></i>仅数据库中存在的项目({{ count($onlyInDb) }}项)
</h2>
<div class="table-container">
<table class="min-w-full bg-white border border-gray-200">
<thead>
<tr class="bg-gray-100">
<th class="py-2 px-4 border-b text-left">序号</th>
<th class="py-2 px-4 border-b text-left">项目名称</th>
</tr>
</thead>
<tbody>
@foreach($onlyInDb as $index => $name)
<tr class="{{ $index % 2 == 0 ? 'bg-white' : 'bg-gray-50' }}">
<td class="py-2 px-4 border-b">{{ $index + 1 }}</td>
<td class="py-2 px-4 border-b">{{ $name }}</td>
</tr>
@endforeach
@if(empty($onlyInDb))
<tr>
<td colspan="2" class="py-3 px-4 text-center text-gray-500">无数据</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
<!-- 两者都存在的项目(带设备关联) -->
<div>
<h2 class="text-xl font-semibold text-green-600 mb-3">
<i class="fa fa-exchange mr-2"></i>两者都存在的项目({{ count($inBoth) }}项)
</h2>
<div class="table-container">
<table class="min-w-full bg-white border border-gray-200">
<thead>
<tr class="bg-gray-100">
<th class="py-2 px-4 border-b text-left">序号</th>
<th class="py-2 px-4 border-b text-left">项目名称</th>
<th class="py-2 px-4 border-b text-left">s_check_item ID</th>
<th class="py-2 px-4 border-b text-left">设备数量</th>
<th class="py-2 px-4 border-b text-left">设备ID</th>
<th class="py-2 px-4 border-b text-left">TXT中的scheduleName</th>
</tr>
</thead>
<tbody>
@foreach($inBoth as $index => $item)
<tr class="{{ $index % 2 == 0 ? 'bg-white' : 'bg-gray-50' }}">
<td class="py-2 px-4 border-b">{{ $index + 1 }}</td>
<td class="py-2 px-4 border-b">{{ $item['name'] }}</td>
<td class="py-2 px-4 border-b">{{ $item['check_item_id'] ?: '-' }}</td>
<td class="py-2 px-4 border-b">{{ $item['device_count'] }}</td>
<td class="py-2 px-4 border-b">
@if(!empty($item['device_ids']))
<div class="tooltip">
{{ implode(', ', $item['device_ids']) }}
@if(count($item['device_ids']) > 3)
<span class="tooltiptext">共 {{ count($item['device_ids']) }} 个设备ID</span>
@endif
</div>
@else
-
@endif
</td>
<td class="py-2 px-4 border-b">
@if(!empty($item['schedule_names']))
<div class="tooltip">
{{ implode(', ', $item['schedule_names']) }}
@if(count($item['schedule_names']) > 2)
<span class="tooltiptext">共 {{ count($item['schedule_names']) }} 个地点</span>
@endif
</div>
@else
-
@endif
</td>
</tr>
@endforeach
@if(empty($inBoth))
<tr>
<td colspan="6" class="py-3 px-4 text-center text-gray-500">无数据</td>
</tr>
@endif
</tbody>
</table>
</div>
</div>
@endif
</div>
</body>
</html>

@ -163,4 +163,3 @@ Route::group(['middleware'=>['log']],function () {
Route::any('/PacsSaveApplyInfo','App\Http\Controllers\API\Third\CSharpController@PacsSaveApplyInfo' )->middleware('log');;//给pacs推送检查申请单
Route::any('/PacsCancelApplyInfo','App\Http\Controllers\API\Third\CSharpController@PacsCancelApplyInfo' )->middleware('log');;//给pacs推送取消检查申请单

@ -39,4 +39,5 @@ Route::get('/yiji', function (Request $request) {
//cas 登录
Route::get('/casLogin', 'App\Http\Controllers\API\CAS\CasLoginController@login');
Route::get('/compare-items', 'App\Http\Controllers\API\ItemDuiBiController@compareWithTxt')
->name('compare.items');

Loading…
Cancel
Save