using MES.Service.Dto.webApi; using MES.Service.Dto.webApi.QcIssueResult; using MES.Service.Modes; using MES.Service.Modes.QcIssueResult; using MES.Service.Modes.SentLaboratory; using MES.Service.service; using MES.Service.service.QcIssueResult; using MES.Service.util; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Diagnostics; using System.Dynamic; using System.Net; using System.Text; using System.Text.Json.Nodes; using System.Web; namespace MESApplication.Controllers.QcIssueResult; [ApiController] [Route("api/[controller]")] public class QcIssueResultController : ControllerBase { private readonly MessageCenterManager _manager = new(); private readonly QcIssueResultManager m = new(); private readonly string METHOD = "POST"; private readonly string TableName = "MES_QCISSUE_RESULT"; private readonly string URL = "http://localhost:10054/api/QcIssueResult/"; [HttpPost("GetProcessNo")] public IActionResult StartDingtalkProcess([FromBody] GetQcIssueResultDetail getQcIssueResultDetail) { try { // 新增URL解码处理逻辑 DecodeUrlEncodedProperties(getQcIssueResultDetail); // 调用 QcIssueResultManager 中的 GetProcessNo 方法来启动钉钉工作流实例 string result = m.GetProcessNo(getQcIssueResultDetail); string getLaboratoryDetailsJson = JsonConvert.SerializeObject(getQcIssueResultDetail, Formatting.Indented); Debug.WriteLine("getQcIssueResultDetail: " + getLaboratoryDetailsJson); string jsonPart = result.Substring(result.IndexOf("{")); JObject jsonObject = JObject.Parse(jsonPart); // 提取instanceId的值 string instanceId = jsonObject["InstanceId"].ToString(); dynamic resultInfos = new ExpandoObject(); string ProcessNo = instanceId; var save = m.SaveProcessNo(getQcIssueResultDetail.ReleaseNo, instanceId); resultInfos.tbBillList = save; return Ok(result); } catch (Exception ex) { // 捕获异常并返回错误信息 return StatusCode(500, $"启动钉钉工作流实例失败: {ex.Message}"); } } // 新增解码方法 private void DecodeUrlEncodedProperties(object obj) { if (obj == null) return; var properties = obj.GetType().GetProperties(); foreach (var prop in properties) { // 只处理字符串类型的属性 if (prop.PropertyType == typeof(string) && prop.CanWrite) { var value = prop.GetValue(obj) as string; if (!string.IsNullOrEmpty(value)) { // 使用UTF8编码进行解码 var decodedValue = HttpUtility.UrlDecode(value, Encoding.UTF8); prop.SetValue(obj, decodedValue); } } } } [HttpPost("Save")] public ResponseResult Save(ErpQcIssueResult erpQcIssueResult) { var entity = new MessageCenter(); entity.TableName = TableName; entity.Url = URL + "Save"; entity.Method = METHOD; entity.Data = JsonConvert.SerializeObject(erpQcIssueResult); entity.Status = 1; entity.CreateBy = "PL017"; try { dynamic resultInfos = new ExpandoObject(); var save = m.Save(erpQcIssueResult); resultInfos.tbBillList = save; entity.Result = 0; if (save) entity.Result = 1; entity.DealWith = 1; _manager.save(entity); return new ResponseResult { status = 0, message = "OK", data = resultInfos }; } catch (Exception ex) { entity.Result = 0; entity.DealWith = 0; entity.ResultData = ex.Message; _manager.save(entity); return ResponseResult.ResponseError(ex); } } }