优化系统数据字典同步
This commit is contained in:
parent
7bcd2fc403
commit
050a9fa253
|
@ -37,9 +37,10 @@ public class AsyncMainServiceImpl extends ServiceImpl<AsyncMainMapper, AsyncMain
|
||||||
@Override
|
@Override
|
||||||
public Map<String, List<AsyncMain>> listByType(AsyncMain am) {
|
public Map<String, List<AsyncMain>> listByType(AsyncMain am) {
|
||||||
Map<String, List<AsyncMain>> result = Maps.newHashMap();
|
Map<String, List<AsyncMain>> result = Maps.newHashMap();
|
||||||
List<AsyncMain> errorList = Lists.newArrayList();
|
List<AsyncMain> errorList = Lists.newArrayList();//异常
|
||||||
List<AsyncMain> processingList = Lists.newArrayList();
|
List<AsyncMain> pendingList = Lists.newArrayList();//同步中
|
||||||
List<AsyncMain> successList = Lists.newArrayList();
|
List<AsyncMain> successList = Lists.newArrayList();//成功
|
||||||
|
List<AsyncMain> processingList = Lists.newArrayList();//待同步
|
||||||
|
|
||||||
List<JSONObject> depts = sysBaseAPI.queryOpeDept();
|
List<JSONObject> depts = sysBaseAPI.queryOpeDept();
|
||||||
|
|
||||||
|
@ -51,7 +52,9 @@ public class AsyncMainServiceImpl extends ServiceImpl<AsyncMainMapper, AsyncMain
|
||||||
asyncMains.stream().forEach(a -> {
|
asyncMains.stream().forEach(a -> {
|
||||||
if ((MQStatus.SUCCESS.getCode() + "").equals(a.getStatus())) {
|
if ((MQStatus.SUCCESS.getCode() + "").equals(a.getStatus())) {
|
||||||
successList.add(a);
|
successList.add(a);
|
||||||
} else {
|
} else if("100".equals(a.getStatus())){
|
||||||
|
processingList.add(a);
|
||||||
|
}else{
|
||||||
errorList.add(a);
|
errorList.add(a);
|
||||||
}
|
}
|
||||||
depts.removeIf(dept -> a.getOrgCode().equals(dept.getString("code")));
|
depts.removeIf(dept -> a.getOrgCode().equals(dept.getString("code")));
|
||||||
|
@ -61,13 +64,14 @@ public class AsyncMainServiceImpl extends ServiceImpl<AsyncMainMapper, AsyncMain
|
||||||
AsyncMain asyncMain = new AsyncMain();
|
AsyncMain asyncMain = new AsyncMain();
|
||||||
asyncMain.setOrgCode(dept.getString("code"));
|
asyncMain.setOrgCode(dept.getString("code"));
|
||||||
asyncMain.setOrgName(dept.getString("name"));
|
asyncMain.setOrgName(dept.getString("name"));
|
||||||
asyncMain.setDescr("同步中/待同步");
|
asyncMain.setDescr("待同步");
|
||||||
processingList.add(asyncMain);
|
pendingList.add(asyncMain);
|
||||||
});
|
});
|
||||||
|
|
||||||
result.put("errorList", errorList);
|
result.put("errorList", errorList);
|
||||||
result.put("processingList", processingList);
|
result.put("pendingList", pendingList);
|
||||||
result.put("successList", successList);
|
result.put("successList", successList);
|
||||||
|
result.put("processingList", processingList);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.io.Serializable;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||||
|
|
||||||
|
@ -94,4 +95,6 @@ public class SysDict implements Serializable {
|
||||||
/** 关联的低代码应用ID */
|
/** 关联的低代码应用ID */
|
||||||
private java.lang.String lowAppId;
|
private java.lang.String lowAppId;
|
||||||
|
|
||||||
|
@TableField(exist = false)
|
||||||
|
private String orgCode;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.nu.dto.SysDictMQDto;
|
||||||
import com.nu.modules.async.entity.AsyncMain;
|
import com.nu.modules.async.entity.AsyncMain;
|
||||||
import com.nu.modules.async.service.IAsyncMainService;
|
import com.nu.modules.async.service.IAsyncMainService;
|
||||||
import com.nu.utils.RabbitMQUtil;
|
import com.nu.utils.RabbitMQUtil;
|
||||||
|
import org.jeecg.modules.system.entity.SysDepart;
|
||||||
import org.jeecg.modules.system.security.DictQueryBlackListHandler;
|
import org.jeecg.modules.system.security.DictQueryBlackListHandler;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
@ -41,6 +42,7 @@ import org.jeecg.modules.system.mapper.SysDictItemMapper;
|
||||||
import org.jeecg.modules.system.mapper.SysDictMapper;
|
import org.jeecg.modules.system.mapper.SysDictMapper;
|
||||||
import org.jeecg.modules.system.model.DuplicateCheckVo;
|
import org.jeecg.modules.system.model.DuplicateCheckVo;
|
||||||
import org.jeecg.modules.system.model.TreeSelectModel;
|
import org.jeecg.modules.system.model.TreeSelectModel;
|
||||||
|
import org.jeecg.modules.system.service.ISysDepartService;
|
||||||
import org.jeecg.modules.system.service.ISysDictService;
|
import org.jeecg.modules.system.service.ISysDictService;
|
||||||
import org.jeecg.modules.system.vo.lowapp.SysDictVo;
|
import org.jeecg.modules.system.vo.lowapp.SysDictVo;
|
||||||
import org.mybatis.spring.MyBatisSystemException;
|
import org.mybatis.spring.MyBatisSystemException;
|
||||||
|
@ -78,6 +80,8 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
private IAsyncMainService asyncMainService;
|
private IAsyncMainService asyncMainService;
|
||||||
|
@Autowired
|
||||||
|
private ISysDepartService departService;
|
||||||
|
|
||||||
@Lazy
|
@Lazy
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -281,9 +285,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
code = SqlInjectionUtil.getSqlInjectField(code);
|
code = SqlInjectionUtil.getSqlInjectField(code);
|
||||||
List<DictModel> dictModels = Lists.newArrayList();
|
List<DictModel> dictModels = Lists.newArrayList();
|
||||||
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
||||||
if(existIzEnabled>0){
|
if (existIzEnabled > 0) {
|
||||||
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, "1");
|
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, "1");
|
||||||
}else{
|
} else {
|
||||||
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, null);
|
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, null);
|
||||||
}
|
}
|
||||||
return dictModels;
|
return dictModels;
|
||||||
|
@ -313,9 +317,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
code = SqlInjectionUtil.getSqlInjectField(code);
|
code = SqlInjectionUtil.getSqlInjectField(code);
|
||||||
List<DictModel> dictModels = Lists.newArrayList();
|
List<DictModel> dictModels = Lists.newArrayList();
|
||||||
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
||||||
if(existIzEnabled>0){
|
if (existIzEnabled > 0) {
|
||||||
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, "1");
|
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, "1");
|
||||||
}else{
|
} else {
|
||||||
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, null);
|
dictModels = sysDictMapper.queryTableDictWithFilter(table, text, code, filterSql, null);
|
||||||
}
|
}
|
||||||
return dictModels;
|
return dictModels;
|
||||||
|
@ -555,10 +559,10 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
// 3. 返回表字典数据
|
// 3. 返回表字典数据
|
||||||
IPage<DictModel> pageList = new Page<>();
|
IPage<DictModel> pageList = new Page<>();
|
||||||
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
||||||
if(existIzEnabled>0){
|
if (existIzEnabled > 0) {
|
||||||
pageList = baseMapper.queryPageTableDictWithFilter(page,table, text, code, filterSql, "1");
|
pageList = baseMapper.queryPageTableDictWithFilter(page, table, text, code, filterSql, "1");
|
||||||
}else{
|
} else {
|
||||||
pageList = baseMapper.queryPageTableDictWithFilter(page,table, text, code, filterSql, null);
|
pageList = baseMapper.queryPageTableDictWithFilter(page, table, text, code, filterSql, null);
|
||||||
}
|
}
|
||||||
return pageList.getRecords();
|
return pageList.getRecords();
|
||||||
}
|
}
|
||||||
|
@ -653,9 +657,9 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
code = SqlInjectionUtil.getSqlInjectField(code);
|
code = SqlInjectionUtil.getSqlInjectField(code);
|
||||||
List<DictModel> ls = Lists.newArrayList();
|
List<DictModel> ls = Lists.newArrayList();
|
||||||
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
int existIzEnabled = sysDictMapper.existColumn(table, "iz_enabled");
|
||||||
if(existIzEnabled>0){
|
if (existIzEnabled > 0) {
|
||||||
ls = baseMapper.queryTableDictWithFilter(table, text, code, filterSql, "1");
|
ls = baseMapper.queryTableDictWithFilter(table, text, code, filterSql, "1");
|
||||||
}else{
|
} else {
|
||||||
ls = baseMapper.queryTableDictWithFilter(table, text, code, filterSql, null);
|
ls = baseMapper.queryTableDictWithFilter(table, text, code, filterSql, null);
|
||||||
}
|
}
|
||||||
return ls;
|
return ls;
|
||||||
|
@ -713,13 +717,13 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<SysDict> queryDeleteList(String tenantId,String tag) {
|
public List<SysDict> queryDeleteList(String tenantId, String tag) {
|
||||||
//update-begin---author:wangshuai---date:2024-02-27---for:【QQYUN-8340】回收站查找软删除记录时,没有判断是否启用多租户,造成可以查找并回收其他租户的数据 #5907---
|
//update-begin---author:wangshuai---date:2024-02-27---for:【QQYUN-8340】回收站查找软删除记录时,没有判断是否启用多租户,造成可以查找并回收其他租户的数据 #5907---
|
||||||
if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) {
|
if (MybatisPlusSaasConfig.OPEN_SYSTEM_TENANT_CONTROL) {
|
||||||
if (oConvertUtils.isEmpty(tenantId)) {
|
if (oConvertUtils.isEmpty(tenantId)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
return baseMapper.queryDeleteListBtTenantId(oConvertUtils.getInt(tenantId),tag);
|
return baseMapper.queryDeleteListBtTenantId(oConvertUtils.getInt(tenantId), tag);
|
||||||
}
|
}
|
||||||
//update-end---author:wangshuai---date:2024-02-27---for:【QQYUN-8340】回收站查找软删除记录时,没有判断是否启用多租户,造成可以查找并回收其他租户的数据 #5907---
|
//update-end---author:wangshuai---date:2024-02-27---for:【QQYUN-8340】回收站查找软删除记录时,没有判断是否启用多租户,造成可以查找并回收其他租户的数据 #5907---
|
||||||
return baseMapper.queryDeleteList(tag);
|
return baseMapper.queryDeleteList(tag);
|
||||||
|
@ -908,17 +912,51 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void async(SysDict sysDict) {
|
public void async(SysDict sysDict) {
|
||||||
|
QueryWrapper<SysDepart> sysDepartQueryWrapper = new QueryWrapper<>();
|
||||||
|
sysDepartQueryWrapper.eq("org_category", "1");
|
||||||
|
sysDepartQueryWrapper.eq("del_flag", "0");
|
||||||
|
if (StringUtils.isNotBlank(sysDict.getOrgCode())) {
|
||||||
|
sysDepartQueryWrapper.eq("org_code", sysDict.getOrgCode());
|
||||||
|
}
|
||||||
|
List<SysDepart> depts = departService.list(sysDepartQueryWrapper);
|
||||||
|
|
||||||
|
List<AsyncMain> ams = Lists.newArrayList();
|
||||||
|
List<String> orgCodes = Lists.newArrayList();
|
||||||
|
if (depts != null && !depts.isEmpty()) {
|
||||||
|
depts.stream().forEach(d -> {
|
||||||
|
AsyncMain asyncMain = new AsyncMain();
|
||||||
|
asyncMain.setPrimaryKey(sysDict.getId());
|
||||||
|
asyncMain.setStatus("100");
|
||||||
|
asyncMain.setOrgCode(d.getOrgCode());
|
||||||
|
asyncMain.setOrgName(d.getDepartName());
|
||||||
|
asyncMain.setDescr("同步中(如果同步时间过久,请检查该业务系统是否正确配置机构编码)");
|
||||||
|
ams.add(asyncMain);
|
||||||
|
orgCodes.add(d.getOrgCode());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QueryWrapper<AsyncMain> asyncMainQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<AsyncMain> asyncMainQueryWrapper = new QueryWrapper<>();
|
||||||
asyncMainQueryWrapper.eq("primary_key",sysDict.getId());
|
asyncMainQueryWrapper.eq("primary_key", sysDict.getId());
|
||||||
|
if (StringUtils.isNotBlank(sysDict.getOrgCode())) {
|
||||||
|
asyncMainQueryWrapper.eq("org_code", sysDict.getOrgCode());
|
||||||
|
} else {
|
||||||
|
asyncMainQueryWrapper.in("org_code", orgCodes);
|
||||||
|
}
|
||||||
asyncMainService.remove(asyncMainQueryWrapper);
|
asyncMainService.remove(asyncMainQueryWrapper);
|
||||||
|
asyncMainService.saveBatch(ams);
|
||||||
|
|
||||||
|
|
||||||
SysDict sd = baseMapper.selectById(sysDict.getId());
|
SysDict sd = baseMapper.selectById(sysDict.getId());
|
||||||
List<SysDictItem> sysDictItems = sysDictItemMapper.selectItemsByMainId(sysDict.getId());
|
List<SysDictItem> sysDictItems = sysDictItemMapper.selectItemsByMainId(sysDict.getId());
|
||||||
SysDictMQDto sysDictMQDto = new SysDictMQDto();
|
SysDictMQDto sysDictMQDto = new SysDictMQDto();
|
||||||
BeanUtils.copyProperties(sd,sysDictMQDto);
|
BeanUtils.copyProperties(sd, sysDictMQDto);
|
||||||
sysDictMQDto.setSysDictItemList(BeanUtil.copyToList(sysDictItems, SysDictItemMQDto.class));
|
sysDictMQDto.setSysDictItemList(BeanUtil.copyToList(sysDictItems, SysDictItemMQDto.class));
|
||||||
|
|
||||||
rabbitMQUtil.sendToExchange("hldy.sysdict.fanout","",sysDictMQDto);
|
if (StringUtils.isNotBlank(sysDict.getOrgCode())) {
|
||||||
|
rabbitMQUtil.sendToExchange("hldy.sysdict.direct", sysDict.getOrgCode() + ".dict.async", sysDictMQDto);
|
||||||
|
} else {
|
||||||
|
rabbitMQUtil.sendToExchange("hldy.sysdict.fanout", "", sysDictMQDto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.jeecg.mq.dict.listener;
|
package org.jeecg.mq.dict.listener;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.nu.dto.StatusMQDto;
|
import com.nu.dto.StatusMQDto;
|
||||||
import com.nu.modules.async.entity.AsyncMain;
|
import com.nu.modules.async.entity.AsyncMain;
|
||||||
import com.nu.modules.async.service.IAsyncMainService;
|
import com.nu.modules.async.service.IAsyncMainService;
|
||||||
|
@ -8,6 +9,8 @@ import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class DictMQListener {
|
public class DictMQListener {
|
||||||
|
@ -19,11 +22,15 @@ public class DictMQListener {
|
||||||
public void handleMessage(StatusMQDto dto) {
|
public void handleMessage(StatusMQDto dto) {
|
||||||
AsyncMain asyncMain = new AsyncMain();
|
AsyncMain asyncMain = new AsyncMain();
|
||||||
asyncMain.setPrimaryKey(dto.getDictId());
|
asyncMain.setPrimaryKey(dto.getDictId());
|
||||||
asyncMain.setStatus(dto.getStatus()+"");
|
asyncMain.setStatus(dto.getStatus() + "");
|
||||||
asyncMain.setOrgCode(dto.getOrgCode());
|
asyncMain.setOrgCode(dto.getOrgCode());
|
||||||
asyncMain.setOrgName(dto.getOrgName());
|
asyncMain.setOrgName(dto.getOrgName());
|
||||||
asyncMain.setDescr(dto.getMessage());
|
asyncMain.setDescr(dto.getMessage());
|
||||||
asyncMainService.save(asyncMain);
|
|
||||||
|
QueryWrapper<AsyncMain> qw = new QueryWrapper<>();
|
||||||
|
qw.eq("primary_key",asyncMain.getPrimaryKey());
|
||||||
|
qw.eq("org_code",asyncMain.getOrgCode());
|
||||||
|
asyncMainService.update(asyncMain,qw);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue