|
|
|
|
@ -1,20 +1,36 @@
|
|
|
|
|
package com.biutag.supervisiondata.service.impl; |
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
import com.biutag.supervisiondata.common.interfaces.CompletableFutureUtil; |
|
|
|
|
import com.biutag.supervisiondata.pojo.constants.Default; |
|
|
|
|
import com.biutag.supervisiondata.pojo.database.Contradiction; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.ads.GBaseSYRKXX; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.dwd.GBaseJJD; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.dwd.GBaseTbDZdrylb; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.dwd.GBaseZDRY; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.mine.RiskPersonal; |
|
|
|
|
import com.biutag.supervisiondata.repository.GBaseJJDRepository; |
|
|
|
|
import com.biutag.supervisiondata.repository.RiskPersonalRepository; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.mine.SupDepart; |
|
|
|
|
import com.biutag.supervisiondata.pojo.entity.mine.SupExternalDepart; |
|
|
|
|
import com.biutag.supervisiondata.pojo.enums.DepartType; |
|
|
|
|
import com.biutag.supervisiondata.repository.*; |
|
|
|
|
import com.biutag.supervisiondata.service.PersonalService; |
|
|
|
|
import com.biutag.supervisiondata.service.RiskPersonalService; |
|
|
|
|
import com.biutag.supervisiondata.util.IdCodeUtil; |
|
|
|
|
import com.biutag.supervisiondata.util.PatternUtil; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
import org.springframework.cglib.core.Local; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.time.LocalDate; |
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
import java.time.ZoneId; |
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.CompletableFuture; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
import java.util.stream.IntStream; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author kami on 2024-11-25 11:01:11 |
|
|
|
|
@ -26,16 +42,17 @@ import java.util.List;
|
|
|
|
|
@AllArgsConstructor |
|
|
|
|
public class PersonalServiceImpl implements PersonalService { |
|
|
|
|
|
|
|
|
|
private final RiskPersonalRepository personalRepository; |
|
|
|
|
|
|
|
|
|
private final GBaseJJDRepository gBaseJJDRepository; |
|
|
|
|
|
|
|
|
|
private final GBaseSYRKXXRepository gBaseSYRKXXRepository; |
|
|
|
|
|
|
|
|
|
private final RiskPersonalService riskPersonalService; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void pullPersonalInfo() { |
|
|
|
|
LocalDateTime start = personalRepository.getBaseMapper().selectMaxCreateTime(); |
|
|
|
|
if(start == null) { |
|
|
|
|
start = LocalDateTime.of(2024, 1,1,0,0,0); |
|
|
|
|
} |
|
|
|
|
public void pullJJDPersonalInfo(LocalDateTime start) { |
|
|
|
|
// LocalDateTime start = Optional.ofNullable(personalRepository.getBaseMapper().selectMaxCreateTime())
|
|
|
|
|
// .orElse(LocalDateTime.of(2024, 1, 1, 0, 0, 0));
|
|
|
|
|
// 结束时间设置为人员的创建时间,保证下次提取是新的接警数据
|
|
|
|
|
LocalDateTime end = LocalDateTime.now(); |
|
|
|
|
|
|
|
|
|
// 获取接警数据
|
|
|
|
|
@ -43,7 +60,267 @@ public class PersonalServiceImpl implements PersonalService {
|
|
|
|
|
end.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
|
|
|
|
log.info("总条数 | {}条", result.size()); |
|
|
|
|
|
|
|
|
|
// 过滤数据
|
|
|
|
|
List<String> idCodes1 = new ArrayList<>(); |
|
|
|
|
List<String> mobiles1 = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
Map<String, List<GBaseJJD>> jjdMap = new HashMap<>(); |
|
|
|
|
Map<String, List<GBaseJJD>> jjdMMap = new HashMap<>(); |
|
|
|
|
List<GBaseJJD> jjdList = new ArrayList<>(); |
|
|
|
|
for (GBaseJJD item : result) { |
|
|
|
|
if (item.getBjrzjhm() != null) { |
|
|
|
|
jjdMap.computeIfAbsent(item.getBjrzjhm(), k -> new ArrayList<>()).add(item); |
|
|
|
|
idCodes1.add(item.getBjrzjhm()); |
|
|
|
|
jjdList.add(item); |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String idCards = PatternUtil.takeIdCard(item.getCjqk()); |
|
|
|
|
if (idCards.isEmpty() && item.getBjrlxdh() == null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
jjdList.add(item); |
|
|
|
|
if (!idCards.isEmpty()) { |
|
|
|
|
String[] strs = idCards.split(","); |
|
|
|
|
for (String s : strs) { |
|
|
|
|
idCodes1.add(s); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
jjdMMap.computeIfAbsent(item.getBjrlxdh(), k -> new ArrayList<>()).add(item); |
|
|
|
|
mobiles1.add(item.getBjrlxdh()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 去重
|
|
|
|
|
List<String> idCodes2 = idCodes1.stream().distinct().collect(Collectors.toList()); |
|
|
|
|
List<String> mobiles2 = mobiles1.stream().distinct().collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 切割
|
|
|
|
|
List<List<String>> idCodes = IntStream.range(0, (idCodes2.size() + 9999) / 10000) |
|
|
|
|
.mapToObj(i -> idCodes2.subList(i * 10000, Math.min((i + 1) * 10000, idCodes2.size()))) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
List<List<String>> mobiles = IntStream.range(0, (mobiles2.size() + 9999) / 10000) |
|
|
|
|
.mapToObj(i -> mobiles2.subList(i * 10000, Math.min((i + 1) * 10000, mobiles2.size()))) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
// 身份证查到的人
|
|
|
|
|
List<GBaseSYRKXX> sFms = new ArrayList<>(); |
|
|
|
|
// 手机号查到的人
|
|
|
|
|
List<GBaseSYRKXX> lXfs = new ArrayList<>(); |
|
|
|
|
// 同步查询
|
|
|
|
|
CompletableFuture.allOf( |
|
|
|
|
CompletableFutureUtil.runSyncObject(() -> sFms.addAll(getByIdCode(idCodes))), |
|
|
|
|
CompletableFutureUtil.runSyncObject(() -> lXfs.addAll(getByMobiles(mobiles))) |
|
|
|
|
).join(); |
|
|
|
|
|
|
|
|
|
Map<String, GBaseSYRKXX> idCodeMap = sFms.stream().collect(Collectors.toMap(GBaseSYRKXX::getGmsfhm, Function.identity(), (oldValue, newValue) -> newValue)); |
|
|
|
|
Map<String, List<GBaseSYRKXX>> mobileMap = lXfs.stream().collect(Collectors.groupingBy(GBaseSYRKXX::getLxdh)); |
|
|
|
|
|
|
|
|
|
List<RiskPersonal> personals = new ArrayList<>(); |
|
|
|
|
// 已出现的份证
|
|
|
|
|
Map<String, Byte[]> cache = new WeakHashMap<>(); |
|
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
|
for (GBaseJJD item : jjdList) { |
|
|
|
|
GBaseSYRKXX syrkxx = null; |
|
|
|
|
// 接警单证件号不为空并没入过库
|
|
|
|
|
if (item.getBjrzjhm() != null && cache.get(item.getBjrzjhm()) == null) { |
|
|
|
|
syrkxx = idCodeMap.get(item.getBjrzjhm()); |
|
|
|
|
cache.put(item.getBjrzjhm(), new Byte[0]); |
|
|
|
|
if (syrkxx != null) { |
|
|
|
|
personals.add(createPerson(syrkxx, item.getBjsj(), now, end)); |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
String idCards = PatternUtil.takeIdCard(item.getCjqk()); |
|
|
|
|
if (!idCards.isEmpty()) { |
|
|
|
|
String[] strs = idCards.split(","); |
|
|
|
|
for (String s : strs) { |
|
|
|
|
if (cache.get(s) == null) { |
|
|
|
|
syrkxx = idCodeMap.get(s); |
|
|
|
|
cache.put(s, new Byte[0]); |
|
|
|
|
if (syrkxx != null) { |
|
|
|
|
personals.add(createPerson(syrkxx, item.getBjsj(), now, end)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
List<GBaseSYRKXX> xxList = Optional.ofNullable(mobileMap.get(item.getBjdh())).orElse(new ArrayList<>()); |
|
|
|
|
syrkxx = compare(xxList, item.getBjrxm()); |
|
|
|
|
if (syrkxx != null) { |
|
|
|
|
cache.put(syrkxx.getGmsfhm(), new Byte[0]); |
|
|
|
|
personals.add(createPerson(syrkxx, item.getBjsj(), now, end)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
riskPersonalService.saveDistinct(personals); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final GBaseZDRYRepository zdryRepository; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void pullPointPersonalInfo() { |
|
|
|
|
List<GBaseZDRY> list = zdryRepository.getBaseMapper().syncPointPeople(); |
|
|
|
|
LocalDate now = LocalDate.now(); |
|
|
|
|
Map<String, Byte[]> exist = new WeakHashMap<>(); |
|
|
|
|
|
|
|
|
|
List<RiskPersonal> personals = new ArrayList<>(); |
|
|
|
|
for (GBaseZDRY ry : list) { |
|
|
|
|
if(exist.get(ry.getSfzh()) != null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
exist.put(ry.getSfzh(), new Byte[0]); |
|
|
|
|
RiskPersonal personal = new RiskPersonal(); |
|
|
|
|
personal.setTags(Default.POINT_POEPLE); |
|
|
|
|
personal.setCreateTime(LocalDateTime.now()); |
|
|
|
|
personal.setIdCode(ry.getSfzh()); |
|
|
|
|
personal.setName(ry.getXm()); |
|
|
|
|
|
|
|
|
|
personal.setControlDepartName(ry.getGxdw()); |
|
|
|
|
personal.setControlDepartId(ry.getGxdwjgdm()); |
|
|
|
|
personal.setControlDepartType(DepartType.POINT.getType()); |
|
|
|
|
try { |
|
|
|
|
personal.setControlTime(LocalDateTime.parse(ry.getJlbgsj(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
} |
|
|
|
|
// 基本信息
|
|
|
|
|
personal.setAge(IdCodeUtil.idCard2Age(personal.getIdCode(), now)); |
|
|
|
|
personal.setGender(IdCodeUtil.idCard2Gender(personal.getIdCode())); |
|
|
|
|
// 去除无
|
|
|
|
|
if (ry.getZdrylxfs() != null) { |
|
|
|
|
String[] str = ry.getZdrylxfs().split(","); |
|
|
|
|
StringBuilder mobiles = new StringBuilder(); |
|
|
|
|
for (String s : str) { |
|
|
|
|
String number = s.chars() |
|
|
|
|
.filter(Character::isDigit) |
|
|
|
|
.collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) |
|
|
|
|
.toString(); |
|
|
|
|
if(number.length() < 8 || number.equals("00000000")) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
mobiles.append(s).append(","); |
|
|
|
|
} |
|
|
|
|
personal.setMobileNumber(mobiles.substring(0, mobiles.length()-1)); |
|
|
|
|
} |
|
|
|
|
personals.add(personal); |
|
|
|
|
} |
|
|
|
|
riskPersonalService.saveDistinct(personals); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void pullContradictionInfo() { |
|
|
|
|
LocalDateTime now = LocalDateTime.now(); |
|
|
|
|
List<Contradiction> list = gBaseSYRKXXRepository.getBaseMapper().selectContradiction(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
|
|
|
|
List<String> idCode = list.stream().map(Contradiction::getGmsfhm).distinct().toList(); |
|
|
|
|
// 切割
|
|
|
|
|
List<List<String>> idCodes = IntStream.range(0, (idCode.size() + 9999) / 10000) |
|
|
|
|
.mapToObj(i -> idCode.subList(i * 10000, Math.min((i + 1) * 10000, idCode.size()))) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
Map<String, Contradiction> map = list.stream().collect(Collectors.toMap(Contradiction::getGmsfhm, Function.identity(), (val, old)->val)); |
|
|
|
|
List<GBaseSYRKXX> xxList = getByIdCode(idCodes); |
|
|
|
|
|
|
|
|
|
Map<String, Byte[]> exist = new WeakHashMap<>(); |
|
|
|
|
List<RiskPersonal> personals = new ArrayList<>(); |
|
|
|
|
for (GBaseSYRKXX syrkxx : xxList) { |
|
|
|
|
if(exist.get(syrkxx.getGmsfhm()) != null) { |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
exist.put(syrkxx.getGmsfhm(), new Byte[0]); |
|
|
|
|
Contradiction contradiction = map.get(syrkxx.getGmsfhm()); |
|
|
|
|
personals.add(createPerson(syrkxx, Optional.of(contradiction).map(Contradiction::getMaxTime) |
|
|
|
|
.orElse(null) ,now.toLocalDate(), now)); |
|
|
|
|
} |
|
|
|
|
riskPersonalService.saveDistinct(personals); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private final SupExternalDepartRepository supExternalDepartRepository; |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void syncOrg() { |
|
|
|
|
List<GBaseSYRKXX> xxInfo = gBaseSYRKXXRepository.getBaseMapper().selectOrg(); |
|
|
|
|
|
|
|
|
|
List<SupExternalDepart> externalDeparts = new ArrayList<>(); |
|
|
|
|
Map<String, Integer> supExternalDepartMap = new WeakHashMap<>(); |
|
|
|
|
for (GBaseSYRKXX syrkxx : xxInfo) { |
|
|
|
|
SupExternalDepart externalDepart = new SupExternalDepart(); |
|
|
|
|
externalDepart.setExternalId(syrkxx.getSspcsdm()); |
|
|
|
|
externalDepart.setExternalName(syrkxx.getSspcsmc()); |
|
|
|
|
externalDepart.setSource("实有人口信息"); |
|
|
|
|
externalDeparts.add(externalDepart); |
|
|
|
|
supExternalDepartMap.put(syrkxx.getSspcsdm(), 1); |
|
|
|
|
} |
|
|
|
|
if (!externalDeparts.isEmpty()) { |
|
|
|
|
supExternalDepartRepository.saveBatch(externalDeparts); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通过身份证号查询实有人口 |
|
|
|
|
* |
|
|
|
|
* @param idCodes 身份证 |
|
|
|
|
* @return 实有人口信息 |
|
|
|
|
*/ |
|
|
|
|
List<GBaseSYRKXX> getByIdCode(List<List<String>> idCodes) { |
|
|
|
|
List<GBaseSYRKXX> tmp = new ArrayList<>(); |
|
|
|
|
for (int i = 0, len = idCodes.size(); i < len; i++) { |
|
|
|
|
tmp.addAll(gBaseSYRKXXRepository.list(new LambdaQueryWrapper<GBaseSYRKXX>() |
|
|
|
|
.select(GBaseSYRKXX::getGmsfhm, GBaseSYRKXX::getXm, GBaseSYRKXX::getLxdh, GBaseSYRKXX::getSspcsdm, GBaseSYRKXX::getSspcsmc) |
|
|
|
|
.in(GBaseSYRKXX::getGmsfhm, idCodes.get(i)))); |
|
|
|
|
log.info("证件查询进度:{}", i); |
|
|
|
|
} |
|
|
|
|
return tmp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 通过手机号查询实有人口信息 |
|
|
|
|
* |
|
|
|
|
* @param mobiles 手机号 |
|
|
|
|
* @return 查到的实有人口数据 |
|
|
|
|
*/ |
|
|
|
|
List<GBaseSYRKXX> getByMobiles(List<List<String>> mobiles) { |
|
|
|
|
List<GBaseSYRKXX> tmp = new ArrayList<>(); |
|
|
|
|
for (int i = 0, len = mobiles.size(); i < len; i++) { |
|
|
|
|
tmp.addAll(gBaseSYRKXXRepository.list(new LambdaQueryWrapper<GBaseSYRKXX>() |
|
|
|
|
.select(GBaseSYRKXX::getGmsfhm, GBaseSYRKXX::getXm, GBaseSYRKXX::getXlmc, GBaseSYRKXX::getLxdh, GBaseSYRKXX::getSspcsdm, GBaseSYRKXX::getSspcsmc) |
|
|
|
|
.in(GBaseSYRKXX::getLxdh, mobiles.get(i)))); |
|
|
|
|
log.info("手机号查询进度:{}", i); |
|
|
|
|
} |
|
|
|
|
return tmp; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
GBaseSYRKXX compare(List<GBaseSYRKXX> infos, String name) { |
|
|
|
|
GBaseSYRKXX info = null; |
|
|
|
|
for (GBaseSYRKXX gBaseSYRKXX : infos) { |
|
|
|
|
if (gBaseSYRKXX.getXm().equals(name)) { |
|
|
|
|
info = gBaseSYRKXX; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return info; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RiskPersonal createPerson(GBaseSYRKXX item, Date bjsj, LocalDate now, LocalDateTime time) { |
|
|
|
|
RiskPersonal person = new RiskPersonal(); |
|
|
|
|
person.setName(item.getXm()); |
|
|
|
|
person.setMobileNumber(item.getLxdh()); |
|
|
|
|
person.setControlDepartId(item.getSspcsdm()); |
|
|
|
|
person.setControlDepartName(item.getSspcsmc()); |
|
|
|
|
person.setControlDepartType(DepartType.OTHER.getType()); |
|
|
|
|
person.setIdCode(item.getGmsfhm().toUpperCase()); |
|
|
|
|
person.setCreateTime(time); |
|
|
|
|
person.setAge(IdCodeUtil.idCard2Age(person.getIdCode(), now)); |
|
|
|
|
person.setGender(IdCodeUtil.idCard2Gender(person.getIdCode())); |
|
|
|
|
person.setTags(Default.BIG_TAG_JJD); |
|
|
|
|
try { |
|
|
|
|
LocalDateTime controlTime = bjsj.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); |
|
|
|
|
person.setControlTime(controlTime); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.info("报警时间处理异常"); |
|
|
|
|
} |
|
|
|
|
if (person.getAge() == null || person.getGender() == null) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
if (person.getAge() <= 6 || person.getAge() >= 80) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
return person; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|