/* *ËùÓйØÓÚVV_InboundOrderInfoÀàµÄÒµÎñ´úÂëÓ¦ÔÚ´Ë´¦±àд *¿ÉʹÓÃrepository.µ÷Óó£Ó÷½·¨£¬»ñÈ¡EF/DapperµÈÐÅÏ¢ *Èç¹ûÐèÒªÊÂÎñÇëʹÓÃrepository.DbContextBeginTransaction *Ò²¿ÉʹÓÃDBServerProvider.ÊÖ¶¯»ñÈ¡Êý¾Ý¿âÏà¹ØÐÅÏ¢ *Óû§ÐÅÏ¢¡¢È¨ÏÞ¡¢½ÇÉ«µÈʹÓÃUserContext.Current²Ù×÷ *VV_InboundOrderInfoService¶ÔÔö¡¢É¾¡¢¸Ä²é¡¢µ¼Èë¡¢µ¼³ö¡¢ÉóºËÒµÎñ´úÂëÀ©Õ¹²ÎÕÕServiceFunFilter */ using WIDESEA.Core.BaseProvider; using WIDESEA.Core.Extensions.AutofacManager; using WIDESEA.Entity.DomainModels; using System.Linq; using WIDESEA.Core.Utilities; using System.Linq.Expressions; using WIDESEA.Core.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.AspNetCore.Http; using WIDESEA.Services.IRepositories; using System; using System.Collections.Generic; using WIDESEA.Services.IServices; using WIDESEA.Common; using WIDESEA.Services.Repositories; using WIDESEA.Core.ManageUser; namespace WIDESEA.Services.Services { public partial class VV_InboundOrderInfoService { private readonly IHttpContextAccessor _httpContextAccessor; private readonly IVV_InboundOrderInfoRepository _repository;//·ÃÎÊÊý¾Ý¿â [ActivatorUtilitiesConstructor] public VV_InboundOrderInfoService( IVV_InboundOrderInfoRepository dbRepository, IHttpContextAccessor httpContextAccessor ) : base(dbRepository) { _httpContextAccessor = httpContextAccessor; _repository = dbRepository; //¶à×â»§»áÓõ½Õâinit´úÂ룬ÆäËûÇé¿ö¿ÉÒÔ²»Óà //base.Init(dbRepository); } /// /// н¨Èë¿â¶©µ¥ /// /// /// public override WebResponseContent Add(SaveModel saveDataModel) { WebResponseContent webResponse = repository.DbContextBeginTransaction(() => { WebResponseContent content = new WebResponseContent { Status = true, Message = "±£´æ³É¹¦" }; try { string number = GetDataNumber(); Guid headId = Guid.NewGuid(); Dt_inboundorder_head head = new Dt_inboundorder_head() { inorderhead_id = headId, inorderhead_areaid = saveDataModel.MainData["inorderhead_areaid"].ToString(), inorderhead_creator = UserContext.Current.UserTrueName, inorderhead_number = number, inorderhead_type = InboundType.TaskType_built.ToString(), inorderhead_createtime = DateTime.Now }; Dt_inboundorder_headRepository.Instance.Add(head, true); Dt_inboundorder_detail detail = new Dt_inboundorder_detail() { inorderdtl_areaid = saveDataModel.MainData["inorderhead_areaid"].ToString(), inorderdtl_batch = saveDataModel.MainData["inorderdtl_batch"].ToString(), inorderdtl_number = number, //inorderdtl_batch_cus = saveDataModel.MainData["inorderdtl_batch_cus"].ToString(), //inorderdtl_checkoutby = "admin", //inorderdtl_checktype = saveDataModel.MainData["inorderdtl_checktype"].ToString(), inorderdtl_createtime = DateTime.Now, inorderdtl_creator = UserContext.Current.UserTrueName, //inorderdtl_depart = saveDataModel.MainData["inorderdtl_depart"].ToString(), //inorderdtl_expiredate = Convert.ToDateTime(saveDataModel.MainData["inorderdtl_expiredate"].ToString()), inorderdtl_finishedqty = 0, inorderdtl_grade = int.Parse(saveDataModel.MainData["inorderdtl_grade"].ToString()), inorderdtl_headid = headId.ToString(), inorderdtl_isupload = false, inorderdtl_item = 1, inorderdtl_loadtime = DateTime.Now, inorderdtl_materielid = saveDataModel.MainData["materiel_id"].ToString(), //inorderdtl_prodtdate = Convert.ToDateTime(saveDataModel.MainData["inorderdtl_prodtdate"].ToString()), inorderdtl_progressqty = 0, inorderdtl_qty = Convert.ToDecimal(saveDataModel.MainData["inorderdtl_qty"].ToString()), inorderdtl_state = ((int)OrderState.WMSReaded).ToString(), //inorderdtl_supply = saveDataModel.MainData["inorderdtl_supply"].ToString() }; Dt_inboundorder_detailRepository.Instance.Add(detail, true); return content; } catch (Exception ex) { content.Data = false; content.Message = ex.Message; return content; } }); //Dt_trackloginfoService.Instance.AddTrackLog(saveDataModel, webResponse, "ÐÂÔöÈë¿â¶©µ¥", "3003", $"ÐÂÔöÈë¿â¶©µ¥"); return webResponse; } /// /// ɾ³ýÈë¿â¶©µ¥ /// /// /// /// public override WebResponseContent Del(object[] keys, bool delList = true) { WebResponseContent content = new WebResponseContent(); content = repository.DbContextBeginTransaction(() => { try { List details = new List(); List heads = new List(); List detailsList = new List(); List headsList = new List(); foreach (var item in keys) { Dt_inboundorder_detail _Detail = Dt_inboundorder_detailRepository.Instance.FindFirst(d => d.inorderdtl_id == Guid.Parse(item.ToString())); if (_Detail != null) { Dt_inboundorder_head _HeadRes = Dt_inboundorder_headRepository.Instance.FindFirst(d => d.inorderhead_id == Guid.Parse(_Detail.inorderdtl_headid.ToString()) && d.inorderhead_type != InboundType.TaskType_built.ToString()); if (_HeadRes != null) { return content.Error("ÇëÑ¡Ôñ¶©µ¥ÀàÐÍΪ¡¾Ð½¨TaskType_built¡¿½øÐвÙ×÷"); } else { Dt_inboundorder_head _Head = Dt_inboundorder_headRepository.Instance.FindFirst(d => d.inorderhead_id == Guid.Parse(_Detail.inorderdtl_headid.ToString()) && d.inorderhead_type == InboundType.TaskType_built.ToString()); Dt_inboundorder_detail inboundorder_Detail = Dt_inboundorder_detailRepository.Instance.FindFirst(d => d.inorderdtl_headid == _Head.inorderhead_id.ToString()); if (_Head != null) { details.Add(inboundorder_Detail.inorderdtl_id.ToString()); heads.Add(_Head.inorderhead_id.ToString()); detailsList.Add(inboundorder_Detail); headsList.Add(_Head); } } } } WebResponseContent headhry = Dt_inboundorder_head_htyService.Instance.AddToHistory(heads); WebResponseContent detailhry = Dt_inboundorder_detail_htyService.Instance.AddToHistory(details); if (headhry.Status) { if (detailhry.Status) { Dt_inboundorder_detailRepository.Instance.DeleteWithKeys(details.ToArray(), true); Dt_inboundorder_headRepository.Instance.DeleteWithKeys(heads.ToArray(), true); content = content.OK("ɾ³ý³É¹¦"); } } return content; } catch (Exception ex) { return content.Error(ex.Message); } }); return content; } /// /// Èë¿â¶©µ¥±à¼­ /// /// /// public override WebResponseContent Update(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); //IDt_trackloginfoService logService = Dt_trackloginfoService.Instance; content = repository.DbContextBeginTransaction(() => { try { Dt_inboundorder_detail _detail = Dt_inboundorder_detailRepository.Instance.FindFirst(d => d.inorderdtl_id == Guid.Parse(saveModel.MainData["inorderdtl_id"].ToString())); if (_detail != null) { Dt_inboundorder_head _Head = Dt_inboundorder_headRepository.Instance.FindFirst(d => d.inorderhead_id == Guid.Parse(_detail.inorderdtl_headid.ToString())); if (_Head != null) { _Head.inorderhead_number = saveModel.MainData["inorderhead_number"].ToString(); _Head.inorderhead_areaid = saveModel.MainData["inorderhead_areaid"].ToString(); int head = Dt_inboundorder_detailRepository.Instance.Update(_Head, true); if (head == 1) { _detail.inorderdtl_number = saveModel.MainData["inorderhead_number"].ToString(); _detail.inorderdtl_materielid = saveModel.MainData["materiel_id"].ToString(); _detail.inorderdtl_qty = decimal.Parse(saveModel.MainData["inorderdtl_qty"].ToString()); _detail.inorderdtl_grade = Convert.ToInt32(saveModel.MainData["inorderdtl_grade"].ToString()); _detail.inorderdtl_batch = saveModel.MainData["inorderdtl_batch"].ToString(); _detail.inorderdtl_createtime = DateTime.Parse(saveModel.MainData["inorderdtl_createtime"].ToString()); int detail = Dt_inboundorder_detailRepository.Instance.Update(_detail, true); if (detail == 1) { content = content.OK("¸üгɹ¦"); } else { content = content.Error("Ìå±í¸üÐÂÒì³£"); } } else { content = content.Error("Í·±í¸üÐÂÒì³£"); } } } //for (int i = 0; i < saveModel.DelKeys.Count(); i++) //{ // Guid detailId = new Guid(saveModel.DelKeys[i].ToString()); // VV_InboundOrderInfo orderInfo = repository.Find(a => a.inorderdtl_id == detailId && a.inorderdtl_state == ((int)OrderState.WMSReaded).ToString()).FirstOrDefault(); // if (orderInfo == null) // { // content.Error($"°üº¬²»ÄÜÐ޸ĵĶ©µ¥"); // //logService.AddTrackLog(saveModel, content, "¹Ø±ÕÈë¿âµ¥Ã÷ϸ", "2002", "¹Ø±ÕÈë¿âµ¥Ã÷ϸ"); // return content; // } //} //IDt_inboundorder_detail_htyService detail_HtyService = Dt_inboundorder_detail_htyService.Instance; //WebResponseContent detailHtyContent = detail_HtyService.AddToHistory(saveModel.DelKeys); //IDt_inboundorder_head_htyService head_HtyService = Dt_inboundorder_head_htyService.Instance; //List headIds = detailHtyContent.Data as List; //head_HtyService.AddToHistory(headIds); //content = content.OK(); } catch (Exception ex) { content.Error(ex.Message); } return content; }); if (content.Status) { return content.OK(); } else { return content.Error(); } //logService.AddTrackLog(saveModel, content, "¹Ø±ÕÈë¿âµ¥Ã÷ϸ", "2002", "¹Ø±ÕÈë¿âµ¥Ã÷ϸ"); } /// /// ´´½¨Èë¿â¶©µ¥ºÅ /// /// public static string GetDataNumber() { string str = string.Empty; try { string date = DateTime.Now.ToString("yyyyMMdd"); string ManualNum = Dt_inboundorder_headRepository.Instance.Find(x => x.inorderhead_number.Contains(date)).Max(x => x.inorderhead_number); string ManualNum_Hty = Dt_inboundorder_head_htyRepository.Instance.Find(x => x.inorderhead_number.Contains(date)).Max(x => x.inorderhead_number); if (!string.IsNullOrEmpty(ManualNum) && !string.IsNullOrEmpty(ManualNum_Hty)) { str = ((Convert.ToDouble(ManualNum) > Convert.ToDouble(ManualNum_Hty) ? Convert.ToDouble(ManualNum) : Convert.ToDouble(ManualNum_Hty)) + 1).ToString(); } else if (!string.IsNullOrEmpty(ManualNum) && string.IsNullOrEmpty(ManualNum_Hty)) { str = (Convert.ToDouble(ManualNum) + 1).ToString(); } else if (string.IsNullOrEmpty(ManualNum) && !string.IsNullOrEmpty(ManualNum_Hty)) { str = (Convert.ToDouble(ManualNum_Hty) + 1).ToString(); } else if (string.IsNullOrEmpty(ManualNum) && string.IsNullOrEmpty(ManualNum_Hty)) { str = (Convert.ToDouble(date + 1.ToString().PadLeft(3, '0')) + 1).ToString(); } } catch { } return str; } } }