1
wtt
2024-09-29 19d0afadbe1c90e227b852db0a97ae413e90691f
WebAPI/Controllers/Êý¾Ýͬ²½/¶¤¶¤Í¬²½/DD_DataSynchronizationController.cs
@@ -16,6 +16,7 @@
using DingTalk.Api;
using DingTalk.Api.Response;
using System.Globalization;
using System.Linq;
namespace WebAPI.Controllers
{
@@ -268,15 +269,23 @@
            public string HExplanation;//   varchar(500)    --维修要求        
            public string HInnerBillNo;//   varchar(50)   --内部单据号
            public Int64 HMouldID;
            public Int64 HMouldMaintainRuleInterID;
            public Int64 HMaintainItemID;
            public Int64 HSupID;//      int   --供应商(Gy_Supplier)               addnew
            public string HRepairType;//   varchar(10)      --维修类型(内部维修,委外维修)      addnew
            public string HNewModel;//   varchar(100)      --维修后新规格            addnew
            public Single HNewDesignLife;//   money         --新设计寿命
            public string HRemark;
            public DateTime HRequestComDate;
            public double HRecentMainModule;
            public double HCumulativeModule;
            public double HProductionModule;
            public DateTime HRepairAccepDate;
            //单据内容
            public string HBillNo;                                //单据号
            public string HDate;                                //日期
            public string HCheckLevel;                          //审核等级
            public string HArea;                                //区域
@@ -332,6 +341,10 @@
            public Single HPlanTimes;// money         --计划维修工时
            public Single HTimes;// money       --实际维修工时
            public string HRemark2;//备注
            public string HRepairCategory;
            public string HUrgenLevel;
            public string HRepairer;
            public string HIsCapacityImpact;
            //单据内容
            public string HDate;                                //日期
@@ -510,7 +523,7 @@
                //OriginatorId = "12",                                                                                          //根据流程发起人工号查询。
                //TaskId = "12",                                                                                                //任务ID。
                //CreateFromTimeGMT = DateTime.Now.ToString("dd") == "01" ? "2022-01-01" : DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                //CreateFromTimeGMT = DateTime.Now.AddMonths(-10).ToString("yyyy-MM-dd"),                                          //创建时间起始值。
                //CreateToTimeGMT = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),                                               //创建时间终止值。
                ModifiedFromTimeGMT = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"),                                          //修改时间起始值。
                ModifiedToTimeGMT = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"),                                               //修改时间终止值。
@@ -2061,6 +2074,13 @@
                                continue;
                            }
                            //开单日期
                            if (keys.Contains("dateField_lq0v65sv"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq0v65sv"].ToString());
                                oItem.HDate = convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm");
                            }
                            //修模开始时间
                            if (keys.Contains("dateField_lq4gf2ih"))
                            {
@@ -2075,17 +2095,52 @@
                                oItem.HRepairEndDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm"));
                            }
                            //模具批次号
                            //模具单据号
                            if (keys.Contains("serialNumberField_lqaak4ts"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["serialNumberField_lqaak4ts"].ToString();
                                oItem.HRemark = HDate_Temp;
                                oItem.HBillNo = HDate_Temp;
                            }
                            //模具编码
                            if (keys.Contains("dateField_lq4gf2ii"))
                            //要求完成日期
                            if (keys.Contains("dateField_lq3idkvd"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["dateField_lq4gf2ii"].ToString();
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq3idkvd"].ToString());
                                oItem.HRequestComDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm:ss"));
                            }
                            //维修受理日期
                            if (keys.Contains("dateField_lq4gf2ih"))
                            {
                                double HDate_Temp = double.Parse(response.Body.Result[i].FormData["dateField_lq4gf2ih"].ToString());
                                oItem.HRepairAccepDate = DateTime.Parse(convertFromMillisecondsToDateString(HDate_Temp, "yyyy-MM-dd HH:mm:ss"));
                            }
                            //最近保养模数
                            if (keys.Contains("numberField_lq3idkvi"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3idkvi"].ToString();
                                oItem.HRecentMainModule = double.Parse(HDate_Temp);
                            }
                            //累计模数
                            if (keys.Contains("numberField_lq3idkvj"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["numberField_lq3idkvj"].ToString();
                                oItem.HCumulativeModule = double.Parse(HDate_Temp);
                            }
                            //本次生产模数
                            if (keys.Contains("textField_lq4vdvgh"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_lq4vdvgh"].ToString();
                                oItem.HProductionModule = double.Parse(HDate_Temp);
                            }
                            //模具编码
                            if (keys.Contains("selectField_lq3idkvg"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["selectField_lq3idkvg"].ToString();
                                DataSet ds = oCN.RunProcReturn("select * from Gy_MouldFileMain with(nolock)  where HNumber='" + HDate_Temp + "'", "Gy_MouldFileMain");
                                string HMouldID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
@@ -2093,6 +2148,7 @@
                                    HMouldID = ds.Tables[0].Rows[0]["HInterID"].ToString();
                                }
                                oItem.HMouldID = long.Parse(HMouldID);
                                oItem.HRemark = HDate_Temp;
                            }
@@ -2116,7 +2172,7 @@
                            if (keys.Contains("employeeField_lq3idkvh"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lq3idkvh"]));
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HNumber='" + HDate_Temp[0] + "'", "Gy_Employee");
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where hname='" + HDate_Temp[0] + "'", "Gy_Employee");
                                string HEmpID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
@@ -2233,6 +2289,7 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                return false;
            }
@@ -2268,11 +2325,33 @@
            try
            {
                oCN.BeginTran();
                string HMouldMaintainRuleInterID = "0";
                string HMaintainItemID = "0";
                string HRepairID = "0";
                DataSet dataSet = oCN.RunProcReturn(@"select  a.HInterID,item.HMaintainItemID    from Sc_MouldMaintainRuleBillMain a with(nolock)
inner join Sc_MouldMaintainRuleBillSub_Item item with(nolock) on  a.HInterID = item.HInterID
where a.HRemark like'%钉钉同步%'", "Sc_MouldMaintainRuleBillMain");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    HMouldMaintainRuleInterID = dataSet.Tables[0].Rows[0]["HInterID"].ToString();
                    HMaintainItemID = dataSet.Tables[0].Rows[0]["HMaintainItemID"].ToString();
                }
                dataSet = oCN.RunProcReturn(@"select HItemID from Gy_Repair a with(nolock) where a.HRemark like'%钉钉同步%' and HName like'%模具维修%'", "Gy_Repair");
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    HRepairID = dataSet.Tables[0].Rows[0]["HItemID"].ToString();
                }
                foreach (MouldFileWeiXiuBaoYang oItem in lsmain)
                {
                    //保养记录
                    if (oItem.DetailColMouldMaintain.Count != 0)
                    {
                        string BillType = "3819";
                        string sql = $@"select HInnerBillNo from Sc_MouldMaintainBillMain
                            where HInnerBillNo = '{oItem.HInstanceID}'";
@@ -2281,7 +2360,7 @@
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            long HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                            string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //long HInterID = 0;
                            //string HBillNo = "";
                            string sql_main = "Insert Into Sc_MouldMaintainBillMain " +
@@ -2290,11 +2369,13 @@
                ",HPlanNo,HPlanInterID,HMouldID,HBeginDate" +
                ",HEndDate" +
                ",HInnerBillNo,HExplanation,HMouldMaintainRuleInterID,HMaintainLevID,HLastResult" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate(),'" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                ",HRequestComDate,HRecentMainModule,HCumulativeModule,HProductionModule)" +
                "values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + oItem.HBillNo + "','"+ oItem.HDate + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark + "','" + oItem.HUpdateDate + "'" +
                      ",'','0','" + oItem.HMouldID + "','" + oItem.HRepairBeginDate + "'" +
                      ",'" + oItem.HRepairEndDate + "'" +
                      ",'" + oItem.HInstanceID + "','',0,0,'OK')";
                      ",'" + oItem.HInstanceID + "','',"+ HMouldMaintainRuleInterID + ",0,'OK'" +
                      ",'"+ oItem.HRequestComDate + "'," + oItem.HRecentMainModule + "," + oItem.HCumulativeModule + "," + oItem.HProductionModule + ")";
                            LogService.Write(sql_main);
                            oCN.RunProc(sql_main);
                            int i = 1;
@@ -2306,11 +2387,12 @@
                          ",HManagerID" +
                          ",HCloseMan,HCloseType,HRemark" +
                          ",HSourceInterID,HSourceEntryID,HSourceBillNo,HSourceBillType,HRelationQty,HRelationMoney,HMaintainResult" +
                          ") values('" + HInterID + "'," + i + ",0,'" + oItem_Detail.HClaim + "'" +
                          ") " +
                          "values('" + HInterID + "'," + i + ","+ HMaintainItemID + ",'" + oItem_Detail.HClaim + "'" +
                     ",'','" + oItem_Detail.HClaim + "'" +
                     ",'" + oItem.HEmpID + "'" +
                     ",'','','" + oItem_Detail.HMaintainResult + "'" +
                     ",'0','0','','',0,0,'')";
                     ",'0','0','','',0,0,'Y')";
                                LogService.Write(sql_sub);
                                oCN.RunProc(sql_sub);
                                i += 1;
@@ -2330,7 +2412,7 @@
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            long HInterID = DBUtility.ClsPub.CreateBillID(BillType, ref DBUtility.ClsPub.sExeReturnInfo);
                            string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //string HBillNo = DBUtility.ClsPub.CreateBillCode_Prod(BillType, ref DBUtility.ClsPub.sExeReturnInfo, true);
                            //long HInterID = 0;
                            //string HBillNo = "";
                            string sql_main = "Insert Into Sc_MouldRepairWorkBillMain " +
@@ -2340,12 +2422,14 @@
                ",HCycleUnit,HPlanTimes,HTimes,HEmpID,HManagerID" +
                ",HDeptID,HExplanation,HInnerBillNo,HMouldID" +
                ",HSupID,HRepairType,HNewModel,HNewDesignLife,HMainSourceBillType,HMainSourceInterID,HMainSourceEntryID" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" +
                ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'0','0','" + oItem.HRepairBeginDate + "','" + oItem.HUpdateDate + "',''" +
                ",HRepairAccepDate)values" +
                "('" + BillType + "','" + BillType + "'," + HInterID + ",'" + oItem.HBillNo + "','"+ oItem .HDate+ "'" +
                ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'0','"+ HRepairID + "','" + oItem.HRepairBeginDate + "','" + oItem.HRepairEndDate + "',''" +
                      ",'小时','" + oItem.HPlanTimes + "','" + oItem.HTimes + "','" + oItem.HEmpID + "',0" +
                      ",'" + oItem.HDeptID + "','','" + oItem.HInstanceID + "','" + oItem.HMouldID + "'" +
                      ",'0','内部维修','','" + oItem.HNewDesignLife + "','',0,0)";
                      ",'0','内部维修','','" + oItem.HNewDesignLife + "','1',0,0" +
                      ",'"+ oItem.HRepairAccepDate + "')";
                            LogService.Write(sql_main);
                            oCN.RunProc(sql_main);
                            int i = 1;
@@ -2357,7 +2441,7 @@
                       ",HRepairID,HRepairExplanation,HManagerID,HMoney) values" +
                       "('" + HInterID + "'," + i + ",'','','','" + oItem_Detail.HRemark + "'" +
                          ",0,0,'','',0,0" +
                          ",0,'" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "',0)";
                          ","+ HRepairID + ",'" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "',0)";
                                LogService.Write(sql_sub);
                                oCN.RunProc(sql_sub);
                                i += 1;
@@ -2373,6 +2457,7 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                oCN.RollBack();
                return false;
@@ -2385,7 +2470,7 @@
        #region èŽ·å– å®œæ­-设备维修记录单 å®žä¾‹ID列表对应的实例详情
        public bool getInstanceDetailList___EquipRepairWeiXiu_YiDa(string appType, string systemToken, string userID, string formUuid, List<string> IDList, ref List<EquipRepairWeiXiu> lsmain, ref string msg, int size = 500)
        {
            string a = "";
            try
            {
                int startIndex = 0;
@@ -2437,11 +2522,59 @@
                                continue;
                            }
                            //报修类别
                            if (keys.Contains("multiSelectField_lfg9hgyv"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["multiSelectField_lfg9hgyv"]));
                                oItem.HRepairCategory = HDate_Temp[0];
                            }
                            //紧急程度
                            if (keys.Contains("radioField_kzgkw10c"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["radioField_kzgkw10c"].ToString();
                                oItem.HUrgenLevel = HDate_Temp;
                            }
                            //报修人
                            if (keys.Contains("employeeField_lkasesrk"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lkasesrk"]));
                                oItem.HRepairer = HDate_Temp[0];
                            }
                            //是否有产能影响
                            if (keys.Contains("textField_lyjddw0r"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_lyjddw0r"].ToString();
                                oItem.HIsCapacityImpact = HDate_Temp;
                            }
                            //维修时间
                            if (keys.Contains("textField_l2r95oo2"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_l2r95oo2"].ToString();
                                bool containsNumber = HDate_Temp.Any(c => char.IsDigit(c));
                                if (!containsNumber)
                                {
                                    HDate_Temp = "0";
                                }
                                LogService.Write("1:------"+HDate_Temp+ ",2:------" + int.Parse(new string(HDate_Temp.Where(char.IsDigit).ToArray())));
                                //a = HDate_Temp;
                                oItem.HTimes = int.Parse(new string(HDate_Temp.Where(char.IsDigit).ToArray()));
                                oItem.HPlanTimes = int.Parse(new string(HDate_Temp.Where(char.IsDigit).ToArray()));
                            }
                            //设备编码
                            if (keys.Contains("textField_lfg9hgys"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_lfg9hgys"].ToString();
                                DataSet ds = oCN.RunProcReturn("select * from Gy_MouldFileMain with(nolock)  where HNumber='" + HDate_Temp + "'", "Gy_MouldFileMain");
                                DataSet ds = oCN.RunProcReturn("select * from Gy_EquipFileBillMain with(nolock)  where HEquipFileNo='" + HDate_Temp + "'", "Gy_EquipFileBillMain");
                                string HEquipID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
@@ -2450,7 +2583,6 @@
                                oItem.HEquipID = long.Parse(HEquipID);
                                oItem.HRemark2 = HDate_Temp;
                            }
                            //维修部门
                            if (keys.Contains("selectField_kzgkw10a"))
@@ -2465,27 +2597,17 @@
                                oItem.HDeptID = long.Parse(HDeptID);
                            }
                            //维修人
                            if (keys.Contains("employeeField_lthwkdh2"))
                            {
                                string[] HDate_Temp = JsonConvert.DeserializeObject<string[]>(JsonConvert.SerializeObject(response.Body.Result[i].FormData["employeeField_lthwkdh2"]));
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HNumber='" + HDate_Temp[0] + "'", "Gy_Employee");
                                DataSet ds = oCN.RunProcReturn("select * from Gy_Employee with(nolock)  where HName='" + HDate_Temp[0] + "'", "Gy_Employee");
                                string HEmpID = "0";
                                if (ds.Tables[0].Rows.Count > 0)
                                {
                                    HEmpID = ds.Tables[0].Rows[0]["HItemID"].ToString();
                                }
                                oItem.HEmpID = long.Parse(HEmpID);
                            }
                            //维修时间
                            if (keys.Contains("textField_l2r95oo2"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textField_l2r95oo2"].ToString();
                                oItem.HTimes = long.Parse(HDate_Temp);
                                oItem.HPlanTimes = long.Parse(HDate_Temp);
                            }
                            //维修内容
@@ -2505,7 +2627,7 @@
                            if (keys.Contains("textareaField_lthwo99r"))
                            {
                                string HDate_Temp = response.Body.Result[i].FormData["textareaField_lthwo99r"].ToString();
                                oItem.HExplanation = HDate_Temp;
                                sub.HRepairExplanation = HDate_Temp;
                            }
@@ -2551,6 +2673,8 @@
                        }
                        catch (Exception e)
                        {
                            //LogService.Write(a);
                            a = "";
                            continue;
                        }
                    }
@@ -2586,7 +2710,7 @@
            int pageNumber = 1;
            int pageSize = 100;
            //获取模具维修保养表的实例ID列表
            //获取设备维修保养表的实例ID列表
            List<string> IDList = new List<string>();
            if (getInstanceIDList_YiDa(appType, systemToken, userID, formUuid, pageNumber, pageSize, ref IDList, ref msg) == false)
            {
@@ -2603,6 +2727,14 @@
            try
            {
                oCN.BeginTran();
               DataSet dataSet = oCN.RunProcReturn(@"select HItemID from Gy_Repair a with(nolock) where a.HRemark like'%钉钉同步%' and HName like'%设备维修%'", "Gy_Repair");
                string HRepairID = "0";
                if (dataSet.Tables[0].Rows.Count > 0)
                {
                    HRepairID = dataSet.Tables[0].Rows[0]["HItemID"].ToString();
                }
                foreach (EquipRepairWeiXiu oItem in lsmain)
                {
                    //维修记录
@@ -2625,11 +2757,13 @@
                ",HEquipID,HRepairID,HPlanTimes,HEmpID,HManagerID,HTimes" +
                ",HDeptID,HExplanation,HInnerBillNo,HRepairBeginDate,HRepairEndDate" +
                ",HRepairContent,HCycleUnit,HMainSourceBillType,HMainSourceInterID,HMainSourceEntryID" +
                ")values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" +
                ",HRepairCategory,HUrgenLevel,HRepairer,HIsCapacityImpact)" +
                "values('" + BillType + "','" + BillType + "'," + HInterID + ",'" + HBillNo + "',getdate()" +
                ",'" + DateTime.Now.Year + "','" + DateTime.Now.Month + "','"+ oItem.HRemark2 + "','" + oItem.HOriginator + "','" + oItem.HMakeDate + "'" +
                      ",'" + oItem.HEquipID + "','0','" + oItem.HTimes + "','" + oItem.HEmpID + "','" + oItem.HEmpID + "','" + oItem.HTimes + "'" +
                      ",'" + oItem.HDeptID + "','" + oItem.HExplanation + "','" + oItem.HInstanceID + "','',''" +
                      ",'" + oItem.HRepairContent + "','小时','','0',0)";
                      ",'" + oItem.HEquipID + "','"+ HRepairID + "','" + oItem.HTimes + "','" + oItem.HEmpID + "','" + oItem.HEmpID + "','" + oItem.HTimes + "'" +
                      ",'" + oItem.HDeptID + "','"+ oItem.HExplanation + "','" + oItem.HInstanceID + "','"+ oItem.HMakeDate + "','" + oItem.HUpdateDate + "'" +
                      ",'" + oItem.HRepairContent + "','小时','手工录入','0',0" +
                      ",'"+ oItem.HRepairCategory + "','" + oItem.HUrgenLevel + "','" + oItem.HRepairer + "','" + oItem.HIsCapacityImpact + "')";
                            LogService.Write(sql_main);
                            oCN.RunProc(sql_main);
                            int i = 1;
@@ -2641,7 +2775,7 @@
                       ",HRepairID,HManagerID,HRepairExplanation,HEmpID)" +
                       "values('" + HInterID + "'," + i + ",'','','','" + oItem_Detail.HRemark + "'" +
                          ",0,0,'','',0,0" +
                          ",0,'" + oItem.HEmpID + "','" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "')";
                          "," + HRepairID + ",'" + oItem.HEmpID + "','" + oItem_Detail.HRepairExplanation + "','" + oItem.HEmpID + "')";
                                LogService.Write(sql_sub);
                                oCN.RunProc(sql_sub);
                                i += 1;
@@ -2657,6 +2791,7 @@
            }
            catch (Exception e)
            {
                LogService.Write(e.Message);
                msg = e.Message;
                oCN.RollBack();
                return false;