1
wtt
2024-08-13 5541b112172f20daad8ea6725082c2db7d15d7be
WebAPI/Controllers/Sb_CheckEqpRepairWorkBillController.cs
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using DLL;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Pub_Class;
using System;
@@ -7,6 +8,7 @@
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
using WebAPI.Models;
@@ -17,6 +19,9 @@
        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();
@@ -473,6 +478,8 @@
                {
                    // 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
                {
@@ -813,6 +820,8 @@
                {
                    // 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, 3);
                }
                else
                {
@@ -1100,9 +1109,10 @@
                //保存完毕后处理
                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
                {
@@ -2935,5 +2945,101 @@
            }
        }
        #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
    }
}