/// <summary> /// 活动处理方法 /// </summary> /// <param name="codeActive">码活动信息对象</param> /// <param name="activityCodes">码活动信息集合</param> public void ActionProcess <T>(CodeActive codeActive, List <T> activityCodes) where T : ActivityCodes { CodeApply codeApply = CodeApplyFactory.Instance.GetApply(codeActive.ApplyId); if (codeApply.ApplyType == 2)//外部平台码 { string[] tempStrings = codeApply.CodeRulesIDs.Split(new char[] { '|' }); int ruleSegId = 0; if (tempStrings.Length > 0 && int.TryParse(tempStrings[0], out ruleSegId)) { List <CodeRuleSeg> ruleSegs = CodeRuleSegFactory.Instance.GetByCodeRuleId(ruleSegId); if (ruleSegs.Count > 0) { Type type = Assembly.Load(new AssemblyName("Acctrue.CMC.CodeBuild")).GetType(ruleSegs[0].ClassName); IOtherFlatformSeg seg = (Activator.CreateInstance(type) as IOtherFlatformSeg); seg.Initialize(Newtonsoft.Json.JsonConvert.DeserializeObject <List <Acctrue.CMC.Model.Code.ParameterInfo> >(ruleSegs[0].ClassArgs)); string mess = string.Empty; if (seg.EcodeActivate(activityCodes.Select(s => s.Code).ToList(), codeActive, out mess)) { } else { throw new Exception($"码激活任务Id:{codeActive.CodeActivityId}进行外部平台激活同步失败:{mess}"); } } } } }
/// <summary> /// 验证码活动在处理中字典内 /// </summary> /// <param name="codeActive">码活动</param> public bool ContainsActiveFlags(CodeActive codeActive) { lock (lock_activeFlags) { return(activeFlags.ContainsKey(codeActive.CodeActivityId)); } }
/// <summary> /// 将码活动从码活动处理中字典移除 /// </summary> /// <param name="codeActive">码活动</param> public void RemoveActiveFlags(CodeActive codeActive) { lock (lock_activeFlags) { activeFlags.TryRemove(codeActive.CodeActivityId, out codeActive); } }
/// <summary> /// 将码活动添加至码活动处理中字典 /// </summary> /// <param name="codeActive">码活动</param> public void AddActiveFlags(CodeActive codeActive) { lock (lock_activeFlags) { activeFlags.TryAdd(codeActive.CodeActivityId, codeActive); } }
/// <summary> /// 码活动处理工作 /// </summary> /// <param name="codeActive">码活动信息</param> /// <param name="ct">工作取消令牌</param> public static void CodeActivitysWork(CodeActive codeActive, CancellationToken ct) { CodeService.logger.Log(LogLevel.Info, $"开始处理码活动Id:{codeActive.CodeActivityId}"); ActivityProcesser activityProcesser = new ActivityProcesser(codeActive); activityProcesser.UpdateSingleActive(ct); CodeService.logger.Log(LogLevel.Info, $"完成码活动Id:{codeActive.CodeActivityId}"); }
/// <summary> /// 构造方法 /// </summary> /// <param name="codeActive"></param> public ActivityProcesser(CodeActive codeActive) { if (!relationInit) { lock (relationLock) { if (!relationInit) { List <Type> actions = Assembly.GetExecutingAssembly().GetTypes().Where(item => item.GetInterfaces().Contains(typeof(IActivityAction))).ToList(); foreach (Type actionType in actions) { IActivityAction action = (Activator.CreateInstance(actionType) as IActivityAction); activateActionRelation.TryAdd(action.ActivityName, action); } } } } this.codeActive = codeActive; }
/// <summary> /// 码激活。 /// </summary> /// <param name="ecodes">码集合</param> /// <param name="messages">提示信息</param> public bool EcodeActivate(List <string> ecodes, CodeActive codeActive, out string messages) { bool succeed = false; messages = string.Empty; string baseUrl = inputParameters["InterfaceAddress"]; string clientId = inputParameters["ClientId"]; long timeStamp = (long)(DateTime.Now - TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalMilliseconds; string sign = Tools.AESEncode(clientId + timeStamp, inputParameters["AESKey"]); Gather gather = new Gather(); gather.Url = $@"{baseUrl}{ActivateSubAddress}/clientId={clientId}/timeStamp={timeStamp}/sign={sign}"; gather.Method = "POST"; gather.PostData = "[{\"ecode\":\"" + string.Join(",", ecodes.ToArray()) + "\",\"photo\":\"\",\"datas\":[{\"key\":\"ProductName\",\"value\":\"" + codeActive.ProductName + "\"},{\"key\":\"ProductCode\",\"value\":\"" + codeActive.ProductCode + "\"},{\"key\":\"CorpName\",\"value\":\"" + codeActive.CorpName + "\"},{\"key\":\"ProductionDate \",\"value\":\"" + codeActive.UploadDate + "\"},{\"key\":\"ProduceWorkline\",\"value\":\"" + codeActive.ProduceWorkline + "\"}]}]"; //gather.PostData = "[{\"ecode\":\"123,123\",\"photo\":\"\",\"datas\":[{\"key\":\"产品名称\",\"value\":\"康师傅矿泉水\"},{\"key\":\"生产厂家\",\"value\":\"1\"},{\"key\":\"生产地址\",\"value\":\"1\"},{\"key\":\"生产日期\",\"value\":\"1525737600000\"},{\"key\":\"产品类型\",\"value\":\"\"},{\"key\":\"产品批次\",\"value\":\"0002\"},{\"key\":\"生产数量\",\"value\":\"1\"}]}]"; gather.ContentType = "application/json"; string resultHtml = gather.GetHtml(); ResultObject jsonResult = JsonConvert.DeserializeObject <ResultObject>(resultHtml); if (jsonResult != null && jsonResult.status == 200) { succeed = true; } else { if (jsonResult == null) { messages = "码激活操作对方接口平台无结果反馈"; } else { messages = jsonResult.msg; } } return(succeed); }
public CMCResponse UploadExcelFile() { try { //保存文件 var file = System.Web.HttpContext.Current.Request.Files[0]; string fullPath = HttpContext.Current.Server.MapPath("~/ExcelUpload/") + file.FileName; file.SaveAs(fullPath); //获取文件数据 using (FileStream fs = new FileStream(fullPath, FileMode.Open)) { IWorkbook workbook = new XSSFWorkbook(fs); ISheet sheet = workbook.GetSheetAt(0); int lastRowIndex = sheet.LastRowNum; //第一行获取活动名称 IRow row = sheet.GetRow(0); int rowLastIndex = row.LastCellNum - 1; string activeName = row.GetCell(rowLastIndex).StringCellValue; int lastColumn = 0; switch (activeName) { case "激活": lastColumn = 9; break; case "营销": lastColumn = 12; break; case "消费者": lastColumn = 16; break; case "资产": lastColumn = 18; break; case "资产领用": lastColumn = 21; break; default: Response.status = 1; Response.message = "上传活动名称有误"; return(Response); } //第3/4行获取名称基本信息 //List<string> nameList = new List<string>(); //List<string> basicInfo = new List<string>(); //for (int nameIndex = 0; nameIndex < lastColumn; nameIndex++) //{ // row = sheet.GetRow(2); // nameList.Add(row.GetCell(nameIndex).StringCellValue); //} //生成上传活动信息存入数据库 byte[] byteArray = new byte[file.ContentLength]; file.InputStream.Read(byteArray, 0, file.ContentLength); //fs.Read(byteArray, 0, Convert.ToInt32(fs.Length)); IRow row3 = sheet.GetRow(3); CodeActive codeActive = new CodeActive(); codeActive.AppId = "Excel文件上传"; codeActive.CorpCode = row3.GetCell(5).StringCellValue; codeActive.CorpName = row3.GetCell(4).StringCellValue; codeActive.SubCorpCode = row3.GetCell(6).StringCellValue; codeActive.ProductCode = row3.GetCell(8).StringCellValue; codeActive.ProductName = row3.GetCell(7).StringCellValue; codeActive.ProduceWorkline = row3.GetCell(6).StringCellValue; codeActive.ActivityName = activeName; codeActive.Amount = Convert.ToString(lastRowIndex - 2); codeActive.ActualQuantity = Convert.ToString(lastRowIndex - 2); codeActive.UploadDate = DateTime.Now; codeActive.Uploader = "CMC后台"; codeActive.ProcessType = 3; codeActive.Memo = row3.GetCell(9).StringCellValue; codeActive.ApplyId = 0; int activeID = CodeActiveUploadFactory.Instance.InsertNewActive(codeActive, byteArray); if (activeName == "激活") { List <ActiveCode> alist = new List <ActiveCode>(); //第4行开始获取数据 for (int index = 3; index <= lastRowIndex; index++) { //获取当前行 row = sheet.GetRow(index); //生成Mongo对象存码信息 ActiveCode c = new ActiveCode(); c.ActiveName = activeName; c.CreateDate = row.GetCell(2).DateCellValue;; c.ApplyId = codeActive.ApplyId; c.CodeActivityId = activeID; c.CorpCode = codeActive.CorpCode; c.SubCorpCode = codeActive.SubCorpCode; c.CorpName = codeActive.CorpName; try { c.Code = row.GetCell(0).StringCellValue; } catch { c.Code = row.GetCell(0).NumericCellValue.ToString(); } //c.MaskCode = row.GetCell(1).NumericCellValue.ToString(); c.ProductCode = row.GetCell(8).StringCellValue; c.ProductName = row.GetCell(7).StringCellValue; c.Memo = row.GetCell(9).StringCellValue; alist.Add(c); } string res = ReportFactory.Instance.SplitMongoInster <ActiveCode>(alist); if (res == "数据插入MongoDB失败") { Response.status = 0; this.Response.message = res + ",检查MongoDB是否正常"; return(Response); } } if (activeName == "营销") { List <SalesCode> alist = new List <SalesCode>(); //第4行开始获取数据 for (int index = 3; index <= lastRowIndex; index++) { //获取当前行 row = sheet.GetRow(index); //生成Mongo对象存码信息 SalesCode c = new SalesCode(); c.ActiveName = activeName; c.CreateDate = row.GetCell(2).DateCellValue;; c.ApplyId = codeActive.ApplyId; c.CodeActivityId = activeID; c.CorpCode = codeActive.CorpCode; c.SubCorpCode = codeActive.SubCorpCode; c.CorpName = codeActive.CorpName; try { c.Code = row.GetCell(0).StringCellValue; } catch { c.Code = row.GetCell(0).NumericCellValue.ToString(); } //c.MaskCode = row.GetCell(1).NumericCellValue.ToString(); c.ProductCode = row.GetCell(8).StringCellValue; c.ProductName = row.GetCell(7).StringCellValue; c.Memo = row.GetCell(9).StringCellValue; c.ActiveDescription = row.GetCell(10).StringCellValue; c.ActiveStartDate = row.GetCell(11).DateCellValue; c.ActiveEndDate = row.GetCell(12).DateCellValue; alist.Add(c); } string res = ReportFactory.Instance.SplitMongoInster <SalesCode>(alist); if (res == "数据插入MongoDB失败") { Response.status = 0; this.Response.message = res + ",检查MongoDB是否正常"; return(Response); } } if (activeName == "消费者") { List <CustomerCode> alist = new List <CustomerCode>(); //第4行开始获取数据 for (int index = 3; index <= lastRowIndex; index++) { //获取当前行 row = sheet.GetRow(index); //生成Mongo对象存码信息 CustomerCode c = new CustomerCode(); c.ActiveName = activeName; c.CreateDate = row.GetCell(2).DateCellValue;; c.ApplyId = codeActive.ApplyId; c.CodeActivityId = activeID; c.CorpCode = codeActive.CorpCode; c.SubCorpCode = codeActive.SubCorpCode; c.CorpName = codeActive.CorpName; try { c.Code = row.GetCell(0).StringCellValue; } catch { c.Code = row.GetCell(0).NumericCellValue.ToString(); } //c.MaskCode = row.GetCell(1).NumericCellValue.ToString(); c.ProductCode = row.GetCell(8).StringCellValue; c.ProductName = row.GetCell(7).StringCellValue; c.Memo = row.GetCell(9).StringCellValue; c.ActiveDescription = row.GetCell(10).StringCellValue; c.ActiveStartDate = row.GetCell(11).DateCellValue; c.ActiveEndDate = row.GetCell(12).DateCellValue; c.CustomerOpenID = row.GetCell(13).StringCellValue; c.CustomerTime = row.GetCell(14).DateCellValue; c.CustomerLocatio = row.GetCell(15).StringCellValue; c.WhatActive = row.GetCell(16).StringCellValue; alist.Add(c); } string res = ReportFactory.Instance.SplitMongoInster <CustomerCode>(alist); if (res == "数据插入MongoDB失败") { Response.status = 0; this.Response.message = res + ",检查MongoDB是否正常"; return(Response); } } if (activeName == "消费者") { List <CustomerCode> alist = new List <CustomerCode>(); //第4行开始获取数据 for (int index = 3; index <= lastRowIndex; index++) { //获取当前行 row = sheet.GetRow(index); //生成Mongo对象存码信息 CustomerCode c = new CustomerCode(); c.ActiveName = activeName; c.CreateDate = row.GetCell(2).DateCellValue;; c.ApplyId = codeActive.ApplyId; c.CodeActivityId = activeID; c.CorpCode = codeActive.CorpCode; c.SubCorpCode = codeActive.SubCorpCode; c.CorpName = codeActive.CorpName; c.Code = row.GetCell(0).NumericCellValue.ToString(); //c.MaskCode = row.GetCell(1).NumericCellValue.ToString(); c.ProductCode = row.GetCell(8).StringCellValue; c.ProductName = row.GetCell(7).StringCellValue; c.Memo = row.GetCell(9).StringCellValue; c.ActiveDescription = row.GetCell(10).StringCellValue; c.ActiveStartDate = row.GetCell(11).DateCellValue; c.ActiveEndDate = row.GetCell(12).DateCellValue; c.CustomerOpenID = row.GetCell(13).StringCellValue; c.CustomerTime = row.GetCell(14).DateCellValue; c.CustomerLocatio = row.GetCell(15).StringCellValue; c.WhatActive = row.GetCell(16).StringCellValue; alist.Add(c); } string res = ReportFactory.Instance.SplitMongoInster <CustomerCode>(alist); if (res == "数据插入MongoDB失败") { Response.status = 0; this.Response.message = res + ",检查MongoDB是否正常"; return(Response); } } if (activeName == "资产") { List <PropertyCode> alist = new List <PropertyCode>(); //第4行开始获取数据 for (int index = 3; index <= lastRowIndex; index++) { //获取当前行 row = sheet.GetRow(index); //生成Mongo对象存码信息 PropertyCode c = new PropertyCode(); c.ActiveName = activeName; c.CreateDate = row.GetCell(2).DateCellValue; c.ApplyId = codeActive.ApplyId; c.CodeActivityId = activeID; c.CorpCode = codeActive.CorpCode; c.SubCorpCode = codeActive.SubCorpCode; c.CorpName = codeActive.CorpName; try { c.Code = row.GetCell(0).StringCellValue; } catch { c.Code = row.GetCell(0).NumericCellValue.ToString(); } //c.MaskCode = row.GetCell(1).NumericCellValue.ToString(); c.ProductCode = row.GetCell(8).StringCellValue; c.ProductName = row.GetCell(7).StringCellValue; c.Memo = row.GetCell(9).StringCellValue; c.ProductProvider = row.GetCell(17).StringCellValue; c.ProductPurcheseDate = row.GetCell(18).DateCellValue; alist.Add(c); } string res = ReportFactory.Instance.SplitMongoInster <PropertyCode>(alist); if (res == "数据插入MongoDB失败") { Response.status = 0; this.Response.message = res + ",检查MongoDB是否正常"; return(Response); } } if (activeName == "资产领用") { List <PropertyUseCode> alist = new List <PropertyUseCode>(); //第4行开始获取数据 for (int index = 3; index <= lastRowIndex; index++) { //获取当前行 row = sheet.GetRow(index); //生成Mongo对象存码信息 PropertyUseCode c = new PropertyUseCode(); c.ActiveName = activeName; c.CreateDate = row.GetCell(2).DateCellValue; c.ApplyId = codeActive.ApplyId; c.CodeActivityId = activeID; c.CorpCode = codeActive.CorpCode; c.SubCorpCode = codeActive.SubCorpCode; c.CorpName = codeActive.CorpName; try { c.Code = row.GetCell(0).StringCellValue; } catch { c.Code = row.GetCell(0).NumericCellValue.ToString(); } //c.MaskCode = row.GetCell(1).NumericCellValue.ToString(); c.ProductCode = row.GetCell(8).StringCellValue; c.ProductName = row.GetCell(7).StringCellValue; c.Memo = row.GetCell(9).StringCellValue; c.ClaimDepartment = row.GetCell(19).StringCellValue; c.ClaimPerson = row.GetCell(20).StringCellValue; c.ClaimDate = row.GetCell(21).DateCellValue; alist.Add(c); } string res = ReportFactory.Instance.SplitMongoInster <PropertyUseCode>(alist); if (res == "数据插入MongoDB失败") { Response.status = 0; this.Response.message = res + ",检查MongoDB是否正常"; return(Response); } } } //删除文件 System.IO.File.Delete(fullPath); Response.status = 1; Response.message = "上传成功"; } catch (Exception e) { Response.status = 0; Response.message = e.Message; } return(Response); }