|
|
@@ -29,6 +29,7 @@ class Facility extends Api
|
|
|
|
|
|
|
|
|
/**
|
|
|
+ * 缓存及时
|
|
|
* 获取指定目录所有图片
|
|
|
*/
|
|
|
public function getPreviewimg()
|
|
|
@@ -46,124 +47,127 @@ class Facility extends Api
|
|
|
return json(['code' => 1, 'msg' => '原图目录不存在']);
|
|
|
}
|
|
|
|
|
|
- // 设置缓存路径
|
|
|
- $cacheDir = RUNTIME_PATH . 'image_cache/';
|
|
|
- if (!is_dir($cacheDir)) {
|
|
|
- mkdir($cacheDir, 0755, true);
|
|
|
- }
|
|
|
- $cacheFile = $cacheDir . md5($relativePath) . '.json';
|
|
|
-
|
|
|
- // 判断缓存文件是否存在,并且最后修改时间在1小时(3600秒)以内
|
|
|
- if (file_exists($cacheFile) && time() - filemtime($cacheFile) < 3600) {
|
|
|
- $imageInfoMap = json_decode(file_get_contents($cacheFile), true);
|
|
|
- } else {
|
|
|
- // 没有缓存或缓存过期,重新扫描目录
|
|
|
- $allImages = glob($fullPath . '/*.{jpg,jpeg,png}', GLOB_BRACE);
|
|
|
- $imageInfoMap = [];
|
|
|
- foreach ($allImages as $imgPath) {
|
|
|
- $relative = str_replace('\\', '/', trim(str_replace($basePath, '', $imgPath), '/'));
|
|
|
- $info = @getimagesize($imgPath);
|
|
|
- $imageInfoMap[$relative] = [
|
|
|
- 'width' => $info[0] ?? 0,
|
|
|
- 'height' => $info[1] ?? 0,
|
|
|
- 'size_kb' => round(filesize($imgPath) / 1024, 2),
|
|
|
- 'created_time' => date('Y-m-d H:i:s', filectime($imgPath))
|
|
|
- ];
|
|
|
- }
|
|
|
- file_put_contents($cacheFile, json_encode($imageInfoMap));
|
|
|
- }
|
|
|
-
|
|
|
- // 1. 获取所有图片路径
|
|
|
- $relativeImages = array_keys($imageInfoMap);
|
|
|
+ // 构建缓存键与构建锁键
|
|
|
+ $hash = md5($relativePath);
|
|
|
+ $cacheKey = "previewimg_full_{$hash}";
|
|
|
+ $lockKey = "previewimg_building_{$hash}";
|
|
|
+ $cacheExpire = 600; // 10分钟
|
|
|
+
|
|
|
+ $fullData = cache($cacheKey);
|
|
|
+
|
|
|
+ if (!$fullData) {
|
|
|
+ // 防止缓存“惊群效应”:只允许一个任务生成缓存,其它等待
|
|
|
+ if (!cache($lockKey)) {
|
|
|
+ cache($lockKey, 1, 60); // 1分钟构建锁
|
|
|
+
|
|
|
+ $allImages = glob($fullPath . '/*.{jpg,jpeg,png}', GLOB_BRACE);
|
|
|
+ $imageInfoMap = [];
|
|
|
+ foreach ($allImages as $imgPath) {
|
|
|
+ $relative = str_replace('\\', '/', trim(str_replace($basePath, '', $imgPath), '/'));
|
|
|
+ $info = @getimagesize($imgPath);
|
|
|
+ $imageInfoMap[$relative] = [
|
|
|
+ 'width' => $info[0] ?? 0,
|
|
|
+ 'height' => $info[1] ?? 0,
|
|
|
+ 'size_kb' => round(filesize($imgPath) / 1024, 2),
|
|
|
+ 'created_time' => date('Y-m-d H:i:s', filectime($imgPath))
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
- // 2. 查询数据库记录(一次性查询所有相关记录)
|
|
|
- $dbRecords = Db::name('text_to_image')
|
|
|
- ->whereIn('old_image_url', $relativeImages)
|
|
|
- ->field('id as img_id, old_image_url, new_image_url, custom_image_url, chinese_description, english_description, img_name, status, status_name')
|
|
|
- ->select();
|
|
|
+ $relativeImages = array_keys($imageInfoMap);
|
|
|
|
|
|
- // 3. 查询队列表中的记录(获取队列状态信息)
|
|
|
- $queueRecords = Db::name('image_task_log')
|
|
|
- // ->where('status', 0)
|
|
|
- // ->where('log', '队列中')
|
|
|
- ->field('file_name, log')
|
|
|
- ->select();
|
|
|
+ // 批量查库
|
|
|
+ $dbRecords = Db::name('text_to_image')
|
|
|
+ ->whereIn('old_image_url', $relativeImages)
|
|
|
+ ->field('id as img_id, old_image_url, new_image_url, custom_image_url, chinese_description, english_description, img_name, status, status_name')
|
|
|
+ ->select();
|
|
|
|
|
|
- // 4. 创建队列信息映射
|
|
|
- $queueMap = [];
|
|
|
- foreach ($queueRecords as $queueItem) {
|
|
|
- $key = str_replace('\\', '/', trim($queueItem['file_name'], '/'));
|
|
|
- $queueMap[$key] = $queueItem['log'];
|
|
|
- }
|
|
|
+ $queueRecords = Db::name('image_task_log')
|
|
|
+ ->where('mod_rq', null)
|
|
|
+ ->field('file_name, log')
|
|
|
+ ->select();
|
|
|
|
|
|
- // 5. 映射记录
|
|
|
- $processedMap = [];
|
|
|
- foreach ($dbRecords as $item) {
|
|
|
- $key = str_replace('\\', '/', trim($item['old_image_url'], '/'));
|
|
|
- $processedMap[$key] = $item;
|
|
|
- }
|
|
|
+ $queueMap = [];
|
|
|
+ foreach ($queueRecords as $q) {
|
|
|
+ $key = str_replace('\\', '/', trim($q['file_name'], '/'));
|
|
|
+ $queueMap[$key] = $q['log'];
|
|
|
+ }
|
|
|
|
|
|
- // 6. 构建完整数据并进行筛选
|
|
|
- $filteredData = [];
|
|
|
- foreach ($relativeImages as $path) {
|
|
|
- $item = $processedMap[$path] ?? [];
|
|
|
- $info = $imageInfoMap[$path];
|
|
|
+ $processedMap = [];
|
|
|
+ foreach ($dbRecords as $item) {
|
|
|
+ $key = str_replace('\\', '/', trim($item['old_image_url'], '/'));
|
|
|
+ $processedMap[$key] = $item;
|
|
|
+ }
|
|
|
|
|
|
- $dbStatus = isset($item['status']) ? (int)$item['status'] : 0;
|
|
|
- $dbStatusName = isset($item['status_name']) ? trim($item['status_name']) : '';
|
|
|
+ $fullData = [];
|
|
|
+ foreach ($relativeImages as $path) {
|
|
|
+ $item = $processedMap[$path] ?? [];
|
|
|
+ $info = $imageInfoMap[$path];
|
|
|
+
|
|
|
+ $fullData[] = [
|
|
|
+ 'path' => $path,
|
|
|
+ 'item' => $item,
|
|
|
+ 'info' => $info,
|
|
|
+ 'dbStatus' => isset($item['status']) ? (int)$item['status'] : 0,
|
|
|
+ 'dbStatusName' => $item['status_name'] ?? '',
|
|
|
+ 'isProcessed' => !empty($item['img_name']) && !empty($item['custom_image_url']),
|
|
|
+ 'queueStatus' => $queueMap[$path] ?? ''
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
- // 状态筛选条件
|
|
|
- if ($status !== '' && (int)$status !== $dbStatus) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- if ($status_name !== '' && $dbStatusName !== $status_name) {
|
|
|
- continue;
|
|
|
+ // 设置缓存 + 删除构建锁
|
|
|
+ cache($cacheKey, $fullData, $cacheExpire);
|
|
|
+ cache($lockKey, null);
|
|
|
+ } else {
|
|
|
+ // 如果有构建锁,等待缓存生成后再读
|
|
|
+ $waitTime = 0;
|
|
|
+ while (!$fullData && $waitTime < 10) {
|
|
|
+ sleep(1);
|
|
|
+ $waitTime++;
|
|
|
+ $fullData = cache($cacheKey);
|
|
|
+ }
|
|
|
+ if (!$fullData) {
|
|
|
+ return json(['code' => 2, 'msg' => '系统正忙,请稍后重试']);
|
|
|
+ }
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- $isProcessed = !empty($item['img_name']) && !empty($item['custom_image_url']);
|
|
|
- $queueStatus = $queueMap[$path] ?? '';
|
|
|
+ // 筛选状态字段
|
|
|
+ $filtered = array_filter($fullData, function ($data) use ($status, $status_name) {
|
|
|
+ if ($status !== '' && (int)$status !== $data['dbStatus']) return false;
|
|
|
+ if ($status_name !== '' && $status_name !== $data['dbStatusName']) return false;
|
|
|
+ return true;
|
|
|
+ });
|
|
|
|
|
|
- $filteredData[] = [
|
|
|
- 'path' => $path,
|
|
|
- 'item' => $item,
|
|
|
- 'info' => $info,
|
|
|
- 'dbStatus' => $dbStatus,
|
|
|
- 'dbStatusName' => $dbStatusName,
|
|
|
- 'isProcessed' => $isProcessed,
|
|
|
- 'queueStatus' => $queueStatus
|
|
|
- ];
|
|
|
- }
|
|
|
+ // 分页处理
|
|
|
+ $total = count($filtered);
|
|
|
+ $paged = array_slice(array_values($filtered), ($page - 1) * $limit, $limit);
|
|
|
|
|
|
- // 7. 获取相同图片数量统计(基于筛选后的结果,只统计有new_image_url的记录)
|
|
|
- $filteredPaths = array_column($filteredData, 'path');
|
|
|
+ // 统计 same_count
|
|
|
+ $paths = array_column($paged, 'path');
|
|
|
$sameCountMap = [];
|
|
|
- if (!empty($filteredPaths)) {
|
|
|
+ if ($paths) {
|
|
|
$sameCountMap = Db::name('text_to_image')
|
|
|
- ->whereIn('old_image_url', $filteredPaths)
|
|
|
- ->where('new_image_url', '<>', '') // 只统计有new_image_url的记录
|
|
|
+ ->whereIn('old_image_url', $paths)
|
|
|
+ ->where('new_image_url', '<>', '')
|
|
|
->group('old_image_url')
|
|
|
->column('count(*) as cnt', 'old_image_url');
|
|
|
}
|
|
|
|
|
|
- // 8. 分页处理
|
|
|
- $total = count($filteredData);
|
|
|
- $pagedData = array_slice($filteredData, ($page - 1) * $limit, $limit);
|
|
|
-
|
|
|
- // 9. 构建最终响应数据
|
|
|
- $resultData = [];
|
|
|
- foreach ($pagedData as $i => $data) {
|
|
|
+ // 构建返回数据
|
|
|
+ $result = [];
|
|
|
+ foreach ($paged as $i => $data) {
|
|
|
$path = $data['path'];
|
|
|
$item = $data['item'];
|
|
|
$info = $data['info'];
|
|
|
|
|
|
- $resultData[] = [
|
|
|
+ $result[] = [
|
|
|
'id' => ($page - 1) * $limit + $i + 1,
|
|
|
'path' => $path,
|
|
|
'status' => $data['dbStatus'],
|
|
|
'status_name' => $data['dbStatusName'],
|
|
|
'same_count' => $sameCountMap[$path] ?? 0,
|
|
|
'is_processed' => $data['isProcessed'] ? 1 : 0,
|
|
|
- 'queue_status' => $data['queueStatus'], // 新增队列状态字段
|
|
|
+ 'queue_status' => $data['queueStatus'],
|
|
|
'new_image_url' => $item['new_image_url'] ?? '',
|
|
|
'custom_image_url' => $item['custom_image_url'] ?? '',
|
|
|
'chinese_description' => $item['chinese_description'] ?? '',
|
|
|
@@ -179,12 +183,304 @@ class Facility extends Api
|
|
|
return json([
|
|
|
'code' => 0,
|
|
|
'msg' => '获取成功',
|
|
|
- 'data' => $resultData,
|
|
|
+ 'data' => $result,
|
|
|
'total' => $total,
|
|
|
'page' => $page,
|
|
|
'limit' => $limit
|
|
|
]);
|
|
|
}
|
|
|
+// public function getPreviewimg()
|
|
|
+// {
|
|
|
+// $page = (int)$this->request->param('page', 1);
|
|
|
+// $limit = (int)$this->request->param('limit', 50);
|
|
|
+// $status = $this->request->param('status', '');
|
|
|
+// $status_name = $this->request->param('status_name', '');
|
|
|
+// $relativePath = $this->request->param('path', '');
|
|
|
+//
|
|
|
+// $basePath = ROOT_PATH . 'public/';
|
|
|
+// $fullPath = $basePath . $relativePath;
|
|
|
+//
|
|
|
+// if (!is_dir($fullPath)) {
|
|
|
+// return json(['code' => 1, 'msg' => '原图目录不存在']);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $baseCacheKey = 'previewimg_full_' . md5($relativePath);
|
|
|
+// $fullData = cache($baseCacheKey);
|
|
|
+//
|
|
|
+// if (!$fullData) {
|
|
|
+// $allImages = glob($fullPath . '/*.{jpg,jpeg,png}', GLOB_BRACE);
|
|
|
+// $imageInfoMap = [];
|
|
|
+//
|
|
|
+// foreach ($allImages as $imgPath) {
|
|
|
+// $relative = str_replace('\\', '/', trim(str_replace($basePath, '', $imgPath), '/'));
|
|
|
+// $info = @getimagesize($imgPath);
|
|
|
+// $imageInfoMap[$relative] = [
|
|
|
+// 'width' => $info[0] ?? 0,
|
|
|
+// 'height' => $info[1] ?? 0,
|
|
|
+// 'size_kb' => round(filesize($imgPath) / 1024, 2),
|
|
|
+// 'created_time' => date('Y-m-d H:i:s', filectime($imgPath))
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $relativeImages = array_keys($imageInfoMap);
|
|
|
+//
|
|
|
+// $dbRecords = Db::name('text_to_image')
|
|
|
+// ->whereIn('old_image_url', $relativeImages)
|
|
|
+// ->field('id as img_id, old_image_url, new_image_url, custom_image_url, chinese_description, english_description, img_name, status, status_name')
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// $queueRecords = Db::name('image_task_log')
|
|
|
+// ->field('file_name, log')
|
|
|
+// ->where('mod_rq', null)
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// $queueMap = [];
|
|
|
+// foreach ($queueRecords as $q) {
|
|
|
+// $k = str_replace('\\', '/', trim($q['file_name'], '/'));
|
|
|
+// $queueMap[$k] = $q['log'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// $processedMap = [];
|
|
|
+// foreach ($dbRecords as $item) {
|
|
|
+// $key = str_replace('\\', '/', trim($item['old_image_url'], '/'));
|
|
|
+// $processedMap[$key] = $item;
|
|
|
+// }
|
|
|
+//
|
|
|
+// $fullData = [];
|
|
|
+// foreach ($relativeImages as $path) {
|
|
|
+// $item = $processedMap[$path] ?? [];
|
|
|
+// $info = $imageInfoMap[$path];
|
|
|
+//
|
|
|
+// $fullData[] = [
|
|
|
+// 'path' => $path,
|
|
|
+// 'item' => $item,
|
|
|
+// 'info' => $info,
|
|
|
+// 'dbStatus' => isset($item['status']) ? (int)$item['status'] : 0,
|
|
|
+// 'dbStatusName' => $item['status_name'] ?? '',
|
|
|
+// 'isProcessed' => !empty($item['img_name']) && !empty($item['custom_image_url']),
|
|
|
+// 'queueStatus' => $queueMap[$path] ?? ''
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 缓存整个数据,不包含分页
|
|
|
+// cache($baseCacheKey, $fullData, 600);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 筛选状态(如 status, status_name)
|
|
|
+// $filteredData = array_filter($fullData, function ($data) use ($status, $status_name) {
|
|
|
+// if ($status !== '' && (int)$status !== $data['dbStatus']) return false;
|
|
|
+// if ($status_name !== '' && $status_name !== $data['dbStatusName']) return false;
|
|
|
+// return true;
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 分页处理
|
|
|
+// $total = count($filteredData);
|
|
|
+// $pagedData = array_slice(array_values($filteredData), ($page - 1) * $limit, $limit);
|
|
|
+//
|
|
|
+// // 统计 same_count
|
|
|
+// $paths = array_column($pagedData, 'path');
|
|
|
+// $sameCountMap = [];
|
|
|
+// if (!empty($paths)) {
|
|
|
+// $sameCountMap = Db::name('text_to_image')
|
|
|
+// ->whereIn('old_image_url', $paths)
|
|
|
+// ->where('new_image_url', '<>', '')
|
|
|
+// ->group('old_image_url')
|
|
|
+// ->column('count(*) as cnt', 'old_image_url');
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 构建返回结构
|
|
|
+// $resultData = [];
|
|
|
+// foreach ($pagedData as $i => $data) {
|
|
|
+// $path = $data['path'];
|
|
|
+// $item = $data['item'];
|
|
|
+// $info = $data['info'];
|
|
|
+//
|
|
|
+// $resultData[] = [
|
|
|
+// 'id' => ($page - 1) * $limit + $i + 1,
|
|
|
+// 'path' => $path,
|
|
|
+// 'status' => $data['dbStatus'],
|
|
|
+// 'status_name' => $data['dbStatusName'],
|
|
|
+// 'same_count' => $sameCountMap[$path] ?? 0,
|
|
|
+// 'is_processed' => $data['isProcessed'] ? 1 : 0,
|
|
|
+// 'queue_status' => $data['queueStatus'],
|
|
|
+// 'new_image_url' => $item['new_image_url'] ?? '',
|
|
|
+// 'custom_image_url' => $item['custom_image_url'] ?? '',
|
|
|
+// 'chinese_description' => $item['chinese_description'] ?? '',
|
|
|
+// 'english_description' => $item['english_description'] ?? '',
|
|
|
+// 'img_name' => $item['img_name'] ?? '',
|
|
|
+// 'width' => $info['width'],
|
|
|
+// 'height' => $info['height'],
|
|
|
+// 'size_kb' => $info['size_kb'],
|
|
|
+// 'created_time' => $info['created_time']
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// return json([
|
|
|
+// 'code' => 0,
|
|
|
+// 'msg' => '获取成功',
|
|
|
+// 'data' => $resultData,
|
|
|
+// 'total' => $total,
|
|
|
+// 'page' => $page,
|
|
|
+// 'limit' => $limit
|
|
|
+// ]);
|
|
|
+// }
|
|
|
+ /**
|
|
|
+ * 获取指定目录所有图片
|
|
|
+ */
|
|
|
+// public function getPreviewimg()
|
|
|
+// {
|
|
|
+// $page = (int)$this->request->param('page', 1);
|
|
|
+// $limit = (int)$this->request->param('limit', 50);
|
|
|
+// $status = $this->request->param('status', '');
|
|
|
+// $status_name = $this->request->param('status_name', '');
|
|
|
+// $relativePath = $this->request->param('path', '');
|
|
|
+//
|
|
|
+// $basePath = ROOT_PATH . 'public/';
|
|
|
+// $fullPath = $basePath . $relativePath;
|
|
|
+//
|
|
|
+// if (!is_dir($fullPath)) {
|
|
|
+// return json(['code' => 1, 'msg' => '原图目录不存在']);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 设置缓存路径
|
|
|
+// $cacheDir = RUNTIME_PATH . 'image_cache/';
|
|
|
+// if (!is_dir($cacheDir)) {
|
|
|
+// mkdir($cacheDir, 0755, true);
|
|
|
+// }
|
|
|
+// $cacheFile = $cacheDir . md5($relativePath) . '.json';
|
|
|
+//
|
|
|
+// // 判断缓存文件是否存在,并且最后修改时间在1小时(3600秒)以内
|
|
|
+// if (file_exists($cacheFile) && time() - filemtime($cacheFile) < 3600) {
|
|
|
+// $imageInfoMap = json_decode(file_get_contents($cacheFile), true);
|
|
|
+// } else {
|
|
|
+// // 没有缓存或缓存过期,重新扫描目录
|
|
|
+// $allImages = glob($fullPath . '/*.{jpg,jpeg,png}', GLOB_BRACE);
|
|
|
+// $imageInfoMap = [];
|
|
|
+// foreach ($allImages as $imgPath) {
|
|
|
+// $relative = str_replace('\\', '/', trim(str_replace($basePath, '', $imgPath), '/'));
|
|
|
+// $info = @getimagesize($imgPath);
|
|
|
+// $imageInfoMap[$relative] = [
|
|
|
+// 'width' => $info[0] ?? 0,
|
|
|
+// 'height' => $info[1] ?? 0,
|
|
|
+// 'size_kb' => round(filesize($imgPath) / 1024, 2),
|
|
|
+// 'created_time' => date('Y-m-d H:i:s', filectime($imgPath))
|
|
|
+// ];
|
|
|
+// }
|
|
|
+// file_put_contents($cacheFile, json_encode($imageInfoMap));
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 1. 获取所有图片路径
|
|
|
+// $relativeImages = array_keys($imageInfoMap);
|
|
|
+//
|
|
|
+// // 2. 查询数据库记录(一次性查询所有相关记录)
|
|
|
+// $dbRecords = Db::name('text_to_image')
|
|
|
+// ->whereIn('old_image_url', $relativeImages)
|
|
|
+// ->field('id as img_id, old_image_url, new_image_url, custom_image_url, chinese_description, english_description, img_name, status, status_name')
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// // 3. 查询队列表中的记录(获取队列状态信息)
|
|
|
+// $queueRecords = Db::name('image_task_log')
|
|
|
+// // ->where('status', 0)
|
|
|
+// // ->where('log', '队列中')
|
|
|
+// ->field('file_name, log')
|
|
|
+// ->select();
|
|
|
+//
|
|
|
+// // 4. 创建队列信息映射
|
|
|
+// $queueMap = [];
|
|
|
+// foreach ($queueRecords as $queueItem) {
|
|
|
+// $key = str_replace('\\', '/', trim($queueItem['file_name'], '/'));
|
|
|
+// $queueMap[$key] = $queueItem['log'];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 5. 映射记录
|
|
|
+// $processedMap = [];
|
|
|
+// foreach ($dbRecords as $item) {
|
|
|
+// $key = str_replace('\\', '/', trim($item['old_image_url'], '/'));
|
|
|
+// $processedMap[$key] = $item;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 6. 构建完整数据并进行筛选
|
|
|
+// $filteredData = [];
|
|
|
+// foreach ($relativeImages as $path) {
|
|
|
+// $item = $processedMap[$path] ?? [];
|
|
|
+// $info = $imageInfoMap[$path];
|
|
|
+//
|
|
|
+// $dbStatus = isset($item['status']) ? (int)$item['status'] : 0;
|
|
|
+// $dbStatusName = isset($item['status_name']) ? trim($item['status_name']) : '';
|
|
|
+//
|
|
|
+// // 状态筛选条件
|
|
|
+// if ($status !== '' && (int)$status !== $dbStatus) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+// if ($status_name !== '' && $dbStatusName !== $status_name) {
|
|
|
+// continue;
|
|
|
+// }
|
|
|
+//
|
|
|
+// $isProcessed = !empty($item['img_name']) && !empty($item['custom_image_url']);
|
|
|
+// $queueStatus = $queueMap[$path] ?? '';
|
|
|
+//
|
|
|
+// $filteredData[] = [
|
|
|
+// 'path' => $path,
|
|
|
+// 'item' => $item,
|
|
|
+// 'info' => $info,
|
|
|
+// 'dbStatus' => $dbStatus,
|
|
|
+// 'dbStatusName' => $dbStatusName,
|
|
|
+// 'isProcessed' => $isProcessed,
|
|
|
+// 'queueStatus' => $queueStatus
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 7. 获取相同图片数量统计(基于筛选后的结果,只统计有new_image_url的记录)
|
|
|
+// $filteredPaths = array_column($filteredData, 'path');
|
|
|
+// $sameCountMap = [];
|
|
|
+// if (!empty($filteredPaths)) {
|
|
|
+// $sameCountMap = Db::name('text_to_image')
|
|
|
+// ->whereIn('old_image_url', $filteredPaths)
|
|
|
+// ->where('new_image_url', '<>', '') // 只统计有new_image_url的记录
|
|
|
+// ->group('old_image_url')
|
|
|
+// ->column('count(*) as cnt', 'old_image_url');
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 8. 分页处理
|
|
|
+// $total = count($filteredData);
|
|
|
+// $pagedData = array_slice($filteredData, ($page - 1) * $limit, $limit);
|
|
|
+//
|
|
|
+// // 9. 构建最终响应数据
|
|
|
+// $resultData = [];
|
|
|
+// foreach ($pagedData as $i => $data) {
|
|
|
+// $path = $data['path'];
|
|
|
+// $item = $data['item'];
|
|
|
+// $info = $data['info'];
|
|
|
+//
|
|
|
+// $resultData[] = [
|
|
|
+// 'id' => ($page - 1) * $limit + $i + 1,
|
|
|
+// 'path' => $path,
|
|
|
+// 'status' => $data['dbStatus'],
|
|
|
+// 'status_name' => $data['dbStatusName'],
|
|
|
+// 'same_count' => $sameCountMap[$path] ?? 0,
|
|
|
+// 'is_processed' => $data['isProcessed'] ? 1 : 0,
|
|
|
+// 'queue_status' => $data['queueStatus'], // 新增队列状态字段
|
|
|
+// 'new_image_url' => $item['new_image_url'] ?? '',
|
|
|
+// 'custom_image_url' => $item['custom_image_url'] ?? '',
|
|
|
+// 'chinese_description' => $item['chinese_description'] ?? '',
|
|
|
+// 'english_description' => $item['english_description'] ?? '',
|
|
|
+// 'img_name' => $item['img_name'] ?? '',
|
|
|
+// 'width' => $info['width'],
|
|
|
+// 'height' => $info['height'],
|
|
|
+// 'size_kb' => $info['size_kb'],
|
|
|
+// 'created_time' => $info['created_time']
|
|
|
+// ];
|
|
|
+// }
|
|
|
+//
|
|
|
+// return json([
|
|
|
+// 'code' => 0,
|
|
|
+// 'msg' => '获取成功',
|
|
|
+// 'data' => $resultData,
|
|
|
+// 'total' => $total,
|
|
|
+// 'page' => $page,
|
|
|
+// 'limit' => $limit
|
|
|
+// ]);
|
|
|
+// }
|
|
|
|
|
|
/**
|
|
|
* 采用缓存机制
|