|
|
@@ -23,69 +23,71 @@ namespace Tasks
|
|
|
|
|
|
public void DoWorks(string content)
|
|
|
{
|
|
|
- try
|
|
|
+ if (!string.IsNullOrEmpty(content))
|
|
|
{
|
|
|
- if (!string.IsNullOrEmpty(content))
|
|
|
- {
|
|
|
- DoQueue(content);
|
|
|
- }
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex, "生成异常");
|
|
|
+ DoQueue(content);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public async void DoQueue(string content)
|
|
|
{
|
|
|
- JsonData jsonObj = JsonMapper.ToObject(content);
|
|
|
- //流水号
|
|
|
- string requestId = jsonObj["requestId"].ToString();
|
|
|
- //模板文件路径
|
|
|
- string modePath = jsonObj["modePath"].ToString();
|
|
|
- //附加数据,原样返回
|
|
|
- string attach = jsonObj["attach"].ToString();
|
|
|
- //读取模板文件内容
|
|
|
- // string templateString = Function.ReadInstance("Template/" + modePath + ".json");
|
|
|
- var templateService = App.GetRequiredService<IMakeTemplateService>();
|
|
|
- var template = templateService.GetFirst(m => m.templateName == modePath);
|
|
|
- if(template == null) return;
|
|
|
- string templateString = template.templateContent;
|
|
|
- templateString = HttpUtility.UrlDecode(templateString);
|
|
|
- //解析模板内容
|
|
|
- string resultString = await Util.Maker.StartMake(jsonObj["data"], templateString);
|
|
|
- //生成文件
|
|
|
- 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<IMakeDataService>();
|
|
|
- var item = makeDataService.GetFirst(m => m.dataId == dataId && m.makeFileType == makeFileType);
|
|
|
- if(item == null)
|
|
|
+ try
|
|
|
{
|
|
|
- makeDataService.Add(new MakeData()
|
|
|
+ Utils.WriteLog(DateTime.Now.ToString() + "\n" + content, "生成接收");
|
|
|
+ JsonData jsonObj = JsonMapper.ToObject(content);
|
|
|
+ //流水号
|
|
|
+ string requestId = jsonObj["requestId"].ToString();
|
|
|
+ //模板文件路径
|
|
|
+ string modePath = jsonObj["modePath"].ToString();
|
|
|
+ //附加数据,原样返回
|
|
|
+ string attach = jsonObj["attach"].ToString();
|
|
|
+ //读取模板文件内容
|
|
|
+ // string templateString = Function.ReadInstance("Template/" + modePath + ".json");
|
|
|
+ var templateService = App.GetRequiredService<IMakeTemplateService>();
|
|
|
+ var template = templateService.GetFirst(m => m.templateName == modePath);
|
|
|
+ if(template == null) return;
|
|
|
+ string templateString = template.templateContent;
|
|
|
+ templateString = HttpUtility.UrlDecode(templateString);
|
|
|
+ //解析模板内容
|
|
|
+ string resultString = await 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<IMakeDataService>();
|
|
|
+ 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
|
|
|
{
|
|
|
- dataId = dataId,
|
|
|
- makeFileName = fileName,
|
|
|
- makeFilePath = path,
|
|
|
- makeFileType = makeFileType,
|
|
|
- createTime = DateTime.Now,
|
|
|
- createBy = data["createBy"].ToString()
|
|
|
- });
|
|
|
+ item.makeFileName = fileName;
|
|
|
+ item.makeFilePath = path;
|
|
|
+ item.updateTime = DateTime.Now;
|
|
|
+ item.updateBy = data["createBy"].ToString();
|
|
|
+ makeDataService.Update(item);
|
|
|
+ }
|
|
|
}
|
|
|
- else
|
|
|
+ catch (Exception ex)
|
|
|
{
|
|
|
- item.makeFileName = fileName;
|
|
|
- item.makeFilePath = path;
|
|
|
- item.updateTime = DateTime.Now;
|
|
|
- item.updateBy = data["createBy"].ToString();
|
|
|
- makeDataService.Update(item);
|
|
|
+ Utils.WriteLog(DateTime.Now.ToString() + "\n" + ex, "生成异常");
|
|
|
}
|
|
|
//MQ回调解析的结果
|
|
|
// RabbitMQClient.Instance.Push("MakeSqlCallBackQueue", requestId + "#cut#" + attach + "#cut#" + resultString);
|