| 27 | import java.util.concurrent.Callable; |
| 28 | |
| 29 | @Slf4j |
| 30 | public class SearchTask implements Callable<List<SearchView>> { |
| 31 | private final JNICLibraryV7_18_92ServiceWorker jnicLibraryV7_18_92ServiceWorker; |
| 32 | private final RedisTemplate redisTemplate; |
| 33 | |
| 34 | public SearchTask(JNICLibraryV7_18_92ServiceWorker jnicLibraryV7_18_92ServiceWorker, RedisTemplate redisTemplate) { |
| 35 | this.jnicLibraryV7_18_92ServiceWorker = jnicLibraryV7_18_92ServiceWorker; |
| 36 | this.redisTemplate = redisTemplate; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | private SearchRequest getSearchRequest(Keywords item) { |
| 41 | String key = "keywords_" + item.getId() + "_filter"; |
| 42 | String keywordsFilter = (String) redisTemplate.opsForValue().get(key); |
| 43 | if (StringUtils.isBlank(keywordsFilter)) { |
| 44 | return null; |
| 45 | } |
| 46 | return JSONObject.parseObject(keywordsFilter, SearchRequest.class); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | private String getTitleFilter(Keywords item) { |
| 51 | String key = "keywords_title_" + item.getId() + "_filter"; |
| 52 | return (String) redisTemplate.opsForValue().get(key); |
| 53 | } |
| 54 | |
| 55 | private String getSellFilter(Keywords item) { |
| 56 | String key = "keywords_sell_" + item.getId() + "_filter"; |
| 57 | return (String) redisTemplate.opsForValue().get(key); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public List<SearchView> call() throws Exception { |
| 62 | List<SearchView> searchViewList = new ArrayList<>(); |
| 63 | String json = (String) redisTemplate.opsForValue().get("keywords"); |
| 64 | if (json != null) { |
| 65 | List<Keywords> keywordsList = JSONObject.parseObject(json, new TypeReference<List<Keywords>>() { |
| 66 | }); |
| 67 | for (Keywords item : keywordsList) { |
| 68 | SearchRequest searchRequest = getSearchRequest(item); |
| 69 | assert searchRequest != null; |
| 70 | searchRequest.rowsPerPage = searchRequest.pageNumber * searchRequest.rowsPerPage; |
| 71 | String titleFilter = getTitleFilter(item); |
| 72 | String sellFilter = getSellFilter(item); |
| 73 | |
| 74 | String t = String.valueOf(System.currentTimeMillis() / 1000); |
| 75 | String dataJson = JSONObject.toJSONString(searchRequest); |
| 76 | Map<String, String> param = RequestParamBuilder.builderParam(t, dataJson, CommonConstants.searchApi); |
| 77 | String input = MapConvert.convertInnerBaseStrMap(CommonConstants.appKey, param, true).get("INPUT").toString(); |
| 78 | Map<String, String> signResult = jnicLibraryV7_18_92ServiceWorker.doCommandNative_70102(CommonConstants.appKey, input, CommonConstants.searchApi).get(); |
| 79 | |
| 80 | try { |
| 81 | |
| 82 | String cookie = Optional.ofNullable(redisTemplate.opsForValue().get("cookie")) |
| 83 | .map(Object::toString) |
| 84 | .orElse(null); |
| 85 | Map<String, String> headers = RequestParamBuilder.builderHeaders(signResult.get("x-sgext"), signResult.get("x-sign"), signResult.get("x-mini-wua"), t, signResult.get("x-umt"), cookie); |
| 86 | param.clear(); |
nothing calls this directly
no outgoing calls
no test coverage detected