PhotoSceneController.java
3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.yoho.search.restapi.scene;
import com.alibaba.fastjson.JSONObject;
import com.yoho.search.models.SearchApiResult;
import com.yoho.search.service.scene.others.photo.SknImageVectorsService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.Map;
@Controller
public class PhotoSceneController {
private static final Logger logger = LoggerFactory.getLogger(PhotoSceneController.class);
private static final String VECTORS_32_KEY = "vectors_32";
private static final String VECTORS_128_KEY = "vectors_128";
private static final String PRODUCT_SKN = "product_skn";
@Autowired
private SknImageVectorsService sknImageVectorsService;
@RequestMapping(method = RequestMethod.POST, value = "/searchSknByPhoto")
@ResponseBody
public SearchApiResult searchSknByPhoto(@RequestBody JSONObject jsonObject) {
try {
String vectors_32 = jsonObject.get(VECTORS_32_KEY) == null ? null : jsonObject.get(VECTORS_32_KEY).toString();
String vectors_128 = jsonObject.get(VECTORS_128_KEY) == null ? null : jsonObject.get(VECTORS_128_KEY).toString();
if (StringUtils.isBlank(vectors_32) || StringUtils.isBlank(vectors_128)) {
return new SearchApiResult().setCode(400).setMessage("vectors_32或vectors_128不能为空");
}
logger.warn("vectors_32 is [{}],vectors_128 is[{}]", vectors_32, vectors_128);
Map<String, String> paramMap = new HashMap<>();
paramMap.put(VECTORS_32_KEY, vectors_32);
paramMap.put(VECTORS_128_KEY, vectors_128);
paramMap.put("viewNum", jsonObject.get("viewNum") == null ? "20" : jsonObject.get("viewNum").toString());
return sknImageVectorsService.searchSknByPhoto(paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("服务异常");
}
}
@RequestMapping(method = RequestMethod.POST, value = "/searchListByPhotoSkns")
@ResponseBody
public SearchApiResult searchListBySkns(@RequestBody JSONObject jsonObject) {
try {
String product_skn = jsonObject.get(PRODUCT_SKN) == null ? null : jsonObject.get(PRODUCT_SKN).toString();
if (StringUtils.isBlank(product_skn)) {
return new SearchApiResult().setCode(400).setMessage("product_skn不能为空");
}
Map<String, String> paramMap = new HashMap<>();
paramMap.put("product_skn", product_skn);
paramMap.put("viewNum", jsonObject.get("viewNum") == null ? "20" : jsonObject.get("viewNum").toString());
return sknImageVectorsService.searchListByPhotoSkns(paramMap);
} catch (Exception e) {
logger.error(e.getMessage(), e);
return new SearchApiResult().setCode(400).setMessage("服务异常");
}
}
}