From 8a829f00d0582a32c7bef960cab5c6fd855c5ea5 Mon Sep 17 00:00:00 2001
From: wtt <1985833171@qq.com>
Date: 星期四, 31 十月 2024 11:05:23 +0800
Subject: [PATCH] Merge branch 'master' of http://101.37.171.70:10101/r/MES-WEB-API

---
 WebAPI/Controllers/Sb_CheckEqpRepairWorkBillController.cs |  222 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 214 insertions(+), 8 deletions(-)

diff --git a/WebAPI/Controllers/Sb_CheckEqpRepairWorkBillController.cs b/WebAPI/Controllers/Sb_CheckEqpRepairWorkBillController.cs
index befbdcc..9a4780c 100644
--- a/WebAPI/Controllers/Sb_CheckEqpRepairWorkBillController.cs
+++ b/WebAPI/Controllers/Sb_CheckEqpRepairWorkBillController.cs
@@ -1,4 +1,5 @@
-锘縰sing Newtonsoft.Json;
+锘縰sing 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 鏁呴殰鐧昏鍗旾D 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,190 @@
             }
         }
         #endregion
+    
+        #region 璁惧绛惧埌鍗曟彁浜DA
+
+        [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 + "',鎹熷潖,璇峰尯鍩熻礋璐d汉:'" + HManagerName + "',灏藉揩鍒扮幇鍦虹淮淇�!!";
+            }
+            else if (num==2)
+            {
+                HDescription = "缁翠慨浜�:'" + HEmpName + "',鍦�'" + HDeptName + "',宸茬淮淇�'" + HEquipName + "',璇峰彂鐜颁汉:'" + HManagerName + "',灏藉揩鍒扮幇鍦虹‘璁ゆ槸鍚︾淮淇畬鎴�!!";
+            }
+            else if (num==3)
+            {
+                HDescription = "楠屾敹浜�:'" + HEmpName + "',鍦�'" + HDeptName + "',宸查獙鏀�'" + HEquipName + "',宸查�氱煡:'" + HManagerName + "',缁翠慨璁惧绗﹀悎楠屾敹!!";
+            }
+             
+
+            //鎺ユ敹浜洪拤閽塱d
+            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();
+
+            //鑾峰彇浼佷笟鐨刟ccess_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;//閽夐拤浜哄憳鐨刬d
+            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
     }
 }

--
Gitblit v1.9.1