增加:制图平台生成PDF的接口
This commit is contained in:
@@ -6,6 +6,7 @@ using Microsoft.Extensions.Caching.Memory;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NPOI.HSSF.Record;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
@@ -133,10 +134,7 @@ namespace BLW_Log.Controllers
|
||||
return rs;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 执行素材查询
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
|
||||
public ReturnInfo MaterialQuery()
|
||||
{
|
||||
string key = "MaterialQuery";
|
||||
@@ -819,8 +817,10 @@ namespace BLW_Log.Controllers
|
||||
{
|
||||
string sql = @"
|
||||
INSERT INTO `cdr_library`.`tbl_web_project`
|
||||
(report_id, hotel_name, room_type_count, room_data_json, remarks, creator, created_at, is_valid, guid, edit_status, cdr_filename)
|
||||
VALUES (@report_id, @hotel_name, @room_type_count, @room_data_json, @remarks, @creator, @created_at, 1, @guid, @edit_status, @cdr_filename)";
|
||||
(report_id, hotel_name, room_type_count, room_data_json, remarks, creator, created_at, is_valid, guid, edit_status, cdr_filename,
|
||||
protocol, project_name, switch_series, socket_series, cn_font, cn_font_size, en_font, en_font_size)
|
||||
VALUES (@report_id, @hotel_name, @room_type_count, @room_data_json, @remarks, @creator, @created_at, 1, @guid, @edit_status, @cdr_filename,
|
||||
@protocol, @project_name, @switch_series, @socket_series, @cn_font, @cn_font_size, @en_font, @en_font_size)";
|
||||
|
||||
var parameters = new[]
|
||||
{
|
||||
@@ -833,7 +833,15 @@ namespace BLW_Log.Controllers
|
||||
new MySqlParameter("@created_at", project.created_at),
|
||||
new MySqlParameter("@guid", Guid.NewGuid().ToString("N")),
|
||||
new MySqlParameter("@edit_status", project.edit_status ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cdr_filename", project.cdr_filename ?? (object)DBNull.Value)
|
||||
new MySqlParameter("@cdr_filename", project.cdr_filename ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@protocol", project.protocol ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@project_name", project.project_name ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@switch_series", project.switch_series ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@socket_series", project.socket_series ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cn_font", project.cn_font ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cn_font_size", project.cn_font_size ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@en_font", project.en_font ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@en_font_size", project.en_font_size ?? (object)DBNull.Value)
|
||||
};
|
||||
|
||||
return ExecuteNonQueryWithGuid(sql, parameters);
|
||||
@@ -865,7 +873,9 @@ namespace BLW_Log.Controllers
|
||||
UPDATE `cdr_library`.`tbl_web_project` SET
|
||||
report_id=@report_id, hotel_name=@hotel_name, room_type_count=@room_type_count,
|
||||
room_data_json=@room_data_json, remarks=@remarks, creator=@creator,
|
||||
edit_status=@edit_status, cdr_filename=@cdr_filename
|
||||
edit_status=@edit_status, cdr_filename=@cdr_filename,
|
||||
protocol=@protocol, project_name=@project_name, switch_series=@switch_series, socket_series=@socket_series,
|
||||
cn_font=@cn_font, cn_font_size=@cn_font_size, en_font=@en_font, en_font_size=@en_font_size
|
||||
WHERE guid=@guid";
|
||||
|
||||
var parameters = new[]
|
||||
@@ -878,6 +888,14 @@ namespace BLW_Log.Controllers
|
||||
new MySqlParameter("@creator", project.creator),
|
||||
new MySqlParameter("@edit_status", project.edit_status ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cdr_filename", project.cdr_filename ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@protocol", project.protocol ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@project_name", project.project_name ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@switch_series", project.switch_series ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@socket_series", project.socket_series ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cn_font", project.cn_font ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cn_font_size", project.cn_font_size ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@en_font", project.en_font ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@en_font_size", project.en_font_size ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@guid", project.guid ?? (object)DBNull.Value)
|
||||
};
|
||||
|
||||
@@ -905,18 +923,45 @@ namespace BLW_Log.Controllers
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public ReturnInfo GetAllProjectCDR([FromBody] QueryInfo info)
|
||||
public ReturnInfo GetAllProjectCDR([FromBody] GetAllProjectCdrRequest request)
|
||||
{
|
||||
ApplyProjectCdrDefaults(request);
|
||||
EnsureEnumValueExists("protocol", request.Protocol, DefaultProtocolOptions);
|
||||
EnsureEnumValueExists("switch_series", request.SwitchSeries, DefaultSwitchSeriesOptions);
|
||||
|
||||
string sql = @"SELECT DISTINCT p.hotel_name, rt.room_name, pnl.model_type, pnl.gang_series,
|
||||
pnl.panel_list_name,pnl.cdr_filename,pnl.position,pnl.carving_quantity,pnl.thumbnail_large,pnl.carving_filename
|
||||
FROM `cdr_library`.`tbl_web_project` p
|
||||
JOIN `cdr_library`.`tbl_web_room_type` rt ON p.room_data_json LIKE CONCAT('%', rt.guid, '%')
|
||||
JOIN `cdr_library`.`tbl_web_panel_list` pnl ON rt.panel_group_count LIKE CONCAT('%', pnl.guid, '%')
|
||||
WHERE p.guid=@guid ORDER BY rt.room_name;";
|
||||
var parameter = new MySqlParameter("@guid", info.GUID ?? (object)DBNull.Value);
|
||||
WHERE p.guid=@guid ORDER BY rt.room_name;";
|
||||
var parameter = new MySqlParameter("@guid", request.GUID ?? (object)DBNull.Value);
|
||||
// 将当前项目状态置为生成中,避免重复触发或并发问题
|
||||
string updateSql = "UPDATE `cdr_library`.`tbl_web_project` SET edit_status='生成中' WHERE guid=@guid";
|
||||
ExecuteNonQueryWithGuid(updateSql, new[] { parameter }, info.GUID);
|
||||
string updateSql = @"UPDATE `cdr_library`.`tbl_web_project` SET
|
||||
edit_status='生成中',
|
||||
protocol=@protocol,
|
||||
project_name=@project_name,
|
||||
switch_series=@switch_series,
|
||||
socket_series=@socket_series,
|
||||
cn_font=@cn_font,
|
||||
cn_font_size=@cn_font_size,
|
||||
en_font=@en_font,
|
||||
en_font_size=@en_font_size
|
||||
WHERE guid=@guid";
|
||||
|
||||
var updateParameters = new[]
|
||||
{
|
||||
parameter,
|
||||
new MySqlParameter("@protocol", request.Protocol ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@project_name", request.ProjectName ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@switch_series", request.SwitchSeries ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@socket_series", request.SocketSeries ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cn_font", request.ChineseFont ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@cn_font_size", request.ChineseFontSize ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@en_font", request.EnglishFont ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@en_font_size", request.EnglishFontSize ?? (object)DBNull.Value)
|
||||
};
|
||||
ExecuteNonQueryWithGuid(updateSql, updateParameters, request.GUID);
|
||||
|
||||
var eq = ExecuteQuery(sql, new[] { parameter });
|
||||
|
||||
@@ -937,11 +982,59 @@ namespace BLW_Log.Controllers
|
||||
if (projectQueryResult != null && projectQueryResult.response != null) projectToken = JToken.Parse(projectQueryResult.response!.ToString());
|
||||
}
|
||||
catch { projectToken = null; }
|
||||
|
||||
// 在推送到Redis前,为项目数据补充固定尺寸说明字段
|
||||
string switchSizeText = "单体:108*108_二连体:194*108_三连体:280*108_四连体:365*108";
|
||||
string socketSizeText = request.SocketSeries == "玻璃"
|
||||
? "单体:108*108_二连体:194*108_三连体:280*108_四连体:365*108"
|
||||
: "单体:86*86_二连体:172*86_三连体:258*86_四连体:344*86";
|
||||
|
||||
// 确保 projectToken 不为 null,且能新增字段
|
||||
if (projectToken == null)
|
||||
{
|
||||
projectToken = new JObject();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (projectToken is JObject projectObj)
|
||||
{
|
||||
projectObj["SwitchSizeText"] = switchSizeText;
|
||||
projectObj["SocketSizeText"] = socketSizeText;
|
||||
}
|
||||
else if (projectToken is JArray projectArr)
|
||||
{
|
||||
if (projectArr.Count == 0)
|
||||
{
|
||||
projectToken = new JObject
|
||||
{
|
||||
["SwitchSizeText"] = switchSizeText,
|
||||
["SocketSizeText"] = socketSizeText
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in projectArr)
|
||||
{
|
||||
if (item is JObject row)
|
||||
{
|
||||
row["SwitchSizeText"] = switchSizeText;
|
||||
row["SocketSizeText"] = socketSizeText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore
|
||||
}
|
||||
string picNum = Guid.NewGuid().ToString("N");
|
||||
var combinedPayload = new
|
||||
{
|
||||
project = projectToken,
|
||||
panels = panelsToken,
|
||||
RecordDate = DateTime.Now.ToString("yyyy—MM-dd"),
|
||||
picNum
|
||||
};
|
||||
|
||||
@@ -952,15 +1045,36 @@ namespace BLW_Log.Controllers
|
||||
});
|
||||
Dictionary<string, string> pcn = new()
|
||||
{
|
||||
{ picNum, info.GUID ?? string.Empty }
|
||||
{ picNum, request.GUID ?? string.Empty }
|
||||
};
|
||||
|
||||
CSRedisCacheHelper.LPush("PicNumList", pcn);
|
||||
LogOperation(info.UserName, "GetAllProjectCDR", hotel_name, info.GUID, info);
|
||||
LogOperation(request.UserName, "GetAllProjectCDR", hotel_name, request.GUID, request);
|
||||
return new() { isok = success, message = success ? "已提交到生成队列" : "提交到生成队列失败", status = success ? 200 : 500, response = null };
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ReturnInfo GetProjectCdrEnums()
|
||||
{
|
||||
var protocols = GetOrInitEnumValues("protocol", DefaultProtocolOptions);
|
||||
var switchSeries = GetOrInitEnumValues("switch_series", DefaultSwitchSeriesOptions);
|
||||
var socketSeries = new List<string> { "玻璃", "塑料", "无" };
|
||||
|
||||
return new ReturnInfo
|
||||
{
|
||||
isok = true,
|
||||
message = "",
|
||||
status = 200,
|
||||
response = JsonConvert.SerializeObject(new
|
||||
{
|
||||
protocols,
|
||||
switchSeries,
|
||||
socketSeries
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取下载CDR文件的路径表单
|
||||
/// </summary>
|
||||
@@ -1081,10 +1195,41 @@ namespace BLW_Log.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
// 添加整体项目的 CDR 文件到 CDR/ 目录下
|
||||
// 添加整体项目的 CDR 文件到 CDR/ 目录下,并生成同名 PDF 复制品加入 ZIP
|
||||
if (!string.IsNullOrWhiteSpace(projectCdr))
|
||||
{
|
||||
AddFileToZip(archive, _webHostEnvironment.WebRootPath, "\\PanelSelectionPic\\" + projectCdr, $"CDR/{hotel_name}_总预览图.cdr", usedNames);
|
||||
var projectCdrRelative = "\\PanelSelectionPic\\" + projectCdr;
|
||||
AddFileToZip(archive, _webHostEnvironment.WebRootPath, projectCdrRelative, $"CDR/{hotel_name}_总预览图.cdr", usedNames);
|
||||
|
||||
try
|
||||
{
|
||||
// 源文件物理路径
|
||||
var webRoot = _webHostEnvironment.WebRootPath ?? "";
|
||||
var sourcePhysical = Path.Combine(webRoot, projectCdrRelative.TrimStart('\\', '/'));
|
||||
|
||||
if (System.IO.File.Exists(sourcePhysical))
|
||||
{
|
||||
// 把路径最后3个字符替换为 pdf(大小写不敏感的替换)
|
||||
string pdfFilename = projectCdr.Length >= 3
|
||||
? projectCdr.Substring(0, projectCdr.Length - 3) + "pdf"
|
||||
: projectCdr + ".pdf";
|
||||
|
||||
var pdfRelative = "\\PanelSelectionPic\\" + pdfFilename;
|
||||
var pdfPhysical = Path.Combine(webRoot, pdfRelative.TrimStart('\\', '/'));
|
||||
|
||||
// 确保目录存在,然后复制文件(覆盖同名文件)
|
||||
var pdfDir = Path.GetDirectoryName(pdfPhysical);
|
||||
if (!string.IsNullOrEmpty(pdfDir) && !Directory.Exists(pdfDir)) Directory.CreateDirectory(pdfDir);
|
||||
System.IO.File.Copy(sourcePhysical, pdfPhysical, true);
|
||||
|
||||
// 将复制的 PDF 加入压缩包,文件名使用 .pdf 后缀
|
||||
AddFileToZip(archive, webRoot, pdfRelative, $"CDR/{hotel_name}_总预览图.pdf", usedNames);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// 复制失败不应阻塞主流程
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1405,6 +1550,122 @@ namespace BLW_Log.Controllers
|
||||
return guidParam?.Value?.ToString();
|
||||
}
|
||||
|
||||
private static readonly List<string> DefaultProtocolOptions = new() { "强电无线", "弱电485" };
|
||||
private static readonly List<string> DefaultSwitchSeriesOptions = new() { "T1水立方", "T1水晶方", "T3水星阁" };
|
||||
|
||||
private static void ApplyProjectCdrDefaults(GetAllProjectCdrRequest request)
|
||||
{
|
||||
if (request == null) return;
|
||||
|
||||
request.Protocol = string.IsNullOrWhiteSpace(request.Protocol) ? "强电无线" : request.Protocol.Trim();
|
||||
request.SwitchSeries = string.IsNullOrWhiteSpace(request.SwitchSeries) ? "T1水立方" : request.SwitchSeries.Trim();
|
||||
// SocketSeries: null 代表未填写 -> 默认“玻璃”;空字符串代表前端选择“无” -> 保留空字符串
|
||||
if (request.SocketSeries == null || string.IsNullOrWhiteSpace(request.SocketSeries))
|
||||
{
|
||||
request.SocketSeries = "";
|
||||
}
|
||||
else
|
||||
{
|
||||
request.SocketSeries = request.SocketSeries.Trim();
|
||||
}
|
||||
|
||||
request.ChineseFont = string.IsNullOrWhiteSpace(request.ChineseFont) ? "思源黑体" : request.ChineseFont.Trim();
|
||||
request.EnglishFont = string.IsNullOrWhiteSpace(request.EnglishFont) ? "Futura Std Medium" : request.EnglishFont.Trim();
|
||||
request.ChineseFontSize ??= 11.0m;
|
||||
request.EnglishFontSize ??= 7.0m;
|
||||
}
|
||||
|
||||
private List<string> GetOrInitEnumValues(string fieldKey, IEnumerable<string> defaultValues)
|
||||
{
|
||||
var defaults = (defaultValues ?? Array.Empty<string>())
|
||||
.Where(v => !string.IsNullOrWhiteSpace(v))
|
||||
.Select(v => v.Trim())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
string sql = "SELECT values_json FROM `cdr_library`.`tbl_web_enum_values` WHERE field_key=@field_key AND is_valid=1 LIMIT 1";
|
||||
var rs = ExecuteQuery(sql, new[] { new MySqlParameter("@field_key", fieldKey) });
|
||||
|
||||
if (rs?.response == null)
|
||||
{
|
||||
UpsertEnumValues(fieldKey, defaults);
|
||||
return defaults;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var table = JsonConvert.DeserializeObject<DataTable>(rs.response.ToString());
|
||||
var valuesJson = table.Rows[0]["values_json"]?.ToString();
|
||||
var parsed = ParseEnumValuesJson(valuesJson, defaults);
|
||||
if (parsed.Count == 0)
|
||||
{
|
||||
UpsertEnumValues(fieldKey, defaults);
|
||||
return defaults;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
catch
|
||||
{
|
||||
UpsertEnumValues(fieldKey, defaults);
|
||||
return defaults;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<string> ParseEnumValuesJson(string valuesJson, List<string> fallback)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(valuesJson)) return fallback;
|
||||
|
||||
try
|
||||
{
|
||||
var arr = JArray.Parse(valuesJson);
|
||||
var list = arr
|
||||
.Select(t => t?.ToString())
|
||||
.Where(s => !string.IsNullOrWhiteSpace(s))
|
||||
.Select(s => s.Trim())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
return list;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureEnumValueExists(string fieldKey, string value, IEnumerable<string> defaultValues)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(fieldKey) || string.IsNullOrWhiteSpace(value)) return;
|
||||
|
||||
var normalizedValue = value.Trim();
|
||||
var values = GetOrInitEnumValues(fieldKey, defaultValues);
|
||||
|
||||
if (values.Contains(normalizedValue)) return;
|
||||
|
||||
values.Add(normalizedValue);
|
||||
UpsertEnumValues(fieldKey, values);
|
||||
}
|
||||
|
||||
private void UpsertEnumValues(string fieldKey, IEnumerable<string> values)
|
||||
{
|
||||
var list = (values ?? Array.Empty<string>())
|
||||
.Where(v => !string.IsNullOrWhiteSpace(v))
|
||||
.Select(v => v.Trim())
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
string sql = @"INSERT INTO `cdr_library`.`tbl_web_enum_values`(field_key, values_json, is_valid, created_at)
|
||||
VALUES(@field_key, @values_json, 1, NOW())
|
||||
ON DUPLICATE KEY UPDATE values_json=@values_json, is_valid=1";
|
||||
|
||||
var parameters = new[]
|
||||
{
|
||||
new MySqlParameter("@field_key", fieldKey ?? (object)DBNull.Value),
|
||||
new MySqlParameter("@values_json", JsonConvert.SerializeObject(list))
|
||||
};
|
||||
ExecuteNonQueryWithGuid(sql, parameters);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -1436,6 +1697,23 @@ namespace BLW_Log.Controllers
|
||||
public string? GUID { get; set; }
|
||||
public string? UserName { get; set; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 请求类:用于 GetAllProjectCDR 接口
|
||||
/// 包含:GUID, UserName, Protocol(协议), ProjectName(项目名称), SwitchSeries(开关系列), SocketSeries(插座系列)
|
||||
/// </summary>
|
||||
public class GetAllProjectCdrRequest
|
||||
{
|
||||
public string? GUID { get; set; }
|
||||
public string? UserName { get; set; }
|
||||
public string? Protocol { get; set; }
|
||||
public string? ProjectName { get; set; }
|
||||
public string? SwitchSeries { get; set; }
|
||||
public string? SocketSeries { get; set; }
|
||||
public string? ChineseFont { get; set; }
|
||||
public decimal? ChineseFontSize { get; set; }
|
||||
public string? EnglishFont { get; set; }
|
||||
public decimal? EnglishFontSize { get; set; }
|
||||
}
|
||||
public class TblWebLog
|
||||
{
|
||||
public long id { get; set; }
|
||||
@@ -1539,6 +1817,14 @@ namespace BLW_Log.Controllers
|
||||
public string? guid { get; set; }
|
||||
public string? edit_status { get; set; }
|
||||
public string? cdr_filename { get; set; }
|
||||
public string? protocol { get; set; }
|
||||
public string? project_name { get; set; }
|
||||
public string? switch_series { get; set; }
|
||||
public string? socket_series { get; set; }
|
||||
public string? cn_font { get; set; }
|
||||
public decimal? cn_font_size { get; set; }
|
||||
public string? en_font { get; set; }
|
||||
public decimal? en_font_size { get; set; }
|
||||
public TblWebProject()
|
||||
{
|
||||
this.created_at = DateTime.Now;
|
||||
|
||||
Reference in New Issue
Block a user