admin
2021-05-19 a1be6075c6b1365a7abc66bf559d6058039248ab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package com.yeshi.fanli.controller.client.v2;
 
import java.io.PrintWriter;
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.yeshi.utils.JsonUtil;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dto.GoodsMoneyConfigParamsDTO;
import com.yeshi.fanli.dto.suning.SuningGoodsInfo;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.homemodule.Special;
import com.yeshi.fanli.service.inter.goods.suning.SuningGoodsService;
import com.yeshi.fanli.service.inter.homemodule.SpecialService;
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.factory.goods.GoodsDetailVOFactory;
import com.yeshi.fanli.vo.goods.GoodsDetailVO;
import com.yeshi.fanli.vo.homemodule.BannerVO;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
/**
 * 热销榜
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("api/v2/suning")
public class SuningControllerV2 {
 
    @Resource
    private SuningGoodsService suningGoodsService;
 
    @Resource
    private SwiperPictureService swiperPictureService;
 
    @Resource
    private SpecialService specialService;
 
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
 
    /**
     * 京东专题分类
     * 
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getClass")
    public void getJDClass(AcceptData acceptData, PrintWriter out) {
        JSONObject root = new JSONObject();
        root.put("list", suningGoodsService.getSpecialClass());
        root.put("suningLink", "https://www.suning.com/");
        out.print(JsonUtil.loadTrueResult(root));
    }
 
    /**
     * 京东专题 + 商品列表
     * 
     * @param acceptData
     * @param out
     */
    @RequestMapping(value = "getGoodsInfo")
    public void getGoodsInfo(AcceptData acceptData, Long cid, Integer page, PrintWriter out) {
        JSONObject root = new JSONObject();
        if (cid == 1 && page == 1) {
            List<BannerVO> topPicList = swiperPictureService.getByBannerCardAndVersion("suning_banner_index",
                    acceptData.getPlatform(), Integer.parseInt(acceptData.getVersion()),acceptData.getSystem());
            if (topPicList == null) {
                topPicList = new ArrayList<BannerVO>();
            }
            root.put("listPic", JsonUtil.getApiCommonGson().toJson(topPicList));
 
            int platformCode = Constant.getPlatformCode(acceptData.getPlatform());
 
            List<Special> listSpecial = specialService.listByPlaceKey("suning_special_index", platformCode,
                    Integer.parseInt(acceptData.getVersion()),acceptData.getSystem());
            if (listSpecial == null) {
                listSpecial = new ArrayList<Special>();
            }
            root.put("listSpe", JsonUtil.getApiCommonGson().toJson(listSpecial));
        }
 
        List<SuningGoodsInfo> goodsList = suningGoodsService.specialSearch(page, cid);
 
        try {
            JSONArray array = new JSONArray();
            if (goodsList != null && goodsList.size() > 0) {
                GoodsMoneyConfigParamsDTO paramsDTO = orderHongBaoMoneyComputeService.getShowComputeRate(acceptData.getPlatform(),
                        acceptData.getVersion(),acceptData.getSystem());
 
                Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder())
                        .excludeFieldsWithoutExposeAnnotation().setDateFormat("yyyy-MM-dd").create();
                for (SuningGoodsInfo goods : goodsList) {
                    GoodsDetailVO goodsDetailVO = GoodsDetailVOFactory.convertSuningGoods(goods, paramsDTO);
                    array.add(gson.toJson(goodsDetailVO));
                }
            }
 
            root.put("list", array);
            root.put("count", 1000);
            out.print(JsonUtil.loadTrueResult(root));
        } catch (Exception e) {
            e.printStackTrace();
            out.print(JsonUtil.loadFalseResult("获取出错"));
        }
    }
 
}