dengjunjie
3 天以前 b52018589bf6c7ec1d51ce8ad000a7aa993b0ab5
´úÂë¹ÜÀí/WIDESEAWCS_Server/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/BoxingDetailService.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.PLCEnum;
@@ -11,6 +12,7 @@
using WIDESEAWCS_Core.BaseServices;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.BasicInfo;
using WIDESEAWCS_IBasicInfoService;
using WIDESEAWCS_Model.Models;
using WIDESEAWCS_QuartzJob;
@@ -22,6 +24,10 @@
        private readonly IBoxingService _boxingService;
        private readonly IFormulaService _formulaService;
        private readonly IFormulaDetailService _formulaDetailService;
        private readonly IProcessInfoDetailService _processInfoDetailService;
        private readonly IScanStationService _scanStationService;
        private readonly IUnitOfWorkManage _unitOfWorkManage;
        public BoxingDetailService(
@@ -29,13 +35,18 @@
            IFormulaService formulaService,
            IBoxingService boxingService,
            IFormulaDetailService formulaDetailService,
            IProcessInfoDetailService processInfoDetailService,
            IScanStationService scanStationService,
            IUnitOfWorkManage unitOfWorkManage
            ) : base(BaseDal)
        {
            _formulaService = formulaService;
            _boxingService = boxingService;
            _formulaDetailService = formulaDetailService;
            _processInfoDetailService = processInfoDetailService;
            _scanStationService = scanStationService;
            _unitOfWorkManage = unitOfWorkManage;
        }
        public IRepository<Dt_BoxingDetail> Repository => BaseDal;
@@ -103,6 +114,7 @@
        /// <returns></returns>
        public string IsComponentCodesEqual(List<string> boxingDetails, List<string> formulaDetails)
        {
            // å¤„理null集合,规避空指针异常
            var boxList = boxingDetails ?? new List<string>();
            var formulaList = formulaDetails ?? new List<string>();
@@ -141,30 +153,51 @@
                    {
                        return WebResponseContent.Instance.Error("提交参数不能为空");
                    }
                    string productCode = toolingBoardSubmitDto.FinishedProductCode?.Trim();
                    string productCode = toolingBoardSubmitDto.FinishedProductCode.Trim();
                    string proCode = string.Empty;
                    string proOther = string.Empty;
                    string supplierCode = string.Empty;
                    if (!string.IsNullOrWhiteSpace(productCode))
                    {
                        string proCode = string.Empty;
                        string proOther = string.Empty;
                        string[] parts = productCode.Split(new char[] { ' ', '|' }, StringSplitOptions.RemoveEmptyEntries);
                        if (parts.Length < 3) return WebResponseContent.Instance.Error("编码规则有误!");
                        proCode = parts[0];
                        proOther = parts[1];
                        supplierCode = parts[2];
                        var proCodeMatch = System.Text.RegularExpressions.Regex.Match(productCode, @"TX(\d+)(?=\s|\||$)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                        if (proCodeMatch.Success)
                        {
                            proCode = $"TX{proCodeMatch.Groups[1].Value.Trim()}"; // æ‹¼æŽ¥TX+数字,保持格式统一
                        }
                        #region èŽ·å–æˆå“ç¼–å·ã€æµæ°´å·ã€ä¾›æ–¹ä»£ç 
                        //var proCodeMatch = Regex.Match(productCode, @"TX(\d+)(?=\s|\||$)", RegexOptions.IgnoreCase);
                        //if (proCodeMatch.Success)
                        //{
                        //    proCode = $"TX{proCodeMatch.Groups[1].Value.Trim()}";
                        //}
                        // æ­£åˆ™2:匹配连续的10位纯数字(全局匹配,取第一个符合的即可)
                        var proOtherMatch = System.Text.RegularExpressions.Regex.Match(productCode, @"\d{10}");
                        if (proOtherMatch.Success)
                        {
                            proOther = proOtherMatch.Value.Trim();
                        }
                        //// æ­£åˆ™2:匹配连续的10位纯数字(全局匹配,取第一个符合的即可)
                        //var proOtherMatch = Regex.Match(productCode, @"\d{10}");
                        //if (proOtherMatch.Success)
                        //{
                        //    proOther = proOtherMatch.Value.Trim();
                        //}
                        //var supplierCodeMatch = Regex.Match(productCode, @"[A-Z]+$", RegexOptions.IgnoreCase);
                        //if (supplierCodeMatch.Success)
                        //{
                        //    supplierCode = supplierCodeMatch.Value.Trim();
                        //}
                        #endregion
                        toolingBoardSubmitDto.PartsList = toolingBoardSubmitDto.PartsList.Where(code => !string.IsNullOrEmpty(code)).ToList();
                        // 2. æŸ¥è¯¢æˆå“é…æ–¹ä¿¡æ¯
                        Dt_Formula formulaModel = _formulaService.Repository.QueryFirst(x => x.ProductCode == proCode);
                        if (formulaModel == null)
                        {
                            return WebResponseContent.Instance.Error("无成品配方,请核对成品编码");
                        }
                        Dt_ScanStation dt_ScanStation = _scanStationService.Repository.QueryFirst(x => x.StationCode == "001");
                        if (dt_ScanStation.StationEndProduct != proCode)
                        {
                            return WebResponseContent.Instance.Error("成品编号错误");
                        }
                        List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == formulaModel.Id && x.IsScanned == 1);
@@ -175,10 +208,10 @@
                            return WebResponseContent.Instance.Error($"物料【{IsCode}】错误,请核对物料编号");
                        }
                        //Dt_Boxing existBoxinModel = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                        //if (existBoxinModel == null)
                        //{
                        //    return WebResponseContent.Instance.Error($"托盘未添加,请稍后重试");
@@ -194,10 +227,17 @@
                        {
                            throw new InvalidOperationException("托盘码未扫到,请重试");
                        }
                        Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == PalletCode);
                        if (dt_Boxing != null)
                        {
                            throw new InvalidOperationException("托盘码重复扫描");
                        }
                        Dt_Boxing existBoxinModel = new Dt_Boxing();
                        existBoxinModel.PalletCode = PalletCode;
                        existBoxinModel.ProductCode = proCode;
                        existBoxinModel.ProductName = formulaModel.ProductName;
                        existBoxinModel.BoxingNo = proOther;
                        existBoxinModel.SupplierCode = supplierCode;
                        int id = _boxingService.Repository.AddData(existBoxinModel);
@@ -216,7 +256,7 @@
                        uow.Commit();
                    }
                    OtherDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceName == "主控PLC") as OtherDevice;
                    if (device == null) throw new Exception("未找到主控PLC设备信息");
@@ -326,9 +366,18 @@
                    //    #endregion
                    //}
                    //uow.Commit();
                    //string msg = existBoxinModel == null ? "组盘信息新增成功!" : "组盘信息修改成功!";
                    string msg = null;
                    List<Dt_ProcessInfoDetail> dt_ProcessInfoDetail = _processInfoDetailService.Repository
                            .QueryData(x => x.ProductSn == proOther && x.ProductCode == proCode).ToList();
                    return WebResponseContent.Instance.OK();
                    // 3. åˆ¤æ–­æŸ¥è¯¢ç»“果,存在则赋值提示信息
                    if (dt_ProcessInfoDetail.Count <= 3 && dt_ProcessInfoDetail.Count != 0)
                    {
                        msg = "已有流水号";
                    }
                    // 4. è¿”回响应(存在重复则msg是"已有流水号",不存在则msg为null)
                    return WebResponseContent.Instance.OK(msg);
                }
                catch (Exception ex)
                {