|
@@ -0,0 +1,285 @@
|
|
|
|
|
+package com.siwei.apply.service.zrzysite.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.siwei.apply.domain.BaseId;
|
|
|
|
|
+import com.siwei.apply.domain.Jsgcghxk;
|
|
|
|
|
+import com.siwei.apply.domain.Project;
|
|
|
|
|
+import com.siwei.apply.domain.vo.JsgcghxkUpdateVo;
|
|
|
|
|
+import com.siwei.apply.domain.vo.JsgcghxkVo;
|
|
|
|
|
+import com.siwei.apply.domain.zrzysite.ZrzysiteAttachment;
|
|
|
|
|
+import com.siwei.apply.domain.zrzysite.ZrzysiteConstruct;
|
|
|
|
|
+import com.siwei.apply.domain.vo.zrzysite.ZrzysiteConstructFilterVo;
|
|
|
|
|
+import com.siwei.apply.enums.AloneWorkFlowEnum;
|
|
|
|
|
+import com.siwei.apply.mapper.JsgcghxkMapper;
|
|
|
|
|
+import com.siwei.apply.mapper.ProjectMapper;
|
|
|
|
|
+import com.siwei.apply.mapper.zrzysite.ZrzysiteAttachmentMapper;
|
|
|
|
|
+import com.siwei.apply.mapper.zrzysite.ZrzysiteConstructMapper;
|
|
|
|
|
+import com.siwei.apply.service.JsgcghxkService;
|
|
|
|
|
+import com.siwei.apply.service.NodeAttachmentService;
|
|
|
|
|
+import com.siwei.apply.service.zrzysite.IZrzysiteCommonService;
|
|
|
|
|
+import com.siwei.apply.utils.ServiceFileUtil;
|
|
|
|
|
+import com.siwei.common.core.utils.DateUtils;
|
|
|
|
|
+import com.siwei.common.core.utils.StringUtils;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@Service
|
|
|
|
|
+public class ZrzysiteCommonServiceImpl implements IZrzysiteCommonService {
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ZrzysiteConstructMapper zrzysiteConstructMapper;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private JsgcghxkMapper jsgcghxkMapper;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private JsgcghxkService jsgcghxkService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private NodeAttachmentService nodeAttachmentService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ZrzysiteAttachmentMapper zrzysiteAttachmentMapper;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<ZrzysiteConstruct> selectList(ZrzysiteConstructFilterVo filterVo) {
|
|
|
|
|
+ return zrzysiteConstructMapper.selectList(filterVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public ZrzysiteConstruct selectById(String sqbh) {
|
|
|
|
|
+ return zrzysiteConstructMapper.selectById(sqbh);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public int selectCount(ZrzysiteConstructFilterVo filterVo) {
|
|
|
|
|
+ return zrzysiteConstructMapper.selectCount(filterVo);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 同步工程建设数据
|
|
|
|
|
+ * @param sqbh
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void syncConstructInfo(String sqbh) {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 1.查询所有的项目数据,及当前节点数据,不存在的,未上链的。
|
|
|
|
|
+ * 2.遍历这些数据,从Oracle中,根据项目号进行查询。
|
|
|
|
|
+ * 3.如果查到一条数据,然后进行入库一系列的操作。
|
|
|
|
|
+ * 4.不进行上链,上链操作,通过其他定时任务完成。
|
|
|
|
|
+ */
|
|
|
|
|
+
|
|
|
|
|
+ // 批量查询所有 项目名称,项目代码,workflow表中是否存在。如果存在,则不处理,如果不存在则处理。
|
|
|
|
|
+ List<Project> constructProjectList = projectMapper.getZrzysiteProjectList("t_jsgcghxk");
|
|
|
|
|
+ if (!constructProjectList.isEmpty()) {
|
|
|
|
|
+ List<String> projectCodes = constructProjectList.stream()
|
|
|
|
|
+ .map(Project::getCode)
|
|
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ List<ZrzysiteConstruct> constructList = zrzysiteConstructMapper.selectByXmdmList(projectCodes);
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, List<ZrzysiteConstruct>> codeToConstructMap = constructList.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(ZrzysiteConstruct::getXmdm));
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ LinkedHashMap<Project, List<ZrzysiteConstruct>> zrzysiteConstructMap = new LinkedHashMap<>();
|
|
|
|
|
+ for (Project project : constructProjectList) {
|
|
|
|
|
+ List<ZrzysiteConstruct> items = codeToConstructMap.getOrDefault(project.getCode(), new ArrayList<>());
|
|
|
|
|
+ if(!items.isEmpty() && (project.getCode().equals("2020-360090-48-01-002429"))){
|
|
|
|
|
+ zrzysiteConstructMap.put(project, items);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ log.info("到这里来了");
|
|
|
|
|
+ addConstructInfoToDataBase(zrzysiteConstructMap);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 根据对应关系,映射转换,然后入库
|
|
|
|
|
+ * @param zrzysiteConstructMap
|
|
|
|
|
+ */
|
|
|
|
|
+ public void addConstructInfoToDataBase(Map<Project, List<ZrzysiteConstruct>> zrzysiteConstructMap) {
|
|
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
+ for (Map.Entry<Project, List<ZrzysiteConstruct>> entry : zrzysiteConstructMap.entrySet()) {
|
|
|
|
|
+ Project project = entry.getKey();
|
|
|
|
|
+ List<ZrzysiteConstruct> constructList = entry.getValue();
|
|
|
|
|
+ if (CollectionUtils.isEmpty(constructList)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String projectId = project.getId();
|
|
|
|
|
+ //来源类型。1.节点不存在的项目。2.节点存在的项目
|
|
|
|
|
+ String sourceType = project.getCreatorId();
|
|
|
|
|
+ if("2".equals(sourceType)){ //修改和新增的情况
|
|
|
|
|
+ List<Jsgcghxk> JsgcghxkList = jsgcghxkMapper.get(projectId);
|
|
|
|
|
+ //1.如果有一个节点已经上链,直接外层跳过
|
|
|
|
|
+ Optional<Jsgcghxk> hasOnchainRes = JsgcghxkList.stream().filter(Jsgcghxk::getHasOnchain).findFirst();
|
|
|
|
|
+ if(hasOnchainRes.isPresent()){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //如果用户手动修改过的数据直接用户操作为准,不再同步
|
|
|
|
|
+ if(JsgcghxkList.stream().anyMatch(obj ->
|
|
|
|
|
+ !DateUtils.isSameMinute(obj.getCreatedAt(), obj.getUpdatedAt())
|
|
|
|
|
+ && StringUtils.isNotBlank(obj.getZsbh())
|
|
|
|
|
+ && StringUtils.isNotBlank(obj.getFzDate()))){
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //找出同步过的数据,不再同步
|
|
|
|
|
+ List<String> sourceIdList = new ArrayList<>();
|
|
|
|
|
+ List<String> resSourceIdList = JsgcghxkList.stream().map(Jsgcghxk::getSourceId).filter(StringUtils::isNotBlank).collect(Collectors.toList());
|
|
|
|
|
+ if(!resSourceIdList.isEmpty()){
|
|
|
|
|
+ sourceIdList = new ArrayList<>(resSourceIdList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //找出需要更新的节点id
|
|
|
|
|
+ List<String> needUpdateNodeIdList = JsgcghxkList.stream().filter(s->StringUtils.isBlank(s.getSourceId())).map(BaseId::getId).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ String addNodeId = "";
|
|
|
|
|
+ for (ZrzysiteConstruct construct : constructList) {
|
|
|
|
|
+ if(sourceIdList.contains(construct.getSqbh())){
|
|
|
|
|
+ //说明已经同步过了
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String needUpdateNodeId = "";
|
|
|
|
|
+ // 取出头部元素并从集合删除
|
|
|
|
|
+ if (!needUpdateNodeIdList.isEmpty()) {
|
|
|
|
|
+ needUpdateNodeId = needUpdateNodeIdList.remove(0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if(StringUtils.isNotBlank(needUpdateNodeId)){
|
|
|
|
|
+ JsgcghxkUpdateVo jsgcghxkUpdateVo = new JsgcghxkUpdateVo();
|
|
|
|
|
+ jsgcghxkUpdateVo.setId(needUpdateNodeId);
|
|
|
|
|
+ jsgcghxkUpdateVo.setProjectId(projectId);
|
|
|
|
|
+ jsgcghxkUpdateVo.setYddw(construct.getYdwz());
|
|
|
|
|
+ jsgcghxkUpdateVo.setYddw(construct.getXddw());
|
|
|
|
|
+ jsgcghxkUpdateVo.setJsgm(construct.getJsgm());
|
|
|
|
|
+ jsgcghxkUpdateVo.setZsbh(construct.getZsbh());
|
|
|
|
|
+ jsgcghxkUpdateVo.setFzjg(construct.getFadw());
|
|
|
|
|
+ jsgcghxkUpdateVo.setSourceId(construct.getSqbh());
|
|
|
|
|
+ jsgcghxkService.update(jsgcghxkUpdateVo);
|
|
|
|
|
+ addNodeId = needUpdateNodeId;
|
|
|
|
|
+ }else {
|
|
|
|
|
+ JsgcghxkVo vo = new JsgcghxkVo();
|
|
|
|
|
+ vo.setProjectId(projectId);
|
|
|
|
|
+ vo.setYdwz(construct.getYdwz());
|
|
|
|
|
+ vo.setYddw(construct.getXddw());
|
|
|
|
|
+ vo.setJsgm(construct.getJsgm());
|
|
|
|
|
+ vo.setZsbh(construct.getZsbh());
|
|
|
|
|
+ vo.setFzjg(construct.getFadw());
|
|
|
|
|
+ vo.setSourceId(construct.getSqbh());
|
|
|
|
|
+ if (construct.getFzrq() != null) {
|
|
|
|
|
+ vo.setFzDate(sdf.format(construct.getFzrq()));
|
|
|
|
|
+ }
|
|
|
|
|
+ addNodeId = jsgcghxkService.add(vo);
|
|
|
|
|
+ }
|
|
|
|
|
+ //这里进行文件处理
|
|
|
|
|
+ getNodeAttachment(projectId,addNodeId,construct.getSqbh(),AloneWorkFlowEnum.NODE_5.getName());
|
|
|
|
|
+ }//end for
|
|
|
|
|
+
|
|
|
|
|
+ }else if("1".equals(sourceType)){ //只存在新增情况
|
|
|
|
|
+ for (ZrzysiteConstruct construct : constructList) {
|
|
|
|
|
+ JsgcghxkVo vo = new JsgcghxkVo();
|
|
|
|
|
+ vo.setProjectId(projectId);
|
|
|
|
|
+ vo.setYdwz(construct.getYdwz());
|
|
|
|
|
+ vo.setYddw(construct.getXddw());
|
|
|
|
|
+ vo.setJsgm(construct.getJsgm());
|
|
|
|
|
+ vo.setZsbh(construct.getZsbh());
|
|
|
|
|
+ vo.setFzjg(construct.getFadw());
|
|
|
|
|
+ vo.setSourceId(construct.getSqbh());
|
|
|
|
|
+ if (construct.getFzrq() != null) {
|
|
|
|
|
+ vo.setFzDate(sdf.format(construct.getFzrq()));
|
|
|
|
|
+ }
|
|
|
|
|
+ String addNodeId = jsgcghxkService.add(vo);
|
|
|
|
|
+ //这里进行文件处理
|
|
|
|
|
+ getNodeAttachment(projectId,addNodeId,construct.getSqbh(),AloneWorkFlowEnum.NODE_5.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }// end for
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /*
|
|
|
|
|
+ 1.先拿到示例id
|
|
|
|
|
+ 2.根据实例id,获取所有的附件材料条数。
|
|
|
|
|
+ 3.把数据下载到当前目录。
|
|
|
|
|
+ 4.获取当前附件的json
|
|
|
|
|
+ 5.存储入库。
|
|
|
|
|
+ */
|
|
|
|
|
+ public String getNodeAttachment(String projectId, String nodeId, String sourceId, String nodeName) {
|
|
|
|
|
+ if (StringUtils.isBlank(sourceId)) {
|
|
|
|
|
+ log.info("文件关联id为空--附件材料无法下载-项目id:{}", projectId);
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String fileDownLoadPath = "";
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ //这里把文件下载下来,并且构建正确的目录结构
|
|
|
|
|
+ List<ZrzysiteAttachment> zrzysiteAttachmentList = zrzysiteAttachmentMapper.selectByApplyinstId(sourceId);
|
|
|
|
|
+ //这里增加一个方法,把文件下载下来
|
|
|
|
|
+
|
|
|
|
|
+ //先创建一个跟路径
|
|
|
|
|
+ //fileDownLoadPath = ServiceFileUtil.createDirectory(nodeName);
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isNotEmpty(zrzysiteAttachmentList)) {
|
|
|
|
|
+ String[] subDirectoryNameArr = zrzysiteAttachmentList.stream().map(s->s.getClmc()).collect(Collectors.toSet()).toArray(new String[0]);
|
|
|
|
|
+ //先删除相关目录
|
|
|
|
|
+ for(String subDirectoryName : subDirectoryNameArr){
|
|
|
|
|
+ ServiceFileUtil.deleteDirectory(subDirectoryName);
|
|
|
|
|
+ }
|
|
|
|
|
+ //重新创建子目录
|
|
|
|
|
+ fileDownLoadPath = ServiceFileUtil.createMultipartDirectory(nodeName,subDirectoryNameArr);
|
|
|
|
|
+
|
|
|
|
|
+ for (ZrzysiteAttachment attachment : zrzysiteAttachmentList) {
|
|
|
|
|
+ String url = attachment.getAttachment();
|
|
|
|
|
+ String directoryName = attachment.getClmc();
|
|
|
|
|
+ String fileName = attachment.getFjmc();
|
|
|
|
|
+// //子目录存在先删除
|
|
|
|
|
+ String subDownLoadFilePath = fileDownLoadPath + "/" + directoryName;
|
|
|
|
|
+ ServiceFileUtil.downloadFile(url,fileName, subDownLoadFilePath);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String nodeAttachmentId = nodeAttachmentService.processFileAndSave(fileDownLoadPath, null, null);
|
|
|
|
|
+ boolean success = nodeAttachmentService.updateNodeId(nodeAttachmentId, nodeId);
|
|
|
|
|
+ log.info("附件材料下载并关联入库成功:{},环节id:{]-项目id:{}",success,nodeId, projectId);
|
|
|
|
|
+ nodeAttachmentService.modifyAttachmentInfo(projectId, nodeId, nodeAttachmentId);
|
|
|
|
|
+ return nodeAttachmentId;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理文件异常", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+}
|