admin
2021-08-13 cdc3690a0354e01b44852f4c9da3b7204128d2eb
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package com.yeshi.buwan.controller.parser;
 
import java.io.PrintWriter;
import java.util.List;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import com.yeshi.buwan.util.annotation.RequireUid;
import com.yeshi.buwan.vo.AcceptData;
import org.springframework.stereotype.Controller;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.yeshi.buwan.domain.user.LoginUser;
import com.yeshi.buwan.domain.UserInfo;
import com.yeshi.buwan.domain.shop.ShopGoodsItem;
import com.yeshi.buwan.domain.shop.ShopItemCollect;
import com.yeshi.buwan.domain.shop.ShopItemComment;
import com.yeshi.buwan.service.imp.shop.ShopService;
import com.yeshi.buwan.util.JsonUtil;
import com.yeshi.buwan.util.StringUtil;
 
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
@Controller
public class ShopParser {
 
    @Resource
    private ShopService shopService;
 
    @RequireUid
    public void getGoodsItemList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String page = request.getParameter("Page");
 
        if (StringUtil.isNullOrEmpty(page)) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        int pageIndex = Integer.parseInt(page);
        pageIndex = pageIndex < 1 ? 1 : pageIndex;
        List<ShopGoodsItem> list = shopService.getGoodsList(acceptData.getUid(), pageIndex);
 
        JSONObject object = new JSONObject();
        object.put("count", 1000 + "");
        JSONArray array = new JSONArray();
        for (int i = 0; i < list.size(); i++)
            array.add(StringUtil.outPutResultJson(list.get(i)));
        object.put("data", array);
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
    @RequireUid
    public void getGoodsItemDetail(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String id = request.getParameter("Id");
 
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseJson("请上传Id"));
            return;
        }
 
        ShopGoodsItem item = shopService.getGoodsDetail(Long.parseLong(id));
        item.setCommentcount(item.getCommentcount() + 1);
        List<ShopItemComment> commentList = shopService.shopItemCommentList(item.getId(), 1);
        ShopItemComment sc = new ShopItemComment();
        sc.setUser(item.getLoginUser());
        sc.setContent(item.getTitle());
        sc.setCreatetime(item.getCreatetime() + "");
        commentList.add(0, sc);
 
        boolean isC = shopService.isCollect(item.getId(), acceptData.getUid());
 
        long ccount = shopService.shopItemCommentCount(item.getId());
        Gson gson = new GsonBuilder().create();
        JSONObject comment = new JSONObject();
        comment.put("count", ccount + 1);
        comment.put("data", StringUtil.outPutResultJson(commentList));
        JSONObject object = new JSONObject();
        object.put("comment", comment);
        object.put("Item", StringUtil.outPutResultJson(item));
        object.put("collect", isC);
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
    public void getCommentList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
 
        String page = request.getParameter("Page");
        String id = request.getParameter("Id");
 
        if (StringUtil.isNullOrEmpty(page)) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        int pageIndex = Integer.parseInt(page);
        pageIndex = pageIndex < 1 ? 1 : pageIndex;
 
        ShopGoodsItem item = shopService.getGoodsDetail(Long.parseLong(id));
        ShopItemComment sc = new ShopItemComment();
        sc.setUser(item.getLoginUser());
        sc.setContent(item.getTitle());
        sc.setCreatetime(item.getCreatetime() + "");
 
        List<ShopItemComment> list = shopService.shopItemCommentList(Long.parseLong(id), pageIndex);
        if (pageIndex == 1)
            list.add(0, sc);
        long count = shopService.shopItemCommentCount(Long.parseLong(id));
 
        Gson gson = new GsonBuilder().create();
        JSONObject object = new JSONObject();
        object.put("count", count + 1);
        object.put("data", StringUtil.outPutResultJson(list));
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
    public void addComment(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String loginUid = request.getParameter("LoginUid");
        String id = request.getParameter("Id");
        String content = request.getParameter("Content");
 
 
        if (StringUtil.isNullOrEmpty(loginUid)) {
            out.print(JsonUtil.loadFalseJson("请上传LoginUid"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseJson("请上传Id"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(content)) {
            out.print(JsonUtil.loadFalseJson("请上传Content"));
            return;
        }
 
        if (StringUtil.match("[\\d]{6,}", content)) {
            out.print(JsonUtil.loadFalseJson("信息格式不正确"));
            return;
        }
 
        ShopItemComment sc = new ShopItemComment();
        sc.setContent(content);
        sc.setCreatetime(System.currentTimeMillis() + "");
        sc.setItemid(Long.parseLong(id));
        sc.setShow(true);
        sc.setUser(new LoginUser(loginUid));
        shopService.addshopItemComment(sc);
        out.print(JsonUtil.loadTrueJson(""));
    }
 
    @RequireUid
    public void addCollect(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String id = request.getParameter("Id");
        String loginUid = request.getParameter("LoginUid");
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseJson("请上传Id"));
            return;
        }
 
        ShopItemCollect sc = new ShopItemCollect();
        sc.setCreatetime(System.currentTimeMillis() + "");
        sc.setItemid(Long.parseLong(id));
        sc.setUser(new UserInfo(acceptData.getUid()));
        if (!StringUtil.isNullOrEmpty(loginUid)) {
            sc.setLoginUser(new LoginUser(loginUid));
        }
        shopService.addshopItemCollect(sc);
        out.print(JsonUtil.loadTrueJson(""));
    }
 
    @RequireUid
    public void cancelCollect(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String id = request.getParameter("Id");
        String loginUid = request.getParameter("LoginUid");
 
        if (StringUtil.isNullOrEmpty(id)) {
            out.print(JsonUtil.loadFalseJson("请上传Id"));
            return;
        }
 
        String[] ids = id.split(",");
        for (String idStr : ids) {
            ShopItemCollect sc = new ShopItemCollect();
            sc.setCreatetime(System.currentTimeMillis() + "");
            sc.setItemid(Long.parseLong(idStr));
            sc.setUser(new UserInfo(acceptData.getUid()));
            if (!StringUtil.isNullOrEmpty(loginUid)) {
                sc.setLoginUser(new LoginUser(loginUid));
            }
            shopService.cancelshopItemCollect(sc);
        }
        out.print(JsonUtil.loadTrueJson(""));
    }
 
    // 获取收藏商品列表
    @RequireUid
    public void getCollectList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) {
        String page = request.getParameter("Page");
        String loginUid = request.getParameter("LoginUid");
 
 
        if (StringUtil.isNullOrEmpty(page)) {
            out.print(JsonUtil.loadFalseJson("请上传Page"));
            return;
        }
 
        int pageIndex = Integer.parseInt(page);
        pageIndex = pageIndex < 1 ? 1 : pageIndex;
        List<ShopItemCollect> list = shopService.collectList(acceptData.getUid(), loginUid, pageIndex);
        long count = shopService.collectCount(acceptData.getUid(), pageIndex);
        JSONObject object = new JSONObject();
        object.put("count", count);
        object.put("data", StringUtil.outPutResultJson(list));
        out.print(JsonUtil.loadTrueJson(object.toString()));
    }
 
}