1
duhe
2024-08-15 57d8bd99cf8114a0bacd8a94cd0e08fb2f233b6a
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();
@@ -472,7 +477,9 @@
                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
                {
@@ -812,7 +819,12 @@
                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
                {
@@ -1100,9 +1112,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
                {
@@ -1313,8 +1326,8 @@
                    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)
                {
@@ -1322,6 +1335,14 @@
                    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";
@@ -2935,5 +2956,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
    }
}