首页
关于
友链
推荐
肥啾解析
百度一下
肥啾GPT
Search
1
宝塔面板登录 phpMyAdmin 提示服务器和客户端上指示的HTTPS之间不匹配
274 阅读
2
Customer complaints evolve with in-car tech
188 阅读
3
JavaScript解析
153 阅读
4
内连接,左连接,右连接作用及区别
112 阅读
5
所谓关系
109 阅读
默认分类
网游架设
手机游戏
python
PHP
Mysql
VBA
C++
JAVASCRIPT
javascript基础
Oracle
生产管理
计划控制
ERP系统开发
APS排产
MES研究
考勤系统
CPA
财管
实务
经济法
战略
审计
税法
藏书架
古典名著
世界名著
编程秘籍
攻防渗透
经管书籍
大佬传经
风雅读物
考试相关
心情格言
拾玉良言
外文报刊
外刊随选
Facebook
Twitter
China Daily
软考
登录
Search
标签搜索
期刊读物
古文
何瑜明
累计撰写
179
篇文章
累计收到
154
条评论
首页
栏目
默认分类
网游架设
手机游戏
python
PHP
Mysql
VBA
C++
JAVASCRIPT
javascript基础
Oracle
生产管理
计划控制
ERP系统开发
APS排产
MES研究
考勤系统
CPA
财管
实务
经济法
战略
审计
税法
藏书架
古典名著
世界名著
编程秘籍
攻防渗透
经管书籍
大佬传经
风雅读物
考试相关
心情格言
拾玉良言
外文报刊
外刊随选
Facebook
Twitter
China Daily
软考
页面
关于
友链
推荐
肥啾解析
百度一下
肥啾GPT
搜索到
179
篇与
的结果
2025-06-22
此内容被密码保护
加密文章,请前往内页查看详情
2025年06月22日
2 阅读
0 评论
0 点赞
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日
12 阅读
0 评论
0 点赞
2025-05-07
此内容被密码保护
加密文章,请前往内页查看详情
2025年05月07日
3 阅读
0 评论
0 点赞
2025-05-07
挤出逻辑
<body> <div class="container"> <h1>挤出排产</h1> <div class="input-group"> <input type="file" id="excelFile" accept=".xlsx"> <input type="date" id="startDate" required> <button onclick="startScheduling()">开始排产</button> </div> <div id="scheduleResult"></div> </div> <script> const PRODUCTION_PARAMS = { speed: { low: 5000, // ≤16mm medium: 4000, // 17-30mm high: 3500 // >30mm }, diameterGroups: [ { max: 8, name: '0-8mm' }, { max: 11, name: '9-11mm' }, { max: Infinity, name: '12mm+' } ] }; document.addEventListener('DOMContentLoaded', () => { if(typeof XLSX === 'undefined') { alert('错误:核心库加载失败,请检查网络连接'); return; } document.getElementById('startDate').valueAsDate = new Date(); }); function startScheduling() { const fileInput = document.getElementById('excelFile'); const startDate = document.getElementById('startDate').value; if(!fileInput.files.length) return alert("请选择Excel文件"); if(!startDate) return alert("请选择排产开始日期"); const reader = new FileReader(); reader.onload = processExcelFile; reader.readAsArrayBuffer(fileInput.files[0]); } function processExcelFile(event) { try { const workbook = XLSX.read(event.target.result, {type: 'array'}); const sheet = workbook.Sheets[workbook.SheetNames[0]]; const rawData = XLSX.utils.sheet_to_json(sheet, {header:1}); const orders = validateAndFormatData(rawData); const schedule = generateProductionSchedule(orders); renderScheduleTable(schedule); } catch (error) { handleError('文件处理失败', error); } } function validateAndFormatData(rawData) { return rawData.slice(1).map((row, index) => { const dateIndex = 2; if(row.length < 7) throw new Error(`第${index+2}行数据列数不足`); let demandDate; const excelDateValue = row[dateIndex]; if(typeof excelDateValue === 'number') { const parsed = XLSX.SSF.parse_date_code(excelDateValue); demandDate = new Date(parsed.y, parsed.m - 1, parsed.d); } else { demandDate = new Date(excelDateValue); } if(isNaN(demandDate.getTime())) { throw new Error(`第${index+2}行需求日期格式错误,值:${excelDateValue}`); } return { 订单号: String(row[0]).trim(), 需求数量: Number(row[1]), 需求日期: demandDate, 产品口径: Number(row[3]), 实际长度: parseFloat(Number(row[4]).toFixed(2)), 胶料类型: String(row[5]).trim(), 生产机台: String(row[6]).trim(), 挤出基数: Math.ceil(row[1] * 1.1 / 10) * 10, 剩余数量: Math.ceil(row[1] * 1.1 / 10) * 10 }; }).filter(order => order.需求数量 >= 10); } function generateProductionSchedule(orders) { const schedule = {}; const startDate = new Date(document.getElementById('startDate').value); const grouped = groupOrders(orders); const sortedKeys = Object.keys(grouped).sort(); sortedKeys.forEach(key => { const [machine, material, diameterGroup] = key.split('|'); const orderList = grouped[key]; let currentDate = new Date(startDate); const { maxQty: maxDailyQty } = calculateDailyCapacity(orderList[0].产品口径, orderList[0].实际长度); while (orderList.some(o => o.剩余数量 > 0)) { const dateKey = formatDate(currentDate); if (!schedule[machine]) schedule[machine] = {}; if (!schedule[machine][dateKey]) { schedule[machine][dateKey] = { items: [], totalLength: 0, usedQty: 0, capacity: maxDailyQty }; } const day = schedule[machine][dateKey]; let capacityLeft = day.capacity - day.usedQty; for (let order of orderList) { if (order.剩余数量 <= 0 || capacityLeft <= 0) continue; const canAlloc = Math.min(order.剩余数量, capacityLeft); day.items.push({ 订单号: order.订单号, 胶料类型: order.胶料类型, 产品口径: order.产品口径, 实际长度: order.实际长度, 排产数量: canAlloc, 排产长度: canAlloc * order.实际长度, 需求日期: order.需求日期 }); day.totalLength += canAlloc * order.实际长度; day.usedQty += canAlloc; order.剩余数量 -= canAlloc; capacityLeft -= canAlloc; } currentDate = addDays(currentDate, 1); } }); return schedule; } function groupOrders(orders) { const groups = {}; orders.forEach(order => { const diameterGroup = PRODUCTION_PARAMS.diameterGroups.find(g => order.产品口径 <= g.max).name; const key = `${order.生产机台}|${order.胶料类型}|${diameterGroup}`; if (!groups[key]) groups[key] = []; groups[key].push(order); }); return groups; } function calculateDailyCapacity(diameter, length) { let speed; if(diameter <= 16) speed = PRODUCTION_PARAMS.speed.low; else if(diameter <= 30) speed = PRODUCTION_PARAMS.speed.medium; else speed = PRODUCTION_PARAMS.speed.high; const maxQty = Math.floor(speed / length); return { value: speed, maxQty }; } function formatDate(date) { return date.toISOString().split('T')[0]; } function addDays(date, days) { const result = new Date(date); result.setDate(result.getDate() + days); return result; } function renderScheduleTable(schedule) { let html = ''; Object.entries(schedule).forEach(([machine, dateMap]) => { html += `<div class="machine-header"> <h3>${machine} 生产计划</h3> <div class="capacity-info">每日最大产能:${Object.values(dateMap)[0].capacity} 米</div> </div>`; html += `<table> <tr> <th>生产日期</th> <th>订单号</th> <th>口径(mm)</th> <th>长度(m)</th> <th>胶料类型</th> <th>排产数量</th> <th>总长度(m)</th> <th>需求日期</th> <th>状态</th> </tr>`; Object.entries(dateMap).forEach(([date, data]) => { data.items.forEach(item => { const isLate = new Date(date) > new Date(item.需求日期); html += `<tr${isLate ? ' class="warning"' : ''}> <td>${date}</td> <td>${item.订单号}</td> <td>${item.产品口径}</td> <td>${item.实际长度.toFixed(2)}</td> <td>${item.胶料类型}</td> <td>${item.排产数量}</td> <td>${item.排产长度.toFixed(1)}</td> <td>${item.需求日期.toISOString().split('T')[0]}</td> <td>${isLate ? '延迟' : '正常'}</td> </tr>`; }); html += `<tr class="summary-row"> <td colspan="5">当日汇总</td> <td>${data.usedQty}</td> <td>${data.totalLength.toFixed(1)}</td> <td colspan="3"> </td> </tr>`; }); html += `</table>`; }); document.getElementById('scheduleResult').innerHTML = html; } function handleError(message, error) { console.error(`${message}:`, error); alert(`${message},请检查控制台获取详细信息`); } </script> </body>
2025年05月07日
8 阅读
0 评论
0 点赞
2025-05-05
此内容被密码保护
加密文章,请前往内页查看详情
2025年05月05日
6 阅读
0 评论
0 点赞
1
...
15
16
17
...
36
0:00