using System; using System.Collections.Generic; using System.Linq; using System.Text; using AutoMapper; 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.Net.Http; using System.Threading.Tasks; using zhengcaioa.Models; using zhengcaioa.IService; using CommonToolsCore; using Services; using Microsoft.Extensions.Configuration; using Newtonsoft.Json.Linq; namespace zhengcaioa.Controllers.BusinessOrder { public class OrderBanciController : Controller { private readonly ILogger _logger; private readonly ILiaotianService _liaotianService; private readonly IOrderBanciService _orderBanciService; private readonly IOrderBanciDtlService _orderBanciDtlService; private readonly IPltPageService _pltPageService; private readonly IConfiguration _configuration; private readonly IHttpClientFactory _clientFactory; private readonly IExpertService _expertService; public OrderBanciController(ILogger logger, ILiaotianService liaotianService, IOrderBanciService orderBanciService, IOrderBanciDtlService orderBanciDtlService , IPltPageService pltPageService , IConfiguration configuration , IHttpClientFactory clientFactory , IExpertService expertService ) { _logger = logger; _liaotianService = liaotianService; _orderBanciService = orderBanciService; _orderBanciDtlService = orderBanciDtlService; _pltPageService = pltPageService; _configuration = configuration; _clientFactory = clientFactory; _expertService = expertService; } [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); var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/OrderBanci/Index/"); var pageEntities1 = pageEntities.Where(x => x.PageMethod == "01").ToList(); var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList(); 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; ViewData["ActionInfo2"] = pageEntities2; return View(); } [CheckLogin] public IActionResult GetList(OrderBanciDTOSearch search) { //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); return new JsonResult(_orderBanciService.SearchByPaging(search)); } [CheckLogin] public IActionResult Edit(string id = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/OrderBanci/Index/"); var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList(); ViewData["ActionInfo2"] = pageEntities2; OrderBanciDTO dto = new OrderBanciDTO(); if (!String.IsNullOrEmpty(id)) { dto = _orderBanciService.Get(id); if (dto.Shijian.HasValue) { dto.ShijianName = dto.Shijian.Value.ToString("yyyy-MM-dd HH:mm"); } if (dto.Shijianend.HasValue) { dto.ShijianendName = dto.Shijianend.Value.ToString("yyyy-MM-dd HH:mm"); } } else { dto.Shijian = DateTime.Now; dto.ShijianName = dto.Shijian.Value.ToString("yyyy-MM-dd HH:mm"); dto.Shijianend = DateTime.Now; dto.ShijianendName = dto.Shijianend.Value.ToString("yyyy-MM-dd HH:mm"); } ViewData.Model = dto; return View(); } //后台留座 [CheckLogin] public async Task LiuzuoAsync(string id = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; //var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/OrderBanci/Index/"); //var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList(); //ViewData["ActionInfo2"] = pageEntities2; var orderBanciDTO = _orderBanciService.Get(id); if (orderBanciDTO.Hang.HasValue && orderBanciDTO.Lie.HasValue) { //查询座位信息 var orderBanciZuoweiDTOs = _orderBanciService.GetOrderBanciZuoweiList(orderBanciDTO.Id); try { string huiyuanurl = _configuration.GetSection("huiyuanurl").Value; string GetTrainingCoursesLockIDSeatId = _configuration.GetSection("GetTrainingCoursesLockIDSeatId").Value; string url = huiyuanurl + GetTrainingCoursesLockIDSeatId + "?ClassID=" + orderBanciDTO.id; Uri postUrl2 = new Uri(url); string result2 = string.Empty; var httpClient2 = _clientFactory.CreateClient(); httpClient2.Timeout = new TimeSpan(0, 0, 10); var Result2 = await httpClient2.GetAsync(postUrl2); result2 = Result2.Content.ReadAsStringAsync().Result; _logger.LogInformation("result2:" + result2); JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2); if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1") { List lockUsers = JsonConvert.DeserializeObject>(jobjectresult["data"].ToString()); foreach (var orderBanciZuoweiDTO in orderBanciZuoweiDTOs) { foreach (var lockUser in lockUsers) { if (orderBanciZuoweiDTO.ZuoweiId == lockUser.ID) { orderBanciZuoweiDTO.Status = "1"; break; } } } } } catch (Exception ex) { } var orderBanciZuoweiDTOsret = new List>(); for (int i = 0; i < orderBanciDTO.Hang; i++) { var orderBanciZuoweiDTOs1 = orderBanciZuoweiDTOs.Where(x => x.RowNo == (i + 1)).ToList(); orderBanciZuoweiDTOsret.Add(orderBanciZuoweiDTOs1); } //查询被用户锁定的座位 orderBanciDTO.orderBanciZuoweiDTOs = orderBanciZuoweiDTOsret; } ViewData.Model = orderBanciDTO; return View(); } /// /// 保存留作信息 /// /// 岗位实体类对象 /// /// [CheckLogin] [HttpPost] public async Task SaveLiuzuoAsync(OrderBanciDTO data) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; ResultEntity resultEntity = new ResultEntity(); resultEntity.Result = true; var orderBanciZuoweiDTOs = _orderBanciService.GetOrderBanciZuoweiList(data.Id); if (data.SeatID!=null&& data.SeatID.Length > 0) { //查询被用户锁定的座位 try { string huiyuanurl = _configuration.GetSection("huiyuanurl").Value; string GetTrainingCoursesLockIDSeatId = _configuration.GetSection("GetTrainingCoursesLockIDSeatId").Value; string url = huiyuanurl + GetTrainingCoursesLockIDSeatId + "?ClassID=" + data.Id; Uri postUrl2 = new Uri(url); string result2 = string.Empty; var httpClient2 = _clientFactory.CreateClient(); httpClient2.Timeout = new TimeSpan(0, 0, 10); var Result2 = await httpClient2.GetAsync(postUrl2); result2 = Result2.Content.ReadAsStringAsync().Result; _logger.LogInformation("result2:" + result2); JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2); if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1") { List lockUsers = JsonConvert.DeserializeObject>(jobjectresult["data"].ToString()); foreach (var SeatID in data.SeatID) { foreach (var lockUser in lockUsers) { if (SeatID == lockUser.ID) { resultEntity = new ResultEntity(); resultEntity.Result = false; resultEntity.Message = lockUser.Name + "座位已经被客户选中!无法预留"; return new JsonResult(resultEntity); } } } } } catch (Exception ex) { } foreach (var seat in data.SeatID) { var orderBanciZuoweiDTO = orderBanciZuoweiDTOs.Where(x => x.ZuoweiId == seat).FirstOrDefault(); if(orderBanciZuoweiDTO.Status == "1") { resultEntity = new ResultEntity(); resultEntity.Result = false; resultEntity.Message = orderBanciZuoweiDTO.SeatNo +"座位已经被客户选中!无法预留"; return new JsonResult(resultEntity); } else if (orderBanciZuoweiDTO.Status == "0") { orderBanciZuoweiDTO.Status = "2"; orderBanciZuoweiDTO.Modifier = curentuser.Id; orderBanciZuoweiDTO.Modifytime = DateTime.Now; resultEntity = _orderBanciService.saveZuowei(orderBanciZuoweiDTO); } } var delete = orderBanciZuoweiDTOs.Where(x => !data.SeatID.Contains(x.ZuoweiId)).ToList(); if (delete != null && delete.Count > 0) { foreach (var orderBanciZuoweiDTO in delete) { if (orderBanciZuoweiDTO.Status == "2") { orderBanciZuoweiDTO.Status = "0"; orderBanciZuoweiDTO.Modifier = curentuser.Id; orderBanciZuoweiDTO.Modifytime = DateTime.Now; resultEntity = _orderBanciService.saveZuowei(orderBanciZuoweiDTO); } } } } else { foreach (var orderBanciZuoweiDTO in orderBanciZuoweiDTOs) { if (orderBanciZuoweiDTO.Status == "2") { orderBanciZuoweiDTO.Status = "0"; orderBanciZuoweiDTO.Modifier = curentuser.Id; orderBanciZuoweiDTO.Modifytime = DateTime.Now; resultEntity = _orderBanciService.saveZuowei(orderBanciZuoweiDTO); } } } return new JsonResult(resultEntity); } /// /// 保存 /// /// 岗位实体类对象 /// /// [CheckLogin] [HttpPost] public IActionResult Save(OrderBanciDTO 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 = _orderBanciService.save(data); return new JsonResult(resultEntity); } /// /// 删除主信息 /// /// 实体 /// /// [CheckLogin] public IActionResult Nullify(string Id = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; return new JsonResult(_orderBanciService.ModifyStatus(Id, curentuser.Id)); } [CheckLogin] public IActionResult IndexDtl(string OrderBanciId) { 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.OrderBanciId = OrderBanciId; return View(); } [CheckLogin] public IActionResult GetListDtl(OrderBanciDtlDTOSearch search) { //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); return new JsonResult(_orderBanciDtlService.SearchByPaging(search)); } [CheckLogin] public IActionResult EditDtl(string id = null,string OrderBanciId = null) { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; OrderBanciDtlDTO dto = new OrderBanciDtlDTO(); if (!String.IsNullOrEmpty(id)) { dto = _orderBanciDtlService.Get(id); } else { dto.OrderBanciId = OrderBanciId; } ViewData["shangxiawu"] = _liaotianService.GetSYScode("order_banci_order", "kechengleixing_id"); ViewData.Model = dto; return View(); } /// /// 保存 /// /// 岗位实体类对象 /// /// [CheckLogin] [HttpPost] public IActionResult SaveDtl(OrderBanciDtlDTO 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 = _orderBanciDtlService.save(data); return new JsonResult(resultEntity); } /// /// 删除主信息 /// /// 实体 /// /// [CheckLogin] public IActionResult NullifyDtl(string Id = "") { var curentuser = JsonConvert.DeserializeObject(HttpContext.Session.GetString("User")); ViewData["curentuser"] = curentuser; return new JsonResult(_orderBanciDtlService.ModifyStatus(Id, curentuser.Id)); } //获取当前的培训 public IActionResult GetBanCi() { ReturnMsg returnMsg = new ReturnMsg(); returnMsg.code = 2; try { OrderBanciDTOSearch search = new OrderBanciDTOSearch(); search.page = 1; search.rows = 1000; search.Createtime = DateTime.Now.Date.ToString(); ResultDataEntity < OrderBanciDTO > resultDataEntity = _orderBanciService.SearchByPaging(search); var ssss = resultDataEntity.DataList.OrderBy(x=>x.Shijian).FirstOrDefault(); if (ssss != null) { var sysCodeDtls = _liaotianService.GetSYScode("order_banci_dtl", "shangxiawu"); List orderBanciDtlDTOs = _orderBanciDtlService.GetList(ssss.Id); if(orderBanciDtlDTOs!=null&& orderBanciDtlDTOs.Count > 0) { foreach (var orderBanciDtlDTO in orderBanciDtlDTOs) { var sysCodeDtl = sysCodeDtls.Where(x => x.CodeSn == orderBanciDtlDTO.Shangxiawu).FirstOrDefault(); if (sysCodeDtl != null) { orderBanciDtlDTO.ShangxiawuName = sysCodeDtl.Comments; } } } ssss.orderBanciDtlDTOs = orderBanciDtlDTOs; returnMsg.code = 1; returnMsg.count = 1; returnMsg.returnObj = ssss; } } catch (Exception ex) { returnMsg.code = 2; returnMsg.error = "没有获取到token"; returnMsg.count = 0; } return new JsonResult(returnMsg); } public async Task GetBanciAllAsync(string id) { ReturnMsg returnMsg = new ReturnMsg(); returnMsg.code = 2; try { var orderBanciDTO = _orderBanciService.GetAll(id); if (orderBanciDTO==null) { returnMsg.code = 2; returnMsg.error = "没有查询到班次"; returnMsg.count = 0; } else { OrderBanciDtlDTOSearch searchEntity = new OrderBanciDtlDTOSearch(); searchEntity.page = 1; searchEntity.rows = 1000; searchEntity.OrderBanciId = id; orderBanciDTO.orderBanciDtlDTOs = _orderBanciDtlService.SearchByPaging(searchEntity).DataList; if(orderBanciDTO.Hang.HasValue && orderBanciDTO.Lie.HasValue) { //查询座位信息 var orderBanciZuoweiDTOs = _orderBanciService.GetOrderBanciZuoweiList(orderBanciDTO.id); //查询被用户锁定的座位 try { string huiyuanurl = _configuration.GetSection("huiyuanurl").Value; string GetTrainingCoursesLockIDSeatId = _configuration.GetSection("GetTrainingCoursesLockIDSeatId").Value; string url = huiyuanurl + GetTrainingCoursesLockIDSeatId + "?ClassID=" + orderBanciDTO.id; Uri postUrl2 = new Uri(url); string result2 = string.Empty; var httpClient2 = _clientFactory.CreateClient(); httpClient2.Timeout = new TimeSpan(0, 0, 10); var Result2 = await httpClient2.GetAsync(postUrl2); result2 = Result2.Content.ReadAsStringAsync().Result; _logger.LogInformation("result2:" + result2); JObject jobjectresult = (JObject)JsonConvert.DeserializeObject(result2); if (jobjectresult["code"] != null && jobjectresult["code"].ToString() == "1") { List lockUsers = JsonConvert.DeserializeObject>(jobjectresult["data"].ToString()); foreach (var orderBanciZuoweiDTO in orderBanciZuoweiDTOs) { foreach(var lockUser in lockUsers) { if(orderBanciZuoweiDTO.ZuoweiId == lockUser.ID) { orderBanciZuoweiDTO.Status = "1"; break; } } } } } catch (Exception ex) { } var orderBanciZuoweiDTOsret = new List>(); for (int i = 0; i < orderBanciDTO.Hang; i++) { var orderBanciZuoweiDTOs1 = orderBanciZuoweiDTOs.Where(x => x.RowNo == (i + 1)).ToList(); orderBanciZuoweiDTOsret.Add(orderBanciZuoweiDTOs1); } orderBanciDTO.orderBanciZuoweiDTOs = orderBanciZuoweiDTOsret; } returnMsg.code = 1; returnMsg.count = 1; returnMsg.returnObj = orderBanciDTO; } } catch (Exception ex) { returnMsg.code = 2; returnMsg.error = "没有获取到token"; returnMsg.count = 0; } return new JsonResult(returnMsg); } //获取当前的培训 public IActionResult GetJifenBanciList() { ReturnMsg> returnMsg = new ReturnMsg>(); returnMsg.code = 2; try { List orderBanciDTOs = _orderBanciService.GetJifenBanciList(); returnMsg.code = 1; returnMsg.count = orderBanciDTOs.Count; returnMsg.returnObj = orderBanciDTOs; } catch (Exception ex) { returnMsg.code = 2; returnMsg.error = "没有获取到token"; returnMsg.count = 0; } return new JsonResult(returnMsg); } //获取当前的培训 public IActionResult GetDangQianBanciList(string id) { ReturnMsg> returnMsg = new ReturnMsg>(); returnMsg.code = 2; try { List orderBanciDTOs = _orderBanciService.GetDangQianBanciList(id); List banciFanhuis = new List(); if (orderBanciDTOs != null && orderBanciDTOs.Count > 0) { foreach (var orderBanciDTO in orderBanciDTOs) { BanciFanhui banciFanhui = new BanciFanhui(); banciFanhui.name = orderBanciDTO.Shijian.HasValue ? orderBanciDTO.Shijian.Value.ToString("yyyy-MM-dd") : ""; banciFanhui.value = orderBanciDTO.Id; banciFanhuis.Add(banciFanhui); } } returnMsg.code = 1; returnMsg.count = orderBanciDTOs.Count; returnMsg.returnObj = banciFanhuis; } catch (Exception ex) { returnMsg.code = 2; returnMsg.error = "没有获取到token"; returnMsg.count = 0; } return new JsonResult(returnMsg); } [CheckLogin] public IActionResult IndexHezuo() { 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); //var pageEntities = _pltPageService.GetUserPage(curentuser.Id, "/OrderBanci/Index/"); //var pageEntities1 = pageEntities.Where(x => x.PageMethod == "01").ToList(); //var pageEntities2 = pageEntities.Where(x => x.PageMethod == "02").ToList(); //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; //ViewData["ActionInfo2"] = pageEntities2; return View(); } public IActionResult GetListHezuo(ExpertDTOSearch search) { //JsonResult jsonResult = new JsonResult(_liaotianService.SearchByPaging(search), new Newtonsoft.Json.Serialization.DefaultContractResolver()); return new JsonResult(_expertService.SearchByPaging(search)); } } }