use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class BriefingCreatorImpl method createAttachment.
/**
* 创建附件
*
* @param json
* @param fileType
* @return
* @throws Exception
*/
private String createAttachment(JSONObject json, String fileType) throws Exception {
String title = json.getString("title");
String issue = json.getString("issue");
String filename = title + issue + System.currentTimeMillis() + "." + fileType;
File file = new File(filepath, filename);
Map<String, Object> dataMap = new HashMap<String, Object>();
String outLine = json.getString("outline");
if (!StringUtils.isEmpty(outLine)) {
// 过滤html标签,只保留文本
outLine = Jsoup.clean(outLine, Whitelist.none());
json.put("outline", outLine);
}
dataMap.put("briefing", json);
FreemarkerUtil.processTemplateIntoFile(dataMap, file, "briefing_" + fileType + ".ftl");
return filename.replace(filepath, "");
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class BriefingCreatorImpl method saveBriefingToMongo.
/**
* 报存专报到mongodb
*
* @param briefing
* @return
*/
public Boolean saveBriefingToMongo(JSONObject briefing) {
try {
DBObject dbObject = (DBObject) JSON.parse(briefing.toString());
Date endDate = new Date();
if (briefing.get("dateCreated") != null) {
endDate.setTime((Long) briefing.get("dateCreated"));
}
dbObject.put("dateCreated", endDate);
dbObject.put("dateModified", endDate);
Long userId = briefing.getLong("userId");
User currentUser = userManager.findById(userId);
dbObject.put("author", currentUser.getFullName() == null ? currentUser.getUsername() : currentUser.getFullName());
JSONObject json = JSONObject.fromObject(dbObject);
String attachment_doc = null;
attachment_doc = createAttachment(json, "doc");
String attachment_html = createAttachment(json, "html");
if (attachment_doc != null && attachment_html != null) {
dbObject.put("attachment", new String[] { attachment_doc, attachment_html });
}
MongoDBUtil.insertDocument(Constants.Mongo.COLLECTION_BRIEFING, dbObject);
} catch (Exception e) {
e.printStackTrace();
String message = "生成报告失败";
LogUtil.logger.error(message);
return false;
}
String message = "生成报告成功@";
LogUtil.logger.info(message);
return true;
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class BriefingCreatorImpl method createSpecial.
@Override
public Future createSpecial(CustomSubject customSubject) throws ExecutionException, InterruptedException {
FutureTask<Boolean> task = new FutureTask<>(() -> {
LogUtil.logger.info("----------------专报分析开始:" + customSubject.getId() + "---------------------");
String id = customSubject.getId().toString();
String mustWord = customSubject.getMustWord();
String shouldWord = customSubject.getShouldWord();
String mustNotWord = customSubject.getMustNotWord();
Long startTime = customSubject.getStartDate().getTime();
Long endTime = customSubject.getEndDate().getTime();
String subjectName = customSubject.getName();
String briefingString = requestBriefingString(Briefing.BriefingType.SPECIAL, mustWord, shouldWord, mustNotWord, startTime, endTime, subjectName);
JSONObject jsonObject = JSONObject.fromObject(briefingString);
jsonObject.put("subjectId", Long.valueOf(id));
jsonObject.put("userId", customSubject.getUserId());
boolean status = saveBriefingToMongo(jsonObject);
// 更新状态
subjectManager.updateState(customSubject.getId(), CustomSubject.State.COMPLETED);
LogUtil.logger.info("----------------专报分析完成:" + customSubject.getId() + "---------------------");
return status;
});
executorService.submit(task);
return task;
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class DataXUtil method main.
public static void main(String[] args) throws Exception {
Map map = new HashMap();
Map json = new HashMap();
json.put("a", "123");
json.put("b", "1234");
JSONObject jsonObject = JSONObject.fromObject(json);
DataXUtil.runJob(jsonObject, json);
}
use of net.sf.json.JSONObject in project topcom-cloud by 545314690.
the class ESEntityHandleThread method saveJson.
private void saveJson(String yuqing, String article, List<JSONObject> jsonObjects) {
Client client = elasticsearchTemplate.getClient();
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
for (int i = 0; i < jsonObjects.size(); i++) {
JSONObject jsonObject = jsonObjects.get(i);
IndexRequestBuilder indexRequestBuilder = client.prepareIndex(yuqing, article).setSource(jsonObject.toString()).setId(jsonObject.get("id").toString());
bulkRequestBuilder.add(indexRequestBuilder);
}
bulkRequestBuilder.execute().actionGet();
}
Aggregations