|
@@ -11,18 +11,27 @@ import com.management.platform.mapper.*;
|
|
import com.management.platform.service.BusinessOpportunityService;
|
|
import com.management.platform.service.BusinessOpportunityService;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
import com.management.platform.service.WxCorpInfoService;
|
|
|
|
+import com.management.platform.util.FileUtil;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
|
+import com.management.platform.util.MessageUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
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.multipart.MultipartFile;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
+import java.net.URLEncoder;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -224,6 +233,114 @@ public class BusinessOpportunityServiceImpl extends ServiceImpl<BusinessOpportun
|
|
return msg;
|
|
return msg;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Value(value = "${upload.file}")
|
|
|
|
+ private String filePath;
|
|
|
|
+ @Override
|
|
|
|
+ public Object uploadFile(BusinessItemCustom bo, HttpServletRequest request, MultipartFile file) {
|
|
|
|
+ User user = userMapper.selectById(request.getHeader("token"));
|
|
|
|
+ if (!file.isEmpty()) { // 检查上传的文件是否为空
|
|
|
|
+ try {
|
|
|
|
+ // 获取上传文件的原始文件名
|
|
|
|
+ String originalFilename = file.getOriginalFilename();
|
|
|
|
+
|
|
|
|
+ // 创建文件存储目录
|
|
|
|
+ File uploadDir = new File(filePath);
|
|
|
|
+ if (!uploadDir.exists()) {
|
|
|
|
+ uploadDir.mkdirs();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ UploadFile uf = new UploadFile();
|
|
|
|
+ uf.setName(originalFilename);
|
|
|
|
+ String realName = "";
|
|
|
|
+ int pos = originalFilename.lastIndexOf(".");
|
|
|
|
+ String suffix = originalFilename.substring(pos).toLowerCase();
|
|
|
|
+ //用uuid替换原始的文件名
|
|
|
|
+ String purFName = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
|
+ realName = purFName + suffix;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ uf.setPath(filePath + realName);
|
|
|
|
+ uf.setCode("business");
|
|
|
|
+ uf.setItemId(bo.getId());
|
|
|
|
+ uf.setRealName(realName);
|
|
|
|
+ uf.setCreateTime(new Date());
|
|
|
|
+ uf.setCreateId(user.getId());
|
|
|
|
+ uploadFileMapper.insert(uf);
|
|
|
|
+ // 构建上传文件的目标路径
|
|
|
|
+ String filePath1 = filePath + realName;
|
|
|
|
+
|
|
|
|
+ // 在服务器上创建文件
|
|
|
|
+ File dest = new File(filePath1);
|
|
|
|
+
|
|
|
|
+ // 将上传的文件保存到目标路径
|
|
|
|
+ file.transferTo(dest);
|
|
|
|
+
|
|
|
|
+ // 文件上传成功的响应消息
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.setMsg("上传成功");
|
|
|
|
+ return msg;
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ // 文件上传失败的响应消息
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.setError("上传成功失败");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 文件为空的响应消息
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.setError("请选择上传文件");
|
|
|
|
+ return msg;
|
|
|
|
+ } }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object downFile(UploadFile file, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ ServletOutputStream os = response.getOutputStream();
|
|
|
|
+ UploadFile uploadFile = uploadFileMapper.selectById(file.getId());
|
|
|
|
+ if (uploadFile == null ){
|
|
|
|
+ msg.setError("文件未找到");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ File uploadFile1 = new File(uploadFile.getPath());
|
|
|
|
+ response.addHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(uploadFile.getName(), "UTF-8"));
|
|
|
|
+ response.setContentType("application/octet-stream");
|
|
|
|
+ // 读取文件的字节流
|
|
|
|
+ os.write(FileUtil.readFileByBytes(uploadFile1));
|
|
|
|
+ os.flush();
|
|
|
|
+
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ msg.setError(MessageUtils.message("file.error"));
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object deleteFile(UploadFile file, HttpServletRequest request) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ UploadFile uploadFile = uploadFileMapper.selectById(file.getId());
|
|
|
|
+ uploadFileMapper.deleteById(uploadFile.getId());
|
|
|
|
+ String realName = uploadFile.getRealName();
|
|
|
|
+ File file1 = new File(path + realName);
|
|
|
|
+ file1.delete();
|
|
|
|
+ msg.setMsg("删除成功");
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ msg.setError("删除失败");
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Object reFileName(UploadFile uploadFile, HttpServletRequest request) {
|
|
|
|
+ return uploadFileMapper.update(null, new UpdateWrapper<UploadFile>().eq("id", uploadFile.getId()).set("name", uploadFile.getName()));
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
private BusinessOpportunity setNull(BusinessOpportunity bo) {
|
|
private BusinessOpportunity setNull(BusinessOpportunity bo) {
|
|
if (bo.getPlate1() == "") {
|
|
if (bo.getPlate1() == "") {
|
|
bo.setPlate1(null);
|
|
bo.setPlate1(null);
|