From 2019e15b7aac1e735d0e6bd959377f17b385efc8 Mon Sep 17 00:00:00 2001 From: wxxwjef <505322415@qq.com> Date: Wed, 14 Jun 2023 19:10:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=9B=B8=E4=BC=BC=E5=92=8C?= =?UTF-8?q?=E6=8E=A8=E8=8D=90=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/controller/GorseController.java | 171 +++++++++-------- .../wx/application/adapter/dto/qo/GorseQ.java | 6 + .../core/controller/RiskUserController.java | 5 + .../wx/application/gorse4j/GorseService.java | 38 +++- .../java/com/wx/application/gorse4j/Item.java | 6 +- .../java/com/wx/application/gorse4j/User.java | 7 + web/src/components/menus/EntrysManage.vue | 17 +- web/src/components/menus/UserManage.vue | 44 ++++- .../components/menus/item/RecommendItem.vue | 178 ++++++++++++++++++ web/src/components/menus/item/SimilarItem.vue | 175 +++++++++++++++++ web/src/components/menus/user/SimilarUser.vue | 122 ++++++++++++ web/src/css/back.css | 25 +++ web/src/router/index.js | 12 ++ 13 files changed, 715 insertions(+), 91 deletions(-) create mode 100644 web/src/components/menus/item/RecommendItem.vue create mode 100644 web/src/components/menus/item/SimilarItem.vue create mode 100644 web/src/components/menus/user/SimilarUser.vue create mode 100644 web/src/css/back.css diff --git a/api/src/main/java/com/wx/application/adapter/controller/GorseController.java b/api/src/main/java/com/wx/application/adapter/controller/GorseController.java index 47c5c6a..fc0e56a 100644 --- a/api/src/main/java/com/wx/application/adapter/controller/GorseController.java +++ b/api/src/main/java/com/wx/application/adapter/controller/GorseController.java @@ -6,10 +6,7 @@ import java.util.Map; import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import com.wx.application.adapter.dto.qo.GorseQ; import com.wx.application.base.BaseController; @@ -29,82 +26,100 @@ import lombok.extern.slf4j.Slf4j; @RequestMapping("/gorse") @RestController("gorseController") public class GorseController extends BaseController { - - @Autowired - GorseService gorseService; - - @Autowired - RiskUserService riskUserService; - - @Autowired - EntrysService entrysService; - - @Autowired - NebulaOperateService nebulaOperateService; - - @Autowired - ImportGraphService importGraphService; - - /** - * 推荐根据userId - * @param gQo - * @return - * @throws Exception - */ - @PostMapping(value = "/recommend_by_userid") + + @Autowired + GorseService gorseService; + + @Autowired + RiskUserService riskUserService; + + @Autowired + EntrysService entrysService; + + @Autowired + NebulaOperateService nebulaOperateService; + + @Autowired + ImportGraphService importGraphService; + + /** + * 推荐根据userId + * + * @param gQo + * @return + * @throws Exception + */ + @PostMapping(value = "/recommend_by_userid") public ResponseData recommendByUserId(@RequestBody GorseQ gQo) throws Exception { - List res = gorseService.getRecommend(gQo.getUserId()); - if(res == null || res.size() == 0) { - return success(); - } - Map mQ = new HashMap<>(); - mQ.put("INS_fid", StringUtils.join(res, ",")); - return success(entrysService.queryList(mQ)); - } - - /** - * 根据列表推荐 - * @param gQo - * @return - * @throws Exception - */ - @PostMapping(value = "/popular_by_category") + List res = gorseService.getRecommend(gQo.getUserId()); + if (res == null || res.size() == 0) { + return success(); + } + Map mQ = new HashMap<>(); + mQ.put("INS_fid", StringUtils.join(res, ",")); + return success(entrysService.queryList(mQ)); + } + + /** + * 根据列表推荐 + * + * @param gQo + * @return + * @throws Exception + */ + @PostMapping(value = "/popular_by_category") public ResponseData popularByCategory(@RequestBody GorseQ gQo) throws Exception { - List res = gorseService.getPopular(gQo.getCategory()); - return success(res); - } - - @PostMapping(value = "/ipt") + List res = gorseService.getPopular(gQo.getCategory()); + return success(res); + } + + @PostMapping(value = "/ipt") public ResponseData ipt() throws Exception { - importGraphService.iptUser(); - importGraphService.iptentrys(); - return success(); - } - - /** - * 推荐根据知识图谱 - * @param gQo - * @return - * @throws Exception - */ - @PostMapping(value = "/recommend_by_userid_with_graph") + importGraphService.iptUser(); + importGraphService.iptentrys(); + return success(); + } + + /** + * 推荐根据知识图谱 + * + * @param gQo + * @return + * @throws Exception + */ + @PostMapping(value = "/recommend_by_userid_with_graph") public ResponseData recommendByUserIdWithGraph(@RequestBody GorseQ gQo) throws Exception { - - NebulaModel nebulaModel = nebulaOperateService.findOnePathById("", gQo.getUserId()); - List nodes = nebulaModel.getNodes(); - - if(nodes != null && nodes.size() > 0) { - nodes.get(0).getVid(); - } - - List res = gorseService.getRecommend(gQo.getUserId()); - if(res == null || res.size() == 0) { - return success(); - } - Map mQ = new HashMap<>(); - mQ.put("INS_fid", StringUtils.join(res, ",")); - return success(entrysService.queryList(mQ)); - } - - + + NebulaModel nebulaModel = nebulaOperateService.findOnePathById("", gQo.getUserId()); + List nodes = nebulaModel.getNodes(); + + if (nodes != null && nodes.size() > 0) { + nodes.get(0).getVid(); + } + + List res = gorseService.getRecommend(gQo.getUserId()); + if (res == null || res.size() == 0) { + return success(); + } + Map mQ = new HashMap<>(); + mQ.put("INS_fid", StringUtils.join(res, ",")); + return success(entrysService.queryList(mQ)); + } + + @PostMapping(value = "/get_similar_user") + public ResponseData getSimilarUser(@RequestBody GorseQ gQo) throws Exception { + return success(gorseService.getSimilarUser(gQo.getUserId())); + } + + @PostMapping(value = "/get_recommend_by_user") + public ResponseData getRecommendByUser(@RequestBody GorseQ gQo) throws Exception { + return success(gorseService.getRecommendByUser(gQo.getUserId(), gQo.getRecommendation(), gQo.getCategory(), gQo.getN())); + } + + @PostMapping(value = "/get_similar_item") + public ResponseData getSimilarItem(@RequestBody GorseQ gQo) throws Exception { + return success(gorseService.getSimilarItem(gQo.getItemId(), gQo.getCategory(), gQo.getN())); + } + + } diff --git a/api/src/main/java/com/wx/application/adapter/dto/qo/GorseQ.java b/api/src/main/java/com/wx/application/adapter/dto/qo/GorseQ.java index 8943474..229ee07 100644 --- a/api/src/main/java/com/wx/application/adapter/dto/qo/GorseQ.java +++ b/api/src/main/java/com/wx/application/adapter/dto/qo/GorseQ.java @@ -8,6 +8,12 @@ import lombok.EqualsAndHashCode; public class GorseQ { private String userId; + + private String itemId; private String category; + + private Integer n; + + private String recommendation; } diff --git a/api/src/main/java/com/wx/application/core/controller/RiskUserController.java b/api/src/main/java/com/wx/application/core/controller/RiskUserController.java index c1c4a12..ffa9758 100644 --- a/api/src/main/java/com/wx/application/core/controller/RiskUserController.java +++ b/api/src/main/java/com/wx/application/core/controller/RiskUserController.java @@ -34,4 +34,9 @@ public class RiskUserController extends BaseController { return success(userService.queryPage(entrysQ)); } + @PostMapping(value = "/query_unique") + public ResponseData queryUnique(@RequestBody Map entrysQ) { + return success(userService.queryUnique(entrysQ)); + } + } diff --git a/api/src/main/java/com/wx/application/gorse4j/GorseService.java b/api/src/main/java/com/wx/application/gorse4j/GorseService.java index 10ca279..fe7b7c2 100644 --- a/api/src/main/java/com/wx/application/gorse4j/GorseService.java +++ b/api/src/main/java/com/wx/application/gorse4j/GorseService.java @@ -10,6 +10,7 @@ import java.net.URL; import java.util.Arrays; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @Service @@ -23,7 +24,7 @@ public class GorseService { //Gorse client = new Gorse("", ""); //System.out.println(client.getRecommend("1265177464")); } - + public RowAffected insertUser(User user) throws IOException { return this.request("POST", this.endpoint + "/api/user", user, RowAffected.class); @@ -60,13 +61,40 @@ public class GorseService { public List getRecommend(String userId) throws IOException { return Arrays.asList(this.request("GET", this.endpoint + "/api/recommend/" + userId, null, String[].class)); } - - + + public List getPopular(String category) throws IOException { return Arrays.asList(this.request("GET", this.endpoint + "/api/dashboard/popular/" + category, null, Item[].class)); } - - + + /** + * 相似(获取相似用户) + */ + public List getSimilarUser(String userId) throws IOException { + return Arrays.asList(this.request("GET", this.endpoint + "/api/dashboard/user/" + userId + "/neighbors", null, User[].class)); + } + + /** + * 洞悉(根据用户获取推荐) + */ + public List getRecommendByUser(String userId, String recommendation, String category, Integer n) throws IOException { + return Arrays.asList(this.request("GET", this.endpoint + "/api/dashboard/recommend/" + userId + + "/" + recommendation + "/" + category + "?n=" + ((n == null || n <= 0) ? 10 : n), null, Item[].class)); + } + + /** + * 相似物品(根据物品ID和分类获取相似物品) + */ + public List getSimilarItem(String itemId, String category, Integer n) throws IOException { + String url = this.endpoint + "/api/dashboard/item/" + itemId + "/neighbors"; + if (StringUtils.isNotBlank(category)) { + // 当默认查询10条 + url += "/" + category + "?n=" + ((n == null || n <= 0) ? 10 : n); + } + System.out.println(url); + return Arrays.asList(this.request("GET", url, null, Item[].class)); + } + private Response request(String method, String url, Request request, Class responseClass) throws IOException { HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); diff --git a/api/src/main/java/com/wx/application/gorse4j/Item.java b/api/src/main/java/com/wx/application/gorse4j/Item.java index 94e5539..319574c 100644 --- a/api/src/main/java/com/wx/application/gorse4j/Item.java +++ b/api/src/main/java/com/wx/application/gorse4j/Item.java @@ -14,12 +14,12 @@ public class Item { private String timestamp; private String comment; - private Integer score; + private Float score; public Item() { } - public Item(String itemId, Boolean isHidden, List labels, List categories, String timestamp, String comment,Integer score) { + public Item(String itemId, Boolean isHidden, List labels, List categories, String timestamp, String comment,Float score) { this.itemId = itemId; this.isHidden = isHidden; this.labels = labels; @@ -60,7 +60,7 @@ public class Item { } @JsonProperty("Score") - public Integer getScore() { + public Float getScore() { return score; } diff --git a/api/src/main/java/com/wx/application/gorse4j/User.java b/api/src/main/java/com/wx/application/gorse4j/User.java index e697a8a..36959ea 100644 --- a/api/src/main/java/com/wx/application/gorse4j/User.java +++ b/api/src/main/java/com/wx/application/gorse4j/User.java @@ -12,6 +12,8 @@ public class User { private String userId; private List labels; + private Float score; + public User() { } @@ -30,6 +32,11 @@ public class User { return labels; } + @JsonProperty("Score") + public Float getScore() { + return score; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/web/src/components/menus/EntrysManage.vue b/web/src/components/menus/EntrysManage.vue index 654d80a..57eba02 100644 --- a/web/src/components/menus/EntrysManage.vue +++ b/web/src/components/menus/EntrysManage.vue @@ -51,11 +51,14 @@ - +