|
|
@@ -0,0 +1,90 @@
|
|
|
+package com.zksy.basicData.service;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
|
+import com.zksy.basicData.mapper.BaseTableMapper;
|
|
|
+import com.zksy.basicData.mapper.XcrAbnormalBusinessOperationsMapper;
|
|
|
+import com.zksy.basicData.mapper.XcrEBaseinfoMapper;
|
|
|
+import com.zksy.basicData.mapper.XcrOtherInfo36Mapper;
|
|
|
+import com.zksy.common.core.domain.AjaxResult;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import java.lang.reflect.ParameterizedType;
|
|
|
+import java.lang.reflect.Type;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class InformationService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private XcrAbnormalBusinessOperationsMapper xcrAbnormalBusinessOperationsMapper;
|
|
|
+ @Autowired
|
|
|
+ private XcrEBaseinfoMapper xcrEBaseinfoMapper;
|
|
|
+ @Autowired
|
|
|
+ private XcrOtherInfo36Mapper xcrOtherInfo36Mapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ThreadPoolTaskExecutor taskExecutor;
|
|
|
+ private List<BaseMapper<?>> mappers;
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ this.mappers = Arrays.asList(xcrAbnormalBusinessOperationsMapper, xcrEBaseinfoMapper,xcrOtherInfo36Mapper);
|
|
|
+ }
|
|
|
+ public AjaxResult queryByCreditCode(String creditCode) {
|
|
|
+ Map<String, List<?>> resultMap = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ List<CompletableFuture<Void>> futures = mappers.stream()
|
|
|
+ .map(mapper -> CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ List<?> result = queryFromMapper(mapper, creditCode);
|
|
|
+ String mapperName = getOriginalClassName(mapper);
|
|
|
+ resultMap.put(mapperName, result);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录异常日志
|
|
|
+ log.error("查询失败: " + mapper.getClass().getName(), e);
|
|
|
+ }
|
|
|
+ }, taskExecutor))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 等待所有异步任务完成
|
|
|
+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
|
|
|
+
|
|
|
+ return AjaxResult.success("查询成功", resultMap);
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> List<T> queryFromMapper(BaseMapper<T> mapper, String creditCode) {
|
|
|
+ try {
|
|
|
+ QueryWrapper<T> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("uni_code", creditCode);
|
|
|
+ List<T> ts = mapper.selectList(queryWrapper);
|
|
|
+ return ts;
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 记录异常日志
|
|
|
+ log.error("查询失败: " + mapper.getClass().getName(), e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private String getOriginalClassName(Object obj) {
|
|
|
+ Class<?>[] interfaces = obj.getClass().getInterfaces();
|
|
|
+ for (Class<?> iface : interfaces) {
|
|
|
+ String className = iface.getSimpleName();
|
|
|
+ // 去掉前缀 "Xcr" 和后缀 "Mapper"
|
|
|
+ if (className.startsWith("Xcr") && className.endsWith("Mapper")) {
|
|
|
+ return className.substring(3, className.length() - 5);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return obj.getClass().getSimpleName();
|
|
|
+ }
|
|
|
+}
|