|
@@ -12,6 +12,8 @@ import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
|
|
|
import com.itextpdf.io.font.FontProgram;
|
|
|
import com.itextpdf.io.font.FontProgramFactory;
|
|
|
import com.itextpdf.layout.font.FontProvider;
|
|
|
+import com.spire.xls.ExcelPicture;
|
|
|
+import com.spire.xls.ExcelVersion;
|
|
|
import com.spire.xls.Workbook;
|
|
|
import com.spire.xls.Worksheet;
|
|
|
import io.swagger.annotations.*;
|
|
@@ -24,6 +26,7 @@ import org.jsoup.nodes.Element;
|
|
|
import org.jsoup.select.Elements;
|
|
|
import org.springblade.business.feign.FileUtilsClient;
|
|
|
import org.springblade.business.feign.InformationQueryClient;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
import org.springblade.common.utils.MathUtil;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.boot.ctrl.BladeController;
|
|
@@ -38,7 +41,6 @@ import org.springblade.manager.entity.*;
|
|
|
import org.springblade.manager.mapper.WbsTreePrivateMapper;
|
|
|
import org.springblade.manager.service.*;
|
|
|
import org.springblade.manager.unit.FileUtils;
|
|
|
-import org.springblade.manager.unit.HtmlToPdf;
|
|
|
import org.springblade.manager.vo.*;
|
|
|
import org.springblade.manager.wrapper.ExcelTabWrapper;
|
|
|
import org.springblade.resource.feign.CommonFileClient;
|
|
@@ -51,7 +53,9 @@ import org.springblade.core.mp.support.Query;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.imageio.ImageIO;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileNotFoundException;
|
|
@@ -427,8 +431,6 @@ public class ExcelTabController extends BladeController {
|
|
|
FileUtil.copy(file_in,file_out);
|
|
|
updateWrapper.set("html_url",thmlUrl);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
// 匹配关联
|
|
|
File file1 = ResourceUtil.getFile(thmlUrl);
|
|
|
String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
@@ -487,6 +489,15 @@ public class ExcelTabController extends BladeController {
|
|
|
File writefile = new File(thmlUrl);
|
|
|
FileUtil.writeToFile(writefile, doc.html(), Boolean.parseBoolean("UTF-8"));
|
|
|
wbsTreePrivateService.update(updateWrapper);
|
|
|
+
|
|
|
+ //日志表单关联解决
|
|
|
+ if(aPrivate.getWbsType().equals("4")){
|
|
|
+ WbsTreePrivate wbsTreeCon = wbsTreePrivateService.getBaseMapper().selectOne(Wrappers.<WbsTreePrivate>query().lambda()
|
|
|
+ .eq(WbsTreePrivate::getId, aPrivate.getParentId()).eq(WbsTreePrivate::getWbsType,"4").eq(WbsTreePrivate::getProjectId,aPrivate.getProjectId()));
|
|
|
+ wbsTreeCon.setExcelId(aPrivate.getPKeyId());
|
|
|
+ wbsTreePrivateService.saveOrUpdate(wbsTreeCon);
|
|
|
+ }
|
|
|
+
|
|
|
//关联项目下所有的合同段
|
|
|
aPrivate.setHtmlUrl(thmlUrl);
|
|
|
wbsTreeContractService.updateAllNodeTabById(aPrivate);
|
|
@@ -562,6 +573,8 @@ public class ExcelTabController extends BladeController {
|
|
|
return R.data(table+"");
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
*保存用户填报数据接口
|
|
|
*/
|
|
@@ -591,26 +604,32 @@ public class ExcelTabController extends BladeController {
|
|
|
// 去掉
|
|
|
dataInfo2.remove("contractId");
|
|
|
dataInfo2.remove("pkeyId");
|
|
|
+ dataInfo2.remove("p_key_id");
|
|
|
dataInfo2.remove("projectId");
|
|
|
dataInfo2.remove("classify");
|
|
|
+ dataInfo2.remove("pickerKey");
|
|
|
+ dataInfo2.remove("id");
|
|
|
+ dataInfo2.remove("");
|
|
|
|
|
|
// 计算数据
|
|
|
Map<String,String> dataMap = new HashMap<>();
|
|
|
for(String k:dataInfo2.keySet()){
|
|
|
- String key = k.split("__")[0];
|
|
|
- if(dataMap.containsKey(key)){
|
|
|
- dataMap.put(key,dataMap.get(key)+","+k);
|
|
|
- }else{
|
|
|
- dataMap.put(key,k);
|
|
|
+ if(k.indexOf("__")>=0){
|
|
|
+ String key = k.split("__")[0];
|
|
|
+ if(dataMap.containsKey(key)){
|
|
|
+ dataMap.put(key,dataMap.get(key)+","+k);
|
|
|
+ }else{
|
|
|
+ dataMap.put(key,k);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Map<String,String> dataMap2 = new HashMap<>();
|
|
|
- dataMap2.put("p_key_id",pkeyId);
|
|
|
+
|
|
|
|
|
|
// 字段组合
|
|
|
for(String k:dataMap.keySet()){
|
|
|
- if(dataMap.get(k).indexOf(",")>=0){
|
|
|
+ if(dataMap.get(k).indexOf(",")>=0 && dataMap.get(k).indexOf("000Z")<0){
|
|
|
String [] ziduan= dataMap.get(k).split(",");
|
|
|
String temp = "";
|
|
|
for(int i = 0; i < ziduan.length - 1; i++) {
|
|
@@ -639,12 +658,16 @@ public class ExcelTabController extends BladeController {
|
|
|
}
|
|
|
dataMap2.put(k,lastStr);
|
|
|
}else{
|
|
|
- if(!(dataInfo2.getString(dataMap.get(k))).equals("")) {
|
|
|
- dataMap2.put(k, dataInfo2.getString(dataMap.get(k))+"__"+dataMap.get(k).split("__")[1]);
|
|
|
+ String dataVal = dataInfo2.getString(dataMap.get(k));
|
|
|
+ if(!dataVal.equals("") || !dataVal.equals("[]") ) {
|
|
|
+ System.out.println(k+"__"+dataMap.get(k));
|
|
|
+ dataMap2.put(k, dataVal+"__"+dataMap.get(k).split("__")[1]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ dataMap2.put("p_key_id",pkeyId);
|
|
|
+
|
|
|
WbsTreeContract wbsTreeContract = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
|
|
|
.eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
if(wbsTreeContract == null){
|
|
@@ -692,7 +715,7 @@ public class ExcelTabController extends BladeController {
|
|
|
wbsTreeContractService.update(updateWrapper);
|
|
|
|
|
|
jdbcTemplate.execute(sqlInfo);
|
|
|
- this.getBussPdfInfo(Long.parseLong(pkeyId));
|
|
|
+ // this.getBussPdfInfo(Long.parseLong(pkeyId));
|
|
|
}
|
|
|
return R.success("1");
|
|
|
}
|
|
@@ -1134,49 +1157,46 @@ public class ExcelTabController extends BladeController {
|
|
|
}
|
|
|
Map<String, Object> mysqlData = dataIn.get(0);
|
|
|
|
|
|
+ //
|
|
|
+ for(String key:mysqlData.keySet()) {
|
|
|
+ String tabVal = mysqlData.get(key) + "";
|
|
|
+ // 时间段处理
|
|
|
+ if (StringUtils.isNotEmpty(tabVal) && !tabVal.equals("null")) {
|
|
|
+ if (tabVal.indexOf("T") >= 0 && tabVal.indexOf(".000Z]") >= 0) {
|
|
|
+ String tabData[] = tabVal.split("__");
|
|
|
+ if (reData.containsKey("pickerKey")) {
|
|
|
+ String pickerKey = reData.get("pickerKey") + "," + tabData[1];
|
|
|
+ reData.put("pickerKey", pickerKey);
|
|
|
+ } else {
|
|
|
+ reData.put("pickerKey", key + "__" + tabData[1]);
|
|
|
+ }
|
|
|
|
|
|
- File file1 = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
- String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
- // 样式集合
|
|
|
- Document doc = Jsoup.parse(htmlString);
|
|
|
- // 解析 style
|
|
|
- Map<String ,String > styleMap = getHtmlStyle(doc);
|
|
|
- //解析
|
|
|
- Element table = doc.select("table").first();
|
|
|
- Elements trs = table.select("tr");
|
|
|
- for(int i = 0 ;i <=trs.size()-1 ;i++) {
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
- for (int j = 0; j < tds.size(); j++) {
|
|
|
- Element data = tds.get(j);
|
|
|
- if(data.html().indexOf("keyname")>=0){
|
|
|
- String keyData = data.children().get(0).attr("keyname");
|
|
|
- String[] key = keyData.split("__");
|
|
|
- String myData = mysqlData.get(key[0])+"";
|
|
|
- System.out.println(myData);
|
|
|
- if(StringUtils.isNotEmpty(myData)&& !myData.equals("null")){
|
|
|
- if(myData.indexOf(",")>=0 && data.html().indexOf("el-date-picker")<0){
|
|
|
- String [] dataVal = myData.split(",");
|
|
|
- for(String val:dataVal){
|
|
|
- if(key[1].equals(val.split("__")[1])){
|
|
|
- reData.put(keyData,val.split("__")[0]);
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(key[1].equals(myData.split("__")[1])) {
|
|
|
- if(data.html().indexOf("el-date-picker")>=0 && reData.containsKey("pickerKey")){
|
|
|
- String pickerKey = reData.get("pickerKey")+","+keyData;
|
|
|
- reData.put("pickerKey",pickerKey);
|
|
|
- }else{
|
|
|
- reData.put("pickerKey",keyData);
|
|
|
- }
|
|
|
- reData.put(keyData, myData.split("__")[0]);
|
|
|
- }
|
|
|
- }
|
|
|
+ String sql = tabData[0];
|
|
|
+ sql = sql.replaceAll("\\[", "['");
|
|
|
+ sql = sql.replaceAll("]", "\']");
|
|
|
+ sql = sql.replaceAll("000Z,", "000Z\',");
|
|
|
+ sql = sql.replaceAll(", 20", ", \'20");
|
|
|
+ reData.put(key + "__" + tabData[1], sql);
|
|
|
+ } else if (tabVal.indexOf("T") >= 0 && tabVal.indexOf(".000Z") >= 0) { //时间
|
|
|
+
|
|
|
+ String tabData[] = tabVal.split("__");
|
|
|
+ reData.put(key + "__" + tabData[1], tabData[0]);
|
|
|
+
|
|
|
+ } else if (tabVal.indexOf(",") >= 0) {
|
|
|
+ String mysql[] = tabVal.split(",");
|
|
|
+ for (String data : mysql) {
|
|
|
+ String tabData[] = data.split("__");
|
|
|
+ reData.put(key + "__" + tabData[1], tabData[0]);
|
|
|
}
|
|
|
+ } else if(tabVal.indexOf("__")>=0){
|
|
|
+ String tabData[] = tabVal.split("__");
|
|
|
+ reData.put(key + "__" + tabData[1], tabData[0]);
|
|
|
+ }else{
|
|
|
+ reData.put(key, tabVal);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
return R.data(reData);
|
|
|
}
|
|
|
|
|
@@ -1187,7 +1207,7 @@ public class ExcelTabController extends BladeController {
|
|
|
@ApiImplicitParams(value = {
|
|
|
@ApiImplicitParam(name = "pkeyId", value = "pkeyId", required = true)
|
|
|
})
|
|
|
- public R getBussPdfInfo(Long pkeyId) throws IOException {
|
|
|
+ public R getBussPdfInfo(Long pkeyId) throws Exception {
|
|
|
|
|
|
WbsTreeContract wbsTreeContract = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
|
|
|
.eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
@@ -1199,81 +1219,80 @@ public class ExcelTabController extends BladeController {
|
|
|
return R.fail("请关联清表!");
|
|
|
}
|
|
|
|
|
|
- String tabName = wbsTreeContract.getInitTableName();
|
|
|
- String isExitSql = " select * from information_schema.TABLES where TABLE_NAME='"+tabName+"'";
|
|
|
- List<Map<String, Object>> tablist = jdbcTemplate.queryForList(isExitSql);
|
|
|
-
|
|
|
- Document doc = null;
|
|
|
- //
|
|
|
- if(tablist!=null && tablist.size()>=1){
|
|
|
+ String pdfPath="/Users/hongchuangyanfa/Desktop/pdf//"+pkeyId+".pdf";
|
|
|
+ File tabpdf = ResourceUtil.getFile(pdfPath);
|
|
|
+ if(tabpdf.exists()){
|
|
|
+ tabpdf.delete();
|
|
|
+ }
|
|
|
|
|
|
- String querySql = "select * from "+wbsTreeContract.getInitTableName()+" where p_key_id="+pkeyId ;
|
|
|
- List<Map<String, Object>> dataIn = jdbcTemplate.queryForList(querySql);
|
|
|
+ // 获取清表信息
|
|
|
+ ExcelTab excelTab = excelTabService.getById(wbsTreeContract.getExcelId());
|
|
|
|
|
|
- if(dataIn!=null && dataIn.size()>=1){
|
|
|
+ Map<String, Object> DataInfo = (Map<String, Object>) getBussDataInfo(pkeyId).getData();
|
|
|
|
|
|
+ // 获取excel流 和 html流
|
|
|
+ Workbook wb = new Workbook();
|
|
|
+ wb.loadFromMHtml(CommonUtil.getOSSInputStream(excelTab.getFileUrl()));
|
|
|
+ //获取工作表
|
|
|
+ Worksheet sheet = wb.getWorksheets().get(0);
|
|
|
|
|
|
- Map<String, Object> mysqlData = dataIn.get(0);
|
|
|
- File file1 = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
- String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
- // 样式集合
|
|
|
- doc = Jsoup.parse(htmlString);
|
|
|
- //解析
|
|
|
- Element table = doc.select("table").first();
|
|
|
- Elements trs = table.select("tr");
|
|
|
- for(int i = 0 ;i <=trs.size()-1 ;i++) {
|
|
|
- Element tr = trs.get(i);
|
|
|
- Elements tds = tr.select("td");
|
|
|
- for (int j = 0; j < tds.size(); j++) {
|
|
|
- Element data = tds.get(j);
|
|
|
- if(data.html().indexOf("keyname")>=0){
|
|
|
- String keyData = data.children().get(0).attr("keyname");
|
|
|
- String[] key = keyData.split("__");
|
|
|
- String myData = mysqlData.get(key[0])+"";
|
|
|
- System.out.println(myData);
|
|
|
- if(StringUtils.isNotEmpty(myData)&& !myData.equals("null")){
|
|
|
- if(myData.indexOf(",")>=0&&data.html().indexOf("el-date-picker")<0){
|
|
|
- String [] dataVal = myData.split(",");
|
|
|
- for(String val:dataVal){
|
|
|
- if(key[1].equals(val.split("__")[1])){
|
|
|
- data.empty().append(val.split("__")[0]);
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(key[1].equals(myData.split("__")[1])) {
|
|
|
- if(myData.indexOf(".000Z")>=0&&myData.indexOf("T")>=0){
|
|
|
- String dataStr[] = myData.split("T")[0].split("-");
|
|
|
- String dataVal = StringUtil.format("{}年{}月{}日", new Object[]{dataStr[0], dataStr[1], Integer.parseInt(dataStr[2])+1});
|
|
|
- data.empty().append(dataVal);
|
|
|
+ if (DataInfo != null && DataInfo.size() >= 1) {
|
|
|
+ File htmlFile = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
+ String htmlString = IoUtil.readToString(new FileInputStream(htmlFile));
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+ Elements trs = table.select("tr");
|
|
|
+ for(String val : DataInfo.keySet()){
|
|
|
+ if(val.indexOf("__")>=0){
|
|
|
+ String DataVal[] = val.split("__");
|
|
|
+ String[] xy = DataVal[1].split("_");
|
|
|
+ Element data = trs.get(Integer.parseInt(xy[0])).select("td").get(Integer.parseInt(xy[1]));
|
|
|
+ if(data.html().indexOf("x1")>=0&&data.html().indexOf("y1")>=0){
|
|
|
+ int x1 = Integer.parseInt(data.children().get(0).attr("x1"));
|
|
|
+ if(x1==0){
|
|
|
+ x1=1;
|
|
|
+ }
|
|
|
+ int y1 = Integer.parseInt(data.children().get(0).attr("y1"));
|
|
|
+ String myData = DataInfo.get(val)+"";
|
|
|
+ if(myData.indexOf("T")>=0 && myData.indexOf("-")>=0){
|
|
|
+ if(myData.indexOf(",")>=0 && myData.indexOf("]")>=0){
|
|
|
+ myData = myData.replace("[","").replace("]","");
|
|
|
+ String[] dataVal = myData.split(",");
|
|
|
+ String Start_dataStr[] = dataVal[0].split("T")[0].split("-");
|
|
|
+ String StartDate = StringUtil.format("{}年{}月{}日", new Object[]{Start_dataStr[0], Start_dataStr[1], Integer.parseInt(Start_dataStr[2])+1});
|
|
|
+
|
|
|
+ String end_dataStr[] = dataVal[1].split("T")[0].split("-");
|
|
|
+ String endDate = StringUtil.format("{}年{}月{}日", new Object[]{end_dataStr[0], end_dataStr[1], Integer.parseInt(end_dataStr[2])+1});
|
|
|
+
|
|
|
+ if(StartDate.equals(endDate)){
|
|
|
+ myData = StartDate;
|
|
|
}else{
|
|
|
- data.empty().append(myData.split("__")[0]);
|
|
|
+ myData = StartDate +"-" +endDate;
|
|
|
}
|
|
|
+ }else {
|
|
|
+ String dataStr[] = myData.split("T")[0].split("-");
|
|
|
+ myData = StringUtil.format("{}年{}月{}日", new Object[]{dataStr[0], dataStr[1], Integer.parseInt(dataStr[2])+1});
|
|
|
}
|
|
|
}
|
|
|
+ https://bladex-test-info.oss-cn-chengdu.aliyuncs.com//upload/20220819/b53cb6700db369381e3b03d7737bcdec.jpg__16_1
|
|
|
+ if(myData.indexOf("https")>=0 && myData.indexOf("aliyuncs")>=0){
|
|
|
+ System.out.println(myData);
|
|
|
+
|
|
|
+ BufferedImage image = ImageIO.read(CommonUtil.getOSSInputStream(myData) );
|
|
|
+ ExcelPicture pic = sheet.getPictures().add(y1, x1,image);
|
|
|
+
|
|
|
+ sheet.getCellRange(y1,x1).getStyle().setShrinkToFit(true);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ sheet.getCellRange(y1,x1).setText(myData);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }else {
|
|
|
- File file1 = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
- String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
- // 样式集合
|
|
|
- doc = Jsoup.parse(htmlString);
|
|
|
- }
|
|
|
- }else{
|
|
|
- File file1 = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
- String htmlString = IoUtil.readToString(new FileInputStream(file1));
|
|
|
- // 样式集合
|
|
|
- doc = Jsoup.parse(htmlString);
|
|
|
- }
|
|
|
|
|
|
- String pdfPath="/Users/hongchuangyanfa/Desktop/pdf//"+pkeyId+".pdf";
|
|
|
- File tabpdf = ResourceUtil.getFile(pdfPath);
|
|
|
- if(tabpdf.exists()){
|
|
|
- tabpdf.delete();
|
|
|
- }
|
|
|
+ sheet.saveToPdf(pdfPath);
|
|
|
|
|
|
- HtmlToPdf.tomPdf(doc,pdfPath);
|
|
|
BladeFile bladeFile = newIOSSClient.uploadFile(pkeyId + ".pdf", pdfPath);
|
|
|
//
|
|
|
TableFile tableFile1 = tableFileService.getBaseMapper().selectOne(Wrappers.<TableFile>query().lambda()
|
|
@@ -1297,7 +1316,7 @@ public class ExcelTabController extends BladeController {
|
|
|
List<TableFile> tableFileList = tableFileService.getBaseMapper().selectList(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId).eq(TableFile::getIsDeleted,0));
|
|
|
tableFileList.sort(Comparator.comparing(TableFile::getType));
|
|
|
|
|
|
- //
|
|
|
+
|
|
|
List<String> dataListPdf = tableFileList.stream().filter(tableFile -> tableFile.getDomainPdfUrl()!=null).map(TableFile::getDomainPdfUrl).collect(Collectors.toList());
|
|
|
|
|
|
String pdfPath2 = "/Users/hongchuangyanfa/Desktop/pdf//"+pkeyId+"_2.pdf";
|
|
@@ -1310,7 +1329,7 @@ public class ExcelTabController extends BladeController {
|
|
|
updateWrapper.in("p_key_id",pkeyId);
|
|
|
updateWrapper.set("pdf_url",bladeFile2.getLink());
|
|
|
wbsTreeContractService.update(updateWrapper);
|
|
|
-
|
|
|
+ wb.dispose();
|
|
|
return R.data(bladeFile2.getLink());
|
|
|
}
|
|
|
|