|
@@ -1,129 +0,0 @@
|
|
|
-package com.skyversation.poiaddr.service.impl;
|
|
|
-
|
|
|
-import com.skyversation.poiaddr.addquery.AddressQueryEngine;
|
|
|
-import com.skyversation.poiaddr.addquery.Constant;
|
|
|
-import com.skyversation.poiaddr.bean.AddressResult;
|
|
|
-import com.skyversation.poiaddr.entity.LegalPerson;
|
|
|
-import com.skyversation.poiaddr.service.LegalPersonRepository;
|
|
|
-import com.skyversation.poiaddr.util.ExcelReaderUtils;
|
|
|
-import com.skyversation.poiaddr.util.status.AddressLevel;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageRequest;
|
|
|
-import org.springframework.data.domain.Pageable;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-import java.util.concurrent.Future;
|
|
|
-
|
|
|
-/**
|
|
|
- * 法人库测试查询
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class LegalPersonServiceImpl {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private LegalPersonRepository legalPersonRepository;
|
|
|
-
|
|
|
- // 查询所有
|
|
|
- @Transactional
|
|
|
- public Page<LegalPerson> getAllData(int page, int size) {
|
|
|
- Pageable pageable = PageRequest.of(page - 1, size);
|
|
|
- return legalPersonRepository.findByAddressdb67Cf74Containing(Constant.getArea(), pageable);
|
|
|
- }
|
|
|
-
|
|
|
- // 批量修改数据库数据
|
|
|
- public List<LegalPerson> updateDatas(List<LegalPerson> legalPerson) {
|
|
|
- return legalPersonRepository.saveAll(legalPerson);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 首先要得到一个Page<T>对象,然后判断是否还有别的数据,有的话接着请求并返回新的Page<T>对象并迭代处理数据
|
|
|
- */
|
|
|
- @Transactional
|
|
|
- public void iterativeProcessing(Integer pageNum, Integer pageSize, Integer level) {
|
|
|
- System.out.println("<<<<<<<<------iterativeProcessing{pageNum:" + pageNum + ",pageSize:" + pageSize + "}");
|
|
|
- Page<LegalPerson> outData = getAllData(pageNum, pageSize);
|
|
|
- List<LegalPerson> listData = outData.getContent();
|
|
|
- // 创建线程池
|
|
|
- int threadCount = Runtime.getRuntime().availableProcessors();
|
|
|
- ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
|
|
|
- List<Future<?>> futures = new ArrayList<>();
|
|
|
- for (LegalPerson item : listData) {
|
|
|
- futures.add(executorService.submit(() -> {
|
|
|
- String addr = item.getAddressdb67Cf74();
|
|
|
-// 判断地址是否属于松江区
|
|
|
- if ((!addr.isEmpty() && ExcelReaderUtils.isOtherDistrictThanSongJiang(addr))) {
|
|
|
-// 开始查询(先去除干扰字和行政区划)
|
|
|
- addr = "上海市" + Constant.getArea() + "区" + AddressQueryEngine.addressReplaceAll(addr);
|
|
|
- List<String> addrs = new ArrayList<>();
|
|
|
- addrs.add(addr);
|
|
|
- AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName(addrs, AddressLevel.values()[level - 1]);
|
|
|
- if (addressResult != null) {
|
|
|
- if (addressResult.getData() == null || addressResult.getData().size() < 1) {
|
|
|
- item.setInTheArea("异常");
|
|
|
- item.setResultAddrKey("未查询到结果!");
|
|
|
- } else {
|
|
|
- try {
|
|
|
- for (AddressResult.ContentBean contentBean : addressResult.getData()) {
|
|
|
- String resultAddrKey = contentBean.getAddress();
|
|
|
- if (resultAddrKey != null && contentBean.getLon() != null && contentBean.getLat() != null && ExcelReaderUtils.isOtherDistrictThanSongJiang(resultAddrKey)) {
|
|
|
- String lng = contentBean.getLat() + "";
|
|
|
- String lat = contentBean.getLon() + "";
|
|
|
- item.setInTheArea("是");
|
|
|
- if (contentBean.getCjJson() != null) {
|
|
|
- item.setTwon(contentBean.getCjJson().getString("所属街道"));
|
|
|
- item.setResidentialCommittee(contentBean.getCjJson().getString("所属居委"));
|
|
|
- }
|
|
|
- item.setLat(lat);
|
|
|
- item.setLon(lng);
|
|
|
- item.setResultAddrKey(resultAddrKey);
|
|
|
- break;
|
|
|
- } else {
|
|
|
- item.setInTheArea("异常");
|
|
|
- item.setResultAddrKey("未查询到符合条件的结果!");
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- item.setInTheArea("异常");
|
|
|
- System.err.println("查询结果处理异常:" + e);
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- item.setInTheArea("异常");
|
|
|
- item.setResultAddrKey("未查询到符合条件的结果!");
|
|
|
- }
|
|
|
- } else {
|
|
|
-// 更新时间,添加是否松江判断字段为否
|
|
|
- item.setInTheArea("否");
|
|
|
- }
|
|
|
- item.setUpdateTime(new Date());
|
|
|
- }));
|
|
|
- }
|
|
|
-
|
|
|
- // 等待所有任务完成
|
|
|
- for (Future<?> future : futures) {
|
|
|
- try {
|
|
|
- future.get();
|
|
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
- System.err.println("线程异常:" + e);
|
|
|
- }
|
|
|
- }
|
|
|
- // 关闭线程池
|
|
|
- executorService.shutdown();
|
|
|
- updateDatas(listData);
|
|
|
-// 多线程处理完成后,判断是否有其他分页并迭代
|
|
|
- if ((long) pageNum * pageSize < outData.getTotalElements()) {
|
|
|
- iterativeProcessing(pageNum + 1, pageSize, level);
|
|
|
- } else {
|
|
|
- System.out.println("<<<<<<<<------任务处理完成!");
|
|
|
- }
|
|
|
- }
|
|
|
-}
|