using System; using SqlSugar; using Infrastructure.Attribute; using Infrastructure.Extensions; using ZR.Model; using ZR.Model.Dto; using ZR.Model.Business; using ZR.Repository; using ZR.Service.Business.IBusinessService; using System.Linq; using Aliyun.OSS; using System.Text.RegularExpressions; namespace ZR.Service.Business { /// /// 质量GP12工单业务模块Service业务层处理 /// [AppService(ServiceType = typeof(IQcGp12Service), ServiceLifetime = LifeTime.Transient)] public class QcGp12Service : BaseService, IQcGp12Service { public QcGp12LabelAnalysisDto AnalyzeLabelToDto(string label, int type) { QcGp12LabelAnalysisDto labelAnalysisDto = new(); labelAnalysisDto.IsOk = true; labelAnalysisDto.Msg = "解析成功!"; // 零件号抓取 var predicate = Expressionable.Create() .And(it => it.Code == "PartNumber") .And(it => it.Status == "1"); List analysisList = Context.Queryable() .Where(predicate.ToExpression()) .ToList(); foreach (QcGp12BaseLabelAnalysis analysis in analysisList) { if(string.IsNullOrEmpty(analysis.Expression)) { continue; } // 零件号正则表达式 Regex pattern = new Regex(@analysis.Expression); Match match = pattern.Match(label); if (match.Success && match.Groups.Count > 1) { labelAnalysisDto.Partnumber = match.Groups[1].Value; break; } } if (string.IsNullOrEmpty(labelAnalysisDto.Partnumber)) { labelAnalysisDto.IsOk = false; labelAnalysisDto.Msg = "零件号标签解析异常!"; } return labelAnalysisDto; } public List GetDefectInitOptions() { List defectList = new(); var predicate = Expressionable.Create() .And(it => it.Status == "1"); List groupList = Context.Queryable() .Where(predicate.ToExpression()) .GroupBy(it=>it.Group) .Select(it => it.Group) .ToList(); foreach (string group in groupList) { QcGp12AlterationDefectDto defectDto = new(); defectDto.GroupName = group; List children = Context.Queryable() .Where(it=>it.Group == group) .Where(predicate.ToExpression()) .Select(it=> new QcGp12ChildrenDefectDto { Name = it.Name, Code = it.Code, Type = it.Type }) .ToList(); defectDto.Children = children; defectList.Add(defectDto); } return defectList; } public List GetGroupOptions() { var predicate = Expressionable.Create() .And(it=>it.Status == "1"); var response = Context.Queryable() .Where(predicate.ToExpression()) .Select(it=> new QcGp12BaseGroupDto()) .ToList(); return response; } public List GetStieOptions() { var predicate = Expressionable.Create() .And(it => it.Status == "1"); var response = Context.Queryable() .Where(predicate.ToExpression()) .Select(it => new QcGp12BaseSiteDto()) .ToList(); return response; } } }