username@email.com
10 小时以前 7b52260c2a83d23adb5447a9e9848d90b4dc018c
zhengcaioa/Crawler/sichuan/sichuantousuoperation.cs
@@ -71,7 +71,7 @@
                            dateTime = DateTime.Now; // 获取当前UTC时间的DateTime对象
                            timestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                            var askurl = "https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/getInfoById?id=" + sichuanjieshoudtl.id +"& _t=" + timestamp;
                            var askurl = "https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/getInfoById?id=" + sichuanjieshoudtl.id +"&_t=" + timestamp;
                            procurementComplaint = new ProcurementComplaint();
                            procurementComplaint.Id = Id;
                            procurementComplaint.ProjectCode = sichuanjieshoudtl.openTenderCode ?? "";
@@ -253,7 +253,7 @@
                                            }
                                            else if (aaaa.IndexOf("部分成立") >= 0)
                                            {
                                                HandlingStatuses.Add(3);
                                                HandlingStatuses.Add(1);//3
                                            }
                                            else
                                            {
@@ -296,7 +296,7 @@
                                                }
                                                else if (aaaa.IndexOf("部分成立") >= 0)
                                                {
                                                    HandlingStatuses.Add(3);
                                                    HandlingStatuses.Add(1);//3
                                                }
                                                else
                                                {
@@ -404,7 +404,7 @@
                {
                    updatetime = new Updatetime();
                    updatetime.Id = Guid.NewGuid().ToString();
                    updatetime.Sheng = "四川省";
                    updatetime.Sheng = "四川省投诉处理";
                    updatetime.Updatetime1 = DateTime.Now.AddDays(-1);
                    _ccontext.Updatetimes.Add(updatetime);
                    _ccontext.SaveChanges();
@@ -422,6 +422,482 @@
            {
            }
        }
        public static void operations1(WebCrawlerContext _ccontext)
        {
            try
            {
                //获取更新时间
                string operationStartTime = "";
                string operationEndTime = "";
                Updatetime updatetime = _ccontext.Updatetimes.Where(x => x.Sheng == "四川省处理处罚").FirstOrDefault();
                if (updatetime != null)
                {
                    operationStartTime = updatetime.Updatetime1.ToString("yyyy-MM-dd");
                    operationEndTime = updatetime.Updatetime1.AddMonths(1).ToString("yyyy-MM-dd");
                }
                else
                {
                    operationStartTime = DateTime.Now.AddMonths(-1).ToString("yyyy-MM-dd");
                    operationEndTime = DateTime.Now.ToString("yyyy-MM-dd");
                }
                //翻页信息
                int currPage = 1;
                int pageSize = 10;
                //开始访问 采购公告
                logg.WriteLog("四川省处理 开始获取", "四川省处理处罚");
                var parser = new HtmlParser();
                while (true)
                {
                    Thread.CurrentThread.Join(1000 * 5);//阻止设定时间
                    logg.WriteLog(operationStartTime + operationEndTime + currPage.ToString(), "四川省处理处罚");
                    DateTime dateTime = DateTime.Now; // 获取当前UTC时间的DateTime对象
                    long timestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                    string address = "https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/selectInfoForIndex?title=&region=&siteId=94c965cc-c55d-4f92-8469-d5875c68bd04&channel=069a8160-27a5-4fc9-9506-3df804023d40&currPage=" + currPage + "&pageSize=" + pageSize + "&noticeType=&regionCode=&cityOrArea=&purchaseManner=&openTenderCode=&purchaser=&agency=&purchaseNature=&operationStartTime=" + operationStartTime + "+00:00:00&operationEndTime=" + operationEndTime + "+00:00:00&_t=" + timestamp;//1748999478170
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              //"https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/selectInfoForIndex?title=&region=&siteId=94c965cc-c55d-4f92-8469-d5875c68bd04&channel=78f796dd-fc3d-452e-8033-6309c70fca6f&currPage=1&pageSize=10&noticeType=&regionCode=&cityOrArea=&purchaseManner=&openTenderCode=&purchaser=&agency=&purchaseNature=&operationStartTime=&operationEndTime=&_t=1750293232376"
                    sichuantousujieshou sichuan = null;
                    using (HttpClient client = new HttpClient())
                    {
                        client.Timeout = TimeSpan.FromSeconds(60);
                        HttpResponseMessage response = client.GetAsync(address).Result;
                        var res = response.Content.ReadAsStringAsync().Result;
                        sichuan = JsonConvert.DeserializeObject<sichuantousujieshou>(res);
                    }
                    if (sichuan.data.rows != null && sichuan.data.rows.Count > 0)
                    {
                        foreach (var sichuanjieshoudtl in sichuan.data.rows)
                        {
                            var Id = Guid.Parse(sichuanjieshoudtl.id);
                            var aDPenalty = _ccontext.ADPenaltys.Find(Id);
                            if (aDPenalty != null)
                            {
                                continue;
                            }
                            dateTime = DateTime.Now; // 获取当前UTC时间的DateTime对象
                            timestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                            var askurl = "https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/getInfoById?id=" + sichuanjieshoudtl.id + "&_t=" + timestamp;
                            aDPenalty = new ADPenalty();
                            aDPenalty.Id = Id;
                            aDPenalty.DecisionDate = sichuanjieshoudtl.noticeTime;
                            aDPenalty.Parties = "";
                            aDPenalty.CaseReason = "";
                            aDPenalty.DisposalDecision = "";
                            aDPenalty.SupervisionDepartment = sichuanjieshoudtl.author ?? "";
                            if (aDPenalty.SupervisionDepartment.Length > 255)
                            {
                                aDPenalty.SupervisionDepartment = aDPenalty.SupervisionDepartment.Substring(0, 255);
                            }
                            aDPenalty.CreateTime = DateTime.Now;
                            aDPenalty.UpdateTime = aDPenalty.CreateTime;
                            aDPenalty.Url = "https://www.ccgp-sichuan.gov.cn/maincms-web/article?type=article&id=" + sichuanjieshoudtl.id;
                            Thread.CurrentThread.Join(1000 * 5);//阻止设定时间
                            logg.WriteLog(askurl, "四川省处理处罚");
                            sichuantousujieshoumingxi sichuanjieshou = null;
                            using (HttpClient client = new HttpClient())
                            {
                                client.Timeout = TimeSpan.FromSeconds(60);
                                HttpResponseMessage response = client.GetAsync(askurl).Result;
                                var res = response.Content.ReadAsStringAsync().Result;
                                sichuanjieshou = JsonConvert.DeserializeObject<sichuantousujieshoumingxi>(res);
                            }
                            if (sichuanjieshou != null && sichuanjieshou.code == "200" && !string.IsNullOrEmpty(sichuanjieshou.data.content))
                            {
                                var document = parser.ParseDocument(sichuanjieshou.data.content);
                                // var contentList = document.QuerySelectorAll("span").Where(x=>x.TextContent !="" && !x.InnerHtml.Contains("<span")).ToList();
                                var contentList = document.QuerySelectorAll("p").Where(x => x.TextContent != "").ToList();
                                bool jibenqingkuang = false;
                                bool chulijieguo = false;
                                foreach (var content in contentList)
                                {
                                    var ssss = content.TextContent.Replace(" ", "");
                                    if (ssss.IndexOf("当事人:") >= 0 || ssss.IndexOf("当事人:") >= 0 || ssss.IndexOf("当 事 人:") >= 0 || ssss.IndexOf("当  事  人:") >= 0 || ssss.IndexOf("当 事 人:") >= 0 || ssss.IndexOf("名称:") >= 0 || ssss.IndexOf("相关供应商:") >= 0 || ssss.IndexOf("当事人(单位):") >= 0)
                                    {
                                        //if (string.IsNullOrEmpty(aDPenalty.Parties))
                                        //{
                                            aDPenalty.Parties = ssss.Replace("当事人:", "").Replace("当事人:", "").Replace("当 事 人:", "").Replace("当  事  人:", "").Replace("当 事 人:", "").Replace("名称:", "").Replace("相关供应商:", "").Replace("当事人(单位):", "").Trim();
                                            if (aDPenalty.Parties.Length > 255)
                                            {
                                                aDPenalty.Parties = aDPenalty.Parties.Substring(0, 255);
                                            }
                                        //}
                                    }
                                    if (ssss.IndexOf("当事人1:") >= 0 || ssss.IndexOf("当事人2:") >= 0 || ssss.IndexOf("当事人3:") >= 0 || ssss.IndexOf("当事人4:") >= 0)
                                    {
                                        aDPenalty.Parties += ssss.Replace("当事人1:", "").Replace("当事人2:", "").Replace("当事人3:", "").Replace("当事人4:", "").Trim() + " ";
                                        if (aDPenalty.Parties.Length > 255)
                                        {
                                            aDPenalty.Parties = aDPenalty.Parties.Substring(0, 255);
                                        }
                                    }
                                    if (ssss.EndsWith(":") || ssss.IndexOf(":") >= 0)
                                    {
                                        if (string.IsNullOrEmpty(aDPenalty.Parties))
                                        {
                                            aDPenalty.Parties = ssss.Replace(":", "").Replace(":", "").Trim();
                                            if (aDPenalty.Parties.Length > 255)
                                            {
                                                aDPenalty.Parties = aDPenalty.Parties.Substring(0, 255);
                                            }
                                        }
                                    }
                                    if (jibenqingkuang)
                                    {
                                        if (string.IsNullOrEmpty(aDPenalty.CaseReason))
                                        {
                                            aDPenalty.CaseReason = ssss.Trim();
                                        }
                                        jibenqingkuang = false;
                                    }
                                    if (ssss.IndexOf("二、 基本情况") >= 0 || ssss.IndexOf("二、基本情况") >= 0 || ssss.IndexOf("一、发现的问题") >= 0 || ssss.IndexOf("一、 发现的问题") >= 0 || ssss.IndexOf("一、整改事项") >= 0 || ssss.IndexOf("一、 整改事项") >= 0 || ssss.IndexOf("一、发现的主要问题") >= 0 || ssss.IndexOf("一、 发现的主要问题") >= 0 || ssss.IndexOf("一、存在问题") >= 0 || ssss.IndexOf("一、 存在问题") >= 0)
                                    {
                                        jibenqingkuang = true;
                                    }
                                    if (chulijieguo)
                                    {
                                        if (string.IsNullOrEmpty(aDPenalty.DisposalDecision))
                                        {
                                            aDPenalty.DisposalDecision = ssss.Trim();
                                        }
                                        chulijieguo = false;
                                    }
                                    if (ssss.IndexOf("三、 处理结果") >= 0 || ssss.IndexOf("三、处理结果") >= 0 || ssss.IndexOf("二、整改要求") >= 0 || ssss.IndexOf("二、 整改要求") >= 0)
                                    {
                                        chulijieguo = true;
                                    }
                                }
                                if (string.IsNullOrEmpty(aDPenalty.DisposalDecision))
                                {
                                    var bbbb = "";
                                    for (int i = 0; i < contentList.Count; i++)
                                    {
                                        var sssssss = contentList[i].TextContent;
                                        if (i == 0 || sssssss != contentList[i - 1].TextContent)
                                        {
                                            bbbb += sssssss;
                                        }
                                    }
                                    aDPenalty.DisposalDecision = bbbb;
                                }
                                _ccontext.ADPenaltys.Add(aDPenalty);
                                _ccontext.SaveChanges();
                            }
                        }
                    }
                    if (currPage * pageSize >= sichuan.data.total)
                    {
                        break;
                    }
                    else
                    {
                        currPage += 1;
                    }
                    //Thread.CurrentThread.Join(1000 * 10);//阻止设定时间
                }
                logg.WriteLog("四川省处理 获取完成", "四川省处理处罚");
                //翻页信息
                currPage = 1;
                pageSize = 10;
                //开始访问 采购公告
                logg.WriteLog("四川省处罚 开始获取", "四川省处理处罚");
                while (true)
                {
                    Thread.CurrentThread.Join(1000 * 5);//阻止设定时间
                    logg.WriteLog(operationStartTime + operationEndTime + currPage.ToString(), "四川省处理处罚");
                    DateTime dateTime = DateTime.Now; // 获取当前UTC时间的DateTime对象
                    long timestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                    string address = "https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/selectInfoForIndex?title=&region=&siteId=94c965cc-c55d-4f92-8469-d5875c68bd04&channel=78f796dd-fc3d-452e-8033-6309c70fca6f&currPage=" + currPage + "&pageSize=" + pageSize + "&noticeType=&regionCode=&cityOrArea=&purchaseManner=&openTenderCode=&purchaser=&agency=&purchaseNature=&operationStartTime=" + operationStartTime + "+00:00:00&operationEndTime=" + operationEndTime + "+00:00:00&_t=" + timestamp;//1748999478170
                                   //"https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/selectInfoForIndex?title=&region=&siteId=94c965cc-c55d-4f92-8469-d5875c68bd04&channel=78f796dd-fc3d-452e-8033-6309c70fca6f&currPage=1&pageSize=10&noticeType=&regionCode=&cityOrArea=&purchaseManner=&openTenderCode=&purchaser=&agency=&purchaseNature=&operationStartTime=&operationEndTime=&_t=1750293232376"
                    sichuantousujieshou sichuan = null;
                    using (HttpClient client = new HttpClient())
                    {
                        client.Timeout = TimeSpan.FromSeconds(60);
                        HttpResponseMessage response = client.GetAsync(address).Result;
                        var res = response.Content.ReadAsStringAsync().Result;
                        sichuan = JsonConvert.DeserializeObject<sichuantousujieshou>(res);
                    }
                    if (sichuan.data.rows != null && sichuan.data.rows.Count > 0)
                    {
                        foreach (var sichuanjieshoudtl in sichuan.data.rows)
                        {
                            var Id = Guid.Parse(sichuanjieshoudtl.id);
                            var aDPenalty = _ccontext.ADPenaltys.Find(Id);
                            if (aDPenalty != null)
                            {
                                continue;
                            }
                            dateTime = DateTime.Now; // 获取当前UTC时间的DateTime对象
                            timestamp = (long)(dateTime - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalMilliseconds;
                            var askurl = "https://www.ccgp-sichuan.gov.cn/gpcms/rest/web/v2/info/getInfoById?id=" + sichuanjieshoudtl.id + "&_t=" + timestamp;
                            aDPenalty = new ADPenalty();
                            aDPenalty.Id = Id;
                            aDPenalty.DecisionDate = sichuanjieshoudtl.noticeTime;
                            aDPenalty.Parties = "";
                            aDPenalty.CaseReason = "";
                            aDPenalty.DisposalDecision = "";
                            aDPenalty.SupervisionDepartment = sichuanjieshoudtl.author ?? "";
                            if (aDPenalty.SupervisionDepartment.Length > 255)
                            {
                                aDPenalty.SupervisionDepartment = aDPenalty.SupervisionDepartment.Substring(0, 255);
                            }
                            aDPenalty.CreateTime = DateTime.Now;
                            aDPenalty.UpdateTime = aDPenalty.CreateTime;
                            aDPenalty.Url = "https://www.ccgp-sichuan.gov.cn/maincms-web/article?type=article&id=" + sichuanjieshoudtl.id;
                            Thread.CurrentThread.Join(1000 * 5);//阻止设定时间
                            logg.WriteLog(askurl, "四川省处理处罚");
                            sichuantousujieshoumingxi sichuanjieshou = null;
                            using (HttpClient client = new HttpClient())
                            {
                                client.Timeout = TimeSpan.FromSeconds(60);
                                HttpResponseMessage response = client.GetAsync(askurl).Result;
                                var res = response.Content.ReadAsStringAsync().Result;
                                sichuanjieshou = JsonConvert.DeserializeObject<sichuantousujieshoumingxi>(res);
                            }
                            if (sichuanjieshou != null && sichuanjieshou.code == "200" && !string.IsNullOrEmpty(sichuanjieshou.data.content))
                            {
                                var document = parser.ParseDocument(sichuanjieshou.data.content);
                                // var contentList = document.QuerySelectorAll("span").Where(x=>x.TextContent !="" && !x.InnerHtml.Contains("<span")).ToList();
                                var contentList = document.QuerySelectorAll("p").Where(x => x.TextContent != "").ToList();
                                bool jibenqingkuang = false;
                                bool chulijieguo = false;
                                foreach (var content in contentList)
                                {
                                    var ssss = content.TextContent.Replace(" ", "");
                                    if (ssss.IndexOf("当事人:") >= 0 || ssss.IndexOf("当事人:") >= 0 || ssss.IndexOf("当 事 人:") >= 0 || ssss.IndexOf("当  事  人:") >= 0 || ssss.IndexOf("当 事 人:") >= 0 || ssss.IndexOf("名称:") >= 0 || ssss.IndexOf("相关供应商:") >= 0 || ssss.IndexOf("当事人(单位):") >= 0 || ssss.IndexOf("被处罚者:") >= 0)
                                    {
                                        //if (string.IsNullOrEmpty(aDPenalty.Parties))
                                        //{
                                            aDPenalty.Parties = ssss.Replace("当事人:", "").Replace("当事人:", "").Replace("当 事 人:", "").Replace("当  事  人:", "").Replace("当 事 人:", "").Replace("名称:", "").Replace("相关供应商:", "").Replace("当事人(单位):", "").Replace("被处罚者:", "").Trim();
                                            if (aDPenalty.Parties.Length > 255)
                                            {
                                                aDPenalty.Parties = aDPenalty.Parties.Substring(0, 255);
                                            }
                                        //}
                                    }
                                    if (ssss.IndexOf("当事人1:") >= 0 || ssss.IndexOf("当事人2:") >= 0 || ssss.IndexOf("当事人3:") >= 0 || ssss.IndexOf("当事人4:") >= 0)
                                    {
                                            aDPenalty.Parties += ssss.Replace("当事人1:", "").Replace("当事人2:", "").Replace("当事人3:", "").Replace("当事人4:", "").Trim()+" ";
                                            if (aDPenalty.Parties.Length > 255)
                                            {
                                                aDPenalty.Parties = aDPenalty.Parties.Substring(0, 255);
                                            }
                                    }
                                    if (ssss.EndsWith(":") || ssss.IndexOf(":") >= 0)
                                    {
                                        if (string.IsNullOrEmpty(aDPenalty.Parties))
                                        {
                                            aDPenalty.Parties = ssss.Replace(":", "").Replace(":", "").Trim();
                                            if (aDPenalty.Parties.Length > 255)
                                            {
                                                aDPenalty.Parties = aDPenalty.Parties.Substring(0, 255);
                                            }
                                        }
                                    }
                                    if (jibenqingkuang)
                                    {
                                        if (string.IsNullOrEmpty(aDPenalty.CaseReason))
                                        {
                                            aDPenalty.CaseReason = ssss.Trim();
                                        }
                                        jibenqingkuang = false;
                                    }
                                    if (ssss.IndexOf("二、 基本情况") >= 0 || ssss.IndexOf("二、基本情况") >= 0 || ssss.IndexOf("一、 基本情况") >= 0 || ssss.IndexOf("一、基本情况") >= 0)
                                    {
                                        jibenqingkuang = true;
                                    }
                                    if (chulijieguo)
                                    {
                                        if (string.IsNullOrEmpty(aDPenalty.DisposalDecision))
                                        {
                                            aDPenalty.DisposalDecision = ssss.Trim();
                                        }
                                        chulijieguo = false;
                                    }
                                    if (ssss.IndexOf("三、 处罚结果") >= 0 || ssss.IndexOf("三、处罚结果") >= 0 || ssss.IndexOf("二、 处罚结果") >= 0 || ssss.IndexOf("二、处罚结果") >= 0)
                                    {
                                        chulijieguo = true;
                                    }
                                }
                                if (string.IsNullOrEmpty(aDPenalty.DisposalDecision))
                                {
                                    var bbbb = "";
                                    for (int i = 0; i < contentList.Count; i++)
                                    {
                                        var sssssss = contentList[i].TextContent;
                                        if (i == 0 || sssssss != contentList[i - 1].TextContent)
                                        {
                                            bbbb += sssssss;
                                        }
                                    }
                                    aDPenalty.DisposalDecision = bbbb;
                                }
                                _ccontext.ADPenaltys.Add(aDPenalty);
                                _ccontext.SaveChanges();
                            }
                        }
                    }
                    if (currPage * pageSize >= sichuan.data.total)
                    {
                        break;
                    }
                    else
                    {
                        currPage += 1;
                    }
                    //Thread.CurrentThread.Join(1000 * 10);//阻止设定时间
                }
                logg.WriteLog("四川省处罚 获取完成", "四川省处理处罚");
                //保存最后更新时间
                if (updatetime != null)
                {
                    if (updatetime.Updatetime1.AddMonths(1).Date >= DateTime.Now.Date)
                    {
                        updatetime.Updatetime1 = DateTime.Now.AddDays(-1);
                    }
                    else
                    {
                        updatetime.Updatetime1 = updatetime.Updatetime1.AddMonths(1).AddDays(-1);
                    }
                    _ccontext.SaveChanges();
                }
                else
                {
                    updatetime = new Updatetime();
                    updatetime.Id = Guid.NewGuid().ToString();
                    updatetime.Sheng = "四川省处理处罚";
                    updatetime.Updatetime1 = DateTime.Now.AddDays(-1);
                    _ccontext.Updatetimes.Add(updatetime);
                    _ccontext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                logg.WriteLog(ex.Message, "四川省处理处罚");
                logg.WriteLog(ex.StackTrace, "四川省处理处罚");
                logg.WriteLog(ex.ToString(), "四川省处理处罚");
            }
            finally
            {
            }
        }
    }
}