package com.zhiqiyun.open.router.apis; 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.dliyun.oap.framework.annotation.ServiceMethod; import com.dliyun.oap.framework.annotation.ServiceMethodBean; import com.dliyun.oap.framework.response.OapResponse; import com.zhiqiyun.open.annotation.Permission; import com.zhiqiyun.open.core.models.statistics.PopularFeelings; import com.zhiqiyun.open.core.models.statistics.PopularFeelingsPage; import com.zhiqiyun.open.core.service.PopularFeelingsPageService; import com.zhiqiyun.open.core.service.PopularFeelingsService; import com.zhiqiyun.open.core.service.SequenceService; import com.zhiqiyun.open.mvc.Result; import com.zhiqiyun.open.mvc.params.statistics.QueryPopularFeelingsPageParam; import com.zhiqiyun.open.router.request.statistics.*; import com.zhiqiyun.open.utils.DateUtil; 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.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import java.util.List; @Slf4j @ServiceMethodBean public class PopularFeelingsApi { @Autowired private PopularFeelingsPageService popularFeelingsPageService; @Autowired private PopularFeelingsService popularFeelingsService; @Autowired private SequenceService sequenceService; @ServiceMethod(method = "popular.feelings.findPage", title = "互联网舆情监控查询") public OapResponse findPage(QueryPopularFeelingsRequest request) { QueryWrapper wrapper = new QueryWrapper<>(); if (StringUtils.isNotBlank(request.getTitle())) { wrapper.like("title", request.getTitle()); } if (StringUtils.isNotBlank(request.getKeywords())) { wrapper.like("keywords", request.getKeywords()); } if (StringUtils.isNotBlank(request.getDomain())) { wrapper.like("domain", request.getDomain()); } Page page = new Page<>(request.getCurrent(), request.getPageSize()); page.addOrder(OrderItem.desc("id")); Page resultData = this.popularFeelingsService.page(page, wrapper); return OapResponse.success().setBody(resultData); } @ServiceMethod(method = "popular.feelings.add", title = "新建舆情监控") public OapResponse save(SavePopularFeelingsRequest request) { PopularFeelings entity = new PopularFeelings(); BeanUtils.copyProperties(request, entity); entity.setCreatedTime(DateUtil.current()); entity.setCreatedBy(1000L); entity.setUpdatedTime(DateUtil.current()); entity.setUpdatedBy(1000L); entity.setId(this.sequenceService.nextId()); this.popularFeelingsService.save(entity); return OapResponse.success().setBody(entity); } @ServiceMethod(method = "popular.feelings.updateById", title = "更新舆情监控") public OapResponse updateById(UpdatePopularFeelingsRequest request) { PopularFeelings entity = new PopularFeelings(); BeanUtils.copyProperties(request, entity); entity.setUpdatedBy(1000L); entity.setUpdatedTime(DateUtil.current()); this.popularFeelingsService.updateById(entity); return OapResponse.success().setBody(entity); } @ServiceMethod(method = "popular.feelings.deleteByIds", title = "删除舆情监控") public OapResponse deleteByIds(PopularFeelingsIdsRequest request) { this.popularFeelingsService.removeByIds(request.getIds()); return OapResponse.success(); } @ServiceMethod(method = "popular.feelings.start", title = "启动舆情监控") public OapResponse startSpider(PopularFeelingsIdsRequest request) { List listData = this.popularFeelingsService.listByIds(request.getIds()); for (PopularFeelings popularFeelings : listData) { this.popularFeelingsService.start(popularFeelings); } return OapResponse.success(); } @ServiceMethod(method = "popular.feelings.stop", title = "停止舆情监控") public OapResponse stopSpider(PopularFeelingsIdsRequest request) { List listData = this.popularFeelingsService.listByIds(request.getIds()); for (PopularFeelings popularFeelings : listData) { this.popularFeelingsService.stop(popularFeelings); } return OapResponse.success(); } @ServiceMethod(method = "popular.feelings.findDetailPage", title = "分页查询舆情监控详情") public OapResponse findDetailPage(QueryPopularFeelingsDetailPageRequest request) { QueryWrapper wrapper = new QueryWrapper<>(); wrapper.select("id", "popular_feelings_id", "url", "title", "spider_time"); wrapper.eq("popular_feelings_id", request.getPopularFeelingsId()); Page page = new Page<>(request.getCurrent(), request.getPageSize()); page.addOrder(OrderItem.desc("id")); Page resultData = this.popularFeelingsPageService.page(page, wrapper); return OapResponse.success().setBody(resultData); } }