|  |  |  | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using DLL; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using Newtonsoft.Json.Linq; | 
|---|
|  |  |  | using Pub_Class; | 
|---|
|  |  |  | using System; | 
|---|
|  |  |  | 
|---|
|  |  |  | using System.Linq; | 
|---|
|  |  |  | using System.Net; | 
|---|
|  |  |  | using System.Net.Http; | 
|---|
|  |  |  | using System.Threading.Tasks; | 
|---|
|  |  |  | using System.Web.Http; | 
|---|
|  |  |  | using WebAPI.Models; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private json objJsonResult = new json(); | 
|---|
|  |  |  | public DataSet ds = new DataSet(); | 
|---|
|  |  |  | public WebServer webserver = new WebServer(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取系统参数 | 
|---|
|  |  |  | Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public DBUtility.ClsPub.Enum_BillStatus BillStatus;//单据状态(新增,修改,浏览,更新单价,变更) | 
|---|
|  |  |  | SQLHelper.ClsCN oCN = new SQLHelper.ClsCN(); | 
|---|
|  |  |  | 
|---|
|  |  |  | if (oBill.omodel.HInterID == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | //部门,发现人,负责人,设备 | 
|---|
|  |  |  | _ = SendDingDingAsync(oBill.omodel.HDeptID, oBill.omodel.HEmpID, oBill.omodel.HManagerID, oBill.omodel.HEquipID,2); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | if (oBill.omodel.HInterID == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | //反写维修记录单关闭 | 
|---|
|  |  |  | string sql = "Update Sb_EquipRepairWorkBillMain set HCloseMan='关联验收单自动关闭',HCloseDate=GETDATE(),HBillStatus=3,HCloseType = 1 Where HInterID=" + oBill.omodel.HMainSourceInterID.ToString(); | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql, "Sb_EquipRepairWorkBillMain"); | 
|---|
|  |  |  | //部门,发现人,负责人,设备 | 
|---|
|  |  |  | _ = SendDingDingAsync(oBill.omodel.HDeptID, oBill.omodel.HEmpID, oBill.omodel.HManagerID, oBill.omodel.HEquipID, 3); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | //保存完毕后处理 | 
|---|
|  |  |  | bool bResult; | 
|---|
|  |  |  | if (oBill.omodel.HInterID == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | // bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | { | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | //部门,发现人,负责人,设备 | 
|---|
|  |  |  | _ = SendDingDingAsync(oBill.omodel.HDeptID, oBill.omodel.HEmpID, oBill.omodel.HManagerID, oBill.omodel.HEquipID,1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //得到信息 | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select top 1 * from h_v_Gy_EquipFileBillList where HBarCode= '" + HBarCode + "'", "Gy_EquipFileBillMain"); | 
|---|
|  |  |  | //得到信息最新的 | 
|---|
|  |  |  | ds = oCN.RunProcReturn("select  * from h_v_Gy_EquipFileBillList where HBarCode= '" + HBarCode + "'  order by 故障登记单ID desc", "Gy_EquipFileBillMain"); | 
|---|
|  |  |  | //写入信息 | 
|---|
|  |  |  | if (ds == null || ds.Tables[0].Rows.Count == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "1.未查询到设备信息! 2.设备没有维护故障登记单  3.设备故障登记单没有审核"; | 
|---|
|  |  |  | objJsonResult.data = null; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if ( ds.Tables[0].Rows.Count > 1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "该设备出现多个故障登记单,请手动选着"; | 
|---|
|  |  |  | objJsonResult.data = ds.Tables[0]; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | objJsonResult.code = "1"; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 设备签到单提交PDA | 
|---|
|  |  |  |  | 
|---|
|  |  |  | [Route("Sb_CheckEqpRepairWorkBill/SaveSb_EquipRepairSignBill_PDA")] | 
|---|
|  |  |  | [HttpPost] | 
|---|
|  |  |  | public object SaveSb_EquipRepairSignBill_PDA([FromBody] JObject msg) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | var _value = msg["msg"].ToString(); | 
|---|
|  |  |  | string msg1 = _value.ToString(); | 
|---|
|  |  |  | string[] sArray = msg1.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries); | 
|---|
|  |  |  | string msg2 = sArray[0].ToString(); | 
|---|
|  |  |  | string msg3 = sArray[1].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string UserName = ""; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ListModels oListModels = new ListModels(); | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DLL.ClsSb_EquipRepairSignBill oBill = new DLL.ClsSb_EquipRepairSignBill(); | 
|---|
|  |  |  | List<Models.ClsSb_EquipRepairSignBillMain> lsmain = new List<Models.ClsSb_EquipRepairSignBillMain>(); | 
|---|
|  |  |  | msg2 = msg2.Replace("\\", ""); | 
|---|
|  |  |  | msg2 = msg2.Replace("\n", ""); | 
|---|
|  |  |  | lsmain = oListModels.getObjectByJson_Sb_EquipRepairSignBill_PDA(msg2); | 
|---|
|  |  |  | foreach (Models.ClsSb_EquipRepairSignBillMain oItem in lsmain) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //单据号是否重复 | 
|---|
|  |  |  | if (BillNew.IsExistBillNo(ref ClsPub.sExeReturnInfo, oItem.HBillNo, BillStatus, BillOld.omodel.HInterID)) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "单据号重复!不允许保存!"; | 
|---|
|  |  |  | objJsonResult.data = 1; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | UserName = oItem.HMaker;  //制单人 | 
|---|
|  |  |  | oItem.HBillType = "3920"; | 
|---|
|  |  |  | oItem.HBillSubType = "3920"; | 
|---|
|  |  |  | oItem.HYear = DBUtility.ClsPub.isLong(DateTime.Now.Year); | 
|---|
|  |  |  | oItem.HMakeDate = DBUtility.ClsPub.isStrNull(DateTime.Now.ToString("yyyy-MM-dd")); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (DBUtility.ClsPub.isStrNull(oItem.HDate) == "") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "保存失败!没有单据日期,无法保存!"; | 
|---|
|  |  |  | objJsonResult.data = 1; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | oBill.omodel = oItem; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //保存 | 
|---|
|  |  |  | //保存完毕后处理 | 
|---|
|  |  |  | bool bResult; | 
|---|
|  |  |  | if (oBill.omodel.HInterID == 0) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | bResult = oBill.AddBill(ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | bResult = oBill.ModifyBill(oBill.omodel.HInterID, ref DBUtility.ClsPub.sExeReturnInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (bResult) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 1; | 
|---|
|  |  |  | objJsonResult.Message = "保存成功!"; | 
|---|
|  |  |  | //WebAPIController.Add_Log("送货单下推", UserName, "生成送货单"); | 
|---|
|  |  |  | objJsonResult.data = 1; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "保存失败!" + DBUtility.ClsPub.sExeReturnInfo; | 
|---|
|  |  |  | objJsonResult.data = 1; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception e) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | objJsonResult.code = "0"; | 
|---|
|  |  |  | objJsonResult.count = 0; | 
|---|
|  |  |  | objJsonResult.Message = "保存失败!" + e.ToString(); | 
|---|
|  |  |  | objJsonResult.data = 1; | 
|---|
|  |  |  | return objJsonResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  |  | 
|---|
|  |  |  | #region 设备故障 登记/记录/验收  发送消息 | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | /// 异常反馈 接收,处理,验收单保存发送消息 | 
|---|
|  |  |  | /// </summary> | 
|---|
|  |  |  | /// <param name="HSendMan"></param> | 
|---|
|  |  |  | /// <param name="HHandleEmpID"></param> | 
|---|
|  |  |  | /// <param name="HDescription"></param> | 
|---|
|  |  |  | /// <param name="HCopyMan"></param> | 
|---|
|  |  |  | /// <returns></returns> | 
|---|
|  |  |  | public async Task<object> SendDingDingAsync(long HDeptID, long HEmpID, long HManagerID, long HEquipID,int num) | 
|---|
|  |  |  | { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | string concatenatedNames = ""; | 
|---|
|  |  |  | string HDescription = ""; | 
|---|
|  |  |  | string appKey = ""; | 
|---|
|  |  |  | string appSecret = ""; | 
|---|
|  |  |  | string sReturn = ""; | 
|---|
|  |  |  | string agentIds = ""; | 
|---|
|  |  |  | Cls_DDMsg msg = new Cls_DDMsg(); | 
|---|
|  |  |  | if (oSystemParameter.ShowBill(ref sReturn) == true) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //系统参数是否 N为本地,Y为斯莫尔 | 
|---|
|  |  |  | if (oSystemParameter.omodel.OA_ErrMsgBackBill_SendDingDingMsg == "N") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | appKey = "dingrsrzhdyn3mlaof95"; | 
|---|
|  |  |  | appSecret = "RAqH6YtZnPLCpDbuqfaYQkKkVtVdS0wqfC8I26X6qiS-8eoCJCNrzx3fubGND4Sq"; | 
|---|
|  |  |  | agentIds = "3118119317"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (oSystemParameter.omodel.OA_ErrMsgBackBill_SendDingDingMsg == "Y") | 
|---|
|  |  |  | { | 
|---|
|  |  |  | appKey = "dingkdddbhdcssk7jduw"; | 
|---|
|  |  |  | appSecret = "iv07c-GLfJPnzfJaNAAOfJDl3Z-eODvDAhlInMZCZhGorkle5Evbaxx3ImylvdjQ"; | 
|---|
|  |  |  | agentIds = "3151454458"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //部门 | 
|---|
|  |  |  | string sql = "select HName from Gy_Department where HItemID='" + HDeptID + "'"; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql, "Gy_Department"); | 
|---|
|  |  |  | string HDeptName = ds.Tables[0].Rows[0]["HName"].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //发现人 | 
|---|
|  |  |  | string sql1 = "select HName from Gy_Employee where HItemID='" + HEmpID + "'"; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql1, "Gy_Employee"); | 
|---|
|  |  |  | string HEmpName = ds.Tables[0].Rows[0]["HName"].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //负责人 | 
|---|
|  |  |  | string sql2 = "select HName from Gy_Employee where HItemID='" + HManagerID + "'"; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql2, "Gy_Employee"); | 
|---|
|  |  |  | string HManagerName = ds.Tables[0].Rows[0]["HName"].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //设备 | 
|---|
|  |  |  | string sql3 = "select HName from Gy_EquipFileBillMain where HInterID='" + HEquipID + "'"; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql3, "Gy_EquipFileBillMain"); | 
|---|
|  |  |  | string HEquipName = ds.Tables[0].Rows[0]["HName"].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //发送内容 | 
|---|
|  |  |  | if (num==1) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | HDescription = "发现人:'" + HEmpName + "',在'" + HDeptName + "',发现'" + HEquipName + "',损坏,请区域负责人:'" + HManagerName + "',尽快到现场维修!!"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (num==2) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | HDescription = "维修人:'" + HEmpName + "',在'" + HDeptName + "',已维修'" + HEquipName + "',请发现人:'" + HManagerName + "',尽快到现场确认是否维修完成!!"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else if (num==3) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | HDescription = "验收人:'" + HEmpName + "',在'" + HDeptName + "',已验收'" + HEquipName + "',已通知:'" + HManagerName + "',维修设备符合验收!!"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //接收人钉钉id | 
|---|
|  |  |  | string sql4 = "select HDingDingUserID 钉钉id from Gy_Czygl where Czymc in ('" + HManagerName + "')"; | 
|---|
|  |  |  | ds = oCN.RunProcReturn(sql4, "Gy_Czygl"); | 
|---|
|  |  |  | concatenatedNames = ds.Tables[0].Rows[0]["钉钉id"].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //获取企业的access_token的值 | 
|---|
|  |  |  | string response = msg.GetAccessToken(appKey, appSecret); | 
|---|
|  |  |  | JObject responseJson = JObject.Parse(response); | 
|---|
|  |  |  | // 获取access_token的值 | 
|---|
|  |  |  | string accessToken = responseJson["accessToken"].ToString(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //调用方法发送消息 | 
|---|
|  |  |  | string agentId = agentIds;//钉钉后台建立的小程序id | 
|---|
|  |  |  | string userIdList = concatenatedNames;//钉钉人员的id | 
|---|
|  |  |  | string deptIdList = "0"; // 空字符串表示不指定部门 | 
|---|
|  |  |  | string toAllUser = "false"; | 
|---|
|  |  |  | string message = HDescription; | 
|---|
|  |  |  | response = await msg.SendTextMessage(accessToken, agentId, userIdList, deptIdList, toAllUser, message); | 
|---|
|  |  |  | Console.WriteLine(response); | 
|---|
|  |  |  | return response; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | #endregion | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|