调整商品图片的缩略图路径接口
This commit is contained in:
@@ -23,6 +23,7 @@ import jxl.Sheet;
|
||||
import jxl.Workbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -70,6 +71,9 @@ public class DepotItemController {
|
||||
@Resource
|
||||
private SystemConfigService systemConfigService;
|
||||
|
||||
@Value(value="${file.uploadType}")
|
||||
private Long fileUploadType;
|
||||
|
||||
/**
|
||||
* 根据仓库和商品查询单据列表
|
||||
* @param mId
|
||||
@@ -255,6 +259,11 @@ public class DepotItemController {
|
||||
item.put("weight", allWeight);
|
||||
item.put("remark", diEx.getRemark());
|
||||
item.put("imgName", diEx.getImgName());
|
||||
if(fileUploadType == 2) {
|
||||
item.put("imgType", "small");
|
||||
} else {
|
||||
item.put("imgType", "");
|
||||
}
|
||||
item.put("linkId", diEx.getLinkId());
|
||||
item.put("depotId", diEx.getDepotId() == null ? "" : diEx.getDepotId());
|
||||
item.put("depotName", diEx.getDepotId() == null ? "" : diEx.getDepotName());
|
||||
|
||||
@@ -16,6 +16,7 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -51,6 +52,9 @@ public class MaterialController {
|
||||
@Resource
|
||||
private DepotService depotService;
|
||||
|
||||
@Value(value="${file.uploadType}")
|
||||
private Long fileUploadType;
|
||||
|
||||
/**
|
||||
* 检查商品是否存在
|
||||
* @param id
|
||||
@@ -263,6 +267,11 @@ public class MaterialController {
|
||||
item.put("stock", stock);
|
||||
item.put("expand", materialService.getMaterialOtherByParam(mpArr, material));
|
||||
item.put("imgName", material.getImgName());
|
||||
if(fileUploadType == 2) {
|
||||
item.put("imgType", "small");
|
||||
} else {
|
||||
item.put("imgType", "");
|
||||
}
|
||||
dataArray.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public class MaterialVo4Unit extends Material{
|
||||
*/
|
||||
private String bigUnitStock;
|
||||
|
||||
private String imgType;
|
||||
|
||||
public String getUnitName() {
|
||||
return unitName;
|
||||
}
|
||||
@@ -206,4 +208,12 @@ public class MaterialVo4Unit extends Material{
|
||||
public void setBigUnitStock(String bigUnitStock) {
|
||||
this.bigUnitStock = bigUnitStock;
|
||||
}
|
||||
|
||||
public String getImgType() {
|
||||
return imgType;
|
||||
}
|
||||
|
||||
public void setImgType(String imgType) {
|
||||
this.imgType = imgType;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import jxl.Sheet;
|
||||
import jxl.Workbook;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
@@ -76,6 +77,9 @@ public class MaterialService {
|
||||
@Resource
|
||||
private MaterialExtendService materialExtendService;
|
||||
|
||||
@Value(value="${file.uploadType}")
|
||||
private Long fileUploadType;
|
||||
|
||||
public Material getMaterial(long id)throws Exception {
|
||||
Material result=null;
|
||||
try{
|
||||
@@ -131,6 +135,9 @@ public class MaterialService {
|
||||
if (null != list && list.size()>0) {
|
||||
Map<Long,BigDecimal> currentStockMap = getCurrentStockMapByMaterialList(list);
|
||||
for (MaterialVo4Unit m : list) {
|
||||
if(fileUploadType == 2) {
|
||||
m.setImgType("small");
|
||||
}
|
||||
m.setMaterialOther(getMaterialOtherByParam(mpArr, m));
|
||||
m.setStock(currentStockMap.get(m.getId())!=null? currentStockMap.get(m.getId()): BigDecimal.ZERO);
|
||||
m.setBigUnitStock(getBigUnitStock(m.getStock(), m.getUnitId()));
|
||||
|
||||
@@ -32,13 +32,13 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.imageio.stream.ImageOutputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@@ -174,7 +174,7 @@ public class SystemConfigService {
|
||||
* @param name 自定义文件名
|
||||
* @return
|
||||
*/
|
||||
public String uploadLocal(MultipartFile mf, String bizPath, String name, HttpServletRequest request) {
|
||||
public String uploadLocal(MultipartFile mf, String bizPath, String name, HttpServletRequest request) throws Exception {
|
||||
try {
|
||||
if(StringUtil.isEmpty(bizPath)){
|
||||
bizPath = "";
|
||||
@@ -202,6 +202,17 @@ public class SystemConfigService {
|
||||
String savePath = file.getPath() + File.separator + fileName;
|
||||
File savefile = new File(savePath);
|
||||
FileCopyUtils.copy(mf.getBytes(), savefile);
|
||||
// 保存缩略图
|
||||
// String fileUrl = getFileUrlLocal(bizPath + File.separator + fileName);
|
||||
// InputStream imgInputStream = new BufferedInputStream(new FileInputStream(fileUrl));
|
||||
// BufferedImage smallImage = getImageMini(imgInputStream, 80);
|
||||
// int index = fileName.lastIndexOf(".");
|
||||
// String ext = fileName.substring(index + 1);
|
||||
// String smallUrl = filePath + "-small" + File.separator + bizPath + File.separator + fileName;
|
||||
// FileUtils.createFile(smallUrl);
|
||||
// File saveSmallFile = new File(smallUrl);
|
||||
// ImageIO.write(smallImage, ext, saveSmallFile);
|
||||
// 返回路径
|
||||
String dbpath = null;
|
||||
if(StringUtil.isNotEmpty(bizPath)){
|
||||
dbpath = bizPath + File.separator + fileName;
|
||||
@@ -251,6 +262,7 @@ public class SystemConfigService {
|
||||
}
|
||||
String filePathStr = StringUtil.isNotEmpty(filePath)? filePath.substring(1):"";
|
||||
String objectName = filePathStr + "/" + bizPath + "/" + fileName;
|
||||
String smallObjectName = filePathStr + "-small/" + bizPath + "/" + fileName;
|
||||
// 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||
byte [] byteArr = mf.getBytes();
|
||||
|
||||
@@ -258,11 +270,30 @@ public class SystemConfigService {
|
||||
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
|
||||
|
||||
try {
|
||||
// 保存原文件
|
||||
InputStream inputStream = new ByteArrayInputStream(byteArr);
|
||||
// 创建PutObjectRequest对象。
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, objectName, inputStream);
|
||||
// 创建PutObject请求。
|
||||
PutObjectResult result = ossClient.putObject(putObjectRequest);
|
||||
ossClient.putObject(putObjectRequest);
|
||||
// 如果是图片-保存缩略图
|
||||
int index = fileName.lastIndexOf(".");
|
||||
String ext = fileName.substring(index + 1);
|
||||
if(ext.contains("gif") || ext.contains("jpg") || ext.contains("jpeg") || ext.contains("png")
|
||||
|| ext.contains("GIF") || ext.contains("JPG") || ext.contains("JPEG") || ext.contains("PNG")) {
|
||||
String fileUrl = getFileUrlAliOss(bizPath + "/" + fileName);
|
||||
URL url = new URL(fileUrl);
|
||||
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
||||
conn.setRequestMethod("GET");
|
||||
conn.setConnectTimeout(5 * 1000);
|
||||
InputStream imgInputStream = conn.getInputStream();// 通过输入流获取图片数据
|
||||
BufferedImage smallImage = getImageMini(imgInputStream, 80);
|
||||
ByteArrayOutputStream bs = new ByteArrayOutputStream();
|
||||
ImageOutputStream imOut = ImageIO.createImageOutputStream(bs);
|
||||
ImageIO.write(smallImage, ext, imOut);
|
||||
InputStream isImg = new ByteArrayInputStream(bs.toByteArray());
|
||||
PutObjectRequest putSmallObjectRequest = new PutObjectRequest(bucketName, smallObjectName, isImg);
|
||||
ossClient.putObject(putSmallObjectRequest);
|
||||
}
|
||||
// 返回路径
|
||||
return bizPath + "/" + fileName;
|
||||
} catch (OSSException oe) {
|
||||
logger.error("Caught an OSSException, which means your request made it to OSS, "
|
||||
|
||||
Reference in New Issue
Block a user