CommonController.java
7.23 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
package com.dili.titan.web.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baidu.ueditor.ActionEnter;
import com.dili.titan.common.utils.web.BaseController;
import com.dili.titan.domain.base.Result;
import com.dili.titan.rpc.ConfigRPC;
import com.dili.titan.rpc.ImageRPC;
import com.diligrp.website.web.interfaces.domain.output.PickUpPointResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* <B>Copyright</B> Copyright (c) 2014 www.diligrp.com All rights reserved. <br />
* 本软件源代码版权归地利集团,未经许可不得任意复制与传播.<br />
* <B>Company</B> 地利集团
* @createTime May 28, 2014 2:48:29 PM
* @author wujianjun
*/
@Controller
@RequestMapping("/common")
public class CommonController extends BaseController {
@Autowired
private ImageRPC imageRPC;
@Autowired
private ConfigRPC configRPC;
/**
* 上传图片
* @return
* @createTime May 28, 2014 2:49:11 PM
* @author wujianjun
*/
@RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
public ModelAndView uploadImage(@RequestParam MultipartFile image,
HttpServletResponse resp) {
Result result = Result.create();
String json = imageRPC.uploadProductImage(image);
result.addResult("json", json);
return toVMSkipLayout("common/uploadImgForUE", result.getAllResult());
}
/**
* 供应图片
* @return
* @createTime May 28, 2014 2:49:11 PM
* @author chenzhiwei
*/
@RequestMapping(value = "/supplyUploadImg",method = RequestMethod.POST,produces = "application/text;charset=UTF-8")
@ResponseBody
public String supplyUploadImg(@RequestParam MultipartFile image) {
String upload = imageRPC.uploadSupplyImage(image);
JSONObject jsonObject = JSONObject.parseObject(upload);
if(jsonObject.getBoolean("success")) {
upload = jsonObject.getString("message");
}
return upload;
}
/**
* 富文本编辑框上传图片
* @return
* @createTime May 28, 2014 2:49:11 PM
* @author wujianjun
*/
@RequestMapping(value = "/uploadImgForUE",method = RequestMethod.POST)
public ModelAndView uploadForUE(@RequestParam MultipartFile image,
HttpServletResponse resp) throws IOException{
Result result = Result.create();
String upload = imageRPC.uploadDescImage(image,true);
JSONObject json = JSONObject.parseObject(upload);
JSONObject returnjson = new JSONObject();
if (json.getBoolean("success")) {
returnjson.put("state", "SUCCESS");
returnjson.put("url", json.getString("message"));
returnjson.put("title", image.getName());
returnjson.put("original", image.getOriginalFilename());
} else {
returnjson.put("state", json.getString("message"));
}
result.addResult("json", returnjson.toJSONString());
return toVMSkipLayout("common/uploadImgForUE", result.getAllResult());
}
/**
* 富文本编辑框上传图片 无水印
*
* @return
* @createTime May 28, 2014 2:49:11 PM
* @author wujianjun
*/
@RequestMapping(value = "/uploadImgNoMark", method = RequestMethod.POST)
public ModelAndView uploadImgNoMark(@RequestParam MultipartFile image) {
String upload = imageRPC.uploadDescImage(image,false);
Result result = Result.create();
result.addResult("json", upload);
return toVMSkipLayout("common/uploadImgForUE", result.getAllResult());
}
/**
* 富文本编辑框上传图片 无水印
*
* @return
* @createTime May 28, 2014 2:49:11 PM
* @author wujianjun
*/
@RequestMapping(value = "/uploadCateIcon", method = RequestMethod.POST)
public ModelAndView uploadCateIcon(@RequestParam MultipartFile image) {
JSONObject returnjson = new JSONObject();
if(image.getSize()>100*1024){
returnjson.put("state", "上传图片不能大于100KB!");
}else {
String upload = imageRPC.uploadAuthImage(image);
JSONObject json = JSONObject.parseObject(upload);
if (json.getBoolean("success")) {
returnjson.put("url", json.getString("message"));
returnjson.put("state", "SUCCESS");
returnjson.put("title", "上传成功");
} else {
returnjson.put("state", json.getString("message"));
}
}
Result result = Result.create();
result.addResult("json", returnjson.toJSONString());
return toVMSkipLayout("common/uploadImgForUE", result.getAllResult());
}
/**
* 搜索供应商
* @param keyword
* @return
*/
@RequestMapping(value = "/searchSupplier", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
public @ResponseBody
String searchAttrbute(String keyword, Model view){
return "";
}
/**
* this method is 富文本编辑框上传图片
*
* @param request
* @param response
* @createTime 2015年1月14日 上午11:21:30
* @author yangjianjun
*/
@RequestMapping(value = "/uploadUmeditor")
public void uploadUmeditor(HttpServletRequest request,
HttpServletResponse response) {
try {
request.setCharacterEncoding("utf-8");
response.setHeader("Content-Type", "text/html");
String rootPath = request.getRealPath("/assets/umeditor");
response.getWriter()
.write(new ActionEnter(request, rootPath).exec());
} catch (IOException e) {
e.printStackTrace();
}
}
@RequestMapping(value="/uploadCategoryIcon",method=RequestMethod.POST)
@ResponseBody
public String uploadAuthIcon(@RequestParam MultipartFile image) throws Exception{
Map<String,Object> result = new HashMap<String,Object>();
String authIcon = imageRPC.uploadCategoryImage(image);
JSONObject jsonObject = JSONObject.parseObject(authIcon);
result.put("success", jsonObject.getBoolean("success"));
result.put("message", jsonObject.getString("message"));
return JSON.toJSONString(result);
}
/**
* 搜索市场
* @param keyword
* @return
*/
@RequestMapping(value = "/searchSc", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json;charset=UTF-8")
public @ResponseBody
String searchSc(String keyword, Model view){
List<PickUpPointResp> list = configRPC.getPickUpInfoByName(keyword);
return JSON.toJSONString(list);
}
}