| | |
| | | package com.yeshi.fanli.controller.web;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.annotation.Resource;
|
| | |
|
| | | 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.TbImgUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.lable.QualityFactory;
|
| | | import com.yeshi.fanli.entity.bus.search.HotSearch;
|
| | | import com.yeshi.fanli.entity.bus.su.search.SuperHotSearch;
|
| | | import com.yeshi.fanli.entity.system.CustomerContent;
|
| | | 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.TaoBaoSearchNav;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.service.inter.config.CustomerContentService;
|
| | | import com.yeshi.fanli.service.inter.config.SuperHotSearchService;
|
| | | import com.yeshi.fanli.service.inter.config.SystemClientParamsService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
|
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
|
| | | import com.yeshi.fanli.service.inter.user.HistorySearchService;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("api/web/v1/webSearch")
|
| | | public class WebSearchController {
|
| | |
|
| | | @Resource
|
| | | private HistorySearchService historySearchService;
|
| | |
|
| | | @Resource
|
| | | private WebControllerUtil webControllerUtil;
|
| | |
|
| | | @Resource
|
| | | private HongBaoManageService manageService;
|
| | |
|
| | | @Resource
|
| | | private SystemClientParamsService systemClientParamsService;
|
| | |
|
| | | @Resource
|
| | | private SuperHotSearchService superHotSearchSerivce;
|
| | |
|
| | | @Resource
|
| | | private CustomerContentService customerContentService;
|
| | |
|
| | | @Resource
|
| | | private QualityGoodsService qualityGoodsService;
|
| | |
|
| | | @RequestMapping(value = "searchGoods", method = RequestMethod.GET)
|
| | | public void searchGoods(String callback, AcceptData acceptData, String kw, int page, int pagesize, String filters,
|
| | | String rate, String order, String startprice, String endprice, PrintWriter out) {
|
| | | /*
|
| | | * System system = webControllerUtil.getSystem(acceptData); if(system ==
|
| | | * null){
|
| | | * out.print(JsonUtil.loadFalseResult(WebControllerUtil.NOSYSTEM));
|
| | | * return; }
|
| | | */
|
| | | if (pagesize > 100)
|
| | | return;
|
| | |
|
| | | SearchFilter sf = new SearchFilter();
|
| | | sf.setPage(page);
|
| | | sf.setPageSize(pagesize);
|
| | | sf.setKey(StringUtil.isNullOrEmpty(kw) ? "" : kw);
|
| | | boolean recommend = false;
|
| | | if (!StringUtil.isNullOrEmpty(filters)) {
|
| | | JSONArray array = JSONArray.fromObject(filters);
|
| | | for (int i = 0; i < array.size(); i++) {
|
| | | String type = array.optJSONObject(i).optString("type");
|
| | | if ("quantype".equalsIgnoreCase(type)) {
|
| | | sf.setQuan(1);
|
| | | } else if ("baoyou".equalsIgnoreCase(type)) {
|
| | | sf.setBaoYou(true);
|
| | | } else if ("usertype".equalsIgnoreCase(type)) {
|
| | | sf.setTmall(true);
|
| | | } else if ("recommend".equalsIgnoreCase(type)) {
|
| | | //
|
| | | recommend = true;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(startprice))
|
| | | sf.setStartPrice(new BigDecimal(startprice));
|
| | | if (!StringUtil.isNullOrEmpty(endprice))
|
| | | sf.setEndPrice(new BigDecimal(endprice));
|
| | |
|
| | | if (!StringUtil.isNullOrEmpty(rate))
|
| | | try {
|
| | | sf.setStartTkRate(Integer.parseInt(rate));
|
| | | } catch (Exception e) {
|
| | | }
|
| | | if (!StringUtil.isNullOrEmpty(order))
|
| | | if (Integer.parseInt(order) == 0)
|
| | | sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW);
|
| | | else if (Integer.parseInt(order) == 2)
|
| | | sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH);
|
| | | else if (Integer.parseInt(order) == 3)
|
| | | sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW);
|
| | | else if (Integer.parseInt(order) == 4)
|
| | | sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW);
|
| | | if (StringUtil.isNullOrEmpty(kw))
|
| | | recommend = true;
|
| | |
|
| | | List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>();
|
| | |
|
| | | long count = 0;
|
| | | if (recommend) {
|
| | |
|
| | | List<QualityFactory> listQuery = qualityGoodsService.listRecommendBykey((page - 1) * pagesize, pagesize, kw,
|
| | | sf.getQuan() == 1 ? 1 : 0, sf.isTmall() ? 1 : 0,
|
| | | StringUtil.isNullOrEmpty(startprice) ? null : Double.parseDouble(startprice),
|
| | | StringUtil.isNullOrEmpty(endprice) ? null : Double.parseDouble(endprice),
|
| | | StringUtil.isNullOrEmpty(rate) ? null : Double.parseDouble(rate), null, 1);
|
| | |
|
| | | 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));
|
| | | }
|
| | | }
|
| | | count = qualityGoodsService.countRecommendBykey(kw, sf.getQuan() == 1 ? 1 : 0, sf.isTmall() ? 1 : 0,
|
| | | StringUtil.isNullOrEmpty(startprice) ? null : Double.parseDouble(startprice),
|
| | | StringUtil.isNullOrEmpty(endprice) ? null : Double.parseDouble(endprice),
|
| | | StringUtil.isNullOrEmpty(rate) ? null : Double.parseDouble(rate), null);
|
| | |
|
| | | } else {
|
| | | TaoBaoSearchResult result = TaoBaoUtil.search(sf);
|
| | | if (result != null) {
|
| | | 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 (taoBaoGoodsBriefs != null)
|
| | | for (TaoBaoGoodsBrief bf : taoBaoGoodsBriefs) {
|
| | | listExtra.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), ""));
|
| | | }
|
| | | } else {
|
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra;
|
| | | if (taoBaoGoodsBriefs != null)
|
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) {
|
| | | taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
| | | proportion.toString(), "");
|
| | | listExtra.add(taoBaoGoodsBriefExtra);
|
| | | }
|
| | | }
|
| | | count = result.getTaoBaoHead().getDocsfound();
|
| | | }
|
| | |
|
| | | }
|
| | | JSONObject data = new JSONObject();
|
| | | Gson gson2 = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
|
| | | data.put("result", gson2.toJson(listExtra));
|
| | | data.put("count", count);
|
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data)));
|
| | | }
|
| | |
|
| | | }
|
| | | package com.yeshi.fanli.controller.web; |
| | | |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | 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.TbImgUtil; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.fanli.entity.accept.AcceptData; |
| | | import com.yeshi.fanli.entity.bus.lable.QualityFactory; |
| | | import com.yeshi.fanli.entity.taobao.SearchFilter; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBrief; |
| | | import com.yeshi.goods.facade.entity.taobao.TaoBaoGoodsBriefExtra; |
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult; |
| | | import com.yeshi.fanli.service.inter.config.CustomerContentService; |
| | | import com.yeshi.fanli.service.inter.config.SuperHotSearchService; |
| | | import com.yeshi.fanli.service.inter.config.SystemClientParamsService; |
| | | import com.yeshi.fanli.service.inter.lable.QualityGoodsService; |
| | | import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; |
| | | import com.yeshi.fanli.service.inter.user.HistorySearchService; |
| | | import com.yeshi.fanli.util.StringUtil; |
| | | import com.yeshi.fanli.util.taobao.TaoBaoUtil; |
| | | |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/web/v1/webSearch") |
| | | public class WebSearchController { |
| | | |
| | | @Resource |
| | | private HistorySearchService historySearchService; |
| | | |
| | | @Resource |
| | | private WebControllerUtil webControllerUtil; |
| | | |
| | | @Resource |
| | | private HongBaoManageService manageService; |
| | | |
| | | @Resource |
| | | private SystemClientParamsService systemClientParamsService; |
| | | |
| | | @Resource |
| | | private SuperHotSearchService superHotSearchSerivce; |
| | | |
| | | @Resource |
| | | private CustomerContentService customerContentService; |
| | | |
| | | @Resource |
| | | private QualityGoodsService qualityGoodsService; |
| | | |
| | | @RequestMapping(value = "searchGoods", method = RequestMethod.GET) |
| | | public void searchGoods(String callback, AcceptData acceptData, String kw, int page, int pagesize, String filters, |
| | | String rate, String order, String startprice, String endprice, PrintWriter out) { |
| | | /* |
| | | * System system = webControllerUtil.getSystem(acceptData); if(system == |
| | | * null){ |
| | | * out.print(JsonUtil.loadFalseResult(WebControllerUtil.NOSYSTEM)); |
| | | * return; } |
| | | */ |
| | | if (pagesize > 100) |
| | | return; |
| | | |
| | | SearchFilter sf = new SearchFilter(); |
| | | sf.setPage(page); |
| | | sf.setPageSize(pagesize); |
| | | sf.setKey(StringUtil.isNullOrEmpty(kw) ? "" : kw); |
| | | boolean recommend = false; |
| | | if (!StringUtil.isNullOrEmpty(filters)) { |
| | | JSONArray array = JSONArray.fromObject(filters); |
| | | for (int i = 0; i < array.size(); i++) { |
| | | String type = array.optJSONObject(i).optString("type"); |
| | | if ("quantype".equalsIgnoreCase(type)) { |
| | | sf.setQuan(1); |
| | | } else if ("baoyou".equalsIgnoreCase(type)) { |
| | | sf.setBaoYou(true); |
| | | } else if ("usertype".equalsIgnoreCase(type)) { |
| | | sf.setTmall(true); |
| | | } else if ("recommend".equalsIgnoreCase(type)) { |
| | | // |
| | | recommend = true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(startprice)) |
| | | sf.setStartPrice(new BigDecimal(startprice)); |
| | | if (!StringUtil.isNullOrEmpty(endprice)) |
| | | sf.setEndPrice(new BigDecimal(endprice)); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(rate)) |
| | | try { |
| | | sf.setStartTkRate(Integer.parseInt(rate)); |
| | | } catch (Exception e) { |
| | | } |
| | | if (!StringUtil.isNullOrEmpty(order)) |
| | | if (Integer.parseInt(order) == 0) |
| | | sf.setSort(TaoBaoUtil.SORT_SALE_HIGH_TO_LOW); |
| | | else if (Integer.parseInt(order) == 2) |
| | | sf.setSort(TaoBaoUtil.SORT_PRICE_LOW_TO_HIGH); |
| | | else if (Integer.parseInt(order) == 3) |
| | | sf.setSort(TaoBaoUtil.SORT_PRICE_HIGH_TO_LOW); |
| | | else if (Integer.parseInt(order) == 4) |
| | | sf.setSort(TaoBaoUtil.SORT_TKRATE_HIGH_TO_LOW); |
| | | if (StringUtil.isNullOrEmpty(kw)) |
| | | recommend = true; |
| | | |
| | | List<TaoBaoGoodsBriefExtra> listExtra = new ArrayList<TaoBaoGoodsBriefExtra>(); |
| | | |
| | | long count = 0; |
| | | if (recommend) { |
| | | |
| | | List<QualityFactory> listQuery = qualityGoodsService.listRecommendBykey((page - 1) * pagesize, pagesize, kw, |
| | | sf.getQuan() == 1 ? 1 : 0, sf.isTmall() ? 1 : 0, |
| | | StringUtil.isNullOrEmpty(startprice) ? null : Double.parseDouble(startprice), |
| | | StringUtil.isNullOrEmpty(endprice) ? null : Double.parseDouble(endprice), |
| | | StringUtil.isNullOrEmpty(rate) ? null : Double.parseDouble(rate), null, 1); |
| | | |
| | | BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem()); |
| | | /* 遍历列表数据 */ |
| | | 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)); |
| | | } |
| | | } |
| | | count = qualityGoodsService.countRecommendBykey(kw, sf.getQuan() == 1 ? 1 : 0, sf.isTmall() ? 1 : 0, |
| | | StringUtil.isNullOrEmpty(startprice) ? null : Double.parseDouble(startprice), |
| | | StringUtil.isNullOrEmpty(endprice) ? null : Double.parseDouble(endprice), |
| | | StringUtil.isNullOrEmpty(rate) ? null : Double.parseDouble(rate), null); |
| | | |
| | | } else { |
| | | TaoBaoSearchResult result = TaoBaoUtil.search(sf,null,null); |
| | | if (result != null) { |
| | | List<TaoBaoGoodsBrief> taoBaoGoodsBriefs = result.getTaoBaoGoodsBriefs(); |
| | | int fq = sf.getQuan(); |
| | | int fh = sf.getHongbao(); |
| | | boolean ft = sf.isTmall(); |
| | | BigDecimal proportion = manageService.getFanLiRate(acceptData.getSystem()); |
| | | if (fq == 0 && fh == 0 && !ft) { |
| | | if (taoBaoGoodsBriefs != null) |
| | | for (TaoBaoGoodsBrief bf : taoBaoGoodsBriefs) { |
| | | listExtra.add(TaoBaoUtil.getTaoBaoGoodsBriefExtra(bf, proportion.toString(), "")); |
| | | } |
| | | } else { |
| | | TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra; |
| | | if (taoBaoGoodsBriefs != null) |
| | | for (TaoBaoGoodsBrief taoBaoGoodsBrief : taoBaoGoodsBriefs) { |
| | | taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, |
| | | proportion.toString(), ""); |
| | | listExtra.add(taoBaoGoodsBriefExtra); |
| | | } |
| | | } |
| | | count = result.getTaoBaoHead().getDocsfound(); |
| | | } |
| | | |
| | | } |
| | | JSONObject data = new JSONObject(); |
| | | Gson gson2 = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create(); |
| | | data.put("result", gson2.toJson(listExtra)); |
| | | data.put("count", count); |
| | | out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(data))); |
| | | } |
| | | |
| | | } |