| | |
| | | using DbType = System.Data.DbType; |
| | | using System.Data; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
| | | using AlibabaCloud.TeaUtil.Models; |
| | | using MES.Service.Modes.QcIssueResult; |
| | | using Newtonsoft.Json; |
| | | using System.Diagnostics; |
| | | using Tea; |
| | | using MES.Service.Modes.DingAPI; |
| | | using static System.Runtime.InteropServices.JavaScript.JSType; |
| | | |
| | | namespace MES.Service.service.QC; |
| | | |
| | |
| | | result = "未检测", |
| | | isCheck = 0 |
| | | }).ToList(); |
| | | } |
| | | |
| | | public List<SJBadReason>? GetReason(string billNo) |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | var count = db.Queryable<SJBadReason>().Where(s => s.BillNo == billNo).Count(); |
| | | |
| | | if (count <= 0) return null; |
| | | |
| | | var reason = db |
| | | .Queryable<SJBadReason>() |
| | | .Where(s => s.BillNo == billNo).Select( |
| | | b => new SJBadReason |
| | | { |
| | | Reason =b.Reason |
| | | }).ToList(); |
| | | |
| | | return reason; |
| | | } |
| | | |
| | | public List<QsItemIpiItem> getQSItems(decimal? pid, decimal? id) |
| | |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取钉钉部门 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<DingDept> getDingDept() |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | return db.Queryable<DingDept>() |
| | | .Where(b => b.NoChild== 1) |
| | | .Select(b => new DingDept |
| | | { |
| | | Id=b.Id, |
| | | Name=b.Name |
| | | }) |
| | | .ToList(); |
| | | } |
| | | |
| | | public List<DeptNode> BuildDeptTree() |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | var flatList = db.Queryable<DingDept>() |
| | | .ToList(); |
| | | var lookup = flatList.ToDictionary( |
| | | d => d.Id, |
| | | d => new DeptNode |
| | | { |
| | | Id = d.Id, |
| | | Label = d.Name, |
| | | Value = d.Id |
| | | }); |
| | | |
| | | List<DeptNode> roots = new(); |
| | | |
| | | foreach (var dept in flatList) |
| | | { |
| | | if ((dept.Pid > 0 && lookup.ContainsKey(dept.Pid))) |
| | | { |
| | | lookup[dept.Pid].Children.Add(lookup[dept.Id]); |
| | | } |
| | | else |
| | | { |
| | | // parentId 为 null 的就是根节点 |
| | | roots.Add(lookup[dept.Id]); |
| | | } |
| | | } |
| | | |
| | | return roots; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取钉钉员工 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public List<DingStaff> getDingUser() |
| | | { |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | return db.Queryable<DingStaff>() |
| | | .Select(b => new DingStaff |
| | | { |
| | | StaffName=b.StaffName, |
| | | Id=b .Id |
| | | }) |
| | | .ToList(); |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 异常处置单推送钉钉 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public static AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client CreateClient() |
| | | { |
| | | AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); |
| | | config.Protocol = "https"; |
| | | config.RegionId = "central"; |
| | | return new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client(config); |
| | | } |
| | | |
| | | public static AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client CreateClient1() |
| | | { |
| | | AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config(); |
| | | config.Protocol = "https"; |
| | | config.RegionId = "central"; |
| | | return new AlibabaCloud.SDK.Dingtalkoauth2_1_0.Client(config); |
| | | } |
| | | |
| | | |
| | | public string GetToken() |
| | | { |
| | | 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", |
| | | }; |
| | | |
| | | try |
| | | { |
| | | var response = client.GetAccessToken(getAccessTokenRequest); |
| | | return response.Body.AccessToken; // 返回获取到的 Access Token |
| | | } |
| | | catch (TeaException err) |
| | | { |
| | | Console.WriteLine($"TeaException: Code={err.Code}, Message={err.Message}"); |
| | | return null; |
| | | } |
| | | catch (Exception _err) |
| | | { |
| | | Console.WriteLine($"Exception: {_err.Message}"); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | public string DingJZCSD(JzcsdData InData) |
| | | { |
| | | |
| | | var db = SqlSugarHelper.GetInstance(); |
| | | |
| | | decimal numUserId = db.Queryable<DingStaff>() |
| | | .Where(t => t.StaffName == InData.Fname) |
| | | .Select(t => t.Id) |
| | | .First(); |
| | | if (numUserId > 0) |
| | | { |
| | | string UserId = Convert.ToString(numUserId); |
| | | |
| | | |
| | | // 使用 JSON 序列化输出对象的详细内容 |
| | | string InDataJson = JsonConvert.SerializeObject(InData, Formatting.Indented); |
| | | Debug.WriteLine("InDataDetail: " + InDataJson); |
| | | |
| | | // 获取 Access Token |
| | | string accessToken = GetToken(); |
| | | if (string.IsNullOrEmpty(accessToken)) |
| | | { |
| | | return "获取 Access Token 失败"; |
| | | } |
| | | |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Client client = CreateClient(); |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceHeaders startProcessInstanceHeaders = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceHeaders(); |
| | | Debug.WriteLine(accessToken); |
| | | startProcessInstanceHeaders.XAcsDingtalkAccessToken = accessToken; // 使用获取到的 Access Token |
| | | /* |
| | | 产品型号 TextField-K2AD4O5B |
| | | 纠正事项来源 DDMultiSelectField_19MZJHE2ZWM80 |
| | | 提出人员 InnerContactField_WY9BZDYT7W00 |
| | | 提出日期 DDDateField_JD4ISXXCNLS0 |
| | | 接收部门 DepartmentField_SLLT1GL6RC00 |
| | | 负责人 InnerContactField_1I3FYOICN4N40 |
| | | 回复日期 DDDateField_1NPTPIPNEI1S0 |
| | | 问题描述 TextareaField_1FUN513WLK4G0 |
| | | 审批选择 DDSelectField_WE67NWABXM80 |
| | | */ |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues0 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //产品型号 |
| | | Name = "TextField-K2AD4O5B", |
| | | Value = InData.Imodel |
| | | }; |
| | | |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues1 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //纠正事项来源 |
| | | Name = "DDMultiSelectField_19MZJHE2ZWM80", |
| | | Value = InData.Source |
| | | /* Value = JsonConvert.SerializeObject(new[] { |
| | | new { value = InData.Source, label = "内部审核" } |
| | | })*/ |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues2 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //提出人员 |
| | | Name = "InnerContactField_WY9BZDYT7W00", |
| | | Value = UserId, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues3 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //提出日期 |
| | | Name = "DDDateField_JD4ISXXCNLS0", |
| | | Value = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues4 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //接收部门 |
| | | Name = "DepartmentField_SLLT1GL6RC00", |
| | | Value = InData.selectedDeptID, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues5 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //负责人 |
| | | Name = "InnerContactField_1I3FYOICN4N40", |
| | | Value = InData.selectedUserID |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues6 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //回复日期 |
| | | Name = "DDDateField_1NPTPIPNEI1S0", |
| | | Value = InData.ReplyDate, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues7 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //问题描述 |
| | | Name = "TextareaField_1FUN513WLK4G0", |
| | | Value = InData.Reason, |
| | | }; |
| | | AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues8 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | { |
| | | //审批选择 |
| | | Name = "DDSelectField_WE67NWABXM80", |
| | | Value = InData.selectedADeptID, |
| | | }; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues8 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //DDSelectField_WE67NWABXM80 |
| | | // Name = "InnerContactField_1I3FYOICN4N40", |
| | | // Value = InData.se, |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues9 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //回复日期 |
| | | // Name = "DDDateField_1NPTPIPNEI1S0", |
| | | // Value = Convert.ToString(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()), |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues10 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //提出部门 |
| | | // Name = "DepartmentField_184EOWTFMJUK0", |
| | | // Value = "挑选内容", |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues11 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //纠正措施 |
| | | // Name = "TextareaField_1PZP4OZ8GSKG0", |
| | | // Value = InData.Action, |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues12 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //纠正措施负责人 |
| | | // Name = "InnerContactField_9PR03WUFX7O0", |
| | | // Value = ActionUserId, |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues13 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //实例ID |
| | | // Name = "api_instanceId", |
| | | // Value = accessToken, |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues14 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //计划完成时间 |
| | | // Name = "DDDateField_1G5HG8KPCY2O0", |
| | | // Value = "否", |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues15 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //提出日期 |
| | | // Name = "DDDateField_JD4ISXXCNLS0", |
| | | // Value = Convert.ToString(DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()), |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues16 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //原因分析 |
| | | // Name = "TextareaField_N3W50F154DS0", |
| | | // Value = InData., |
| | | //}; |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues formComponentValues17 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestFormComponentValues |
| | | //{ |
| | | // //产品型号 |
| | | // Name = "TextField-K2AD4O5B", |
| | | // Value = "附件", |
| | | //}; |
| | | |
| | | //AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners targetSelectActioners0 = new AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners |
| | | //{ |
| | | // // |
| | | // ActionerKey = "null", |
| | | // ActionerUserIds = new List<string> |
| | | //{ |
| | | // 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 |
| | | //}, |
| | | //}; |
| | | |
| | | |
| | | 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", |
| | | 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 |
| | | }, |
| | | // TargetSelectActioners = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestTargetSelectActioners> |
| | | //{ |
| | | // targetSelectActioners0 |
| | | //}, |
| | | // Approvers = new List<AlibabaCloud.SDK.Dingtalkworkflow_1_0.Models.StartProcessInstanceRequest.StartProcessInstanceRequestApprovers> |
| | | //{ |
| | | // approvers0 |
| | | //}, |
| | | CcList = new List<string> |
| | | { |
| | | UserId |
| | | }, |
| | | CcPosition = "START", |
| | | |
| | | }; |
| | | // 序列化 FormComponentValues 列表为 JSON 格式 |
| | | string formComponentValuesJson = JsonConvert.SerializeObject(startProcessInstanceRequest.FormComponentValues, Formatting.Indented); |
| | | Debug.WriteLine("FormComponentValues: " + formComponentValuesJson); |
| | | try |
| | | { |
| | | string requestContent = Newtonsoft.Json.JsonConvert.SerializeObject(startProcessInstanceRequest); |
| | | Debug.WriteLine("startProcessInstanceRequest内容:"); |
| | | Debug.WriteLine(requestContent); |
| | | var response = client.StartProcessInstanceWithOptions(startProcessInstanceRequest, startProcessInstanceHeaders, new RuntimeOptions()); |
| | | return $"钉钉工作流实例启动成功: {Newtonsoft.Json.JsonConvert.SerializeObject(response.Body)}"; |
| | | } |
| | | catch (TeaException err) |
| | | { |
| | | string requestContent = Newtonsoft.Json.JsonConvert.SerializeObject(startProcessInstanceRequest); |
| | | Debug.WriteLine("startProcessInstanceRequest内容:"); |
| | | Debug.WriteLine(startProcessInstanceRequest); |
| | | return $"TeaException: Code={err.Code}, Message={err.Message}"; |
| | | } |
| | | catch (Exception _err) |
| | | { |
| | | return $"Exception: {_err.Message}"; |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return "您不是公司成员或还未被加入到数据库中或名字填写错误,未找到匹配的用户信息"; |
| | | } |
| | | } |
| | | |
| | | } |