Commit 4c645225 by HlQ

[chg] 无用代码删除

1 parent 09198e44
...@@ -4,14 +4,8 @@ import cn.hutool.core.collection.CollUtil; ...@@ -4,14 +4,8 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter; import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -20,21 +14,12 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -20,21 +14,12 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import vion.dto.FileInfoDTO; import vion.dto.FileInfoDTO;
import vion.model.Contract;
import vion.model.FileInfo; import vion.model.FileInfo;
import vion.model.Pic;
import vion.service.IContractService;
import vion.service.IFileService; import vion.service.IFileService;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.sql.*;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController @RestController
@RequestMapping("/api") @RequestMapping("/api")
...@@ -43,7 +28,6 @@ import java.util.stream.Collectors; ...@@ -43,7 +28,6 @@ import java.util.stream.Collectors;
public class FileController { public class FileController {
private final IFileService fileService; private final IFileService fileService;
private final IContractService contractService;
private final Converter converter; private final Converter converter;
@Value("${fileUrl:}") @Value("${fileUrl:}")
...@@ -133,194 +117,4 @@ public class FileController { ...@@ -133,194 +117,4 @@ public class FileController {
} }
return "文件保存成功"; 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";
}*/
@GetMapping("/contractFile")
public String export() {
String url = "jdbc:sqlserver://47.92.144.255:1433;databaseName=UFDATA_001_2020;encrypt=false";
String username = "vion-reader";
String password = "vion-reader";
List<Pic> res = new ArrayList<>();
try (Connection connection = DriverManager.getConnection(url, username, password)) {
String sql = "select hetongpingshen_char05 as contract_no,hetongpingshen_char01 as pic_url from tcu_hetongpingshen;";
try (Statement statement = connection.createStatement()) {
ResultSet resultSet = statement.executeQuery(sql);
while (resultSet.next()) {
Pic pic = new Pic();
String contractNo = resultSet.getString("contract_no");
pic.setContractNo(contractNo);
String picUrl = resultSet.getString("pic_url");
if (StrUtil.isBlank(picUrl)) {
continue;
}
// 获取字符串picUrl后五个字符
String code = picUrl.substring(picUrl.length() - 36);
pic.setCode(code);
res.add(pic);
}
}
} catch (SQLException e) {
}
Map<String, Contract> no2ConMap = contractService.list().stream().collect(Collectors.toMap(Contract::getContractNo, Function.identity()));
// CSRP20111098 CSRM23065215
for (Pic pic : res) {
String contractNo = pic.getContractNo();
String code = pic.getCode();
if (!no2ConMap.containsKey(contractNo)) {
log.info("合同文件导入-合同不存在:{}", contractNo);
continue;
}
Contract contract = no2ConMap.get(contractNo);
List<FileInfo> list = fileService.lambdaQuery()
.eq(FileInfo::getContractId, contract.getId())
.eq(FileInfo::getSourceType, 5)
.eq(FileInfo::getSourceId, contract.getId()).list();
if (CollUtil.isNotEmpty(list)) {
log.info("合同文件导入-合同文件已存在:{}", contractNo);
continue;
}
String body = HttpRequest.post("http://47.92.144.255:8072/pub/processattach.php?Action=viewfiles&PageSrc=")
.header("Cookie", "PHPSESSID=c52hbrbdc4tp73fai2shhkscj4; LoginSystemCookie=1; LoginNameCookie=0191; OrgCodeCookie=%28default%29%40001; ID_LIST_OL_10_0_0_MessageItem__Subject=250; TL_EXPANDED=*XSFPSQD.hetonglur2017*REL_XSFPSQDITEMS2002*REL_PRIVILEGE2002*hetongpingshen.Opportunity4*hetongluru.XMMC4")
.form("cellID", code)
.execute()
.body();
if (body.contains("text/javascript")) {
log.info("合同文件导入-调CRM接口出错:{}", contractNo);
break;
}
if (StrUtil.isBlank(body)) {
log.info("合同文件导入-body为空:{},code:{}", contractNo, code);
continue;
}
if (!StrUtil.contains(body, "href")) {
log.info("合同文件导入-无文件:{},code:{}", contractNo, code);
continue;
}
JSONObject json = JSONUtil.parseObj(body);
Object o = json.get("files");
if (o instanceof JSONObject) {
JSONObject files = json.getJSONObject("files");
for (Map.Entry<String, Object> entry : files) {
if (ObjUtil.isEmpty(entry.getValue())) {
continue;
}
String href = entry.getValue().toString();
String suf = ReUtil.get("href='(.*?)'", href, 1);
String finalUrl = "http://47.92.144.255:8072" + suf;
String name = ReUtil.get(">(.*?)<", href, 1);
String path = fileUrl + FileUtil.FILE_SEPARATOR + "contract" + FileUtil.FILE_SEPARATOR + contract.getId() + FileUtil.FILE_SEPARATOR + name;
log.info("合同:{},文件存入路径:{}", contractNo, path);
File file = HttpUtil.downloadFileFromUrl(finalUrl, FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(contract.getId());
fileInfo.setSourceType(5);
fileInfo.setContractId(contract.getId());
fileInfo.setName(name);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("CRM");
fileService.save(fileInfo);
}
} else if (o instanceof JSONArray) {
JSONArray files = json.getJSONArray("files");
for (Object obj : files) {
if (ObjUtil.isEmpty(obj)) {
continue;
}
String href = obj.toString();
String suf = ReUtil.get("href='(.*?)'", href, 1);
String finalUrl = "http://47.92.144.255:8072" + suf;
String name = ReUtil.get(">(.*?)<", href, 1);
String path = fileUrl + FileUtil.FILE_SEPARATOR + "contract" + FileUtil.FILE_SEPARATOR + contract.getId() + FileUtil.FILE_SEPARATOR + name;
log.info("合同:{},文件存入路径:{}", contractNo, path);
File file = HttpUtil.downloadFileFromUrl(finalUrl, FileUtil.file(path));
FileInfo fileInfo = new FileInfo();
fileInfo.setStoreId(-1L);
fileInfo.setSourceId(contract.getId());
fileInfo.setSourceType(5);
fileInfo.setContractId(contract.getId());
fileInfo.setName(name);
fileInfo.setUrl(path);
fileInfo.setType(FileUtil.extName(file));
fileInfo.setSha256(SecureUtil.sha256(file).toUpperCase());
fileInfo.setUploader("CRM");
fileService.save(fileInfo);
}
} else {
log.info("合同文件导入-json转化出错:{},code:{}", contractNo, code);
}
}
return "success";
}
} }
\ No newline at end of file \ No newline at end of file
package vion.model;
import lombok.Data;
@Data
public class Pic {
private String contractNo;
private String code;
}
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!