ChannelController.java
10 KB
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package com.sincere.wechatbusiness.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.sincere.wechatbusiness.dto.BaseDto;
import com.sincere.wechatbusiness.dto.ChannelDto;
import com.sincere.wechatbusiness.model.*;
import com.sincere.wechatbusiness.service.*;
import com.sincere.wechatbusiness.utils.Page;
import io.swagger.annotations.ApiOperation;
import org.bouncycastle.jcajce.provider.symmetric.util.BaseWrapCipher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
@RestController
public class ChannelController {
@Autowired
ChannelService channelService;
@Autowired
ChannelProductService channelProductService;
@Autowired
BannerService bannerService;
@Autowired
AttentionService attentionService;
@Autowired
CatalogService catalogService;
@Autowired
CatalogContentService catalogContentService;
@RequestMapping(value = "GetChannelList",method = RequestMethod.POST)
@ApiOperation(value = "获取渠道商列表")
public BaseDto<Page<Channel>> GetChannelList(@RequestBody ChannelDto channelDto){
BaseDto<Page<Channel>> result=new BaseDto<>();
Channel channel=new Channel();
channel.setName(channelDto.getName());
channel.setState(1);
result.setData(channelService.getList(channel,channelDto.getPage(),channelDto.getPageSize()));
return result;
}
@RequestMapping(value = "GetPackageList",method = RequestMethod.POST)
@ApiOperation(value = "获取代理商品列表")
public BaseDto<List<DiscountPackage>> GetPackageList(){
BaseDto<List<DiscountPackage>> result=new BaseDto<>();
String r=Get("https://mytest.myjxt.com:51314/University/getPackageList","");
JSONObject jsonObject= JSONObject.parseObject(r);
String data = jsonObject.getString("data");
List<DiscountPackage> list=JSON.parseObject(data,new TypeReference<List<DiscountPackage>>(){});
result.setData(list);
return result;
}
@RequestMapping(value = "AddChannel",method = RequestMethod.POST)
@ApiOperation(value = "新增渠道商")
public BaseDto AddChannel(@RequestBody Channel channel){
channelService.insert(channel);
if(channel.getChannelProductList()!=null&&channel.getChannelProductList().size()>0) {
for(ChannelProduct channelProduct:channel.getChannelProductList()){
channelProduct.setChannelId(channel.getId());
channelProductService.insert(channelProduct);
}
}
return new BaseDto();
}
@RequestMapping(value = "GetChannelDetail",method = RequestMethod.GET)
@ApiOperation(value = "获取渠道商详情")
public BaseDto<Channel> GetChannelDetail(int id){
BaseDto<Channel> result=new BaseDto<>();
Channel channel=channelService.getDetail(id);
channel.setChannelProductList(channelProductService.getList(id));
result.setData(channel);
return result;
}
@RequestMapping(value = "UpdateChannel",method = RequestMethod.POST)
@ApiOperation(value = "编辑渠道商")
public BaseDto UpdateChannel(@RequestBody Channel channel){
channelService.update(channel);
if(channel.getChannelProductList()!=null&&channel.getChannelProductList().size()>0){
channelProductService.deleteChannelProduct(channel.getId());
for (ChannelProduct channelProduct:channel.getChannelProductList()){
channelProduct.setChannelId(channel.getId());
channelProductService.insert(channelProduct);
}
}
return new BaseDto();
}
@RequestMapping(value = "DeleteChannel",method = RequestMethod.GET)
@ApiOperation(value = "删除渠道商")
public BaseDto DeleteChannel(int id){
channelService.deleteChannel(id);
return new BaseDto();
}
@RequestMapping(value = "UpdateChannelProduct",method = RequestMethod.POST)
@ApiOperation(value = "编辑代理商品")
public BaseDto UpdateChannelProduct(@RequestBody ChannelProduct channelProduct){
channelProductService.update(channelProduct);
return new BaseDto();
}
@RequestMapping(value = "GetBannerList",method = RequestMethod.GET)
@ApiOperation(value = "获取Banner轮播图列表")
public BaseDto<List<Banner>> GetBannerList(int id){
BaseDto<List<Banner>> result=new BaseDto<>();
result.setData(bannerService.getList(id));
return result;
}
@RequestMapping(value = "AddBanner",method = RequestMethod.POST)
@ApiOperation(value = "添加Banner轮播图")
public BaseDto AddBanner(@RequestBody Banner banner){
bannerService.insert(banner);
return new BaseDto();
}
@RequestMapping(value = "UpdateBanner",method = RequestMethod.POST)
@ApiOperation(value = "编辑Banner轮播图")
public BaseDto UpdateBanner(@RequestBody Banner banner){
bannerService.update(banner);
return new BaseDto();
}
@RequestMapping(value = "DeleteBanner",method = RequestMethod.GET)
@ApiOperation(value = "删除Banner轮播图")
public BaseDto DeleteBanner(int id){
bannerService.deleteBanner(id);
return new BaseDto();
}
@RequestMapping(value = "GetAttention",method = RequestMethod.GET)
@ApiOperation(value = "获取关注配置")
public BaseDto<Attention> GetAttention(int id){
BaseDto<Attention> result=new BaseDto<>();
result.setData(attentionService.getDetail(id));
return result;
}
@RequestMapping(value = "AddAttention",method = RequestMethod.POST)
@ApiOperation(value = "添加关注配置")
public BaseDto AddAttention(@RequestBody Attention attention){
attentionService.insert(attention);
return new BaseDto();
}
@RequestMapping(value = "UpdateAttention",method = RequestMethod.POST)
@ApiOperation(value = "编辑关注配置")
public BaseDto UpdateAttention(@RequestBody Attention attention){
attentionService.update(attention);
return new BaseDto();
}
@RequestMapping(value = "GetCatalog",method = RequestMethod.GET)
@ApiOperation(value = "获取栏目")
public BaseDto<Catalog> GetCatalog(int channelId,int sort){
BaseDto<Catalog> result=new BaseDto<>();
Catalog catalog=new Catalog();
catalog.setChannelId(channelId);
catalog.setSort(sort);
catalog=catalogService.getDetail(catalog);
catalog.setCatalogContentList(catalogContentService.getList(catalog.getId()));
result.setData(catalog);
return result;
}
@RequestMapping(value = "AddCatalog",method = RequestMethod.POST)
@ApiOperation(value = "新增栏目")
public BaseDto AddCatalog(@RequestBody Catalog catalog){
catalogService.insert(catalog);
return new BaseDto();
}
@RequestMapping(value = "UpdateCatalog",method = RequestMethod.POST)
@ApiOperation(value = "编辑栏目")
public BaseDto UpdateCatalog(@RequestBody Catalog catalog){
catalogService.update(catalog);
return new BaseDto();
}
@RequestMapping(value = "AddCatalogContent",method = RequestMethod.POST)
@ApiOperation(value = "新增栏目内容")
public BaseDto AddCatalogContent(@RequestBody CatalogContent catalogContent){
catalogContentService.insert(catalogContent);
return new BaseDto();
}
@RequestMapping(value = "UpdateCatalogContent",method = RequestMethod.POST)
@ApiOperation(value = "编辑栏目内容")
public BaseDto UpdateCatalogContent(@RequestBody CatalogContent catalogContent){
catalogContentService.update(catalogContent);
return new BaseDto();
}
@RequestMapping(value = "DeleteCatalogContent",method = RequestMethod.GET)
@ApiOperation(value = "删除栏目内容")
public BaseDto DeleteCatalogContent(int id){
catalogContentService.deleteCatalogContent(id);
return new BaseDto();
}
public String Get(String url, String param) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
}