Browse Source

完善 仓库图片上传的功能

master
djz8236 2 years ago
parent
commit
554aa40c6b
  1. 5
      warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouse.java
  2. 10
      warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseDetailsVo.java
  3. 9
      warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseDto.java
  4. 5
      warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseQuery.java
  5. 5
      warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseVo.java
  6. 42
      warehousing-system/project/wh-manage/src/main/java/com/wh/controller/shstorehouse/ShStorehouseRest.java
  7. 3
      warehousing-system/project/wh-manage/src/main/java/com/wh/mapper/shstorehouseattachment/ShStorehouseAttachmentMapper.java
  8. 33
      warehousing-system/project/wh-manage/src/main/java/com/wh/service/shstorehouse/ShStorehouseService.java
  9. 16
      warehousing-system/project/wh-manage/src/main/java/com/wh/service/shstorehouseattachment/ShStorehouseAttachmentService.java

5
warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouse.java

@ -94,5 +94,8 @@ public class ShStorehouse extends BaseEntity {
private String linkerPhone; // 联系人电话
@ApiModelProperty("图片访问url")
private String picUrl; // 图片访问url
@ApiModelProperty("精度")
private String lon;
@ApiModelProperty("维度")
private String lat;
}

10
warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseDetailsVo.java

@ -26,12 +26,15 @@
package com.wh.pojo.shstorehouse;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachmentVo;
import com.yxt.common.core.vo.Vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* Project: yxt_supervise(宇信通监管) <br/>
* File: ShStorehouseVo.java <br/>
@ -95,5 +98,10 @@ public class ShStorehouseDetailsVo implements Vo {
private String linkerPhone; // 联系人电话
@ApiModelProperty("图片访问url")
private String picUrl; // 图片访问url
@ApiModelProperty("图片集合")
private List<ShStorehouseAttachmentVo> pics;
@ApiModelProperty("精度")
private String lon;
@ApiModelProperty("维度")
private String lat;
}

9
warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseDto.java

@ -33,6 +33,9 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* Project: yxt_supervise(宇信通监管) <br/>
* File: ShStorehouseDto.java <br/>
@ -96,4 +99,10 @@ public class ShStorehouseDto implements Dto {
private String linkerPhone; // 联系人电话
@ApiModelProperty("图片访问url")
private String picUrl; // 图片访问url
@ApiModelProperty("图片的集合")
private List<String> pics=new ArrayList<>();
@ApiModelProperty("精度")
private String lon;
@ApiModelProperty("维度")
private String lat;
}

5
warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseQuery.java

@ -93,5 +93,8 @@ public class ShStorehouseQuery implements Query {
private String linkerPhone; // 联系人电话
@ApiModelProperty("图片访问url")
private String picUrl; // 图片访问url
@ApiModelProperty("精度")
private String lon;
@ApiModelProperty("维度")
private String lat;
}

5
warehousing-system/project/wh-common/src/main/java/com/wh/pojo/shstorehouse/ShStorehouseVo.java

@ -95,5 +95,8 @@ public class ShStorehouseVo implements Vo {
private String linkerPhone; // 联系人电话
@ApiModelProperty("图片访问url")
private String picUrl; // 图片访问url
@ApiModelProperty("精度")
private String lon;
@ApiModelProperty("维度")
private String lat;
}

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

@ -29,11 +29,14 @@ import cn.hutool.core.lang.Assert;
import com.wh.feign.enterpriseinformation.WhEnterpriseInformationFeign;
import com.wh.feign.enterpriseinformation.WhEnterpriseInformationVo;
import com.wh.pojo.shstorehouse.*;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachmentDto;
import com.wh.service.shstorehouse.ShStorehouseService;
import com.wh.service.shstorehouseattachment.ShStorehouseAttachmentService;
import com.yxt.common.core.query.PagerQuery;
import com.yxt.common.core.result.ResultBean;
import com.yxt.common.core.vo.PagerVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@ -43,6 +46,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;
import java.util.UUID;
/**
* Project: yxt_supervise(宇信通监管) <br/>
@ -66,6 +70,8 @@ public class ShStorehouseRest {
@Autowired
private ShStorehouseService shStorehouseService;
@Autowired
private ShStorehouseAttachmentService shStorehouseAttachmentService;
@Autowired
private WhEnterpriseInformationFeign whEnterpriseInformationFeign;
@ApiOperation("根据条件分页查询数据的列表")
@PostMapping("/listPage")
@ -147,6 +153,42 @@ public class ShStorehouseRest {
}
return ResultBean.fireSuccess().setData(urlPath);
}
@ApiOperation("图片上传")
@PostMapping("/uploadPics")
public ResultBean uploadPics(@RequestParam("file") MultipartFile file, HttpServletRequest request) {
String filePath = ""; // 文件保存的位置
String urlPath = "";// 文件web浏览路径
Assert.isTrue(!file.isEmpty(), "文件为空");
// 原始名 以 a.jpg为例
String originalFilename = file.getOriginalFilename();
// 获取后缀并拼接'/'用于分类,也可以用日期 例: suffix = "jpg/"
String suffix = originalFilename.substring(originalFilename.lastIndexOf(".") + 1) + "/";
// 加上时间戳生成新的文件名,防止重复 newFileName = "1595511980146a.jpg"
String newFileName = System.currentTimeMillis() + originalFilename;
filePath = fileRootPath+ suffix + newFileName;
System.out.println(filePath);
String s = UUID.randomUUID().toString();
try {
File file1 = new File(filePath);
if (!file1.exists()) file1.mkdirs(); // 要是目录不存在,创建一个
file.transferTo(file1); // 保存起来
urlPath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/archive/" + suffix + newFileName;
ShStorehouseAttachmentDto dto=new ShStorehouseAttachmentDto();
// dto.setStorehouseSid(); // 库房sid
// dto.setStorehouseName(); // 库房名称
dto.setFileName(newFileName); // 文件名称
dto.setFileDesc(""); // 文件描述
dto.setFileType(suffix); // 文件类型,Word,Excel,PDF或图片
dto.setFileSuffix(suffix); // 文件后缀,如:png,jpg,xls,xlsx
dto.setFilePath(filePath); // 文件在服务器的存放路径
dto.setFileUrl(urlPath); // 文件获取的url地址
dto.setSid(s);
shStorehouseAttachmentService.insertByDto(dto);
} catch (Exception e) {
e.printStackTrace();
}
return ResultBean.fireSuccess().setData(s);
}
@ApiOperation("获取所有的企业信息")
@GetMapping("/fetchEntList")
public ResultBean<List<WhEnterpriseInformationVo>> fetchDetailsBySid(){

3
warehousing-system/project/wh-manage/src/main/java/com/wh/mapper/shstorehouseattachment/ShStorehouseAttachmentMapper.java

@ -31,6 +31,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachment;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachmentVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
@ -62,4 +63,6 @@ public interface ShStorehouseAttachmentMapper extends BaseMapper<ShStorehouseAtt
@Select("select * from sh_storehouse_attachment")
List<ShStorehouseAttachmentVo> selectListVo();
@Delete("delete from sh_storehouse_attachment where storehouse_sid=#{shsid}")
void deleteByHouseSid(@Param("shsid") String dtoSid);
}

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

@ -30,6 +30,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wh.mapper.shstorehouse.ShStorehouseMapper;
import com.wh.pojo.shstorehouse.*;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachmentDetailsVo;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachmentDto;
import com.wh.pojo.shstorehouseattachment.ShStorehouseAttachmentVo;
import com.wh.service.shstorehouseattachment.ShStorehouseAttachmentService;
import com.yxt.common.base.config.component.FileUploadComponent;
import com.yxt.common.base.config.component.ImageUploadUtil;
import com.yxt.common.core.result.FileUploadResult;
@ -42,6 +46,7 @@ import com.yxt.common.core.vo.PagerVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
@ -66,6 +71,7 @@ import java.util.Map;
public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper, ShStorehouse> {
@Autowired
private FileUploadComponent fileUploadComponent;
private ShStorehouseAttachmentService shStorehouseAttachmentService;
private QueryWrapper<ShStorehouse> createQueryWrapper(ShStorehouseQuery query) {
// todo: 这里根据具体业务调整查询条件
// 多字段Like示例:qw.and(wrapper -> wrapper.like("name", query.getName()).or().like("remark", query.getName()));
@ -95,12 +101,15 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
return shStorehouseVos;
}
@Transactional
public void saveOrUpdateDto(ShStorehouseDto dto){
String dtoSid = dto.getSid();
shStorehouseAttachmentService.deleteByHouseSid(dtoSid);
if (StringUtils.isBlank(dtoSid)) {
this.insertByDto(dto);
this.insertByDto(dto);
return;
}
}
this.updateByDto(dto);
}
@ -112,6 +121,15 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
String countyName = dto.getCountyName();
String regionName=provinceName+","+cityName+","+countyName;
entity.setRegionName(regionName);
List<String> pics = dto.getPics();
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);
shStorehouseAttachmentService.updateByDto(picdto);
}
baseMapper.insert(entity);
}
@ -127,6 +145,15 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
String regionName=provinceName+","+cityName+","+countyName;
entity.setRegionName(regionName);
BeanUtil.copyProperties(dto, entity, "id", "sid");
List<String> pics = dto.getPics();
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);
shStorehouseAttachmentService.updateByDto(picdto);
}
baseMapper.updateById(entity);
}
@ -135,7 +162,9 @@ public class ShStorehouseService extends MybatisBaseService<ShStorehouseMapper,
ShStorehouseDetailsVo vo = new ShStorehouseDetailsVo();
if (vo==null)
return null;
List<ShStorehouseAttachmentVo> pics=shStorehouseAttachmentService.fetchDetailsVoByShSid(sid);
BeanUtil.copyProperties(entity, vo);
vo.setPics(pics);
return vo;
}

16
warehousing-system/project/wh-manage/src/main/java/com/wh/service/shstorehouseattachment/ShStorehouseAttachmentService.java

@ -39,6 +39,7 @@ import com.yxt.common.core.vo.PagerVo;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -83,7 +84,7 @@ public class ShStorehouseAttachmentService extends MybatisBaseService<ShStorehou
public void insertByDto(ShStorehouseAttachmentDto dto){
ShStorehouseAttachment entity = new ShStorehouseAttachment();
BeanUtil.copyProperties(dto, entity, "id", "sid");
BeanUtil.copyProperties(dto, entity, "id");
baseMapper.insert(entity);
}
@ -103,4 +104,17 @@ public class ShStorehouseAttachmentService extends MybatisBaseService<ShStorehou
BeanUtil.copyProperties(entity, vo);
return vo;
}
public void deleteByHouseSid(String dtoSid) {
baseMapper.deleteByHouseSid(dtoSid);
}
public List<ShStorehouseAttachmentVo> fetchDetailsVoByShSid(String sid) {
QueryWrapper<ShStorehouseAttachment> qw =new QueryWrapper<>();
if (StringUtils.isBlank(sid)){
return new ArrayList<>();
}
qw.eq("storehouse_sid",sid);
return baseMapper.selectListAllVo(qw);
}
}
Loading…
Cancel
Save