commit
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.base.config.DataCenterProperties;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.models.Sys_data_dict;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.services.SysDataDictPullService;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:SysDataDictPullServiceImpl
|
||||
* @Date 2025/9/22 11:37
|
||||
* @注释
|
||||
*/
|
||||
@Slf4j
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysDataDictPullServiceImpl extends BaseServiceImpl<Sys_dict> implements SysDataDictPullService {
|
||||
|
||||
@Inject
|
||||
private DataCenterProperties dcPro;
|
||||
@Inject
|
||||
private SysDictService dictService;
|
||||
|
||||
// code
|
||||
private final static String KEY_PREFIX = "user_";
|
||||
|
||||
public SysDataDictPullServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void pullDataDict() {
|
||||
Map<String, String> urls = dcPro.getUrls();
|
||||
List<String> list = urls.keySet().stream().filter(o -> o.startsWith(KEY_PREFIX.toUpperCase())).toList();
|
||||
|
||||
List<Sys_data_dict> dataDictList = new ArrayList<>();
|
||||
|
||||
for (String key : list) {
|
||||
// 获取配置
|
||||
DataCenterProperties.Credential credential = dcPro.credential(key);
|
||||
String url = credential.getUrl();
|
||||
String token = credential.getToken();
|
||||
|
||||
// 请求数据
|
||||
HttpRequest httpRequest = HttpUtil.createPost(url);
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("X-H3C-TOKEN", token);
|
||||
httpRequest.body(JSONUtil.toJsonStr(Map.of()));
|
||||
|
||||
String resBody = httpRequest.execute().body();
|
||||
JSONObject jsonBody = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (jsonBody.getInt("code") != 200) {
|
||||
log.error("获取{}字典数据失败,错误码: {};错误原因:{}", key, jsonBody.getInt("code"), jsonBody.getStr("msg"));
|
||||
}
|
||||
List<NutMap> data = Json.fromJsonAsList(NutMap.class, jsonBody.getStr("data"));
|
||||
|
||||
// 先删除
|
||||
Sys_dict sysDict = dao().fetch(Sys_dict.class, Cnd.where(Sys_dict::getCode, "=", key));
|
||||
dao().clear(Sys_dict.class, Cnd.where(Sys_dict::getParentId, "=", sysDict.getId()));
|
||||
|
||||
// 组合数据
|
||||
data.forEach(o -> {
|
||||
Sys_dict dict = new Sys_dict();
|
||||
dict.setParentId(sysDict.getId());
|
||||
|
||||
dict.setPath(dictService.getSubPath("sys_dict", "path", sysDict.getPath()));
|
||||
dict.setName(o.getString("xbname"));
|
||||
dict.setCode(o.getString("xbname"));
|
||||
dict.setDisabled(false);
|
||||
dict.setHasChildren(false);
|
||||
dao().insert(dict);
|
||||
|
||||
Sys_data_dict sysDataDict = new Sys_data_dict();
|
||||
sysDataDict.setParentCode(key);
|
||||
sysDataDict.setCode(o.getString("xbcode"));
|
||||
sysDataDict.setName(o.getString("xbname"));
|
||||
|
||||
dataDictList.add(sysDataDict);
|
||||
|
||||
});
|
||||
|
||||
dao().insert(dataDictList);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.base.config.DataCenterProperties;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.enums.Api2UnitFiledMap;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.services.SysDataUnitPullService;
|
||||
import com.budwk.app.sys.utils.DataCenterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @version 1.0
|
||||
* @Author zzr
|
||||
* @name:SysDataUnitPullServiceImpl
|
||||
* @Date 2025/9/15 17:52
|
||||
* @注释
|
||||
*/
|
||||
@Slf4j
|
||||
@IocBean(args = {"refer:dao"})
|
||||
public class SysDataUnitPullServiceImpl extends BaseServiceImpl<Sys_unit> implements SysDataUnitPullService {
|
||||
|
||||
@Inject
|
||||
private DataCenterProperties dcPro;
|
||||
|
||||
public SysDataUnitPullServiceImpl(Dao dao) {
|
||||
super(dao);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void updateUnits() {
|
||||
Sql sql = Sqls.create("select id from sys_unit group by id");
|
||||
sql.setCallback(Sqls.callback.strList());
|
||||
dao().execute(sql);
|
||||
List<String> unitIds = sql.getList(String.class);
|
||||
updateUnits(unitIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取单位数据
|
||||
*/
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void updateUnits(List<String> unitIds) {
|
||||
// 获取配置
|
||||
DataCenterProperties.Credential credential = dcPro.credential("unit");
|
||||
String url = credential.getUrl();
|
||||
String token = credential.getToken();
|
||||
|
||||
// 请求数据
|
||||
HttpRequest httpRequest = HttpUtil.createPost(url);
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("X-H3C-TOKEN", token);
|
||||
httpRequest.body(JSONUtil.toJsonStr(Map.of()));
|
||||
|
||||
String resBody = httpRequest.execute().body();
|
||||
JSONObject jsonBody = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (jsonBody.getInt("code") != 200) {
|
||||
throw new BaseException("获取单位数据失败,错误码: " + jsonBody.getInt("code") + ";错误原因:" + jsonBody.getStr("msg"));
|
||||
}
|
||||
|
||||
// 需要新增的单位
|
||||
List<Sys_unit> insertList = new ArrayList<>();
|
||||
// 需要更新的单位
|
||||
List<Sys_unit> updateList = new ArrayList<>();
|
||||
|
||||
// 拉取过来的数据,全部的单位,一万四千多条,这里只保留 “部门类”
|
||||
List<JSONObject> data = jsonBody.getJSONArray("data").stream()
|
||||
.map(o -> (JSONObject) o)
|
||||
.filter(row -> StrUtil.isNotBlank(row.getStr("bmlb")))
|
||||
.toList();
|
||||
|
||||
Map<String, String> api2db = Arrays.stream(Api2UnitFiledMap.values())
|
||||
.collect(Collectors.toMap(e -> e.apiField, e -> e.dbColumn));
|
||||
for (JSONObject row : data) {
|
||||
Sys_unit unit = DataCenterUtil.mapJsonToBean(row, Sys_unit.class, api2db);
|
||||
unit.setUnitcode(unit.getId());
|
||||
unit.setUnitTypeCode(unit.getUnitType().contains("部门") ? 1 : 0);
|
||||
|
||||
if (unitIds.contains(unit.getId())) {
|
||||
// 存在则更新
|
||||
updateList.add(unit);
|
||||
} else {
|
||||
// 不存在则新增
|
||||
insertList.add(unit);
|
||||
}
|
||||
}
|
||||
log.info("本次拉取单位数据,新增{}条,更新{}条", insertList.size(), updateList.size());
|
||||
dao().insert(insertList);
|
||||
dao().update(updateList);
|
||||
}
|
||||
}
|
||||
+14
-34
@@ -9,7 +9,6 @@ import cn.hutool.http.HtmlUtil;
|
||||
import com.budwk.app.base.constant.RoleConstant;
|
||||
import com.budwk.app.base.event.role.RoleEventMsg;
|
||||
import com.budwk.app.base.event.role.RoleEventPublisher;
|
||||
import com.budwk.app.base.utils.ConditionGroupUtil;
|
||||
import com.budwk.app.base.utils.PwdUtil;
|
||||
import com.budwk.app.sys.annotation.DataCenterColumn;
|
||||
import com.budwk.app.sys.models.*;
|
||||
@@ -37,7 +36,10 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -153,7 +155,7 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
|
||||
// 处理复杂条件
|
||||
if (updateParam.getConditionGroup() != null) {
|
||||
cnd = ConditionGroupUtil.applyConditionGroup(cnd, updateParam.getConditionGroup());
|
||||
// cnd = ConditionGroupUtil.applyConditionGroup(cnd, updateParam.getConditionGroup());
|
||||
}
|
||||
|
||||
List<Sys_user_source> sources = dao.query(Sys_user_source.class, cnd.groupBy("loginname"));
|
||||
@@ -184,42 +186,20 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
u.setSalt(salt);
|
||||
u.setPassword(PwdUtil.getPassword(PwdUtil.generate(12), salt));
|
||||
|
||||
// 检查是否符合会员条件
|
||||
boolean shouldBeMember = checkMembershipEligibility(
|
||||
source.getUserState(),
|
||||
source.getPreparedBy(),
|
||||
source.getPostDoctoralJoinDate()
|
||||
);
|
||||
|
||||
if (shouldBeMember) {
|
||||
u.setMember(true);
|
||||
if (u.getMember()) {
|
||||
addMemberUserIds.add(u.getId());
|
||||
} else {
|
||||
u.setMember(false);
|
||||
}
|
||||
|
||||
needInitUserList.add(u);
|
||||
} else {
|
||||
// 修改现有用户
|
||||
u.setId(user.getId());
|
||||
|
||||
// 检查会员资格
|
||||
boolean shouldBeMember = checkMembershipEligibility(
|
||||
source.getUserState(),
|
||||
source.getPreparedBy(),
|
||||
source.getPostDoctoralJoinDate()
|
||||
);
|
||||
|
||||
// 更新会员状态
|
||||
boolean currentIsMember = user.getMember() != null && user.getMember();
|
||||
|
||||
if (shouldBeMember && !currentIsMember) {
|
||||
// 添加会员
|
||||
u.setMember(true);
|
||||
if (!currentIsMember) {
|
||||
addMemberUserIds.add(user.getId());
|
||||
} else if (!shouldBeMember && currentIsMember) {
|
||||
// 移除会员
|
||||
u.setMember(false);
|
||||
} else{
|
||||
removeMemberUserIds.add(user.getId());
|
||||
}
|
||||
|
||||
@@ -431,9 +411,9 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
// 如果值不相等,记录变更
|
||||
if (!ObjectUtil.equals(sourceValue, userValue)) {
|
||||
NutMap change = NutMap.NEW();
|
||||
change.put("name", mapping.name);
|
||||
change.put("fieldName", mapping.name);
|
||||
change.put("field", mapping.field.getName());
|
||||
change.put("value", userValue == null ? "" : userValue.toString());
|
||||
change.put("sourceValue", userValue == null ? "" : userValue.toString());
|
||||
change.put("newValue", sourceValue == null ? "" : sourceValue.toString());
|
||||
changeList.add(change);
|
||||
}
|
||||
@@ -461,9 +441,9 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
if (!ObjectUtil.equals(user.getUnitId(), source.getUnitId())) {
|
||||
changeTypes.add(MemberChangeType.UNIT_CHANGE.name());
|
||||
NutMap change = NutMap.NEW();
|
||||
change.put("name", "单位");
|
||||
change.put("fieldName", "单位");
|
||||
change.put("field", "unitId");
|
||||
change.put("value", user.getUnitId());
|
||||
change.put("sourceValue", user.getUnitId());
|
||||
change.put("newValue", source.getUnitId());
|
||||
changeList.add(change);
|
||||
}
|
||||
@@ -475,8 +455,8 @@ public class SysDataUserAllUpdateServiceImpl implements SysDataUserUpdateService
|
||||
|
||||
// 生成变更信息描述
|
||||
String changeInfos = changeList.stream()
|
||||
.map(v -> v.getString("name") + ":" +
|
||||
HtmlUtil.cleanHtmlTag(v.getString("value")) + "→" +
|
||||
.map(v -> v.getString("fieldName") + ":" +
|
||||
HtmlUtil.cleanHtmlTag(v.getString("sourceValue")) + "→" +
|
||||
HtmlUtil.cleanHtmlTag(v.getString("newValue")))
|
||||
.collect(Collectors.joining(";"));
|
||||
|
||||
|
||||
@@ -1,35 +1,46 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.IdcardUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.http.Header;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.budwk.app.base.config.DataCenterProperties;
|
||||
import com.budwk.app.base.exception.BaseException;
|
||||
import com.budwk.app.base.service.impl.BaseServiceImpl;
|
||||
import com.budwk.app.sys.annotation.DataCenterColumn;
|
||||
import com.budwk.app.sys.enums.Api2FinanceFiledMap;
|
||||
import com.budwk.app.sys.models.Sys_data_dict;
|
||||
import com.budwk.app.sys.models.Sys_dict;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.models.Sys_user_source;
|
||||
import com.budwk.app.sys.services.SysDataUnitPullService;
|
||||
import com.budwk.app.sys.services.SysDataUserPullService;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.utils.DataCenterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.aop.interceptor.ioc.TransAop;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
import org.nutz.dao.sql.Sql;
|
||||
import org.nutz.ioc.aop.Aop;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.json.Json;
|
||||
import org.nutz.lang.util.NutMap;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -40,6 +51,10 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private DataCenterProperties dataCenterProperties;
|
||||
@Inject
|
||||
private SysDataUnitPullService sysDataUnitPullService;
|
||||
@Inject
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
public SysDataUserPullServiceImpl(Dao dao) {
|
||||
@@ -52,10 +67,12 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
private static class FieldMapping {
|
||||
final Field field;
|
||||
final String key;
|
||||
final String dict;
|
||||
|
||||
FieldMapping(Field field, String key) {
|
||||
FieldMapping(Field field, String key, String dict) {
|
||||
this.field = field;
|
||||
this.key = key;
|
||||
this.dict = dict;
|
||||
field.setAccessible(true);
|
||||
}
|
||||
}
|
||||
@@ -77,7 +94,7 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
for (Field field : fields) {
|
||||
DataCenterColumn annotation = field.getAnnotation(DataCenterColumn.class);
|
||||
if (annotation != null) {
|
||||
mappings.add(new FieldMapping(field, annotation.key()));
|
||||
mappings.add(new FieldMapping(field, annotation.key(), annotation.dict()));
|
||||
}
|
||||
}
|
||||
fieldMappings = mappings;
|
||||
@@ -88,58 +105,48 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Date pull() {
|
||||
try {
|
||||
// 博士后进站日期数据
|
||||
Map<String, Date> doctoralData = pullPostDoctoral();
|
||||
// 获取数据中心的字典
|
||||
List<Sys_data_dict> dataDictList = dao().query(Sys_data_dict.class, Cnd.NEW());
|
||||
// 字典码表Map,key为父级编码,value为子级字典列表
|
||||
Map<String, List<Sys_data_dict>> dataDictMap = dataDictList.stream().collect(Collectors.groupingBy(Sys_data_dict::getParentCode));
|
||||
|
||||
Date nowDate = new Date();
|
||||
String appId = "1926887238437818370";
|
||||
String secret = "32df31fcf4fc43f9a647ee1f47134f36";
|
||||
Map<String, NutMap> financeUserMap = pullFinance();
|
||||
// // 博士后进站日期数据
|
||||
// Map<String, Date> doctoralData = pullPostDoctoral();
|
||||
|
||||
// 获取配置文件 接口地址 和 token
|
||||
DataCenterProperties.Credential credential = dataCenterProperties.credential("teacher");
|
||||
String url = credential.getUrl();
|
||||
String token = credential.getToken();
|
||||
|
||||
// 请求数据
|
||||
HttpRequest httpRequest = HttpUtil.createPost(url);
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("X-H3C-TOKEN", token);
|
||||
httpRequest.body(JSONUtil.toJsonStr(Map.of()));
|
||||
|
||||
String resBody = httpRequest.execute().body();
|
||||
JSONObject jsonBody = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (jsonBody.getInt("code") != 200) {
|
||||
throw new BaseException("获取人员数据失败,错误码: " + jsonBody.getInt("code") + ";错误原因:" + jsonBody.getStr("msg"));
|
||||
}
|
||||
|
||||
List<JSONObject> rawDataList = new ArrayList<>();
|
||||
int skip = 0;
|
||||
int totalCount = 0;
|
||||
boolean firstRequest = true;
|
||||
do {
|
||||
long ts = System.currentTimeMillis();
|
||||
String sign = Base64.encode(DigestUtil.md5Hex(appId + secret + ts, CharsetUtil.CHARSET_UTF_8));
|
||||
JSONArray data = jsonBody.getJSONArray("data");
|
||||
|
||||
HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0026");
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("appId", appId);
|
||||
httpRequest.header("timestamp", String.valueOf(ts));
|
||||
httpRequest.header("sign", sign);
|
||||
if (!data.isEmpty()) {
|
||||
// 先收集所有原始数据
|
||||
rawDataList = data.stream().map(v -> (JSONObject) v).toList();
|
||||
log.info("数据拉取进度: {}/{}", rawDataList.size(), jsonBody.getInt("total"));
|
||||
} else {
|
||||
log.warn("当前未获取到数据");
|
||||
}
|
||||
|
||||
HashMap<String, Object> reqBody = new HashMap<>();
|
||||
reqBody.put("$count", true);
|
||||
reqBody.put("$skip", skip);
|
||||
reqBody.put("$top", 1000);
|
||||
// reqBody.put("$filter", "yrfsmc eq '事业编制' or yrfsmc eq '校聘合同制' or yrfsmc eq '新人事代理' or yrfsmc eq '博士后' or yrfsmc eq '劳动合同'");
|
||||
|
||||
httpRequest.body(JSONUtil.toJsonStr(reqBody));
|
||||
String resBody = httpRequest.execute().body();
|
||||
|
||||
JSONObject entries = JSONUtil.parseObj(resBody);
|
||||
|
||||
if (firstRequest) {
|
||||
totalCount = entries.getInt("@odata.count", 0);
|
||||
firstRequest = false;
|
||||
}
|
||||
|
||||
JSONArray value = entries.getJSONArray("value");
|
||||
|
||||
if (!value.isEmpty()) {
|
||||
// 先收集所有原始数据
|
||||
List<JSONObject> currentBatch = value.stream().map(v -> (JSONObject) v).toList();
|
||||
rawDataList.addAll(currentBatch);
|
||||
skip += currentBatch.size();
|
||||
log.info("数据拉取进度: {}/{}", rawDataList.size(), totalCount);
|
||||
} else {
|
||||
log.warn("当前批次未获取到数据,skip={}", skip);
|
||||
break;
|
||||
}
|
||||
} while (skip < totalCount);
|
||||
Date nowDate = new Date();
|
||||
|
||||
// 赋值
|
||||
List<Sys_user_source> latestSourceList = rawDataList.stream().map(raw -> {
|
||||
@@ -150,12 +157,25 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
try {
|
||||
// 根据字段类型设置值
|
||||
if (mapping.field.getType() == String.class) {
|
||||
// 特殊处理性别字段
|
||||
if (mapping.field.getName().equals("sex")) {
|
||||
String xbmc = raw.getStr(mapping.key);
|
||||
mapping.field.set(sysUser, StrUtil.equals("男性", xbmc) ? "男" : StrUtil.equals("女性", xbmc) ? "女" : null);
|
||||
|
||||
if (StrUtil.isNotBlank(mapping.dict)) {
|
||||
Sys_data_dict sysDataDict = dataDictMap.get(mapping.dict).stream()
|
||||
.filter(v -> raw.getStr(mapping.key)
|
||||
.equals(v.getCode())).findFirst().orElse(new Sys_data_dict());
|
||||
mapping.field.set(sysUser, sysDataDict.getName());
|
||||
} else {
|
||||
mapping.field.set(sysUser, raw.getStr(mapping.key));
|
||||
// 特殊处理 根据身份证号获取性别和出生年月
|
||||
if ("sfzjh".equals(mapping.field.getName())) {
|
||||
String idCard = raw.getStr(mapping.key);
|
||||
if (StrUtil.isNotBlank(idCard)) {
|
||||
int gender = IdcardUtil.getGenderByIdCard(idCard);
|
||||
// 性别(1 : 男 , 0 : 女)
|
||||
sysUser.setSex(gender == 1 ? "男" : "女");
|
||||
mapping.field.set(sysUser, raw.getStr(mapping.key));
|
||||
}
|
||||
} else {
|
||||
mapping.field.set(sysUser, raw.getStr(mapping.key));
|
||||
}
|
||||
}
|
||||
} else if (mapping.field.getType() == Date.class) {
|
||||
mapping.field.set(sysUser, raw.getDate(mapping.key));
|
||||
@@ -165,22 +185,40 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
}
|
||||
}
|
||||
|
||||
// 设置博士后的进站日期
|
||||
if (doctoralData.containsKey(sysUser.getLoginname())) {
|
||||
sysUser.setPostDoctoralJoinDate(doctoralData.get(sysUser.getLoginname()));
|
||||
// 设置单位相关信息
|
||||
sysUser.setUnitId(raw.getStr("dwh"));
|
||||
sysUser.setPullTime(nowDate);
|
||||
|
||||
// 判断财务信息有没有值,
|
||||
if (financeUserMap.containsKey(sysUser.getLoginname())) {
|
||||
NutMap nutMap = financeUserMap.get(sysUser.getLoginname());
|
||||
sysUser.setMember(true);
|
||||
sysUser.setWelfareMember(true);
|
||||
sysUser.setPreparationMemberFee(BigDecimal.valueOf(nutMap.getDouble("preparationMemberFee")));
|
||||
sysUser.setContractMemberFee(BigDecimal.valueOf(nutMap.getDouble("contractMemberFee")));
|
||||
} else {
|
||||
sysUser.setMember(false);
|
||||
sysUser.setWelfareMember(false);
|
||||
}
|
||||
|
||||
// 设置单位相关信息
|
||||
sysUser.setUnitName(raw.getStr("dwmc"));
|
||||
sysUser.setUnitId(raw.getStr("dwdm"));
|
||||
sysUser.setPullTime(nowDate);
|
||||
return sysUser;
|
||||
}).toList();
|
||||
|
||||
log.info("--------------------");
|
||||
log.info("用户数据初始化完成,等待插入,当前数据条数{}", latestSourceList.size());
|
||||
// 插入到数据库
|
||||
dao().insert(latestSourceList);
|
||||
|
||||
// 人员的单位数据和数据库的单位数据比较,如果人员里面有单位不存在,去更新单位数据
|
||||
List<String> sourceUnitIds = latestSourceList.stream().map(Sys_user_source::getUnitId).distinct().toList();
|
||||
Sql sql = Sqls.create("select id from sys_unit group by id");
|
||||
sql.setCallback(Sqls.callback.strList());
|
||||
dao().execute(sql);
|
||||
List<String> unitIds = sql.getList(String.class);
|
||||
|
||||
if (!new HashSet<>(unitIds).containsAll(sourceUnitIds)) {
|
||||
log.info("单位需要更新,正在同步更新");
|
||||
sysDataUnitPullService.updateUnits(unitIds);
|
||||
}
|
||||
return nowDate;
|
||||
} catch (Exception e) {
|
||||
throw new BaseException("数据拉取失败,{}", e.getMessage());
|
||||
@@ -346,4 +384,74 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
""");
|
||||
return listMap(sql);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, NutMap> pullFinance() {
|
||||
// 获取配置文件 接口地址 和 token
|
||||
DataCenterProperties.Credential credential = dataCenterProperties.credential("finance");
|
||||
String url = credential.getUrl();
|
||||
String token = credential.getToken();
|
||||
|
||||
List<JSONObject> rawDataList = new ArrayList<>();
|
||||
String year = String.valueOf(DateUtil.thisYear());
|
||||
String month = String.valueOf(DateUtil.thisMonth() + 1);
|
||||
|
||||
int pageNum = 1;
|
||||
int pageSize = 1000;
|
||||
int totalPages = 1;
|
||||
int totalCount = 0;
|
||||
do {
|
||||
HttpRequest httpRequest = HttpUtil.createPost(url);
|
||||
httpRequest.header(Header.CONTENT_TYPE, "application/json");
|
||||
httpRequest.header("Accept-Encoding", "gzip, deflate, br");
|
||||
httpRequest.header("X-H3C-TOKEN", token);
|
||||
Map<String, Object> reqBody = Map.of(
|
||||
"nf", year,
|
||||
"yf", month,
|
||||
"pageNum", pageNum,
|
||||
"pageSize", pageSize
|
||||
);
|
||||
httpRequest.body(JSONUtil.toJsonStr(reqBody));
|
||||
|
||||
JSONObject resp = JSONUtil.parseObj(httpRequest.execute().body());
|
||||
if (resp.getInt("code") != 0) {
|
||||
throw new BaseException("获取财务数据失败,错误码: " + resp.getInt("code") + ";错误原因:" + resp.getStr("msg"));
|
||||
}
|
||||
|
||||
JSONObject data = resp.getJSONObject("data");
|
||||
if (pageNum == 1) {
|
||||
totalCount = data.getInt("total", 0);
|
||||
// totalPages = data.getInt("pages", 0);
|
||||
totalPages = (int) Math.ceil((double) totalCount / pageSize);
|
||||
}
|
||||
|
||||
JSONArray records = data.getJSONArray("records");
|
||||
if (CollUtil.isNotEmpty(records)) {
|
||||
rawDataList.addAll(records.stream().map(v -> (JSONObject) v).toList());
|
||||
log.info("数据拉取进度: {}/{}", rawDataList.size(), totalCount);
|
||||
}
|
||||
pageNum++; // 只加页码
|
||||
} while (pageNum <= totalPages);
|
||||
|
||||
// 接口数据输出
|
||||
log.info("数据拉取结果: {}", rawDataList);
|
||||
|
||||
// 最后结果数据
|
||||
Map<String, NutMap> result = new HashMap<>();
|
||||
|
||||
Map<String, String> api2db = Arrays.stream(Api2FinanceFiledMap.values())
|
||||
.collect(Collectors.toMap(e -> e.apiField, e -> e.dbColumn));
|
||||
|
||||
for (JSONObject row : rawDataList) {
|
||||
NutMap nutMap = DataCenterUtil.mapJsonToBean(row, NutMap.class, api2db);
|
||||
result.put(nutMap.getString("loginname"), nutMap);
|
||||
}
|
||||
|
||||
// 输出结果
|
||||
log.info("财务数据拉取转换结果: {}", result);
|
||||
|
||||
log.info("数据拉取完成,共拉取 {} 条数据", result.size());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user