|
|
@@ -0,0 +1,214 @@
|
|
|
+package com.siwei.apply.service.zrzysite.impl;
|
|
|
+
|
|
|
+import com.siwei.apply.domain.Jsydghxk;
|
|
|
+import com.siwei.apply.domain.Project;
|
|
|
+import com.siwei.apply.domain.vo.JsydghxkUpdateVo;
|
|
|
+import com.siwei.apply.domain.vo.JsydghxkVo;
|
|
|
+import com.siwei.apply.domain.zrzysite.ZrzysiteLand;
|
|
|
+import com.siwei.apply.mapper.JsydghxkMapper;
|
|
|
+import com.siwei.apply.mapper.ProjectMapper;
|
|
|
+import com.siwei.apply.mapper.zrzysite.ZrzysiteLandMapper;
|
|
|
+import com.siwei.apply.service.JsydghxkService;
|
|
|
+import com.siwei.apply.service.zrzysite.IZrzysiteCommonService;
|
|
|
+import com.siwei.apply.service.zrzysite.IZrzysiteLandService;
|
|
|
+import com.siwei.apply.enums.AloneWorkFlowEnum;
|
|
|
+import com.siwei.common.core.exception.ServiceException;
|
|
|
+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 ZrzysiteLandServiceImpl implements IZrzysiteLandService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ZrzysiteLandMapper zrzysiteLandMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProjectMapper projectMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JsydghxkMapper jsydghxkMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JsydghxkService jsydghxkService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IZrzysiteCommonService zrzysiteCommonService;
|
|
|
+
|
|
|
+ private final SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.YYYY_MM_DD);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncConstructInfo() {
|
|
|
+ List<Project> landProjectList = projectMapper.getZrzysiteProjectList("t_jsydghxk");
|
|
|
+ if (!landProjectList.isEmpty()) {
|
|
|
+ List<String> projectCodes = landProjectList.stream()
|
|
|
+ .map(Project::getCode)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ List<ZrzysiteLand> landList = zrzysiteLandMapper.selectByXmdmList(projectCodes);
|
|
|
+
|
|
|
+ Map<String, List<ZrzysiteLand>> codeToLandMap = landList.stream()
|
|
|
+ .collect(Collectors.groupingBy(ZrzysiteLand::getXmdm));
|
|
|
+
|
|
|
+ LinkedHashMap<Project, List<ZrzysiteLand>> zrzysiteLandMap = new LinkedHashMap<>();
|
|
|
+ for (Project project : landProjectList) {
|
|
|
+ List<ZrzysiteLand> items = codeToLandMap.getOrDefault(project.getCode(), new ArrayList<>());
|
|
|
+ zrzysiteLandMap.put(project, items);
|
|
|
+ }
|
|
|
+ addLandInfoToDataBase(zrzysiteLandMap);
|
|
|
+ }
|
|
|
+ log.info("当前批次执行完毕");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void syncCurrentNodeInfo(String projectId, String nodeTableName) {
|
|
|
+ Project project = projectMapper.get(projectId);
|
|
|
+ if (Objects.isNull(project) || StringUtils.isBlank(project.getCode())) {
|
|
|
+ throw new ServiceException("当前项目不具备同步条件,请检查项目代码是否存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<ZrzysiteLand> landList = zrzysiteLandMapper.selectByXmdmList(new ArrayList<>(Collections.singleton(project.getCode())));
|
|
|
+ if (CollectionUtils.isEmpty(landList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Jsydghxk> jsydghxkList = jsydghxkMapper.getList(projectId);
|
|
|
+ Map<String, String> resSourceIdMap = jsydghxkList.stream()
|
|
|
+ .filter(obj -> StringUtils.isNotBlank(obj.getSourceId()))
|
|
|
+ .collect(Collectors.toMap(Jsydghxk::getSourceId, Jsydghxk::getId));
|
|
|
+ List<String> needUpdateNodeIdList = jsydghxkList.stream()
|
|
|
+ .filter(s -> StringUtils.isBlank(s.getSourceId()))
|
|
|
+ .map(Jsydghxk::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ String addNodeId = "";
|
|
|
+ for (ZrzysiteLand land : landList) {
|
|
|
+ String needUpdateNodeId = "";
|
|
|
+ if (resSourceIdMap.containsKey(land.getSqbh())) {
|
|
|
+ needUpdateNodeId = resSourceIdMap.get(land.getSqbh());
|
|
|
+ } else if (!needUpdateNodeIdList.isEmpty()) {
|
|
|
+ needUpdateNodeId = needUpdateNodeIdList.remove(0);
|
|
|
+ }
|
|
|
+ addNodeId = addOrUpdatToTable(land, projectId, needUpdateNodeId);
|
|
|
+ zrzysiteCommonService.getNodeAttachment(projectId, addNodeId, land.getSqbh(), AloneWorkFlowEnum.NODE_4.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addLandInfoToDataBase(Map<Project, List<ZrzysiteLand>> zrzysiteLandMap) {
|
|
|
+ for (Map.Entry<Project, List<ZrzysiteLand>> entry : zrzysiteLandMap.entrySet()) {
|
|
|
+ Project project = entry.getKey();
|
|
|
+ List<ZrzysiteLand> landList = entry.getValue();
|
|
|
+ if (CollectionUtils.isEmpty(landList)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String projectId = project.getId();
|
|
|
+ String sourceType = project.getCreatorId();
|
|
|
+
|
|
|
+ String addNodeId = "";
|
|
|
+ if ("2".equals(sourceType)) {
|
|
|
+ List<Jsydghxk> jsydghxkList = jsydghxkMapper.getList(projectId);
|
|
|
+ Optional<Jsydghxk> hasOnchainRes = jsydghxkList.stream().filter(Jsydghxk::getHasOnchain).findFirst();
|
|
|
+ if (hasOnchainRes.isPresent()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (jsydghxkList.stream().anyMatch(obj ->
|
|
|
+ StringUtils.isNotBlank(obj.getZsbh())
|
|
|
+ && StringUtils.isNotBlank(obj.getFzDate()))) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> resSourceIdList = jsydghxkList.stream()
|
|
|
+ .map(Jsydghxk::getSourceId)
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!resSourceIdList.isEmpty()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<String> needUpdateNodeIdList = jsydghxkList.stream()
|
|
|
+ .filter(s -> StringUtils.isBlank(s.getSourceId()))
|
|
|
+ .map(Jsydghxk::getId)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ for (ZrzysiteLand land : landList) {
|
|
|
+ String needUpdateNodeId = "";
|
|
|
+ if (!needUpdateNodeIdList.isEmpty()) {
|
|
|
+ needUpdateNodeId = needUpdateNodeIdList.remove(0);
|
|
|
+ }
|
|
|
+ addNodeId = addOrUpdatToTable(land, projectId, needUpdateNodeId);
|
|
|
+ zrzysiteCommonService.getNodeAttachment(projectId, addNodeId, land.getSqbh(), AloneWorkFlowEnum.NODE_4.getName());
|
|
|
+ }
|
|
|
+ } else if ("1".equals(sourceType)) {
|
|
|
+ for (ZrzysiteLand land : landList) {
|
|
|
+ addNodeId = addOrUpdatToTable(land, projectId, "");
|
|
|
+ zrzysiteCommonService.getNodeAttachment(projectId, addNodeId, land.getSqbh(), AloneWorkFlowEnum.NODE_4.getName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String addOrUpdatToTable(ZrzysiteLand land, String projectId, String needUpdateNodeId) {
|
|
|
+ String addNodeId = "";
|
|
|
+ if (StringUtils.isNotBlank(needUpdateNodeId)) {
|
|
|
+ JsydghxkUpdateVo updateVo = new JsydghxkUpdateVo();
|
|
|
+ updateVo.setId(needUpdateNodeId);
|
|
|
+ updateVo.setProjectId(projectId);
|
|
|
+ updateVo.setYddw(land.getXddw());
|
|
|
+ updateVo.setYdwz(land.getYdwz());
|
|
|
+ if (StringUtils.isNotBlank(land.getYdmj())) {
|
|
|
+ try {
|
|
|
+ updateVo.setYdArea(Float.parseFloat(land.getYdmj()));
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("用地面积转换失败: {}", land.getYdmj());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ updateVo.setTdyt(land.getTdyt());
|
|
|
+ updateVo.setTdhqfs(land.getTdhqfs());
|
|
|
+ updateVo.setPzydjg(land.getPzydjg());
|
|
|
+ updateVo.setPzydwh(land.getPzydwh());
|
|
|
+ updateVo.setJsgm(land.getJsgm());
|
|
|
+ updateVo.setZsbh(land.getZsbh());
|
|
|
+ updateVo.setFzjg(land.getFadw());
|
|
|
+ updateVo.setSourceId(land.getSqbh());
|
|
|
+ if (land.getFzrq() != null) {
|
|
|
+ updateVo.setFzDate(sdf.format(land.getFzrq()));
|
|
|
+ }
|
|
|
+ jsydghxkService.update(updateVo);
|
|
|
+ addNodeId = needUpdateNodeId;
|
|
|
+ } else {
|
|
|
+ JsydghxkVo vo = new JsydghxkVo();
|
|
|
+ vo.setProjectId(projectId);
|
|
|
+ vo.setYddw(land.getXddw());
|
|
|
+ vo.setYdwz(land.getYdwz());
|
|
|
+ if (StringUtils.isNotBlank(land.getYdmj())) {
|
|
|
+ try {
|
|
|
+ vo.setYdArea(Float.parseFloat(land.getYdmj()));
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.warn("用地面积转换失败: {}", land.getYdmj());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setTdyt(land.getTdyt());
|
|
|
+ vo.setTdhqfs(land.getTdhqfs());
|
|
|
+ vo.setPzydjg(land.getPzydjg());
|
|
|
+ vo.setPzydwh(land.getPzydwh());
|
|
|
+ vo.setJsgm(land.getJsgm());
|
|
|
+ vo.setZsbh(land.getZsbh());
|
|
|
+ vo.setFzjg(land.getFadw());
|
|
|
+ vo.setSourceId(land.getSqbh());
|
|
|
+ if (land.getFzrq() != null) {
|
|
|
+ vo.setFzDate(sdf.format(land.getFzrq()));
|
|
|
+ }
|
|
|
+ addNodeId = jsydghxkService.add(vo);
|
|
|
+ }
|
|
|
+ return addNodeId;
|
|
|
+ }
|
|
|
+}
|