Commit 378cdabe by 吴学德

添加上传图片功能

parent 50d37e64
...@@ -11,8 +11,8 @@ import java.util.Map; ...@@ -11,8 +11,8 @@ import java.util.Map;
*/ */
public enum FilePath { public enum FilePath {
// //
BACKGROUNDIMG("套餐背景图片基础路径","BackgroundImg"), BACKGROUNDIMG("套餐背景图片基础路径","enclosure"),
IDCARD("身份证明","packageNewClothes/images/idCard/"); IDCARD("身份证明","enclosure/images/idCard/");
FilePath(String id, String value) { FilePath(String id, String value) {
this.id = id; this.id = id;
this.value = value; this.value = value;
......
package com.winsun.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sun.org.apache.regexp.internal.RE;
import com.winsun.bean.Package;
import com.winsun.constant.FilePath;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.HttpRequest;
import org.springframework.http.MediaType;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Map;
/**
* @Author xuede
* @Date 2020/3/6 16:44
* @Version 1.0
*/
@Slf4j
@RestController
public class ImgController {
//menuname = "图片路径" 只支持jpeg 和 png
@RequestMapping( value = "/images/**",produces ={MediaType.IMAGE_JPEG_VALUE,MediaType.IMAGE_PNG_VALUE} )
public byte[] getbackground(HttpServletRequest request) {
byte[] bytes={};
request.getServletPath();
String imgurl= FilePath.BACKGROUNDIMG.getValue()+"/"+request.getServletPath();
imgurl = imgurl.replace("//", "/");
File file = new File(imgurl);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bytes = new byte[0];
try {
bytes = new byte[inputStream.available()];
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.read(bytes, 0, inputStream.available());
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
}
...@@ -224,75 +224,5 @@ public class PackageController extends BaseController { ...@@ -224,75 +224,5 @@ public class PackageController extends BaseController {
} }
//menuname = "展示背景图"
@RequestMapping( value = "getbackground/{id}",produces = MediaType.IMAGE_JPEG_VALUE)
public byte[] getbackground(@PathVariable(value = "id") String id) {
byte[] bytes={};
if (!StringUtils.isBlank(id)){
EntityWrapper<Package> packagewrapper = new EntityWrapper<>();
packagewrapper.eq("id", id);
packagewrapper.setSqlSelect("adv_img as imgurl");
List<Map<String, Object>> selectMaps = packageMapper.selectMaps(packagewrapper);
if (!CollectionUtils.isEmpty(selectMaps)){
String imgurl = selectMaps.get(0).get("imgurl").toString();
imgurl=FilePath.BACKGROUNDIMG.getValue()+"/"+imgurl;
File file = new File(imgurl);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bytes = new byte[0];
try {
bytes = new byte[inputStream.available()];
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.read(bytes, 0, inputStream.available());
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
}
return bytes;
}
//menuname = "展示小图"
@RequestMapping( value = "getxiaotu/{id}",produces = MediaType.IMAGE_JPEG_VALUE)
public byte[] getxiaotu(@PathVariable(value = "id") String id) {
byte[] bytes={};
if (!StringUtils.isBlank(id)){
EntityWrapper<Package> packagewrapper = new EntityWrapper<>();
packagewrapper.eq("id", id);
packagewrapper.setSqlSelect("logo as imgurl");
List<Map<String, Object>> selectMaps = packageMapper.selectMaps(packagewrapper);
if (!CollectionUtils.isEmpty(selectMaps)){
String imgurl = selectMaps.get(0).get("imgurl").toString();
imgurl=FilePath.BACKGROUNDIMG.getValue()+"/"+imgurl;
File file = new File(imgurl);
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bytes = new byte[0];
try {
bytes = new byte[inputStream.available()];
} catch (IOException e) {
e.printStackTrace();
}
try {
inputStream.read(bytes, 0, inputStream.available());
} catch (IOException e) {
e.printStackTrace();
}
return bytes;
}
}
return bytes;
}
} }
...@@ -12,10 +12,12 @@ import com.winsun.bean.Package; ...@@ -12,10 +12,12 @@ import com.winsun.bean.Package;
import com.winsun.bean.Product; import com.winsun.bean.Product;
import com.winsun.bean.School; import com.winsun.bean.School;
import com.winsun.bean.SchoolPackage; import com.winsun.bean.SchoolPackage;
import com.winsun.constant.FilePath;
import com.winsun.mapper.PackageMapper; import com.winsun.mapper.PackageMapper;
import com.winsun.mapper.ProductMapper; import com.winsun.mapper.ProductMapper;
import com.winsun.mapper.SchoolMapper; import com.winsun.mapper.SchoolMapper;
import com.winsun.mapper.SchoolPackageMapper; import com.winsun.mapper.SchoolPackageMapper;
import com.winsun.utils.FileUtil;
import com.winsun.utils.MyBatisPlusUpdateUtils; import com.winsun.utils.MyBatisPlusUpdateUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -26,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod; ...@@ -26,6 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.winsun.auth.core.common.model.ResponseData; import com.winsun.auth.core.common.model.ResponseData;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -50,6 +53,12 @@ public class SchoolManagementController extends BaseController { ...@@ -50,6 +53,12 @@ public class SchoolManagementController extends BaseController {
private static ProductMapper productMapper; private static ProductMapper productMapper;
//默认路径
private static String DEFAULTPATH="images/schoolPartner/";
private static String FILENAME=".jpg";
@Autowired @Autowired
public SchoolManagementController(SchoolMapper schoolMapper, SchoolPackageMapper schoolPackageMapper,PackageMapper packageMapper,ProductMapper productMapper) { public SchoolManagementController(SchoolMapper schoolMapper, SchoolPackageMapper schoolPackageMapper,PackageMapper packageMapper,ProductMapper productMapper) {
SchoolManagementController.schoolMapper = schoolMapper; SchoolManagementController.schoolMapper = schoolMapper;
...@@ -219,4 +228,24 @@ public class SchoolManagementController extends BaseController { ...@@ -219,4 +228,24 @@ public class SchoolManagementController extends BaseController {
hashMap.put("choosepages",arrayList); hashMap.put("choosepages",arrayList);
return ResponseData.success(hashMap, "查询完毕!"); return ResponseData.success(hashMap, "查询完毕!");
} }
@Permission(menuname = "上传二维码", value = "qrcodeUpload", method = RequestMethod.POST)
public ResponseData<String>xiaotuUpload(@RequestParam(value = "file") MultipartFile file, @RequestParam(value = "id",required = false) String id) {
String backgroundpath= FilePath.BACKGROUNDIMG.getValue()+"/"+DEFAULTPATH+"/";
if (StringUtils.isBlank(id)){
EntityWrapper<School> packagewrapper = new EntityWrapper<>();
packagewrapper.setSqlSelect("max(id) as id");
List<Map<String, Object>> selectMaps = schoolMapper.selectMaps(packagewrapper);
id = selectMaps.get(0).get("id").toString();
id = Integer.valueOf(Integer.valueOf(id)+1).toString();
}
boolean makefile = FileUtil.makefile(backgroundpath, file,id+FILENAME);
if (!makefile){
return ResponseData.error("上传失败!");
}
return ResponseData.success("上传成功" );
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment