| | |
| | | import org.springframework.web.bind.annotation.RequestMethod;
|
| | | import org.yeshi.utils.JsonUtil;
|
| | |
|
| | | import com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.yeshi.fanli.dto.ConfigParamsDTO;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsClass;
|
| | | import com.yeshi.fanli.entity.bus.clazz.GoodsSubClass;
|
| | | import com.yeshi.fanli.entity.bus.clazz.TaoBaoClass;
|
| | | import com.yeshi.fanli.entity.bus.lable.QualityFactory;
|
| | | import com.yeshi.fanli.entity.taobao.SearchFilter;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoSearchResult;
|
| | | import com.yeshi.fanli.log.LogHelper;
|
| | | import com.yeshi.fanli.service.inter.clazz.GoodsSubClassLabelService;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsClassService;
|
| | | import com.yeshi.fanli.service.inter.goods.GoodsSubClassService;
|
| | | import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
|
| | | import com.yeshi.fanli.service.inter.lable.LabelClassService;
|
| | | import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
|
| | | import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
|
| | | import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
|
| | | import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsUpdateService;
|
| | | import com.yeshi.fanli.util.Constant;
|
| | | import com.yeshi.fanli.util.StringUtil;
|
| | | import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
|
| | | import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
| | | import com.yeshi.fanli.vo.goods.GoodsDetailVO;
|
| | | import com.yeshi.fanli.vo.goods.GoodsSubClassLabelVO;
|
| | |
|
| | | import net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | @Controller
|
| | | @RequestMapping("api/v2/class")
|
| | | public class GoodsClassControllerV2 {
|
| | |
|
| | |
|
| | | @Resource
|
| | | private GoodsClassService goodsClassService;
|
| | |
| | | @Resource
|
| | | private GoodsSubClassLabelService goodsSubClassLabelService;
|
| | |
|
| | | @Resource
|
| | | private GoodsSubClassService goodsSubClassService;
|
| | |
|
| | | @Resource(name = "taskExecutor")
|
| | | private TaskExecutor executor;
|
| | |
|
| | | @Resource
|
| | | private QualityGoodsService qualityGoodsService;
|
| | |
|
| | | @Resource
|
| | | private TaoKeGoodsService taoKeGoodsService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoClassService taoBaoClassService;
|
| | |
|
| | | @Resource
|
| | | private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
|
| | |
|
| | | @Resource
|
| | | private LabelClassService labelClassService;
|
| | |
|
| | | @Resource
|
| | | private TaoBaoGoodsUpdateService taoBaoGoodsUpdateService;
|
| | |
|
| | | /**
|
| | | * 一级分类
|
| | | * |
| | | * @param acceptData
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "listClass", method = RequestMethod.POST)
|
| | | public void listClass(AcceptData acceptData, PrintWriter out) {
|
| | | List<GoodsClass> list =goodsClassService.getEffectiveClassCache();
|
| | | if (list == null ) {
|
| | | List<GoodsClass> list = goodsClassService.getEffectiveClassCache();
|
| | | if (list == null) {
|
| | | list = new ArrayList<GoodsClass>();
|
| | | }
|
| | |
|
| | |
| | | */
|
| | | @RequestMapping(value = "listSubMap", method = RequestMethod.POST)
|
| | | public void listSubMap(AcceptData acceptData, Long cid, PrintWriter out) {
|
| | | if(cid == null) {
|
| | | if (cid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("参数不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | |
|
| | | List<GoodsSubClassLabelVO> list = goodsSubClassLabelService.listSubMapCache(cid);
|
| | | if (list == null) {
|
| | | list = new ArrayList<GoodsSubClassLabelVO>();
|
| | | }
|
| | | |
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("list", JsonUtil.getApiCommonGson().toJson(list));
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | /**
|
| | | * 分类下的精选商品
|
| | | */
|
| | | @RequestMapping("getClassGoods")
|
| | | public void getClassGoods(AcceptData acceptData, long gcid, int page, PrintWriter out) {
|
| | | GoodsClass goodsClass = goodsClassService.getGoodsClassCache(gcid);
|
| | | if (goodsClass == null) {
|
| | | out.print(JsonUtil.loadFalseResult("不存在该分类"));
|
| | | return;
|
| | | }
|
| | |
|
| | | |
| | | if (page < 1)
|
| | | page = 1;
|
| | |
|
| | | int pageSize = Constant.PAGE_SIZE;
|
| | |
|
| | | List<QualityFactory> listQuery = qualityGoodsService.listQueryByClassId((page - 1) * pageSize, pageSize, gcid);
|
| | | // 总条数
|
| | | long counttotal = 5000;
|
| | |
|
| | | List<TaoBaoGoodsBrief> updateGoodsList = new ArrayList<>();
|
| | |
|
| | | // 精选库数据小于10时,网络进行查询
|
| | | if (listQuery == null || listQuery.size() < 10) {
|
| | | long count = qualityGoodsService.countQueryClassId(gcid);
|
| | | int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
|
| | | page = page - totalPage;
|
| | | if (page < 1)
|
| | | page = 1;
|
| | |
|
| | | // 淘宝类目id
|
| | | String taoBaoCatIds = taoBaoClassService.getTaoBaoCatIds(gcid);
|
| | |
|
| | | SearchFilter filter = null;
|
| | |
|
| | | String searchParam = goodsClass.getSearchParam();
|
| | | if (!StringUtil.isNullOrEmpty(searchParam)) {
|
| | | Gson gs = new Gson();
|
| | | filter = gs.fromJson(searchParam, SearchFilter.class);
|
| | | } else {
|
| | | filter = new SearchFilter();
|
| | | }
|
| | |
|
| | | filter.setMaterialId("6707");
|
| | | filter.setPage(page);
|
| | | filter.setPageSize(pageSize);
|
| | | filter.setCateIds(taoBaoCatIds);
|
| | |
|
| | | JSONObject result = taoKeGoodsService.searchWuLiaoV2(filter,acceptData.getPlatform(),acceptData.getVersion());
|
| | | out.print(JsonUtil.loadTrueResult(result));
|
| | | return;
|
| | | }
|
| | |
|
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
| | |
|
| | | ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
|
| | | acceptData.getVersion());
|
| | | |
| | | // 精选库数据
|
| | | JSONArray array = new JSONArray();
|
| | | for (QualityFactory selectionGoods : listQuery) {
|
| | | TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
| | | if (taoBaoGoodsBrief == null) {
|
| | | continue;
|
| | | }
|
| | | updateGoodsList.add(taoBaoGoodsBrief);
|
| | | GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertTaoBao(taoBaoGoodsBrief, paramsDTO);
|
| | | array.add(gson.toJson(goodsDetailVO));
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("nav", null);
|
| | | data.put("count", counttotal);
|
| | | data.put("result", array);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | try {
|
| | | taoBaoGoodsUpdateService.addUpdateQueueAsync(updateGoodsList);
|
| | | } catch (Exception e) {
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 获取二级分类商品
|
| | | * |
| | | * @param acceptData
|
| | | * @param page
|
| | | * @param scid
|
| | | * @param filter
|
| | | * @param order
|
| | | * 来源:【推荐:0 | 综合:4 、综合只看有券 1 、综合只看天猫 1 | 价格:低到高3 高到低2 | 销量:1】
|
| | | * 排序值:【销量由高到低: 1 ; 销量由低到高 5; 价格从高到低: 2 ; 价格从低到高:3 ; 推广量高到低:4 ;
|
| | | * 其他默认: 销量由高到低】
|
| | | * |
| | | * @param startprice
|
| | | * 起始价格
|
| | | * @param endprice
|
| | | * 结束价格
|
| | | * @param fastFilter
|
| | | * fastFilter 有券 [{"type":"quantype"}] 天猫商品 [{"type":"shoptype"}]
|
| | | * @param totalSales
|
| | | * 销量以上
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getSubGoods", method = RequestMethod.POST)
|
| | | public void getSecondClassGoods(AcceptData acceptData, int page, long scid, String filter, String order,
|
| | | String startprice, String endprice, String fastFilter, Integer totalSales, PrintWriter out) {
|
| | |
|
| | | try {
|
| | | GoodsSubClass goodsSubClass = goodsSubClassService.getSubClassByPrimaryKeyCache(scid);
|
| | | if (goodsSubClass == null) {
|
| | | out.print(JsonUtil.loadFalseResult("不存在该分类"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 统计点击量
|
| | | if (page == 1) {
|
| | | goodsSubClassService.countClick(acceptData, goodsSubClass);
|
| | | }
|
| | |
|
| | | SearchFilter sf = new SearchFilter();
|
| | | String catesId = "";
|
| | | // 查询是否有淘宝分类ID
|
| | | List<TaoBaoClass> tbClassList = taoBaoClassService.listBySystemSubCid(0, 10, goodsSubClass.getId());
|
| | | if (tbClassList != null && tbClassList.size() > 0)
|
| | | for (TaoBaoClass tbc : tbClassList) {
|
| | | catesId += tbc.getCategoryId() + ",";
|
| | | }
|
| | | if (catesId.endsWith(","))
|
| | | catesId = catesId.substring(0, catesId.length() - 1);
|
| | | sf.setCateIds(catesId);
|
| | |
|
| | | // 按分类名称搜索
|
| | | if (!StringUtil.isNullOrEmpty(catesId)) {
|
| | | String searchParam = goodsSubClass.getSearchJson();
|
| | | Gson gs = new Gson();
|
| | | SearchFilter searchfilter = gs.fromJson(searchParam, SearchFilter.class);
|
| | | searchfilter.setCateIds(catesId);
|
| | | searchfilter.setPage(page);
|
| | | searchfilter.setPageSize(20);
|
| | | if (Integer.parseInt(order) == 0)
|
| | | searchfilter.setMaterialId("6707");
|
| | | taoKeGoodsService.setSearchFilter(searchfilter, filter, order, startprice, endprice, fastFilter,
|
| | | totalSales);
|
| | | TaoBaoSearchResult searchResult = TaoKeApiUtil.searchWuLiao(searchfilter);
|
| | | long count = searchResult.getPageEntity().getTotalCount();
|
| | |
|
| | | List<TaoBaoGoodsBrief> resultGoodsList = searchResult.getTaoBaoGoodsBriefs();
|
| | | // 查询是否超过了最大的商品数
|
| | | if ((resultGoodsList == null || resultGoodsList.size() < 20)
|
| | | && !StringUtil.isNullOrEmpty(goodsSubClass.getKey())) {
|
| | | if (resultGoodsList == null)
|
| | | resultGoodsList = new ArrayList<>();
|
| | |
|
| | | // 需要根据关键字查询
|
| | | searchfilter.setCateIds(null);
|
| | | searchfilter.setPage((int) (count % 20 == 0 ? count / 20 - 1 : count / 20));
|
| | | searchfilter.setPageSize(20);
|
| | | searchfilter.setKey(goodsSubClass.getKey());
|
| | | TaoBaoSearchResult searchResult2 = TaoKeApiUtil.searchWuLiao(searchfilter);
|
| | | if (searchResult2 != null) {
|
| | | List<TaoBaoGoodsBrief> resultListTemp = searchResult2.getTaoBaoGoodsBriefs();
|
| | | if (resultListTemp != null)
|
| | | resultGoodsList.addAll(resultListTemp);
|
| | | }
|
| | | }
|
| | |
|
| | | Gson gson2 = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
| | | .excludeFieldsWithoutExposeAnnotation().create();
|
| | |
|
| | | JSONArray array = new JSONArray();
|
| | | if (resultGoodsList != null) {
|
| | | ConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
|
| | | acceptData.getVersion());
|
| | | for (TaoBaoGoodsBrief goods : resultGoodsList) {
|
| | | GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertTaoBao(goods, paramsDTO);
|
| | | array.add(gson2.toJson(goodsDetailVO));
|
| | | }
|
| | | }
|
| | | JSONObject result = new JSONObject();
|
| | | result.put("result", array);
|
| | | result.put("count", result.optLong("count") + count);
|
| | | out.print(JsonUtil.loadTrueResult(result));
|
| | | return;
|
| | | } else {
|
| | | String searchParam = goodsSubClass.getSearchJson();
|
| | | Gson gs = new Gson();
|
| | | SearchFilter searchfilter = gs.fromJson(searchParam, SearchFilter.class);
|
| | | searchfilter.setCateIds(catesId);
|
| | | searchfilter.setPage(page);
|
| | | searchfilter.setPageSize(20);
|
| | | if (Integer.parseInt(order) == 0)
|
| | | searchfilter.setMaterialId("6707");
|
| | | searchfilter.setKey(goodsSubClass.getKey());
|
| | | taoKeGoodsService.setSearchFilter(searchfilter, filter, order, startprice, endprice, fastFilter,
|
| | | totalSales);
|
| | |
|
| | | JSONObject result = taoKeGoodsService.searchWuLiaoV2(searchfilter,acceptData.getPlatform(),acceptData.getVersion());
|
| | | out.print(JsonUtil.loadTrueResult(result));
|
| | | return;
|
| | | }
|
| | | } catch (Exception e) {
|
| | | out.print(JsonUtil.loadFalseResult("数据异常"));
|
| | | LogHelper.errorDetailInfo(e);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|