新增:伙伴云API对接 控制器
This commit is contained in:
@@ -5,6 +5,7 @@ using NLog;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using static Google.Protobuf.Reflection.SourceCodeInfo.Types;
|
||||
|
||||
@@ -13,11 +14,11 @@ namespace BLW_Log.Models
|
||||
public class PanelSelectionClass : BackgroundService
|
||||
{
|
||||
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
|
||||
public static ConcurrentBag<Dictionary<string, string>> PicNumList = new();
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
await Task.Factory.StartNew(async () =>
|
||||
{
|
||||
//return; // 老服务器需要注释此行代码
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
try
|
||||
@@ -26,7 +27,7 @@ namespace BLW_Log.Models
|
||||
Dictionary<string, string> PicNum = CSRedisCacheHelper.BRPop<Dictionary<string, string>>("PicNumList");
|
||||
|
||||
_logger.Info("开始执行Redis轮询");
|
||||
if(PicNum != null)
|
||||
if (PicNum != null)
|
||||
{
|
||||
var pair = PicNum.ElementAt(0);
|
||||
_logger.Info($"开始处理{pair.Key}");
|
||||
@@ -36,63 +37,70 @@ namespace BLW_Log.Models
|
||||
try
|
||||
{
|
||||
// 反序列化Redis返回的数据
|
||||
var redisResult = JsonConvert.DeserializeObject<RedisSendNode>(RS);
|
||||
|
||||
if (redisResult != null)
|
||||
var rss = JsonConvert.DeserializeObject<TypeNode>(RS);
|
||||
var redisResult = rss.MsgNode;
|
||||
if (rss.MsgType == 1)
|
||||
{
|
||||
bool isUnitPanel = pair.Key.StartsWith("Unit");
|
||||
bool updateSuccess = false;
|
||||
|
||||
if (redisResult.Process == 0)
|
||||
if (redisResult != null)
|
||||
{
|
||||
// Process=0: 预览小图
|
||||
bool isUnitPanel = pair.Key.StartsWith("Unit");
|
||||
bool updateSuccess = false;
|
||||
|
||||
// Process=0: 预览小图 1: CDR
|
||||
updateSuccess = UpdatePanelThumbnail(
|
||||
pair.Value,
|
||||
redisResult.ImagePath,
|
||||
redisResult.Process == 0 ? redisResult.ImagePath : redisResult.CdrPath,
|
||||
isUnitPanel,
|
||||
0
|
||||
redisResult.Process
|
||||
);
|
||||
|
||||
if (updateSuccess)
|
||||
{
|
||||
CSRedisCacheHelper.Del(pair.Key);
|
||||
_logger.Info($"成功更新{pair.Value}的thumbnail_large");
|
||||
}
|
||||
else
|
||||
{
|
||||
Dictionary<string, string> newDic = new()
|
||||
{
|
||||
{ pair.Key, pair.Value }
|
||||
};
|
||||
CSRedisCacheHelper.LPush("PicNumList", newDic);
|
||||
}
|
||||
}
|
||||
else if (redisResult.Process == 1)
|
||||
}
|
||||
else if (rss.MsgType == 2)
|
||||
{
|
||||
if (redisResult != null)
|
||||
{
|
||||
// Process=1: 生成文件
|
||||
updateSuccess = UpdatePanelThumbnail(
|
||||
bool isUnitPanel = pair.Key.StartsWith("Unit");
|
||||
bool updateSuccess = false;
|
||||
|
||||
updateSuccess = UpdatePorjectCdrpath(
|
||||
pair.Value,
|
||||
redisResult.CdrPath,
|
||||
isUnitPanel,
|
||||
1
|
||||
redisResult.CdrPath
|
||||
);
|
||||
|
||||
if (updateSuccess)
|
||||
{
|
||||
CSRedisCacheHelper.Del(pair.Key);
|
||||
_logger.Info($"成功更新{pair.Value}的cdr_filename");
|
||||
}
|
||||
}
|
||||
|
||||
// 无论成功与否,都从Redis中删除该键
|
||||
CSRedisCacheHelper.Del(pair.Key);
|
||||
|
||||
// 如果更新bu成功,可以从PicNumList中移除该项
|
||||
if (!updateSuccess)
|
||||
{
|
||||
Dictionary<string, string> newDic = new()
|
||||
else
|
||||
{
|
||||
{ pair.Key, pair.Value }
|
||||
};
|
||||
CSRedisCacheHelper.LPush("PicNumList", newDic);
|
||||
Dictionary<string, string> newDic = new()
|
||||
{
|
||||
{ pair.Key, pair.Value }
|
||||
};
|
||||
CSRedisCacheHelper.LPush("PicNumList", newDic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Error($"处理Redis消息失败: {ex.Message}");
|
||||
// 发生异常时也删除Redis键,避免重复处理
|
||||
CSRedisCacheHelper.Del(pair.Key);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -104,17 +112,81 @@ namespace BLW_Log.Models
|
||||
CSRedisCacheHelper.LPush("PicNumList", newDic);
|
||||
}
|
||||
}
|
||||
await Task.Delay(1000);
|
||||
await Task.Delay(1145);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Info("Redis轮询err:" + ex.StackTrace + " | " + ex.Message);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
}
|
||||
|
||||
private bool UpdatePanelThumbnail(string guid, string imagePath, bool isUnitPanel, int process)
|
||||
private bool UpdatePanelThumbnail(string guid, string imagePathPlt, bool isUnitPanel, int? process)
|
||||
{
|
||||
try
|
||||
{
|
||||
string imagePath = Regex.Replace(imagePathPlt, @"\.plt$", ".cdr", RegexOptions.IgnoreCase);
|
||||
using var conn = new MySqlConnection(ReadConfig.Instance.MySQLConnectionString);
|
||||
conn.Open();
|
||||
|
||||
string sql;
|
||||
using var cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
if (isUnitPanel)
|
||||
{
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_unit`
|
||||
SET thumbnail_large = @ImagePath, design_status = ''
|
||||
WHERE guid = @Guid";
|
||||
cmd.CommandText = sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (process == 0)
|
||||
{
|
||||
// Process=0: 更新thumbnail_large,设置design_status为空
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_list`
|
||||
SET thumbnail_large = @ImagePath, design_status = ''
|
||||
WHERE guid = @Guid";
|
||||
cmd.CommandText = sql;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Process=1: 更新cdr_filename,设置design_status为空
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_list`
|
||||
SET cdr_filename = @ImagePath, carving_filename = @carving_filename, design_status = ''
|
||||
WHERE guid = @Guid";
|
||||
cmd.CommandText = sql;
|
||||
cmd.Parameters.AddWithValue("@carving_filename", imagePathPlt);
|
||||
}
|
||||
}
|
||||
cmd.Parameters.AddWithValue("@ImagePath", imagePath);
|
||||
cmd.Parameters.AddWithValue("@Guid", guid);
|
||||
using var cmdRt = new MySqlCommand("SELECT design_status FROM `cdr_library`.`tbl_web_panel_list` WHERE guid=@Guid;", conn);
|
||||
cmdRt.Parameters.AddWithValue("@Guid", guid);
|
||||
|
||||
int affectedRows = cmd.ExecuteNonQuery();
|
||||
var affectedRowsRt = cmdRt.ExecuteScalar() != null ? cmdRt.ExecuteScalar().ToString() : "";
|
||||
if (string.IsNullOrEmpty(affectedRowsRt))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 记录日志
|
||||
_logger.Error($"更新面板数据失败: {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private bool UpdatePorjectCdrpath(string guid, string imagePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -122,47 +194,27 @@ namespace BLW_Log.Models
|
||||
conn.Open();
|
||||
|
||||
string sql;
|
||||
if (isUnitPanel)
|
||||
using var cmd = new MySqlCommand();
|
||||
cmd.Connection = conn;
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_project`
|
||||
SET cdr_filename = @ImagePath, edit_status = ''
|
||||
WHERE guid = @Guid";
|
||||
cmd.CommandText = sql;
|
||||
cmd.Parameters.AddWithValue("@ImagePath", imagePath);
|
||||
cmd.Parameters.AddWithValue("@Guid", guid);
|
||||
using var cmdRt = new MySqlCommand("SELECT edit_status FROM `cdr_library`.`tbl_web_project` WHERE guid=@Guid;", conn);
|
||||
cmdRt.Parameters.AddWithValue("@Guid", guid);
|
||||
|
||||
int affectedRows = cmd.ExecuteNonQuery();
|
||||
var affectedRowsRt = cmdRt.ExecuteScalar() != null ? cmdRt.ExecuteScalar().ToString() : "";
|
||||
if (string.IsNullOrEmpty(affectedRowsRt))
|
||||
{
|
||||
if (process == 0)
|
||||
{
|
||||
// Process=0: 更新thumbnail_large,设置design_status为空
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_unit`
|
||||
SET thumbnail_large = @ImagePath, design_status = ''
|
||||
WHERE guid = @Guid";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Process=1: 更新cdr_filename,设置thumbnail_small为空
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_unit`
|
||||
SET cdr_filename = @ImagePath, thumbnail_small = ''
|
||||
WHERE guid = @Guid";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (process == 0)
|
||||
{
|
||||
// Process=0: 更新thumbnail_large,设置thumbnail_small为空
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_list`
|
||||
SET thumbnail_large = @ImagePath, thumbnail_small = ''
|
||||
WHERE guid = @Guid";
|
||||
}
|
||||
else
|
||||
{
|
||||
// Process=1: 更新cdr_filename,设置thumbnail_small为空
|
||||
sql = $@"UPDATE `cdr_library`.`tbl_web_panel_list`
|
||||
SET cdr_filename = @ImagePath, thumbnail_small = ''
|
||||
WHERE guid = @Guid";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
using var cmd = new MySqlCommand(sql, conn);
|
||||
cmd.Parameters.AddWithValue("@ImagePath", imagePath);
|
||||
cmd.Parameters.AddWithValue("@Guid", guid);
|
||||
|
||||
int affectedRows = cmd.ExecuteNonQuery();
|
||||
return affectedRows > 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -172,7 +224,14 @@ namespace BLW_Log.Models
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class RedisInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 列表
|
||||
/// </summary>
|
||||
public object ObjToRedis { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
public class RedisInfoNode
|
||||
{
|
||||
/// <summary>
|
||||
@@ -314,7 +373,11 @@ namespace BLW_Log.Models
|
||||
/// </summary>
|
||||
public string LineNumber { get; set; }
|
||||
}
|
||||
|
||||
public class TypeNode
|
||||
{
|
||||
public int MsgType { get; set; }
|
||||
public RedisSendNode MsgNode { get; set; }
|
||||
}
|
||||
public class RedisSendNode
|
||||
{
|
||||
/// <summary>
|
||||
@@ -353,7 +416,7 @@ namespace BLW_Log.Models
|
||||
/// 流程
|
||||
/// 0-预览小图 1-生成文件
|
||||
/// </summary>
|
||||
public int Process { get; set; }
|
||||
public int? Process { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 图号
|
||||
@@ -388,6 +451,11 @@ namespace BLW_Log.Models
|
||||
/// <summary>
|
||||
/// 返回信息
|
||||
/// </summary>
|
||||
public string Msg { get; set; }
|
||||
public string? Msg { get; set; }
|
||||
}
|
||||
public class CellCorelDRAW
|
||||
{
|
||||
public int MsgType { get; set; }
|
||||
public object MsgNode { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user