|
@@ -47,12 +47,14 @@ import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.support.Condition;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.redis.cache.BladeRedis;
|
|
|
import org.springblade.core.secure.BladeUser;
|
|
|
import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.constant.BladeConstant;
|
|
|
import org.springblade.core.tool.utils.*;
|
|
|
+import org.springblade.evisa.redissionUtil.DistributedRedisLock;
|
|
|
import org.springblade.manager.bean.TableInfo;
|
|
|
import org.springblade.manager.dto.AddBussFileSortDTO;
|
|
|
import org.springblade.manager.entity.*;
|
|
@@ -78,9 +80,12 @@ import org.springframework.mock.web.MockMultipartFile;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.context.request.RequestContextHolder;
|
|
|
+import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Valid;
|
|
|
import java.awt.*;
|
|
@@ -93,10 +98,13 @@ import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.nio.file.Paths;
|
|
|
import java.nio.file.StandardCopyOption;
|
|
|
+import java.sql.SQLException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -1980,121 +1988,236 @@ public class ExcelTabController extends BladeController {
|
|
|
}
|
|
|
|
|
|
|
|
|
+// @PostMapping("/save_buss_data")
|
|
|
+// @ApiOperationSupport(order = 13)
|
|
|
+// @ApiOperation(value = "填报页面数据保存", notes = "填报页面数据保存")
|
|
|
+// public R saveBussData2(@Valid @RequestBody JSONObject dataInfo) throws Exception {
|
|
|
+//
|
|
|
+// ExecutionTime executionTime = new ExecutionTime();
|
|
|
+// executionTime.info("----计划开始----");
|
|
|
+// JSONArray dataArray = new JSONArray();
|
|
|
+// if (dataInfo.containsKey("dataInfo")) { //节点保存
|
|
|
+// JSONObject jsonObject = dataInfo.getJSONObject("dataInfo");
|
|
|
+// dataArray = jsonObject.getJSONArray("orderList");
|
|
|
+// } else { //单个保存
|
|
|
+// dataArray.add(dataInfo);
|
|
|
+// }
|
|
|
+//
|
|
|
+// String singnType ="2";
|
|
|
+// if(dataInfo.containsKey("signType")){
|
|
|
+// singnType=dataInfo.getString("signType");
|
|
|
+// } else {
|
|
|
+// singnType = "";
|
|
|
+// }
|
|
|
+//
|
|
|
+// // dataInfo.getJSONObject("dataInfo").getJSONArray("orderList");
|
|
|
+//
|
|
|
+// JSONObject tableInfo1 = dataArray.getJSONObject(0);
|
|
|
+// String nodeId = tableInfo1.getString("nodeId");
|
|
|
+// String contractId = tableInfo1.getString("contractId");
|
|
|
+// String projectId = tableInfo1.getString("projectId");
|
|
|
+// String classify = tableInfo1.getString("classify");
|
|
|
+//
|
|
|
+// executionTime.info("----组装开始----");
|
|
|
+// /*全加载,或者可以优化成依赖加载*/
|
|
|
+// List<AppWbsTreeContractVO> tableAll = new ArrayList<>();
|
|
|
+// List<TableInfo> tableInfoList = this.excelTabService.getTableInfoList(dataArray);
|
|
|
+// executionTime.info("----组装完成----");
|
|
|
+// try {
|
|
|
+// Long pKeyId = Long.parseLong(tableInfoList.get(0).getPkeyId());
|
|
|
+// String sql = "SELECT node_name from m_wbs_tree_contract where p_key_id=" + pKeyId;
|
|
|
+// String nodeName = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
+// HashMap<Long, String> map = new HashMap<>();
|
|
|
+// map.put(pKeyId, nodeName);
|
|
|
+// RandomNumberHolder.setRandomNumber(map);
|
|
|
+// } catch (NumberFormatException e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// //公式填充
|
|
|
+// executionTime.info("----公式填充执行----");
|
|
|
+// this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeId), ExecuteType.INSPECTION);
|
|
|
+// RandomNumberHolder.RandomNumberclear();
|
|
|
+// assert tableInfoList != null;
|
|
|
+// if (tableInfoList.size() == 0) {
|
|
|
+// R.success("数据未发生变化");
|
|
|
+// }
|
|
|
+// executionTime.info("----公式填充执行完毕----");
|
|
|
+// //保存数据到数据库
|
|
|
+// R<Object> result = this.excelTabService.saveOrUpdateInfo(tableInfoList,singnType);
|
|
|
+// RandomNumberHolder.RandomTemplateTypeclear();
|
|
|
+// RandomNumberHolder.RandomWbsTreeContractclear();
|
|
|
+// executionTime.info("----数据保存结束----");
|
|
|
+// if (!result.isSuccess()) {
|
|
|
+// return R.fail(result.getMsg());
|
|
|
+// }
|
|
|
+// executionTime.info("----数据合并前----");
|
|
|
+// List<String> errorPKeyIds = new ArrayList<>();
|
|
|
+// //单个pdf加载
|
|
|
+// tableInfoList = (List<TableInfo>) result.getData();
|
|
|
+// if (tableInfoList != null) {
|
|
|
+// String finalSingnType = singnType;
|
|
|
+// tableInfoList.parallelStream().forEach(tableInfo -> {
|
|
|
+// R bussPdfInfo = null;
|
|
|
+// try {
|
|
|
+// if(finalSingnType.equals("1") && tableInfo.getProjectId().equals("1630011899725201410") && (tableInfo.getIsTypePrivatePid().equals("1559714325173080065") || tableInfo.getIsTypePrivatePid().equals("1559479719236702210") )){
|
|
|
+// System.out.println("12312312");
|
|
|
+// }else{
|
|
|
+// bussPdfInfo = excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// e.printStackTrace();
|
|
|
+// }
|
|
|
+// if (bussPdfInfo!=null && (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200)) {
|
|
|
+// //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
|
|
|
+// errorPKeyIds.add(tableInfo.getPkeyId());
|
|
|
+// }
|
|
|
+// });
|
|
|
+// }
|
|
|
+// //检查当前节点下所有的未隐藏的表单日期是否填写完整
|
|
|
+// WbsTreeContract contract = wbsTreeContractService.getById(Long.parseLong(nodeId));
|
|
|
+// if(contract!=null){
|
|
|
+// wbsTreeContractService.checkNodeAllDate(contract);
|
|
|
+// }
|
|
|
+// executionTime.info("----数据保存完毕 ----");
|
|
|
+// //发生异常后直接返回,不进行合并
|
|
|
+// if (errorPKeyIds.size() > 0) {
|
|
|
+// List<AppWbsTreeContractVO> errorTabs = new LinkedList<>();
|
|
|
+// for (AppWbsTreeContractVO appWbsTreeContractVO : tableAll) {
|
|
|
+// if (errorPKeyIds.contains(appWbsTreeContractVO.getPKeyId().toString())) {
|
|
|
+// errorTabs.add(appWbsTreeContractVO);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (errorTabs.size() > 0) {
|
|
|
+// List<String> names = errorTabs.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
|
|
|
+// return R.fail("以下的表在生成pdf文件时发生了异常【" + StringUtils.join(names, "、") + "】");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// executionTime.info("----数据合并前 ----");
|
|
|
+// //合并pdf加载
|
|
|
+// excelTabService.getBussPdfs(nodeId, classify, contractId, projectId);
|
|
|
+// executionTime.info("---PDF合并耗时---");
|
|
|
+// //更新缓存
|
|
|
+// informationQueryClient.delAsyncWbsTree(contractId);
|
|
|
+// executionTime.info("缓存删除耗时");
|
|
|
+// executionTime.brief();
|
|
|
+// return R.data(result.getMsg());
|
|
|
+// }
|
|
|
@PostMapping("/save_buss_data")
|
|
|
@ApiOperationSupport(order = 13)
|
|
|
@ApiOperation(value = "填报页面数据保存", notes = "填报页面数据保存")
|
|
|
public R saveBussData2(@Valid @RequestBody JSONObject dataInfo) throws Exception {
|
|
|
-
|
|
|
- ExecutionTime executionTime = new ExecutionTime();
|
|
|
- executionTime.info("----计划开始----");
|
|
|
- JSONArray dataArray = new JSONArray();
|
|
|
+ JSONArray dataArray;
|
|
|
if (dataInfo.containsKey("dataInfo")) { //节点保存
|
|
|
JSONObject jsonObject = dataInfo.getJSONObject("dataInfo");
|
|
|
dataArray = jsonObject.getJSONArray("orderList");
|
|
|
} else { //单个保存
|
|
|
+ dataArray = new JSONArray();
|
|
|
dataArray.add(dataInfo);
|
|
|
}
|
|
|
-
|
|
|
- String singnType ="2";
|
|
|
- if(dataInfo.containsKey("signType")){
|
|
|
- singnType=dataInfo.getString("signType");
|
|
|
- } else {
|
|
|
- singnType = "";
|
|
|
- }
|
|
|
-
|
|
|
- // dataInfo.getJSONObject("dataInfo").getJSONArray("orderList");
|
|
|
-
|
|
|
JSONObject tableInfo1 = dataArray.getJSONObject(0);
|
|
|
String nodeId = tableInfo1.getString("nodeId");
|
|
|
String contractId = tableInfo1.getString("contractId");
|
|
|
String projectId = tableInfo1.getString("projectId");
|
|
|
String classify = tableInfo1.getString("classify");
|
|
|
-
|
|
|
- executionTime.info("----组装开始----");
|
|
|
- /*全加载,或者可以优化成依赖加载*/
|
|
|
- List<AppWbsTreeContractVO> tableAll = new ArrayList<>();
|
|
|
- List<TableInfo> tableInfoList = this.excelTabService.getTableInfoList(dataArray);
|
|
|
- executionTime.info("----组装完成----");
|
|
|
- try {
|
|
|
- Long pKeyId = Long.parseLong(tableInfoList.get(0).getPkeyId());
|
|
|
- String sql = "SELECT node_name from m_wbs_tree_contract where p_key_id=" + pKeyId;
|
|
|
- String nodeName = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
- HashMap<Long, String> map = new HashMap<>();
|
|
|
- map.put(pKeyId, nodeName);
|
|
|
- RandomNumberHolder.setRandomNumber(map);
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- //公式填充
|
|
|
- executionTime.info("----公式填充执行----");
|
|
|
- this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeId), ExecuteType.INSPECTION);
|
|
|
- RandomNumberHolder.RandomNumberclear();
|
|
|
- assert tableInfoList != null;
|
|
|
- if (tableInfoList.size() == 0) {
|
|
|
- R.success("数据未发生变化");
|
|
|
- }
|
|
|
- executionTime.info("----公式填充执行完毕----");
|
|
|
- //保存数据到数据库
|
|
|
- R<Object> result = this.excelTabService.saveOrUpdateInfo(tableInfoList,singnType);
|
|
|
- RandomNumberHolder.RandomTemplateTypeclear();
|
|
|
- RandomNumberHolder.RandomWbsTreeContractclear();
|
|
|
- executionTime.info("----数据保存结束----");
|
|
|
- if (!result.isSuccess()) {
|
|
|
- return R.fail(result.getMsg());
|
|
|
+ boolean b = DistributedRedisLock.acquire("save_pdf:" + nodeId + "-" + classify, 180);
|
|
|
+ if (!b) {
|
|
|
+ return R.fail("正在保存中,请稍后!");
|
|
|
}
|
|
|
- executionTime.info("----数据合并前----");
|
|
|
- List<String> errorPKeyIds = new ArrayList<>();
|
|
|
- //单个pdf加载
|
|
|
- tableInfoList = (List<TableInfo>) result.getData();
|
|
|
- if (tableInfoList != null) {
|
|
|
- String finalSingnType = singnType;
|
|
|
- tableInfoList.parallelStream().forEach(tableInfo -> {
|
|
|
- R bussPdfInfo = null;
|
|
|
+ HttpServletRequest request = WebUtil.getRequest();
|
|
|
+ try {
|
|
|
+ // 异步执行任务并设置超时
|
|
|
+ return CompletableFuture.supplyAsync(() -> {
|
|
|
try {
|
|
|
- if(finalSingnType.equals("1") && tableInfo.getProjectId().equals("1630011899725201410") && (tableInfo.getIsTypePrivatePid().equals("1559714325173080065") || tableInfo.getIsTypePrivatePid().equals("1559479719236702210") )){
|
|
|
- System.out.println("12312312");
|
|
|
- }else{
|
|
|
- bussPdfInfo = excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
|
|
|
+ // 手动设置请求上下文
|
|
|
+ RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
|
|
|
+ String singnType = "2";
|
|
|
+ if (dataInfo.containsKey("signType")) {
|
|
|
+ singnType = dataInfo.getString("signType");
|
|
|
+ } else {
|
|
|
+ singnType = "";
|
|
|
+ }
|
|
|
+ /*全加载,或者可以优化成依赖加载*/
|
|
|
+ List<AppWbsTreeContractVO> tableAll = new ArrayList<>();
|
|
|
+ List<TableInfo> tableInfoList = this.excelTabService.getTableInfoList(dataArray);
|
|
|
+ Long pKeyId = Long.parseLong(tableInfoList.get(0).getPkeyId());
|
|
|
+ String sql = "SELECT node_name from m_wbs_tree_contract where p_key_id=" + pKeyId;
|
|
|
+ String nodeName = jdbcTemplate.queryForObject(sql, String.class);
|
|
|
+ HashMap<Long, String> map = new HashMap<>();
|
|
|
+ map.put(pKeyId, nodeName);
|
|
|
+ RandomNumberHolder.setRandomNumber(map);
|
|
|
+ //公式填充
|
|
|
+ this.excelTabService.formulaFillData(tableInfoList, Long.parseLong(nodeId), ExecuteType.INSPECTION);
|
|
|
+ RandomNumberHolder.RandomNumberclear();
|
|
|
+ if (tableInfoList.isEmpty()) {
|
|
|
+ R.success("数据未发生变化");
|
|
|
}
|
|
|
+ //保存数据到数据库
|
|
|
+ R<Object> result = this.excelTabService.saveOrUpdateInfo(tableInfoList, singnType);
|
|
|
+ RandomNumberHolder.RandomTemplateTypeclear();
|
|
|
+ RandomNumberHolder.RandomWbsTreeContractclear();
|
|
|
+ if (!result.isSuccess()) {
|
|
|
+ return R.fail(result.getMsg());
|
|
|
+ }
|
|
|
+ List<String> errorPKeyIds = new ArrayList<>();
|
|
|
+ //单个pdf加载
|
|
|
+ tableInfoList = (List<TableInfo>) result.getData();
|
|
|
+ if (tableInfoList != null) {
|
|
|
+ String finalSingnType = singnType;
|
|
|
+ tableInfoList.parallelStream().forEach(tableInfo -> {
|
|
|
+ R bussPdfInfo = null;
|
|
|
+ try {
|
|
|
+ if (finalSingnType.equals("1") && tableInfo.getProjectId().equals("1630011899725201410") && (tableInfo.getIsTypePrivatePid().equals("1559714325173080065") || tableInfo.getIsTypePrivatePid().equals("1559479719236702210"))) {
|
|
|
+ System.out.println("12312312");
|
|
|
+ } else {
|
|
|
+ bussPdfInfo = excelTabService.getBussPdfInfo(Long.parseLong(tableInfo.getPkeyId()));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (bussPdfInfo != null && (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200)) {
|
|
|
+ //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
|
|
|
+ errorPKeyIds.add(tableInfo.getPkeyId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //检查当前节点下所有的未隐藏的表单日期是否填写完整
|
|
|
+ WbsTreeContract contract = wbsTreeContractService.getById(Long.parseLong(nodeId));
|
|
|
+ if (contract != null) {
|
|
|
+ wbsTreeContractService.checkNodeAllDate(contract);
|
|
|
+ }
|
|
|
+ //发生异常后直接返回,不进行合并
|
|
|
+ if (errorPKeyIds.size() > 0) {
|
|
|
+ List<AppWbsTreeContractVO> errorTabs = new LinkedList<>();
|
|
|
+ for (AppWbsTreeContractVO appWbsTreeContractVO : tableAll) {
|
|
|
+ if (errorPKeyIds.contains(appWbsTreeContractVO.getPKeyId().toString())) {
|
|
|
+ errorTabs.add(appWbsTreeContractVO);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (errorTabs.size() > 0) {
|
|
|
+ List<String> names = errorTabs.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
|
|
|
+ return R.fail("以下的表在生成pdf文件时发生了异常【" + StringUtils.join(names, "、") + "】");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //合并pdf加载
|
|
|
+ excelTabService.getBussPdfs(nodeId, classify, contractId, projectId);
|
|
|
+ //更新缓存
|
|
|
+ informationQueryClient.delAsyncWbsTree(contractId);
|
|
|
+ return R.data(result.getMsg());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ return R.fail("保存失败!");
|
|
|
+ } finally {
|
|
|
+ DistributedRedisLock.release("save_pdf:" + nodeId + "-" + classify);
|
|
|
+ // 清理请求上下文
|
|
|
+ RequestContextHolder.resetRequestAttributes();
|
|
|
}
|
|
|
- if (bussPdfInfo!=null && (ObjectUtil.isEmpty(bussPdfInfo) || bussPdfInfo.getCode() != 200)) {
|
|
|
- //如果返回的单张pdfUrl为空,那么表示发生异常,返回异常信息
|
|
|
- errorPKeyIds.add(tableInfo.getPkeyId());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- //检查当前节点下所有的未隐藏的表单日期是否填写完整
|
|
|
- WbsTreeContract contract = wbsTreeContractService.getById(Long.parseLong(nodeId));
|
|
|
- if(contract!=null){
|
|
|
- wbsTreeContractService.checkNodeAllDate(contract);
|
|
|
- }
|
|
|
- executionTime.info("----数据保存完毕 ----");
|
|
|
- //发生异常后直接返回,不进行合并
|
|
|
- if (errorPKeyIds.size() > 0) {
|
|
|
- List<AppWbsTreeContractVO> errorTabs = new LinkedList<>();
|
|
|
- for (AppWbsTreeContractVO appWbsTreeContractVO : tableAll) {
|
|
|
- if (errorPKeyIds.contains(appWbsTreeContractVO.getPKeyId().toString())) {
|
|
|
- errorTabs.add(appWbsTreeContractVO);
|
|
|
- }
|
|
|
- }
|
|
|
- if (errorTabs.size() > 0) {
|
|
|
- List<String> names = errorTabs.stream().map(WbsTreeContract::getNodeName).collect(Collectors.toList());
|
|
|
- return R.fail("以下的表在生成pdf文件时发生了异常【" + StringUtils.join(names, "、") + "】");
|
|
|
- }
|
|
|
+ }).get(30L, TimeUnit.SECONDS);
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 超时或其他异常
|
|
|
+ return R.fail("保存超时,系统还在保存中,请耐心等待");
|
|
|
}
|
|
|
- executionTime.info("----数据合并前 ----");
|
|
|
- //合并pdf加载
|
|
|
- excelTabService.getBussPdfs(nodeId, classify, contractId, projectId);
|
|
|
- executionTime.info("---PDF合并耗时---");
|
|
|
- //更新缓存
|
|
|
- informationQueryClient.delAsyncWbsTree(contractId);
|
|
|
- executionTime.info("缓存删除耗时");
|
|
|
- executionTime.brief();
|
|
|
- return R.data(result.getMsg());
|
|
|
}
|
|
|
|
|
|
/*并发加载表单数据*/
|