| | |
| | | package com.yeshi.fanli.controller.client.v2;
|
| | |
|
| | | import java.io.PrintWriter;
|
| | | import java.lang.reflect.Type;
|
| | | import java.math.BigDecimal;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Date;
|
| | | 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 com.google.gson.Gson;
|
| | | import com.google.gson.GsonBuilder;
|
| | | import com.google.gson.JsonElement;
|
| | | import com.google.gson.JsonPrimitive;
|
| | | import com.google.gson.JsonSerializationContext;
|
| | | import com.google.gson.JsonSerializer;
|
| | | import com.yeshi.fanli.entity.accept.AcceptData;
|
| | | import com.yeshi.fanli.entity.goods.CollectionGoodsV2;
|
| | | import com.yeshi.fanli.entity.goods.CommonGoods;
|
| | | import com.yeshi.fanli.entity.goods.ScanHistoryV2;
|
| | | import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
|
| | | import com.yeshi.fanli.exception.goods.CollectionGoodsException;
|
| | | import com.yeshi.fanli.exception.taobao.TaoKeApiException;
|
| | | import com.yeshi.fanli.exception.taobao.TaobaoGoodsDownException;
|
| | | import com.yeshi.fanli.service.inter.config.BusinessSystemService;
|
| | | import com.yeshi.fanli.service.inter.goods.CollectionGoodsV2Service;
|
| | | import com.yeshi.fanli.service.inter.goods.ScanHistoryV2Service;
|
| | | import com.yeshi.fanli.service.inter.hongbao.HongBaoManageService;
|
| | | 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 net.sf.json.JSONArray;
|
| | | import net.sf.json.JSONObject;
|
| | |
|
| | | /**
|
| | | * 用户相关商品
|
| | | * |
| | | * @author Administrator
|
| | | *
|
| | | */
|
| | | @Controller
|
| | | @RequestMapping("api/v2/consumer")
|
| | | public class ConsumerControllerV2 {
|
| | |
|
| | | @Resource
|
| | | private BusinessSystemService businessSystemService;
|
| | | |
| | | @Resource
|
| | | private HongBaoManageService hongBaoManageService;
|
| | |
|
| | | @Resource
|
| | | private CollectionGoodsV2Service collectionGoodsV2Service;
|
| | |
|
| | | @Resource
|
| | | private ScanHistoryV2Service scanHistoryV2Service;
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 删除收藏
|
| | | * @param acceptData
|
| | | * @param ids
|
| | | * @param type
|
| | | * @param uid
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping("deleteCollectionGoods")
|
| | | public void deleteCollectionGoods(AcceptData acceptData, Long uid, String ids, Integer type, PrintWriter out) {
|
| | | if (uid == null || uid <= 0) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | | |
| | | if (type != null && type == 1) { // 删除全部
|
| | | try {
|
| | | collectionGoodsV2Service.cancelCollectionByUid(uid);
|
| | | } catch (CollectionGoodsException e) {
|
| | | out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMessage()));
|
| | | return;
|
| | | }
|
| | | } else { // 删除部分
|
| | | if (!StringUtil.isNullOrEmpty(ids)) {
|
| | | Arrays.asList(ids.split(",")).parallelStream().forEach(idStr -> {
|
| | | try {
|
| | | collectionGoodsV2Service.deteleBYByUidAndCommonId(uid, Long.parseLong(idStr));
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | | out.print(JsonUtil.loadTrueResult("删除成功"));
|
| | | }
|
| | |
|
| | | |
| | | |
| | | /**
|
| | | * 收藏列表
|
| | | * |
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param page
|
| | | * @param goodsType
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping("collectionGoodsList")
|
| | | public void collectionGoodsList(AcceptData acceptData, Long uid, Integer page, Integer goodsType, PrintWriter out) {
|
| | | if (uid == null) {
|
| | | out.print(JsonUtil.loadFalseResult("用户未登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (page < 1) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "page不小于1"));
|
| | | return;
|
| | | }
|
| | |
|
| | | List<CollectionGoodsV2> collectionGoodsList = collectionGoodsV2Service.getCollectionGoodsList(uid, page,
|
| | | Constant.PAGE_SIZE, goodsType);
|
| | |
|
| | | long count = collectionGoodsV2Service.getCollectionGoodsCount(uid, goodsType);
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | List<GoodsDetailVO> list = new ArrayList<GoodsDetailVO>();
|
| | |
|
| | | if (collectionGoodsList != null && collectionGoodsList.size() > 0) {
|
| | | List<Long> listGid = new ArrayList<Long>();
|
| | | for (CollectionGoodsV2 collectionGoodsV2 : collectionGoodsList) {
|
| | | CommonGoods commonGoods = collectionGoodsV2.getCommonGoods();
|
| | | if (commonGoods == null || commonGoods.getGoodsType() != Constant.SOURCE_TYPE_TAOBAO) {
|
| | | continue;
|
| | | }
|
| | | listGid.add(commonGoods.getGoodsId());
|
| | | }
|
| | |
|
| | | // API网络接口验证是否在售
|
| | | List<TaoBaoGoodsBrief> listTaoKeGoods = null;
|
| | | if (listGid.size() > 0) {
|
| | | try {
|
| | | listTaoKeGoods = TaoKeApiUtil.getBatchGoodsInfo(listGid);
|
| | | } catch (TaoKeApiException e) {
|
| | | e.printStackTrace();
|
| | | } catch (TaobaoGoodsDownException e) {
|
| | | e.printStackTrace();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
|
| | | BigDecimal shareRate = hongBaoManageService.getShareRate();
|
| | |
|
| | | for (CollectionGoodsV2 collectionGoodsV2 : collectionGoodsList) {
|
| | | CommonGoods commonGoods = collectionGoodsV2.getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | if (listTaoKeGoods != null && listTaoKeGoods.size() > 0
|
| | | && commonGoods.getGoodsType() == Constant.SOURCE_TYPE_TAOBAO) {
|
| | | int state = 1; // 默认停售
|
| | | Long goodsId = commonGoods.getGoodsId();
|
| | | for (TaoBaoGoodsBrief taoKeGoods : listTaoKeGoods) {
|
| | | Long auctionId = taoKeGoods.getAuctionId();
|
| | | if (goodsId == auctionId || goodsId.equals(auctionId)) {
|
| | | state = 0; // 在售
|
| | | break;
|
| | | }
|
| | | }
|
| | | commonGoods.setState(state);
|
| | | }
|
| | |
|
| | | GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate,
|
| | | shareRate);
|
| | | detailVO.setId(commonGoods.getId());
|
| | | detailVO.setCreatetime(collectionGoodsV2.getCreateTime());
|
| | | list.add(detailVO);
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | GsonBuilder builder = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
| | | @Override
|
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
|
| | | if (value == null) {
|
| | | return new JsonPrimitive("");
|
| | | } else {
|
| | | return new JsonPrimitive(value.getTime() + "");
|
| | | }
|
| | | }
|
| | | });
|
| | |
|
| | | Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(builder).excludeFieldsWithoutExposeAnnotation()
|
| | | .create();
|
| | | data.put("list", gson.toJson(list));
|
| | | data.put("count", count);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * 删除足迹
|
| | | * @param acceptData
|
| | | * @param type
|
| | | * @param uid
|
| | | * @param ids
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "deleteScanhistory", method = RequestMethod.POST)
|
| | | public void deleteScanHistory(AcceptData acceptData, String type, Long uid, String ids, PrintWriter out) {
|
| | | if ("1".equals(type)) {
|
| | | // 全部删除
|
| | | scanHistoryV2Service.deleteByDeviceOrUid(uid, acceptData.getDevice());
|
| | | } else {
|
| | | // 删除部分
|
| | | if (StringUtil.isNullOrEmpty(ids)) {
|
| | | out.print(JsonUtil.loadFalseResult("ids不能为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | String[] idStr = ids.split(",");
|
| | | for (String id : idStr) {
|
| | | scanHistoryV2Service.deleteByAuctionIdAndDeviceOrUid(uid, acceptData.getDevice(), Long.parseLong(id));
|
| | | }
|
| | | }
|
| | | out.print(JsonUtil.loadTrueResult(""));
|
| | | }
|
| | | |
| | | |
| | | /**
|
| | | * 获取浏览记录
|
| | | * @param acceptData
|
| | | * @param uid
|
| | | * @param page
|
| | | * @param goodsType
|
| | | * @param out
|
| | | */
|
| | | @RequestMapping(value = "getScanHistory", method = RequestMethod.POST)
|
| | | public void getScanHistory(AcceptData acceptData, Long uid, int page, Integer goodsType, PrintWriter out) {
|
| | | if (page < 1) {
|
| | | out.print(JsonUtil.loadFalseResult(1, "page不小于1"));
|
| | | return;
|
| | | }
|
| | |
|
| | | List<ScanHistoryV2> list = scanHistoryV2Service.getScanHistoryByDeviceOrUid(uid, acceptData.getDevice(), page,
|
| | | 20, goodsType);
|
| | |
|
| | | GsonBuilder gsonBuilder = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder());
|
| | | gsonBuilder.excludeFieldsWithoutExposeAnnotation();
|
| | | gsonBuilder.registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
| | | @Override
|
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
|
| | | if (value == null) {
|
| | | return new JsonPrimitive("");
|
| | | } else {
|
| | | return new JsonPrimitive(value.getTime() + "");
|
| | | }
|
| | | }
|
| | | });
|
| | | |
| | | long count = scanHistoryV2Service.getCountByDeviceOrUid(uid, acceptData.getDevice(), goodsType);
|
| | |
|
| | | JSONArray array = new JSONArray();
|
| | | if (list != null && list.size() > 0) {
|
| | | Gson gson = gsonBuilder.create();
|
| | | BigDecimal fanLiRate = hongBaoManageService.getFanLiRate();
|
| | | BigDecimal shareRate = hongBaoManageService.getShareRate();
|
| | | for (ScanHistoryV2 sh : list) {
|
| | | CommonGoods commonGoods = sh.getCommonGoods();
|
| | | if (commonGoods == null) {
|
| | | continue;
|
| | | }
|
| | |
|
| | | GoodsDetailVO detailVO = GoodsDetailVOFactory.convertCommonGoods(commonGoods, null, fanLiRate,
|
| | | shareRate);
|
| | | |
| | | detailVO.setId(commonGoods.getId());
|
| | | detailVO.setCreatetime(sh.getCreateTime());
|
| | | array.add(gson.toJson(detailVO));
|
| | | }
|
| | | }
|
| | |
|
| | | JSONObject data = new JSONObject();
|
| | | data.put("count", count);
|
| | | data.put("data", array);
|
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | return;
|
| | | }
|
| | | |
| | | |
| | | |
| | | }
|