Bläddra i källkod

试验公式颜色bug

liuyc 2 år sedan
förälder
incheckning
16852cd488

+ 12 - 9
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -1240,7 +1240,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             tabPdf.delete();
         }
 
-        // 获取清表信息
+        //获取清表信息
         ExcelTab excelTab = this.getById(wbsTreeContract.getExcelId());
 
         if (excelTab == null) {
@@ -1249,7 +1249,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
 
         Map<String, Object> DataInfo = (Map<String, Object>) getBussDataInfo(pkeyId, 0).getData();
 
-        // 获取excel流 和 html流
+        //获取excel流 和 html流
         InputStream exceInp = CommonUtil.getOSSInputStream(excelTab.getFileUrl());
         org.apache.poi.ss.usermodel.Workbook workbook = WorkbookFactory.create(exceInp);
 
@@ -1257,7 +1257,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         Sheet sheet = workbook.getSheetAt(0);
         sheet.setForceFormulaRecalculation(true);
 
-        // 标题添加
+        //标题添加
         ProjectInfo projectInfo = projectInfoService.getById(wbsTreeContract.getProjectId());
 
         int all = sheet.getRow(0).getLastCellNum();
@@ -1299,7 +1299,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             }
         }
 
-        // 数据不为空 &&
+        //数据不为空
         if (StringUtils.isNotEmpty(wbsTreeContract.getHtmlUrl())) {
             File htmlFile = ResourceUtil.getFile(wbsTreeContract.getHtmlUrl());
             if (htmlFile.exists()) {
@@ -1488,11 +1488,12 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         FileUtils.setExcelScaleToPdf(excelPath, pdfPath);
         BladeFile bladeFile = newIOSSClient.uploadFile(pkeyId + ".pdf", pdfPath);
 
+        //附件
         TableFile tableFile1 = tableFileService.getBaseMapper().selectList(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId + "").eq(TableFile::getType, 1)).stream().findAny().orElse(null);
         if (tableFile1 != null) {
             /*tableFile1.setDomainPdfUrl(bladeFile.getLink());
             tableFileService.saveOrUpdate(tableFile1);*/
-            tableFileService.update(Wrappers.<TableFile>lambdaUpdate().set(TableFile::getDomainPdfUrl,bladeFile.getLink()).eq(TableFile::getId,tableFile1.getId()));
+            tableFileService.update(Wrappers.<TableFile>lambdaUpdate().set(TableFile::getDomainPdfUrl, bladeFile.getLink()).eq(TableFile::getId, tableFile1.getId()));
         } else {
             TableFile tableFile = new TableFile();
             String fileExtension = FileUtil.getFileExtension(wbsTreeContract.getFullName() + ".pdf");
@@ -2299,12 +2300,14 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         FileOutputStream outputStream = new FileOutputStream(excelPath);
         workbook.write(outputStream);
         FileUtils.setExcelScaleToPdf(excelPath, 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).eq(TableFile::getTrialRecordId, id));
+
+        //附件
+        TableFile tableFile1 = tableFileService.getBaseMapper().selectList(Wrappers.<TableFile>query().lambda().eq(TableFile::getTabId, pkeyId + "").eq(TableFile::getType, 1)).stream().findAny().orElse(null);
         if (tableFile1 != null) {
-            tableFile1.setDomainPdfUrl(bladeFile.getLink());
-            tableFileService.saveOrUpdate(tableFile1);
+            /*tableFile1.setDomainPdfUrl(bladeFile.getLink());
+            tableFileService.saveOrUpdate(tableFile1);*/
+            tableFileService.update(Wrappers.<TableFile>lambdaUpdate().set(TableFile::getDomainPdfUrl, bladeFile.getLink()).eq(TableFile::getId, tableFile1.getId()));
         } else {
             TableFile tableFile = new TableFile();
             String fileExtension = FileUtil.getFileExtension(wbsTreePrivate.getFullName() + ".pdf");

+ 65 - 63
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreePrivateServiceImpl.java

@@ -894,26 +894,26 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
 
     @Override
     public R<String> syncPrivateProjectFormula(Long projectId, Long pKeyId) {
-        if(projectId!=null&&pKeyId!=null){
+        if (projectId != null && pKeyId != null) {
             ProjectInfo projectInfo = projectInfoMapper.selectById(projectId);
-            ProjectInfo sourceProject=jdbcTemplate.queryForObject("select a.* from m_project_info a join m_wbs_tree_private b on a.id=b.project_id where b.p_key_id="+projectInfo.getReferenceWbsTemplateId()+" limit 1",new BeanPropertyRowMapper<>(ProjectInfo.class));
+            ProjectInfo sourceProject = jdbcTemplate.queryForObject("select a.* from m_project_info a join m_wbs_tree_private b on a.id=b.project_id where b.p_key_id=" + projectInfo.getReferenceWbsTemplateId() + " limit 1", new BeanPropertyRowMapper<>(ProjectInfo.class));
             /*只需要同步私有引用就可以了*/
-            if("private".equals(projectInfo.getReferenceWbsTemplateType())&&sourceProject!=null){
+            if ("private".equals(projectInfo.getReferenceWbsTemplateType()) && sourceProject != null) {
                 WbsTreePrivate selectNodeNow = baseMapper.selectOne(Wrappers.<WbsTreePrivate>lambdaQuery().eq(WbsTreePrivate::getPKeyId, pKeyId).eq(WbsTreePrivate::getStatus, 1));
                 if (selectNodeNow == null) {
                     throw new ServiceException("未获取到当前选择同步的节点信息,请联系管理员");
                 }
-                List<ElementFormulaMapping> insertList=new ArrayList<>();
-                List<Formula> insertFormulaList=new ArrayList<>();
-                List<Formula> updateFormulaList=new ArrayList<>();
+                List<ElementFormulaMapping> insertList = new ArrayList<>();
+                List<Formula> insertFormulaList = new ArrayList<>();
+                List<Formula> updateFormulaList = new ArrayList<>();
                 /*同步公共部分*/
-                global(sourceProject.getId(),projectInfo,insertList,insertFormulaList,updateFormulaList);
+                global(sourceProject.getId(), projectInfo, insertList, insertFormulaList, updateFormulaList);
                 /*同步节点部分,查找模版的叶子节点,查找目标叶子节点,id一样的是关联数据  */
-                part(sourceProject.getId(),projectInfo,insertList,insertFormulaList,updateFormulaList);
+                part(sourceProject.getId(), projectInfo, insertList, insertFormulaList, updateFormulaList);
                 /*保存记录*/
-                int n=saveAll(insertList,insertFormulaList,updateFormulaList);
-                if(n>0){
-                    R.success("成功同步"+n+"条公式");
+                int n = saveAll(insertList, insertFormulaList, updateFormulaList);
+                if (n > 0) {
+                    R.success("成功同步" + n + "条公式");
                 }
             }
             return R.success("引用公有模版无需同步");
@@ -921,73 +921,75 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
         return R.fail("同步异常,请联系管理员");
     }
 
-    private int saveAll(List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList){
-        int n=0;
-        if(!insertList.isEmpty()) {
-            this.elementFormulaMappingService.saveBatch(insertList,1000);
+    private int saveAll(List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList) {
+        int n = 0;
+        if (!insertList.isEmpty()) {
+            this.elementFormulaMappingService.saveBatch(insertList, 1000);
         }
-        if(!insertFormulaList.isEmpty()) {
-            this.formulaService.saveBatch(insertFormulaList,1000);
-            n+=insertList.size();
+        if (!insertFormulaList.isEmpty()) {
+            this.formulaService.saveBatch(insertFormulaList, 1000);
+            n += insertList.size();
         }
-        if(!updateFormulaList.isEmpty()) {
-            this.formulaService.updateBatchById(updateFormulaList,1000);
-            n+=updateFormulaList.size();
+        if (!updateFormulaList.isEmpty()) {
+            this.formulaService.updateBatchById(updateFormulaList, 1000);
+            n += updateFormulaList.size();
         }
         return n;
     }
 
-    private void global(Long srcProjectId,ProjectInfo distProject,List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList){
-        this.check( srcProjectId, distProject, insertList,  insertFormulaList,  updateFormulaList,FormulaBean.PRO_GLOBAL);
+    private void global(Long srcProjectId, ProjectInfo distProject, List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList) {
+        this.check(srcProjectId, distProject, insertList, insertFormulaList, updateFormulaList, FormulaBean.PRO_GLOBAL);
     }
-    private void part(Long srcProjectId,ProjectInfo distProject,List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList){
-        this.check( srcProjectId, distProject, insertList,  insertFormulaList,  updateFormulaList,FormulaBean.PRO_PART);
+
+    private void part(Long srcProjectId, ProjectInfo distProject, List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList) {
+        this.check(srcProjectId, distProject, insertList, insertFormulaList, updateFormulaList, FormulaBean.PRO_PART);
     }
-    private void check(Long srcProjectId,ProjectInfo distProject,List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList,int model){
-        Map<String,ElementFormulaMapping> efmListScopeMap=new HashMap<>();
-        Map<String,ElementFormulaMapping> sourceEfmListScopeMap=new HashMap<>();
-        Map<Long,Formula> formulaScopeMap = new HashMap<>();
-        Map<Long,Formula> sourceFormulaScopeMap = new HashMap<>();
-        List<ElementFormulaMapping> efmListScope=this.elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getProjectId,distProject.getId()).eq(ElementFormulaMapping::getScope, model));
-        if(!efmListScope.isEmpty()){
+
+    private void check(Long srcProjectId, ProjectInfo distProject, List<ElementFormulaMapping> insertList, List<Formula> insertFormulaList, List<Formula> updateFormulaList, int model) {
+        Map<String, ElementFormulaMapping> efmListScopeMap = new HashMap<>();
+        Map<String, ElementFormulaMapping> sourceEfmListScopeMap = new HashMap<>();
+        Map<Long, Formula> formulaScopeMap = new HashMap<>();
+        Map<Long, Formula> sourceFormulaScopeMap = new HashMap<>();
+        List<ElementFormulaMapping> efmListScope = this.elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getProjectId, distProject.getId()).eq(ElementFormulaMapping::getScope, model));
+        if (!efmListScope.isEmpty()) {
             formulaScopeMap = this.formulaService.listByIds(efmListScope.stream().map(ElementFormulaMapping::getFormulaId).collect(Collectors.toList())).stream().collect(Collectors.toMap(Formula::getId, f -> f));
         }
-        List<ElementFormulaMapping>sourceEfmListScope=this.elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getProjectId,srcProjectId).eq(ElementFormulaMapping::getScope, model));
-        if(!sourceEfmListScope.isEmpty()){
+        List<ElementFormulaMapping> sourceEfmListScope = this.elementFormulaMappingService.list(Wrappers.<ElementFormulaMapping>lambdaQuery().eq(ElementFormulaMapping::getProjectId, srcProjectId).eq(ElementFormulaMapping::getScope, model));
+        if (!sourceEfmListScope.isEmpty()) {
             sourceFormulaScopeMap = this.formulaService.listByIds(sourceEfmListScope.stream().map(ElementFormulaMapping::getFormulaId).collect(Collectors.toList())).stream().collect(Collectors.toMap(Formula::getId, f -> f));
         }
-        if(FormulaBean.PRO_PART.equals(model)) {
+        if (FormulaBean.PRO_PART.equals(model)) {
             efmListScopeMap = efmListScope.stream().collect(Collectors.toMap(e -> e.getElementId() + "" + e.getNodeId(), t -> t));
             sourceEfmListScopeMap = sourceEfmListScope.stream().collect(Collectors.toMap(e -> e.getElementId() + "" + e.getNodeId(), t -> t));
-        }else{
+        } else {
             efmListScopeMap = efmListScope.stream().collect(Collectors.toMap(e -> e.getElementId().toString(), t -> t));
             sourceEfmListScopeMap = sourceEfmListScope.stream().collect(Collectors.toMap(e -> e.getElementId().toString(), t -> t));
         }
-        String[] exclude= new String[]{"id"};
+        String[] exclude = new String[]{"id"};
         Map<String, ElementFormulaMapping> finalEfmListScopeMap = efmListScopeMap;
         Map<Long, Formula> finalSourceFormulaScopeMap = sourceFormulaScopeMap;
         Map<Long, Formula> finalFormulaScopeMap = formulaScopeMap;
-        sourceEfmListScopeMap.forEach((k, v)->{
-            if(!finalEfmListScopeMap.containsKey(k)){
+        sourceEfmListScopeMap.forEach((k, v) -> {
+            if (!finalEfmListScopeMap.containsKey(k)) {
                 /*不存在*/
                 ElementFormulaMapping target = new ElementFormulaMapping();
-                BeanUtils.copyProperties(v,target,exclude);
+                BeanUtils.copyProperties(v, target, exclude);
                 target.setWbsId(distProject.getReferenceWbsTemplateId());
                 target.setProjectId(distProject.getId());
                 insertList.add(target);
-                Formula sf= finalSourceFormulaScopeMap.get(v.getFormulaId());
-                Formula target2= new Formula();
-                BeanUtils.copyProperties(sf,target2);
-                Long id=SnowFlakeUtil.getId();
+                Formula sf = finalSourceFormulaScopeMap.get(v.getFormulaId());
+                Formula target2 = new Formula();
+                BeanUtils.copyProperties(sf, target2);
+                Long id = SnowFlakeUtil.getId();
                 target.setFormulaId(id);
                 target2.setId(id);
                 insertFormulaList.add(target2);
-            }else{
+            } else {
                 /*存在则比较,有差异则覆盖*/
-                Formula sf= finalSourceFormulaScopeMap.get(v.getFormulaId());
-                Formula tf= finalFormulaScopeMap.get(finalEfmListScopeMap.get(k).getFormulaId());
-                if(!tf.getFormula().equals(sf.getFormula())){
-                    BeanUtils.copyProperties(sf,tf,exclude);
+                Formula sf = finalSourceFormulaScopeMap.get(v.getFormulaId());
+                Formula tf = finalFormulaScopeMap.get(finalEfmListScopeMap.get(k).getFormulaId());
+                if (!tf.getFormula().equals(sf.getFormula())) {
+                    BeanUtils.copyProperties(sf, tf, exclude);
                     updateFormulaList.add(tf);
                 }
 
@@ -1964,23 +1966,23 @@ public class WbsTreePrivateServiceImpl extends BaseServiceImpl<WbsTreePrivateMap
 
         //获取公式颜色
         String tabName = wbsTreePrivate.getInitTableName();
-        //字段查询 获取公式字段
-        String colKeys = "SELECT e_key from m_wbs_tree a ,m_wbs_form_element b WHERE a.init_table_name = '" + tabName + "' and a.id=b.f_id and b.id  in(SELECT element_id from m_formula c where c.is_deleted=0) ";
+        //字段查询获取公式字段
+        String colKeys = "SELECT e_key from m_table_info a ,m_wbs_form_element b WHERE a.tab_en_name = '" + tabName + "' and a.id=b.f_id and b.id  in(SELECT element_id from m_element_formula_mapping c where c.is_deleted=0) ";
         List<Map<String, Object>> maps = jdbcTemplate.queryForList(colKeys);
-        for (Map<String, Object> keys : maps) {
-            String key = keys.get("e_key") + "__";
-            Elements gsColor = doc.select("el-input[keyname~=^" + key + "]");
-            for (Element element : gsColor) {
-                //System.out.println(element.parent());
-                element.parent().attr("gscolor", "11");
-            }
-            Elements dateColor = doc.select("el-date-picker[keyname~=^" + key + "]");
-            for (Element element : dateColor) {
-                //System.out.println(element.parent());
-                element.parent().attr("gscolor", "11");
+        if (maps.size() > 0) {
+            for (Map<String, Object> keys : maps) {
+                String key = keys.get("e_key") + "__";
+                Elements gsColor = doc.select("el-input[keyname~=^" + key + "]");
+                for (Element element : gsColor) {
+                    element.parent().attr("gscolor", "11");
+                }
+
+                Elements dateColor = doc.select("el-date-picker[keyname~=^" + key + "]");
+                for (Element element : dateColor) {
+                    element.parent().attr("gscolor", "11");
+                }
             }
         }
-
         doc.select("Col").remove();
         fileInputStream.close();
         return R.data(table + "");