feat: 信息中心获取 用户时补充不存在单位
This commit is contained in:
@@ -26,3 +26,6 @@ hs_err_pid*
|
||||
|
||||
src/main/resources/application.yaml
|
||||
src/main/resources/application-dev.yaml
|
||||
.vscode
|
||||
bin
|
||||
node-data-center-mock/
|
||||
@@ -26,7 +26,7 @@ public class Sys_unit extends BaseModel implements Serializable {
|
||||
@Name
|
||||
@Comment("ID")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 32)
|
||||
@PrevInsert(uu32 = true)
|
||||
@PrevInsert(uu32 = true, nullEffective = true)
|
||||
private String id;
|
||||
|
||||
@Column
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.budwk.app.sys.services;
|
||||
import com.budwk.app.base.service.BaseService;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@@ -15,6 +17,8 @@ public interface SysUnitService extends BaseService<Sys_unit> {
|
||||
*/
|
||||
void save(Sys_unit unit, String pid);
|
||||
|
||||
void saveBatch(List<Sys_unit> units, String pid);
|
||||
|
||||
/**
|
||||
* 级联删除单位及单位下用户
|
||||
*
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.budwk.app.sys.services.impl;
|
||||
|
||||
import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
@@ -14,18 +13,20 @@ 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.models.Sys_dict;
|
||||
import com.budwk.app.sys.models.Sys_unit;
|
||||
import com.budwk.app.sys.models.Sys_user;
|
||||
import com.budwk.app.sys.models.Sys_user_source;
|
||||
import com.budwk.app.sys.services.SysDataUserPullService;
|
||||
import com.budwk.app.sys.services.SysDictService;
|
||||
import com.budwk.app.sys.services.SysUnitService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
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.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;
|
||||
|
||||
@@ -40,6 +41,8 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
@Inject
|
||||
private SysDictService sysDictService;
|
||||
@Inject
|
||||
private SysUnitService sysUnitService;
|
||||
@Inject
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
public SysDataUserPullServiceImpl(Dao dao) {
|
||||
@@ -105,7 +108,8 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
long ts = System.currentTimeMillis();
|
||||
String sign = Base64.encode(DigestUtil.md5Hex(appId + secret + ts, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0026");
|
||||
// HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0026");
|
||||
HttpRequest httpRequest = HttpUtil.createPost("http://127.0.0.1:3001/cdsp/data-api/v2/DS0026");
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("appId", appId);
|
||||
httpRequest.header("timestamp", String.valueOf(ts));
|
||||
@@ -180,6 +184,7 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
log.info("--------------------");
|
||||
// 插入到数据库
|
||||
dao().insert(latestSourceList);
|
||||
syncUnits(latestSourceList);
|
||||
|
||||
return nowDate;
|
||||
} catch (Exception e) {
|
||||
@@ -187,6 +192,33 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
}
|
||||
}
|
||||
|
||||
private void syncUnits(List<Sys_user_source> userSources) {
|
||||
Map<String, String> unitIdNameMap = userSources.stream()
|
||||
.filter(source -> StrUtil.isAllNotBlank(source.getUnitId(), source.getUnitName()))
|
||||
.collect(Collectors.toMap(Sys_user_source::getUnitId, Sys_user_source::getUnitName,
|
||||
(existingValue, newValue) -> newValue));
|
||||
if (unitIdNameMap.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Set<String> existingUnitIds = dao().query(Sys_unit.class, Cnd.NEW()).stream()
|
||||
.map(Sys_unit::getId).collect(Collectors.toSet());
|
||||
List<Sys_unit> insertUnits = unitIdNameMap.entrySet().stream()
|
||||
.filter(entry -> !existingUnitIds.contains(entry.getKey()))
|
||||
.map(entry -> {
|
||||
Sys_unit unit = new Sys_unit();
|
||||
unit.setId(entry.getKey());
|
||||
unit.setUnitcode(entry.getKey());
|
||||
unit.setName(entry.getValue());
|
||||
unit.setParentId("1");
|
||||
unit.setUnitLevel(2);
|
||||
return unit;
|
||||
}).toList();
|
||||
if (!insertUnits.isEmpty()) {
|
||||
sysUnitService.saveBatch(insertUnits, "1");
|
||||
log.info("拉取数据后新增单位: {} 个", insertUnits.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
private void updateDict(List<Sys_user_source> userSources) {
|
||||
//判断是否要更新在职状态字典
|
||||
@@ -260,7 +292,8 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
long ts = System.currentTimeMillis();
|
||||
String sign = Base64.encode(DigestUtil.md5Hex(appId + secret + ts, CharsetUtil.CHARSET_UTF_8));
|
||||
|
||||
HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0040");
|
||||
// HttpRequest httpRequest = HttpUtil.createPost("https://sjzcpt.nnu.edu.cn/cdsp/data-api/v2/DS0040");
|
||||
HttpRequest httpRequest = HttpUtil.createPost("http://127.0.0.1:3001/cdsp/data-api/v2/DS0040");
|
||||
httpRequest.header("Content-Type", "application/json");
|
||||
httpRequest.header("appId", appId);
|
||||
httpRequest.header("timestamp", String.valueOf(ts));
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.nutz.lang.Strings;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheDefaults;
|
||||
import org.nutz.plugins.wkcache.annotation.CacheRemoveAll;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by wizzer on 2016/12/22.
|
||||
*/
|
||||
@@ -50,6 +52,40 @@ public class SysUnitServiceImpl extends BaseServiceImpl<Sys_unit> implements Sys
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public void saveBatch(List<Sys_unit> units, String pid) {
|
||||
if (units == null || units.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
String path = "";
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
Sys_unit parent = this.fetch(pid);
|
||||
if (parent != null) {
|
||||
path = parent.getPath();
|
||||
}
|
||||
}
|
||||
int nextPathIndex = 0;
|
||||
if (StrUtil.isNotBlank(path)) {
|
||||
String nextPath = getSubPath("sys_unit", "path", path);
|
||||
nextPathIndex = Integer.parseInt(nextPath.substring(path.length()));
|
||||
}
|
||||
for (Sys_unit unit : units) {
|
||||
if (StrUtil.isNotBlank(path) && nextPathIndex <= 9999) {
|
||||
// 批量入库前按序分配路径,避免重复查询产生相同路径。
|
||||
unit.setPath(path + String.format("%04d", nextPathIndex++));
|
||||
} else {
|
||||
unit.setPath(null);
|
||||
}
|
||||
unit.setId(unit.getUnitcode());
|
||||
unit.setParentId(pid);
|
||||
}
|
||||
dao().fastInsert(units);
|
||||
if (!Strings.isEmpty(pid)) {
|
||||
this.update(Chain.make("hasChildren", true), Cnd.where("id", "=", pid));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 级联删除单位
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user