Commit 5ac12cce by HlQ

[chg] FileController 删除无用代码

1 parent 24dc594b
......@@ -3,9 +3,8 @@ package vion.controller;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
......@@ -14,18 +13,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vion.dto.FileInfoDTO;
import vion.model.*;
import vion.service.*;
import vion.utils.ResultUtil;
import vion.vo.ResultVO;
import vion.model.FileInfo;
import vion.service.IFileService;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api")
......@@ -36,11 +29,6 @@ public class FileController {
private final IFileService fileService;
private final Converter converter;
private final IDeliveryRecordService deliveryRecordService;
private final ITbDeliverGoodsService deliverGoodsService;
private final ITbAppendixService appendixService;
private final IContractService contractService;
@Value("${fileUrl:}")
private String fileUrl;
......@@ -61,14 +49,8 @@ public class FileController {
}
}
/*
* todo
* 手机端工单预处理提交
* 项目阶段修改,待联调 sourceType=1 这里的附件查询
* 工单处理上传附件
*/
@PostMapping("/upLoadFile")
public ResultVO uploadFile(Long storeId, Long sourceId, FileInfo fileInfo, @RequestParam(name = "file") MultipartFile infile) {
public String uploadFile(Long storeId, Long sourceId, FileInfo fileInfo, @RequestParam(name = "file") MultipartFile infile) {
try {
//上传url地址
String filename = infile.getOriginalFilename() + "_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
......@@ -78,39 +60,21 @@ public class FileController {
infile.transferTo(file);
String sha256 = SecureUtil.sha256(file).toUpperCase();
String extName = FileUtil.extName(file);
return ResultUtil.success(path);
} catch (IOException e) {
e.printStackTrace();
}
return ResultUtil.success();
/*String filename = infile.getOriginalFilename() + "_" + DateUtil.format(new Date(), DatePattern.PURE_DATETIME_PATTERN);
String path = fileurl + FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
// String path = fileurl + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
infile.transferTo(file);
return path;
} catch (IOException e) {
throw new RuntimeException(e);
log.error("上传文件失败", e);
}
fileInfo.setName(filename);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
// 如果是预工单的话,可能是客户上传的文件
// fileInfo.setUploader();
fileService.save(fileInfo);
return ResultUtil.success();*/
return "success";
}
@PostMapping("/uploadFile1")
public String uploadFile1(FileInfo fileInfo, @RequestParam(name = "files") MultipartFile[] files) throws IOException {
for (MultipartFile infile : files) {
String orgName = infile.getOriginalFilename();
String fileName = orgName.substring(0, orgName.lastIndexOf("."));
String fileExt = orgName.substring(orgName.lastIndexOf("."));
String filename = fileName + "_" + DateUtil.format(new Date(), "yyyyMMdd_HHmmss") + fileExt;
String path = fileUrl + FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);
String path = FileUtil.FILE_SEPARATOR + fileInfo.getStoreId() + FileUtil.FILE_SEPARATOR + fileInfo.getSourceId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
infile.transferTo(file);
......@@ -129,63 +93,4 @@ public class FileController {
return "文件保存成功";
}
@GetMapping("/tmpfile")
public String sync() {
// bDeliverGoodsId => tbAppendix
Map<String, List<TbAppendix>> id2UrlMap = appendixService.list(Wrappers.<TbAppendix>lambdaQuery().eq(TbAppendix::getBusinessTable, "tb_deliver_goods"))
.stream().collect(Collectors.groupingBy(TbAppendix::getBusinessUnid));
// bDeliverGoodsId => tbDeliverGoods
Map<Long, TbDeliverGoods> id2DeliverGoodsMap = deliverGoodsService.list().stream().collect(Collectors.toMap(TbDeliverGoods::getDeliverUnid, Function.identity()));
// contractNo => contract
Map<String, Long> no2ContractIdMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Contract::getId));
// contractNo => List<DeliveryRecord>
Map<String, List<DeliveryRecord>> no2IdMap = deliveryRecordService.list().stream().collect(Collectors.groupingBy(DeliveryRecord::getContractNo));
id2UrlMap.forEach((id, appendixList) -> appendixList.forEach(appendix -> {
TbDeliverGoods deliverGoods = id2DeliverGoodsMap.get(Long.valueOf(id));
String contractNo = deliverGoods.getContractUnid();
Long contractId = no2ContractIdMap.get(contractNo);
if (contractId == null) {
log.error("合同不存在:{}", contractNo);
return;
}
List<DeliveryRecord> deliveryIdList = no2IdMap.get(contractNo);
if (deliveryIdList.size() == 1) {
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + contractId + FileUtil.FILE_SEPARATOR + deliveryIdList.get(0).getId() + FileUtil.FILE_SEPARATOR + appendix.getAppendixName();
File file = HttpUtil.downloadFileFromUrl(appendix.getAppendixUrl().replace("192.168.9.110", "117.133.143.114"), FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(deliveryIdList.get(0).getId());
fileInfo.setSourceType(6);
fileInfo.setContractId(contractId);
fileInfo.setName(appendix.getAppendixName());
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("原合同平台");
fileService.save(fileInfo);
} else {
for (DeliveryRecord deliveryRecord : deliveryIdList) {
if (deliveryRecord.getSignDate().equals(id2DeliverGoodsMap.get(Long.valueOf(id)).getGoodsAcceptancDate()) && deliveryRecord.getShipDate().equals(id2DeliverGoodsMap.get(Long.valueOf(id)).getDeliverGoodsDate())) {
String path = fileUrl + FileUtil.FILE_SEPARATOR + "/delivery" + FileUtil.FILE_SEPARATOR + contractId + FileUtil.FILE_SEPARATOR + deliveryRecord.getId() + FileUtil.FILE_SEPARATOR + appendix.getAppendixName();
File file = HttpUtil.downloadFileFromUrl(appendix.getAppendixUrl().replace("192.168.9.110", "117.133.143.114"), FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(deliveryRecord.getId());
fileInfo.setSourceType(6);
fileInfo.setContractId(contractId);
fileInfo.setName(appendix.getAppendixName());
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("原合同平台");
fileService.save(fileInfo);
}
}
}
}));
return "success";
}
}
\ No newline at end of file
......@@ -219,7 +219,6 @@ public class ContractServiceImpl extends MPJBaseServiceImpl<ContractMapper, Cont
String mainName = FileUtil.mainName(orgName);
String fileExt = FileUtil.extName(orgName);
String filename = StrUtil.format("{}_{}.{}", mainName, DateUtil.format(new Date(), "yyyyMMdd_HHmmss"), fileExt);
;
String path = fileUrl + FileUtil.FILE_SEPARATOR + "contract" + FileUtil.FILE_SEPARATOR + contract.getId() + FileUtil.FILE_SEPARATOR + filename;
File file = FileUtil.touch(path);
try {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!