| | |
| | | using System; |
| | | using Autofac.Core; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Common.PLCEnum; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | using WIDESEAWCS_Model.Models; |
| | | using WIDESEAWCS_QuartzJob; |
| | | |
| | | namespace WIDESEAWCS_BasicInfoService |
| | | { |
| | | public class ScanStationService : ServiceBase<Dt_ScanStation, IRepository<Dt_ScanStation>>, IScanStationService |
| | | { |
| | | public ScanStationService(IRepository<Dt_ScanStation> BaseDal) : base(BaseDal) |
| | | private readonly IFormulaService _formulaService; |
| | | private readonly IFormulaDetailService _formulaDetailService; |
| | | |
| | | public ScanStationService(IRepository<Dt_ScanStation> BaseDal, |
| | | IFormulaService formulaService, |
| | | IFormulaDetailService formulaDetailService |
| | | ) : base(BaseDal) |
| | | { |
| | | _formulaService = formulaService; |
| | | _formulaDetailService = formulaDetailService; |
| | | } |
| | | |
| | | public IRepository<Dt_ScanStation> Repository => BaseDal; |
| | | |
| | | |
| | | /// <summary> |
| | | /// å¯å¨PLC |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | /// <summary> |
| | | public WebResponseContent StartPLC(bool isStop) |
| | | { |
| | | try |
| | | { |
| | | OtherDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceName == "主æ§PLC") as OtherDevice; |
| | | if (device == null) throw new Exception("æªæ¾å°ä¸»æ§PLC设å¤ä¿¡æ¯"); |
| | | if (!device.IsConnected) throw new Exception($"主æ§PLC设å¤é讯å¼å¸¸"); |
| | | if (isStop) |
| | | { |
| | | device.SetValue(W_PLCDBName.wboolAutoStart, false); |
| | | //æåä¿¡å· |
| | | device.SetValue(W_PLCDBName.wboolAutoPause, false); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | var Heart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolHeart); |
| | | var EMG = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolEMG); |
| | | var OnlineExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolOnlineExecuting); |
| | | var Error = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolError); |
| | | |
| | | if (Heart && !EMG && OnlineExecuting && !Error) |
| | | { |
| | | device.SetValue(W_PLCDBName.wboolAutoStart, true); |
| | | //æåä¿¡å· |
| | | device.SetValue(W_PLCDBName.wboolAutoPause, false); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | |
| | | return WebResponseContent.Instance.Error("设å¤ä¸æ¯å¨çº¿ç¶æ"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æå/æ¢å¤PLCï¼ååæ§å¶ï¼ |
| | | /// </summary> |
| | | /// <param name="isPause">æ¯å¦ä¸ºæåæä½ï¼true=æåï¼false=æ¢å¤</param> |
| | | /// <returns>ç»ä¸æ ¼å¼çååºç»æ</returns> |
| | | public WebResponseContent PausePLC(bool isPause) |
| | | { |
| | | try |
| | | { |
| | | OtherDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceName == "主æ§PLC") as OtherDevice; |
| | | if (device == null) throw new Exception("æªæ¾å°ä¸»æ§PLC设å¤ä¿¡æ¯"); |
| | | if (!device.IsConnected) throw new Exception($"主æ§PLC设å¤é讯å¼å¸¸"); |
| | | |
| | | var Heart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolHeart); |
| | | var EMG = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolEMG); |
| | | var Error = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolError); |
| | | if(!device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolAutoStart)) |
| | | { |
| | | return WebResponseContent.Instance.Error("è®¾å¤æªå¯å¨"); |
| | | } |
| | | |
| | | if (!Heart || EMG || Error) |
| | | { |
| | | return WebResponseContent.Instance.Error("设å¤ç¶æå¼å¸¸ï¼æ æ³æ§è¡æå/æ¢å¤æä½"); |
| | | } |
| | | device.SetValue(W_PLCDBName.wboolAutoPause, isPause); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// è¿åä¿¡å· |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | /// <exception cref="Exception"></exception> |
| | | public WebResponseContent GetSignalStates() |
| | | { |
| | | OtherDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceName == "主æ§PLC") as OtherDevice; |
| | | if (device == null) throw new Exception("æªæ¾å°ä¸»æ§PLC设å¤ä¿¡æ¯"); |
| | | if (!device.IsConnected) throw new Exception($"主æ§PLC设å¤é讯å¼å¸¸"); |
| | | |
| | | //è·åä¿¡å·ç¯ç¶æ |
| | | var Heart = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolHeart); |
| | | var EMG = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolEMG); |
| | | var AutoExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolAutoExecuting); |
| | | var OnlineExecuting = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolOnlineExecuting); |
| | | var Error = device.GetValue<R_PLCDBName, bool>(R_PLCDBName.rboolError); |
| | | |
| | | //è·åå¯å¨æåç¶æ |
| | | var IsStarted = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolAutoStart); |
| | | var IsPaused = device.GetValue<W_PLCDBName, bool>(W_PLCDBName.wboolAutoPause); |
| | | |
| | | //è¿å对象 |
| | | var responseData = new |
| | | { |
| | | // ä¿¡å·ç¯ç¶ææ°ç»ï¼ä¿æåæé¡ºåºï¼ |
| | | signalStates = new bool[] { Heart, EMG, AutoExecuting, OnlineExecuting, Error }, |
| | | // PLCå¯å¨/æåç¶æå¯¹è±¡ |
| | | plcStatus = new |
| | | { |
| | | isStarted = IsStarted, |
| | | isPaused = IsPaused |
| | | } |
| | | }; |
| | | return WebResponseContent.Instance.OK(data: responseData); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åæåä¿¡æ¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetLeftInitialData() |
| | | { |
| | | try |
| | | { |
| | | Dt_ScanStation dt_ScanStation = BaseDal.QueryFirst(x => x.StationCode == "001"); |
| | | if (dt_ScanStation == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°å·¥ä½ç¼ç 为001çå·¥ä½ä¿¡æ¯"); |
| | | } |
| | | Dt_Formula dt_Formula = _formulaService.Repository.QueryFirst(x => x.ProductCode == dt_ScanStation.StationEndProduct); |
| | | if (dt_Formula == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°æåç¼å·ã{dt_ScanStation.StationEndProduct}ã对åºçé
æ¹ä¿¡æ¯"); |
| | | } |
| | | List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == dt_Formula.Id); |
| | | |
| | | var responseData = new |
| | | { |
| | | finishedProductId = dt_Formula.Id, |
| | | finishedProduct = dt_Formula.ProductCode, |
| | | leftPartCodes = new List<string>(), |
| | | leftPartIds = new List<int>(), |
| | | leftPartChecked = new List<int>() |
| | | }; |
| | | |
| | | foreach (var detail in dt_FormulaDetails.Take(10)) |
| | | { |
| | | responseData.leftPartCodes.Add(detail.ComponentCode ?? ""); |
| | | responseData.leftPartIds.Add(detail.Id); |
| | | responseData.leftPartChecked.Add(detail.IsScanned); |
| | | } |
| | | |
| | | int needFillCount = 10 - responseData.leftPartCodes.Count; |
| | | for (int i = 0; i < needFillCount; i++) |
| | | { |
| | | responseData.leftPartCodes.Add(""); |
| | | responseData.leftPartIds.Add(0); |
| | | responseData.leftPartChecked.Add(0); |
| | | } |
| | | return WebResponseContent.Instance.OK("è·å左侧åå§æ°æ®æå", responseData); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"è·å左侧åå§æ°æ®å¤±è´¥ï¼è¯·ç¨åéè¯ã{ex.Message}ã"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°æ¯å¦æ«ç |
| | | /// </summary> |
| | | /// <param name="updatePartScannedStatusRequest"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent UpdatePartScannedStatus(UpdatePartScannedStatusRequest updatePartScannedStatusRequest) |
| | | { |
| | | try |
| | | { |
| | | Dt_FormulaDetail dt_FormulaDetail = _formulaDetailService.Repository.QueryFirst(x => x.Id == updatePartScannedStatusRequest.Id); |
| | | dt_FormulaDetail.IsScanned = updatePartScannedStatusRequest.IsScanned; |
| | | bool flag = _formulaDetailService.Repository.UpdateData(dt_FormulaDetail); |
| | | if (flag) |
| | | { |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | return WebResponseContent.Instance.Error("æ´æ°é误"); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error("è·åæ°æ®å¤±è´¥"); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |