| | |
| | | using Newtonsoft.Json; |
| | | using Oracle.ManagedDataAccess.Client; |
| | | using System.Data; |
| | | using System.Reflection; |
| | | using System.Text; |
| | | using DingTalk.Api; |
| | | using System.Net.Http; |
| | | |
| | | namespace MES.Service.service.QcIssueResult; |
| | | |
| | | //异常处置单结果表 |
| | | [SugarTable("MES_QA_ITEMS_DETECT_01")] |
| | | public class QcIssueResultManager: Repository<QcIssueResults> |
| | | public class QcIssueResultManager : Repository<QcIssueResults> |
| | | { |
| | | /** |
| | | * 使用 Token 初始化账号Client |
| | |
| | | AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client client = CreateClient1(); |
| | | AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest getAccessTokenRequest = new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Models.GetAccessTokenRequest |
| | | { |
| | | AppKey = "dingyzos0r1bizj7g6lr", |
| | | AppSecret = "-HP4RvK2OUbqhG3iBUpd_TPe5MZRj8cfLc0b8Skt8rhC3I38kVLY9SS8P3kLWFcH", |
| | | AppKey = "ding8nmegrbi29a78ze0", |
| | | AppSecret = "CwWeKXzItBJktsVhGoZi73Ts79bP8qp3FuLmS5PtJgNmMxrWFaqdQQTY0RqCRQSC", |
| | | }; |
| | | |
| | | try |
| | |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ProcessForecastRequest processForecastRequest = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ProcessForecastRequest |
| | | { |
| | | ProcessCode = "PROC-BBA5632D-DC7C-4267-A3E2-757E2B7023BC", |
| | | ProcessCode = "PROC-4F4B3976-BA15-47EF-9A3C-3A07AC07DFEA", |
| | | DeptId = 1, |
| | | UserId = "923188102", |
| | | FormComponentValues = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.ProcessForecastRequest.ProcessForecastRequestFormComponentValues> |
| | |
| | | } |
| | | catch (TeaException err) |
| | | { |
| | | |
| | | return $"TeaException: Code={err.Code}, Message={err.Message}"; |
| | | |
| | | |
| | | return $"TeaException: Code={err.Code}, Message={err.Message}"; |
| | | |
| | | } |
| | | catch (Exception _err) |
| | | { |
| | | return $"Exception: {_err.Message}"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取userid |
| | | * @return string 返回启动结果 |
| | | */ |
| | | public HttpClient _httpClient; |
| | | public string DingTalkService() |
| | | { |
| | | _httpClient = new HttpClient(); |
| | | _httpClient.Timeout = TimeSpan.FromSeconds(30); |
| | | return "1"; |
| | | } |
| | | |
| | | public async Task<string> GetUserId(string phone) |
| | | { |
| | | // 参数验证 |
| | | if (string.IsNullOrWhiteSpace(phone)) |
| | | throw new ArgumentException("手机号不能为空", nameof(phone)); |
| | | |
| | | // 获取访问令牌 |
| | | string accessToken = GetToken(); |
| | | |
| | | // 调用现有方法 |
| | | return await GetUserIdByMobile(accessToken, phone); |
| | | } |
| | | |
| | | |
| | | |
| | | public async Task<string> GetUserIdByMobile(string accessToken, string mobile) |
| | | { |
| | | // 参数验证 |
| | | if (string.IsNullOrWhiteSpace(accessToken)) |
| | | throw new ArgumentException("Access token cannot be empty", nameof(accessToken)); |
| | | |
| | | if (string.IsNullOrWhiteSpace(mobile) || !IsValidMobile(mobile)) |
| | | throw new ArgumentException("Invalid mobile number", nameof(mobile)); |
| | | |
| | | try |
| | | { |
| | | // 构造请求URL |
| | | var url = $"https://oapi.dingtalk.com/topapi/v2/user/getbymobile?access_token={accessToken}"; |
| | | |
| | | string m = DingTalkService(); |
| | | |
| | | // 构造请求体 |
| | | var requestBody = new { mobile }; |
| | | var jsonContent = JsonConvert.SerializeObject(requestBody); |
| | | var content = new StringContent(jsonContent, Encoding.UTF8, "application/json"); |
| | | |
| | | // 发送请求 |
| | | var response = await _httpClient.PostAsync(url, content); |
| | | |
| | | // 处理响应 |
| | | response.EnsureSuccessStatusCode(); |
| | | |
| | | var responseBody = await response.Content.ReadAsStringAsync(); |
| | | var result = JsonConvert.DeserializeObject<DingTalkResponse>(responseBody); |
| | | |
| | | // 处理业务逻辑错误 |
| | | if (result?.Errcode != 0) |
| | | throw new DingTalkApiException(result?.Errcode ?? -1, result?.Errmsg ?? "Unknown error"); |
| | | |
| | | return result?.Result?.UserId ?? throw new InvalidOperationException("User ID not found in response"); |
| | | } |
| | | catch (HttpRequestException ex) |
| | | { |
| | | throw new DingTalkApiException(500, $"HTTP request failed: {ex.Message}", ex); |
| | | } |
| | | catch (JsonException ex) |
| | | { |
| | | throw new DingTalkApiException(500, $"JSON parsing failed: {ex.Message}", ex); |
| | | } |
| | | } |
| | | |
| | | private bool IsValidMobile(string mobile) |
| | | { |
| | | // 简单的手机号格式验证 |
| | | return !string.IsNullOrEmpty(mobile) && mobile.Length == 11 && mobile.StartsWith("1"); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | public string GetProcessNo(GetQcIssueResultDetail getQcIssueResultDetail) |
| | | { |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | var mapping = db.Queryable<DingNameCode>() |
| | | .Where(t => t.DingDingName == getQcIssueResultDetail.Fname) |
| | | |
| | | var stafflist = db.Queryable<DingNameCode>() |
| | | .Where(t => t.STAFF_NO == getQcIssueResultDetail.StaffNo) |
| | | .Select(t => new DingNameCode |
| | | { |
| | | DingDingCode=t.DingDingCode, |
| | | STAFF_NAME = t.STAFF_NAME, |
| | | PHONE_NUMBER = t.PHONE_NUMBER |
| | | }) |
| | | .ToList(); |
| | | if (mapping.Any()) |
| | | { |
| | | string UserId = mapping.FirstOrDefault().DingDingCode; |
| | | |
| | | if (stafflist.Any()) |
| | | { |
| | | Task<string> task = GetUserId(stafflist[0].PHONE_NUMBER); |
| | | string UserId = task.Result; |
| | | string applicationUser = $"[\"{UserId}\"]"; |
| | | |
| | | // 使用 JSON 序列化输出对象的详细内容 |
| | | string getQcIssueResultDetailJson = JsonConvert.SerializeObject(getQcIssueResultDetail, Formatting.Indented); |
| | |
| | | startProcessInstanceHeaders.XAcsDingtalkAccessToken = accessToken; // 使用获取到的 Access Token |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues1 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextField-K2AD4O5B", |
| | | Value = getQcIssueResultDetail.ItemName, |
| | | Name = "TextField_K5AVR59BD28", |
| | | Value = getQcIssueResultDetail.ItemNo, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues2 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextField_DYFD1EESLVC0", |
| | | Value = getQcIssueResultDetail.ItemModel, |
| | | Name = "TextField_1LW382XRH1DS0", |
| | | Value = getQcIssueResultDetail.ItemName, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues3 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextField_1AVN2BNVY1OG0", |
| | | Name = "NumberField_UKE91Z101BK0", |
| | | Value = getQcIssueResultDetail.FbatchQty, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues4 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextField_1DKEMESOOGSG0", |
| | | Name = "TextField_1QM2NWE9T3Y80", |
| | | Value = getQcIssueResultDetail.SuppName, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues5 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "DDDateField_20LKOACGMLXC0", |
| | | Value = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Name = "TextField_1DAQ9890FDWG0", |
| | | Value = getQcIssueResultDetail.AppicationReason, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues6 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextField_WBNBWGFHR000", |
| | | Value = getQcIssueResultDetail.CgOrder, |
| | | Name = "DDSelectField_76Z6HC5W1F0", |
| | | Value = getQcIssueResultDetail.BadReason, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues7 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextareaField_1ZP3BDPMYY800", |
| | | Name = "TextField_3B85TFIK9Z60", |
| | | Value = getQcIssueResultDetail.remark, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues8 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "SignatureField_SKF9Q82DZUO0", |
| | | Value = getQcIssueResultDetail.Fname, |
| | | Name = "InnerContactField_WVZLUIPZ9J40", |
| | | Value = applicationUser, |
| | | |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues9 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "DDSelectField_1AK82Q8A2NB40", |
| | | Value = "退货", |
| | | Name = "DDSelectField_1AL6MWUUUOHS0", |
| | | Value = getQcIssueResultDetail.IqcStatus, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues10 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextareaField_1LM82CPPR35S0", |
| | | Value = "挑选内容", |
| | | Name = "DepartmentField_10ZVNJNJCRJK0", |
| | | Value = getQcIssueResultDetail.Department, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues11 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextareaField_AK4JLDDNS2O0", |
| | | Value = "让步接收内容", |
| | | Name = "DDSelectField_HG2SQUPO2NK0", |
| | | Value = getQcIssueResultDetail.WorkShop, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues12 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextareaField_K69R6770WLS0", |
| | | Value = "退货备注", |
| | | Name = "DDPhotoField_QD15KYR764G0", |
| | | Value = "测试不良图片", |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues13 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | Name = "TextareaField_194UFGLMI02O0", |
| | | Value = "报废备注", |
| | | Name = "DDAttachment_GLZLFSIWK9S0", |
| | | Value = "附件", |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues14 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | |
| | | { |
| | | ActionerKey = "null", |
| | | ActionerUserIds = new List<string> |
| | | { |
| | | UserId |
| | | }, |
| | | { |
| | | UserId |
| | | }, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers approvers0 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers |
| | | { |
| | | ActionType = "OR", |
| | | UserIds = new List<string> |
| | | { |
| | | UserId |
| | | }, |
| | | { |
| | | UserId |
| | | }, |
| | | }; |
| | | |
| | | |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest startProcessInstanceRequest = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest |
| | | { |
| | | OriginatorUserId = UserId, |
| | | ProcessCode = "PROC-BBA5632D-DC7C-4267-A3E2-757E2B7023BC", |
| | | ProcessCode = "PROC-4F4B3976-BA15-47EF-9A3C-3A07AC07DFEA", |
| | | DeptId = 1, |
| | | FormComponentValues = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues> |
| | | { |
| | | formComponentValues1,formComponentValues2,formComponentValues3, formComponentValues4, formComponentValues5, formComponentValues6, formComponentValues7, formComponentValues8, |
| | | formComponentValues9,formComponentValues10, formComponentValues11, formComponentValues12, formComponentValues13, formComponentValues14 |
| | | }, |
| | | { |
| | | formComponentValues1,formComponentValues2,formComponentValues3, formComponentValues4, formComponentValues5, formComponentValues6, formComponentValues7, formComponentValues8, |
| | | formComponentValues9, formComponentValues11 |
| | | }, |
| | | TargetSelectActioners = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners> |
| | | { |
| | | targetSelectActioners0 |
| | | }, |
| | | { |
| | | targetSelectActioners0 |
| | | }, |
| | | Approvers = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers> |
| | | { |
| | | approvers0 |
| | | }, |
| | | { |
| | | approvers0 |
| | | }, |
| | | CcList = new List<string> |
| | | { |
| | | UserId |
| | | }, |
| | | { |
| | | UserId |
| | | }, |
| | | CcPosition = "START", |
| | | |
| | | }; |
| | |
| | | return $"Exception: {_err.Message}"; |
| | | } |
| | | } |
| | | else { |
| | | return "您不是公司成员或还未被加入到数据库中或名字填写错误,总之未找到匹配的用户信息"; |
| | | else |
| | | { |
| | | return "查不到您的手机号"; |
| | | } |
| | | } |
| | | |
| | |
| | | /** |
| | | * 将带有流程号和检验单号的新记录插入表中 |
| | | */ |
| | | public dynamic SaveProcessNo(string ReleaseNo,string ProcessNo) |
| | | public dynamic SaveProcessNo(string ReleaseNo, string ProcessNo, string StaffNo, string Department) |
| | | { |
| | | |
| | | var QcIssueResults = GetQcIssueResults(ReleaseNo, ProcessNo); |
| | | |
| | | var ApplicantResults = GetApplicantResults(ProcessNo, StaffNo); |
| | | |
| | | var DepartmentResults = GetDepartmentResults(ProcessNo, Department); |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | db.Insertable(ApplicantResults).ExecuteCommand(); // 插入申请人数据 |
| | | db.Insertable(DepartmentResults).ExecuteCommand(); // 插入部门数据 |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | | return SaveOrUpdateData(db, QcIssueResults) ? 1 : 0; |
| | | }) > 0; |
| | | try |
| | | { |
| | | |
| | | |
| | | // 统一使用事务db |
| | | //SaveOrUpdateApplicantData(db, ApplicantResults); |
| | | //SaveOrUpdateDepartmentData(db, DepartmentResults); |
| | | SaveOrUpdateData(db, QcIssueResults); |
| | | |
| | | return 1; |
| | | } |
| | | catch |
| | | { |
| | | db.RollbackTran(); |
| | | throw; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public QcIssueResults GetQcIssueResults(string ReleaseNo, string ProcessNo) |
| | | { |
| | | var QcIssueResults = new QcIssueResults |
| | | { |
| | | ProcessNo = ProcessNo, |
| | | INSTANCEID = ProcessNo, |
| | | ReleaseNo = ReleaseNo, |
| | | QcStatu = "" |
| | | }; |
| | |
| | | return QcIssueResults; |
| | | } |
| | | |
| | | public IqcApplicant GetApplicantResults(string ProcessNo, string StaffNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | var stafflist = db.Queryable<DingNameCode>() |
| | | .Where(t => t.STAFF_NO == StaffNo) |
| | | .Select(t => new DingNameCode |
| | | { |
| | | STAFF_NAME = t.STAFF_NAME, |
| | | PHONE_NUMBER = t.PHONE_NUMBER |
| | | }) |
| | | .ToList(); |
| | | |
| | | var ApplicantResults = new IqcApplicant |
| | | { |
| | | INSTANCEID = ProcessNo, |
| | | APPLICANTID = StaffNo, |
| | | APPLICANTNAME = stafflist[0].STAFF_NAME |
| | | }; |
| | | |
| | | return ApplicantResults; |
| | | } |
| | | |
| | | public IqcDepartment GetDepartmentResults(string ProcessNo, string Department) |
| | | { |
| | | |
| | | var DepartmentResults = new IqcDepartment |
| | | { |
| | | INSTANCEID = ProcessNo, |
| | | DEPARTMENTNAME = Department |
| | | }; |
| | | |
| | | return DepartmentResults; |
| | | } |
| | | |
| | | /** |
| | | * 根据流程号更新表的记录 |
| | | */ |
| | | public dynamic Save(ErpQcIssueResult erpQcIssueResult) |
| | | { |
| | | var json = JsonConvert.SerializeObject(erpQcIssueResult); |
| | | //var json = JsonConvert.SerializeObject(erpQcIssueResult); |
| | | |
| | | //var saveSuccess = UseTransaction(db => |
| | | ////var saveSuccess = UseTransaction(db => |
| | | ////{ |
| | | //// var data = GetMesQcIssueResults(erpQcIssueResult); |
| | | //// return SaveOrUpdateData(db, data); |
| | | ////}); |
| | | |
| | | //return new |
| | | //{ |
| | | // var data = GetMesQcIssueResults(erpQcIssueResult); |
| | | // return SaveOrUpdateData(db, data); |
| | | //}); |
| | | // SerializedPayload = json, |
| | | // ServerTime = DateTime.UtcNow.ToString("O") |
| | | //}; |
| | | |
| | | return new |
| | | var mesQcIssueResults = GetMesQcIssueResults(erpQcIssueResult); |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | | SerializedPayload = json, |
| | | ServerTime = DateTime.UtcNow.ToString("O") |
| | | }; |
| | | return SaveOrUpdateData(db, mesQcIssueResults) ? 1 : 0; |
| | | }) > 0; |
| | | |
| | | } |
| | | |
| | | public QcIssueResults GetMesQcIssueResults(ErpQcIssueResult erpQcIssueResult) |
| | | { |
| | | var mesQcIssueResults = new QcIssueResults |
| | | { |
| | | ProcessNo = erpQcIssueResult.ProcessNo, |
| | | INSTANCEID = erpQcIssueResult.ProcessNo, |
| | | FReview = erpQcIssueResult.FReview, |
| | | QcStatu = erpQcIssueResult.QcStatus |
| | | APPLICATIONNUM = erpQcIssueResult.ApplicationQuantity.ToString(), |
| | | BADCAUSES = erpQcIssueResult.BadCauses, |
| | | BELONGINGWORKSHOP = erpQcIssueResult.AffiliatedWorkshop, |
| | | REVIEWSTATUS = erpQcIssueResult.FReview, |
| | | QcStatu = erpQcIssueResult.QcStatus, |
| | | ITEMNAME = erpQcIssueResult.ItemName, |
| | | ITEMNO = erpQcIssueResult.ItemNo, |
| | | SUPPLIERNAME = erpQcIssueResult.SupplierName, |
| | | REMARK = erpQcIssueResult.Remark, |
| | | APPLICATIONRESON=erpQcIssueResult.Reason |
| | | }; |
| | | |
| | | return mesQcIssueResults; |
| | |
| | | |
| | | // 查询 QcIssueResults 表中是否存在匹配的记录 |
| | | var mapping = db.Queryable<QcIssueResults>() |
| | | .Where(t => t.ProcessNo == qcIssueResults.ProcessNo) |
| | | .Where(t => t.INSTANCEID == qcIssueResults.INSTANCEID) |
| | | .Select(t => new QcIssueResults |
| | | { |
| | | ReleaseNo = t.ReleaseNo, |
| | |
| | | |
| | | if (mapping.Any()) |
| | | { |
| | | if (qcIssueResults.QcStatu=="拒绝") |
| | | if (qcIssueResults.QcStatu == "拒绝") |
| | | { |
| | | string ReleaseNo = mapping.FirstOrDefault().ReleaseNo; |
| | | |
| | |
| | | .SetColumns(t => new QcIssueResults |
| | | { |
| | | ReleaseNo = ReleaseNo, |
| | | FReview = qcIssueResults.FReview |
| | | INSTANCEID = qcIssueResults.INSTANCEID, |
| | | FReview = qcIssueResults.FReview, |
| | | APPLICATIONNUM = qcIssueResults.APPLICATIONNUM, |
| | | BADCAUSES = qcIssueResults.BADCAUSES, |
| | | BELONGINGWORKSHOP = qcIssueResults.BELONGINGWORKSHOP, |
| | | REVIEWSTATUS = qcIssueResults.REVIEWSTATUS, |
| | | QcStatu = qcIssueResults.QcStatu, |
| | | ITEMNAME = qcIssueResults.ITEMNAME, |
| | | ITEMNO = qcIssueResults.ITEMNO, |
| | | SUPPLIERNAME = qcIssueResults.SUPPLIERNAME, |
| | | REMARK = qcIssueResults.REMARK, |
| | | APPLICATIONRESON=qcIssueResults.APPLICATIONRESON |
| | | |
| | | }) |
| | | .Where(t => t.ProcessNo == qcIssueResults.ProcessNo) // 显式指定更新条件 |
| | | .Where(t => t.INSTANCEID == qcIssueResults.INSTANCEID) // 显式指定更新条件 |
| | | .ExecuteCommand(); |
| | | |
| | | // 查询 UpdateMesQaItems 表中是否存在匹配的记录 |
| | |
| | | |
| | | if (existingRecord != null) |
| | | { |
| | | string result = null; |
| | | bool returnValue = false; |
| | | try |
| | | { |
| | | string connectionString = "User Id=yc_dev;Password=ycdev;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.0.100)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)))"; |
| | | using (OracleConnection connection = new OracleConnection(connectionString)) |
| | | //定义输入参数 |
| | | var inputParam1 = new SugarParameter("pi_no", existingRecord.ReleaseNo); |
| | | var inputParam2 = new SugarParameter("pi_user", "PL017"); |
| | | // 定义输出参数 |
| | | var outParam1 = new SugarParameter("po_result", null, true); |
| | | var outParam2 = new SugarParameter("po_msg", null, true); |
| | | // 使用 SqlSugar 执行存储过程 |
| | | Db.Ado.ExecuteCommand("BEGIN PRC_MES_IQC_CG_REVOCK(:pi_no,:pi_user,:po_result,:po_msg ); END;", inputParam1, inputParam2, outParam1, outParam2); |
| | | // 获取输出参数的值 |
| | | int result = int.Parse((string)outParam1.Value); |
| | | string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value; |
| | | if (result == 1) |
| | | { |
| | | using (OracleCommand command = new OracleCommand("PRC_MES_IQC_CG_REVOCK", connection)) |
| | | { |
| | | command.CommandType = CommandType.StoredProcedure; |
| | | // 添加输入参数 |
| | | command.Parameters.Add("pi_no", OracleDbType.Varchar2).Value = existingRecord.ReleaseNo; // 替换为实际值 |
| | | command.Parameters.Add("pi_user", OracleDbType.Varchar2).Value = "PL017"; // 替换为实际值 |
| | | // 添加输出参数 |
| | | OracleParameter poResult = new OracleParameter("po_result", OracleDbType.Int32, ParameterDirection.Output); |
| | | OracleParameter poMsg = new OracleParameter("po_msg", OracleDbType.Varchar2, 4000, ParameterDirection.Output); |
| | | command.Parameters.Add(poResult); |
| | | command.Parameters.Add(poMsg); |
| | | // 打开连接并执行命令 |
| | | connection.Open(); |
| | | command.ExecuteNonQuery(); |
| | | // 处理返回值 |
| | | if (poResult.Value != null && poResult.Value.ToString() == "0") |
| | | { |
| | | returnValue = true; |
| | | } |
| | | else |
| | | { |
| | | // 输出错误信息 |
| | | string errorMsg = poMsg.Value != null ? poMsg.Value.ToString() : "Unknown error occurred"; |
| | | Console.WriteLine("Error: " + errorMsg); |
| | | } |
| | | } |
| | | //存储过程失败则事务进行回滚 |
| | | db.Ado.RollbackTran(); |
| | | throw new Exception(message); |
| | | } |
| | | return returnValue; |
| | | // 提交事务 |
| | | db.Ado.CommitTran(); |
| | | return true; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | throw new Exception("未找到需要更新的记录"); |
| | | } |
| | | } |
| | | else{ |
| | | else |
| | | { |
| | | string ReleaseNo = mapping.FirstOrDefault().ReleaseNo; |
| | | |
| | | // 只更新 ReleaseNo 和 FReview 两个字段 |
| | |
| | | .SetColumns(t => new QcIssueResults |
| | | { |
| | | ReleaseNo = ReleaseNo, |
| | | FReview = qcIssueResults.FReview |
| | | INSTANCEID = qcIssueResults.INSTANCEID, |
| | | FReview = qcIssueResults.FReview, |
| | | APPLICATIONNUM = qcIssueResults.APPLICATIONNUM, |
| | | BADCAUSES = qcIssueResults.BADCAUSES, |
| | | BELONGINGWORKSHOP = qcIssueResults.BELONGINGWORKSHOP, |
| | | REVIEWSTATUS = qcIssueResults.REVIEWSTATUS, |
| | | QcStatu = qcIssueResults.QcStatu, |
| | | ITEMNAME = qcIssueResults.ITEMNAME, |
| | | ITEMNO = qcIssueResults.ITEMNO, |
| | | SUPPLIERNAME = qcIssueResults.SUPPLIERNAME, |
| | | REMARK = qcIssueResults.REMARK, |
| | | APPLICATIONRESON = qcIssueResults.APPLICATIONRESON |
| | | |
| | | |
| | | }) |
| | | .Where(t => t.ProcessNo == qcIssueResults.ProcessNo) // 显式指定更新条件 |
| | | .Where(t => t.INSTANCEID == qcIssueResults.INSTANCEID) // 显式指定更新条件 |
| | | .ExecuteCommand(); |
| | | |
| | | // 查询 UpdateMesQaItems 表中是否存在匹配的记录 |
| | |
| | | if (existingRecord != null) |
| | | { |
| | | // 更新 UpdateMesQaItems 表中的字段 |
| | | existingRecord.FngHandle = qcIssueResults.FReview; |
| | | existingRecord.FngHandle = qcIssueResults.REVIEWSTATUS; |
| | | if (existingRecord.FngHandle == "退货") |
| | | { |
| | | existingRecord.FMRMODE = "退料补料"; |
| | |
| | | |
| | | // 执行更新操作 |
| | | updateResult = db.Updateable(existingRecord).ExecuteCommand(); |
| | | |
| | | if (updateResult > 0) |
| | | { |
| | | try |
| | | { |
| | | |
| | | //定义输入参数 |
| | | var inputParam1 = new SugarParameter("PI_BILLNO", ReleaseNo); |
| | | var inputParam2 = new SugarParameter("PI_USER", "PL017"); |
| | | var inputParam3 = new SugarParameter("PI_HANDLE", existingRecord.FngHandle); |
| | | var inputParam4 = new SugarParameter("PI_TLFS", existingRecord.FMRMODE); |
| | | var inputParam5 = new SugarParameter("PI_REMARK", ""); |
| | | |
| | | // 定义输出参数 |
| | | var outParam1 = new SugarParameter("PO_RESULT", null, true); |
| | | var outParam2 = new SugarParameter("PO_MSG", null, true); |
| | | // 使用 SqlSugar 执行存储过程 |
| | | Db.Ado.ExecuteCommand("BEGIN PRC_MES_IQC_CG_SUBMIT(:PI_BILLNO,:PI_BILLNO,:PI_HANDLE,:PI_TLFS,:PI_REMARK,:PO_RESULT,:PO_MSG); END;", inputParam1, inputParam2, inputParam3, inputParam4, inputParam5, outParam1, outParam2); |
| | | // 获取输出参数的值 |
| | | int result = int.Parse((string)outParam1.Value); |
| | | string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value; |
| | | if (result == 1) |
| | | { |
| | | //存储过程失败则事务进行回滚 |
| | | db.Ado.RollbackTran(); |
| | | throw new Exception(message); |
| | | } |
| | | // 提交事务 |
| | | db.Ado.CommitTran(); |
| | | return true; |
| | | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine("Exception: " + ex.Message); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return updateResult > 0; // 如果更新成功,返回 true |
| | | } |
| | |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | |
| | | // 响应模型 |
| | | public class DingTalkResponse |
| | | { |
| | | [JsonProperty("errcode")] |
| | | public int Errcode { get; set; } |
| | | |
| | | [JsonProperty("errmsg")] |
| | | public string Errmsg { get; set; } |
| | | |
| | | [JsonProperty("result")] |
| | | public UserResult Result { get; set; } |
| | | } |
| | | |
| | | public class UserResult |
| | | { |
| | | [JsonProperty("userid")] |
| | | public string UserId { get; set; } |
| | | } |
| | | |
| | | // 自定义异常 |
| | | public class DingTalkApiException : Exception |
| | | { |
| | | public int ErrorCode { get; } |
| | | |
| | | public DingTalkApiException(int errorCode, string message) : base(message) |
| | | { |
| | | ErrorCode = errorCode; |
| | | } |
| | | |
| | | public DingTalkApiException(int errorCode, string message, Exception innerException) |
| | | : base(message, innerException) |
| | | { |
| | | ErrorCode = errorCode; |
| | | } |
| | | } |