首页
关于
友链
推荐
肥啾解析
百度一下
肥啾GPT
Search
1
宝塔面板登录 phpMyAdmin 提示服务器和客户端上指示的HTTPS之间不匹配
259 阅读
2
Customer complaints evolve with in-car tech
184 阅读
3
测试
147 阅读
4
内连接,左连接,右连接作用及区别
95 阅读
5
所谓关系
94 阅读
默认分类
网游架设
手机游戏
python
PHP
Mysql
VBA
C++
JAVA
java基础
生产管理
计划控制
ERP系统开发
APS排产
MES研究
考勤系统
CPA
财管
实务
经济法
战略
审计
税法
藏书架
古典名著
世界名著
编程秘籍
攻防渗透
经管书籍
大佬传经
风雅读物
考试相关
心情格言
拾玉良言
外文报刊
外刊随选
Facebook
Twitter
China Daily
软考
登录
Search
标签搜索
期刊读物
古文
何瑜明
累计撰写
103
篇文章
累计收到
153
条评论
首页
栏目
默认分类
网游架设
手机游戏
python
PHP
Mysql
VBA
C++
JAVA
java基础
生产管理
计划控制
ERP系统开发
APS排产
MES研究
考勤系统
CPA
财管
实务
经济法
战略
审计
税法
藏书架
古典名著
世界名著
编程秘籍
攻防渗透
经管书籍
大佬传经
风雅读物
考试相关
心情格言
拾玉良言
外文报刊
外刊随选
Facebook
Twitter
China Daily
软考
页面
关于
友链
推荐
肥啾解析
百度一下
肥啾GPT
搜索到
18
篇与
的结果
2025-05-14
扫描文件逻辑
时区设置 date_default_timezone_set('Asia/Shanghai'); 将脚本时区设置为北京时间(东八区),确保所有时间相关函数返回中国时区的时间37。 安全配置 set_time_limit(1000); $allowed_extensions = ['pdf', 'jpg', 'jpeg', 'png']; 设置脚本最大执行时间为1000秒 定义允许处理的文件扩展名白名单 路径定义 $dataFilePath = __DIR__.'/data/files2.json'; $pdfBasePath = __DIR__.'/pdf2/'; 指定JSON输出文件路径 设置PDF文件存储根目录 目录创建 if (!file_exists(dirname($dataFilePath))) { mkdir(dirname($dataFilePath), 0755, true); } 递归创建JSON文件所需的目录结构(如果不存在) 核心扫描函数 function scanFiles($dir, &$result, $rootDir, $allowed) { // 扫描目录 $files = scandir($dir); foreach ($files as $file) { // 跳过特殊目录 if ($file === '.' || $file === '..') continue; $fullPath = $dir.'/'.$file; // 递归处理子目录 if (is_dir($fullPath)) { scanFiles($fullPath, $result, $rootDir, $allowed); continue; } // 文件名编码转换 $fileNameUTF8 = iconv('GBK', 'UTF-8//IGNORE', $file); $ext = strtolower(pathinfo($fileNameUTF8, PATHINFO_EXTENSION)); // 扩展名检查 if (!in_array($ext, $allowed)) continue; // 路径处理 $relativePath = substr($fullPath, strlen($rootDir) + 1); $relativePathUTF8 = iconv('GBK', 'UTF-8//IGNORE', $relativePath); // 构建文件信息数组 $result[] = [ 'name' => $fileNameUTF8, 'path' => str_replace('\\', '/', $relativePathUTF8), 'size' => filesize($fullPath), 'time' => date('Y-m-d H:i:s', filemtime($fullPath)) ]; } } 路径验证 $pdfPathGBK = iconv('UTF-8', 'GBK', $pdfBasePath); $realPdfPath = realpath($pdfPathGBK); if (!$realPdfPath || !is_dir($realPdfPath)) { die("PDF目录不存在或无法访问"); } 处理中文路径编码问题 验证PDF目录有效性 执行扫描 $fileList = []; scanFiles($realPdfPath, $fileList, $realPdfPath, $allowed_extensions); 初始化空数组并开始递归扫描 排序处理 usort($fileList, function($a, $b) { return $b['time'] - $a['time']; }); 按文件修改时间降序排序 结果输出 file_put_contents( $dataFilePath, json_encode(['files' => $fileList], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ); 将结果以JSON格式写入文件,保留Unicode字符和斜杠 完成提示 echo "<script>alert('已生成 ".count($fileList)." 个文件索引');</script>"; 通过JavaScript弹窗显示处理结果 这段代码主要实现了: 递归扫描指定目录下的文件 过滤指定扩展名的文件 处理中文路径编码问题 生成包含文件信息的JSON索引 按修改时间排序输出结果 特别注意: 代码中多处使用iconv()处理GBK/UTF-8编码转换,说明目标环境可能存在中文Windows服务器 时区设置确保所有时间戳都显示为北京时间37 路径处理中统一使用正斜杠提高跨平台兼容性<?php // generate_json.php // 设置时区为北京时间 date_default_timezone_set('Asia/Shanghai'); // 安全配置 set_time_limit(1000); // 将最大执行时间设置为60秒 $allowed_extensions = ['pdf', 'jpg', 'jpeg', 'png']; $dataFilePath = __DIR__.'/data/files2.json'; // JSON存储路径 $pdfBasePath = __DIR__.'/pdf2/'; // PDF存储根目录 // 创建数据目录 if (!file_exists(dirname($dataFilePath))) { mkdir(dirname($dataFilePath), 0755, true); } // 递归扫描目录 function scanFiles($dir, &$result, $rootDir, $allowed) { $files = scandir($dir); foreach ($files as $file) { if ($file === '.' || $file === '..') continue; $fullPath = $dir.'/'.$file; if (is_dir($fullPath)) { scanFiles($fullPath, $result, $rootDir, $allowed); continue; } // 处理文件名编码(GBK转UTF-8) $fileNameUTF8 = iconv('GBK', 'UTF-8//IGNORE', $file); $ext = strtolower(pathinfo($fileNameUTF8, PATHINFO_EXTENSION)); if (!in_array($ext, $allowed)) continue; // 计算相对路径 $relativePath = substr($fullPath, strlen($rootDir) + 1); $relativePathUTF8 = iconv('GBK', 'UTF-8//IGNORE', $relativePath); $result[] = [ 'name' => $fileNameUTF8, 'path' => str_replace('\\', '/', $relativePathUTF8), // 统一斜杠方向 'size' => filesize($fullPath), 'time' => date('Y-m-d H:i:s', filemtime($fullPath)) ]; } } // 验证PDF目录有效性 $pdfPathGBK = iconv('UTF-8', 'GBK', $pdfBasePath); $realPdfPath = realpath($pdfPathGBK); if (!$realPdfPath || !is_dir($realPdfPath)) { die("PDF目录不存在或无法访问"); } $fileList = []; scanFiles($realPdfPath, $fileList, $realPdfPath, $allowed_extensions); // 按修改时间排序 usort($fileList, function($a, $b) { return $b['time'] - $a['time']; }); // 写入JSON文件 file_put_contents( $dataFilePath, json_encode(['files' => $fileList], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ); //echo "已生成 ".count($fileList)." 个文件索引"; echo "<script>alert('已生成 ".count($fileList)." 个文件索引');</script>"; ?>
2025年05月14日
3 阅读
0 评论
0 点赞
2025-05-05
此内容被密码保护
加密文章,请前往内页查看详情
2025年05月05日
3 阅读
0 评论
0 点赞
2025-04-16
分班问题
<?php header('Content-Type: application/json'); $data = json_decode(file_get_contents('php://input'), true)['data']; $pdo = new PDO('mysql:host=localhost;dbname=ytpmc;charset=utf8', 'ytpmc', 'ytpmc321'); // 读取共用模具信息 $gongyongData = []; $sql = "SELECT productId, promj, promjsl FROM gongyong"; foreach ($pdo->query($sql) as $row) { $gongyongData[$row['productId']] = [ 'mould' => $row['promj'], 'limit' => $row['promjsl'] * 6 ]; } // 按日期分组 $grouped = []; foreach ($data as $row) { list($productId, $qty, $date,$sx) = $row; $grouped[$date][] = ['productId' => $productId, 'quantity' => (int)$qty, 'sx' => $sx]; } $result = []; foreach ($grouped as $date => $items) { $A = []; $B = []; $sumA = 0; $sumB = 0; $typesA = []; $typesB = []; $mouldA = []; $mouldB = []; $warnings = []; $mouldProducts = []; // 存储共用模具的产品信息 $mouldTotalUsage = ['A' => [], 'B' => []]; // 存储各班次模具总使用量 // 预先建立模具到产品的映射关系 foreach ($items as $item) { $pid = $item['productId']; //$sx=$item['sx']; if (isset($gongyongData[$pid])) { $mould = $gongyongData[$pid]['mould']; $mouldProducts[$mould][] = $pid; } } // 拆分任务:将数量 > 10 的产品拆成多个 $splitItems = []; foreach ($items as $item) { if ($item['quantity'] <= 10 && $item['quantity']<=$item['sx'] ) { $splitItems[] = $item; } else { $qty = $item['quantity']; $half = (int)ceil($qty / 2); $splitItems[] = ['productId' => $item['productId'], 'quantity' => $half,'sx' => $item['sx']]; $splitItems[] = ['productId' => $item['productId'], 'quantity' => $qty - $half,'sx' => $item['sx']]; } } // 排序优化(先排大任务) usort($splitItems, function ($a, $b) { return $b['quantity'] - $a['quantity']; }); // 分配任务 foreach ($splitItems as $item) { $pid = $item['productId']; $qty = $item['quantity']; $sx=$item['sx']; $mould = isset($gongyongData[$pid]) ? $gongyongData[$pid]['mould'] : null; $limit = isset($gongyongData[$pid]) ? $gongyongData[$pid]['limit'] : null; // 检查产品是否已在班次中 $inA = isset($typesA[$pid]); $inB = isset($typesB[$pid]); // 计算模具总使用量(同班次所有共用该模具的产品) $mouldATotal = ($mould && isset($mouldTotalUsage['A'][$mould])) ? $mouldTotalUsage['A'][$mould] : 0; $mouldBTotal = ($mould && isset($mouldTotalUsage['B'][$mould])) ? $mouldTotalUsage['B'][$mould] : 0; // 判断分配条件 $canA = !$inA && ($mould ? $mouldATotal + $qty <= 10000 : true); $canB = !$inB && ($mould ? $mouldBTotal + $qty <= 10000 : true); if (!$canA && !$canB) { $sharedProducts = isset($mouldProducts[$mould]) ? implode(',', array_unique($mouldProducts[$mould])) : ''; $warnings[] = "模具 {$mould} 已达到上限 | 共用产品: {$sharedProducts} | 上限: {$limit} | A班已用: {$mouldATotal} | B班已用: {$mouldBTotal}"; continue; } // 分配逻辑 if ($sumA <= $sumB+70 && $canA) { $A[] = ['productId' => $pid, 'quantity' => $qty, 'sx' => $sx]; $sumA += $qty; $typesA[$pid] = true; if ($mould) { $mouldTotalUsage['A'][$mould] = ($mouldTotalUsage['A'][$mould] ?? 0) + $qty; } } elseif ($sumB < $sumA && $canB) { $B[] = ['productId' => $pid, 'quantity' => $qty, 'sx' => $sx]; $sumB += $qty; $typesB[$pid] = true; if ($mould) { $mouldTotalUsage['B'][$mould] = ($mouldTotalUsage['B'][$mould] ?? 0) + $qty; } } elseif ($canA) { $A[] = ['productId' => $pid, 'quantity' => $qty, 'sx' => $sx]; $sumA += $qty; $typesA[$pid] = true; if ($mould) { $mouldTotalUsage['A'][$mould] = ($mouldTotalUsage['A'][$mould] ?? 0) + $qty; } } elseif ($canB) { $B[] = ['productId' => $pid, 'quantity' => $qty, 'sx' => $sx]; $sumB += $qty; $typesB[$pid] = true; if ($mould) { $mouldTotalUsage['B'][$mould] = ($mouldTotalUsage['B'][$mould] ?? 0) + $qty; } } } // 检查是否有共用模具超限情况 foreach ($mouldTotalUsage['A'] as $mould => $used) { if ($used > $gongyongData[$mouldProducts[$mould][0]]['limit']) { $sharedProducts = implode(',', array_unique($mouldProducts[$mould])); $limit = $gongyongData[$mouldProducts[$mould][0]]['limit']; $warnings[] = "A班模具 {$mould} 共用超限需增加模具数量 | 共用产品: {$sharedProducts} | 上限: {$limit} | 已排产: {$used}"; } } foreach ($mouldTotalUsage['B'] as $mould => $used) { if ($used > $gongyongData[$mouldProducts[$mould][0]]['limit']) { $sharedProducts = implode(',', array_unique($mouldProducts[$mould])); $limit = $gongyongData[$mouldProducts[$mould][0]]['limit']; $warnings[] = "B班模具 {$mould} 共用超限需增加模具数量 | 共用产品: {$sharedProducts} | 上限: {$limit} | 已排产: {$used}"; } } $result[$date] = [ 'A' => $A, 'B' => $B, 'sumA' => $sumA, 'sumB' => $sumB, 'typesA' => count($typesA), 'typesB' => count($typesB), 'warnings' => array_unique($warnings), // 去重 'mouldUsage' => [ 'A' => $mouldTotalUsage['A'], 'B' => $mouldTotalUsage['B'] ], 'mouldInfo' => $mouldProducts ]; } echo json_encode($result, JSON_UNESCAPED_UNICODE);
2025年04月16日
3 阅读
0 评论
0 点赞
2025-04-08
此内容被密码保护
加密文章,请前往内页查看详情
2025年04月08日
1 阅读
0 评论
0 点赞
2025-04-08
此内容被密码保护
加密文章,请前往内页查看详情
2025年04月08日
1 阅读
0 评论
0 点赞
1
2
...
4
0:00