commit
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.budwk</groupId>
|
||||
<artifactId>zhgh_hdc</artifactId>
|
||||
<artifactId>mini</artifactId>
|
||||
<version>5.6.0-plus</version>
|
||||
<build>
|
||||
<resources>
|
||||
|
||||
@@ -48,6 +48,7 @@ import javax.validation.Valid;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@IocBean
|
||||
@@ -215,6 +216,41 @@ public class SysUnionController {
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("sys.manager.union")
|
||||
@ApiModelProperty("校工会人员角色选项")
|
||||
public Result schoolUnionRoleOptions() {
|
||||
return Result.success(roleOptionsByDictCode("SCHOOL_UNION_ROLES"));
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("sys.manager.union")
|
||||
@ApiModelProperty("分工会人员角色选项")
|
||||
public Result branchUnionRoleOptions() {
|
||||
return Result.success(roleOptionsByDictCode("BRANCH_UNION_ROLES"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据角色字典获取下拉选项,只保留系统角色表中存在的角色编码。
|
||||
*/
|
||||
private List<Sys_dict> roleOptionsByDictCode(String dictCode) {
|
||||
List<Sys_dict> dictRoles = sysDictService.getSubListByCode(dictCode);
|
||||
if (Lang.isEmpty(dictRoles)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<String> roleCodes = dictRoles.stream().map(Sys_dict::getCode).filter(StrUtil::isNotBlank).toList();
|
||||
if (Lang.isEmpty(roleCodes)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Set<String> existRoleCodes = sysRoleService.query(Cnd.where(Sys_role::getCode, "in", roleCodes))
|
||||
.stream()
|
||||
.map(Sys_role::getCode)
|
||||
.collect(Collectors.toSet());
|
||||
return dictRoles.stream()
|
||||
.filter(dict -> existRoleCodes.contains(dict.getCode()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
@At
|
||||
@SaCheckPermission("sys.manager.union.schoolOfficer")
|
||||
@ApiModelProperty("添加校工会人员角色")
|
||||
|
||||
@@ -137,13 +137,13 @@ public class Sys_user extends BaseModel implements Serializable {
|
||||
@Column
|
||||
@Comment("职称")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@DataCenterColumn(name = "职称", key = "DQZC", dict = "USER_PROFESSIONAL_TITLE")
|
||||
@DataCenterColumn(name = "职称", key = "zyjszwrzzgjb", dict = "USER_PROFESSIONAL_TITLE")
|
||||
private String professionalTitle;
|
||||
|
||||
@Column
|
||||
@Comment("职级")
|
||||
@ColDefine(type = ColType.VARCHAR, width = 50)
|
||||
@DataCenterColumn(name = "取得职称等级码", key = "QDZCDJM", dict = "USER_PROFESSIONAL_LEVEL")
|
||||
@DataCenterColumn(name = "取得职称等级码", key = "xzzwrzjb", dict = "USER_PROFESSIONAL_LEVEL")
|
||||
private String professionalLevel;
|
||||
|
||||
@Column
|
||||
|
||||
@@ -27,6 +27,7 @@ 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.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.dao.Dao;
|
||||
import org.nutz.dao.Sqls;
|
||||
@@ -107,10 +108,6 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
@Aop(TransAop.READ_COMMITTED)
|
||||
public Date pull() {
|
||||
try {
|
||||
// 获取数据中心的字典
|
||||
List<Sys_data_dict> dataDictList = dao().query(Sys_data_dict.class, Cnd.NEW());
|
||||
Map<String, List<Sys_data_dict>> dataDictMap = dataDictList.stream().collect(Collectors.groupingBy(Sys_data_dict::getParentCode));
|
||||
|
||||
// 请求人员数据
|
||||
HttpRequest httpRequest = HttpUtil.createGet("http://211.82.200.130:10003/api/139/1/5000");
|
||||
|
||||
@@ -134,6 +131,13 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
log.warn("当前未获取到数据");
|
||||
}
|
||||
|
||||
// 根据本次拉取的人员字段原始值同步信息中心字典和系统业务字典
|
||||
syncUserPullDict(rawDataList);
|
||||
|
||||
// 获取同步后的数据中心字典,用于本次人员字段映射
|
||||
List<Sys_data_dict> dataDictList = dao().query(Sys_data_dict.class, Cnd.NEW());
|
||||
Map<String, List<Sys_data_dict>> dataDictMap = dataDictList.stream().collect(Collectors.groupingBy(Sys_data_dict::getParentCode));
|
||||
|
||||
Date nowDate = new Date();
|
||||
|
||||
List<Sys_user_source> latestSourceList = rawDataList.stream().map(raw -> {
|
||||
@@ -152,7 +156,12 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
String finalValue = value;
|
||||
Sys_data_dict sysDataDict = dictList.stream()
|
||||
.filter(v -> finalValue != null && finalValue.equals(v.getCode())).findFirst().orElse(new Sys_data_dict());
|
||||
mapping.field.set(sysUser, sysDataDict.getName());
|
||||
if (StrUtil.isNotBlank(sysDataDict.getName())) {
|
||||
mapping.field.set(sysUser, sysDataDict.getName());
|
||||
} else {
|
||||
mapping.field.set(sysUser, value);
|
||||
log.warn("未找到字典编码:{},字段:{},使用原始值:{}", mapping.dict, mapping.key, value);
|
||||
}
|
||||
} else {
|
||||
// 如果找不到对应的字典,直接使用原始值
|
||||
mapping.field.set(sysUser, value);
|
||||
@@ -253,6 +262,103 @@ public class SysDataUserPullServiceImpl extends BaseServiceImpl<Sys_user_source>
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据本次人员拉取结果同步字典,字典编码和值都采用信息中心返回的原始字段值。
|
||||
*/
|
||||
private void syncUserPullDict(List<JSONObject> rawDataList) {
|
||||
Map<String, LinkedHashSet<String>> dictValueMap = new LinkedHashMap<>();
|
||||
for (FieldMapping mapping : getFieldMappings()) {
|
||||
if (StrUtil.isBlank(mapping.dict)) {
|
||||
continue;
|
||||
}
|
||||
LinkedHashSet<String> values = dictValueMap.computeIfAbsent(mapping.dict, key -> new LinkedHashSet<>());
|
||||
for (JSONObject raw : rawDataList) {
|
||||
String value = raw.getStr(mapping.key);
|
||||
if (StrUtil.isNotBlank(value)) {
|
||||
values.add(value.trim());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Map.Entry<String, LinkedHashSet<String>> entry : dictValueMap.entrySet()) {
|
||||
syncDataDict(entry.getKey(), entry.getValue());
|
||||
syncSystemDict(entry.getKey(), entry.getValue());
|
||||
}
|
||||
sysDictService.clearCache();
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步 sys_data_dict,拉取值不存在时删除旧字典内容。
|
||||
*/
|
||||
private void syncDataDict(String parentCode, Set<String> values) {
|
||||
Set<String> sourceValues = new LinkedHashSet<>(values);
|
||||
List<Sys_data_dict> existingDicts = dao().query(Sys_data_dict.class, Cnd.where(Sys_data_dict::getParentCode, "=", parentCode));
|
||||
|
||||
if (sourceValues.isEmpty()) {
|
||||
dao().clear(Sys_data_dict.class, Cnd.where(Sys_data_dict::getParentCode, "=", parentCode));
|
||||
return;
|
||||
}
|
||||
|
||||
dao().clear(Sys_data_dict.class, Cnd.where(Sys_data_dict::getParentCode, "=", parentCode).and(Sys_data_dict::getCode, "not in", sourceValues));
|
||||
|
||||
Set<String> existingCodes = existingDicts.stream()
|
||||
.map(Sys_data_dict::getCode)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
for (String value : sourceValues) {
|
||||
if (existingCodes.contains(value)) {
|
||||
dao().update(Sys_data_dict.class,
|
||||
Chain.make("name", value),
|
||||
Cnd.where(Sys_data_dict::getParentCode, "=", parentCode).and(Sys_data_dict::getCode, "=", value));
|
||||
} else {
|
||||
Sys_data_dict dict = new Sys_data_dict();
|
||||
dict.setParentCode(parentCode);
|
||||
dict.setCode(value);
|
||||
dict.setName(value);
|
||||
dao().insert(dict);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 同步 sys_dict 子级字典,子级 code 和 name 均采用拉取值。
|
||||
*/
|
||||
private void syncSystemDict(String parentCode, Set<String> values) {
|
||||
Sys_dict parentDict = dao().fetch(Sys_dict.class, Cnd.where(Sys_dict::getCode, "=", parentCode));
|
||||
if (parentDict == null) {
|
||||
log.warn("系统字典父编码不存在:{},跳过 sys_dict 同步", parentCode);
|
||||
return;
|
||||
}
|
||||
|
||||
Set<String> sourceValues = new LinkedHashSet<>(values);
|
||||
List<Sys_dict> existingDicts = dao().query(Sys_dict.class, Cnd.where(Sys_dict::getParentId, "=", parentDict.getId()));
|
||||
|
||||
for (Sys_dict existingDict : existingDicts) {
|
||||
if (!sourceValues.contains(existingDict.getCode())) {
|
||||
sysDictService.deleteAndChild(existingDict);
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> existingCodes = existingDicts.stream()
|
||||
.map(Sys_dict::getCode)
|
||||
.filter(StrUtil::isNotBlank)
|
||||
.collect(Collectors.toSet());
|
||||
for (String value : sourceValues) {
|
||||
if (existingCodes.contains(value)) {
|
||||
dao().update(Sys_dict.class,
|
||||
Chain.make("name", value).add("code", value).add("disabled", false),
|
||||
Cnd.where(Sys_dict::getParentId, "=", parentDict.getId()).and(Sys_dict::getCode, "=", value));
|
||||
} else {
|
||||
Sys_dict dict = new Sys_dict();
|
||||
dict.setCode(value);
|
||||
dict.setName(value);
|
||||
dict.setDisabled(false);
|
||||
dict.setHasChildren(false);
|
||||
sysDictService.save(dict, parentDict.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
private void updateDict(List<Sys_user_source> userSources) {
|
||||
//判断是否要更新在职状态字典
|
||||
|
||||
@@ -45,7 +45,14 @@ const branchUnionUserManage = {
|
||||
<el-dialog title="添加" :visible.sync="dialogFormVisible" width="600px" :close-on-click-modal="false">
|
||||
<el-form :model="formData" ref="form" size="small" label-width="80px">
|
||||
<el-form-item prop="roleCode" label="角色">
|
||||
<dict-select v-model="formData.roleCode" code="BRANCH_UNION_ROLES" placeholder="请选择角色"></dict-select>
|
||||
<el-select v-model="formData.roleCode" clearable filterable placeholder="请选择角色" style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in roleOptions"
|
||||
:key="item.code"
|
||||
:label="item.name"
|
||||
:value="item.code"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="userId" label="人员">
|
||||
<user-select
|
||||
@@ -81,7 +88,8 @@ const branchUnionUserManage = {
|
||||
searchName: "username"
|
||||
},
|
||||
dialogFormVisible: false,
|
||||
formData: {}
|
||||
formData: {},
|
||||
roleOptions: []
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@@ -92,8 +100,16 @@ const branchUnionUserManage = {
|
||||
methods: {
|
||||
openAdd() {
|
||||
this.dialogFormVisible = true
|
||||
this.loadRoleOptions()
|
||||
this.$nextTick(() => {
|
||||
this.formData = {}
|
||||
this.$set(this, "formData", {})
|
||||
})
|
||||
},
|
||||
loadRoleOptions() {
|
||||
this.$axios.post("/platform/sys/union/branchUnionRoleOptions").then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.$set(this, "roleOptions", res.data || [])
|
||||
}
|
||||
})
|
||||
},
|
||||
doSubmit() {
|
||||
@@ -140,6 +156,7 @@ const branchUnionUserManage = {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadRoleOptions()
|
||||
this.pageData()
|
||||
},
|
||||
style: /*language=CSS*/ `
|
||||
|
||||
@@ -42,7 +42,14 @@ const schoolUnionUserManage = {
|
||||
<el-dialog title="添加" :visible.sync="dialogFormVisible" width="600px" :close-on-click-modal="false">
|
||||
<el-form :model="formData" ref="form" size="small" label-width="80px">
|
||||
<el-form-item prop="roleCode" label="角色">
|
||||
<dict-select v-model="formData.roleCode" code="SCHOOL_UNION_ROLES"></dict-select>
|
||||
<el-select v-model="formData.roleCode" clearable filterable placeholder="请选择角色" style="width: 100%">
|
||||
<el-option
|
||||
v-for="item in roleOptions"
|
||||
:key="item.code"
|
||||
:label="item.name"
|
||||
:value="item.code"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item prop="userId" label="人员">
|
||||
<user-select v-model="formData.userId" api_input_key_name="query"></user-select>
|
||||
@@ -63,14 +70,23 @@ const schoolUnionUserManage = {
|
||||
searchName: "username"
|
||||
},
|
||||
dialogFormVisible: false,
|
||||
formData: {}
|
||||
formData: {},
|
||||
roleOptions: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
openAdd() {
|
||||
this.dialogFormVisible = true
|
||||
this.loadRoleOptions()
|
||||
this.$nextTick(() => {
|
||||
this.formData = {}
|
||||
this.$set(this, "formData", {})
|
||||
})
|
||||
},
|
||||
loadRoleOptions() {
|
||||
$.get("/platform/sys/union/schoolUnionRoleOptions").then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.$set(this, "roleOptions", res.data || [])
|
||||
}
|
||||
})
|
||||
},
|
||||
doSubmit() {
|
||||
@@ -105,6 +121,7 @@ const schoolUnionUserManage = {
|
||||
}
|
||||
},
|
||||
created() {
|
||||
this.loadRoleOptions()
|
||||
this.pageData()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user