|
@@ -0,0 +1,371 @@
|
|
|
+package org.springblade.manager.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
|
|
+import com.spire.xls.ExcelPicture;
|
|
|
+import com.spire.xls.Workbook;
|
|
|
+import com.spire.xls.Worksheet;
|
|
|
+import io.swagger.annotations.*;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import lombok.SneakyThrows;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import org.jsoup.Jsoup;
|
|
|
+import org.jsoup.nodes.Document;
|
|
|
+import org.jsoup.nodes.Element;
|
|
|
+import org.jsoup.select.Elements;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.core.boot.ctrl.BladeController;
|
|
|
+import org.springblade.core.oss.model.BladeFile;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.*;
|
|
|
+import org.springblade.manager.entity.*;
|
|
|
+import org.springblade.manager.service.*;
|
|
|
+import org.springblade.manager.unit.FileUtils;
|
|
|
+import org.springblade.resource.feign.CommonFileClient;
|
|
|
+import org.springblade.resource.feign.IOSSClient;
|
|
|
+import org.springblade.resource.feign.NewIOSSClient;
|
|
|
+import org.springblade.resource.vo.NewBladeFile;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * 首件
|
|
|
+ *
|
|
|
+ * @author BladeX
|
|
|
+ * @since 2022-05-18
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@AllArgsConstructor
|
|
|
+@RequestMapping("/first")
|
|
|
+@Api(value = "首件基础数据表", tags = "首件基础数据表接口")
|
|
|
+public class FirstController extends BladeController {
|
|
|
+
|
|
|
+ // 元素信息表-
|
|
|
+ private final IWbsTreeContractService wbsTreeContractService;
|
|
|
+ private final IOSSClient iossClient;
|
|
|
+ private final CommonFileClient commonFileClient;
|
|
|
+ // 表单附件信息
|
|
|
+ private final ITableFileService tableFileService;
|
|
|
+
|
|
|
+ private final NewIOSSClient newIOSSClient;
|
|
|
+
|
|
|
+ // excel 基本信息表
|
|
|
+ private final IExcelTabService excelTabService;
|
|
|
+
|
|
|
+ private final JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 首件表单获取 html页面
|
|
|
+ */
|
|
|
+ @GetMapping("/get-first-excel-html")
|
|
|
+ @ApiOperationSupport(order = 1)
|
|
|
+ @ApiOperation(value = "首件表单获取html页面", notes = "首件表单获取html页面")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "projectId", value = "projectId", required = true)
|
|
|
+ })
|
|
|
+ public R getFirstExcelHtml(Long projectId) throws IOException, InterruptedException {
|
|
|
+
|
|
|
+ WbsTreeContract wbsTreeContract = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
|
|
|
+ .eq(WbsTreeContract::getProjectId,projectId).eq(WbsTreeContract::getTableType,"111"));
|
|
|
+ if(wbsTreeContract ==null ){
|
|
|
+ return R.fail("该数据下无此节点!");
|
|
|
+ }
|
|
|
+ if(wbsTreeContract .getHtmlUrl()==null){
|
|
|
+ return R.fail("请上传清表!");
|
|
|
+ }
|
|
|
+
|
|
|
+ File file1 = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
|
|
|
+ FileInputStream fileInputStream = new FileInputStream(file1);
|
|
|
+ String htmlString = IoUtil.readToString(fileInputStream);
|
|
|
+ // 解析 style
|
|
|
+ Document doc = Jsoup.parse(htmlString);
|
|
|
+ Element table = doc.select("table").first();
|
|
|
+ doc.select("Col").remove();
|
|
|
+ fileInputStream.close();
|
|
|
+ JSONObject reData = new JSONObject();
|
|
|
+ reData.put("id",wbsTreeContract.getPKeyId());
|
|
|
+ reData.put("data",table);
|
|
|
+ return R.data(table+"");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传文件
|
|
|
+ *
|
|
|
+ * @param file 文件
|
|
|
+ * @return ObjectStat
|
|
|
+ */
|
|
|
+ @SneakyThrows
|
|
|
+ @PostMapping("/add-first-buss-file")
|
|
|
+ @ApiOperationSupport(order = 2)
|
|
|
+ @ApiOperation(value = "首件-附件上传", notes = "首件-附件上传")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "file", value = "file", required = true),
|
|
|
+ @ApiImplicitParam(name = "pkeyId", value = "pkeyId", required = true)
|
|
|
+ })
|
|
|
+ public R addBussFile(@RequestParam("file") MultipartFile file, Long pkeyId) {
|
|
|
+
|
|
|
+ // 直接删除以前记录
|
|
|
+ tableFileService.getBaseMapper().delete(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId,pkeyId).eq(TableFile::getType,3));
|
|
|
+
|
|
|
+ R<BladeFile> bladeFile = iossClient.addFileInfo(file);
|
|
|
+ BladeFile bladeFile1 = bladeFile.getData();
|
|
|
+ TableFile tableFile = new TableFile();
|
|
|
+ String fileExtension = FileUtil.getFileExtension(bladeFile1.getName());
|
|
|
+ tableFile.setTabId(pkeyId+"");
|
|
|
+ tableFile.setName(file.getOriginalFilename());
|
|
|
+ tableFile.setType(3); // 表示首件的附件
|
|
|
+ tableFile.setDomainUrl(bladeFile1.getLink());
|
|
|
+ tableFile.setIsDeleted(0);
|
|
|
+ tableFile.setExtension(fileExtension);
|
|
|
+
|
|
|
+ NewBladeFile newBladeFile = new NewBladeFile();
|
|
|
+ if(fileExtension.contains("xlsx")){
|
|
|
+ newBladeFile = this.commonFileClient.excelToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if(fileExtension.contains("xls")){
|
|
|
+ newBladeFile = this.commonFileClient.excelToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if(fileExtension.contains("docx")){
|
|
|
+ newBladeFile = this.commonFileClient.wordToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if(fileExtension.contains("png") || file.getOriginalFilename().contains("jpg")){
|
|
|
+ newBladeFile = this.commonFileClient.pngOrJpgToPdf(file);
|
|
|
+ tableFile.setDomainPdfUrl(newBladeFile.getPdfUrl());
|
|
|
+ } else if(fileExtension.contains("pdf")){
|
|
|
+ tableFile.setDomainPdfUrl(bladeFile1.getLink());
|
|
|
+ }
|
|
|
+ tableFile.setStatus("finished");
|
|
|
+ tableFileService.saveOrUpdate(tableFile);
|
|
|
+ return R.data(tableFile.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @GetMapping("/get-first-buss-pdfInfo")
|
|
|
+ @ApiOperationSupport(order = 3)
|
|
|
+ @ApiOperation(value = "首件-pdf预览", notes = "首件-单pdf预览")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "pkeyId", value = "pkeyId", required = true),
|
|
|
+ @ApiImplicitParam(name = "liunkIds", value = "liunkIds", required = true)
|
|
|
+ })
|
|
|
+ public R getBussPdfInfo(Long pkeyId,String liunkIds) throws Exception {
|
|
|
+
|
|
|
+ WbsTreeContract wbsTreeContract = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
|
|
|
+ .eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
+
|
|
|
+ if(wbsTreeContract ==null ){
|
|
|
+ return R.fail("该数据下无此节点!");
|
|
|
+ }
|
|
|
+ if(wbsTreeContract.getHtmlUrl()==null){
|
|
|
+ return R.fail("请关联清表!");
|
|
|
+ }
|
|
|
+
|
|
|
+ String pdfPath="/Users/hongchuangyanfa/Desktop/pdf//"+pkeyId+".pdf";
|
|
|
+ File tabpdf = ResourceUtil.getFile(pdfPath);
|
|
|
+ if(tabpdf.exists()){
|
|
|
+ tabpdf.delete();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取清表信息
|
|
|
+ ExcelTab excelTab = excelTabService.getById(wbsTreeContract.getExcelId());
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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{
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sheet.saveToPdf(pdfPath);
|
|
|
+
|
|
|
+ BladeFile bladeFile = newIOSSClient.uploadFile(pkeyId + ".pdf", pdfPath);
|
|
|
+ //
|
|
|
+ TableFile tableFile1 = tableFileService.getBaseMapper().selectOne(Wrappers.<TableFile>query().lambda()
|
|
|
+ .eq(TableFile::getTabId, pkeyId).eq(TableFile::getType,1));
|
|
|
+ if(tableFile1!=null){
|
|
|
+ tableFile1.setDomainPdfUrl(bladeFile.getLink());
|
|
|
+ tableFileService.saveOrUpdate(tableFile1);
|
|
|
+ }else{
|
|
|
+ TableFile tableFile = new TableFile();
|
|
|
+ String fileExtension = FileUtil.getFileExtension(wbsTreeContract.getFullName()+".pdf");
|
|
|
+ tableFile.setTabId(pkeyId+"");
|
|
|
+ tableFile.setName(wbsTreeContract.getFullName()+".pdf");
|
|
|
+ tableFile.setType(1);
|
|
|
+ tableFile.setDomainUrl(bladeFile.getLink());
|
|
|
+ tableFile.setIsDeleted(0);
|
|
|
+ tableFile.setExtension(fileExtension);
|
|
|
+ tableFile.setDomainPdfUrl(bladeFile.getLink());
|
|
|
+ tableFileService.saveOrUpdate(tableFile);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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";
|
|
|
+
|
|
|
+ FileUtils.mergePdfPublicMethods(dataListPdf,pdfPath2);
|
|
|
+
|
|
|
+ BladeFile bladeFile2 = newIOSSClient.uploadFile(pkeyId + "2.pdf", pdfPath2);
|
|
|
+
|
|
|
+ UpdateWrapper<WbsTreeContract> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.in("p_key_id",pkeyId);
|
|
|
+ updateWrapper.set("pdf_url",bladeFile2.getLink());
|
|
|
+ wbsTreeContractService.update(updateWrapper);
|
|
|
+ wb.dispose();
|
|
|
+ return R.data(bladeFile2.getLink());
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/get-first-buss-dataInfo")
|
|
|
+ @ApiOperationSupport(order = 4)
|
|
|
+ @ApiOperation(value = "获取首件用户保存数据", notes = "获取首件用户保存数据")
|
|
|
+ @ApiImplicitParams(value = {
|
|
|
+ @ApiImplicitParam(name = "pkeyId", value = "pkeyId", required = true)
|
|
|
+ })
|
|
|
+ public R getBussDataInfo(Long pkeyId) throws FileNotFoundException {
|
|
|
+
|
|
|
+ Map<String, Object> reData = new HashMap<>();
|
|
|
+
|
|
|
+ WbsTreeContract wbsTreeContract = wbsTreeContractService.getBaseMapper().selectOne(Wrappers.<WbsTreeContract>query().lambda()
|
|
|
+ .eq(WbsTreeContract::getPKeyId, pkeyId));
|
|
|
+
|
|
|
+ if(wbsTreeContract ==null ){
|
|
|
+ return R.data(reData);
|
|
|
+ }
|
|
|
+ if(wbsTreeContract.getHtmlUrl()==null){
|
|
|
+ return R.data(reData);
|
|
|
+ }
|
|
|
+ //表单是否存储在
|
|
|
+ String tabName = wbsTreeContract.getInitTableName();
|
|
|
+ String isExitSql = " select * from information_schema.TABLES where TABLE_NAME='"+tabName+"'";
|
|
|
+ List<Map<String, Object>> tablist = jdbcTemplate.queryForList(isExitSql);
|
|
|
+ if(tablist==null || tablist.size()<=0){
|
|
|
+ return R.fail("无实体表对应");
|
|
|
+ }
|
|
|
+
|
|
|
+ String querySql = "select * from "+wbsTreeContract.getInitTableName()+" where p_key_id="+pkeyId ;
|
|
|
+ List<Map<String, Object>> dataIn = jdbcTemplate.queryForList(querySql);
|
|
|
+
|
|
|
+ if(dataIn==null||dataIn.size()<=0){
|
|
|
+ return R.data(reData);
|
|
|
+ }
|
|
|
+ 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]);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|