/// <summary> /// 配置产品级别 /// </summary> /// <param name="productLevelName"></param> /// <param name="productLevelCount"></param> /// <returns></returns> public async Task <string> ConfigureProductLevel(string productLevelCode, string productLevelName, int productLevelCount) { var pls = await _productLevelRepository.Where(e => e.Prol_Name.Contains(productLevelName)).ToListAsync(); if (pls.Any()) { return(string.Join(',', pls.Select(e => e.Prol_ID).OrderBy(e => e).ToList())); } for (int i = 0; i < productLevelCount; i++) { var pl = new CrmProductLevel() { Prol_Code = $"{productLevelCode}{i + 1}", Prol_Name = $"{productLevelName}{i + 1}", Prol_CreatedBy = 1, Prol_CreatedDate = DateTime.Now, Prol_UpdatedBy = 1, Prol_UpdatedDate = DateTime.Now, Prol_Deleted = 0, Prol_Ab = (i + 1).ToString() }; await _productLevelRepository.InsertAsync(pl); pls.Add(pl); } await _uow.SaveChangesAsync(); return(string.Join(',', pls.Select(e => e.Prol_ID).OrderBy(e => e).ToList())); }
public async Task <string> SendClassToMtsAsync(int productType, int branchId, List <CrmClassCourse> targetClasses, int classPerLevel, string SAId, string FTId, string LTId) { try { var branch = await _branchRepository.FirstOrDefaultAsync(); List <string> pls = targetClasses.Select(e => e.Product.Prod_Levels).ToList(); List <string> plsIds = new List <string>(); foreach (var pl in pls) { List <string> plIds = pl.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList(); plsIds = plsIds.Union(plIds).ToList(); } List <int> pliIds = plsIds.Select <string, int>(e => Convert.ToInt32(e)).ToList(); List <CrmProductLevel> productLevels = _productLevelRepository.Where(e => pliIds.Contains(e.Prol_ID)).ToList(); List <ClassSendMtsModel> clsses = new List <ClassSendMtsModel>(); foreach (var tc in targetClasses) { var product = await GetNewProductByOriginProductAsync(tc.Product); var model = new ClassSendMtsModel(); model.SchoolId = tc.Branch.Bran_SapId; model.ProductId = product.Prod_Type; model.ClassTypeId = product.Prod_SubTypeID; model.ProductLevelId = await GetCurrentProductLevelOfClassAsync(tc, classPerLevel); model.ClassCName = tc.Clas_Code; //model.SAId = tc.SA?.User_Logon ?? "jennifer_jy"; model.SAId = SAId; model.HasFT = true; model.FTId = FTId; model.HasLT = true; //中教没有就使用默认的 model.LTId = tc.LT?.User_Logon ?? LTId; //model.HasFT = tc.FT != null; //model.FTId = tc.FT?.User_Logon; //model.HasLT = tc.LT != null; //model.LTId = tc.LT?.User_Logon; model.ClassOpenDate = tc.Clas_ActualBeginDate?.ToString("yyyy-MM-dd"); //处理上课时间的内容 List <SimpleClassSchedule> scss = new List <SimpleClassSchedule>(); scss = JsonConvert.DeserializeObject <List <SimpleClassSchedule> >(tc.Clas_Schedule); StringBuilder scheduleBuilder = new StringBuilder(); foreach (var scs in scss) { var beginTime = Convert.ToDateTime(scs.BeginTime); var endTime = Convert.ToDateTime(scs.EndTime); var currentTime = beginTime.AddHours(1); while (true) { scheduleBuilder.Append($"{scs.Week}*{beginTime.ToString("HH:mm")}*{currentTime.ToString("HH:mm")}&"); if (currentTime >= endTime) { break; } beginTime = currentTime; currentTime = currentTime.AddHours(1); } } model.CourseTimes = scheduleBuilder.ToString().TrimEnd('&'); clsses.Add(model); } int successCount = 0; DateTime now = DateTime.Now; string batchNo = $"{DataTransferConst.ClassTransferNo}{now.ToString("yyyyMMddHHmmss")}"; TransferLog transferLog = new TransferLog() { BatchNo = batchNo, BranchInfo = $"{branch.Bran_ID}-{branch.Bran_Name}-{branch.Bran_SapId}", ProductTypeInfo = $"{productType}", Type = TransferLogType.Class, CreateTime = DateTime.Now }; List <ESClassLog> esLogs = new List <ESClassLog>(); foreach (var c in clsses) { var response = HttpHelper.PostAsync <ClassMRTSResponseEntity>(_classOptions.Value.ClassSendMTSUrl, c); if (response.ResultCode == "100000" || response.ResultCode == "100002") { successCount++; //保存classRelation的关系 var crmClassId = targetClasses.FirstOrDefault(e => e.Clas_Code == c.ClassCName)?.Clas_ID; var existClassRelation = await _classRelationRepository.FirstOrDefaultAsync(e => e.CrmClassId == crmClassId); if (existClassRelation != null) { existClassRelation.MTSClassId = response.MTSClassId; await _classRelationRepository.UpdateAsync(existClassRelation); } else { await _classRelationRepository.InsertAsync(new ClassRelation() { CrmClassId = crmClassId, MTSClassId = response.MTSClassId }); } } //保存日志 transferLog.TransferLogDetails.Add(new TransferLogDetail() { Para = JsonConvert.SerializeObject(c), Response = JsonConvert.SerializeObject(response), ClassInfo = $"{c.ClassTypeId}-{c.ClassCName}" }); esLogs.Add(new ESClassLog() { Id = c.ClassCName, Para = c, Response = response }); } transferLog.Count = transferLog.TransferLogDetails.Count; await _transferLogRepository.InsertAsync(transferLog); await _uow.SaveChangesAsync(); esLogs.ToES <ESClassLog>(); return($"Class Trasfer info:Total:{clsses.Count} Success:{successCount} Fail:{clsses.Count - successCount}"); } catch (Exception ex) { return("error"); } }