Browse Source

完善 仓库图片上传的功能

master
djz8236 2 years ago
parent
commit
1c9984d54f
  1. 29
      warehousing-system/project/wh-manage/src/main/java/com/wh/config/FileUploadConfig.java
  2. 7
      warehousing-system/project/wh-manage/src/main/java/com/wh/controller/shstorehouse/ShStorehouseRest.java
  3. 38
      warehousing-system/project/wh-manage/src/main/java/com/wh/service/shstorehouse/ShStorehouseService.java
  4. 2
      warehousing-system/project/wh-manage/src/main/resources/application.yml

29
warehousing-system/project/wh-manage/src/main/java/com/wh/config/FileUploadConfig.java

@ -0,0 +1,29 @@
package com.wh.config;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;
import javax.servlet.MultipartConfigElement;
/**
* 文件上传配置类
*
* @Author mashanghaoyun
* @Date 2020/11/11 01:34
* @Version 1.0
**/
@Configuration
public class FileUploadConfig {
@Bean
public MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
// 单个数据大小
factory.setMaxFileSize(DataSize.parse("502400KB")); // KB,MB
// 总上传数据大小
factory.setMaxRequestSize(DataSize.parse("1024000KB"));
return factory.createMultipartConfig();
}
}

7
warehousing-system/project/wh-manage/src/main/java/com/wh/controller/shstorehouse/ShStorehouseRest.java

@ -147,7 +147,9 @@ public class ShStorehouseRest {
File file1 = new File(filePath);
if (!file1.exists()) file1.mkdirs(); // 要是目录不存在,创建一个
file.transferTo(file1); // 保存起来
urlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/archive/" + suffix + newFileName;
//urlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/archive/" + suffix + newFileName;
urlPath = "http://jianguan.yyundong.com/warehouseapi/archive/" + suffix + newFileName;
} catch (Exception e) {
e.printStackTrace();
}
@ -173,7 +175,8 @@ public class ShStorehouseRest {
File file1 = new File(filePath);
if (!file1.exists()) file1.mkdirs(); // 要是目录不存在,创建一个
file.transferTo(file1); // 保存起来
urlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/archive/" + suffix + newFileName;
//urlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/archive/" + suffix + newFileName;
urlPath = "http://jianguan.yyundong.com/warehouseapi/archive/" + suffix + newFileName;
// dto.setStorehouseSid(); // 库房sid
// dto.setStorehouseName(); // 库房名称

38
warehousing-system/project/wh-manage/src/main/java/com/wh/service/shstorehouse/ShStorehouseService.java

@ -50,9 +50,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
/**
* Project: yxt_supervise(宇信通监管) <br/>
@ -71,6 +69,7 @@ import java.util.Map;
public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper, ShStorehouse> {
@Autowired
private FileUploadComponent fileUploadComponent;
@Autowired
private ShStorehouseAttachmentService shStorehouseAttachmentService;
private QueryWrapper<ShStorehouse> createQueryWrapper(ShStorehouseQuery query) {
// todo: 这里根据具体业务调整查询条件
@ -104,12 +103,11 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
@Transactional
public void saveOrUpdateDto(ShStorehouseDto dto){
String dtoSid = dto.getSid();
shStorehouseAttachmentService.deleteByHouseSid(dtoSid);
if (StringUtils.isBlank(dtoSid)) {
this.insertByDto(dto);
return;
}
this.updateByDto(dto);
}
@ -127,7 +125,7 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
shStorehouseAttachmentDetailsVo.setStorehouseSid(entity.getSid());
shStorehouseAttachmentDetailsVo.setStorehouseName(entity.getName());
ShStorehouseAttachmentDto picdto=new ShStorehouseAttachmentDto();
BeanUtil.copyProperties(pic,picdto);
BeanUtil.copyProperties(shStorehouseAttachmentDetailsVo,picdto);
shStorehouseAttachmentService.updateByDto(picdto);
}
baseMapper.insert(entity);
@ -137,7 +135,16 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
String dtoSid = dto.getSid();
if (StringUtils.isBlank(dtoSid)) {
return;
}
}
List<ShStorehouseAttachmentVo> shStorehouseAttachmentVos=new ArrayList<>();
if (StringUtils.isNotBlank(dtoSid)) {
shStorehouseAttachmentVos= shStorehouseAttachmentService.fetchDetailsVoByShSid(dtoSid);
}
Map<String,String> picsmap2=new HashMap<>();
for (ShStorehouseAttachmentVo shStorehouseAttachmentVo : shStorehouseAttachmentVos) {
picsmap2.put(shStorehouseAttachmentVo.getSid(),shStorehouseAttachmentVo.getSid());
}
ShStorehouse entity = fetchBySid(dtoSid);
String provinceName = dto.getProvinceName();
String cityName = dto.getCityName();
@ -146,12 +153,25 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
entity.setRegionName(regionName);
BeanUtil.copyProperties(dto, entity, "id", "sid");
List<String> pics = dto.getPics();
Map<String,String> picsmap=new HashMap<>();
for (String pic : pics) {
picsmap.put(pic,pic);
}
Set<Map.Entry<String, String>> entries = picsmap2.entrySet();
for (Map.Entry<String, String> entry : entries) {
String key = entry.getKey();
if(picsmap.get(key)==null){
shStorehouseAttachmentService.deleteBySid(key);
}
}
for (String pic : pics) {
ShStorehouseAttachmentDetailsVo shStorehouseAttachmentDetailsVo = shStorehouseAttachmentService.fetchDetailsVoBySid(pic);
shStorehouseAttachmentDetailsVo.setStorehouseSid(entity.getSid());
shStorehouseAttachmentDetailsVo.setStorehouseName(entity.getName());
ShStorehouseAttachmentDto picdto=new ShStorehouseAttachmentDto();
BeanUtil.copyProperties(pic,picdto);
BeanUtil.copyProperties(shStorehouseAttachmentDetailsVo,picdto);
shStorehouseAttachmentService.updateByDto(picdto);
}
baseMapper.updateById(entity);
@ -160,7 +180,7 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
public ShStorehouseDetailsVo fetchDetailsVoBySid(String sid){
ShStorehouse entity = fetchBySid(sid);
ShStorehouseDetailsVo vo = new ShStorehouseDetailsVo();
if (vo==null)
if (entity==null)
return null;
List<ShStorehouseAttachmentVo> pics=shStorehouseAttachmentService.fetchDetailsVoByShSid(sid);
BeanUtil.copyProperties(entity, vo);

2
warehousing-system/project/wh-manage/src/main/resources/application.yml

@ -4,7 +4,7 @@ server:
context-path: /
multipart:
enabled: true
max-file-size: 20MB
max-file-size: 50MB
max-request-size: 200MB
spring:
application:

Loading…
Cancel
Save