|
@@ -1,11 +1,13 @@
|
|
|
package com.tzld.piaoquan.recommend.server.web;
|
|
|
|
|
|
import com.google.common.base.Strings;
|
|
|
+import com.google.protobuf.InvalidProtocolBufferException;
|
|
|
+import com.tzld.piaoquan.recommend.server.client.ProtobufUtils;
|
|
|
import com.tzld.piaoquan.recommend.server.client.RecommendHttpRequest;
|
|
|
import com.tzld.piaoquan.recommend.server.gen.recommend.RecommendRequest;
|
|
|
import com.tzld.piaoquan.recommend.server.gen.recommend.RecommendResponse;
|
|
|
import com.tzld.piaoquan.recommend.server.service.RecommendService;
|
|
|
-import com.tzld.piaoquan.recommend.server.util.JSONUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.collections4.MapUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -20,6 +22,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|
|
* @author dyp
|
|
|
*/
|
|
|
@RestController
|
|
|
+@Slf4j
|
|
|
public class RecommendController {
|
|
|
@Autowired
|
|
|
private RecommendService recommendService;
|
|
@@ -32,13 +35,25 @@ public class RecommendController {
|
|
|
@RequestMapping("/homepage/recommend")
|
|
|
public String homepageRecommend(@RequestBody RecommendHttpRequest httpRequest) {
|
|
|
RecommendResponse response = recommendService.homepageRecommend(generate(httpRequest));
|
|
|
- return JSONUtils.toJson(response);
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ result = ProtobufUtils.toJson(response);
|
|
|
+ } catch (InvalidProtocolBufferException e) {
|
|
|
+ log.error("homepageRecommend ProtobufUtils.toJson", e);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
@RequestMapping("/relevant/recommend")
|
|
|
public String relevantRecommend(@RequestBody RecommendHttpRequest httpRequest) {
|
|
|
RecommendResponse response = recommendService.relevantRecommend(generate(httpRequest));
|
|
|
- return JSONUtils.toJson(response);
|
|
|
+ String result = "";
|
|
|
+ try {
|
|
|
+ result = ProtobufUtils.toJson(response);
|
|
|
+ } catch (InvalidProtocolBufferException e) {
|
|
|
+ log.error("relevantRecommend ProtobufUtils.toJson", e);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
private RecommendRequest generate(RecommendHttpRequest httpRequest) {
|