From 7a40849a91c3f4cc7bb12aacb7473018e26c6f85 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期二, 29 四月 2025 11:29:49 +0800
Subject: [PATCH] 1.MES->OA主表+图片推送成功。
---
Controllers/QC/OAJyController.cs | 2
service/QC/OaApi.cs | 242 ++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 203 insertions(+), 41 deletions(-)
diff --git a/Controllers/QC/OAJyController.cs b/Controllers/QC/OAJyController.cs
index 44228f0..3587ecc 100644
--- a/Controllers/QC/OAJyController.cs
+++ b/Controllers/QC/OAJyController.cs
@@ -15,7 +15,7 @@
OaApiService m = new OaApiService();
[HttpPost("SumbitIQCToOA")]
- public ResponseResult SumbitIQCToOA([FromBody] dynamic queryObj)
+ public ResponseResult SumbitIQCToOA(dynamic queryObj)
{
try
{
diff --git a/service/QC/OaApi.cs b/service/QC/OaApi.cs
index e4d2669..00964f7 100644
--- a/service/QC/OaApi.cs
+++ b/service/QC/OaApi.cs
@@ -7,12 +7,18 @@
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
+using NewPdaSqlServer.entity.Base;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
+using NewPdaSqlServer.DB;
+using SqlSugar;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
+using NewPdaSqlServer.entity;
+using System.Linq;
-public class OaApiService : IDisposable
+public class OaApiService : Repository<dynamic>
{
private readonly HttpClient _httpClient;
private const string AppId = "303233EF-AC39-40C1-8364-AC989C6258A5";
@@ -27,16 +33,14 @@
public async Task<dynamic> SubmitIQCToOA(dynamic queryObj)
{
-
- //if (unity.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖");
- //if (unity.sectionCode.IsNullOrEmpty()) throw new Exception("搴撲綅缂栧彿涓嶅厑璁镐负绌�");
- //if (unity.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�");
- //if (unity.billNo.IsNullOrEmpty()) throw new Exception("鐢宠鍗曞彿涓嶅厑璁镐负绌�");
+ // 淇敼鍙傛暟楠岃瘉瀛楁鍚�
+ //if (queryObj.userId.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛id涓嶅厑璁镐负绌�");
+ //if (queryObj.qcczdGuid.IsNullOrEmpty()) throw new Exception("寮傚父澶勭疆鍗昳d涓嶈兘涓虹┖"); // 鍘熷弬鏁板悕涓� qcczdGuid
try
{
// 瑙f瀽璇锋眰鍙傛暟
- var query = queryObj;
+ //var query = queryObj;
//var query = JObject.FromObject(queryObj);
// 1. 娉ㄥ唽鑾峰彇鍑瘉
@@ -55,7 +59,7 @@
_httpClient.DefaultRequestHeaders.Add("userid", RSAEncrypt("1268", spk));
// 4. 鏋勫缓璇锋眰浣�
- var requestData = BuildRequestData();
+ var requestData = BuildRequestData(queryObj);
// 5. 鍙戦�佽姹�
var response = await PostFormAsync(WorkflowUrl, requestData);
@@ -70,46 +74,201 @@
}
}
- private Dictionary<string, object> BuildRequestData()
+ private Dictionary<string, object> BuildRequestData(dynamic queryObj)
{
// 浠巕uery鍙傛暟涓幏鍙栧疄闄呬笟鍔℃暟鎹�
return new Dictionary<string, object>
{
- {"mainData", BuildMainData()},
- {"requestName", $"IQC娴佺▼-{DateTime.Now:yyyyMMddHHmmss}"},
+ {"mainData", BuildMainData(queryObj)},
+ {"requestName", $"IQC寮傚父澶勭疆鍗曟祦绋�-{DateTime.Now:yyyyMMddHHmmss}"},
{"workflowId", "379"},
//{"otherParams", BuildOtherParams()},
- //{"detailData", BuildDetailData(query)}
+ //{"detailData", BuildDetailData(queryObj)}
};
+ }
+
+ private JArray createbhgpqxmszp(dynamic files)
+ {
+ var attachments = new JArray();
+
+ foreach (var file in files ?? Enumerable.Empty<dynamic>())
+ {
+ attachments.Add(new JObject
+ {
+ // 淇瀛楁鍚嶇О鍖归厤鏍囧噯鏍煎紡
+ ["filePath"] = file.url?.ToString() ?? string.Empty,
+ ["fileName"] = file.FileName?.ToString() ?? "鏈懡鍚嶆枃浠�"
+ });
+ }
+
+ return attachments;
+ }
+ private JArray BuildMainData(dynamic queryObj)
+ {
+ // 浣跨敤鍙傛暟鍖栨煡璇㈤槻姝QL娉ㄥ叆
+ const string mainSql = @"
+SELECT TOP 1
+ C.item_no AS wlbm,
+ C.item_name AS jzmcwlmc,
+ D.supp_name AS khgys,
+ B.bill_no AS dhdhmes,
+ B.remark AS bhgpqxms
+FROM Mes_QC_Exceptional A
+LEFT JOIN MES_INV_ITEM_ARN B ON A.aboutGuid = b.guid
+LEFT JOIN MES_ITEMS C ON A.itemId = c.item_id
+LEFT JOIN MES_SUPPLIER D ON B.supp_id = D.id
+WHERE a.guid = @guid";
+
+ var mainData = Db.Ado.SqlQuery<dynamic>(mainSql, new { guid = queryObj.qcczdGuid });
+
+ // 鏇寸簿纭殑鏁版嵁瀛樺湪鎬ф鏌�
+ if (mainData == null || !mainData.Any())
+ {
+ throw new Exception($"鏈壘鍒板紓甯稿缃崟[{queryObj.qcczdGuid}]鐩稿叧鏁版嵁");
+ }
+ var firstRecord = mainData.First();
+
+ // 瀛楁鏄犲皠閰嶇疆锛堝瓧娈靛悕 -> 鏁版嵁搴撳垪鍚嶏級
+ var fieldMappings = new Dictionary<string, (string Field, string Default)>
+ {
+ ["wlbm"] = ("wlbm", "N/A"),
+ ["khgys"] = ("khgys", "N/A"),
+ ["jzmcwlmc"] = ("jzmcwlmc", "N/A"),
+ ["dhdhmes"] = ("dhdhmes", "N/A"),
+ ["bhgpqxms"] = ("bhgpqxms", "鏃犵己闄锋弿杩�")
+ };
+
+ // 鍔ㄦ�佺敓鎴愬瓧娈甸泦鍚�
+ var result = new JArray();
+ foreach (var mapping in fieldMappings)
+ {
+ var value = GetDynamicValue(firstRecord, mapping.Value.Field, mapping.Value.Default);
+ result.Add(new JObject
+ {
+ ["fieldName"] = mapping.Key,
+ ["fieldValue"] = value
+ });
+ }
+
+ // 澶勭悊鏂囦欢鏁版嵁
+ const string fileSql = @"
+SELECT
+ release_no+'-鍥剧墖'+CAST(row_number() over (order by release_no) AS VARCHAR(20)) AS FileName,
+ 'http://192.168.1.145:81/upload/'+url_Path as url
+FROM [Mes_QC_Exceptional_Detail] A
+LEFT JOIN MES_QA_ITEMS_DETECT_01 B ON A.releaseNo = B.release_no
+LEFT JOIN MES_FILE C ON C.parent_Guid = B.guid
+WHERE pGuid = @guid";
+
+ var fileData = Db.Ado.SqlQuery<dynamic>(fileSql, new { guid = queryObj.qcczdGuid });
+ var files = CreateFileData(fileData);
+
+ // 娣诲姞鏂囦欢瀛楁
+ result.Add(new JObject
+ {
+ ["fieldName"] = "bhgpqxmszp",
+ ["fieldValue"] = files
+ });
+
+ return result;
}
- private JArray BuildMainData()
+ // 杈呭姪鏂规硶锛氬畨鍏ㄨ幏鍙杁ynamic瀵硅薄鍊�
+ private static string GetDynamicValue(dynamic record, string field, string defaultValue)
{
- // 绀轰緥瀛楁锛屾牴鎹疄闄呬笟鍔¢渶姹傝皟鏁�
- return new JArray
+ try
{
- new JObject
- {
- ["fieldName"] = "wlbm",
- ["fieldValue"] = "1.01.01.001"
- },
- new JObject
- {
- ["fieldName"] = "khgys",
- ["fieldValue"] = "闄堥洩骞�"
- },
- new JObject
- {
- ["fieldName"] = "bhgpqxms",
- ["fieldValue"] = "澶栬涓嶅悎鏍硷紝灏哄涓嶅悎鏍硷紝棰滆壊涓嶇鍚�"
- },
- new JObject
- {
- ["fieldName"] = "dhdhmes",
- ["fieldValue"] = "MES001"
- }
- };
+ return ((IDictionary<string, object>)record)[field]?.ToString() ?? defaultValue;
+ }
+ catch
+ {
+ return defaultValue;
+ }
}
+
+ // 鏂囦欢鏁版嵁鐢熸垚鏂规硶锛堢ず渚嬩繚鎸佸師閫昏緫锛�
+ private JArray CreateFileData(IEnumerable<dynamic> fileData)
+ {
+ // 鍋囪杩欐槸鍘焎reatebhgpqxmszp鏂规硶鐨勫疄鐜�
+ return new JArray(fileData.Select(f => new JObject
+ {
+ ["fileName"] = f.FileName,
+ ["filePath"] = f.url
+ }));
+ }
+
+ // // 淇敼BuildMainData涓殑瀛楁璧嬪��
+ // private JArray BuildMainData(dynamic queryObj)
+ // {
+ // var sql = string.Format(@"select TOP 1 C.item_no AS wlbm,
+ // C.item_name AS jzmcwlmc,
+ // D.supp_name AS khgys,
+ // B.bill_no AS dhdhmes,
+ // B.remark AS bhgpqxms
+ //from Mes_QC_Exceptional A
+ // LEFT JOIN MES_INV_ITEM_ARN B
+ // ON A.aboutGuid = b.guid
+ // LEFT JOIN MES_ITEMS C ON A.itemId = c.item_id
+ // LEFT JOIN MES_SUPPLIER D ON B.supp_id = D.id
+ //WHERE a.guid = '{0}'", queryObj.qcczdGuid);
+
+ // var tBiqcczd = Db.Ado.SqlQuery<dynamic>(sql);
+
+ // // 淇鏁版嵁鑾峰彇閫昏緫
+ // if (tBiqcczd == null)
+ // {
+ // throw new Exception($"鏈壘鍒板紓甯稿缃崟[{queryObj.qcczdGuid}]鐩稿叧鏁版嵁");
+ // }
+ // var data = tBiqcczd; // 杞崲涓哄瓧鍏歌闂�
+
+ // var wlbm = data[0]["wlbm"];
+
+ // var sql1 = string.Format(@"select release_no+'-鍥剧墖'+CAST(row_number() over (order by release_no) AS VARCHAR(20)) AS FileName, 'http://192.168.1.145:81/upload/'+url_Path as url
+ //from [Mes_QC_Exceptional_Detail] A
+ // LEFT JOIN MES_QA_ITEMS_DETECT_01 B ON A.releaseNo = B.release_no
+ // LEFT JOIN MES_FILE C ON C.parent_Guid = B.guid
+ //WHERE pGuid = '{0}'", queryObj.qcczdGuid);
+
+ // var tBdataFile = Db.Ado.SqlQuery<dynamic>(sql1);
+
+ // var data_file = createbhgpqxmszp(tBdataFile);
+
+
+ // return new JArray
+ // {
+ // // 淇敼鎵�鏈夊瓧娈佃闂柟寮忥紙浠lbm涓轰緥锛�
+ // new JObject
+ // {
+ // ["fieldName"] = "wlbm",
+ // ["fieldValue"] = data?["wlbm"]?.ToString() ?? "N/A" // 浣跨敤瀛楀吀鏂瑰紡璁块棶
+ // },
+ // new JObject
+ // {
+ // ["fieldName"] = "khgys",
+ // ["fieldValue"] = data?["khgys"]?.ToString() ?? "N/A" // 缁熶竴瀛楀吀璁块棶
+ // },
+ // new JObject
+ // {
+ // ["fieldName"] = "jzmcwlmc",
+ // ["fieldValue"] = data?["jzmcwlmc"]?.ToString() ?? "N/A" // 缁熶竴瀛楀吀璁块棶
+ // },
+ // new JObject
+ // {
+ // ["fieldName"] = "dhdhmes",
+ // ["fieldValue"] = data?["dhdhmes"]?.ToString() ?? "N/A" // 缁熶竴瀛楀吀璁块棶
+ // },
+ // new JObject
+ // {
+ // ["fieldName"] = "bhgpqxms",
+ // ["fieldValue"] = data?["bhgpqxms"]?.ToString() ?? "鏃犵己闄锋弿杩�" // 缁熶竴瀛楀吀璁块棶
+ // },
+ // new JObject
+ // {
+ // ["fieldName"] = "bhgpqxmszp",
+ // ["fieldValue"] = data_file // 浣跨敤鐢熸垚鐨勯檮浠舵暟缁�
+ // },
+ // };
+ // }
private JArray BuildAttachments(JToken attachments)
{
@@ -136,7 +295,7 @@
{
new JObject
{
- ["tableDBName"] = "formtable_main_24_dt1",
+ ["tableDBName"] = "formtable_main_33_dt1",
["workflowRequestTableRecords"] = new JArray
{
new JObject
@@ -144,9 +303,12 @@
["recordOrder"] = "0",
["workflowRequestTableFields"] = new JArray
{
- new JObject { ["fieldName"] = "xm", ["fieldValue"] = query["inspector"] ?? "榛樿妫�楠屽憳" },
- new JObject { ["fieldName"] = "bh", ["fieldValue"] = query["batchNo"] ?? "榛樿鎵规鍙�" },
- new JObject { ["fieldName"] = "dz", ["fieldValue"] = query["location"] ?? "榛樿鍦扮偣" }
+ new JObject { ["fieldName"] = "jydh", ["fieldValue"] = query[""] ?? "妫�楠屽崟鍙�" },
+ new JObject { ["fieldName"] = "jydrq", ["fieldValue"] = query[""] ?? "妫�楠屽崟鏃ユ湡" },
+ new JObject { ["fieldName"] = "sjsl", ["fieldValue"] = query[""] ?? "娑夊強鏁伴噺" },
+ new JObject { ["fieldName"] = "cys", ["fieldValue"] = query[""] ?? "鎶芥牱鏁�" },
+ new JObject { ["fieldName"] = "bls", ["fieldValue"] = query[""] ?? "涓嶈壇鏁�" },
+ new JObject { ["fieldName"] = "bll", ["fieldValue"] = query[""] ?? "涓嶈壇鐜�" }
}
}
}
--
Gitblit v1.9.3