Explorar el Código

日志填报相关

huangjn hace 2 años
padre
commit
41a053f306

+ 4 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/ContractLog.java

@@ -58,6 +58,10 @@ public class ContractLog extends BaseEntity {
      */
     @ApiModelProperty("日志类型")
     private Integer wbsNodeType;
+
+    @ApiModelProperty("表格ID,指向wbs_tree_private表p_key_id")
+    private Long tableId;
+
     /**
      * 填报时间、施工时间
      */

+ 5 - 1
blade-service-api/blade-business-api/src/main/java/org/springblade/business/vo/SaveContractLogVO.java

@@ -24,6 +24,9 @@ public class SaveContractLogVO {
     @ApiModelProperty("日志填报的节点ID(唯一键)")
     private Long wbsNodeId;
 
+    @ApiModelProperty("表格ID,指向wbs_tree_private表p_key_id")
+    private Long tableId;
+
     @ApiModelProperty("填报的日志类型")
     private Integer wbsNodeType;
 
@@ -33,11 +36,12 @@ public class SaveContractLogVO {
     @ApiModelProperty("关联工序的ids")
     private List<JSONObject> correlationIds;
 
-    public SaveContractLogVO(Long businessId, String projectId, String contractId, Long wbsNodeId, Integer wbsNodeType, String recordTime, List<JSONObject> correlationIds){
+    public SaveContractLogVO(Long businessId, String projectId, String contractId, Long wbsNodeId, Long tableId, Integer wbsNodeType, String recordTime, List<JSONObject> correlationIds){
         this.dataId = businessId;
         this.projectId = Long.parseLong(projectId);
         this.contractId = Long.parseLong(contractId);
         this.wbsNodeId = wbsNodeId;
+        this.tableId = tableId;
         this.wbsNodeType = wbsNodeType;
         this.recordTime = recordTime;
         this.correlationIds = correlationIds;

+ 7 - 2
blade-service/blade-business/src/main/java/org/springblade/business/feignClient/ContractLogClientImpl.java

@@ -31,7 +31,9 @@ public class ContractLogClientImpl implements ContractLogClient {
 
     @Override
     public JSONObject queryContractLogByPrimaryKeyIdAndRecordTime(String nodePrimaryKeyId, String recordTime) {
-        ContractLog log = this.contractLogService.getOne(Wrappers.<ContractLog>lambdaQuery().eq(ContractLog::getWbsNodeId, nodePrimaryKeyId).eq(ContractLog::getRecordTime, recordTime));
+        ContractLog log = this.contractLogService.getOne(Wrappers.<ContractLog>lambdaQuery()
+                .eq(ContractLog::getWbsNodeId, nodePrimaryKeyId)
+                .eq(ContractLog::getRecordTime, recordTime).eq(ContractLog::getCreateUser, AuthUtil.getUserId()));
         return log != null ? JSONObject.parseObject(JSONObject.toJSONString(log)) : null;
     }
 
@@ -47,7 +49,10 @@ public class ContractLogClientImpl implements ContractLogClient {
         //复制数据
         BeanUtils.copyProperties(saveContractLogVO, contractLog);
 
-        if(contractLog.getId() != null){
+        //查询是否存在旧数据
+        JSONObject logJson = this.queryContractLogByPrimaryKeyIdAndRecordTime(saveContractLogVO.getWbsNodeId().toString(), saveContractLogVO.getRecordTime());
+
+        if(logJson != null){
             //主键不为空,说明是修改
             //修改只修改关联的工序ids
             if(saveContractLogVO.getCorrelationIds() != null && saveContractLogVO.getCorrelationIds().size() > 0){

+ 233 - 15
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -1712,12 +1712,18 @@ public class ExcelTabController extends BladeController {
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
 
         //获取对应的日志
-        JSONObject theLogJson = this.contractLogClient.queryContractLogById(theLogId);
+        JSONObject theLogJson;
+        if(StringUtils.isNotEmpty(theLogId)){
+            theLogJson = this.contractLogClient.queryContractLogById(theLogId);
+        } else {
+            theLogJson = this.contractLogClient.queryContractLogByPrimaryKeyIdAndRecordTime(nodePrimaryKeyId, recordTime);
+        }
+
         if(theLogJson != null){
+            theLogId = theLogJson.getString("id");
+
             //查询对应的html
-            WbsTreePrivate node = this.wbsTreePrivateService.getById(theLogJson.getString("wbsNodeId"));
-            //获取表格
-            WbsTreePrivate tableNode = this.wbsTreePrivateService.getById(node.getExcelId());
+            WbsTreePrivate tableNode = this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, theLogJson.getString("tableId")));
 
             if(tableNode == null){
                 return R.fail("该数据下无此节点!");
@@ -1727,20 +1733,152 @@ public class ExcelTabController extends BladeController {
                 return R.fail("请关联清表!");
             }
 
-            String pdfPath = file_path + "/pdf//" + theLogId + ".pdf";
-            File tabpdf = ResourceUtil.getFile(pdfPath);
-            if (tabpdf.exists()) {
-                tabpdf.delete();
-            }
-
             // 获取清表信息
             ExcelTab excelTab = excelTabService.getById(tableNode.getExcelId());
-
             if (excelTab == null) {
                 return R.fail("失败");
             }
 
+            //获取数据
+            List<Map<String, Object>> businessDataMapList = (List<Map<String, Object>>)this.getTheLogBusinessData(theLogId, nodePrimaryKeyId, recordTime).getData();
+            //PDF路径
+            List<String> pdfUrls = new ArrayList<>();
+
+            //处理数据
+            for(Map<String, Object> dataMap : businessDataMapList){
+                // 获取excel流 和 html流
+                Workbook wb = new Workbook();
+                wb.loadFromMHtml(CommonUtil.getOSSInputStream(excelTab.getFileUrl()));
+                //获取工作表
+                Worksheet sheet = wb.getWorksheets().get(0);
+
+                // 数据不为空 &&
+                if (StringUtils.isNotEmpty(tableNode.getHtmlUrl())) {
+                    File htmlFile = ResourceUtil.getFile(tableNode.getHtmlUrl());
+                    if (htmlFile.exists()) {
+                        String htmlString = IoUtil.readToString(new FileInputStream(htmlFile));
+                        Document doc = Jsoup.parse(htmlString);
+                        Element table = doc.select("table").first();
+                        Elements trs = table.select("tr");
+
+                        if (ObjectUtil.isNotEmpty(dataMap)) {
+                            for (String val : dataMap.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, y1;
+
+                                        if (data.html().indexOf("el-tooltip") >= 0) {
+                                            x1 = Integer.parseInt(data.children().get(0).children().get(0).attr("x1"));
+                                            y1 = Integer.parseInt(data.children().get(0).children().get(0).attr("y1"));
+                                        } else {
+                                            x1 = Integer.parseInt(data.children().get(0).attr("x1"));
+                                            y1 = Integer.parseInt(data.children().get(0).attr("y1"));
+                                        }
+                                        if (x1 == 0) {
+                                            x1 = 1;
+                                        }
+                                        String myData = dataMap.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});
+                                            }
+                                        }
+
+                                        if (myData.indexOf("https") >= 0 && myData.indexOf("aliyuncs") >= 0) {
+                                            Element element = trs.get(y1).select("td").get(x1);
+                                            String styles[] = element.attr("style").split(";");
+                                            int Height = 0;
+                                            for (String sty : styles) {
+                                                if (sty.indexOf("height:") >= 0) {
+                                                    Height = Integer.parseInt(sty.replace("height:", "").replace("px", ""));
+                                                }
+                                            }
+
+                                            BufferedImage image = ImageIO.read(CommonUtil.getOSSInputStream(myData));
+                                            ExcelPicture pic = sheet.getPictures().add(y1, x1, image);
+                                            pic.setHeight(Height);
+                                            sheet.getCellRange(y1, x1).getStyle().setShrinkToFit(true);
+
+                                        } else {
+                                            final CellRange cellRange = sheet.getCellRange(y1, x1);
+                                            cellRange.setText(myData);
+                                        }
+                                    }
+                                }
+                            }
+                        }
+
+                        // 组装电签设置
+                        QueryWrapper<TextdictInfo> queryWrapper = new QueryWrapper<>();
+                        queryWrapper.eq("type", 2);
+                        queryWrapper.eq("tab_id", tableNode.getPKeyId());
+
+                        final List<TextdictInfo> textdictInfos = textdictInfoService.getBaseMapper().selectList(queryWrapper);
+                        if (textdictInfos != null && !textdictInfos.isEmpty()) {
+                            textdictInfos.forEach(e -> {
+                                String key = e.getColKey();
+                                String keys[] = key.split("__");
+                                String[] trtd = keys[1].split("_");
+                                Element data = trs.get(Integer.parseInt(trtd[0])).select("td").get(Integer.parseInt(trtd[1]));
+                                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"));
+
+                                final CellRange cellRange = sheet.getCellRange(y1, x1);
+                                cellRange.setText(e.getId() + "");
+                                cellRange.getCellStyle().getFont().setColor(Color.white);
 
+                            });
+                        }
+                    }
+                }
+
+                Long fileName = SnowFlakeUtil.getId();
+                String onePdfPath = file_path + "/pdf//" + fileName + ".pdf";
+
+                sheet.saveToPdf(onePdfPath);
+
+                BladeFile bladeFile = newIOSSClient.uploadFile( fileName + ".pdf", onePdfPath);
+
+                pdfUrls.add(bladeFile.getLink());
+
+                wb.dispose();
+            }
+
+            if(pdfUrls.size() > 0){
+                String mergePdfPath = file_path + "/pdf//" + theLogId + ".pdf";
+                File oldMergePdf = ResourceUtil.getFile(mergePdfPath);
+                if (oldMergePdf.exists()) {
+                    oldMergePdf.delete();
+                }
+
+                FileUtils.mergePdfPublicMethods(pdfUrls, mergePdfPath);
+
+                BladeFile mergeFile = newIOSSClient.uploadFile(theLogId + new Date().getTime() + ".pdf", mergePdfPath);
+
+                return R.data(mergeFile.getLink());
+            }
 
         }
 
@@ -1748,15 +1886,95 @@ public class ExcelTabController extends BladeController {
     }
 
     @GetMapping("/get-the-log-business-data")
-    @ApiOperationSupport(order = 25)
+    @ApiOperationSupport(order = 26)
     @ApiOperation(value = "获取当前用户当前日期的填报记录")
     @ApiImplicitParam(name = "theLogId", value = "日志ID", required = true)
-    public R getTheLogBusinessData(String nodePrimaryKeyId, String recordTime) {
-        Map<String, Object> resultMap = new HashMap<>();
+    public R getTheLogBusinessData(String theLogId, String nodePrimaryKeyId, String recordTime) {
+        List<Map<String, Object>> resultMapList = new ArrayList<>();
         //获取对应的记录
+        JSONObject theLogJson;
+        if(StringUtils.isNotEmpty(theLogId)){
+            theLogJson = this.contractLogClient.queryContractLogById(theLogId);
+        } else {
+            theLogJson = this.contractLogClient.queryContractLogByPrimaryKeyIdAndRecordTime(nodePrimaryKeyId, recordTime);
+        }
+        if(theLogJson != null){
+            //查询对应的html
+            WbsTreePrivate tableNode = this.wbsTreePrivateService.getOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, theLogJson.getString("tableId")));
+
+            //检查实体表是否存在
+            String tabName = tableNode.getInitTableName();
+            String isExitSql = " select * from information_schema.TABLES where TABLE_NAME='" + tabName + "'";
+            List<Map<String, Object>> tabList = this.jdbcTemplate.queryForList(isExitSql);
+            if (tabList.size() <= 0) {
+                return R.fail("无实体表对应");
+            }
 
+            //查询数据
+            String querySql = "SELECT * FROM " + tabName + " WHERE group_id = " + theLogJson.get("dataId");
+            List<Map<String, Object>> businessDataMap = this.jdbcTemplate.queryForList(querySql);
 
-        return R.data(null);
+            if(businessDataMap.size() > 0){
+
+                for(Map<String, Object> mysqlData : businessDataMap){
+                    //数据结果
+                    Map<String, Object> reData = new HashMap<>();
+
+                    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") + "," + key + "__" + 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");
+                                sql = sql.replaceAll("'", "");
+                                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);
+                            }
+                        }
+                    }
+
+                    // 移除Id 和 p_key_id
+                    reData.remove("id");
+                    reData.remove("p_key_id");
+                    reData.remove("classify");
+                    reData.remove("contractId");
+                    reData.remove("pkeyId");
+                    reData.remove("projectId");
+
+                    resultMapList.add(reData);
+                }
+            }
+        }
+
+        return R.data(resultMapList);
     }
 
 }

+ 1 - 0
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -340,6 +340,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
 				tableInfoList.get(0).getProjectId(),
 				tableInfoList.get(0).getContractId(),
 				parentNode.getPKeyId(),
+				tableNode.getPKeyId(),
 				parentNode.getMajorDataType(),
 				recordTime,
 				linkTabIds