package com.yeshi.fanli.controller.client.v1;
|
|
import java.io.PrintWriter;
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.Collections;
|
import java.util.HashSet;
|
import java.util.List;
|
import java.util.Set;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.taobao.TaoBaoAuthUtil;
|
import org.yeshi.utils.taobao.TbImgUtil;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.yeshi.fanli.dto.dataoke.DaTaoKeGoodsResult;
|
import com.yeshi.fanli.entity.accept.AcceptData;
|
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
|
import com.yeshi.fanli.entity.bus.recommend.Honest;
|
import com.yeshi.fanli.entity.bus.search.HotSearch;
|
import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch;
|
import com.yeshi.fanli.entity.system.BusinessSystem;
|
import com.yeshi.fanli.entity.taobao.PidUser;
|
import com.yeshi.fanli.entity.taobao.SearchFilter;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
|
import com.yeshi.fanli.entity.taobao.TaoBaoProvince;
|
import com.yeshi.fanli.entity.taobao.TaoBaoSearchNav;
|
import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
|
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetailV2;
|
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
|
import com.yeshi.fanli.service.inter.config.ConfigService;
|
import com.yeshi.fanli.service.inter.config.SuperHotSearchService;
|
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
|
import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
|
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
|
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
|
import com.yeshi.fanli.service.inter.user.HistorySearchService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.EhcacheUtil;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.ThreadUtil;
|
import com.yeshi.fanli.util.cache.TaoBaoGoodsCacheUtil;
|
import com.yeshi.fanli.util.dataoke.DaTaoKeApiUtil;
|
import com.yeshi.fanli.util.taobao.SearchFilterUtil;
|
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
|
import net.sf.ehcache.Element;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("api/v1/search")
|
public class SearchController {
|
|
@Resource
|
private BusinessSystemService businessSystemService;
|
|
@Resource
|
private ConfigService configService;
|
|
@Resource
|
private SuperHotSearchService superHotSearchSerivce;
|
|
@Resource
|
private HistorySearchService historySearchService;
|
|
@Resource
|
private HongBaoManageService manageService;
|
|
@Resource
|
private TaoBaoUnionConfigService taoBaoUnionConfigService;
|
|
@Resource
|
private TaoKeGoodsService taoKeGoodsService;
|
|
@Resource
|
private QualityGoodsService qualityGoodsService;
|
|
@Resource
|
private TaoBaoGoodsCacheUtil taoBaoGoodsCacheUtil;
|
|
@Resource
|
private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
|
|
@RequestMapping(value = "gethotsearch", method = RequestMethod.POST)
|
public void getHotSearch(AcceptData acceptData, PrintWriter out) {
|
BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
|
acceptData.getPackages());
|
if (system == null) {
|
out.print(JsonUtil.loadFalseResult("系统不存在"));
|
return;
|
}
|
List<SuperHotSearch> superHotSearchList = superHotSearchSerivce
|
.getSuperHotSearchBySystemIdCache(system.getId());
|
if (superHotSearchList == null || superHotSearchList.size() == 0) {
|
out.print(JsonUtil.loadFalseResult("没有数据"));
|
return;
|
}
|
List<HotSearch> hotSearchList = new ArrayList<HotSearch>();
|
for (SuperHotSearch superHotSearch : superHotSearchList) {
|
HotSearch hotSearch = superHotSearch.getHotSearch();
|
if (hotSearch != null)
|
hotSearchList.add(hotSearch);
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", hotSearchList.size());
|
data.put("hotSearchList", hotSearchList);
|
String result = JsonUtil.loadTrueResult(data);
|
out.print(result);
|
return;
|
}
|
|
@RequestMapping("specialSearch")
|
public void specialSearch(AcceptData acceptData, long hid, int page, PrintWriter out) {
|
Honest honest = null;
|
if (honest == null) {
|
out.print(JsonUtil.loadFalseResult(""));
|
return;
|
}
|
String key = hid + "#" + page;
|
Element element = EhcacheUtil.getCache("temai").get(key);
|
if (element != null) {
|
String value = (String) element.getObjectValue();
|
if (value != null) {
|
out.print(value);
|
return;
|
}
|
}
|
|
List<TaoBaoUnionConfig> config = taoBaoUnionConfigService.getConfigByTypeCache(PidUser.TYPE_FANLI_ANDROID);
|
|
SearchFilter searchFilter = SearchFilterUtil.getSearchFilter(honest, page);
|
TaoBaoSearchResult result = TaoBaoUtil.search3(searchFilter, config.get(0));
|
List<TaoBaoSearchNav> navList = TaoBaoUtil.getBaseNav();
|
if (result.getNavList() != null)
|
navList.addAll(result.getNavList());
|
Gson gson = new GsonBuilder().create();
|
JSONObject data = new JSONObject();
|
data.put("nav", gson.toJson(navList));
|
List<TaoBaoGoodsBriefExtra> re = new ArrayList<TaoBaoGoodsBriefExtra>();
|
List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs();
|
BigDecimal proportion = manageService.getFanLiRate();
|
for (TaoBaoGoodsBrief bf : taoBaoGoodsBriefs) {
|
re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
|
}
|
Gson gson2 = JsonUtil.getApiCommonGson();
|
data.put("result", gson2.toJson(re));
|
int count = 0;
|
if (result.getTaoBaoHead() != null) {
|
count = result.getTaoBaoHead().getDocsfound();
|
}
|
data.put("count", count);
|
|
String loadTrueResult = JsonUtil.loadTrueResult(data);
|
if (count != 0) {
|
EhcacheUtil.getCache("temai").put(new Element(key, loadTrueResult));
|
}
|
out.print(loadTrueResult);
|
}
|
|
@RequestMapping(value = "search")
|
public void search(AcceptData acceptData, String kw, int page, String filter, String order, String startprice,
|
String endprice, String fastFilter, PrintWriter out) {
|
String bid = getHistorySearchBid(acceptData);
|
historySearchService.addHistorySearch(kw, bid);
|
BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
|
acceptData.getPackages());
|
if (system == null) {
|
out.print(JsonUtil.loadFalseResult("系统不存在"));
|
return;
|
}
|
|
if (!StringUtil.isNullOrEmpty(kw) && (kw.startsWith("http://") || kw.startsWith("https://"))) {
|
out.print(JsonUtil.loadFalseResult("无法搜索链接"));
|
return;
|
}
|
|
if (!StringUtil.isNullOrEmpty(fastFilter)) {
|
if (!StringUtil.isNullOrEmpty(filter)) {
|
JSONArray filterArray = JSONArray.fromObject(filter);
|
JSONArray fastFilterArray = JSONArray.fromObject(fastFilter);
|
filterArray.addAll(fastFilterArray);
|
filter = filterArray.toString();
|
} else {
|
filter = fastFilter;
|
}
|
}
|
JSONObject data = search(kw, page, filter, order, startprice, endprice);
|
out.print(JsonUtil.loadTrueResult(data));
|
}
|
|
@Cacheable(value = "goodsCache", key = "#md5")
|
public JSONObject searchClass(AcceptData acceptData, String kw, int page, String filter, String order,
|
String startprice, String endprice, String md5) {
|
java.lang.System.out.println("searchClass");
|
JSONObject data = search(kw, page, filter, order, startprice, endprice);
|
return data;
|
}
|
|
private JSONObject search(String kw, int page, String filter, String order, String startprice, String endprice) {
|
page = page + 1;
|
|
SearchFilter sf = new SearchFilter();
|
sf.setKey(SearchFilterUtil.filterSearchContent(kw));
|
sf.setPage(page);
|
sf.setSort(0);
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(startprice)) {
|
sf.setStartPrice(new BigDecimal(startprice));
|
}
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(endprice)) {
|
sf.setEndPrice(new BigDecimal(endprice));
|
}
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(order)) {
|
if (Integer.parseInt(order) == 1) {
|
sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
|
} else if (Integer.parseInt(order) == 2) {
|
sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW);
|
} else if (Integer.parseInt(order) == 3) {
|
sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH);
|
}
|
} else {
|
// 默认销量从高到低排序
|
sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
|
}
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) {
|
// 查询淘宝天猫
|
JSONArray array = JSONArray.fromObject(filter);
|
Set<String> params = new HashSet<String>();
|
for (int i = 0; i < array.size(); i++) {
|
// [{"type":'shoptype',id:12}]
|
String ty = array.optJSONObject(i).optString("type");
|
if ("shoptype".equalsIgnoreCase(ty)) {
|
if (array.optJSONObject(i).optInt("id") == 21) {
|
sf.setTmFlagship(false); // 不筛�?
|
} else {
|
sf.setTmFlagship(true);
|
sf.setTmall(true);
|
sf.setShopTag("b2c");
|
}
|
} else if ("category".equalsIgnoreCase(ty)) {
|
sf.setCateIds(array.optJSONObject(i).optString("id"));
|
} else if ("userType".equalsIgnoreCase(ty)) {
|
// if(array.optJSONObject(i).optInt("id") == 51)
|
sf.setTmall(true);
|
// else
|
// sf.setTmall(false);
|
} else if ("baoyou".equalsIgnoreCase(ty)) {
|
// if(array.optJSONObject(i).optInt("id") == 61)
|
sf.setBaoYou(true);
|
// else
|
// sf.setBaoYou(false);
|
} else if ("quantype".equalsIgnoreCase(ty)) {
|
// if (array.optJSONObject(i).optInt("id") == 31){
|
sf.setQuan(1);
|
if (sf.isTmFlagship()) {
|
sf.setShopTag(sf.getShopTag() + ",dpyhq");
|
} else {
|
sf.setShopTag("dpyhq");
|
}
|
// }
|
// else
|
// sf.setQuan(2);
|
} else if ("hongbaotype".equalsIgnoreCase(ty)) {
|
if (array.optJSONObject(i).optInt("id") == 41)// 有红�?
|
sf.setHongbao(1);
|
else// 无红�?
|
sf.setHongbao(2);
|
} else if ("property".equalsIgnoreCase(ty)) {
|
String pid = (String) array.optJSONObject(i).opt("pid");
|
String id = (String) array.optJSONObject(i).opt("id");
|
boolean flag = false;
|
String str = null;
|
for (String string : params) {
|
flag = string.contains(pid + ":");
|
if (flag) {
|
str = string;
|
break;
|
}
|
}
|
if (flag) {
|
params.add(str + "," + id);
|
params.remove(str);
|
} else {
|
params.add(pid + ":" + id);
|
}
|
} else if ("fahuodi".equalsIgnoreCase(ty)) {
|
int id = array.optJSONObject(i).optInt("id");
|
sf.setProvinceId(id);
|
} else if ("materialId".equalsIgnoreCase(ty)) {
|
int id = array.optJSONObject(i).optInt("id");
|
sf.setProvinceId(id);
|
}
|
}
|
sf.setParams(params);
|
}
|
TaoBaoSearchResult result = TaoBaoUtil.search(sf);
|
if (result == null) {
|
return null;
|
}
|
|
List<TaoBaoSearchNav> navList = TaoBaoUtil.getBaseNav();
|
if (result.getNavList() != null)
|
navList.addAll(result.getNavList());
|
Gson gson = new GsonBuilder().create();
|
JSONObject data = new JSONObject();
|
data.put("nav", gson.toJson(navList));
|
List<TaoBaoGoodsBriefExtra> re = new ArrayList<TaoBaoGoodsBriefExtra>();
|
List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs();
|
int fq = sf.getQuan();
|
int fh = sf.getHongbao();
|
boolean ft = sf.isTmall();
|
BigDecimal proportion = manageService.getFanLiRate();
|
if (fq == 0 && fh == 0 && !ft) {
|
if (result != null && result.getTaoBaoGoodsBriefs() != null)
|
for (TaoBaoGoodsBrief bf : result.getTaoBaoGoodsBriefs()) {
|
int count = bf.getBiz30day();
|
if (count >= 10000) { // 对销量数据做处理 页面展示7.3万
|
double sales = count;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
bf.setSalesCount(salesCountMidea + "万");
|
re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
|
} else {
|
bf.setSalesCount(count + "");
|
re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
|
}
|
}
|
} else {
|
TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra;
|
if (taoBaoGoodsBriefs != null)
|
for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) {
|
int count = taoBaoGoodsBrief.getBiz30day();
|
if (count >= 10000) {
|
double sales = count;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
taoBaoGoodsBrief.setSalesCount(salesCountMidea + "万");
|
taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
proportion.toString(), "");
|
re.add(taoBaoGoodsBriefExtra);
|
} else {
|
taoBaoGoodsBrief.setSalesCount(count + "");
|
taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
proportion.toString(), "");
|
re.add(taoBaoGoodsBriefExtra);
|
}
|
}
|
}
|
Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().create();
|
data.put("result", gson2.toJson(re));
|
data.put("count", result.getTaoBaoHead().getDocsfound());
|
return data;
|
}
|
|
@RequestMapping(value = "suggestsearch", method = RequestMethod.POST)
|
public void getSugguestSearch(AcceptData acceptData, String kw, PrintWriter out) {
|
List<String> list = TaoBaoUtil.getSuguestSearch(kw);
|
if (list != null && list.size() > 0) {
|
JSONArray array = new JSONArray();
|
for (String st : list)
|
array.add(st);
|
out.print(JsonUtil.loadTrueResult(array));
|
} else {
|
out.print(JsonUtil.loadFalseResult("暂无建议内容"));
|
}
|
return;
|
}
|
|
private String getHistorySearchBid(AcceptData acceptData) {
|
StringBuffer sb = new StringBuffer();
|
String link = "#$$$#";
|
String platform = acceptData.getPlatform();
|
String packages = acceptData.getPackages();
|
String device = acceptData.getDevice();
|
sb.append(platform).append(link).append(packages).append(link).append(device);
|
return StringUtil.Md5(sb.toString());
|
}
|
|
/**
|
* 搜索-新版
|
*
|
* @param acceptData
|
* @param kw
|
* @param page
|
* @param filter
|
* @param order
|
* 销量由高到低:1 、 价格从高到低:2 、 价格从低到高:3 、 推广量高到低:4(综合默认)、返利比高到低:5
|
* 、返利比低到高:6 、推荐20
|
* @param startprice
|
* @param endprice
|
* @param fastFilter
|
* @param out
|
*/
|
@RequestMapping(value = "searchgoods")
|
public void searchgoods(AcceptData acceptData, String kw, int page, String filter, String order, String startprice,
|
String endprice, Double startTkRate, Double endTkRate, String fastFilter, PrintWriter out) {
|
|
String bid = getHistorySearchBid(acceptData);
|
|
historySearchService.addHistorySearch(kw, bid);
|
|
BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
|
acceptData.getPackages());
|
if (system == null) {
|
out.print(JsonUtil.loadFalseResult("系统不存在"));
|
return;
|
}
|
|
if (!StringUtil.isNullOrEmpty(kw) && (kw.startsWith("http://") || kw.startsWith("https://"))) {
|
out.print(JsonUtil.loadFalseResult("无法搜索链接"));
|
return;
|
}
|
|
if (!StringUtil.isNullOrEmpty(fastFilter)) {
|
if (!StringUtil.isNullOrEmpty(filter)) {
|
JSONArray filterArray = JSONArray.fromObject(filter);
|
JSONArray fastFilterArray = JSONArray.fromObject(fastFilter);
|
filterArray.addAll(fastFilterArray);
|
filter = filterArray.toString();
|
} else {
|
filter = fastFilter;
|
}
|
}
|
|
// 是否是推荐
|
boolean recommend = false;
|
if (!StringUtil.isNullOrEmpty(fastFilter)) {
|
// 查询淘宝天猫
|
JSONArray array = JSONArray.fromObject(filter);
|
for (int i = 0; i < array.size(); i++) {
|
String ty = array.optJSONObject(i).optString("type");
|
|
if ("recommend".equalsIgnoreCase(ty)) {
|
recommend = true;
|
}
|
}
|
}
|
|
JSONObject data = null;
|
if (!recommend) {
|
|
// 淘宝接口请求
|
data = searchGoods(kw, page, filter, order, startprice, endprice);
|
} else {
|
// 推荐:精选库
|
// data = searchQualityGoods(kw, page, filter, order, startprice,
|
// endprice);
|
data = searchDaTaoKeGoods(kw, page, filter, order, startprice, endprice);
|
}
|
|
// 获取推荐词
|
List<String> listRecommendWords = new ArrayList<String>();
|
// 综合 查询第一页时获取候选词
|
if (page == 0) {
|
listRecommendWords = TaoBaoUtil.getSuguestSearch(kw);
|
if (listRecommendWords == null || listRecommendWords.size() == 0) {
|
listRecommendWords = new ArrayList<String>();
|
}
|
}
|
|
Gson gson = new GsonBuilder().create();
|
if (data != null)
|
data.put("words", gson.toJson(listRecommendWords));
|
|
out.print(JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
* 执行搜索-新版
|
*
|
* @param kw
|
* @param page
|
* @param filter
|
* @param order
|
* @param startprice
|
* @param endprice
|
* @return
|
*/
|
private JSONObject searchGoods(String kw, int page, String filter, String order, String startprice,
|
String endprice) {
|
page = page + 1;
|
|
SearchFilter sf = new SearchFilter();
|
sf.setKey(SearchFilterUtil.filterSearchContent(kw));
|
sf.setPage(page);
|
sf.setSort(0);
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(startprice)) {
|
sf.setStartPrice(new BigDecimal(startprice));
|
}
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(endprice)) {
|
sf.setEndPrice(new BigDecimal(endprice));
|
}
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(order)) {
|
if (Integer.parseInt(order) == 1) {
|
sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
|
} else if (Integer.parseInt(order) == 2) {
|
sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW);
|
} else if (Integer.parseInt(order) == 3) {
|
sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH);
|
} else if (Integer.parseInt(order) == 4) {
|
sf.setSort(TaoBaoUtil.SORT_TOTAL_SALES_HIGH_TO_LOW);
|
} else if (Integer.parseInt(order) == 5) {
|
sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW);
|
} else if (Integer.parseInt(order) == 6) {
|
sf.setSort(TaoBaoUtil.SORT_TKRATE_LOW_TO_HIGH);
|
}
|
} else {
|
// 默认销量从高到低排序
|
sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
|
}
|
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) {
|
// 查询淘宝天猫
|
JSONArray array = JSONArray.fromObject(filter);
|
Set<String> params = new HashSet<String>();
|
for (int i = 0; i < array.size(); i++) {
|
// [{"type":'shoptype',id:12}]
|
String ty = array.optJSONObject(i).optString("type");
|
if ("shoptype".equalsIgnoreCase(ty)) {
|
if (array.optJSONObject(i).optInt("id") == 21) {
|
sf.setTmFlagship(false); // 不筛�?
|
} else {
|
sf.setTmFlagship(true);
|
sf.setTmall(true);
|
sf.setShopTag("b2c");
|
}
|
} else if ("category".equalsIgnoreCase(ty)) {
|
sf.setCateIds(array.optJSONObject(i).optString("id"));
|
} else if ("userType".equalsIgnoreCase(ty)) {
|
// if(array.optJSONObject(i).optInt("id") == 51)
|
sf.setTmall(true);
|
// else
|
// sf.setTmall(false);
|
} else if ("baoyou".equalsIgnoreCase(ty)) {
|
// if(array.optJSONObject(i).optInt("id") == 61)
|
sf.setBaoYou(true);
|
// else
|
// sf.setBaoYou(false);
|
} else if ("quantype".equalsIgnoreCase(ty)) {
|
// if (array.optJSONObject(i).optInt("id") == 31){
|
sf.setQuan(1);
|
if (sf.isTmFlagship()) {
|
sf.setShopTag(sf.getShopTag() + ",dpyhq");
|
} else {
|
sf.setShopTag("dpyhq");
|
}
|
// }
|
// else
|
// sf.setQuan(2);
|
} else if ("hongbaotype".equalsIgnoreCase(ty)) {
|
if (array.optJSONObject(i).optInt("id") == 41)// 有红�?
|
sf.setHongbao(1);
|
else// 无红�?
|
sf.setHongbao(2);
|
} else if ("property".equalsIgnoreCase(ty)) {
|
String pid = (String) array.optJSONObject(i).opt("pid");
|
String id = (String) array.optJSONObject(i).opt("id");
|
boolean flag = false;
|
String str = null;
|
for (String string : params) {
|
flag = string.contains(pid + ":");
|
if (flag) {
|
str = string;
|
break;
|
}
|
}
|
if (flag) {
|
params.add(str + "," + id);
|
params.remove(str);
|
} else {
|
params.add(pid + ":" + id);
|
}
|
} else if ("fahuodi".equalsIgnoreCase(ty)) {
|
int id = array.optJSONObject(i).optInt("id");
|
sf.setProvinceId(id);
|
} else if ("materialId".equalsIgnoreCase(ty)) {
|
int id = array.optJSONObject(i).optInt("id");
|
sf.setProvinceId(id);
|
} else if ("tkRate1".equalsIgnoreCase(ty)) {
|
setSearchTkRate(0, sf);
|
} else if ("tkRate2".equalsIgnoreCase(ty)) {
|
setSearchTkRate(1, sf);
|
} else if ("tkRate3".equalsIgnoreCase(ty)) {
|
setSearchTkRate(2, sf);
|
} else if ("tkRate4".equalsIgnoreCase(ty)) {
|
setSearchTkRate(3, sf);
|
} else if ("tkRate5".equalsIgnoreCase(ty)) {
|
setSearchTkRate(4, sf);
|
}
|
}
|
sf.setParams(params);
|
}
|
|
// 搜索大淘客
|
List<DaTaoKeDetail> daTaoKeList = null;
|
if (page == 1)
|
daTaoKeList = daTaoKeGoodsDetailService.listByDtitle(kw);
|
|
TaoBaoSearchResult result = TaoBaoUtil.search(sf);
|
if (result == null) {
|
return null;
|
}
|
// 搜索是否在营销主商品库
|
if (result != null && result.getTaoBaoGoodsBriefs() != null && result.getTaoBaoGoodsBriefs().size() > 0) {
|
// 暂时放弃更新到营销商品库
|
// String numIds = "";
|
// for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs()) {
|
// numIds += goods.getAuctionId() + ",";
|
// }
|
// if (numIds.endsWith(","))
|
// numIds = numIds.substring(0, numIds.length() - 1);
|
// try {
|
// List<TaoBaoGoodsBrief> goodsList =
|
// TaoKeApiUtil.getBatchGoodsInfos(numIds);
|
// Map<Long, Integer> map = new HashMap<>();
|
// for (TaoBaoGoodsBrief g : goodsList)
|
// map.put(g.getAuctionId(), g.getMaterialLibType());
|
// for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs())
|
// goods.setMaterialLibType(map.get(goods.getAuctionId()));
|
|
ThreadUtil.run(new Runnable() {
|
@Override
|
public void run() {
|
// 更新到緩存
|
for (TaoBaoGoodsBrief goods : result.getTaoBaoGoodsBriefs())
|
taoBaoGoodsCacheUtil.saveCommonTaoBaoGoodsInfo(goods);
|
}
|
});
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
|
}
|
|
List<TaoBaoSearchNav> navList = TaoBaoUtil.getBaseNav();
|
if (result.getNavList() != null)
|
navList.addAll(result.getNavList());
|
Gson gson = new GsonBuilder().create();
|
JSONObject data = new JSONObject();
|
data.put("nav", gson.toJson(navList));
|
List<TaoBaoGoodsBriefExtra> re = new ArrayList<TaoBaoGoodsBriefExtra>();
|
List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs();
|
if (taoBaoGoodsBriefs == null)
|
taoBaoGoodsBriefs = new ArrayList<>();
|
|
try {
|
if (daTaoKeList != null && daTaoKeList.size() > 0) {
|
Collections.reverse(daTaoKeList);
|
for (DaTaoKeDetail detail : daTaoKeList) {
|
taoBaoGoodsBriefs.add(0, TaoBaoUtil.convert(detail));
|
}
|
}
|
} catch (Exception e) {
|
}
|
|
int fq = sf.getQuan();
|
int fh = sf.getHongbao();
|
boolean ft = sf.isTmall();
|
BigDecimal proportion = manageService.getFanLiRate();
|
if (fq == 0 && fh == 0 && !ft) {
|
if (result != null && taoBaoGoodsBriefs != null)
|
for (TaoBaoGoodsBrief bf : taoBaoGoodsBriefs) {
|
int count = bf.getBiz30day();
|
if (count >= 10000) { // 对销量数据做处理 页面展示7.3万
|
double sales = count;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
bf.setSalesCount(salesCountMidea + "万");
|
re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
|
} else {
|
bf.setSalesCount(count + "");
|
re.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
|
}
|
}
|
} else {
|
TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra;
|
if (taoBaoGoodsBriefs != null)
|
for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) {
|
int count = taoBaoGoodsBrief.getBiz30day();
|
if (count >= 10000) {
|
double sales = count;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
taoBaoGoodsBrief.setSalesCount(salesCountMidea + "万");
|
taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
proportion.toString(), "");
|
re.add(taoBaoGoodsBriefExtra);
|
} else {
|
taoBaoGoodsBrief.setSalesCount(count + "");
|
taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
proportion.toString(), "");
|
re.add(taoBaoGoodsBriefExtra);
|
}
|
}
|
}
|
Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().create();
|
data.put("result", gson2.toJson(re));
|
data.put("count", result.getTaoBaoHead().getDocsfound());
|
return data;
|
}
|
|
/**
|
* 执行搜索精选库
|
*
|
* @param kw
|
* @param page
|
* @param filter
|
* @param order
|
* @param startprice
|
* @param endprice
|
* @return
|
*/
|
private JSONObject searchQualityGoods(String key, int page, String filter, String order, String startprice,
|
String endprice) {
|
|
Integer hasQuan = null;
|
Integer userType = null;
|
Double start_Price = null;
|
Double end_Price = null;
|
Integer sort = null;
|
Double startTkRate = null;
|
Double endTkRate = null;
|
|
int provinceId = -100;
|
|
// 起始价格
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(startprice)) {
|
start_Price = Double.parseDouble(startprice);
|
}
|
// 结束价格
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(endprice)) {
|
end_Price = Double.parseDouble(endprice);
|
}
|
|
// 排序
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(order)) {
|
|
if (Integer.parseInt(order) == 4) {
|
sort = 20; // 综合时:采用默认权重排序
|
} else {
|
sort = Integer.parseInt(order);
|
}
|
|
}
|
|
/* 其他筛选条件 */
|
if (!com.yeshi.fanli.util.StringUtil.isNullOrEmpty(filter)) {
|
// 查询淘宝天猫
|
JSONArray array = JSONArray.fromObject(filter);
|
for (int i = 0; i < array.size(); i++) {
|
String ty = array.optJSONObject(i).optString("type");
|
|
if ("userType".equalsIgnoreCase(ty)) {
|
userType = 1; // 天猫
|
} else if ("quantype".equalsIgnoreCase(ty)) {
|
hasQuan = 1; // 有券
|
} else if ("hongbaotype".equalsIgnoreCase(ty)) {
|
|
} else if ("fahuodi".equalsIgnoreCase(ty)) {
|
provinceId = array.optJSONObject(i).optInt("id");
|
} else if ("tkRate1".equalsIgnoreCase(ty)) {
|
// 获取对应参数
|
String value = configService.get("tkRate_range");
|
if (!StringUtil.isNullOrEmpty(value)) {
|
JSONArray tkRatearray = JSONArray.fromObject(value);
|
if (tkRatearray != null) {
|
String start = tkRatearray.optJSONObject(0).optString("start");
|
if (!StringUtil.isNullOrEmpty(start)) {
|
startTkRate = Double.parseDouble(start);
|
}
|
String end = tkRatearray.optJSONObject(0).optString("end");
|
if (!StringUtil.isNullOrEmpty(end)) {
|
endTkRate = Double.parseDouble(end);
|
}
|
}
|
}
|
} else if ("tkRate2".equalsIgnoreCase(ty)) {
|
// 获取对应参数
|
String value = configService.get("tkRate_range");
|
if (!StringUtil.isNullOrEmpty(value)) {
|
JSONArray tkRatearray = JSONArray.fromObject(value);
|
if (tkRatearray != null) {
|
String start = tkRatearray.optJSONObject(1).optString("start");
|
if (!StringUtil.isNullOrEmpty(start)) {
|
startTkRate = Double.parseDouble(start);
|
}
|
String end = tkRatearray.optJSONObject(1).optString("end");
|
if (!StringUtil.isNullOrEmpty(end)) {
|
endTkRate = Double.parseDouble(end);
|
}
|
}
|
}
|
} else if ("tkRate3".equalsIgnoreCase(ty)) {
|
// 获取对应参数
|
String value = configService.get("tkRate_range");
|
if (!StringUtil.isNullOrEmpty(value)) {
|
JSONArray tkRatearray = JSONArray.fromObject(value);
|
if (tkRatearray != null) {
|
String start = tkRatearray.optJSONObject(2).optString("start");
|
if (!StringUtil.isNullOrEmpty(start)) {
|
startTkRate = Double.parseDouble(start);
|
}
|
String end = tkRatearray.optJSONObject(2).optString("end");
|
if (!StringUtil.isNullOrEmpty(end)) {
|
endTkRate = Double.parseDouble(end);
|
}
|
}
|
}
|
} else if ("tkRate4".equalsIgnoreCase(ty)) {
|
// 获取对应参数
|
String value = configService.get("tkRate_range");
|
if (!StringUtil.isNullOrEmpty(value)) {
|
JSONArray tkRatearray = JSONArray.fromObject(value);
|
if (tkRatearray != null) {
|
String start = tkRatearray.optJSONObject(3).optString("start");
|
if (!StringUtil.isNullOrEmpty(start)) {
|
startTkRate = Double.parseDouble(start);
|
}
|
String end = tkRatearray.optJSONObject(3).optString("end");
|
if (!StringUtil.isNullOrEmpty(end)) {
|
endTkRate = Double.parseDouble(end);
|
}
|
}
|
}
|
} else if ("tkRate5".equalsIgnoreCase(ty)) {
|
// 获取对应参数
|
String value = configService.get("tkRate_range");
|
if (!StringUtil.isNullOrEmpty(value)) {
|
JSONArray tkRatearray = JSONArray.fromObject(value);
|
if (tkRatearray != null) {
|
String start = tkRatearray.optJSONObject(4).optString("start");
|
if (!StringUtil.isNullOrEmpty(start)) {
|
startTkRate = Double.parseDouble(start);
|
}
|
String end = tkRatearray.optJSONObject(4).optString("end");
|
if (!StringUtil.isNullOrEmpty(end)) {
|
endTkRate = Double.parseDouble(end);
|
}
|
}
|
}
|
}
|
}
|
}
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
List<QualityFactory> listQuery = qualityGoodsService.listRecommendBykey(page * pageSize, pageSize, key, hasQuan,
|
userType, start_Price, end_Price, startTkRate, endTkRate, sort);
|
|
List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
|
BigDecimal proportion = manageService.getFanLiRate();
|
/* 遍历列表数据 */
|
if (listQuery != null && listQuery.size() > 0) {
|
for (QualityFactory selectionGoods : listQuery) {
|
|
TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
|
if (taoBaoGoodsBrief == null) {
|
continue;
|
}
|
|
int biz30day = taoBaoGoodsBrief.getBiz30day();
|
if (biz30day >= 10000) {
|
double sales = biz30day;
|
String salesCountMidea = String.format("%.1f", sales / 10000);
|
taoBaoGoodsBrief.setSalesCount(salesCountMidea + "万");
|
} else {
|
taoBaoGoodsBrief.setSalesCount(biz30day + "");
|
}
|
|
// 改变图片尺寸
|
String pictUrl = taoBaoGoodsBrief.getPictUrl();
|
if (!StringUtil.isNullOrEmpty(pictUrl) && !pictUrl.contains("320x320")) {
|
taoBaoGoodsBrief.setPictUrl(TbImgUtil.getTBSize320Img(pictUrl));
|
}
|
|
listExtra.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null));
|
}
|
}
|
|
long count = qualityGoodsService.countRecommendBykey(key, hasQuan, userType, start_Price, end_Price,
|
startTkRate, endTkRate);
|
|
// 设置发货地址
|
TaoBaoSearchNav nav = new TaoBaoSearchNav();
|
nav.setName("发货地选择");
|
nav.setFlag("address");
|
nav.setId(11110);
|
nav.setType("fahuodi");
|
|
List<TaoBaoSearchNav> navList = new ArrayList<>();
|
|
List<TaoBaoSearchNav> childNavList = new ArrayList<>();
|
List<TaoBaoProvince> provinceList = TaoBaoUtil.getTaoBaoProvinceList();
|
for (TaoBaoProvince province : provinceList) {
|
TaoBaoSearchNav childNav = new TaoBaoSearchNav();
|
childNav.setName(province.getName());
|
childNav.setId(Integer.parseInt(province.getId()));
|
childNav.setType("fahuodi-child");
|
if (Integer.parseInt(province.getId()) == provinceId)
|
childNav.setSelector(1);
|
childNavList.add(childNav);
|
}
|
|
nav.setSubIds(childNavList);
|
navList.add(nav);
|
|
Gson gson = new GsonBuilder().create();
|
Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().create();
|
|
JSONObject data = new JSONObject();
|
data.put("nav", gson.toJson(navList));
|
data.put("result", gson2.toJson(listExtra));
|
data.put("count", count);
|
|
return data;
|
}
|
|
private JSONObject searchDaTaoKeGoods(String key, int page, String filter, String order, String startprice,
|
String endprice) {
|
page=page+1;
|
int sort = DaTaoKeApiUtil.SORT_DEFAULT;
|
if ("5".equalsIgnoreCase(order)) {
|
sort = DaTaoKeApiUtil.SORT_COMMISSION;
|
} else if ("1".equalsIgnoreCase(order)) {
|
sort = DaTaoKeApiUtil.SORT_SALES;
|
} else if ("2".equalsIgnoreCase(order)) {
|
sort = DaTaoKeApiUtil.SORT_PRICE_HIGH_TO_LOW;
|
} else if ("3".equalsIgnoreCase(order)) {
|
sort = DaTaoKeApiUtil.SORT_PRICE_LOW_TO_HIGH;
|
}
|
|
List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
|
BigDecimal proportion = manageService.getFanLiRate();
|
|
DaTaoKeGoodsResult result = DaTaoKeApiUtil.search(key, null, page, 20, sort);
|
if (result != null && result.getGoodsList() != null)
|
for (DaTaoKeDetailV2 goods : result.getGoodsList()) {
|
listExtra.add(
|
TaoBaoUtil.getTaoBaoGoodsBriefExtra(TaoBaoUtil.convert(goods), proportion.toString(), null));
|
}
|
|
List<TaoBaoSearchNav> navList = new ArrayList<>();
|
Gson gson = new GsonBuilder().create();
|
Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().create();
|
|
JSONObject data = new JSONObject();
|
data.put("nav", gson.toJson(navList));
|
data.put("result", gson2.toJson(listExtra));
|
data.put("count", result.getTotalCount());
|
|
return data;
|
}
|
|
/**
|
* 设置查询佣金比例范围
|
*
|
* @param i
|
* @param sf
|
*/
|
public void setSearchTkRate(int i, SearchFilter sf) {
|
// 获取对应参数
|
String value = configService.get("tkRate_range");
|
|
if (!StringUtil.isNullOrEmpty(value)) {
|
|
JSONArray tkRatearray = JSONArray.fromObject(value);
|
|
if (tkRatearray != null) {
|
|
String start = tkRatearray.optJSONObject(i).optString("start");
|
|
if (!StringUtil.isNullOrEmpty(start)) {
|
int tkRate = (int) (Float.parseFloat(start) * 100);
|
sf.setStartTkRate(tkRate);
|
}
|
|
String end = tkRatearray.optJSONObject(i).optString("end");
|
if (!StringUtil.isNullOrEmpty(end)) {
|
int tkRate = (int) (Float.parseFloat(end) * 100);
|
sf.setEndTkRate(tkRate);
|
}
|
}
|
|
}
|
}
|
}
|