stjdydayou 4 år sedan
förälder
incheckning
6f93c8b2fe

+ 1 - 1
pom.xml

@@ -35,7 +35,7 @@
         <afirma-lib-jmimemagic.version>0.0.6</afirma-lib-jmimemagic.version>
         <thumbnailator.version>0.4.16</thumbnailator.version>
 
-        <framework.version>1.0.18</framework.version>
+        <framework.version>1.0.19</framework.version>
         <db-migration.version>1.0.0</db-migration.version>
     </properties>
 

+ 13 - 6
src/main/java/com/zhiqiyun/open/core/service/PopularFeelingsService.java

@@ -7,11 +7,18 @@ import com.zhiqiyun.open.core.models.statistics.PopularFeelings;
  * @author jtoms
  */
 public interface PopularFeelingsService extends IService<PopularFeelings> {
-    /**
-     * 启动采集
-     *
-     * @param popular
-     */
-    void start(PopularFeelings popular);
+	/**
+	 * 启动采集
+	 *
+	 * @param popular
+	 */
+	void start(PopularFeelings popular);
+
+	/**
+	 * 停止采集
+	 *
+	 * @param popular
+	 */
+	void stop(PopularFeelings popular);
 
 }

+ 5 - 0
src/main/java/com/zhiqiyun/open/core/service/impl/PopularFeelingsServiceImpl.java

@@ -51,6 +51,11 @@ public class PopularFeelingsServiceImpl extends ServiceImpl<PopularFeelingsMappe
         spider.runAsync();
     }
 
+    @Override
+    public void stop(PopularFeelings popular) {
+
+    }
+
     static class PopularFeelingsProcessor implements PageProcessor {
         private final List<String> LIST_SPIDER_URLS = new ArrayList<>();
 

+ 1 - 0
src/main/java/com/zhiqiyun/open/mvc/controller/PopularFeelingsController.java

@@ -135,6 +135,7 @@ public class PopularFeelingsController {
     public Result findDetailPage(@RequestBody QueryPopularFeelingsPageParam param) {
 
         QueryWrapper<PopularFeelingsPage> wrapper = new QueryWrapper<>();
+        wrapper.select("id", "popular_feelings_id", "url", "title", "spider_time");
         wrapper.eq("popular_feelings_id", param.getPopularFeelingsId());
 
         Page<PopularFeelingsPage> page = param.getPage();

+ 110 - 18
src/main/java/com/zhiqiyun/open/router/apis/PopularFeelingsApi.java

@@ -1,42 +1,134 @@
 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.core.models.UploadResult;
-import com.zhiqiyun.open.core.service.UploadFileInfoService;
-import com.zhiqiyun.open.router.request.UploaderBase64Request;
+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.codec.binary.Base64;
-import org.apache.commons.codec.digest.DigestUtils;
 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.io.IOException;
+import java.util.List;
 
 @Slf4j
 @ServiceMethodBean
 public class PopularFeelingsApi {
+
+	@Autowired
+	private PopularFeelingsPageService popularFeelingsPageService;
+
+	@Autowired
+	private PopularFeelingsService popularFeelingsService;
+
 	@Autowired
-	private UploadFileInfoService uploadFileInfoService;
+	private SequenceService sequenceService;
 
-	@ServiceMethod(method = "uploader.handle.base64File", title = "文件上传")
-	public OapResponse handleBase64File(@RequestBody UploaderBase64Request request) throws IOException {
+	@ServiceMethod(method = "popular.feelings.findPage", title = "互联网舆情监控查询")
+	public OapResponse findPage(QueryPopularFeelingsRequest request) {
 
-		byte[] fileBuff = Base64.decodeBase64(request.getBase64File());
+		QueryWrapper<PopularFeelings> wrapper = new QueryWrapper<>();
+
+		if (StringUtils.isNotBlank(request.getTitle())) {
+			wrapper.like("title", request.getTitle());
+		}
+
+		if (StringUtils.isNotBlank(request.getKeywords())) {
+			wrapper.like("keywords", request.getKeywords());
+		}
 
-		String originalFilename = request.getFilename();
-		if (StringUtils.isBlank(originalFilename)) {
-			originalFilename = String.format("%s.%s", DigestUtils.md5Hex(fileBuff), "png");
+		if (StringUtils.isNotBlank(request.getDomain())) {
+			wrapper.like("domain", request.getDomain());
 		}
 
-		UploadResult uploadResult = this.uploadFileInfoService.handle(originalFilename, fileBuff);
+		Page<PopularFeelings> page = new Page<>(request.getCurrent(), request.getPageSize());
+		page.addOrder(OrderItem.desc("id"));
+
+		Page<PopularFeelings> 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());
 
-		if (uploadResult.isSuccess()) {
-			return OapResponse.success().setBody(uploadResult);
-		} else {
-			return OapResponse.fail("UPLOAD_FAIL", uploadResult.getMessage());
+		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<PopularFeelings> 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<PopularFeelings> 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<PopularFeelingsPage> wrapper = new QueryWrapper<>();
+		wrapper.select("id", "popular_feelings_id", "url", "title", "spider_time");
+		wrapper.eq("popular_feelings_id", request.getPopularFeelingsId());
+
+		Page<PopularFeelingsPage> page = new Page<>(request.getCurrent(), request.getPageSize());
+		page.addOrder(OrderItem.desc("id"));
+
+		Page<PopularFeelingsPage> resultData = this.popularFeelingsPageService.page(page, wrapper);
+
+		return OapResponse.success().setBody(resultData);
 	}
 }

+ 18 - 0
src/main/java/com/zhiqiyun/open/router/request/statistics/PopularFeelingsIdsRequest.java

@@ -0,0 +1,18 @@
+package com.zhiqiyun.open.router.request.statistics;
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotEmpty;
+import java.util.List;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class PopularFeelingsIdsRequest extends AbstractOapRequest {
+	@NotEmpty
+	@ServiceParamField(describe = "ID数组")
+	private List<Long> ids;
+}

+ 29 - 0
src/main/java/com/zhiqiyun/open/router/request/statistics/QueryPopularFeelingsDetailPageRequest.java

@@ -0,0 +1,29 @@
+package com.zhiqiyun.open.router.request.statistics;
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import com.zhiqiyun.open.mvc.params.QueryPageParams;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+
+/**
+ * @author jtoms
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class QueryPopularFeelingsDetailPageRequest extends AbstractOapRequest {
+	@NotNull
+	@ServiceParamField(describe = "页数")
+	private Integer current = 1;
+
+	@NotNull
+	@ServiceParamField(describe = "每页条数")
+	private Integer pageSize = 10;
+
+	@NotNull
+	@ServiceParamField(describe = "舆情ID")
+	private Long popularFeelingsId;
+}

+ 29 - 0
src/main/java/com/zhiqiyun/open/router/request/statistics/QueryPopularFeelingsRequest.java

@@ -0,0 +1,29 @@
+package com.zhiqiyun.open.router.request.statistics;
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class QueryPopularFeelingsRequest extends AbstractOapRequest {
+	@NotBlank
+	@ServiceParamField(describe = "页数")
+	private Integer current = 1;
+
+	@NotBlank
+	@ServiceParamField(describe = "每页条数")
+	private Integer pageSize = 10;
+
+	@ServiceParamField(describe = "标题(模糊查询)")
+	private String title;
+
+	@ServiceParamField(describe = "舆论关键词(模糊查询)")
+	private String keywords;
+
+	@ServiceParamField(describe = "监控网站域名(模糊查询)")
+	private String domain;
+}

+ 30 - 0
src/main/java/com/zhiqiyun/open/router/request/statistics/SavePopularFeelingsRequest.java

@@ -0,0 +1,30 @@
+package com.zhiqiyun.open.router.request.statistics;
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author jtoms
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class SavePopularFeelingsRequest extends AbstractOapRequest {
+	@NotBlank
+	@ServiceParamField(describe = "网站名称")
+	private String siteName;
+	@NotBlank
+	@ServiceParamField(describe = "监控词")
+	private String keywords;
+	@NotBlank
+	@ServiceParamField(describe = "监控域名")
+	private String domain;
+	@NotNull
+	@ServiceParamField(describe = "启动域名")
+	private List<String> startUrls;
+}

+ 33 - 0
src/main/java/com/zhiqiyun/open/router/request/statistics/UpdatePopularFeelingsRequest.java

@@ -0,0 +1,33 @@
+package com.zhiqiyun.open.router.request.statistics;
+
+import com.dliyun.oap.framework.annotation.ServiceParamField;
+import com.dliyun.oap.framework.request.AbstractOapRequest;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import javax.validation.constraints.NotBlank;
+import javax.validation.constraints.NotNull;
+import java.util.List;
+
+/**
+ * @author jtoms
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class UpdatePopularFeelingsRequest extends AbstractOapRequest {
+	@NotNull
+	@ServiceParamField(describe = "ID")
+	private Long id;
+	@NotBlank
+	@ServiceParamField(describe = "网站名称")
+	private String siteName;
+	@NotBlank
+	@ServiceParamField(describe = "监控词")
+	private String keywords;
+	@NotBlank
+	@ServiceParamField(describe = "监控域名")
+	private String domain;
+	@NotNull
+	@ServiceParamField(describe = "启动域名")
+	private List<String> startUrls;
+}

+ 17 - 13
src/test/java/com/zhiqiyun/TestSdk.java

@@ -5,23 +5,27 @@ import com.dliyun.AlgorithmType;
 import com.dliyun.DefaultClient;
 import com.dliyun.Response;
 
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
 public class TestSdk {
-    public static void main(String[] args) throws Exception {
-        DefaultClient client = new DefaultClient(
-                "http://127.0.0.1:9800/router",
-                "220118010121",
-                "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCjgdx7EA9femto4A1MXYy1Ycs0ZmqrE1FYqgpEplh0VYbIhhTauXZxxxs07NO7GjL9mCa+WqmSNkZq1/UcqYj3yM7ATyWKDTJUpxoEX9Asr3uyECsRthiq688unhsavcNY54kEjFFXoE/sNnPTkzsbidVgi8gWjbTGUiIOVGTeAQIDAQAB",
-                AlgorithmType.RSA
-        );
-        Map<String, Object> form1 = new HashMap<>();
-//        form1.put("userName", "13666666666");
+	public static void main(String[] args) throws Exception {
+		DefaultClient client = new DefaultClient(
+				"http://127.0.0.1:9800/router",
+				"220228000055",
+				"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCMbziui2H+WBpd0TbA7tNrqnk5X0ecoqD5PZjnRscwQ88Q0STqyOe2PE6LjFPG9mQOOhKAJqbZRPeyzXuLIGlMrUZ2BmAl488n5mxkO24DPnC42/1OTHWjOjRHndPA/IyuEzv7lVkhMTj9hkoxz45yP3s/O/kUSgYH9FkF/wl2MQIDAQAB\n",
+				AlgorithmType.RSA
+		);
+		Map<String, Object> form1 = new HashMap<>();
+		form1.put("siteName", "1");
+		form1.put("keywords", "2");
+		form1.put("domain", "www.188420.com");
+		form1.put("startUrls", Arrays.asList("https://www.188420.com", "https://www.1234.com"));
 //        form1.put("password", "admin");
-        form1.put("accessToken", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0ZW5hbnRfaWQiOiIxMDQ3ODQiLCJ1c2VyX25hbWUiOiIxMzY2NjY2NjY2NiIsInJlYWxfbmFtZSI6ImFkbWluIiwiYXZhdGFyIjoiIiwiYXV0aG9yaXRpZXMiOlsiYWRtaW4iXSwiY2xpZW50X2lkIjoic2FiZXIiLCJyb2xlX25hbWUiOiJhZG1pbiIsImxpY2Vuc2UiOiJwb3dlcmVkIGJ5IGJsYWRleCIsImFjY291bnRfaWQiOiIxNDg0MTI3ODYwMzI5NDcyMDAxIiwicG9zdF9pZCI6IjE0ODQxMjc4NTk2MzcxNTc4ODkiLCJ1c2VyX2lkIjoiMTQ4NDEyNzg2MDI0MTM5MTYxOCIsInJvbGVfaWQiOiIxNDg0MTI3ODU3MzUxMjYyMjEwIiwic2NvcGUiOlsiYWxsIl0sIm5pY2tfbmFtZSI6ImFkbWluIiwib2F1dGhfaWQiOiIiLCJkZXRhaWwiOnsidHlwZSI6IndlYiJ9LCJleHAiOjE2NDI3NzUwMDIsImRlcHRfaWQiOiIxNDg0MTI3ODU5NjIwMzgwNjc0IiwianRpIjoiMzE5MTQyMTQtMzA2ZS00OGZiLWE1YzYtNWQwMDZmN2YwYjRlIiwiYWNjb3VudCI6IjEzNjY2NjY2NjY2In0.I6J6GFDqjlRY1U9D_NNPDTFFpEa-DoCnF9iuArCwy5o");
 //        form1.put("password", "admin");
-        Response<Map<String, Object>> response = client.execute("oauth2.user.info", "1.0.0", form1);
-        System.out.println(JSON.toJSONString(response));
-    }
+		Response<Map<String, Object>> response = client.execute("popular.feelings.add", "1.0.0", form1);
+		System.out.println(JSON.toJSONString(response));
+	}
 }