using System.Collections; using System.Text.RegularExpressions; using System.Web; using Common; using Infrastructure; using LitJson; using Microsoft.CodeAnalysis.CSharp.Scripting; using Model; using Services; namespace Tasks { public class MakeHelper { public readonly static MakeHelper Instance = new MakeHelper(); private MakeHelper() { } public void Start(string QueueName) { RabbitMQClient.Instance.StartReceive(QueueName, content => DoWorks(content)); } public void DoWorks(string content) { if (!string.IsNullOrEmpty(content)) { DoQueue(content); } } public void DoQueue(string content) { try { // Utils.WriteLog(DateTime.Now.ToString() + "\n" + content, "生成接收"); JsonData jsonObj = JsonMapper.ToObject(content); //流水号 string requestId = jsonObj["requestId"].ToString(); //模板文件路径 string modePath = jsonObj["modePath"].ToString(); // if(modePath.Contains("controller") && content.Contains("DoubleAward")) // { // string packageName = "123123123"; // } //附加数据,原样返回 string attach = jsonObj["attach"].ToString(); //读取模板文件内容 // string templateString = Function.ReadInstance("Template/" + modePath + ".json"); var templateService = App.GetRequiredService(); var template = templateService.GetFirst(m => m.templateName == modePath); if(template == null) return; string templateString = template.templateContent; templateString = HttpUtility.UrlDecode(templateString); //解析模板内容 string resultString = Util.Maker.StartMake(jsonObj["data"], templateString); resultString = Util.Maker.replaceKeyToValue(jsonObj["data"], resultString); //生成文件 string path = template.makePath.Substring(0, template.makePath.LastIndexOf("/") + 1); string fileName = template.makePath.Substring(template.makePath.LastIndexOf("/") + 1); path = Util.Maker.replaceKeyToValue(jsonObj["data"], path); fileName = Util.Maker.replaceKeyToValue(jsonObj["data"], fileName); Function.WritePage(path, fileName, resultString); //生成数据入库 JsonData data = JsonMapper.ToObject(attach); int dataId = 0; if(attach.Contains("dataId")) dataId = int.Parse(Function.CheckInt(data["dataId"].ToString())); string makeFileType = data["fileType"].ToString(); var makeDataService = App.GetRequiredService(); var item = makeDataService.GetFirst(m => m.dataId == dataId && m.makeFileType == makeFileType); if(item == null) { makeDataService.Add(new MakeData() { dataId = dataId, makeFileName = fileName, makeFilePath = path, makeFileType = makeFileType, createTime = DateTime.Now, createBy = data["createBy"].ToString() }); } else { item.makeFileName = fileName; item.makeFilePath = path; item.updateTime = DateTime.Now; item.updateBy = data["createBy"].ToString(); makeDataService.Update(item); } } catch (Exception ex) { Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex, "生成异常"); } //MQ回调解析的结果 // RabbitMQClient.Instance.Push("MakeSqlCallBackQueue", requestId + "#cut#" + attach + "#cut#" + resultString); } } }