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