| | |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEAWCS_Core; |
| | | using WIDESEAWCS_Core.BaseRepository; |
| | | using WIDESEAWCS_Core.BaseServices; |
| | | using WIDESEAWCS_DTO.BasicInfo; |
| | | using WIDESEAWCS_Model.Models; |
| | | |
| | | namespace WIDESEAWCS_BasicInfoService |
| | | { |
| | | public class BoxingDetailService : ServiceBase<Dt_BoxingDetail, IRepository<Dt_BoxingDetail>>, IBoxingDetailService |
| | | { |
| | | public BoxingDetailService(IRepository<Dt_BoxingDetail> BaseDal) : base(BaseDal) |
| | | |
| | | private readonly IBoxingService _boxingService; |
| | | private readonly IFormulaService _formulaService; |
| | | private readonly IFormulaDetailService _formulaDetailService; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | |
| | | public BoxingDetailService( |
| | | IRepository<Dt_BoxingDetail> BaseDal, |
| | | IFormulaService formulaService, |
| | | IBoxingService boxingService, |
| | | IFormulaDetailService formulaDetailService, |
| | | IUnitOfWorkManage unitOfWorkManage |
| | | ) : base(BaseDal) |
| | | { |
| | | _formulaService = formulaService; |
| | | _boxingService = boxingService; |
| | | _formulaDetailService = formulaDetailService; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | } |
| | | |
| | | public IRepository<Dt_BoxingDetail> Repository => BaseDal; |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ¯è¾é¶ä»¶æ¯å¦é½å
¨ |
| | |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | List<string> BoxingIdList = new List<string>(); |
| | | List<string> FormulaIdList = new List<string>(); |
| | | |
| | | for (int i = 0; i < boxingDetails.Count; i++) |
| | | { |
| | | BoxingIdList.Add(boxingDetails[i].ComponentCode); |
| | | FormulaIdList.Add(formulaDetails[i].ComponentCode); |
| | | List<string> BoxingIdList = boxingDetails.Select(x => x.ComponentCode).ToList(); |
| | | List<string> FormulaIdList = formulaDetails.Select(x => x.ComponentCode).ToList(); |
| | | return !BoxingIdList.Except(FormulaIdList).Any() && !FormulaIdList.Except(BoxingIdList).Any(); |
| | | } |
| | | BoxingIdList.Sort(); |
| | | FormulaIdList.Sort(); |
| | | |
| | | for (int i = 0; i < BoxingIdList.Count; i++) |
| | | |
| | | /// <summary> |
| | | /// æ£æ¥é¶ä»¶ |
| | | /// </summary> |
| | | /// <param name="boxingDetails"></param> |
| | | /// <param name="formulaDetails"></param> |
| | | /// <returns></returns> |
| | | public string IsComponentCodesEqual(List<string> boxingDetails, List<string> formulaDetails) |
| | | { |
| | | if (BoxingIdList[i] != FormulaIdList[i]) |
| | | // å¤çnulléåï¼è§é¿ç©ºæéå¼å¸¸ |
| | | var boxList = boxingDetails ?? new List<string>(); |
| | | var formulaList = formulaDetails ?? new List<string>(); |
| | | |
| | | var validBoxCodes = boxList.Where(code => !string.IsNullOrEmpty(code)).ToList(); |
| | | var validFormulaCodes = formulaList.Where(code => !string.IsNullOrEmpty(code)).ToList(); |
| | | |
| | | foreach (var group in validBoxCodes.GroupBy(code => code)) |
| | | { |
| | | return false; |
| | | string componentCode = group.Key; |
| | | int boxCount = group.Count(); |
| | | int formulaCount = validFormulaCodes.Count(code => code == componentCode); |
| | | |
| | | if (formulaCount == 0 || formulaCount < boxCount) |
| | | { |
| | | return componentCode; |
| | | } |
| | | } |
| | | return true; |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// æ·»å /ä¿®æ¹ç»çä¿¡æ¯ï¼ä¸ä½åæ¥å£ï¼ä¼ å·¥è£
æ¿ç¼å·åå¨åä¿®æ¹ï¼ä¸åå¨åæ°å¢ï¼ |
| | | /// </summary> |
| | | /// <param name="toolingBoardSubmitDto"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent SaveToolingBoardNo(ToolingBoardSubmitDto toolingBoardSubmitDto) |
| | | { |
| | | using (var uow = _unitOfWorkManage.CreateUnitOfWork()) |
| | | { |
| | | try |
| | | { |
| | | // 1. åæ°æ ¡éª |
| | | if (toolingBoardSubmitDto == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æäº¤åæ°ä¸è½ä¸ºç©º"); |
| | | } |
| | | string palletCode = toolingBoardSubmitDto.ToolingBoardNo?.Trim(); |
| | | string productCode = toolingBoardSubmitDto.FinishedProductCode?.Trim(); |
| | | if (string.IsNullOrWhiteSpace(palletCode)) |
| | | { |
| | | return WebResponseContent.Instance.Error("å·¥è£
æ¿ç¼å·ä¸è½ä¸ºç©º"); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(productCode)) |
| | | { |
| | | return WebResponseContent.Instance.Error("æåç¼ç ä¸è½ä¸ºç©º"); |
| | | } |
| | | |
| | | // 2. æ¥è¯¢æåé
æ¹ä¿¡æ¯ |
| | | Dt_Formula formulaModel = _formulaService.Repository.QueryFirst(x => x.ProductCode == productCode); |
| | | if (formulaModel == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æ æåé
æ¹ï¼è¯·æ ¸å¯¹æåç¼ç "); |
| | | } |
| | | |
| | | List<Dt_FormulaDetail> dt_FormulaDetails = _formulaDetailService.Repository.QueryData(x => x.FormulaId == formulaModel.Id && x.IsScanned == 1); |
| | | List<string> Codelist = dt_FormulaDetails.Select(x => x.ComponentCode).ToList(); |
| | | string IsCode = IsComponentCodesEqual(toolingBoardSubmitDto.PartsList, Codelist); |
| | | if (IsCode != null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"ç©æã{IsCode}ãé误ï¼è¯·æ ¸å¯¹ç©æç¼å·"); |
| | | } |
| | | |
| | | |
| | | // 3. æ ¸å¿å¤æï¼æ ¹æ®å·¥è£
æ¿ç¼å·æ¥è¯¢æ¯å¦åå¨ãæ°å¢/ä¿®æ¹ãçä¸»è¡¨æ°æ® |
| | | Dt_Boxing existBoxinModel = _boxingService.Repository.QueryFirst(x => x.PalletCode == palletCode); |
| | | if (existBoxinModel == null) |
| | | { |
| | | #region æ°å¢é»è¾ - åé»è¾ä¼åç |
| | | Dt_Boxing dt_boxin = new Dt_Boxing() |
| | | { |
| | | PalletCode = palletCode, |
| | | ProductCode = productCode, |
| | | ProductName = formulaModel.ProductName.Trim(), |
| | | Creater = "admin", |
| | | CreateDate = DateTime.Now |
| | | }; |
| | | int newBoxingId = _boxingService.Repository.AddData(dt_boxin); |
| | | |
| | | |
| | | // æ¹éæ·»å æç»è¡¨æ°æ® |
| | | if (toolingBoardSubmitDto.PartsList != null && toolingBoardSubmitDto.PartsList.Count > 0) |
| | | { |
| | | List<Dt_BoxingDetail> detailList = new List<Dt_BoxingDetail>(); |
| | | foreach (string ComponentCode in toolingBoardSubmitDto.PartsList) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(ComponentCode)) continue; |
| | | string ComponentCodeTrim = ComponentCode.Trim(); |
| | | |
| | | Dt_FormulaDetail formulaDetail = _formulaDetailService.Repository.QueryFirst(x => x.FormulaId == formulaModel.Id && x.ComponentCode == ComponentCodeTrim); |
| | | if (formulaDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"é
æ¹ä¸æ æ¤ç©æã{ComponentCodeTrim}ãï¼è¯·æ ¸å¯¹ç©æç¼å·"); |
| | | } |
| | | |
| | | Dt_BoxingDetail detailModel = new Dt_BoxingDetail() |
| | | { |
| | | BoxingId = newBoxingId, |
| | | ComponentCode = ComponentCodeTrim, |
| | | ComponentName = formulaDetail.ComponentName, |
| | | Creater = "admin", |
| | | CreateDate = DateTime.Now |
| | | }; |
| | | detailList.Add(detailModel); |
| | | } |
| | | if (detailList.Count > 0) |
| | | { |
| | | BaseDal.AddData(detailList); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | else |
| | | { |
| | | #region ä¿®æ¹é»è¾ - æ°å¢æ ¸å¿é»è¾ |
| | | // 1. æ´æ°ä¸»è¡¨æ°æ® |
| | | existBoxinModel.ProductCode = productCode; |
| | | existBoxinModel.ProductName = formulaModel.ProductName.Trim(); |
| | | existBoxinModel.Modifier = "admin"; |
| | | existBoxinModel.ModifyDate = DateTime.Now; |
| | | _boxingService.Repository.UpdateData(existBoxinModel); |
| | | |
| | | int boxingId = existBoxinModel.Id; |
| | | |
| | | // 2. å é¤è¯¥ç»çä¸çãåæå
¨é¨æç»è¡¨æ°æ®ã |
| | | List<Dt_BoxingDetail> oldDetailList = BaseDal.QueryData(x => x.BoxingId == boxingId); |
| | | if (oldDetailList != null && oldDetailList.Count > 0) |
| | | { |
| | | BaseDal.DeleteData(oldDetailList); |
| | | } |
| | | |
| | | // 3. éæ°æå
¥ä¿®æ¹åçæç»è¡¨æ°æ® |
| | | if (toolingBoardSubmitDto.PartsList != null && toolingBoardSubmitDto.PartsList.Count > 0) |
| | | { |
| | | List<Dt_BoxingDetail> detailList = new List<Dt_BoxingDetail>(); |
| | | foreach (string ComponentCode in toolingBoardSubmitDto.PartsList) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(ComponentCode)) continue; |
| | | string ComponentCodeTrim = ComponentCode.Trim(); |
| | | |
| | | Dt_FormulaDetail formulaDetail = _formulaDetailService.Repository.QueryFirst(x => x.FormulaId == formulaModel.Id && x.ComponentCode == ComponentCodeTrim); |
| | | if (formulaDetail == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"é
æ¹ä¸æ æ¤ç©æã{ComponentCodeTrim}ãï¼è¯·æ ¸å¯¹ç©æåç§°"); |
| | | } |
| | | |
| | | Dt_BoxingDetail detailModel = new Dt_BoxingDetail() |
| | | { |
| | | BoxingId = boxingId, |
| | | ComponentCode = ComponentCodeTrim, |
| | | ComponentName = formulaDetail.ComponentName, |
| | | Creater = "admin", |
| | | CreateDate = DateTime.Now |
| | | }; |
| | | detailList.Add(detailModel); |
| | | } |
| | | if (detailList.Count > 0) |
| | | { |
| | | BaseDal.AddData(detailList); |
| | | } |
| | | } |
| | | #endregion |
| | | } |
| | | uow.Commit(); |
| | | string msg = existBoxinModel == null ? "ç»çä¿¡æ¯æ°å¢æåï¼" : "ç»çä¿¡æ¯ä¿®æ¹æåï¼"; |
| | | return WebResponseContent.Instance.OK(msg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"ä¿åå·¥è£
æ¿ç»çä¿¡æ¯å¼å¸¸ï¼{ex.Message}ï¼å æ ï¼{ex.StackTrace}"); |
| | | return WebResponseContent.Instance.Error($"æäº¤å¤±è´¥ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// è·åæåç¼å·åé¶ä»¶ç¼å· |
| | | /// </summary> |
| | | /// <param name="palletCode"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetProductAndPartsByBoardNo(string palletCode) |
| | | { |
| | | try |
| | | { |
| | | if (string.IsNullOrWhiteSpace(palletCode)) |
| | | { |
| | | return WebResponseContent.Instance.OK("æ¥è¯¢æå", new |
| | | { |
| | | finishedProductCode = "", |
| | | partsList = Enumerable.Repeat("", 10).ToList() |
| | | }); |
| | | } |
| | | Dt_Boxing dt_Boxing = _boxingService.Repository.QueryFirst(x => x.PalletCode == palletCode); |
| | | if (dt_Boxing == null) |
| | | { |
| | | return WebResponseContent.Instance.OK("æªæ¥è¯¢å°è¯¥å·¥è£
æ¿å¯¹åºçæåä¿¡æ¯", new |
| | | { |
| | | finishedProductCode = "", |
| | | partsList = Enumerable.Repeat("", 10).ToList() |
| | | }); |
| | | } |
| | | List<Dt_BoxingDetail> dt_BoxingDetails = BaseDal.QueryData(x => x.BoxingId == dt_Boxing.Id)?.ToList() ?? new List<Dt_BoxingDetail>(); |
| | | // åé¶ä»¶ç¼å· |
| | | List<string> partsList = dt_BoxingDetails.Select(d => d.ComponentCode).ToList(); |
| | | List<string> resultPartsList = new List<string>(); |
| | | for (int i = 0; i < 10; i++) |
| | | { |
| | | if (i < partsList.Count) |
| | | { |
| | | resultPartsList.Add(partsList[i] ?? ""); |
| | | } |
| | | else |
| | | { |
| | | resultPartsList.Add(""); |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK("é¶ä»¶ç¼å·å表æ¥è¯¢æå", new |
| | | { |
| | | finishedProductCode = dt_Boxing.ProductCode ?? "", |
| | | partsList = resultPartsList |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æ¥è¯¢é¶ä»¶ç¼å·å表å¼å¸¸ï¼{ex.Message}"); |
| | | } |
| | | } |
| | | } |
| | | } |