|
@@ -16,10 +16,10 @@ import io.swagger.annotations.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.SneakyThrows;
|
|
|
import org.apache.commons.codec.Charsets;
|
|
|
-import org.apache.commons.lang.ArrayUtils;
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
-import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
@@ -38,10 +38,13 @@ import org.springblade.core.mp.support.Query;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
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.manager.bean.TableInfo;
|
|
|
+import org.springblade.manager.dto.ExcelTabBatchUploadDTO;
|
|
|
+import org.springblade.manager.dto.ExcelTabFileDTO;
|
|
|
import org.springblade.manager.entity.*;
|
|
|
import org.springblade.manager.enums.ExecuteType;
|
|
|
import org.springblade.manager.mapper.ExcelTabMapper;
|
|
@@ -306,35 +309,35 @@ public class ExcelTabController extends BladeController {
|
|
|
sheet.saveToHtml(thmlUrl, options);
|
|
|
|
|
|
CellRange[] mergedCells = sheet.getMergedCells();
|
|
|
- Map<String,Map<String,Integer>> xyList = new HashMap<>();
|
|
|
- int j=0;
|
|
|
- for (int i=0;i<mergedCells.length;i++){
|
|
|
- Map<String,Integer> dataMap = new HashMap<>();
|
|
|
+ Map<String, Map<String, Integer>> xyList = new HashMap<>();
|
|
|
+ int j = 0;
|
|
|
+ for (int i = 0; i < mergedCells.length; i++) {
|
|
|
+ Map<String, Integer> dataMap = new HashMap<>();
|
|
|
CellRange mergedCell = mergedCells[i];
|
|
|
- j = j+1;
|
|
|
- mergedCell.getComment().getRichText().setText(j+"");
|
|
|
- mergedCell.setValue(j+"");
|
|
|
- dataMap.put("x1",mergedCell.getRow());
|
|
|
- dataMap.put("x2",mergedCell.getLastRow());
|
|
|
- dataMap.put("y1",mergedCell.getColumn());
|
|
|
- dataMap.put("y2",mergedCell.getLastColumn());
|
|
|
- xyList.put(j+"",dataMap);
|
|
|
+ j = j + 1;
|
|
|
+ mergedCell.getComment().getRichText().setText(j + "");
|
|
|
+ mergedCell.setValue(j + "");
|
|
|
+ dataMap.put("x1", mergedCell.getRow());
|
|
|
+ dataMap.put("x2", mergedCell.getLastRow());
|
|
|
+ dataMap.put("y1", mergedCell.getColumn());
|
|
|
+ dataMap.put("y2", mergedCell.getLastColumn());
|
|
|
+ xyList.put(j + "", dataMap);
|
|
|
}
|
|
|
|
|
|
CellRange[] mergedCells2 = sheet.getCells();
|
|
|
- for (int i=0;i<mergedCells2.length;i++){
|
|
|
+ for (int i = 0; i < mergedCells2.length; i++) {
|
|
|
CellRange mergedCell = mergedCells2[i];
|
|
|
String data = mergedCell.getComment().getRichText().getText();
|
|
|
- if(StringUtils.isEmpty(data)){
|
|
|
- j = j+1;
|
|
|
- mergedCell.getComment().getRichText().setText(j+"");
|
|
|
- mergedCell.setValue(j+"");
|
|
|
- Map<String,Integer> dataMap = new HashMap<>();
|
|
|
- dataMap.put("x1",mergedCell.getRow());
|
|
|
- dataMap.put("x2",mergedCell.getLastRow());
|
|
|
- dataMap.put("y1",mergedCell.getColumn());
|
|
|
- dataMap.put("y2",mergedCell.getLastColumn());
|
|
|
- xyList.put(j+"",dataMap);
|
|
|
+ if (StringUtils.isEmpty(data)) {
|
|
|
+ j = j + 1;
|
|
|
+ mergedCell.getComment().getRichText().setText(j + "");
|
|
|
+ mergedCell.setValue(j + "");
|
|
|
+ Map<String, Integer> dataMap = new HashMap<>();
|
|
|
+ dataMap.put("x1", mergedCell.getRow());
|
|
|
+ dataMap.put("x2", mergedCell.getLastRow());
|
|
|
+ dataMap.put("y1", mergedCell.getColumn());
|
|
|
+ dataMap.put("y2", mergedCell.getLastColumn());
|
|
|
+ xyList.put(j + "", dataMap);
|
|
|
}
|
|
|
}
|
|
|
sheet.saveToHtml(thmlUrl2, options);
|
|
@@ -354,22 +357,22 @@ public class ExcelTabController extends BladeController {
|
|
|
Element table2 = doc2.select("table").first();
|
|
|
Elements trs2 = table2.select("tr");
|
|
|
|
|
|
- for(int i=0;i<trs1.size();i++){
|
|
|
+ for (int i = 0; i < trs1.size(); i++) {
|
|
|
Elements td1 = trs1.get(i).select("td");
|
|
|
Elements td2 = trs2.get(i).select("td");
|
|
|
- for(int x=0;x<td1.size();x++){
|
|
|
+ for (int x = 0; x < td1.size(); x++) {
|
|
|
Element cell1 = td1.get(x);
|
|
|
Element cell2 = td2.get(x);
|
|
|
String html = cell2.html();
|
|
|
- if(html.indexOf("div")>=0){
|
|
|
- html=cell2.children().get(0).html();
|
|
|
+ if (html.indexOf("div") >= 0) {
|
|
|
+ html = cell2.children().get(0).html();
|
|
|
}
|
|
|
Map<String, Integer> xyMap = xyList.get(html);
|
|
|
- if(xyMap!=null){
|
|
|
- cell1.attr("x1",xyMap.get("x1")+"");
|
|
|
- cell1.attr("x2",xyMap.get("x2")+"");
|
|
|
- cell1.attr("y1",xyMap.get("y1")+"");
|
|
|
- cell1.attr("y2",xyMap.get("y2")+"");
|
|
|
+ if (xyMap != null) {
|
|
|
+ cell1.attr("x1", xyMap.get("x1") + "");
|
|
|
+ cell1.attr("x2", xyMap.get("x2") + "");
|
|
|
+ cell1.attr("y1", xyMap.get("y1") + "");
|
|
|
+ cell1.attr("y2", xyMap.get("y2") + "");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -383,7 +386,7 @@ public class ExcelTabController extends BladeController {
|
|
|
detail.setHtmlUrl(thmlUrl);
|
|
|
excelTabService.saveOrUpdate(detail);
|
|
|
|
|
|
- if(html2.exists()){
|
|
|
+ if (html2.exists()) {
|
|
|
html2.delete();
|
|
|
}
|
|
|
// 解析html
|
|
@@ -566,11 +569,11 @@ public class ExcelTabController extends BladeController {
|
|
|
//解析
|
|
|
Element table = doc.select("table").first();
|
|
|
Elements trs = table.select("tr");
|
|
|
- if(StringUtils.isNotEmpty(excelTab.getTabId())){
|
|
|
+ if (StringUtils.isNotEmpty(excelTab.getTabId())) {
|
|
|
updateWrapper.set("init_table_id", excelTab.getTabId());
|
|
|
org.springblade.manager.entity.TableInfo tableInfo = tableInfoService.getById(excelTab.getTabId());
|
|
|
updateWrapper.set("init_table_name", tableInfo.getTabEnName());
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
if (aPrivate.getInitTableId() == null) {
|
|
|
org.springblade.manager.entity.TableInfo tableInfo = tableInfoService.getOne(new LambdaQueryWrapper<org.springblade.manager.entity.TableInfo>()
|
|
|
.eq(org.springblade.manager.entity.TableInfo::getTabEnName, aPrivate.getInitTableName()));
|
|
@@ -670,12 +673,12 @@ public class ExcelTabController extends BladeController {
|
|
|
|
|
|
//关联项目下所有的合同段
|
|
|
// if (aPrivate.getType() != 10) {
|
|
|
- aPrivate.setHtmlUrl(thmlUrl);
|
|
|
+ aPrivate.setHtmlUrl(thmlUrl);
|
|
|
|
|
|
- //关联清表后 表单名和清表一样
|
|
|
- aPrivate.setNodeName(excelTab.getName());
|
|
|
- aPrivate.setFullName(excelTab.getName());
|
|
|
- wbsTreeContractService.updateAllNodeTabById(aPrivate);
|
|
|
+ //关联清表后 表单名和清表一样
|
|
|
+ aPrivate.setNodeName(excelTab.getName());
|
|
|
+ aPrivate.setFullName(excelTab.getName());
|
|
|
+ wbsTreeContractService.updateAllNodeTabById(aPrivate);
|
|
|
// }
|
|
|
return R.success("关联成功");
|
|
|
}
|
|
@@ -727,7 +730,7 @@ public class ExcelTabController extends BladeController {
|
|
|
//判断是否是水利水电表,水利水电项目名14,表名12 。 其他表都是18
|
|
|
Boolean isWater = false;
|
|
|
ExcelTab tab = excelTabMapper.getWaterByTableId(wbsTreeContract.getExcelId());
|
|
|
- if (tab != null){
|
|
|
+ if (tab != null) {
|
|
|
isWater = true;
|
|
|
}
|
|
|
|
|
@@ -742,11 +745,11 @@ public class ExcelTabController extends BladeController {
|
|
|
String style = data.attr("style");
|
|
|
if (style.indexOf("font-size") >= 0) {
|
|
|
int fontsize = Integer.parseInt(style.substring(style.indexOf("font-size:") + 10, style.indexOf(".0pt")));
|
|
|
- if (isWater){
|
|
|
+ if (isWater) {
|
|
|
if (StringUtils.isNotEmpty(data.text()) && fontsize >= 12) {
|
|
|
trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
if (StringUtils.isNotEmpty(data.text()) && fontsize >= 14) {
|
|
|
trs.get(i - 1).select("td").get(0).text(projectInfo.getProjectName());
|
|
|
}
|
|
@@ -1347,7 +1350,7 @@ public class ExcelTabController extends BladeController {
|
|
|
|
|
|
//对excel 的图片进行操作
|
|
|
ExcelTab exceltab = excelTabService.getById(excelId);
|
|
|
- if(exceltab!=null){
|
|
|
+ if (exceltab != null) {
|
|
|
// 获取excle 的数据
|
|
|
String fileUrl = exceltab.getFileUrl();
|
|
|
InputStream ossInputStream = CommonUtil.getOSSInputStream(fileUrl);
|
|
@@ -1355,15 +1358,15 @@ public class ExcelTabController extends BladeController {
|
|
|
wb.loadFromMHtml(ossInputStream);
|
|
|
Worksheet sheet = wb.getWorksheets().get(0);
|
|
|
PicturesCollection pictures = sheet.getPictures();
|
|
|
- if(pictures!=null && pictures.size()>=1){
|
|
|
- for (int i=0 ; i<pictures.size() ; i++){
|
|
|
+ if (pictures != null && pictures.size() >= 1) {
|
|
|
+ for (int i = 0; i < pictures.size(); i++) {
|
|
|
ExcelPicture pic = pictures.get(i);
|
|
|
int x = pic.getLeftColumn();
|
|
|
int y = pic.getBottomRow();
|
|
|
Elements select = doc.select("el-input[x1=" + x + "][y1=" + y + "]");
|
|
|
- System.out.println("xx=--"+x);
|
|
|
- System.out.println("yy=--"+y);
|
|
|
- if(select!=null && select.size()>=1){
|
|
|
+ System.out.println("xx=--" + x);
|
|
|
+ System.out.println("yy=--" + y);
|
|
|
+ if (select != null && select.size() >= 1) {
|
|
|
Element element = select.get(0);
|
|
|
Element elementP = element.parent();
|
|
|
element.remove();
|
|
@@ -3246,17 +3249,94 @@ public class ExcelTabController extends BladeController {
|
|
|
WbsTreeContract wbsInfo = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
|
|
|
.eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
|
|
|
- if(wbsInfo!=null){
|
|
|
+ if (wbsInfo != null) {
|
|
|
String tabName = wbsInfo.getInitTableName();
|
|
|
- if(StringUtils.isNotEmpty(tabName)){
|
|
|
- String delSql = "delete from "+tabName+" where p_key_id = " + pkeyId;
|
|
|
+ if (StringUtils.isNotEmpty(tabName)) {
|
|
|
+ String delSql = "delete from " + tabName + " where p_key_id = " + pkeyId;
|
|
|
jdbcTemplate.execute(delSql);
|
|
|
- }else{
|
|
|
- return R.fail("获取InitTableName失败!");
|
|
|
+ } else {
|
|
|
+ return R.fail("获取InitTableName失败!");
|
|
|
}
|
|
|
- }else{
|
|
|
- return R.fail("获取数据失败!");
|
|
|
+ } else {
|
|
|
+ return R.fail("获取数据失败!");
|
|
|
}
|
|
|
return R.data("成功!");
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/batchUploadExcelTab")
|
|
|
+ @ApiOperationSupport(order = 39)
|
|
|
+ @ApiOperation(value = "批量上传清表", notes = "传入ExcelTabBatchUploadDTO")
|
|
|
+ public R<Object> batchUploadExcelTab(@RequestBody ExcelTabBatchUploadDTO dto) throws IOException {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getId())) {
|
|
|
+ throw new ServiceException("获取节点信息失败");
|
|
|
+ }
|
|
|
+ if (ObjectUtil.isEmpty(dto.getFileList()) || dto.getFileList().size() <= 0) {
|
|
|
+ throw new ServiceException("未获取到需要上传的文件信息");
|
|
|
+ }
|
|
|
+ ExcelTab excelTabParentNode = excelTabService.getBaseMapper().selectById(dto.getId());
|
|
|
+ List<ExcelTab> excelTabs = excelTabService.getBaseMapper().selectList(Wrappers.<ExcelTab>lambdaQuery().select(ExcelTab::getSort).eq(ExcelTab::getParentId, excelTabParentNode.getId()));
|
|
|
+ Optional<Integer> maxSort = excelTabs.stream().map(ExcelTab::getSort).max(Integer::compare);
|
|
|
+ int maxValue = 1;
|
|
|
+ if (maxSort.isPresent()) {
|
|
|
+ maxValue = maxSort.get();
|
|
|
+ }
|
|
|
+ for (ExcelTabFileDTO fileDTO : dto.getFileList()) {
|
|
|
+ if (ObjectUtil.isEmpty(fileDTO.getFileName())) {
|
|
|
+ throw new ServiceException("文件名不能为空");
|
|
|
+ }
|
|
|
+ if (!this.isExcelFormat(fileDTO.getFileName())) {
|
|
|
+ throw new ServiceException("文件名后缀不是.xlsx或者.xls格式,请重新填写");
|
|
|
+ }
|
|
|
+ if (!this.isExcelFile(fileDTO.getFile())) {
|
|
|
+ throw new ServiceException("【" + fileDTO.getFileName() + "】文件不是excel格式文件,上传终止");
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ R<BladeFile> bladeFile = iossClient.addFileInfo(fileDTO.getFile());
|
|
|
+ if (ObjectUtil.isNotEmpty(bladeFile.getData())) {
|
|
|
+ //创建节点,并上传excel文件到节点上
|
|
|
+ ExcelTab excelTabNode = new ExcelTab();
|
|
|
+ excelTabNode.setId(SnowFlakeUtil.getId());
|
|
|
+ excelTabNode.setParentId(excelTabParentNode.getId());
|
|
|
+ excelTabNode.setFileType(excelTabParentNode.getFileType());
|
|
|
+ excelTabNode.setName(fileDTO.getFileName().split(".xls")[0]);
|
|
|
+ excelTabNode.setAlias(excelTabParentNode.getAlias() + "," + excelTabParentNode.getId());
|
|
|
+ excelTabNode.setFileUrl(bladeFile.getData().getLink());
|
|
|
+ excelTabNode.setExtension(fileDTO.getFileName());
|
|
|
+ excelTabNode.setCreateTime(new Date());
|
|
|
+ excelTabNode.setUpdateTime(new Date());
|
|
|
+ excelTabNode.setCreateUser(SecureUtil.getUserId());
|
|
|
+ excelTabNode.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ excelTabNode.setCreateDept(SecureUtil.getUser().getDeptId().contains(",") ? Long.parseLong(SecureUtil.getUser().getDeptId().split(",")[0]) : Long.parseLong(SecureUtil.getUser().getDeptId()));
|
|
|
+ excelTabNode.setStatus(1);
|
|
|
+ excelTabNode.setIsDeleted(0);
|
|
|
+ excelTabNode.setTabType(excelTabParentNode.getTabType());
|
|
|
+ excelTabNode.setTenantId(SecureUtil.getTenantId());
|
|
|
+ excelTabNode.setSort(maxValue++);
|
|
|
+ excelTabService.save(excelTabNode);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new ServiceException("【" + fileDTO.getFileName() + "】文件上传失败,上传终止" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.success("操作成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isExcelFormat(String filename) {
|
|
|
+ return filename.toLowerCase().endsWith(".xlsx") || filename.toLowerCase().endsWith(".xls");
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isExcelFile(MultipartFile file) throws IOException {
|
|
|
+ org.apache.poi.ss.usermodel.Workbook workbook = null;
|
|
|
+ try (InputStream inputStream = file.getInputStream()) {
|
|
|
+ workbook = WorkbookFactory.create(inputStream);
|
|
|
+ return ObjectUtil.isNotEmpty(workbook);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ } finally {
|
|
|
+ if (workbook != null) {
|
|
|
+ workbook.close();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|