package com.yeshi.fanli.controller.apph5;
|
|
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.MergeClass;
|
import com.yeshi.fanli.entity.bus.lable.QualityFactory;
|
import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBriefExtra;
|
import com.yeshi.fanli.entity.taobao.TaoBaoHongBaoInfo;
|
import com.yeshi.fanli.entity.taobao.TaobaoMeterial;
|
import com.yeshi.fanli.entity.taobao.dataoke.DaTaoKeDetail;
|
import com.yeshi.fanli.exception.taobao.TaoKeApiException;
|
import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.config.ConfigService;
|
import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
|
import com.yeshi.fanli.service.inter.goods.GoodsClassService;
|
import com.yeshi.fanli.service.inter.goods.TaoBaoClassService;
|
import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService;
|
import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
import com.yeshi.fanli.service.inter.lable.LabelService;
|
import com.yeshi.fanli.service.inter.lable.MergeClassService;
|
import com.yeshi.fanli.service.inter.lable.QualityFactoryService;
|
import com.yeshi.fanli.service.inter.lable.QualityFlashSaleService;
|
import com.yeshi.fanli.service.inter.lable.QualityGoodsService;
|
import com.yeshi.fanli.service.inter.lable.TaoKeGoodsService;
|
import com.yeshi.fanli.service.inter.taobao.TaoBaoGoodsActivityService;
|
import com.yeshi.fanli.service.inter.taobao.TaobaoMeterialService;
|
import com.yeshi.fanli.service.inter.taobao.dataoke.DaTaoKeGoodsDetailService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.TimeUtil;
|
import com.yeshi.fanli.util.taobao.TaoBaoUtil;
|
import com.yeshi.fanli.util.taobao.TaoKeApiUtil;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("api/apph5/v1/quality")
|
public class AppH5QualityGoodsController {
|
|
@Resource
|
private LabelService labelService;
|
|
@Resource
|
private QualityFactoryService selectionGoodsService;
|
|
@Resource
|
private TaoBaoGoodsBriefService taoBaoGoodsBriefService;
|
|
@Resource
|
private TaobaoMeterialService taobaoMeterialService;
|
|
@Resource
|
private TaoKeGoodsService taoKeGoodsService;
|
|
@Resource
|
private GoodsClassService goodsClassService;
|
|
@Resource
|
private HongBaoManageService manageService;
|
|
@Resource
|
private MergeClassService mergeClassService;
|
|
@Resource
|
private TaoBaoClassService taoBaoClassService;
|
|
@Resource
|
private QualityGoodsService qualityGoodsService;
|
|
@Resource
|
private QualityFlashSaleService qualityFlashSaleService;
|
|
@Resource
|
private CollectionGoodsV2Service collectionGoodsV2Service;
|
|
@Resource
|
private HongBaoManageService hongBaoManageService;
|
|
@Resource
|
private ConfigService configService;
|
|
@Resource
|
private TaoBaoGoodsActivityService taoBaoGoodsActivityService;
|
|
@Resource
|
private DaTaoKeGoodsDetailService daTaoKeGoodsDetailService;
|
|
/**
|
* 9.9商品
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get9k9")
|
public void get9k9(String callback, Integer page, Long mcid, PrintWriter out) {
|
get9k9ClassGoods(callback, out, page, 500, new BigDecimal(209.9), new BigDecimal(0), new BigDecimal(9.9), mcid);
|
|
}
|
|
/**
|
* 19.9商品
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get19k9")
|
public void get19k9(String callback, Integer page, Long mcid, PrintWriter out) {
|
get9k9ClassGoods(callback, out, page, 500, new BigDecimal(319.9), new BigDecimal(9.9), new BigDecimal(19.9),
|
mcid);
|
|
}
|
|
/**
|
* 29.9商品
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get29k9")
|
public void get29k9(String callback, Integer page, Long mcid, PrintWriter out) {
|
get9k9ClassGoods(callback, out, page, 500, new BigDecimal(429.9), new BigDecimal(19.9), new BigDecimal(29.9),
|
mcid);
|
|
}
|
|
/**
|
* 49.9商品
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get49k9")
|
public void get49k9(String callback, Integer page, Long mcid, PrintWriter out) {
|
get9k9ClassGoods(callback, out, page, 500, new BigDecimal(549.9), new BigDecimal(29.9), new BigDecimal(49.9),
|
mcid);
|
}
|
|
/**
|
* 9k9类型的商品查询
|
*
|
* @param labName
|
* 标签名称
|
* @param callback
|
* @param page
|
* @param mcid
|
* 对应类目id
|
* @param out
|
*/
|
public void get9k9ClassGoods(String callback, PrintWriter out, Integer page, Integer biz30day, BigDecimal zkPrice,
|
BigDecimal minQuanPrice, BigDecimal maxQuanPrice, Long mcid) {
|
try {
|
if (page == null || page <= 0) {
|
page = 1;
|
}
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
String mergeCids = null;
|
if (mcid != null && (!mcid.equals(0) || mcid != 0)) {
|
MergeClass mergeClass = mergeClassService.selectByPrimaryKeyCache(mcid);
|
if (mergeClass != null) {
|
// 分类id,隔开
|
mergeCids = mergeClass.getMergeCids();
|
}
|
}
|
|
// 根据标签id 查询数据
|
List<QualityFactory> listQuery = qualityGoodsService.get9k9ClassGoods((page - 1) * pageSize, pageSize,
|
biz30day, zkPrice, minQuanPrice, maxQuanPrice, mergeCids);
|
if (listQuery == null || listQuery.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
// 总条数
|
long count = qualityGoodsService.count9k9ClassGoods(biz30day, zkPrice, minQuanPrice, maxQuanPrice,
|
mergeCids);
|
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = hongBaoManageService.getFanLiRate();
|
/* 遍历列表数据 */
|
for (QualityFactory selectionGoods : listQuery) {
|
TaoBaoGoodsBrief goodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
if (goodsBrief == null) {
|
continue;
|
}
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion.toString(), null)));
|
}
|
|
// 618活动
|
if (System.currentTimeMillis() < TimeUtil.convertToTimeTemp("2019-06-19", "yyyy-MM-dd")) {
|
if (mcid == null || mcid == 0) {
|
count = taoBaoGoodsActivityService.countByPrice(minQuanPrice,
|
maxQuanPrice.add(new BigDecimal("0.1")));
|
List<TaoBaoGoodsBrief> goodsList = taoBaoGoodsActivityService.listByPrice(minQuanPrice,
|
maxQuanPrice.add(new BigDecimal("0.1")), page, pageSize);
|
if (goodsList != null) {
|
array.clear();
|
for (TaoBaoGoodsBrief goods : goodsList) {
|
array.add(gson
|
.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goods, proportion.toString(), null)));
|
}
|
}
|
}
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("result_list", array);
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
LogHelper.errorDetailInfo(e);
|
}
|
}
|
|
/**
|
* 9.9商品-每日必抢
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get9k9EverydayRob")
|
public void get9k9EverydayRob(String callback, Integer page, Long mcid, PrintWriter out) {
|
queryEverydayRob(callback, out, page, new BigDecimal(209.9), new BigDecimal(0), new BigDecimal(9.9));
|
|
}
|
|
/**
|
* 19.9商品-每日必抢
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get19k9EverydayRob")
|
public void get19k9EverydayRob(String callback, Integer page, Long mcid, PrintWriter out) {
|
queryEverydayRob(callback, out, page, new BigDecimal(319.9), new BigDecimal(9.9), new BigDecimal(19.9));
|
}
|
|
/**
|
* 29.9商品-每日必抢
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get29k9EverydayRob")
|
public void get29k9EverydayRob(String callback, Integer page, Long mcid, PrintWriter out) {
|
queryEverydayRob(callback, out, page, new BigDecimal(429.9), new BigDecimal(19.9), new BigDecimal(29.9));
|
|
}
|
|
/**
|
* 49.9商品-每日必抢
|
*
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "get49k9EverydayRob")
|
public void get49k9EverydayRob(String callback, Integer page, Long mcid, PrintWriter out) {
|
queryEverydayRob(callback, out, page, new BigDecimal(549.9), new BigDecimal(29.9), new BigDecimal(49.9));
|
|
}
|
|
/**
|
* 每日必抢
|
*
|
* @param page
|
* @param pageSize
|
* @param labId
|
* @return
|
* @throws Exception
|
*/
|
public void queryEverydayRob(String callback, PrintWriter out, Integer page, BigDecimal zkPrice,
|
BigDecimal minQuanPrice, BigDecimal maxQuanPrice) {
|
|
if (page == null)
|
page = 1;
|
|
// 20 条一页请求到3页结束今日新品
|
if (page > 3) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
try {
|
int pageSize = Constant.PAGE_SIZE;
|
List<QualityFactory> listQuery = qualityGoodsService.listQueryEverydayRob((page - 1) * pageSize, pageSize,
|
zkPrice, minQuanPrice, maxQuanPrice);
|
if (listQuery == null || listQuery.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
for (QualityFactory selectionGoods : listQuery) {
|
TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
if (taoBaoGoodsBrief == null) {
|
continue;
|
}
|
array.add(gson
|
.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
|
}
|
|
long count = qualityGoodsService.countQueryEverydayRob(zkPrice, minQuanPrice, maxQuanPrice);
|
if (count < 50) {
|
count = listQuery.size();
|
} else {
|
count = 50;
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("result_list", array);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
LogHelper.errorDetailInfo(e);
|
}
|
}
|
|
/**
|
* 品牌购 (官方推荐【品牌券】接口)
|
*
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "getBrandsGoods")
|
public void getBrandsGoods(String callback, Integer page, String subName, PrintWriter out) {
|
|
try {
|
|
List<TaobaoMeterial> list = taobaoMeterialService.selectByClassNameAndSuperNameCache(subName, "品牌券");
|
|
if (list == null || list.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial taobaoMeterial = list.get(0);
|
Integer materialId = taobaoMeterial.getMaterialId();
|
if (materialId == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
JSONObject jsonObject = taoKeGoodsService.getBrandsGoods(materialId, page, pageSize);
|
|
if (jsonObject == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(jsonObject));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 品牌购 (官方推荐【品牌券】接口)
|
*
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "getBrandsShops")
|
public void getBrandsShops(String callback, Integer page, PrintWriter out) {
|
|
try {
|
String subName = "综合";
|
List<TaobaoMeterial> list = taobaoMeterialService.selectByClassNameAndSuperNameCache(subName, "品牌券");
|
|
if (list == null || list.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial taobaoMeterial = list.get(0);
|
Integer materialId = taobaoMeterial.getMaterialId();
|
if (materialId == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
JSONObject jsonObject = taoKeGoodsService.getBrandsShops(materialId, page, pageSize);
|
|
if (jsonObject == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(jsonObject));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 大额券 (官方推荐中的【特惠】)
|
*
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "getPreferential", method = RequestMethod.POST)
|
public void getPreferential(int page, PrintWriter out) {
|
|
try {
|
|
List<TaobaoMeterial> taobaoMeterials = taobaoMeterialService.selectByClassNameAndSuperNameCache(null, "特惠");
|
|
if (taobaoMeterials == null || taobaoMeterials.size() == 0) {
|
out.print(JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial meterial = taobaoMeterials.get(0);
|
Integer materialId = meterial.getMaterialId();
|
if (materialId == null) {
|
out.print(JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page < 1)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
JSONObject jsonObject = queryMaterialGoods(page, pageSize, materialId);
|
|
if (jsonObject == null) {
|
out.print(JsonUtil.loadFalseResult(2, "暂无更多数据"));
|
}
|
out.print(JsonUtil.loadTrueResult(jsonObject));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult("查询失败"));
|
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 超高奖金(官方推荐中的【有好货】)
|
*
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "getSuperiors", method = RequestMethod.POST)
|
public void getSuperiors(int page, PrintWriter out) {
|
|
try {
|
|
List<TaobaoMeterial> taobaoMeterials = taobaoMeterialService.selectByClassNameAndSuperNameCache(null,
|
"有好货");
|
|
if (taobaoMeterials == null || taobaoMeterials.size() == 0) {
|
out.print(JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial meterial = taobaoMeterials.get(0);
|
Integer materialId = meterial.getMaterialId();
|
if (materialId == null) {
|
out.print(JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page < 1)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
JSONObject jsonObject = queryMaterialGoods(page, pageSize, materialId);
|
|
if (jsonObject == null) {
|
out.print(JsonUtil.loadFalseResult(2, "暂无更多数据"));
|
}
|
out.print(JsonUtil.loadTrueResult(jsonObject));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult("查询失败"));
|
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 今日新品【(官方推荐【好券直播】接口)
|
*
|
* @param page
|
* @param subName
|
* 子类名称
|
*/
|
@RequestMapping(value = "todayNew")
|
public void todayNew(String callback, Integer page, String subName, String uid, PrintWriter out) {
|
|
try {
|
|
List<TaobaoMeterial> list = taobaoMeterialService.selectByClassNameAndSuperNameCache(subName, "好券直播");
|
|
if (list == null || list.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial taobaoMeterial = list.get(0);
|
Integer materialId = taobaoMeterial.getMaterialId();
|
if (materialId == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
List<TaoBaoGoodsBrief> listMaterial = taoKeGoodsService.listByMaterial(materialId, page, pageSize);
|
|
if (listMaterial == null || listMaterial.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
|
/* 遍历列表数据 */
|
for (TaoBaoGoodsBrief taoBaoGoodsBrief : listMaterial) {
|
|
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();
|
pictUrl = pictUrl.replaceAll("320x320", "640x640");
|
taoBaoGoodsBrief.setPictUrl(pictUrl);
|
|
int collected = 0;
|
// 判断收藏
|
if (!StringUtil.isNullOrEmpty(uid)) {
|
CollectionGoodsV2 collectionGoods = collectionGoodsV2Service
|
.findByUidAndAuctionId(Long.parseLong(uid), taoBaoGoodsBrief.getAuctionId());
|
if (collectionGoods != null) {
|
collected = 1;
|
}
|
}
|
|
TaoBaoGoodsBriefExtra taoBaoGoodsBriefExtra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
proportion.toString(), null);
|
taoBaoGoodsBriefExtra.setCollected(collected);
|
|
array.add(gson.toJson(taoBaoGoodsBriefExtra));
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("result_list", array);
|
data.put("count", 1000);
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 潮品热卖(官方推荐中的【潮流范】)
|
*
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "getFashions")
|
public void getFashions(String callback, Integer page, PrintWriter out) {
|
|
try {
|
|
List<TaobaoMeterial> taobaoMeterials = taobaoMeterialService.selectByClassNameAndSuperNameCache(null,
|
"潮流范");
|
|
if (taobaoMeterials == null || taobaoMeterials.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial meterial = taobaoMeterials.get(0);
|
Integer materialId = meterial.getMaterialId();
|
if (materialId == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page == null) {
|
page = 1;
|
}
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
JSONObject jsonObject = queryMaterialGoods(page, pageSize, materialId);
|
|
if (jsonObject == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(jsonObject));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 母婴精选(官方推荐中的【母婴主题】)
|
*
|
* @param page
|
* @param out
|
*/
|
@RequestMapping(value = "getPregnantBaby")
|
public void getPregnantBaby(AcceptData acceptData, String callback, Integer page, String subName, PrintWriter out) {
|
|
try {
|
|
List<TaobaoMeterial> taobaoMeterials = taobaoMeterialService.selectByClassNameAndSuperNameCache(subName,
|
"母婴主题");
|
|
if (taobaoMeterials == null || taobaoMeterials.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
TaobaoMeterial meterial = taobaoMeterials.get(0);
|
Integer materialId = meterial.getMaterialId();
|
if (materialId == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("未检索到数据"));
|
return;
|
}
|
|
if (page == null) {
|
page = 1;
|
}
|
int pageSize = Constant.PAGE_SIZE;
|
|
JSONObject jsonObject = queryMaterialGoods(page, pageSize, materialId);
|
|
if (jsonObject == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
}
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(jsonObject));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
|
try {
|
LogHelper.errorDetailInfo(e);
|
} catch (Exception e1) {
|
e1.printStackTrace();
|
}
|
}
|
}
|
|
/**
|
* 推荐查询接口对接-公用方法
|
*
|
* @param page
|
* @param pageSize
|
* @param materialId
|
* @return
|
* @throws Exception
|
*/
|
public JSONObject queryMaterialGoods(int page, int pageSize, Integer materialId) throws Exception {
|
|
List<TaoBaoGoodsBrief> listBrands = taoKeGoodsService.listByMaterial(materialId, page, pageSize);
|
|
if (listBrands == null || listBrands.size() == 0) {
|
return null;
|
}
|
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
|
/* 遍历列表数据 */
|
for (TaoBaoGoodsBrief taoBaoGoodsBrief : listBrands) {
|
|
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));
|
}
|
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("result_list", array);
|
data.put("count", 1000);
|
|
return data;
|
|
}
|
|
/**
|
* 限时抢购
|
*
|
* @param callback
|
* @param page
|
* @param out
|
*/
|
@RequestMapping("getFlashSale")
|
public void getFlashSale(String callback, Integer page, Long auctionId, PrintWriter out) {
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
int type = qualityFlashSaleService.getNowType();
|
|
TaoBaoGoodsBrief goodsBrief = null;
|
if (page == 1 && auctionId != null) {
|
List<TaoBaoGoodsBrief> list = taoBaoGoodsBriefService.queryByAuctionId(auctionId);
|
if (list != null && list.size() > 0) {
|
goodsBrief = list.get(0);
|
}
|
}
|
|
if (goodsBrief != null) {
|
pageSize = pageSize - 1;
|
}
|
|
List<QualityFactory> listQuery = qualityGoodsService.listQueryByFlashSale((page - 1) * pageSize, pageSize);
|
|
// 精选库数据为空
|
if (listQuery == null || listQuery.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
long count = 3000;
|
|
// 精选库数据处理返回 前端
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
|
if (goodsBrief != null) {
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(goodsBrief, proportion.toString(), null)));
|
}
|
|
// 遍历列表数据
|
for (QualityFactory quality : listQuery) {
|
|
TaoBaoGoodsBrief taoBaoGoodsBrief = quality.getTaoBaoGoodsBrief();
|
if (taoBaoGoodsBrief == null) {
|
continue;
|
}
|
|
if (goodsBrief != null && auctionId.equals(taoBaoGoodsBrief.getAuctionId())) {
|
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));
|
}
|
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("type", type);
|
data.put("result_list", array);
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
|
@RequestMapping("getFlashSaleNew")
|
public void getFlashSaleNew(String callback, Integer page, Long auctionId, String time, PrintWriter out) {
|
List<DaTaoKeDetail> detailList0 = daTaoKeGoodsDetailService.getDingDongQiangData(time);
|
if (detailList0 == null)
|
detailList0 = new ArrayList<>();
|
List<DaTaoKeDetail> detailList = new ArrayList<>();
|
detailList.addAll(detailList0);
|
JSONArray array = new JSONArray();
|
if (page == 1) {
|
if (auctionId != null && detailList != null)
|
for (int i = 0; i < detailList.size(); i++) {
|
if (detailList.get(i).getGoodsId().longValue() == auctionId) {
|
DaTaoKeDetail goods = detailList.get(i);
|
detailList.remove(i);
|
detailList.add(0, goods);
|
break;
|
}
|
}
|
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
if (detailList != null)
|
for (DaTaoKeDetail detail : detailList) {
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(TaoBaoUtil.convert(detail),
|
hongBaoManageService.getFanLiRate() + "", null)));
|
}
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", detailList.size());
|
data.put("result_list", array);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
* 大额券(券面值范围)
|
*
|
* @param callback
|
* @param amount
|
* @param page
|
* @param out
|
*/
|
@RequestMapping("choiceCouponAmount")
|
public void choiceCouponAmount(String callback, Integer amount, Integer page, PrintWriter out) {
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
Integer startAmount = null;
|
Integer endAmount = null;
|
|
if (amount.equals(1)) {
|
startAmount = 5;
|
endAmount = 10;
|
} else if (amount.equals(2)) {
|
startAmount = 10;
|
endAmount = 30;
|
} else if (amount.equals(3)) {
|
startAmount = 30;
|
endAmount = 50;
|
} else if (amount.equals(4)) {
|
startAmount = 50;
|
}
|
|
Integer startPropor = 20;
|
|
List<QualityFactory> listQuery = qualityGoodsService.listQueryByCouponAmount((page - 1) * pageSize, pageSize,
|
startAmount, endAmount, startPropor);
|
|
if (listQuery == null || listQuery.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
long count = qualityGoodsService.countQueryByCouponAmount(startAmount, endAmount, startPropor);
|
|
// 精选库数据处理返回 前端
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
// 遍历列表数据
|
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));
|
}
|
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("result", array);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
* 超高奖金
|
*
|
* @param callback
|
* @param page
|
* @param type
|
* @param out
|
*/
|
@RequestMapping("choiceRebate")
|
public void choiceRebate(String callback, Integer page, Integer type, PrintWriter out) {
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
Integer startAmount = null;
|
Integer endAmount = null;
|
|
if (type.equals(1)) {
|
startAmount = 1;
|
endAmount = 5;
|
} else if (type.equals(2)) {
|
startAmount = 5;
|
endAmount = 10;
|
} else if (type.equals(3)) {
|
startAmount = 10;
|
endAmount = 15;
|
} else if (type.equals(4)) {
|
startAmount = 15;
|
}
|
|
double tkRate = 20.00;
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
List<QualityFactory> listQuery = qualityGoodsService.listQueryByRebateAmount((page - 1) * pageSize, pageSize,
|
proportion.toString(), startAmount, endAmount, tkRate);
|
|
if (listQuery == null || listQuery.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
long count = qualityGoodsService.countQueryByRebateAmount(proportion.toString(), startAmount, endAmount,
|
tkRate);
|
|
// 精选库数据处理返回 前端
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
// 遍历列表数据
|
for (QualityFactory quality : listQuery) {
|
|
TaoBaoGoodsBrief taoBaoGoodsBrief = quality.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));
|
}
|
|
array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, proportion.toString(), null)));
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("result_list", array);
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
}
|
|
/**
|
* 超高奖金
|
*
|
* @param callback
|
* @param page
|
* @param type
|
* @param out
|
*/
|
@RequestMapping("recommendToIndex")
|
public void recommendToIndex(String callback, Integer page, PrintWriter out) {
|
|
if (page == null)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
JSONArray array = qualityGoodsService.getRecommendToIndex((page - 1) * pageSize, pageSize,
|
proportion.toString());
|
|
if (array == null) {
|
out.print(JsonUtil.loadFalseResult("没有更多了"));
|
return;
|
}
|
|
long count = qualityGoodsService.countRecommendToIndex(proportion.toString());
|
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("result_list", array);
|
|
out.print(JsonUtil.loadTrueResult(data));
|
return;
|
}
|
|
/**
|
* 超高奖金
|
*
|
* @param callback
|
* @param page
|
* @param type
|
* @param out
|
*/
|
@RequestMapping("freeGoods")
|
public void freeGoods(String callback, Integer page, PrintWriter out) {
|
try {
|
if (page == null || page < 1)
|
page = 1;
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
List<QualityFactory> listQuery = qualityGoodsService.listFreeGoods((page - 1) * pageSize, pageSize);
|
if (listQuery == null || listQuery.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(2, "没有更多了"));
|
return;
|
}
|
|
List<Long> listGid = new ArrayList<Long>();
|
for (QualityFactory qualityFactory : listQuery) {
|
TaoBaoGoodsBrief taoBaoGoodsBrief = qualityFactory.getTaoBaoGoodsBrief();
|
|
if (taoBaoGoodsBrief == null) {
|
continue;
|
}
|
listGid.add(taoBaoGoodsBrief.getAuctionId());
|
}
|
|
// API网络接口验证是否在售
|
List<TaoBaoGoodsBrief> listTaoKeGoods = null;
|
try {
|
listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
|
} catch (TaoKeApiException e) {
|
e.printStackTrace();
|
} catch (TaobaoGoodsDownException e) {
|
e.printStackTrace();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
JSONArray array = new JSONArray();
|
Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
|
.excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
|
|
BigDecimal proportion = manageService.getFanLiRate();
|
/* 遍历列表数据 */
|
for (QualityFactory selectionGoods : listQuery) {
|
|
TaoBaoGoodsBrief taoBaoGoodsBrief = selectionGoods.getTaoBaoGoodsBrief();
|
|
if (taoBaoGoodsBrief == null) {
|
continue;
|
}
|
|
if (listTaoKeGoods != null && listTaoKeGoods.size() > 0) {
|
boolean stateSale = false; // 默认停售
|
Long goodsId = taoBaoGoodsBrief.getAuctionId();
|
for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
|
Long auctionId = taoKeGoods.getAuctionId();
|
if (goodsId == auctionId || goodsId.equals(auctionId)) {
|
stateSale = true; // 在售
|
break;
|
}
|
}
|
|
if (!stateSale) {
|
continue;
|
}
|
}
|
|
BigDecimal couplePrice = TaoBaoUtil.getAfterUseCouplePrice(taoBaoGoodsBrief);
|
if (couplePrice.compareTo(new BigDecimal("9.9")) == 1) {
|
continue; // 券后价大于10
|
}
|
|
TaoBaoGoodsBriefExtra extra = TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief,
|
proportion.toString(), null);
|
// 将返利改为券后价
|
TaoBaoHongBaoInfo taoBaoHongBaoInfo = extra.getTaoBaoHongBaoInfo();
|
if (taoBaoHongBaoInfo != null) {
|
taoBaoHongBaoInfo.setHongbao(extra.getQuanPrice());
|
taoBaoHongBaoInfo.setRate("¥" + extra.getQuanPrice());
|
}
|
|
array.add(gson.toJson(extra));
|
}
|
|
long count = qualityGoodsService.countFreeGoods();
|
|
JSONObject data = new JSONObject();
|
if (page == 1) {
|
// 抽奖规则
|
String rules = configService.get("free_goods_rule");
|
data.put("ruleLink", rules);
|
}
|
|
data.put("count", count);
|
data.put("result_list", array);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("数据暂未提供"));
|
LogHelper.errorDetailInfo(e);
|
}
|
}
|
|
}
|