From 16edbbe772e24eb71f6519558576d513e3cf2746 Mon Sep 17 00:00:00 2001 From: liuying <1427574514@qq.com> Date: 周三, 24 9月 2025 15:31:07 +0800 Subject: [PATCH] Merge branch 'master' of http://222.71.245.114:9086/r/DF22001YiQi --- iWara.SCADA.Code/iWare.Wms.Application/Service/Pda/PdaService.cs | 517 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 491 insertions(+), 26 deletions(-) diff --git a/iWara.SCADA.Code/iWare.Wms.Application/Service/Pda/PdaService.cs b/iWara.SCADA.Code/iWare.Wms.Application/Service/Pda/PdaService.cs index 44b8d03..f56d5f8 100644 --- a/iWara.SCADA.Code/iWare.Wms.Application/Service/Pda/PdaService.cs +++ b/iWara.SCADA.Code/iWare.Wms.Application/Service/Pda/PdaService.cs @@ -9,6 +9,7 @@ using Furion.DynamicApiController; using System.Text; using iWare.Wms.Core.Enum; +using Microsoft.AspNetCore.Authorization; namespace iWare.Wms.Application.Service.Pda { @@ -18,6 +19,7 @@ //[Route("api")] [ApiDescriptionSettings("Pda鐩稿叧鎺ュ彛", Name = "PdaService", Order = 100)] [Route("api/[Controller]")] + [DisableOpLog] public class PdaService : IDynamicApiController, ITransient { private readonly IRepository<EquipmentBaseInfo, MasterDbContextLocator> _equipmentBaseInfoRep; @@ -30,12 +32,16 @@ private readonly IRepository<SysDictType, MasterDbContextLocator> _sysDictTypeRep; private readonly IRepository<WorkPieceInfoLog, MasterDbContextLocator> _workPieceInfoLogRep; private readonly IRepository<WorkPieceOutbound, MasterDbContextLocator> _workPieceOutboundRep; + private readonly IRepository<WorkPieceOutboundRecord, MasterDbContextLocator> _workPieceOutboundRecordRep; + private readonly IRepository<WorkPieceUnLine, MasterDbContextLocator> _workPieceUnLineRep; /// <summary> /// 璁惧鍩虹淇℃伅鏋勯�犲嚱鏁� /// </summary> /// <param name="equipmentBaseInfoRep"></param> public PdaService( + IRepository<WorkPieceOutboundRecord, MasterDbContextLocator> workPieceOutboundRecordRep, + IRepository<WorkPieceUnLine, MasterDbContextLocator> workPieceUnLineRep, IRepository<EquipmentBaseInfo, MasterDbContextLocator> equipmentBaseInfoRep, IRepository<V_GetEquipmentAlert, MasterDbContextLocator> v_GetEquipmentAlert, IRepository<EquipmentCurrentMonitor, MasterDbContextLocator> equipmentCurrentMonitorRep, @@ -48,6 +54,8 @@ IRepository<WorkPieceOutbound, MasterDbContextLocator> workPieceOutboundRep ) { + _workPieceOutboundRecordRep = workPieceOutboundRecordRep; + _workPieceUnLineRep = workPieceUnLineRep; _equipmentBaseInfoRep = equipmentBaseInfoRep; _v_GetEquipmentAlertRep = v_GetEquipmentAlert; _equipmentCurrentMonitorRep = equipmentCurrentMonitorRep; @@ -66,7 +74,7 @@ /// </summary> /// <returns></returns> [HttpGet("getOneWorkPiece")] - public async Task<WorkPieceInfoOutput> getOneWorkPiece([FromQuery] WorkPieceProcessPdaSearch input) + public async Task<WorkPieceInfoOutput> getOneWorkPiece([FromQuery] WorkPieceProcessPdaSearch input) { if (string.IsNullOrEmpty(input.WorkPieceID)) { @@ -97,8 +105,8 @@ WorkPieceCurrentPosition = s.c.a.WorkPieceCurrentPosition, WorkPieceinitOnlineTime = s.c.a.WorkPieceinitOnlineTime, WorkPieceLastOfflineTime = s.c.a.WorkPieceLastOfflineTime, - WorkingProcedureCompleted= s.c.a.WorkingProcedureCompleted, - OP80NewCode=s.c.a.OP80NewCode, + WorkingProcedureCompleted = s.c.a.WorkingProcedureCompleted, + OP80NewCode = s.c.a.OP80NewCode, }) .ProjectToType<WorkPieceInfoOutput>().FirstOrDefaultAsync(); if (workPieceInfo == null) @@ -122,7 +130,7 @@ // //.Where(x => (x.g.Code.Equals("equipment_state"))) .Where(u => u.a.QualityState != (int)EnumQualityState.OK) .Where(u => u.a.IsDeleted == false) - .Where(o => o.a.WorkPieceID.Contains(queryStr ?? "")|| o.a.QualityErrorInfo.Contains(queryStr ?? "")) + .Where(o => o.a.WorkPieceID.Contains(queryStr ?? "") || o.a.QualityErrorInfo.Contains(queryStr ?? "")) //.Where(o => (o.a.QualityStateUpdateTime.HasValue ? o.a.QualityStateUpdateTime.Value : DateTime.MinValue) > DateTime.Now.AddDays(-7)) .Where(o => !string.IsNullOrEmpty(o.a.WorkPieceID)) .Select(s => new WorkPieceInfoOutput @@ -137,8 +145,8 @@ WorkingProcedureCompleted = s.a.WorkingProcedureCompleted, WorkPieceinitOnlineTime = s.a.WorkPieceinitOnlineTime, QualityState = s.a.QualityState, - QualityErrorInfo= s.a.QualityErrorInfo, - QualityStateUpdateTime=(s.a.QualityStateUpdateTime.HasValue? s.a.QualityStateUpdateTime.Value:DateTime.MinValue), + QualityErrorInfo = s.a.QualityErrorInfo, + QualityStateUpdateTime = (s.a.QualityStateUpdateTime.HasValue ? s.a.QualityStateUpdateTime.Value : DateTime.MinValue), EquipmentID = s.a.EquipmentID, EquipmentName = s.b.EquipmentName, //EquipmentCurrentState = s.d.EquipmentCurrentState, @@ -221,6 +229,7 @@ /// <param name="input"></param> /// <returns></returns> [HttpGet("getWorkPieceProcess")] + [DisableOpLog] public async Task<WorkPieceProcessPdaOutput> getWorkPieceProcess([FromQuery] WorkPieceProcessPdaSearch input) { var workPieceProcesss = await _workPieceProcessRep.DetachedEntities @@ -230,6 +239,15 @@ .Select(s => new WorkPieceProcessOutput { Id = s.a.Id, + + JiaJuGongWei = s.a.JiaJuGongWei, + + DataCapturePointCname = s.a.DataCapturePointCname, + UpdateDataCapturePointCname = s.a.UpdateDataCapturePointCname, + QualityNoOkReason = s.a.QualityNoOkReason, + CreateUserName = s.a.CreatedUserName, + UpdatedUserName = s.a.UpdatedUserName, + WorkPieceID = s.a.WorkPieceID, WorkingProcedureCurrent = s.a.WorkingProcedureCurrent, EquipmentID = s.a.EquipmentID, @@ -287,7 +305,7 @@ throw Oops.Oh($"淇敼宸ヤ欢璐ㄩ噺鐘舵�佸け璐ワ細宸ヤ欢{item}涓嶅瓨鍦紒"); } - if(int.Parse(input.QualityState)==(int)EnumQualityState.OK) + if (int.Parse(input.QualityState) == (int)EnumQualityState.OK) { workPieceInfo.QualityErrorInfo = ""; } @@ -321,7 +339,7 @@ [HttpPost("updateWorkPieceInfo")] public async Task<string> updateWorkPieceInfo([FromBody] UpdateQualityStateInput input) { - if (input == null || input.WorkPieceIDList.Count == 0 || input.Password == null) + if (input == null || input.WorkPieceIDList.Count == 0 || input.Password == null) { throw Oops.Oh("淇敼宸ヤ欢淇℃伅澶辫触锛氫紶鍙備笉鑳戒负绌猴紒"); } @@ -341,7 +359,7 @@ { throw Oops.Oh($"淇敼宸ヤ欢淇℃伅澶辫触锛氫紶鍏ュ伐浠剁姸鎬乕{input.WorkPieceState}]涓嶅锛�"); } - if (input.WorkingProcedure.Length!=4|| !input.WorkingProcedure.Contains("OP")) + if (input.WorkingProcedure.Length != 4 || !input.WorkingProcedure.Contains("OP")) { throw Oops.Oh($"淇敼宸ヤ欢淇℃伅澶辫触锛氫紶鍏ュ伐搴廩{input.WorkingProcedure}]涓嶅锛�"); } @@ -358,7 +376,7 @@ throw Oops.Oh($"淇敼宸ヤ欢璐ㄩ噺鐘舵�佸け璐ワ細宸ヤ欢{item}涓嶅瓨鍦紒"); } string LogAddRemark = ""; - if (workPieceInfo.QualityState!= int.Parse(input.QualityState)) + if (workPieceInfo.QualityState != int.Parse(input.QualityState)) { LogAddRemark += $"璐ㄩ噺淇℃伅[{workPieceInfo.QualityState ?? 0}]鍒癧{input.QualityState}]"; workPieceInfo.QualityState = int.Parse(input.QualityState); @@ -383,7 +401,7 @@ { LogAddRemark += $"宸ヤ欢鐘舵�� [{workPieceInfo.WorkPieceState}]鍒癧{input.WorkPieceState}]"; workPieceInfo.WorkPieceState = int.Parse(input.WorkPieceState); - if(workPieceInfo.WorkPieceState==(int)EnumWorkPieceState.FinishedProducts) + if (workPieceInfo.WorkPieceState == (int)EnumWorkPieceState.FinishedProducts) { workPieceInfo.WorkPieceLastOfflineTime = DateTime.Now; } @@ -411,16 +429,22 @@ /// </summary> /// <returns></returns> [HttpGet("getWorkPieceByOP80NewCode")] + [DisableOpLog] + [AllowAnonymous] public async Task<WorkPieceInfoOutput> getWorkPieceByOP80NewCode([FromQuery] WorkPieceByOP80NewCodeInputSearch input) { if (string.IsNullOrEmpty(input.OP80NewCode)) { - throw Oops.Oh($"璇疯緭鍏P80鎵撳嵃鎴愬搧鐮佹垨浜岀淮鐮侊紒"); + throw Oops.Oh($"璇疯緭鍏ユ垚鍝佺爜鎴栧伐浠剁爜锛�"); + } + if (input.OP80NewCode.Length > 22) + { + throw Oops.Oh($"宸ヤ欢鐮佹垨鎴愬搧鐮亄input.OP80NewCode}闀垮害涓嶆纭紒"); } string OP80NewCode = input.OP80NewCode.Trim(); var workPieceInfo = await _workPieceInfoRep.DetachedEntities - .Where(!string.IsNullOrEmpty(OP80NewCode), u => u.OP80NewCode == OP80NewCode||u.WorkPieceID== OP80NewCode) + .Where(!string.IsNullOrEmpty(OP80NewCode), u => u.OP80NewCode == OP80NewCode || u.WorkPieceID == OP80NewCode) .Select(s => new WorkPieceInfoOutput { Id = s.Id, @@ -440,8 +464,23 @@ }).FirstOrDefaultAsync(); if (workPieceInfo == null) { - throw Oops.Oh($"OP80鎵撳嵃鎴愬搧鐮佹垨宸ヤ欢浜岀淮鐮併�恵OP80NewCode}銆戞病鏈夋壘鍒扮浉鍏冲伐浠朵俊鎭紒"); + //throw Oops.Oh($"OP80鎵撳嵃鎴愬搧鐮佹垨宸ヤ欢浜岀淮鐮併�恵OP80NewCode}銆戞病鏈夋壘鍒扮浉鍏冲伐浠朵俊鎭紒"); + workPieceInfo = new WorkPieceInfoOutput + { + WorkPieceID = OP80NewCode, + OP80NewCode = OP80NewCode, + }; } + + //鍒ゆ柇鏄惁宸茬粡鍑哄簱 + List<WorkPieceOutbound> db_itemModelList = await _workPieceOutboundRep.DetachedEntities.Where(w => (w.WorkPieceID == OP80NewCode || w.OP80NewCode == OP80NewCode) && w.IsDeleted == false).ToListAsync(); + if (db_itemModelList != null && db_itemModelList.Count > 0) + { + var itemModel = db_itemModelList.First(); + var createitme = itemModel.CreatedTime == null ? "" : (((DateTimeOffset)itemModel.CreatedTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"宸ヤ欢{itemModel.WorkPieceID}宸插嚭搴擄紝鍑哄簱鏃堕棿:{createitme}"); + } + return workPieceInfo; } @@ -451,33 +490,62 @@ /// <param name="input"></param> /// <returns></returns> [HttpPost("outBoundWorkPiece")] + [DisableOpLog] + [UnitOfWork] public async Task<string> outBoundWorkPiece([FromBody] OutBoundInput input) { - if (input.Password == null || !input.Password.Equals("123456")) - { - throw Oops.Oh("淇敼宸ヤ欢璐ㄩ噺鐘舵�佸け璐ワ細瀵嗙爜杈撳叆閿欒锛�"); - } + //if (input.Password == null || !input.Password.Equals("123456")) + //{ + // throw Oops.Oh("淇敼宸ヤ欢璐ㄩ噺鐘舵�佸け璐ワ細瀵嗙爜杈撳叆閿欒锛�"); + //} if (input.WorkPieceInfoLst.Count < 1) { - throw Oops.Oh("宸ヤ欢鍑哄簱澶辫触锛氭暟鎹笉鑳戒负绌猴紒"); + throw Oops.Oh("宸ヤ欢鍏ュ簱澶辫触锛氭暟鎹笉鑳戒负绌猴紒"); } - List<WorkPieceInfoOutput> WorkPieceInfoLst = input.WorkPieceInfoLst; + List<OutBoundDetailsInput> WorkPieceInfoLst = input.WorkPieceInfoLst; var addOutBoundList = new List<WorkPieceOutbound>(); + var queryOP80NewCodeList = WorkPieceInfoLst.Select(x => x.OP80NewCode).ToList(); + List<WorkPieceOutbound> db_itemModelList = await _workPieceOutboundRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + List<WorkPieceInfo> db_WorkPieceInfoList = await _workPieceInfoRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + var addOutBoundLogList = new List<WorkPieceOutboundRecord>(); + foreach (var item in WorkPieceInfoLst) { - WorkPieceOutbound itemModel=await _workPieceOutboundRep.FirstOrDefaultAsync(w=>w.WorkPieceID==item.WorkPieceID); - if (itemModel != null) { - itemModel.IsDeleted = true; - itemModel.Remark = itemModel.Remark ?? "" + "浜屾鍙戣揣鑷姩鎾ら攢鍙戣揣"; - await _workPieceOutboundRep.UpdateAsync(itemModel); + var itemModel = db_itemModelList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode && w.IsDeleted == false); + if (itemModel != null) + { + //itemModel.IsDeleted = true; + //itemModel.Remark = itemModel.Remark ?? "" + "浜屾鍙戣揣鑷姩鎾ら攢鍙戣揣"; + //await _workPieceOutboundRep.UpdateAsync(itemModel); + + /* + var createitme = itemModel.CreatedTime == null ? "" : (((DateTimeOffset)itemModel.CreatedTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}宸插嚭搴擄紝鍑哄簱鏃堕棿:{createitme}"); + + //*/ + + //涓嶅啀鎻愮ず鍑烘潵锛岃嚜鍔ㄥ拷鐣� 銆怑ditby shaocx,2024-09-04銆� + continue; + } + var workPiece = db_WorkPieceInfoList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (workPiece != null) + { + workPiece.OutPerson = CurrentUserInfo.Name; + workPiece.OutRemark = "鎾ら攢宸ヤ欢鍏ュ簱"; + workPiece.OutTime = DateTime.Now; + workPiece.IsOut = false; + + await _workPieceInfoRep.UpdateAsync(workPiece); } var outBoundLog = new WorkPieceOutbound { - WorkPieceID = item.WorkPieceID, + WorkPieceID = workPiece?.WorkPieceID, OP80NewCode = item.OP80NewCode, WorkPieceOutboundTime = DateTime.Now, WorkPieceOutboundUserId = CurrentUserInfo.UserId, @@ -486,10 +554,407 @@ CreatedUserName = CurrentUserInfo.Name, }; addOutBoundList.Add(outBoundLog); + + var outBoundLogRecord = new WorkPieceOutboundRecord + { + OperationType = OutboundOperationType.鍏ュ簱.ToString(), + WorkPieceID = workPiece?.WorkPieceID, + OP80NewCode = item.OP80NewCode, + + CreatedUserId = CurrentUserInfo.UserId, + CreatedUserName = CurrentUserInfo.Name, + + + //CarNo = input.CarNo, + Remark = "宸ヤ欢鍏ュ簱", + + }; + addOutBoundLogList.Add(outBoundLogRecord); + + } await _workPieceOutboundRep.InsertAsync(addOutBoundList); + + await _workPieceOutboundRecordRep.InsertAsync(addOutBoundLogList); + return "鍑哄簱鎴愬姛"; } + /// <summary> + /// 鍑哄簱缁熻 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost("getOutBoundWorkPieceInfoCount")] + [DisableOpLog] + public async Task<string> GetOutBoundWorkPieceInfoCount() + { + DateTimeOffset now = DateTimeOffset.Now; // 鑾峰彇褰撳墠鏃堕棿锛屽寘鎷椂鍖哄亸绉婚噺 + DateTimeOffset startOfDay = new DateTimeOffset(now.Year, now.Month, now.Day, 0, 0, 0, now.Offset); // 褰撳ぉ寮�濮嬫椂闂� + DateTimeOffset endOfDay = new DateTimeOffset(now.Year, now.Month, now.Day, 23, 59, 59, now.Offset); // 褰撳ぉ缁撴潫鏃堕棿 + List<WorkPieceOutbound> db_itemModelList = await _workPieceOutboundRep.Where(w => w.CreatedTime >= startOfDay && w.CreatedTime <= endOfDay && w.IsDeleted == false).ToListAsync(); + + return db_itemModelList.Count().ToString(); + } + + + #region 鏂扮増 涓嬬嚎銆佸嚭搴撴墽琛� + + /// <summary> + /// 涓嬬嚎鎵ц + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost("unLineWorkPiece")] + [DisableOpLog] + [UnitOfWork] + public async Task<string> unLineWorkPiece([FromBody] UnLineInput input) + { + if (input.WorkPieceInfoLst.Count < 1) + { + throw Oops.Oh("鏁版嵁涓嶈兘涓虹┖锛�"); + } + if (input.CarNo == null || input.CarNo.Equals("")) + { + throw Oops.Oh("灏忚溅鐮佸繀椤昏緭鍏ワ紒"); + } + + List<UnBoundDetailsInput> WorkPieceInfoLst = input.WorkPieceInfoLst; + + var addOutBoundList = new List<WorkPieceOutbound>(); + var addOutBoundLogList = new List<WorkPieceOutboundRecord>(); + + var queryOP80NewCodeList = WorkPieceInfoLst.Select(x => x.OP80NewCode).ToList(); + List<WorkPieceOutbound> db_WorkPieceOutboundList = await _workPieceOutboundRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + List<WorkPieceInfo> db_WorkPieceInfoList = await _workPieceInfoRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + foreach (var item in WorkPieceInfoLst) + { + var itemModel = db_WorkPieceOutboundList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (itemModel != null) + { + if (itemModel.UnLineStage == PieceUnLineStage.宸插嚭搴�) + { + var createitme = itemModel.WorkPieceOutboundTime == null ? "" : (((DateTimeOffset)itemModel.WorkPieceOutboundTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}宸插嚭搴擄紝鍑哄簱鏃堕棿:{createitme}"); + } + if (itemModel.UnLineStage == PieceUnLineStage.宸蹭笅绾�) + { + var createitme = itemModel.WorkPieceUnLineTime == null ? "" : (((DateTimeOffset)itemModel.WorkPieceUnLineTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}宸蹭笅绾匡紝涓嬬嚎鏃堕棿:{createitme}"); + } + } + var workPiece = db_WorkPieceInfoList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (workPiece != null) + { + + workPiece.OutRemark = "宸ヤ欢涓嬬嚎"; + workPiece.UnLineStage = PieceUnLineStage.宸蹭笅绾�; + workPiece.UnLineStageName = PieceUnLineStage.宸蹭笅绾�.ToString(); + workPiece.WorkPieceUnLineTime = DateTime.Now; + workPiece.WorkPieceUnLineUserId = CurrentUserInfo.UserId; + workPiece.WorkPieceUnLineUserName = CurrentUserInfo.Name; + + await _workPieceInfoRep.UpdateAsync(workPiece); + } + var outBound = new WorkPieceOutbound + { + WorkPieceID = workPiece?.WorkPieceID, + OP80NewCode = item.OP80NewCode, + WorkPieceOutboundTime = DateTime.Now, + WorkPieceOutboundUserId = CurrentUserInfo.UserId, + WorkPieceOutboundUserName = CurrentUserInfo.Name, + CreatedUserId = CurrentUserInfo.UserId, + CreatedUserName = CurrentUserInfo.Name, + + UnLineStage = PieceUnLineStage.宸蹭笅绾�, + UnLineStageName = PieceUnLineStage.宸蹭笅绾�.ToString(), + WorkPieceUnLineTime = DateTime.Now, + WorkPieceUnLineUserId = CurrentUserInfo.UserId, + WorkPieceUnLineUserName = CurrentUserInfo.Name, + CarNo = input.CarNo, + Remark = "宸ヤ欢涓嬬嚎", + + }; + addOutBoundList.Add(outBound); + + var outBoundLog = new WorkPieceOutboundRecord + { + OperationType = OutboundOperationType.涓嬬嚎.ToString(), + WorkPieceID = workPiece?.WorkPieceID, + OP80NewCode = item.OP80NewCode, + + CreatedUserId = CurrentUserInfo.UserId, + CreatedUserName = CurrentUserInfo.Name, + + + CarNo = input.CarNo, + Remark = "宸ヤ欢涓嬬嚎", + + }; + addOutBoundLogList.Add(outBoundLog); + + + + } + await _workPieceOutboundRep.InsertAsync(addOutBoundList); + await _workPieceOutboundRecordRep.InsertAsync(addOutBoundLogList); + + return "涓嬬嚎鎴愬姛"; + } + + + + + /// <summary> + /// 鍑哄簱鎵ц + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost("outStoreWorkPiece")] + [DisableOpLog] + [UnitOfWork] + public async Task<string> outStoreWorkPiece([FromBody] OutStoreInput input) + { + if (input.CarNo == null || input.CarNo.Equals("")) + { + throw Oops.Oh("灏忚溅鐮佸繀椤昏緭鍏ワ紒"); + } + + + var updateOutBoundList = new List<WorkPieceOutbound>(); + var addOutBoundLogList = new List<WorkPieceOutboundRecord>(); + + List<WorkPieceOutbound> db_WorkPieceOutboundList = await _workPieceOutboundRep.Where(w => + w.CarNo == input.CarNo + && w.UnLineStage == PieceUnLineStage.宸蹭笅绾� + && w.IsDeleted == false).ToListAsync(); + + if (db_WorkPieceOutboundList?.Count == 0) + { + throw Oops.Oh("娌℃湁鍙嚭搴撶殑鏁版嵁锛�"); + } + + + var queryOP80NewCodeList = db_WorkPieceOutboundList.Select(x => x.OP80NewCode).ToList(); + + List<WorkPieceInfo> db_WorkPieceInfoList = await _workPieceInfoRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + foreach (var item in db_WorkPieceOutboundList) + { + var itemModel = db_WorkPieceOutboundList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (itemModel != null) + { + if (itemModel.UnLineStage == PieceUnLineStage.宸插嚭搴�) + { + var createitme = itemModel.WorkPieceOutboundTime == null ? "" : (((DateTimeOffset)itemModel.WorkPieceOutboundTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}宸插嚭搴擄紝鍑哄簱鏃堕棿:{createitme}"); + } + } + else + { + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}娌℃湁涓嬬嚎鏁版嵁"); + } + var workPiece = db_WorkPieceInfoList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (workPiece != null) + { + + workPiece.OutRemark = "宸ヤ欢鍑哄簱"; + workPiece.UnLineStage = PieceUnLineStage.宸插嚭搴�; + workPiece.UnLineStageName = PieceUnLineStage.宸插嚭搴�.ToString(); + workPiece.OutTime = DateTime.Now; + workPiece.OutPerson = CurrentUserInfo.Name; + + await _workPieceInfoRep.UpdateAsync(workPiece); + } + + item.UnLineStage = PieceUnLineStage.宸插嚭搴�; + item.UnLineStageName = PieceUnLineStage.宸插嚭搴�.ToString(); + item.WorkPieceUnLineTime = DateTime.Now; + item.WorkPieceUnLineUserId = CurrentUserInfo.UserId; + item.WorkPieceUnLineUserName = CurrentUserInfo.Name; + updateOutBoundList.Add(item); + + var outBoundLog = new WorkPieceOutboundRecord + { + OperationType = OutboundOperationType.鍑哄簱.ToString(), + WorkPieceID = workPiece?.WorkPieceID, + OP80NewCode = item.OP80NewCode, + + CreatedUserId = CurrentUserInfo.UserId, + CreatedUserName = CurrentUserInfo.Name, + + + CarNo = input.CarNo, + Remark = "宸ヤ欢鍑哄簱", + + }; + addOutBoundLogList.Add(outBoundLog); + + + + } + await _workPieceOutboundRep.UpdateAsync(updateOutBoundList); + await _workPieceOutboundRecordRep.InsertAsync(addOutBoundLogList); + + return "鍑哄簱鎴愬姛"; + } + + + /// <summary> + /// 涓嬬嚎鎾ゅ洖/鍑哄簱鎾ゅ洖 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost("unLineWorkPieceRollback")] + [DisableOpLog] + [UnitOfWork] + public async Task<string> unLineWorkPieceRollback([FromBody] UnLineRoolbackInput input) + { + if (input.WorkPieceInfoLst.Count < 1) + { + throw Oops.Oh("鏁版嵁涓嶈兘涓虹┖锛�"); + } + if (!(input.Flag == 1 || input.Flag == 2)) + { + throw Oops.Oh("鏍囪涓嶆纭紒"); + } + var remark = "宸ヤ欢涓嬬嚎鎾ゅ洖"; + if (input.Flag == 2) + { + remark = "宸ヤ欢鍑哄簱鎾ゅ洖"; + } + + List<UnBoundDetailsInput> WorkPieceInfoLst = input.WorkPieceInfoLst; + + var removeOutBoundList = new List<WorkPieceOutbound>(); + var addOutBoundLogList = new List<WorkPieceOutboundRecord>(); + + var queryOP80NewCodeList = WorkPieceInfoLst.Select(x => x.OP80NewCode).ToList(); + List<WorkPieceOutbound> db_WorkPieceOutboundList = await _workPieceOutboundRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + List<WorkPieceInfo> db_WorkPieceInfoList = await _workPieceInfoRep.Where(w => queryOP80NewCodeList.Contains(w.OP80NewCode) && w.IsDeleted == false).ToListAsync(); + + foreach (var item in WorkPieceInfoLst) + { + var itemModel = db_WorkPieceOutboundList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (itemModel != null) + { + if (input.Flag == 1 && itemModel.UnLineStage == PieceUnLineStage.宸插嚭搴�) + { + var createitme = itemModel.WorkPieceOutboundTime == null ? "" : (((DateTimeOffset)itemModel.WorkPieceOutboundTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}宸插嚭搴擄紝鍑哄簱鏃堕棿:{createitme}"); + } + if (input.Flag == 2 && itemModel.UnLineStage == PieceUnLineStage.宸蹭笅绾�) + { + var createitme = itemModel.WorkPieceUnLineTime == null ? "" : (((DateTimeOffset)itemModel.WorkPieceUnLineTime).UtcDateTime.ToString("yyyy-MM-dd HH:mm:ss")); + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}宸蹭笅绾匡紝涓嬬嚎鏃堕棿:{createitme}"); + } + } + else + { + throw Oops.Oh($"鎴愬搧鐮亄itemModel.OP80NewCode}娌℃湁涓嬬嚎鍑哄簱鏁版嵁"); + } + var workPiece = db_WorkPieceInfoList.FirstOrDefault(w => w.OP80NewCode == item.OP80NewCode); + if (workPiece != null) + { + workPiece.OutRemark = remark; + + if (input.Flag == 1) + { + workPiece.UnLineStage = null; + workPiece.UnLineStageName = ""; + workPiece.WorkPieceUnLineTime = null; + workPiece.WorkPieceUnLineUserId = null; + workPiece.WorkPieceUnLineUserName = ""; + } + else + { + workPiece.UnLineStage = PieceUnLineStage.宸蹭笅绾�; + workPiece.UnLineStageName = PieceUnLineStage.宸蹭笅绾�.ToString(); + workPiece.WorkPieceUnLineTime = DateTime.Now; + workPiece.WorkPieceUnLineUserId = CurrentUserInfo.UserId; + workPiece.WorkPieceUnLineUserName = CurrentUserInfo.Name; + } + + + await _workPieceInfoRep.UpdateAsync(workPiece); + } + + + removeOutBoundList.Add(itemModel); + + var outBoundLog = new WorkPieceOutboundRecord + { + OperationType = input.Flag == 1 ? OutboundOperationType.鎾ら攢涓嬬嚎.ToString() : OutboundOperationType.鎾ら攢鍑哄簱.ToString(), + WorkPieceID = workPiece?.WorkPieceID, + OP80NewCode = item.OP80NewCode, + + CreatedUserId = CurrentUserInfo.UserId, + CreatedUserName = CurrentUserInfo.Name, + + CarNo = itemModel.CarNo, + Remark = remark, + + }; + addOutBoundLogList.Add(outBoundLog); + + + + } + await _workPieceOutboundRep.DeleteAsync(removeOutBoundList); + await _workPieceOutboundRecordRep.InsertAsync(addOutBoundLogList); + + return "鎿嶄綔鎴愬姛"; + } + + + + /// <summary> + /// 鍑哄簱缁熻 + /// </summary> + /// <param name="input"></param> + /// <returns></returns> + [HttpPost("getOutBoundWorkPieceInfoCountList")] + [DisableOpLog] + public async Task<List<OutBoundWorkPieceInfoCountOutput>> GetOutBoundWorkPieceInfoCountList([FromBody] OutBoundWorkPieceInfoCountInput input) + { + /* + //娴嬭瘯 + List<OutBoundWorkPieceInfoCountOutput> outBoundWorkPieceInfoCountOutputs = new List<OutBoundWorkPieceInfoCountOutput>(); + outBoundWorkPieceInfoCountOutputs.Add(new OutBoundWorkPieceInfoCountOutput() + { + Count = 10, + WorkPieceOutboundUserName = "AAA" + }); + outBoundWorkPieceInfoCountOutputs.Add(new OutBoundWorkPieceInfoCountOutput() + { + Count = 99, + WorkPieceOutboundUserName = "BBb" + }); + return outBoundWorkPieceInfoCountOutputs; + //*/ + + + //DateTimeOffset now = DateTimeOffset.Now; // 鑾峰彇褰撳墠鏃堕棿锛屽寘鎷椂鍖哄亸绉婚噺 + DateTimeOffset now = input.Date; // 鑾峰彇褰撳墠鏃堕棿锛屽寘鎷椂鍖哄亸绉婚噺 + DateTimeOffset startOfDay = new DateTimeOffset(now.Year, now.Month, now.Day, 0, 0, 0, now.Offset); // 褰撳ぉ寮�濮嬫椂闂� + DateTimeOffset endOfDay = new DateTimeOffset(now.Year, now.Month, now.Day, 23, 59, 59, now.Offset); // 褰撳ぉ缁撴潫鏃堕棿 + List<WorkPieceOutbound> db_itemModelList = await _workPieceOutboundRep.Where(w => w.CreatedTime >= startOfDay + && w.CreatedTime <= endOfDay && w.IsDeleted == false).ToListAsync(); + //姹囨�诲垎缁� + var groupList = db_itemModelList.GroupBy(g => g.WorkPieceOutboundUserName).Select(s => new OutBoundWorkPieceInfoCountOutput() + { + WorkPieceOutboundUserName = s.Key, + Count = s.ToList().Count + }).ToList(); + return groupList; + //*/ + } + + + #endregion + } } -- Gitblit v1.9.3