Search in sources :

Example 1 with StaffSentiment

use of com.topcom.cms.yuqing.domain.StaffSentiment in project topcom-cloud by 545314690.

the class StaffSentimentController method searchOneStaff.

// 后期改用多线程查询,临时单线程查询
private StaffSentiment searchOneStaff(Staff staff, StaffSentimentRequest request) {
    StaffSentiment staffSentiment = new StaffSentiment();
    staffSentiment.setId(String.valueOf(staff.getId()));
    staffSentiment.setStaff(staff.toMap());
    BoolQueryRequest boolRequest = new BoolQueryRequest();
    boolRequest.setDate(request.getDate());
    boolRequest.setGroupName("nlp.sentiment.label");
    boolRequest.setKeyword(new Keyword(staff.getExpression()));
    PageRequest page = new PageRequest(1, 10);
    page.setOrders(request.getSortBy());
    boolRequest.setPage(page);
    boolRequest.setFiled(request.getFiled());
    boolRequest.setType(request.getArticleType());
    // 情感值
    Map kvMap = KV.kvList2Map(esManager.filterAndGroupBy(boolRequest));
    staffSentiment.setNEG((Long) (kvMap.get("NEG") == null ? 0 : kvMap.get("NEG")));
    staffSentiment.setNEU((Long) (kvMap.get("NEU") == null ? 0 : kvMap.get("NEU")));
    staffSentiment.setPOS((Long) (kvMap.get("POS") == null ? 0 : kvMap.get("POS")));
    // 总数 以及条新闻,最新?还是最负面?
    Page articlePage = esManager.findByMustShouldDateInType(boolRequest);
    if (articlePage.getTotalElements() > 0) {
        staffSentiment.setArticle((Map) articlePage.getContent().get(0));
        staffSentiment.setTotal(articlePage.getTotalElements());
        Long time = Long.valueOf(((Map) articlePage.getContent().get(0)).get("pubTime").toString());
        staffSentiment.setNewsDate(new Date(time));
    }
    return staffSentiment;
}
Also used : BoolQueryRequest(com.topcom.cms.es.vo.BoolQueryRequest) PageRequest(com.topcom.cms.common.page.PageRequest) Keyword(com.topcom.cms.es.vo.Keyword) StaffSentiment(com.topcom.cms.yuqing.domain.StaffSentiment) Page(org.springframework.data.domain.Page) Map(java.util.Map) Date(java.util.Date)

Example 2 with StaffSentiment

use of com.topcom.cms.yuqing.domain.StaffSentiment in project topcom-cloud by 545314690.

the class StaffSentimentController method getStaffSentimentByOTSId.

/**
 * 根据部门ID获取领导舆情列表
 * 缓存规则  根据部门id查询时,先查询redis有没有此id的数据,若有则查询mongo,
 * 若没有则查询es并存储到mongo中并在redis中做标记。redis缓存时间决定mongo中数据的有效期。
 * @return
 */
@RequestMapping(value = "/getStaffSentimentByOTSId/", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public Page<StaffSentiment> getStaffSentimentByOTSId(@RequestBody StaffSentimentRequest request) {
    Object o = redisTemplateUtils.getValue(request.toString());
    List<Long> staffIdList = new ArrayList<>();
    List<Staff> staffList = staffManager.findByOrganizationalStructureId(request.getOrganizationalStructureId());
    if (staffList == null || staffList.size() < 1) {
        return null;
    }
    for (int i = 0; i < staffList.size(); i++) {
        staffIdList.add(staffList.get(i).getId());
    }
    List<StaffSentiment> staffSentimentList = new ArrayList<>();
    if (o == null) {
        for (int i = 0; i < staffIdList.size(); i++) {
            Staff staff = staffManager.findById(staffIdList.get(i));
            staffSentimentList.add(searchOneStaff(staff, request));
        }
        redisTemplateUtils.saveValue(request.toString(), true, saveTime);
        staffSentimentManager.save(staffSentimentList);
    }
    return this.staffSentimentManager.findByIdIn(request.getPage().pageable(), staffIdList);
}
Also used : StaffSentiment(com.topcom.cms.yuqing.domain.StaffSentiment) Staff(com.topcom.cms.yuqing.domain.Staff) ArrayList(java.util.ArrayList) JSONObject(net.sf.json.JSONObject)

Aggregations

StaffSentiment (com.topcom.cms.yuqing.domain.StaffSentiment)2 PageRequest (com.topcom.cms.common.page.PageRequest)1 BoolQueryRequest (com.topcom.cms.es.vo.BoolQueryRequest)1 Keyword (com.topcom.cms.es.vo.Keyword)1 Staff (com.topcom.cms.yuqing.domain.Staff)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Map (java.util.Map)1 JSONObject (net.sf.json.JSONObject)1 Page (org.springframework.data.domain.Page)1