优化系统数据字典同步
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,6 +52,8 @@ 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 if("100".equals(a.getStatus())){
|
||||||
|
processingList.add(a);
|
||||||
}else{
|
}else{
|
||||||
errorList.add(a);
|
errorList.add(a);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -908,9 +912,39 @@ 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());
|
||||||
|
@ -918,8 +952,12 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
|
||||||
BeanUtils.copyProperties(sd, sysDictMQDto);
|
BeanUtils.copyProperties(sd, sysDictMQDto);
|
||||||
sysDictMQDto.setSysDictItemList(BeanUtil.copyToList(sysDictItems, SysDictItemMQDto.class));
|
sysDictMQDto.setSysDictItemList(BeanUtil.copyToList(sysDictItems, SysDictItemMQDto.class));
|
||||||
|
|
||||||
|
if (StringUtils.isNotBlank(sysDict.getOrgCode())) {
|
||||||
|
rabbitMQUtil.sendToExchange("hldy.sysdict.direct", sysDict.getOrgCode() + ".dict.async", sysDictMQDto);
|
||||||
|
} else {
|
||||||
rabbitMQUtil.sendToExchange("hldy.sysdict.fanout", "", sysDictMQDto);
|
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 {
|
||||||
|
@ -23,7 +26,11 @@ public class DictMQListener {
|
||||||
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