username@email.com
2023-02-28 67a0042c5f29e4bb0e0b82f6190f2bc51480b45c
zhengcaioa/zhengcaioa/Controllers/ProjectController.cs
@@ -17,6 +17,9 @@
using System.IdentityModel.Tokens.Jwt;
using CommonToolsCore;
using System.Transactions;
using DTO.WebCrawler;
using System.Net.Http.Headers;
using Microsoft.Extensions.Configuration;
namespace zhengcaioa.Controllers
{
@@ -32,13 +35,14 @@
        private readonly IFiOrderrecievemoneyService _fiOrderrecievemoneyService;
        private readonly IAreaService _areaService;
        private readonly IPltPageService _pltPageService;
        private readonly IConfiguration _configuration;
        public ProjectController(ILogger<ProjectController> logger, IProjectService projectService, ILiaotianService liaotianService,IIntentionCustomerService intentionCustomerService, IUserService userService
            , ICooperatecustomCustomerService cooperatecustomCustomerService
            , ISysBaimingdanService sysBaimingdanService
            , IFiOrderrecievemoneyService fiOrderrecievemoneyService
            , IAreaService areaService
              , IPltPageService pltPageService)
              , IPltPageService pltPageService
              , IConfiguration configuration)
        {
            _logger = logger;
            _projectService = projectService;
@@ -50,6 +54,7 @@
            _fiOrderrecievemoneyService = fiOrderrecievemoneyService;
            _areaService = areaService;
            _pltPageService = pltPageService;
            _configuration = configuration;
        }
        [CheckLogin]
        public IActionResult Index()
@@ -389,6 +394,9 @@
            ViewBag.Baomingtimebegin = DateTime.Now.AddMonths(-6).ToString("yyyy-MM-dd");
            ViewBag.Baomingtimeend = DateTime.Now.ToString("yyyy-MM-dd");
            ViewBag.wanshan = _liaotianService.GetSYScode("Project", "wanshan").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            return View();
        }
@@ -452,6 +460,15 @@
                            }
                        }
                        var feibiaoliyous = cDocumet.QuerySelectorAll("div").Where(m => m.Id == "_notice_content_reason-reason");
                        if (feibiaoliyous != null && feibiaoliyous.ToList().Count > 0)
                        {
                            var feibiaoliyou = feibiaoliyous.First();
                            projectDTO.Fbyy = feibiaoliyou.TextContent.Replace("\n", "").Replace("\t", "");
                            projectDTO.Fblx = "终止采购";
                        }
                        var Numbers = cDocumet.QuerySelectorAll("h4");
                        foreach(var Number in Numbers )
                        {
@@ -479,7 +496,15 @@
                            {
                                var Fbyy = Number.QuerySelector("span");
                                projectDTO.Fbyy = Fbyy.TextContent.Trim();
                                projectDTO.Fblx = "停止评审";
                            }
                            if (Number != null && Number.TextContent.Contains("终止原因"))
                            {
                                var Fbyy = Number.QuerySelector("span");
                                projectDTO.Fbyy = Fbyy.TextContent.Trim();
                                projectDTO.Fblx = "停止评审";
                            }
                        }
                        var Caigourennames = cDocumet.QuerySelectorAll("span").Where(m => m.Id == "_notice_content_noticePurchase-purchaserOrgName");
                        if (Caigourennames != null && Caigourennames.ToList().Count > 0)
@@ -567,6 +592,14 @@
                        }
                        projectDTO.StartTimestr = timestr;
                    }
                    var tittle = document.QuerySelector("h1");
                    if (tittle != null)
                    {
                        string tittlestr = tittle.TextContent;
                        projectDTO.Name = tittlestr;
                    }
                    var table = document.QuerySelector("table").QuerySelectorAll("tr");
                    if (table != null)
                    {
@@ -587,14 +620,34 @@
                                }
                            }
                            else if (select != null && select.TextContent.IndexOf("项目名称") >= 0)
                            //else if (select != null && select.TextContent.IndexOf("项目名称") >= 0)
                            //{
                            //    if (table[i + 1] != null)
                            //    {
                            //        var td1 = table[i + 1].QuerySelector("td");
                            //        if (td1 != null)
                            //        {
                            //            projectDTO.Name = table[i + 1].QuerySelector("td").TextContent.Trim();//OuterHtml
                            //        }
                            //    }
                            //}
                            else if (select != null && select.TextContent.IndexOf("项目终止的原因") >= 0)
                            {
                                if (table[i + 1] != null)
                                {
                                    var td1 = table[i + 1].QuerySelector("td");
                                    if (td1 != null)
                                    {
                                        projectDTO.Name = table[i + 1].QuerySelector("td").TextContent.Trim();//OuterHtml
                                        projectDTO.Fbyy = table[i + 1].QuerySelector("td").TextContent.Trim();//OuterHtml
                                        if (projectDTO.Fbyy.IndexOf("终止")<0)
                                        {
                                            projectDTO.Fblx = "停止评审";
                                        }
                                        else
                                        {
                                            projectDTO.Fblx = "终止采购";
                                        }
                                    }
                                }
@@ -1321,5 +1374,326 @@
            return new JsonResult(resultEntity);
        }
        [CheckLogin]
        public IActionResult indexZhengfuProject()
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            List<ActionEntity> actionlist = new List<ActionEntity>();
            //ActionEntity actionEntity = new ActionEntity();
            //actionEntity.OpenType = 0;
            //actionEntity.ActionUrl = "";
            //actionEntity.ActionFun = "Search";
            //actionEntity.PageIco = "fa fa-search";
            //actionEntity.ActionName = "查询";
            //actionlist.Add(actionEntity);
            //ActionEntity actionEntity1 = new ActionEntity();
            //actionEntity1.OpenType = 0;
            //actionEntity1.ActionUrl = "";
            //actionEntity1.ActionFun = "Add";
            //actionEntity1.PageIco = "fa fa-plus";
            //actionEntity1.ActionName = "新增";
            //actionlist.Add(actionEntity1);
            var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/Project/indexZhengfuProject");
            var pageEntities1 = pageEntities.Where(x => x.PageMethod == "01").ToList();
            if (pageEntities1.Count(x => x.PageShortcut == "Search") <= 0)
            {
                ActionEntity actionEntity = new ActionEntity();
                actionEntity.OpenType = 0;
                actionEntity.ActionUrl = "";
                actionEntity.ActionFun = "Search";
                actionEntity.PageIco = "fa fa-search";
                actionEntity.ActionName = "查询";
                actionlist.Add(actionEntity);
                ViewData["Creater11"] = curentuser.Id;
            }
            foreach (var pageEntity in pageEntities1)
            {
                ActionEntity actionEntity1 = new ActionEntity();
                actionEntity1.OpenType = pageEntity.OpenType;
                actionEntity1.ActionUrl = "";
                actionEntity1.ActionFun = pageEntity.PageShortcut;
                actionEntity1.PageIco = pageEntity.PageIco;
                actionEntity1.ActionName = pageEntity.PageName;
                actionlist.Add(actionEntity1);
            }
            ViewData["ActionInfo"] = actionlist;
            ViewBag.ProjectDropDown = _projectService.AllcgfsDropDown().Select(x => new { code = x.Value, label = x.Text }).ToList();
            //ViewBag.flbx = _liaotianService.GetSYScode("Project", "flbx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            var areaDTOs = _projectService.Getsheng().ToList();
            foreach (var areaDTO in areaDTOs)
            {
                if (areaDTO.CodeId == "510000")
                {
                    areaDTOs.Remove(areaDTO);
                    break;
                }
            }
            var areaDTOsic = new Area();
            areaDTOsic.CodeId = "510000";
            areaDTOsic.Name = "四川省";
            areaDTOsic.ParentId = "0     ";
            areaDTOs.Insert(1, areaDTOsic);
            ViewBag.ShengDropDown = areaDTOs.Select(x => new { code = x.CodeId, label = x.Name }).ToList();
            ViewBag.Creater = _userService.GetList().Select(x => new { code = x.Id, label = x.UserName }).ToList();
            ViewBag.gglx = _liaotianService.GetSYScode("zhengfu_Project", "gglx").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.cgfs = _liaotianService.GetSYScode("zhengfu_Project", "cgfs").Select(x => new { code = x.CodeSn, label = x.Comments }).ToList();
            ViewBag.Baomingtimebegin = DateTime.Now.AddMonths(-6).ToString("yyyy-MM-dd");
            ViewBag.Baomingtimeend = DateTime.Now.ToString("yyyy-MM-dd");
            return View();
        }
        [CheckLogin]
        public string GetZhengfuProjectList(ZhengfuProjectDTOSearch search)
        {
            //JsonResult jsonResult =   new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver());
            return JsonConvert.SerializeObject(_projectService.SearchByPagingCaigougonggao(search));
        }
        public IActionResult ADDZhengfuProject(string id = null)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/Project/indexZhengfuProject");
            var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList();
            ViewData["ActionInfo2"] = pageEntities2;
            ZhengfuProjectDTO zhengfuProjectDTO = new ZhengfuProjectDTO();
            if (!String.IsNullOrEmpty(id))
            {
                zhengfuProjectDTO = _projectService.GetZhengfuProjectDTO(id);
            }
            else
            {
                zhengfuProjectDTO.Sheng = "510000";
                zhengfuProjectDTO.City = "510100";
                zhengfuProjectDTO.RegionCode = "510107";
                zhengfuProjectDTO.NoticeTime = DateTime.Now;
                zhengfuProjectDTO.Gglx = "02";
                //zhengfuProjectDTO.NoticeTime = DateTime.Now;
                //zhengfuProjectDTO.NoticeTime = DateTime.Now;
            }
            var areaDTOs = _projectService.Getsheng().ToList();
            foreach (var areaDTO in areaDTOs)
            {
                if (areaDTO.CodeId == "510000")
                {
                    areaDTOs.Remove(areaDTO);
                    break;
                }
            }
            var areaDTOsic = new Area();
            areaDTOsic.CodeId = "510000";
            areaDTOsic.Name = "四川省";
            areaDTOsic.ParentId = "0     ";
            areaDTOs.Insert(1, areaDTOsic);
            var sheng = areaDTOs;
            var shi = _projectService.Getshi(zhengfuProjectDTO.Sheng);
            var quxian = _projectService.Getquxian(zhengfuProjectDTO.City);
            ViewBag.gglx = _liaotianService.GetSYScode("zhengfu_Project", "gglx");
            ViewBag.cgfs = _liaotianService.GetSYScode("zhengfu_Project", "cgfs");
            ViewBag.hyfl = _liaotianService.GetSYScode("CooperatecustomCustomer", "hyfl");
            ViewBag.sheng = sheng;
            ViewBag.shi = shi;
            ViewBag.quxian = quxian;
            ViewData.Model = zhengfuProjectDTO;
            return View();
        }
        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        ///
        [CheckLogin]
        [HttpPost]
        public string SaveZhengfuProject(ZhengfuProjectDTO data)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(HttpContext.Session.GetString("User"));
            ViewData["curentuser"] = curentuser;
            data.RecStatus = "A";
            if (String.IsNullOrEmpty(data.Id))
            {
                data.Creater = curentuser.Id;
                data.Createtime = DateTime.Now;
            }
            if (string.IsNullOrWhiteSpace(data.Content))
            {
                data.Content = data.Content1;
            }
            data.Shorttitle = data.Title;
            data.Modifier = curentuser.Id;
            data.Modifytime = DateTime.Now;
            ResultEntity resultEntity = new ResultEntity();
            resultEntity.Result = false;
                resultEntity = _projectService.saveZhengfuProjectDTO(data);
            if (resultEntity.Result)
            {
                var areaDTOs = _areaService.GetList();
                string api_domain = _configuration.GetSection("Elasticsearchurl").Value;
                string url = $"{api_domain}/webcrawler/_doc/" + data.Id;
                string result = string.Empty;
                Uri postUrl = new Uri(url);
                eswebcrawler eswebcrawler1 = new eswebcrawler();
                eswebcrawler1.Id = data.Id;
                eswebcrawler1.noticeTime = data.NoticeTime.ToString("yyyy-MM-dd HH:mm:ss");
                eswebcrawler1.openTenderTime = data.OpenTenderTime.HasValue ? data.OpenTenderTime.Value.ToString("yyyy-MM-dd HH:mm:ss") : null;
                eswebcrawler1.sheng = data.Sheng;
                if (!string.IsNullOrWhiteSpace(data.Sheng))
                {
                    var areaDTO = areaDTOs.Where(x => x.CodeId == data.Sheng).FirstOrDefault();
                    if (areaDTO != null)
                    {
                        eswebcrawler1.shengName = areaDTO.Name;
                    }
                }
                eswebcrawler1.city = data.City;
                if (!string.IsNullOrWhiteSpace(data.City))
                {
                    var areaDTO = areaDTOs.Where(x => x.CodeId == data.City).FirstOrDefault();
                    if (areaDTO != null)
                    {
                        eswebcrawler1.cityName = areaDTO.Name;
                    }
                }
                eswebcrawler1.regionCode = data.RegionCode;
                if (!string.IsNullOrWhiteSpace(data.RegionCode))
                {
                    var areaDTO = areaDTOs.Where(x => x.CodeId == data.RegionCode).FirstOrDefault();
                    if (areaDTO != null)
                    {
                        eswebcrawler1.regionName = areaDTO.Name;
                    }
                }
                eswebcrawler1.cgfs = data.Cgfs;
                if (!string.IsNullOrWhiteSpace(data.Cgfs))
                {
                    var sysCodeDtl = _liaotianService.GetSYScode("zhengfu_Project", "cgfs").Where(x => x.CodeSn == data.Cgfs).FirstOrDefault();
                    if (sysCodeDtl != null)
                    {
                        eswebcrawler1.cgfsName = sysCodeDtl.Comments;
                    }
                }
                eswebcrawler1.gglx = data.Gglx;
                if (!string.IsNullOrWhiteSpace(data.Gglx))
                {
                    var sysCodeDtl = _liaotianService.GetSYScode("zhengfu_Project", "gglx").Where(x => x.CodeSn == data.Gglx).FirstOrDefault();
                    if (sysCodeDtl != null)
                    {
                        eswebcrawler1.gglxName = sysCodeDtl.Comments;
                    }
                }
                eswebcrawler1.openTenderCode = data.OpenTenderCode;
                eswebcrawler1.title = data.Title;
                eswebcrawler1.shorttitle = data.Shorttitle;
                eswebcrawler1.pageurl = data.Pageurl;
                eswebcrawler1.pingmu = data.Pingmu;
                eswebcrawler1.pingmuName = "";
                eswebcrawler1.purchaser = data.Purchaser;
                eswebcrawler1.budget = data.Budget.HasValue ? data.Budget.Value.ToString() : "";
                eswebcrawler1.agency = data.Agency;
                eswebcrawler1.agencyCode = data.AgencyCode;
                eswebcrawler1.modifyTime = data.Modifytime.ToString("yyyy-MM-dd HH:mm:ss");
                string requestJson = JsonConvert.SerializeObject(eswebcrawler1);
                using (HttpContent httpContent = new StringContent(requestJson))
                {
                    httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    using (HttpClient httpClient = new HttpClient())
                    {
                        httpClient.Timeout = TimeSpan.FromSeconds(60);
                        HttpResponseMessage responseMessage = httpClient.PutAsync(postUrl, httpContent).Result;
                        result = responseMessage.Content.ReadAsStringAsync().Result;
                    }
                }
                Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)JsonConvert.DeserializeObject(result);
                if (jobject["error"] == null && jobject["_shards"]["successful"].ToString() == "1")
                {
                }
                else
                {
                    resultEntity.Result = false;
                    resultEntity.Message = "保存数据库出错!";
                }
            }
            return JsonConvert.SerializeObject(resultEntity);
        }
        /// <summary>
        /// 获取项目是否已经录入
        /// </summary>
        /// <param name="shengid">市id</param>
        /// <returns></returns>
        [CheckLogin]
        public string getPageurl(string Pageurl, string Id)
        {
            var quxian = _projectService.GetZhengfuProjectDTOByPageurl(Pageurl, Id);
            return JsonConvert.SerializeObject(quxian);
        }
        /// <summary>
        /// 获取项目是否已经录入
        /// </summary>
        /// <param name="shengid">市id</param>
        /// <returns></returns>
        [CheckLogin]
        public string getTitle(string Title, string Id, DateTime? NoticeTime)
        {
            var quxian = _projectService.GetZhengfuProjectDTOByTitle(Title, Id, NoticeTime);
            return JsonConvert.SerializeObject(quxian);
        }
    }
}