|
|
@@ -0,0 +1,201 @@
|
|
|
+package com.zhiqiyun.open.mvc.controller;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.zhiqiyun.open.annotation.Permission;
|
|
|
+import com.zhiqiyun.open.core.models.place.PlaceBaseInfo;
|
|
|
+import com.zhiqiyun.open.core.models.place.PlaceCategory;
|
|
|
+import com.zhiqiyun.open.core.models.sentiment.SentimentSpiderEvent;
|
|
|
+import com.zhiqiyun.open.core.models.sentiment.SentimentSpiderSiteRule;
|
|
|
+import com.zhiqiyun.open.core.models.user.OauthInfo;
|
|
|
+import com.zhiqiyun.open.core.service.OauthService;
|
|
|
+import com.zhiqiyun.open.core.service.SentimentSpiderEventService;
|
|
|
+import com.zhiqiyun.open.core.service.SentimentSpiderRuleService;
|
|
|
+import com.zhiqiyun.open.core.service.SequenceService;
|
|
|
+import com.zhiqiyun.open.mvc.Result;
|
|
|
+import com.zhiqiyun.open.mvc.params.sentiment.QuerySpiderEventParam;
|
|
|
+import com.zhiqiyun.open.mvc.params.sentiment.QuerySpiderSiteRuleParam;
|
|
|
+import com.zhiqiyun.open.mvc.params.sentiment.SaveSpiderEventParam;
|
|
|
+import com.zhiqiyun.open.mvc.params.sentiment.SaveSpiderSiteRuleParam;
|
|
|
+import com.zhiqiyun.open.utils.DateUtil;
|
|
|
+import com.zhiqiyun.open.utils.ServletContext;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.validation.Valid;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/sentiment/spider")
|
|
|
+public class SentimentSpiderController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SentimentSpiderEventService sentimentSpiderEventService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SentimentSpiderRuleService sentimentSpiderRuleService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private OauthService oauthService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SequenceService sequenceService;
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.rule.find", tags = "查询采集网站规则")
|
|
|
+ @PostMapping("/rule/findPage")
|
|
|
+ public Result findRulePage(@RequestBody QuerySpiderSiteRuleParam param) {
|
|
|
+ QueryWrapper<SentimentSpiderSiteRule> wrapper = new QueryWrapper<>();
|
|
|
+ if (StringUtils.isNotBlank(param.getSiteName())) {
|
|
|
+ wrapper.like("site_name", param.getSiteName());
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<SentimentSpiderSiteRule> page = param.getPage();
|
|
|
+ page.addOrder(OrderItem.desc("id"));
|
|
|
+
|
|
|
+ Page<SentimentSpiderSiteRule> resultData = this.sentimentSpiderRuleService.page(page, wrapper);
|
|
|
+
|
|
|
+ return Result.instance(Result.Code.SUCCESS).setData(resultData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @ResponseBody
|
|
|
+ @PostMapping("/rule/findSelectByKeyword")
|
|
|
+ public Result findSelectByKeyword(String keyword) {
|
|
|
+ QueryWrapper<SentimentSpiderSiteRule> queryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(keyword)) {
|
|
|
+ queryWrapper.like("site_name", keyword);
|
|
|
+ queryWrapper.or();
|
|
|
+ queryWrapper.like("id", keyword);
|
|
|
+ }
|
|
|
+ queryWrapper.last("limit 10");
|
|
|
+ queryWrapper.orderByDesc("id");
|
|
|
+
|
|
|
+ List<SentimentSpiderSiteRule> listData = this.sentimentSpiderRuleService.list(queryWrapper);
|
|
|
+ return Result.instance(Result.Code.SUCCESS).setData(listData);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.rule.add", tags = "添加采集网站规则")
|
|
|
+ @PostMapping("/rule/save")
|
|
|
+ public Result saveRule(@Valid @RequestBody SaveSpiderSiteRuleParam param) throws Exception {
|
|
|
+
|
|
|
+ SentimentSpiderSiteRule entity = new SentimentSpiderSiteRule();
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+
|
|
|
+ OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
|
|
|
+
|
|
|
+ entity.setCreatedTime(DateUtil.current());
|
|
|
+ entity.setCreatedBy(oauthInfo.getId());
|
|
|
+
|
|
|
+ entity.setUpdatedTime(DateUtil.current());
|
|
|
+ entity.setUpdatedBy(oauthInfo.getId());
|
|
|
+ entity.setId(this.sequenceService.nextId());
|
|
|
+
|
|
|
+ this.sentimentSpiderRuleService.save(entity);
|
|
|
+
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.rule.edit", tags = "修改采集网站规则")
|
|
|
+ @PostMapping("/rule/updateById")
|
|
|
+ public Result updateRuleById(Long id, @Valid @RequestBody SaveSpiderSiteRuleParam param) {
|
|
|
+ SentimentSpiderSiteRule entity = new SentimentSpiderSiteRule();
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+
|
|
|
+ OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
|
|
|
+
|
|
|
+ entity.setUpdatedBy(oauthInfo.getId());
|
|
|
+ entity.setUpdatedTime(DateUtil.current());
|
|
|
+ entity.setId(id);
|
|
|
+
|
|
|
+ this.sentimentSpiderRuleService.updateById(entity);
|
|
|
+
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.rule.delete", tags = "采集网站规则删除")
|
|
|
+ @PostMapping("/rule/deleteByIds")
|
|
|
+ public Result deleteRuleByIds(@RequestBody List<Long> ids) {
|
|
|
+ this.sentimentSpiderRuleService.removeByIds(ids);
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.event.find", tags = "查询舆情事件")
|
|
|
+ @PostMapping("/event/findPage")
|
|
|
+ public Result findEventPage(@RequestBody QuerySpiderEventParam param) {
|
|
|
+ QueryWrapper<SentimentSpiderEvent> wrapper = new QueryWrapper<>();
|
|
|
+ if (param.getSiteRuleId() != null) {
|
|
|
+ wrapper.eq("site_rule_id", param.getSiteRuleId());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(param.getEventTitle())) {
|
|
|
+ wrapper.like("event_title", param.getEventTitle());
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(param.getKeywords())) {
|
|
|
+ wrapper.like("keywords", param.getKeywords());
|
|
|
+ }
|
|
|
+
|
|
|
+ Page<SentimentSpiderEvent> page = param.getPage();
|
|
|
+ page.addOrder(OrderItem.desc("id"));
|
|
|
+
|
|
|
+ Page<SentimentSpiderEvent> resultData = this.sentimentSpiderEventService.page(page, wrapper);
|
|
|
+ for (SentimentSpiderEvent event : resultData.getRecords()) {
|
|
|
+ SentimentSpiderSiteRule rule = this.sentimentSpiderRuleService.getById(event.getSiteRuleId());
|
|
|
+ event.setRule(rule);
|
|
|
+ event.setStatus(this.sentimentSpiderEventService.getStatus(event.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return Result.instance(Result.Code.SUCCESS).setData(resultData);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.event.add", tags = "添加采集网站规则")
|
|
|
+ @PostMapping("/event/save")
|
|
|
+ public Result saveEvent(@Valid @RequestBody SaveSpiderEventParam param) throws Exception {
|
|
|
+
|
|
|
+ SentimentSpiderEvent entity = new SentimentSpiderEvent();
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+
|
|
|
+ OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
|
|
|
+
|
|
|
+ entity.setCreatedTime(DateUtil.current());
|
|
|
+ entity.setCreatedBy(oauthInfo.getId());
|
|
|
+
|
|
|
+ entity.setUpdatedTime(DateUtil.current());
|
|
|
+ entity.setUpdatedBy(oauthInfo.getId());
|
|
|
+ entity.setId(this.sequenceService.nextId());
|
|
|
+
|
|
|
+ this.sentimentSpiderEventService.save(entity);
|
|
|
+
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.event.edit", tags = "修改采集网站规则")
|
|
|
+ @PostMapping("/event/updateById")
|
|
|
+ public Result updateRuleById(Long id, @Valid @RequestBody SaveSpiderEventParam param) {
|
|
|
+ SentimentSpiderEvent entity = new SentimentSpiderEvent();
|
|
|
+ BeanUtils.copyProperties(param, entity);
|
|
|
+
|
|
|
+ OauthInfo oauthInfo = this.oauthService.getAuth(ServletContext.getAccessToken());
|
|
|
+
|
|
|
+ entity.setUpdatedBy(oauthInfo.getId());
|
|
|
+ entity.setUpdatedTime(DateUtil.current());
|
|
|
+ entity.setId(id);
|
|
|
+
|
|
|
+ this.sentimentSpiderEventService.updateById(entity);
|
|
|
+
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Permission(value = "sentiment.spider.event.delete", tags = "采集网站规则删除")
|
|
|
+ @PostMapping("/event/deleteByIds")
|
|
|
+ public Result deleteEventByIds(@RequestBody List<Long> ids) {
|
|
|
+ this.sentimentSpiderEventService.removeByIds(ids);
|
|
|
+ return Result.instance(Result.Code.MESSAGE_SUCCESS);
|
|
|
+ }
|
|
|
+}
|