admin
2019-07-18 8579b9ea8205a2bcea72d2c9a843fdad1ed2e665
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
package com.yeshi.fanli.controller.client.v1;
 
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 com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.fanli.dto.common.CommonContentNav;
import com.yeshi.fanli.dto.common.CommonContentResult;
import com.yeshi.fanli.dto.common.CommonContentTypeEnum;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief;
import com.yeshi.fanli.service.inter.goods.CommonTemplateContentService;
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
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.taobao.TaoBaoUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
/**
 * 通用模板
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("api/v1/commoncontent")
public class CommonContentController {
 
    @Resource
    private SwiperPictureService swiperPictureService;
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource
    private CommonTemplateContentService commonTemplateContentService;
 
    /**
     * 通用模板导航
     * 
     * @param acceptData
     * @param key
     * @param out
     */
    @RequestMapping(value = "getNavList", method = RequestMethod.POST)
    public void getNavList(AcceptData acceptData, String key, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(key)) {
            out.print(JsonUtil.loadFalseResult(1, "请传入Key"));
            return;
        }
        List<CommonContentNav> list = commonTemplateContentService.getNavList(CommonContentTypeEnum.valueOf(key));
        out.print(JsonUtil.loadTrueResult(new Gson().toJson(list)));
    }
 
    /**
     * 获取内容
     * 
     * @param acceptData
     * @param key
     * @param page-页码
     * @param navId-导航ID
     * @param out
     */
    @RequestMapping(value = "getNavGoodsList", method = RequestMethod.POST)
    public void getNavContent(AcceptData acceptData, String key, Integer page, String cid, PrintWriter out) {
        if (StringUtil.isNullOrEmpty(key)) {
            out.print(JsonUtil.loadFalseResult(1, "请传入Key"));
            return;
        }
 
        if (page == null || page < 1) {
            out.print(JsonUtil.loadFalseResult(1, "请传入正确的page"));
            return;
        }
 
        CommonContentResult result = commonTemplateContentService.getContentList(CommonContentTypeEnum.valueOf(key),
                cid, page, 10);
 
        // 保留暂时不开启,待后续开启
        List<SwiperPicture> bannerList = new ArrayList<>();
 
        JSONObject root = new JSONObject();
        if (page == 1)
            root.put("bannerList", new Gson().toJson(bannerList));
 
        JSONArray array = new JSONArray();
        Gson gson = JsonUtil.getConvertBigDecimalToStringSubZeroBuilder(new GsonBuilder()).create();
        BigDecimal pro = hongBaoManageService.getFanLiRate();
        List<TaoBaoGoodsBrief> goodsList = result.getGoodsList();
        for (TaoBaoGoodsBrief taoBaoGoodsBrief : goodsList) {
            array.add(gson.toJson(TaoBaoUtil.getTaoBaoGoodsBriefExtra(taoBaoGoodsBrief, pro.toString(), "")));
        }
        root.put("goodsList", array);
        root.put("goodsCount", result.getCount());
        out.print(JsonUtil.loadTrueResult(root));
    }
 
}