/* *所有关于dt_pattern类的业务代ç 应在æ¤å¤„编写 *å¯ä½¿ç”¨repository.调用常用方法,获å–EF/Dapperç‰ä¿¡æ¯ *如果需è¦äº‹åŠ¡è¯·ä½¿ç”¨repository.DbContextBeginTransaction *也å¯ä½¿ç”¨DBServerProvider.æ‰‹åŠ¨èŽ·å–æ•°æ®åº“ç›¸å…³ä¿¡æ¯ *用户信æ¯ã€æƒé™ã€è§’色ç‰ä½¿ç”¨UserContext.Currentæ“作 *dt_patternService对增ã€åˆ ã€æ”¹æŸ¥ã€å¯¼å…¥ã€å¯¼å‡ºã€å®¡æ ¸ä¸šåŠ¡ä»£ç æ‰©å±•å‚ç…§ServiceFunFilter */ using WIDESEA_Core.BaseProvider; using WIDESEA_Core.Extensions.AutofacManager; using WIDESEA_Entity.DomainModels; using System.Linq; using WIDESEA_Core.Utilities; using System.Linq.Expressions; using WIDESEA_Core.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Http; using WIDESEA_WCS.IRepositories; using Microsoft.AspNetCore.Mvc.RazorPages; using Newtonsoft.Json; using WIDESEA_Core.EFDbContext; using WIDESEA_WCS.Repositories; using WIDESEA_Comm; using WIDESEA_WCS.WCSClient; using System.Xml.Linq; using OfficeOpenXml.FormulaParsing.Excel.Functions.Math; namespace WIDESEA_WCS.Services { public partial class dt_patternService { private readonly IHttpContextAccessor _httpContextAccessor; private readonly Idt_patternRepository _repository;//访问数æ®åº“ [ActivatorUtilitiesConstructor] public dt_patternService( Idt_patternRepository dbRepository, IHttpContextAccessor httpContextAccessor ) : base(dbRepository) { _httpContextAccessor = httpContextAccessor; _repository = dbRepository; //多租户会用到这init代ç ,其他情况å¯ä»¥ä¸ç”¨ //base.Init(dbRepository); } /// <summary> /// 模å¼1 /// </summary> /// <param name="v"></param> /// <returns></returns> public WebResponseContent UpdateAuto(string v) { WebResponseContent content = new WebResponseContent(); try { var model = JsonConvert.DeserializeObject<dt_pattern>(v); if (model.pattern_state == 1) throw new Exception("当å‰å°±æ˜¯æ¨¡å¼1"); var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "æ¡æž¶"); if (Gantry_client == null) throw new Exception("æ¡æž¶è°ƒåº¦æœåŠ¡æœªå¼€å¯ï¼"); if (!Gantry_client.IsConnected) throw new Exception("ä¸Žæ¡æž¶è¿žæŽ¥è¶…æ—¶ï¼"); VOLContext context = new VOLContext(); Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList(); if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any()) throw new Exception("设置为模å¼1失败ï¼ä¸‹æ–™ä½å˜åœ¨è½¦è½®ï¼"); #region 写入信å·å‘Šè¯‰æ¡æž¶åˆ‡æ¢æ¨¡å¼ var ok = Gantry_client.ReadByOrder<bool>("o_enable_change_mode", model.pattern_name); #endregion if (ok) { Gantry_client.WriteByOrder("i_mode", (Int16)1, model.pattern_name); model.pattern_state = 1; var cont = _repository.Update(model, true); if (cont > 0) content.OK(model.pattern_name + "设置为模å¼1æˆåŠŸï¼"); else throw new Exception(model.pattern_name + "设置为模å¼2失败ï¼"); foreach (var stat in stations) { stat.enable = true; } stationinfoRepository.UpdateRange(stations, x => new { x.enable }, true); } else content.Error(model.pattern_name + "设置为模å¼1å¤±è´¥ï¼æ¡æž¶æœªå…许设置为模å¼1"); } catch (Exception ex) { content.Error(ex.Message); } return content; } /// <summary> /// 模å¼2 /// </summary> /// <param name="v"></param> /// <returns></returns> public WebResponseContent UpdateManual(string v) { WebResponseContent content = new WebResponseContent(); try { var model = JsonConvert.DeserializeObject<dt_pattern>(v); if (model.pattern_state == 0) throw new Exception("当å‰å°±æ˜¯æ¨¡å¼2"); var Gantry_client = PLCClient.Clients.FirstOrDefault(t => t.PLCName == "æ¡æž¶"); if (Gantry_client == null) throw new Exception("æ¡æž¶è°ƒåº¦æœåŠ¡æœªå¼€å¯ï¼"); if (!Gantry_client.IsConnected) throw new Exception("ä¸Žæ¡æž¶è¿žæŽ¥è¶…æ—¶ï¼"); VOLContext context = new VOLContext(); Idt_stationinfoRepository stationinfoRepository = new dt_stationinfoRepository(context); var stations = stationinfoRepository.Find(x => x.stationCode == "X01001001" || x.stationCode == "X01001002" || x.stationCode == "X02001001" || x.stationCode == "X02001002").ToList(); if (stations.Where(x => x.tray_status == TrayStateEnum.StrogeTray.ToString()).Any()) throw new Exception("设置为模å¼2失败ï¼ä¸‹æ–™ä½å˜åœ¨è½¦è½®ï¼"); #region 写入信å·å‘Šè¯‰æ¡æž¶åˆ‡æ¢æ¨¡å¼ var ok = Gantry_client.ReadByOrder<bool>("o_enable_change_mode", model.pattern_name); #endregion if (ok) { Gantry_client.WriteByOrder("i_mode", (Int16)2, model.pattern_name); model.pattern_state = 0; var cont = _repository.Update(model, true); if (cont > 0) content.OK(model.pattern_name + "设置为模å¼2æˆåŠŸï¼"); else throw new Exception(model.pattern_name + "设置为模å¼2失败ï¼"); foreach (var stat in stations) { stat.enable = false; } stationinfoRepository.UpdateRange(stations, x => new { x.enable }, true); } else content.Error(model.pattern_name + "设置为模å¼2å¤±è´¥ï¼æ¡æž¶æœªå…许设置为模å¼2"); } catch (Exception ex) { content.Error(ex.Message); } return content; } } }