using AngleSharp.Html.Parser; using DTO; using IServices; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Text; using System.Threading.Tasks; using zhengcaioa.IService; using zhengcaioa.Models; namespace zhengcaioa.Controllers { public class ProjectController : Controller { private readonly ILogger _logger; private readonly IProjectService _projectService; private readonly ILiaotianService _liaotianService; private readonly IIntentionCustomerService _intentionCustomerService; private readonly IUserService _userService; public ProjectController(ILogger logger, IProjectService projectService, ILiaotianService liaotianService,IIntentionCustomerService intentionCustomerService, IUserService userService) { _logger = logger; _projectService = projectService; _liaotianService = liaotianService; _intentionCustomerService = intentionCustomerService; _userService = userService; } [CheckLogin] public IActionResult Index() { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List actionlist = new List(); 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); ViewData["ActionInfo"] = actionlist; return View(); } [CheckLogin] public IActionResult Add(string id = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; ProjectDTO projectDTO = new ProjectDTO(); if (!String.IsNullOrEmpty(id)) { projectDTO = _projectService.GetLiaotianEntity(id); var intentionCustomerDTOs = _intentionCustomerService.GetList(); if (projectDTO.Projectzhongbiaos!=null && projectDTO.Projectzhongbiaos.Count > 0) { for(int i=0;i< projectDTO.Projectzhongbiaos.Count; i++) { var intt = intentionCustomerDTOs.Count(x=>x.Name == projectDTO.Projectzhongbiaos[i].Names); if (intt > 0) { projectDTO.Projectzhongbiaos[i].ProjectId = "yes"; } } } if (!string.IsNullOrWhiteSpace(projectDTO.Drhx)) { var intt = intentionCustomerDTOs.Count(x => x.Name == projectDTO.Drhx); if (intt > 0) { projectDTO.Drcunzai = "yes"; } } if (!string.IsNullOrWhiteSpace(projectDTO.Dshx)) { var intt = intentionCustomerDTOs.Count(x => x.Name == projectDTO.Dshx); if (intt > 0) { projectDTO.Dscunzai = "yes"; } } if (projectDTO.projectreasons != null && projectDTO.projectreasons.Count > 0) { for (int i = 0; i < projectDTO.projectreasons.Count; i++) { var intt = intentionCustomerDTOs.Count(x => x.Name == projectDTO.projectreasons[i].Reasonname); if (intt > 0) { projectDTO.projectreasons[i].ProjectId = "yes"; } } } if (projectDTO.Projectyouxiaos != null && projectDTO.Projectyouxiaos.Count > 0) { for (int i = 0; i < projectDTO.Projectyouxiaos.Count; i++) { var intt = intentionCustomerDTOs.Count(x => x.Name == projectDTO.Projectyouxiaos[i].Namesyouxiao); if (intt > 0) { projectDTO.Projectyouxiaos[i].ProjectId = "yes"; } } } } else { projectDTO.Sheng = "510000"; projectDTO.City = "510100"; projectDTO.AreaId = "510107"; var Projectreasonlist = new List(); Projectreasonlist.Add(new Projectreason()); projectDTO.projectreasons = Projectreasonlist; var Projectyouxiaolist = new List(); Projectyouxiaolist.Add(new Projectyouxiao()); projectDTO.Projectyouxiaos = Projectyouxiaolist; var Projectzhongbiaoslist = new List(); Projectzhongbiaoslist.Add(new Projectzhongbiao()); projectDTO.Projectzhongbiaos = Projectzhongbiaoslist; projectDTO.StartTime = DateTime.Now; } var zhuanjia = _projectService.Getzhuanjie(); var cgfs = _projectService.GetCgfs(); var sheng = _projectService.Getsheng(); var shi = _projectService.Getshi(projectDTO.Sheng); var quxian = _projectService.Getquxian(projectDTO.City); ViewBag.flbx = _liaotianService.GetSYScode("Project", "flbx"); ViewBag.zhuanjia = zhuanjia; ViewBag.cgfs = cgfs; ViewBag.sheng = sheng; ViewBag.shi = shi; ViewBag.quxian = quxian; ViewData.Model = projectDTO; return View(); } /// /// 获取区县 /// /// 市id /// [CheckLogin] public string getAreaId(string cityid = "") { var quxian = _projectService.Getquxian(cityid); return JsonConvert.SerializeObject(quxian); } /// /// 获取市 /// /// 省id /// /// [CheckLogin] public string getCity(string shengid = "") { var shi = _projectService.Getshi(shengid); return JsonConvert.SerializeObject(shi); } /// /// 保存 /// /// 岗位实体类对象 /// /// [CheckLogin] [HttpPost] public string Save(ProjectDTO data) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; data.RecStatus = "A"; if (String.IsNullOrEmpty(data.Id)) { data.Creater = curentuser.Id; data.Createtime = DateTime.Now; } data.Modifier = curentuser.Id; data.Modifytime = DateTime.Now; ResultEntity resultEntity = _projectService.saveLiaotian(data); return JsonConvert.SerializeObject(resultEntity); } [CheckLogin] public IActionResult Select() { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; List actionlist = new List(); 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); 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(); ViewBag.ShengDropDown = _projectService.Getsheng().Select(x => new { code = x.CodeId, label = x.Name }).ToList(); ViewBag.Creater = _userService.GetList().Select(x => new { code = x.Id, label = x.UserName }).ToList(); return View(); } [CheckLogin] public string GetLiaotianList(ProjectDTOSearch search) { //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); return JsonConvert.SerializeObject(_projectService.SearchByPaging(search)); } /// /// 删除主信息 /// /// 实体 /// /// [CheckLogin] public string Nullify(string Id = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; return JsonConvert.SerializeObject(_projectService.ModifyStatus(Id, curentuser.Id)); } /// /// 获取项目信息 /// /// 项目网址 /// /// public string getProjectxinxi(string address = "") { ProjectDTO projectDTO = new ProjectDTO(); var parser = new HtmlParser(); using (HttpClient client = new HttpClient()) { HttpResponseMessage response = client.GetAsync(address).Result; var res = response.Content.ReadAsStringAsync().Result; var document = parser.ParseDocument(res); var time = document.QuerySelector("p"); if (time != null) { string timestr = time.TextContent; if (timestr.IndexOf("系统发布时间:") >= 0) { timestr = timestr.Replace("系统发布时间:", ""); } projectDTO.StartTimestr = timestr; } var table = document.QuerySelector("table").QuerySelectorAll("tr"); if (table != null) { for (int i = 0; i < table.Length; i++) { var select = table[i].QuerySelector("td"); if (select != null && select.TextContent.IndexOf("项目编号") >= 0) { if (table[i + 1] != null) { var td1 = table[i + 1].QuerySelector("td"); if (td1 != null) { projectDTO.Number = 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 } } } else if (select != null && select.TextContent.IndexOf("中标(成交)信息") >= 0) { projectDTO.Projectzhongbiaos = new List(); if (table[i + 1] != null) { var tds = table[i + 1].QuerySelectorAll("td"); if (tds != null) { if (tds.Length > 1) { string surpliername= table[i + 1].QuerySelectorAll("td")[1].TextContent.Trim();//OuterHtml var surpliernames = surpliername.Split(','); for(int j = 0;j< surpliernames.Length; j++) { var projectzhongbiao = new Projectzhongbiao(); projectzhongbiao.Names = surpliernames[j].Trim(); //if (table[i + 2] != null) //{ // var tds2 = table[i + 2].QuerySelectorAll("td"); // if (tds2 != null) // { // if (tds2.Length > 1) // { // string adress = table[i + 2].QuerySelectorAll("td")[1].TextContent.Trim();//OuterHtml // var adresss = adress.Split(';'); // if (adresss.Length == surpliernames.Length) // { // projectzhongbiao.Names += " " + adresss[j].Trim(); // } // else if (adresss.Length < surpliernames.Length) // { // if (j < adresss.Length) // { // projectzhongbiao.Names += " " + adresss[j].Trim(); // } // else // { // projectzhongbiao.Names += " "; // } // } // else if (adresss.Length % surpliernames.Length == 0) // { // projectzhongbiao.Names += " " + adresss[(j + 1) * (adresss.Length / surpliernames.Length) - 1].Trim(); // } // else // { // projectzhongbiao.Names += " " + adresss[j + (adresss.Length - surpliernames.Length)].Trim(); // } // } // } //} if (table[i + 3] != null) { var tds3 = table[i + 3].QuerySelectorAll("td"); if (tds3 != null) { if (tds3.Length > 1) { string jine = table[i + 3].QuerySelectorAll("td")[1].TextContent.Trim();//OuterHtml var jines = jine.Split(';'); if (jines.Length == surpliernames.Length) { projectzhongbiao.Price = jines[j].Trim().Replace("中标金额","").Replace(":", "").Replace(":", "");//OuterHtml } else if (jines.Length < surpliernames.Length) { if (j < jines.Length) { projectzhongbiao.Price = jines[j].Trim().Replace("中标金额", "").Replace(":", "").Replace(":", ""); } else { projectzhongbiao.Price = " "; } } else { if (j == 0) { projectzhongbiao.Price = jine.Trim().Replace("中标金额", "").Replace(":", "").Replace(":", ""); } else { projectzhongbiao.Price = jines[j + (jines.Length - surpliernames.Length)].Trim().Replace("中标金额", "").Replace(":", "").Replace(":", ""); } } } } } projectDTO.Projectzhongbiaos.Add(projectzhongbiao); } } } } } else if (select != null && select.TextContent.IndexOf("评审专家") >= 0) { if (table[i + 1] != null) { var td1 = table[i + 1].QuerySelector("td"); if (td1 != null) { string ssss = table[i + 1].QuerySelector("td").TextContent.Trim(); ssss = ssss.Replace("(组长)", "").Replace("(组长)", "").Replace(",", "、").Replace("(评审组长)", "").Replace("(评审组长)", "").Replace(";", "、").Replace("评审组长:", "").Replace("组长:", "").Replace("组员:",""); projectDTO.Zhuanjia = ssss;//OuterHtml } } } else if (table[i] != null && table[i].TextContent.IndexOf("采购人信息") >= 0) { //StringBuilder remark = new StringBuilder(); // remark.Append("采购人信息:"); if (table[i + 1] != null) { var tds = table[i + 1].QuerySelectorAll("td"); if (tds != null) { // remark.Append(table[i + 1].QuerySelectorAll("td")[0].TextContent.Trim());//OuterHtml) if (tds.Length > 1) { // remark.Append(table[i + 1].QuerySelectorAll("td")[1].TextContent.Trim());//OuterHtml) projectDTO.Caigourenname = table[i + 1].QuerySelectorAll("td")[1].TextContent.Trim(); } } // remark.Append(" "); } if (table[i + 2] != null) { var tds = table[i + 2].QuerySelectorAll("td"); if (tds != null) { // remark.Append(table[i + 2].QuerySelectorAll("td")[0].TextContent.Trim());//OuterHtml) if (tds.Length > 1) { // remark.Append(table[i + 2].QuerySelectorAll("td")[1].TextContent.Trim());//OuterHtml) projectDTO.Caigourenaddress = table[i + 2].QuerySelectorAll("td")[1].TextContent.Trim(); } } // remark.Append(" "); } if (table[i + 3] != null) { var tds = table[i + 3].QuerySelectorAll("td"); if (tds != null) { // remark.Append(table[i + 3].QuerySelectorAll("td")[0].TextContent.Trim());//OuterHtml) if (tds.Length > 1) { // remark.Append(table[i + 3].QuerySelectorAll("td")[1].TextContent.Trim());//OuterHtml) projectDTO.Caigourencontact = table[i + 3].QuerySelectorAll("td")[1].TextContent.Trim(); } } // remark.Append(" "); } // remark.Append(" \n"); // projectDTO.Remark = remark.ToString(); } else if (table[i] != null && table[i].TextContent.IndexOf("采购代理机构信息") >= 0) { // StringBuilder remark = new StringBuilder(); // remark.Append("采购代理机构信息:"); if (table[i + 1] != null) { var tds = table[i + 1].QuerySelectorAll("td"); if (tds != null) { // remark.Append(table[i + 1].QuerySelectorAll("td")[0].TextContent.Trim());//OuterHtml) if (tds.Length > 1) { // remark.Append(table[i + 1].QuerySelectorAll("td")[1].TextContent.Trim());//OuterHtml) projectDTO.Dailiname = table[i + 1].QuerySelectorAll("td")[1].TextContent.Trim(); } // remark.Append(" "); } } if (table[i + 2] != null) { var tds = table[i + 2].QuerySelectorAll("td"); if (tds != null) { // remark.Append(table[i + 2].QuerySelectorAll("td")[0].TextContent.Trim());//OuterHtml) if (tds.Length > 1) { // remark.Append(table[i + 2].QuerySelectorAll("td")[1].TextContent.Trim());//OuterHtml) projectDTO.Dailiaddress = table[i + 2].QuerySelectorAll("td")[1].TextContent.Trim(); } } // remark.Append(" "); } if (table[i + 3] != null) { var tds = table[i + 3].QuerySelectorAll("td"); if (tds != null) { //remark.Append(table[i + 3].QuerySelectorAll("td")[0].TextContent.Trim());//OuterHtml) if (tds.Length > 1) { // remark.Append(table[i + 3].QuerySelectorAll("td")[1].TextContent.Trim());//OuterHtml) projectDTO.Dailicontact = table[i + 3].QuerySelectorAll("td")[1].TextContent.Trim(); } } //remark.Append(" "); } // remark.Append(" \n"); //if (string.IsNullOrEmpty(projectDTO.Remark)) //{ // projectDTO.Remark = remark.ToString(); //} //else //{ // projectDTO.Remark += remark.ToString(); //} } } } return JsonConvert.SerializeObject(projectDTO); } } } }