Răsfoiți Sursa

同步功能-错误信息提示调整

LHB 2 luni în urmă
părinte
comite
ed869a555c

+ 1 - 3
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/entity/WbsTreeSynchronousRecord.java

@@ -33,9 +33,7 @@ public class WbsTreeSynchronousRecord {
      */
     private String projectName;
 
-    /**
-     * 同步范围1 (1-从后管同步,2-同步到合同段, 3-单表单同步,4-单表强制同步)
-     */
+
     @TableField("`range`")
     private Integer range;
     /**

+ 20 - 5
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousEViSaServiceImpl.java

@@ -1,16 +1,18 @@
 package org.springblade.manager.service.impl;
 
+import cn.hutool.core.date.DateTime;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import org.springblade.manager.entity.TextdictInfo;
 import org.springblade.manager.entity.WbsTreePrivate;
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
 import org.springblade.manager.mapper.TextdictInfoMapper;
 import org.springblade.manager.mapper.WbsTreePrivateMapper;
+import org.springblade.manager.mapper.WbsTreeSynchronousRecordMapper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.util.List;
-import java.util.stream.Collectors;
 
 /**
  * @author LHB
@@ -23,6 +25,8 @@ public class WbsSynchronousEViSaServiceImpl {
     //电签
     @Autowired
     private TextdictInfoMapper textdictInfoMapper;
+    @Autowired
+    private WbsTreeSynchronousRecordMapper synchronousRecordMapper;
 
     @Transactional(rollbackFor = Exception.class)
     public void updateTextDictInfo(Long projectId, List<Long> editPrivateIds, List<TextdictInfo> addData) {
@@ -35,19 +39,30 @@ public class WbsSynchronousEViSaServiceImpl {
     }
 
     @Transactional(rollbackFor = Exception.class)
-    public void updateSyncPrivateForm(String htmlUrl,List<Long> collect) {
+    public void updateSyncPrivateForm(String htmlUrl, List<Long> collect, Long id) {
         wbsTreePrivateMapper.update(null, Wrappers.<WbsTreePrivate>lambdaUpdate()
                 .set(WbsTreePrivate::getHtmlUrl, htmlUrl)
-                .in(WbsTreePrivate::getPKeyId,collect)
+                .in(WbsTreePrivate::getPKeyId, collect)
         );
+        synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                .set(WbsTreeSynchronousRecord::getStatus, 2)
+                .set(WbsTreeSynchronousRecord::getErrorMsg, null)
+                .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                .eq(WbsTreeSynchronousRecord::getId, id));
     }
+
     @Transactional(rollbackFor = Exception.class)
-    public void syncPrivateForceForm(WbsTreePrivate wbsTreePrivate, String nodeId) {
+    public void syncPrivateForceForm(WbsTreePrivate wbsTreePrivate, String nodeId, Long id) {
         wbsTreePrivateMapper.update(null, Wrappers.<WbsTreePrivate>lambdaUpdate()
                 .set(WbsTreePrivate::getExcelId, wbsTreePrivate.getExcelId())
                 .set(WbsTreePrivate::getInitTableName, wbsTreePrivate.getInitTableName())
                 .set(WbsTreePrivate::getHtmlUrl, wbsTreePrivate.getHtmlUrl())
-                .in(WbsTreePrivate::getPKeyId,nodeId)
+                .in(WbsTreePrivate::getPKeyId, nodeId)
         );
+        synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
+                .set(WbsTreeSynchronousRecord::getStatus, 2)
+                .set(WbsTreeSynchronousRecord::getErrorMsg, null)
+                .set(WbsTreeSynchronousRecord::getUpdateTime, DateTime.now())
+                .eq(WbsTreeSynchronousRecord::getId, id));
     }
 }

+ 29 - 31
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsSynchronousServiceImpl.java

@@ -78,7 +78,7 @@ public class WbsSynchronousServiceImpl {
         //
         try {
             Integer range = wbsTreeSynchronousRecord.getRange();
-            switch (range){
+            switch (range) {
                 case 1:
                     //同步项目
                     insertPrivateNode(wbsTreeSynchronousRecord);
@@ -96,19 +96,7 @@ public class WbsSynchronousServiceImpl {
                     syncPrivateForceForm(wbsTreeSynchronousRecord);
                     break;
                 default:
-                    break;
-            }
-
-            if (range == 1) {
-
-            } else if (range == 2) {
-
-            } else if (range == 3) {
-
-            } else if (range == 4) {
-
-            } else{
-                throw new ServiceException("同步类型错误");
+                    throw new ServiceException("同步类型错误");
             }
         } catch (Exception e) {
             synchronousRecordMapper.update(null, Wrappers.<WbsTreeSynchronousRecord>lambdaUpdate()
@@ -123,29 +111,36 @@ public class WbsSynchronousServiceImpl {
 
     /**
      * 同步所有相同元素的表单
+     *
      * @param wbsTreeSynchronousRecord
      */
     private void syncPrivateAllForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
         String nodeId = wbsTreeSynchronousRecord.getNodeId();
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(nodeId);
+        if (wbsTreePrivate == null) {
+            throw new ServiceException("节点/表单 不存在");
+        }
         String initTableName = wbsTreePrivate.getInitTableName();
-        if(StringUtil.isBlank(initTableName)){
+        if (StringUtil.isBlank(initTableName)) {
             throw new ServiceException("表单未绑定实体表");
         }
         //在指定项目下指定实体表相同的数据
         List<WbsTreePrivate> wbsTreePrivates = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery()
                 .eq(WbsTreePrivate::getProjectId, wbsTreePrivate.getProjectId())
+                .ne(WbsTreePrivate::getPKeyId, nodeId)
                 .eq(WbsTreePrivate::getInitTableName, initTableName)
         );
+        if(CollectionUtil.isEmpty(wbsTreePrivates)){
+            throw new ServiceException("当前项目没有相同实体表的其他表单");
+        }
         //清表也相同的数据
         List<WbsTreePrivate> collect = wbsTreePrivates.stream().filter(f ->
                 Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())
         ).collect(Collectors.toList());
         //清表不同的数据
         List<WbsTreePrivate> noExcelIdEq = wbsTreePrivates.stream().filter(f -> !Objects.equals(f.getExcelId(), wbsTreePrivate.getExcelId())).collect(Collectors.toList());
-        if(CollectionUtil.isEmpty(noExcelIdEq)){
-
-            StringBuffer sb = new StringBuffer();
+        if (CollectionUtil.isNotEmpty(noExcelIdEq)) {
+            StringBuilder sb = new StringBuilder();
             for (WbsTreePrivate treePrivate : noExcelIdEq) {
                 List<WbsTreePrivate> list = wbsTreePrivateMapper.selectList(Wrappers.<WbsTreePrivate>lambdaQuery().in(WbsTreePrivate::getPKeyId, Func.toLongList(treePrivate.getAncestorsPId())));
                 List<String> nodeNames = list.stream().map(WbsTreePrivate::getNodeName).collect(Collectors.toList());
@@ -156,23 +151,26 @@ public class WbsSynchronousServiceImpl {
         }
         List<Long> ids = collect.stream().map(WbsTreePrivate::getPKeyId).collect(Collectors.toList());
         //修改数据
-        wbsSynchronousEViSaService.updateSyncPrivateForm(wbsTreePrivate.getHtmlUrl(),ids);
+        wbsSynchronousEViSaService.updateSyncPrivateForm(wbsTreePrivate.getHtmlUrl(), ids, wbsTreeSynchronousRecord.getId());
     }
 
     /**
-     *
      * 强制同步表单
+     *
      * @param wbsTreeSynchronousRecord
      */
     private void syncPrivateForceForm(WbsTreeSynchronousRecord wbsTreeSynchronousRecord) {
         String nodeId = wbsTreeSynchronousRecord.getNodeId();
-        if(nodeId.contains(",")){
+        if (nodeId.contains(",")) {
             throw new ServiceException("不能选中多个节点");
         }
         String formIds = wbsTreeSynchronousRecord.getFormIds();
         //选中的表单
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(formIds);
-        wbsSynchronousEViSaService.syncPrivateForceForm(wbsTreePrivate,nodeId);
+        if (wbsTreePrivate == null) {
+            throw new ServiceException("表单不存在");
+        }
+        wbsSynchronousEViSaService.syncPrivateForceForm(wbsTreePrivate, nodeId, wbsTreeSynchronousRecord.getId());
     }
 
     /**
@@ -204,9 +202,6 @@ public class WbsSynchronousServiceImpl {
         ProjectInfo projectInfo = projectInfoMapper.selectOne(Wrappers.<ProjectInfo>lambdaQuery().eq(ProjectInfo::getId, wbsTreeSynchronousRecord.getProjectId()));
 
 
-
-
-
         for (String primaryKeyId : nodeIds) {
             if (StringUtils.isNotEmpty(primaryKeyId)) {
                 //获取当前节点对应节点信息
@@ -217,16 +212,15 @@ public class WbsSynchronousServiceImpl {
                 //当前项目绑定的是公有模板还是私有项目
                 Boolean isPublic = false;
                 if (
-                        ("1".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateType()))   ||
-                                ("2".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateTypeTrial()))   ||
-                                ("3".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateTypeMeter()))   ||
+                        ("1".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateType())) ||
+                                ("2".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateTypeTrial())) ||
+                                ("3".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateTypeMeter())) ||
                                 ("5".equals(wbsTreePrivate.getWbsType()) && ("public").equals(projectInfo.getReferenceWbsTemplateTypeLar()))
                 ) {
                     isPublic = true;
                 }
 
 
-
                 //当前项目模板对应的节点信息
                 List<WbsTreePrivate> templateNodes = new ArrayList<>();
                 //质检
@@ -386,8 +380,12 @@ public class WbsSynchronousServiceImpl {
                                     editPrivateNode.setExcelId(templateNode.getExcelId());
                                     //绑定实体表
                                     editPrivateNode.setInitTableName(templateNode.getInitTableName());
-                                    //封装Html路径
-                                    if (StringUtil.isBlank(editPrivateNode.getHtmlUrl()) || !Objects.equals(editPrivateNode.getHtmlUrl(), templateNode.getHtmlUrl())) {
+
+                                    if(StringUtil.isBlank(templateNode.getHtmlUrl())){
+                                        throw new ServiceException(templateNode.getNodeName() + "HTML文件不存在");
+                                    }
+                                    //封装Html路径 根据模板html copy一份到自己项目节点上
+                                    if (StringUtil.isNotBlank(editPrivateNode.getHtmlUrl()) && (StringUtil.isBlank(editPrivateNode.getHtmlUrl()) || !Objects.equals(editPrivateNode.getHtmlUrl(), templateNode.getHtmlUrl()))) {
                                         String[] split = templateNode.getHtmlUrl().split("/");
                                         String htmlUrl = file_path + "privateUrlCopy/" + projectInfo.getId() + "/" + split[split.length - 1];
                                         File file_in = ResourceUtil.getFile(templateNode.getHtmlUrl());

+ 23 - 8
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/WbsTreeSynchronousRecordServiceImpl.java

@@ -8,19 +8,19 @@ import org.springblade.common.utils.SnowFlakeUtil;
 import org.springblade.core.log.exception.ServiceException;
 import org.springblade.core.secure.BladeUser;
 import org.springblade.core.secure.utils.SecureUtil;
-import org.springblade.core.tool.utils.BeanUtil;
-import org.springblade.core.tool.utils.CollectionUtil;
-import org.springblade.manager.entity.*;
+import org.springblade.core.tool.utils.StringUtil;
+import org.springblade.manager.entity.ProjectInfo;
+import org.springblade.manager.entity.WbsInfo;
+import org.springblade.manager.entity.WbsTreePrivate;
+import org.springblade.manager.entity.WbsTreeSynchronousRecord;
 import org.springblade.manager.mapper.*;
 import org.springblade.manager.service.WbsTreeSynchronousRecordService;
 import org.springblade.manager.vo.WbsTreeSynchronousRecordVo;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
 import java.util.stream.Collectors;
@@ -101,9 +101,24 @@ public class WbsTreeSynchronousRecordServiceImpl extends ServiceImpl<WbsTreeSync
 
         //获取项目名称
         ProjectInfo projectInfo = projectInfoMapper.selectById(mWbsTreeSynchronousRecord.getProjectId());
-
+        if(projectInfo == null){
+            throw new ServiceException("项目不存在");
+        }
         mWbsTreeSynchronousRecord.setId(SnowFlakeUtil.getId());
         mWbsTreeSynchronousRecord.setProjectName(projectInfo.getProjectName());
+
+
+        //类型为3 、 4
+        if (mWbsTreeSynchronousRecord.getRange() == 3) {
+            mWbsTreeSynchronousRecord.setRangeName("单表单同步");
+        }
+        if (mWbsTreeSynchronousRecord.getRange() == 4) {
+            mWbsTreeSynchronousRecord.setRangeName("单表强制同步");
+            if (StringUtil.isBlank(mWbsTreeSynchronousRecord.getFormIds())){
+                throw new ServiceException("请选择表单");
+            }
+        }
+
         //获取当前用户
         BladeUser user = SecureUtil.getUser();
         mWbsTreeSynchronousRecord.setCreateUserId(user.getUserId());
@@ -122,7 +137,7 @@ public class WbsTreeSynchronousRecordServiceImpl extends ServiceImpl<WbsTreeSync
         //选中节点
         WbsTreePrivate wbsTreePrivate = wbsTreePrivateMapper.selectById(nodeId);
         List<WbsTreeSynchronousRecordVo> wbsTreePrivates = new ArrayList<>();
-        if(wbsTreePrivate == null){
+        if (wbsTreePrivate == null) {
             return wbsTreePrivates;
         }
         List<WbsTreeSynchronousRecordVo> tempProject = getTempProject(wbsTreePrivate, wbsTreePrivates);
@@ -169,7 +184,7 @@ public class WbsTreeSynchronousRecordServiceImpl extends ServiceImpl<WbsTreeSync
      * 同步节点表单
      * 定时检查同步任务,状态为1的数据如果最后更新时间与当前时间超过10分钟,则修改状态为1
      */
-    @Scheduled(fixedDelay = 10000)
+//    @Scheduled(fixedDelay = 10000)
     public void syncInit() {
         List<WbsTreeSynchronousRecord> wbsTreeSynchronousRecords = baseMapper.selectList(new QueryWrapper<WbsTreeSynchronousRecord>().lambda()
                 .in(WbsTreeSynchronousRecord::getStatus, 0, 1)