|
@ -2,12 +2,26 @@ package com.yihu.wlyy.controller.manager.healthbank;
|
|
|
|
|
|
import com.yihu.wlyy.controller.BaseController;
|
|
|
import com.yihu.wlyy.service.manager.healthbank.ActivityService;
|
|
|
import org.json.JSONObject;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.util.FileCopyUtils;
|
|
|
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.multipart.MultipartHttpServletRequest;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.Map;
|
|
|
import java.util.Random;
|
|
|
|
|
|
/**
|
|
|
* Created by humingfen on 2018/6/19.
|
|
@ -16,6 +30,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
@Controller
|
|
|
@RequestMapping("admin/activity")
|
|
|
public class ActivityController extends BaseController {
|
|
|
private Logger logger = LoggerFactory.getLogger(ActivityController.class);
|
|
|
|
|
|
@Autowired
|
|
|
private ActivityService activityService;
|
|
@ -89,6 +104,39 @@ public class ActivityController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "upload", produces = "application/json;charset=UTF-8")
|
|
|
@ResponseBody
|
|
|
public String upload(@RequestParam(value = "file") MultipartFile file, HttpServletRequest request) throws IOException {
|
|
|
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
|
|
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
|
|
// 创建文件夹
|
|
|
String rootpath = request.getSession().getServletContext().getRealPath("/");
|
|
|
File folder = new File(rootpath + "/image/");
|
|
|
if (!folder.exists()) {
|
|
|
folder.mkdirs();
|
|
|
}
|
|
|
String fileName = null;
|
|
|
String newFileName = null;
|
|
|
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
|
|
// 上传文件
|
|
|
MultipartFile mf = entity.getValue();
|
|
|
fileName = mf.getOriginalFilename();
|
|
|
String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
|
// 重命名文件
|
|
|
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000) + "." + fileExt;
|
|
|
File uploadFile = new File(rootpath + "/image/" + newFileName);
|
|
|
// 拷贝文件流到指定文件路径
|
|
|
FileCopyUtils.copy(mf.getBytes(), uploadFile);
|
|
|
}
|
|
|
JSONObject json = new JSONObject();
|
|
|
json.put("status", 200);
|
|
|
json.put("msg", "上传成功");
|
|
|
// 图片标识对象的HTTP链接
|
|
|
json.put("urls", String.join(",", "/image/" + newFileName));
|
|
|
return json.toString();
|
|
|
}
|
|
|
|
|
|
/*@RequestMapping(value = "delete")
|
|
|
@ResponseBody
|
|
|
public String delete(String id) {
|