username@email.com
2023-11-02 558dae4a18d393ac38daa43a354e8bc9a22e4e26
zhengcaioa/zhengcaioa/Controllers/BusinessOrder/OrderBanciController.cs
@@ -17,6 +17,8 @@
using zhengcaioa.IService;
using CommonToolsCore;
using Services;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json.Linq;
namespace zhengcaioa.Controllers.BusinessOrder
{
@@ -27,14 +29,22 @@
        private readonly ILiaotianService _liaotianService;
        private readonly IOrderBanciService _orderBanciService;
        private readonly IOrderBanciDtlService _orderBanciDtlService;
        private readonly IPltPageService _pltPageService;
        private readonly IConfiguration _configuration;
        private readonly IHttpClientFactory _clientFactory;
        public OrderBanciController(ILogger<OrderBanciController> logger, ILiaotianService liaotianService, IOrderBanciService orderBanciService, IOrderBanciDtlService orderBanciDtlService)
        public OrderBanciController(ILogger<OrderBanciController> logger, ILiaotianService liaotianService, IOrderBanciService orderBanciService, IOrderBanciDtlService orderBanciDtlService
             , IPltPageService pltPageService
              , IConfiguration configuration
             , IHttpClientFactory clientFactory)
        {
            _logger = logger;
            _liaotianService = liaotianService;
            _orderBanciService = orderBanciService;
            _orderBanciDtlService = orderBanciDtlService;
            _pltPageService = pltPageService;
            _configuration = configuration;
            _clientFactory = clientFactory;
        }
        [CheckLogin]
@@ -50,18 +60,34 @@
            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);
            //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();
@@ -77,7 +103,9 @@
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(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))
            {
@@ -111,6 +139,221 @@
            ViewData.Model = dto;
            return View();
        }
        //后台留座
        [CheckLogin]
        public async Task<IActionResult> LiuzuoAsync(string id = null)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(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<LockUser> lockUsers = JsonConvert.DeserializeObject<List<LockUser>>(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<List<OrderBanciZuoweiDTO>>();
                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();
        }
        /// <summary>
        /// 保存留作信息
        /// </summary>
        /// <param name="data">岗位实体类对象</param>
        /// <returns></returns>
        ///
        [CheckLogin]
        [HttpPost]
        public async Task<IActionResult> SaveLiuzuoAsync(OrderBanciDTO data)
        {
            var curentuser = JsonConvert.DeserializeObject<PltUser>(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<LockUser> lockUsers = JsonConvert.DeserializeObject<List<LockUser>>(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);
        }
@@ -214,7 +457,7 @@
            ViewData["shangxiawu"] = _liaotianService.GetSYScode("order_banci_dtl", "shangxiawu");
            ViewData["shangxiawu"] = _liaotianService.GetSYScode("order_banci_order", "kechengleixing_id");
@@ -321,7 +564,7 @@
        }
        public IActionResult GetBanciAll(string id)
        public async Task<IActionResult> GetBanciAllAsync(string id)
        {
            ReturnMsg<OrderBanciDTO> returnMsg = new ReturnMsg<OrderBanciDTO>();
            returnMsg.code = 2;
@@ -334,10 +577,92 @@
                    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);
                returnMsg.code = 1;
                returnMsg.count = 1;
                returnMsg.returnObj = orderBanciDTO;
                            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<LockUser> lockUsers = JsonConvert.DeserializeObject<List<LockUser>>(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<List<OrderBanciZuoweiDTO>>();
                        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)
            {
@@ -351,5 +676,39 @@
          
        }
        //获取当前的培训
        public IActionResult GetJifenBanciList()
        {
            ReturnMsg<List<OrderBanciDTO>> returnMsg = new ReturnMsg<List<OrderBanciDTO>>();
            returnMsg.code = 2;
            try
            {
                List<OrderBanciDTO> 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);
        }
    }
}