给商品相关接口增加图片缩略图字段的返回
This commit is contained in:
@@ -254,6 +254,7 @@ public class DepotItemController {
|
||||
BigDecimal allWeight = diEx.getBasicNumber()==null||diEx.getWeight()==null?BigDecimal.ZERO:diEx.getBasicNumber().multiply(diEx.getWeight());
|
||||
item.put("weight", allWeight);
|
||||
item.put("remark", diEx.getRemark());
|
||||
item.put("imgName", diEx.getImgName());
|
||||
item.put("linkId", diEx.getLinkId());
|
||||
item.put("depotId", diEx.getDepotId() == null ? "" : diEx.getDepotId());
|
||||
item.put("depotName", diEx.getDepotId() == null ? "" : diEx.getDepotName());
|
||||
|
||||
@@ -6,16 +6,13 @@ import com.jsh.erp.service.systemConfig.SystemConfigService;
|
||||
import com.jsh.erp.service.user.UserService;
|
||||
import com.jsh.erp.service.userBusiness.UserBusinessService;
|
||||
import com.jsh.erp.utils.BaseResponseInfo;
|
||||
import com.jsh.erp.utils.FileUtils;
|
||||
import com.jsh.erp.utils.StringUtil;
|
||||
import com.jsh.erp.utils.Tools;
|
||||
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.util.AntPathMatcher;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -25,8 +22,10 @@ import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.HandlerMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
@@ -227,6 +226,51 @@ public class SystemConfigController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预览缩略图&下载文件
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@GetMapping(value = "/static/mini/**")
|
||||
@ApiOperation(value = "预览缩略图&下载文件")
|
||||
public void viewMini(HttpServletRequest request, HttpServletResponse response) {
|
||||
// ISO-8859-1 ==> UTF-8 进行编码转换
|
||||
String imgPath = extractPathFromPattern(request);
|
||||
if(StringUtil.isEmpty(imgPath) || imgPath=="null"){
|
||||
return;
|
||||
}
|
||||
OutputStream outputStream = null;
|
||||
try {
|
||||
imgPath = imgPath.replace("..", "");
|
||||
if (imgPath.endsWith(",")) {
|
||||
imgPath = imgPath.substring(0, imgPath.length() - 1);
|
||||
}
|
||||
String fileUrl = "";
|
||||
if(fileUploadType == 1) {
|
||||
fileUrl = systemConfigService.getFileUrlLocal(imgPath);
|
||||
} else if(fileUploadType == 2) {
|
||||
fileUrl = systemConfigService.getFileUrlAliOss(imgPath);
|
||||
}
|
||||
int index = fileUrl.lastIndexOf(".");
|
||||
String ext = fileUrl.substring(index + 1);
|
||||
BufferedImage image = systemConfigService.getImageMini(fileUrl, 40);
|
||||
outputStream = response.getOutputStream();
|
||||
ImageIO.write(image, ext, outputStream);
|
||||
response.flushBuffer();
|
||||
} catch (Exception e) {
|
||||
response.setStatus(404);
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 把指定URL后的字符串全部截断当成参数
|
||||
* 这么做是为了防止URL中包含中文或者特殊字符(/等)时,匹配不了的问题
|
||||
|
||||
@@ -50,6 +50,8 @@ public class DepotItemVo4WithInfoEx extends DepotItem{
|
||||
|
||||
private BigDecimal weight;
|
||||
|
||||
private String imgName;
|
||||
|
||||
public Long getMId() {
|
||||
return MId;
|
||||
}
|
||||
@@ -233,4 +235,12 @@ public class DepotItemVo4WithInfoEx extends DepotItem{
|
||||
public void setWeight(BigDecimal weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getImgName() {
|
||||
return imgName;
|
||||
}
|
||||
|
||||
public void setImgName(String imgName) {
|
||||
this.imgName = imgName;
|
||||
}
|
||||
}
|
||||
@@ -31,7 +31,10 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -287,6 +290,28 @@ public class SystemConfigService {
|
||||
return linkUrl + filePath + "/" + imgPath;
|
||||
}
|
||||
|
||||
public BufferedImage getImageMini(String fileUrl, int w) throws Exception {
|
||||
BufferedImage img = ImageIO.read(new File(fileUrl));
|
||||
//获取图片的长和宽
|
||||
int width = img.getWidth();
|
||||
int height = img.getHeight();
|
||||
int tempw = 0;
|
||||
int temph = 0;
|
||||
if(width>height){
|
||||
tempw = w;
|
||||
temph = height* w/width;
|
||||
}else{
|
||||
tempw = w*width/height;
|
||||
temph = w;
|
||||
}
|
||||
Image _img = img.getScaledInstance(tempw, temph, Image.SCALE_DEFAULT);
|
||||
BufferedImage image = new BufferedImage(tempw, temph, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics2D graphics = image.createGraphics();
|
||||
graphics.drawImage(_img, 0, 0, null);
|
||||
graphics.dispose();
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取仓库开关
|
||||
* @return
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
<result column="MStandard" jdbcType="VARCHAR" property="MStandard" />
|
||||
<result column="MMfrs" jdbcType="VARCHAR" property="MMfrs" />
|
||||
<result column="weight" jdbcType="VARCHAR" property="weight" />
|
||||
<result column="img_name" jdbcType="VARCHAR" property="imgName" />
|
||||
<result column="MOtherField1" jdbcType="VARCHAR" property="MOtherField1" />
|
||||
<result column="MOtherField2" jdbcType="VARCHAR" property="MOtherField2" />
|
||||
<result column="MOtherField3" jdbcType="VARCHAR" property="MOtherField3" />
|
||||
@@ -301,7 +302,7 @@
|
||||
</select>
|
||||
|
||||
<select id="getDetailList" parameterType="com.jsh.erp.datasource.entities.DepotItemExample" resultMap="ResultWithInfoExMap">
|
||||
select di.*,m.name MName,m.model MModel,m.unit MaterialUnit,m.color MColor,m.standard MStandard,m.mfrs MMfrs,m.weight,
|
||||
select di.*,m.name MName,m.model MModel,m.unit MaterialUnit,m.color MColor,m.standard MStandard,m.mfrs MMfrs,m.weight, m.img_name,
|
||||
m.other_field1 MOtherField1,m.other_field2 MOtherField2,m.other_field3 MOtherField3,m.enable_serial_number, m.enable_batch_number,
|
||||
dp1.name DepotName,dp2.name AnotherDepotName, me.bar_code barCode, me.purchase_decimal
|
||||
from jsh_depot_item di
|
||||
|
||||
Reference in New Issue
Block a user