安全巡检接入真实数据库:编码字段自动生成、公示牌二维码修复、安全问题统计排除作废

- 安全巡检表新增编码字段(Code,全局唯一 XJ-序号),WebAPI/桌面端新增时自动生成,不可重复
- 修复危大超危工程公示牌二维码不显示:urlName 含非法字符?导致 image.Save 抛异常,改用主键+内容哈希安全文件名
- 安全问题统计(mainProject/main3)排除作废数据(States=4),图表口径与顶部计数一致
- Word 导出文件名改为 监督巡视部位+编号
- Model.cs 由 SqlMetal 重新生成,补齐巡检人ID/签收人ID/发现问题/处理要求等字段;新增 HSSE_SafetyPatrol.Code.cs 补充 Code 列
- 新增安全巡检完整建表脚本(SGGLDB_V2026-08-25-001);删除已过时的接口文档 SafetyPatrol_API.md
This commit is contained in:
2026-08-26 19:13:11 +08:00
parent 55944d732a
commit 192824ea90
27 changed files with 1601 additions and 309 deletions
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.IO.Compression;
using System.Linq;
namespace FineUIPro.Web.HSSE.HazardousMG
@@ -35,6 +37,117 @@ namespace FineUIPro.Web.HSSE.HazardousMG
}
}
/// <summary>
/// 导出Word:每条记录生成独立文档(文档名使用监督巡视部位)。
/// 单条直接下载 .docx;多条打包为 .zip,压缩包内每个 .docx 以监督巡视部位命名。
/// </summary>
protected void btnOut_Click(object sender, EventArgs e)
{
string[] ids = Grid1.SelectedRowIDArray;
if (ids == null || ids.Length == 0)
{
Alert.ShowInTop("请先勾选要导出的巡检记录!", MessageBoxIcon.Warning);
return;
}
List<KeyValuePair<string, byte[]>> files = new List<KeyValuePair<string, byte[]>>();
int dupIndex = 0;
foreach (string id in ids)
{
if (string.IsNullOrEmpty(id))
{
continue;
}
Model.HSSE_SafetyPatrol info = BLL.SafetyPatrolService.GetById(id);
if (info == null)
{
continue;
}
byte[] bytes = BLL.SafetyPatrolWordService.Generate(id);
if (bytes == null)
{
continue;
}
////文件名 = 监督巡视部位 + 编号(编码唯一,规避同名覆盖)
string baseName = SanitizeFileName(info.HazardProjectName);
string codeSuffix = string.IsNullOrEmpty(info.Code) ? string.Empty : "_" + info.Code;
string fileName = baseName + codeSuffix + ".docx";
// 同名记录去重,避免覆盖
while (files.Any(f => f.Key == fileName))
{
dupIndex++;
fileName = baseName + "(" + dupIndex + ").docx";
}
files.Add(new KeyValuePair<string, byte[]>(fileName, bytes));
}
if (files.Count == 0)
{
Alert.ShowInTop("未找到有效巡检记录!", MessageBoxIcon.Warning);
return;
}
Response.Clear();
if (files.Count == 1)
{
// 单条:直接下发 .docx
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(files[0].Key, System.Text.Encoding.UTF8));
Response.BinaryWrite(files[0].Value);
}
else
{
// 多条:打包为 .zip
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("安全巡检记录_" + BLL.Funs.GetNewFileName() + ".zip", System.Text.Encoding.UTF8));
using (MemoryStream ms = new MemoryStream())
{
using (ZipArchive zip = new ZipArchive(ms, ZipArchiveMode.Create, true))
{
foreach (KeyValuePair<string, byte[]> f in files)
{
ZipArchiveEntry entry = zip.CreateEntry(f.Key, CompressionLevel.Optimal);
using (Stream es = entry.Open())
{
es.Write(f.Value, 0, f.Value.Length);
}
}
}
Response.BinaryWrite(ms.ToArray());
}
}
Response.Flush();
Response.End();
}
/// <summary>
/// 清洗文件名(去非法字符),保证文件名合法可下载。
/// </summary>
/// <param name="name">监督巡视部位名称</param>
/// <returns>合法文件名(不含扩展名)</returns>
private static string SanitizeFileName(string name)
{
if (string.IsNullOrEmpty(name))
{
return "监督记录表";
}
string fileName = name;
foreach (char c in Path.GetInvalidFileNameChars())
{
fileName = fileName.Replace(c, '_');
}
fileName = fileName.Trim();
if (fileName.Length == 0)
{
return "监督记录表";
}
if (fileName.Length > 80)
{
fileName = fileName.Substring(0, 80);
}
return fileName;
}
/// <summary>
/// 扫码巡检按钮事件
/// </summary>
@@ -51,12 +164,20 @@ namespace FineUIPro.Web.HSSE.HazardousMG
#region
/// <summary>
/// 巡检状态颜色(待整改标红)
/// 巡检状态颜色(待整改标红、整改待复查标橙、正常标绿
/// </summary>
public Color GetPatrolStatusColor(object value)
{
string state = value == null ? "" : value.ToString();
return state == "待整改" ? Color.Red : Color.Green;
switch (state)
{
case "待整改":
return Color.Red;
case "整改待复查":
return Color.Orange;
default:
return Color.Green;
}
}
#endregion
@@ -217,6 +338,11 @@ namespace FineUIPro.Web.HSSE.HazardousMG
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type={0}&toKeyId={1}&path=FileUpload/SafetyPatrol&menuId={2}",
-1, e.RowID, BLL.Const.SafetyPatrolMenuId)));
}
else if (e.CommandName == "attchUrlRectify")
{
PageContext.RegisterStartupScript(WindowAtt.GetShowReference(String.Format("../../AttachFile/webuploader.aspx?type={0}&toKeyId={1}&path=FileUpload/SafetyPatrolCorrect&menuId={2}",
-1, e.RowID, BLL.Const.SafetyPatrolRectifyMenuId)));
}
}
#endregion
}