Compare commits

..

3 Commits

Author SHA1 Message Date
1378012178@qq.com 7bcd2fc403 1、系统级别数据字典同步
2、调整业务系统mq监听的队列:根据机构动态生成队列名称、key名称并绑定交换机(解决队列名称写死,每次新增业务系统都需要修改问题)
2025-05-08 16:21:03 +08:00
1378012178@qq.com 67d83e35bf Merge branch 'master' of http://47.115.223.229:8888/yangjun/hldy_java_monomer 2025-05-07 14:18:52 +08:00
1378012178@qq.com 217c5844dc 系统数据字典同步(临时提交) 2025-05-07 14:18:46 +08:00
26 changed files with 2085 additions and 1641 deletions

View File

@ -18,7 +18,7 @@ public class AdvisoryMQExceptionHandler implements RabbitListenerErrorHandler {
// 根据异常类型选择处理策略
if (isRetryable(e)) {
// 可重试异常抛出异常触发重试
throw e;
throw new AmqpRejectAndDontRequeueException("消息处理失败且禁止重试", e);
} else {
// 不可恢复异常拒绝消息且不重新入队
throw new AmqpRejectAndDontRequeueException("消息处理失败且禁止重试", e);

View File

@ -0,0 +1,73 @@
package com.nu.modules.pad.appversionconfig.api;
import cn.hutool.core.util.StrUtil;
import com.nu.modules.pad.appversionconfig.entity.AppConfig;
import com.nu.modules.pad.appversionconfig.entity.R;
import com.nu.modules.pad.appversionconfig.entity.VersionInfo;
import com.nu.modules.pad.appversionconfig.service.IAppConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/nuIpadApi/versionManage")
@CrossOrigin("*")
public class VersionManageApi {
@Autowired
private IAppConfigService appConfigService;
/**
* APP版本更新
* 请求参数中其实不止传递了一下四个更多请看插件市场作者的文档https://ext.dcloud.net.cn/plugin?id=3931
* @param platform 平台android/ios
* @param name 应用名称
* @param version 应用版本名称 主版本号.次版本号.修订号
* @param code 应用版本号
* @return
*/
@RequestMapping("/versionUpdate")
public R check(String platform,String name,String version,String code) {
Map<String, Object> map = new HashMap<>();
VersionInfo info = new VersionInfo();
info.setUpdate_flag(0);
map.put("code", 100);
map.put("data", info);
AppConfig appConfig = appConfigService.findLastVersionInfo();
if(appConfig ==null) {
map.put("msg", "无版本配置信息");
return R.ok(map);
}
if(!StrUtil.isEmptyIfStr(version) && !StrUtil.isEmptyIfStr(platform)) {
int[] oldVers = StrUtil.splitToInt(version, ".");
int[] newVers = StrUtil.splitToInt(appConfig.getVersionCode(), ".");
boolean isUpdateFlag = false;
int length = oldVers.length > newVers.length ? newVers.length : oldVers.length;
for (int i = 0; i < length; i++) {
if(newVers[i] > oldVers[i]) {
isUpdateFlag = true;
break;
}
}
if(isUpdateFlag) {
info.setUpdate_flag(1);//0不需要更新1:需要更新
info.setVersion(appConfig.getVersionCode());
info.setUpdate_url(appConfig.getVersionUrl());
info.setUpdate_tips(appConfig.getUpdateTrips());
info.setForceupdate(appConfig.getIsForceUpdate());
map.put("code", 100);
map.put("msg", "应用程序需要更新");
map.put("data", info);
}
return R.ok(map);
}else {
map.put("code", 500);
map.put("msg", "请求参数不含版本号、平台");
map.put("data", info);
return R.ok(map);
}
}
}

View File

@ -16,7 +16,7 @@ import java.util.Map;
@RestController
@RequestMapping("/api/pad")
@CrossOrigin("*")
public class VersionUpdateApi {
public class VersionManageApiBK {
@Autowired
private IAppConfigService appConfigService;

View File

@ -114,6 +114,7 @@ public class ShiroConfig {
filterChainDefinitionMap.put("/sys/getQrcodeToken/**", "anon"); //监听扫码
filterChainDefinitionMap.put("/sys/checkAuth", "anon"); //授权接口排除
filterChainDefinitionMap.put("/api/pad/versionUpdate", "anon");//pad端版本检测接口
filterChainDefinitionMap.put("/nuIpadApi/versionManage/versionUpdate", "anon");//pad端版本检测接口
//update-begin--Author:scott Date:20221116 for排除静态资源后缀
filterChainDefinitionMap.put("/", "anon");

View File

@ -17,6 +17,11 @@
<artifactId>nursing-unit-base-core</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.nursingunit.boot</groupId>
<artifactId>nu-system-local-api</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
</project>

View File

@ -32,43 +32,6 @@ public class RabbitMQConfig {
return new DirectExchange("hldy.fwzl");
}
// 队列
@Bean
public Queue nu001FwzlAsyncQueue() {
return new Queue("nu001.fwzl.async", true);
}
@Bean
public Queue nu001FwzlStatusQueue() {
return new Queue("nu001.fwzl.status", true);
}
@Bean
public Queue nu002FwzlAsyncQueue() {
return new Queue("nu002.fwzl.async", true);
}
@Bean
public Queue nu002FwzlStatusQueue() {
return new Queue("nu002.fwzl.status", true);
}
@Bean
public Binding binding1(Queue nu001FwzlAsyncQueue, DirectExchange fwzlExchange) {
return BindingBuilder.bind(nu001FwzlAsyncQueue).to(fwzlExchange).with("nu001.fwzl.async");
}
@Bean
public Binding binding2(Queue nu001FwzlStatusQueue, DirectExchange fwzlExchange) {
return BindingBuilder.bind(nu001FwzlStatusQueue).to(fwzlExchange).with("nu001.fwzl.status");
}
@Bean
public Binding binding3(Queue nu002FwzlAsyncQueue, DirectExchange fwzlExchange) {
return BindingBuilder.bind(nu002FwzlAsyncQueue).to(fwzlExchange).with("nu002.fwzl.async");
}
@Bean
public Binding binding4(Queue nu002FwzlStatusQueue, DirectExchange fwzlExchange) {
return BindingBuilder.bind(nu002FwzlStatusQueue).to(fwzlExchange).with("nu002.fwzl.status");
}
//注册
@Bean
public DirectExchange registerExchange() {
@ -90,4 +53,5 @@ public class RabbitMQConfig {
public Binding bindingRegEdit(Queue registerEditQueue, DirectExchange registerExchange) {
return BindingBuilder.bind(registerEditQueue).to(registerExchange).with("register.editData");
}
}

View File

@ -13,4 +13,9 @@ public class StatusMQDto {
private String asyncId;
//同步表子表code
private String code;
private String dictId;
private String orgCode;
private String orgName;
}

View File

@ -0,0 +1,70 @@
package com.nu.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* <p>
*
* </p>
*
* @Author zmy
* @since 2025-5-6
*/
@Data
public class SysDictItemMQDto implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* 字典id
*/
private String dictId;
/**
* 字典项文本
*/
private String itemText;
/**
* 字典项值
*/
private String itemValue;
/**
* 描述
*/
private String description;
/**
* 排序
*/
private Integer sortOrder;
/**
* 状态1启用 0不启用
*/
private Integer status;
private String createBy;
private Date createTime;
private String updateBy;
private Date updateTime;
/**
* 字典项颜色
*/
private String itemColor;
}

View File

@ -0,0 +1,90 @@
package com.nu.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
* <p>
* 字典表
* </p>
*
* @Author zmy
* @since 2025-5-6
*/
@Data
public class SysDictMQDto implements Serializable {
private static final long serialVersionUID = 1L;
/**
* id
*/
private String id;
/**
* [预留字段暂时无用]
* 字典类型,0 string,1 number类型,2 boolean
* 前端js对stirng类型和number类型 boolean 类型敏感需要区分在select 标签匹配的时候会用到
* 默认为string类型
*/
private Integer type;
/**
* 字典名称
*/
private String dictName;
/**
* 字典编码
*/
private String dictCode;
/**
* 描述
*/
private String description;
/**
* 标识
* sys系统字典非客户使用字典
* nu业务字典客户使用字典
*/
private String tag;
/**
* 删除状态
*/
private Integer delFlag;
/**
* 创建人
*/
private String createBy;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新人
*/
private String updateBy;
/**
* 更新时间
*/
private Date updateTime;
/**租户ID*/
private Integer tenantId;
/** 关联的低代码应用ID */
private String lowAppId;
private List<SysDictItemMQDto> sysDictItemList;
}

View File

@ -2,6 +2,7 @@ package com.nu.modules.async.controller;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -17,6 +18,7 @@ import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
@ -35,6 +37,7 @@ import org.apache.shiro.authz.annotation.RequiresPermissions;
@RequestMapping("/asyncmain/asyncMain")
@Slf4j
public class AsyncMainController extends JeecgController<AsyncMain, IAsyncMainService> {
@Autowired
private IAsyncMainService asyncMainService;
@ -60,7 +63,7 @@ public class AsyncMainController extends JeecgController<AsyncMain, IAsyncMainSe
IPage<AsyncMain> pageList = asyncMainService.page(page, queryWrapper);
List<AsyncMain> records = pageList.getRecords();
if (records != null && !records.isEmpty()) {
records = asyncMainService.pageList(records);
records = asyncMainService.pageList(records,asyncMain);
pageList.setRecords(records);
}
return Result.OK(pageList);
@ -168,4 +171,8 @@ public class AsyncMainController extends JeecgController<AsyncMain, IAsyncMainSe
return super.importExcel(request, response, AsyncMain.class);
}
@PostMapping("/listByType")
public Result<Map<String,List<AsyncMain>>> listByType(@RequestBody AsyncMain am){
return Result.OK(asyncMainService.listByType(am));
}
}

View File

@ -35,10 +35,18 @@ public class AsyncMain implements Serializable {
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "id")
private java.lang.String id;
/**被同步数据的主键id*/
@Excel(name = "被同步数据的主键id", width = 15)
@ApiModelProperty(value = "被同步数据的主键id")
private java.lang.String primaryKey;
/**机构编码*/
@Excel(name = "机构编码", width = 15)
@ApiModelProperty(value = "机构编码")
private java.lang.String orgCode;
/**机构名称*/
@Excel(name = "机构名称", width = 15)
@ApiModelProperty(value = "机构名称")
private java.lang.String orgName;
/**类型(同步的是什么类型的数据)*/
@Excel(name = "类型(同步的是什么类型的数据)", width = 15)
@ApiModelProperty(value = "类型(同步的是什么类型的数据)")
@ -56,7 +64,13 @@ public class AsyncMain implements Serializable {
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
@ApiModelProperty(value = "创建日期")
private java.util.Date createTime;
/**状态*/
@Excel(name = "状态", width = 15)
@ApiModelProperty(value = "状态")
private java.lang.String status;
@TableField(exist = false)
private List<AsyncStatus> asyncStatusList;
@TableField(exist = false)
private List<String> ids;
}

View File

@ -14,5 +14,5 @@ import java.util.List;
*/
public interface AsyncMainMapper extends BaseMapper<AsyncMain> {
List<AsyncMain> pageList(@Param("pojo") List<AsyncMain> records);
List<AsyncMain> pageList(@Param("records") List<AsyncMain> records,@Param("dto") AsyncMain dto);
}

View File

@ -4,7 +4,9 @@
<resultMap id="asyncResultMap" type="com.nu.modules.async.entity.AsyncMain">
<id property="id" column="id"/>
<result property="primaryKey" column="primaryKey"/>
<result property="orgCode" column="orgCode"/>
<result property="orgName" column="orgName"/>
<result property="type" column="type"/>
<result property="descr" column="descr"/>
<result property="createBy" column="createBy"/>
@ -22,7 +24,9 @@
<select id="pageList" resultMap="asyncResultMap">
select
f.id as id,
f.primary_key as primaryKey,
f.org_code as orgCode,
f.org_name as orgName,
f.type as type,
f.descr as descr,
f.create_by as createBy,
@ -36,10 +40,16 @@
from nu_async_main f
left join nu_async_status z on f.id = z.pkid
<where>
<if test="records !=null and !records.isEmpty()">
f.id in
<foreach collection="pojo" item="am" separator="," open="(" close=")">
<foreach collection="records" item="am" separator="," open="(" close=")">
#{am.id}
</foreach>
</if>
<if test="dto.primaryKey != '' and dto.primaryKey != null">
and f.primary_key = #{dto.primaryKey}
and f.status = '500'
</if>
</where>
order by f.create_time desc,z.update_time desc
</select>

View File

@ -4,6 +4,7 @@ import com.nu.modules.async.entity.AsyncMain;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
import java.util.Map;
/**
* @Description: 数据同步主表
@ -13,5 +14,7 @@ import java.util.List;
*/
public interface IAsyncMainService extends IService<AsyncMain> {
List<AsyncMain> pageList(List<AsyncMain> records);
List<AsyncMain> pageList(List<AsyncMain> records, AsyncMain dto);
Map<String,List<AsyncMain>> listByType(AsyncMain am);
}

View File

@ -1,13 +1,21 @@
package com.nu.modules.async.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Maps;
import com.nu.enums.MQStatus;
import com.nu.modules.async.entity.AsyncMain;
import com.nu.modules.async.mapper.AsyncMainMapper;
import com.nu.modules.async.service.IAsyncMainService;
import org.apache.commons.compress.utils.Lists;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import java.util.Map;
/**
* @Description: 数据同步主表
@ -18,8 +26,48 @@ import java.util.List;
@Service
public class AsyncMainServiceImpl extends ServiceImpl<AsyncMainMapper, AsyncMain> implements IAsyncMainService {
@Autowired
private ISysBaseAPI sysBaseAPI;
@Override
public List<AsyncMain> pageList(List<AsyncMain> records) {
return baseMapper.pageList(records);
public List<AsyncMain> pageList(List<AsyncMain> records, AsyncMain dto) {
return baseMapper.pageList(records, dto);
}
@Override
public Map<String, List<AsyncMain>> listByType(AsyncMain am) {
Map<String, List<AsyncMain>> result = Maps.newHashMap();
List<AsyncMain> errorList = Lists.newArrayList();
List<AsyncMain> processingList = Lists.newArrayList();
List<AsyncMain> successList = Lists.newArrayList();
List<JSONObject> depts = sysBaseAPI.queryOpeDept();
QueryWrapper<AsyncMain> asyncMainQueryWrapper = new QueryWrapper<>();
asyncMainQueryWrapper.eq("primary_key", am.getPrimaryKey());
asyncMainQueryWrapper.orderByAsc("org_code");
List<AsyncMain> asyncMains = baseMapper.selectList(asyncMainQueryWrapper);
if (asyncMains != null && !asyncMains.isEmpty()) {
asyncMains.stream().forEach(a -> {
if ((MQStatus.SUCCESS.getCode() + "").equals(a.getStatus())) {
successList.add(a);
} else {
errorList.add(a);
}
depts.removeIf(dept -> a.getOrgCode().equals(dept.getString("code")));
});
}
depts.forEach(dept -> {
AsyncMain asyncMain = new AsyncMain();
asyncMain.setOrgCode(dept.getString("code"));
asyncMain.setOrgName(dept.getString("name"));
asyncMain.setDescr("同步中/待同步");
processingList.add(asyncMain);
});
result.put("errorList", errorList);
result.put("processingList", processingList);
result.put("successList", successList);
return result;
}
}

View File

@ -67,7 +67,7 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
@ApiOperation(value = "服务指令-分页列表查询", notes = "服务指令-分页列表查询")
@GetMapping(value = "/list")
@DS("#dataSourceCode")
public Result<IPage<ConfigServiceDirective>> queryPageList(String dataSourceCode,ConfigServiceDirective configServiceDirective,
public Result<IPage<ConfigServiceDirective>> queryPageList(String dataSourceCode, ConfigServiceDirective configServiceDirective,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
@ -113,8 +113,9 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
*/
@PostMapping("/async")
public Result<String> async(@RequestBody DirectiveMQDto dto) {
List<DictModel> dicts = sysBaseAPI.getDictItems("mq_org_queue");
String queue = dicts.stream().filter(d -> d.getValue().equals(dto.getOrgCode())).findFirst().map(DictModel::getText).orElse(null);
// List<DictModel> dicts = sysBaseAPI.getDictItems("mq_org_queue");
// String queue = dicts.stream().filter(d -> d.getValue().equals(dto.getOrgCode())).findFirst().map(DictModel::getText).orElse(null);
String queue = dto.getOrgCode() + ".fwzl.async";
if (StringUtils.isNotBlank(queue)) {
//先在数据同步表中插入数据
AsyncMain asyncMain = new AsyncMain();
@ -167,5 +168,4 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
}
}

View File

@ -9,6 +9,10 @@ import com.nu.modules.async.service.IAsyncMainService;
import com.nu.modules.async.service.IAsyncStatusService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@ -24,16 +28,14 @@ public class DirectiveMQListener {
@Autowired
private IAsyncStatusService asyncStatusService;
@RabbitListener(queues = "nu001.fwzl.status", errorHandler = "directiveMQErrorHandler")
public void handleNu001AsyncMessageStatus(StatusMQDto dto) {
try {
System.out.println("接收到了消息:" + dto.getStatus() + "消息体:" + dto.getMessage());
} catch (Exception e) {
System.out.println("异常了:" + e.getMessage());
}
}
@RabbitListener(queues = "nu002.fwzl.status", errorHandler = "directiveMQErrorHandler")
@RabbitListener(
bindings = @QueueBinding(
value = @Queue(name = "fwzl.async.result"),
exchange = @Exchange(name = "hldy.fwzl", type = ExchangeTypes.DIRECT),
key = "fwzl.async.result"
),
errorHandler = "directiveMQErrorHandler"
)
public void handleNu002AsyncMessageStatus(StatusMQDto dto) {
LambdaQueryWrapper<AsyncStatus> qw = new LambdaQueryWrapper<>();
qw.eq(AsyncStatus::getPkid, dto.getAsyncId());

View File

@ -544,4 +544,9 @@ public interface ISysBaseAPI extends CommonAPI {
*/
boolean dictTableWhiteListCheckByDict(String tableOrDictCode, String... fields);
/**
* 查询各业务机构 编码名称
*
*/
List<JSONObject> queryOpeDept();
}

View File

@ -25,6 +25,12 @@
<artifactId>hibernate-re</artifactId>
</dependency>
<dependency>
<groupId>com.nursingunit.boot</groupId>
<artifactId>nursing-unit-common</artifactId>
<version>${nursingunit.version}</version>
</dependency>
<!-- 企业微信/钉钉 api -->
<dependency>
<groupId>org.jeecgframework</groupId>

View File

@ -792,4 +792,10 @@ public class SysDictController {
sysDictService.editDictByLowAppId(sysDictVo);
return Result.ok("编辑成功");
}
@PostMapping("/async")
public Result<String> async(@RequestBody SysDict sysDict){
sysDictService.async(sysDict);
return Result.ok();
}
}

View File

@ -300,4 +300,6 @@ public interface ISysDictService extends IService<SysDict> {
* @param ids
*/
boolean removeLogicDeleted(List<String> ids);
void async(SysDict sysDict);
}

View File

@ -1,12 +1,19 @@
package org.jeecg.modules.system.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.nu.dto.SysDictItemMQDto;
import com.nu.dto.SysDictMQDto;
import com.nu.modules.async.entity.AsyncMain;
import com.nu.modules.async.service.IAsyncMainService;
import com.nu.utils.RabbitMQUtil;
import org.jeecg.modules.system.security.DictQueryBlackListHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
@ -66,6 +73,11 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
private SysDictItemMapper sysDictItemMapper;
@Autowired
private DictQueryBlackListHandler dictQueryBlackListHandler;
@Autowired
private RabbitMQUtil rabbitMQUtil;
@Lazy
@Autowired
private IAsyncMainService asyncMainService;
@Lazy
@Autowired
@ -894,6 +906,21 @@ public class SysDictServiceImpl extends ServiceImpl<SysDictMapper, SysDict> impl
return line > 0;
}
@Override
public void async(SysDict sysDict) {
QueryWrapper<AsyncMain> asyncMainQueryWrapper = new QueryWrapper<>();
asyncMainQueryWrapper.eq("primary_key",sysDict.getId());
asyncMainService.remove(asyncMainQueryWrapper);
SysDict sd = baseMapper.selectById(sysDict.getId());
List<SysDictItem> sysDictItems = sysDictItemMapper.selectItemsByMainId(sysDict.getId());
SysDictMQDto sysDictMQDto = new SysDictMQDto();
BeanUtils.copyProperties(sd,sysDictMQDto);
sysDictMQDto.setSysDictItemList(BeanUtil.copyToList(sysDictItems, SysDictItemMQDto.class));
rabbitMQUtil.sendToExchange("hldy.sysdict.fanout","",sysDictMQDto);
}
/**
* 添加字典
*

View File

@ -0,0 +1,28 @@
package com.nu.mq.directive.exceptionhandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.AmqpRejectAndDontRequeueException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler;
import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException;
import org.springframework.stereotype.Component;
@Slf4j
@Component("dictMQErrorHandler")
public class DictMQExceptionHandler implements RabbitListenerErrorHandler {
@Override
public Object handleError(Message message, org.springframework.messaging.Message<?> message1, ListenerExecutionFailedException e) {
log.error("MQ消息处理失败 | 消息体: {} | 异常原因: {}", new String(message.getBody()), e.getCause().getMessage());
// 根据异常类型选择处理策略
// if (isRetryable(e)) {
// // 可重试异常抛出异常触发重试
// throw e;
// } else {
// 不可恢复异常拒绝消息且不重新入队
throw new AmqpRejectAndDontRequeueException("消息处理失败且禁止重试", e);
// }
}
}

View File

@ -0,0 +1,29 @@
package org.jeecg.mq.dict.listener;
import com.nu.dto.StatusMQDto;
import com.nu.modules.async.entity.AsyncMain;
import com.nu.modules.async.service.IAsyncMainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Slf4j
@Component
public class DictMQListener {
@Autowired
private IAsyncMainService asyncMainService;
@RabbitListener(queues = "sysdict.async.result", errorHandler = "dictMQErrorHandler")
public void handleMessage(StatusMQDto dto) {
AsyncMain asyncMain = new AsyncMain();
asyncMain.setPrimaryKey(dto.getDictId());
asyncMain.setStatus(dto.getStatus()+"");
asyncMain.setOrgCode(dto.getOrgCode());
asyncMain.setOrgName(dto.getOrgName());
asyncMain.setDescr(dto.getMessage());
asyncMainService.save(asyncMain);
}
}

View File

@ -186,6 +186,12 @@ spring:
host: redis
port: 6379
password: uUgrUus4JAYuwxzo
rabbitmq:
host: rabbitm
prot: 5672
username: hldy
password: SJ+lhRn6nZ43KeXE
virtual-host: /hldy
#mybatis plus 设置
mybatis-plus:
mapper-locations: classpath*:org/jeecg/**/xml/*Mapper.xml,classpath*:com/nu/**/xml/*Mapper.xml