长者标签

This commit is contained in:
1378012178@qq.com 2025-08-15 14:19:14 +08:00
parent c724558cbb
commit 59b51aedab
5 changed files with 213 additions and 172 deletions

View File

@ -1,26 +1,41 @@
package com.nu.modules.eldertag.controller;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
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.nu.dto.DirectiveAsyncMQDto;
import com.nu.dto.DirectiveMQDto;
import com.nu.dto.ElderTagAsyncMQDto;
import com.nu.dto.ElderTagMQDto;
import com.nu.enums.MQStatus;
import com.nu.modules.async.entity.AsyncMain;
import com.nu.modules.async.entity.AsyncStatus;
import com.nu.modules.async.service.IAsyncMainService;
import com.nu.modules.async.service.IAsyncStatusService;
import com.nu.modules.eldertag.entity.ElderTag;
import com.nu.modules.eldertag.entity.ElderTagSyncDto;
import com.nu.modules.eldertag.service.IElderTagService;
import com.nu.utils.RabbitMQUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Description: 长者标签
@ -37,6 +52,13 @@ public class ElderTagController extends JeecgController<ElderTag, IElderTagServi
private IElderTagService elderTagService;
@Autowired
private ISysBaseAPI sysBaseAPI;
@Autowired
private RabbitMQUtil rabbitMQUtil;
@Autowired
private IAsyncMainService asyncMainService;
@Autowired
private IAsyncStatusService asyncStatusService;
/**
* 分页列表查询-更换数据源
@ -102,4 +124,79 @@ public class ElderTagController extends JeecgController<ElderTag, IElderTagServi
}
return Result.OK(elderTag);
}
/**
* @param sourceOrgCode 源数据机构编码
* @return
*/
@AutoLog(value = "长者标签-标签同步")
@ApiOperation(value = "长者标签-标签同步", notes = "长者标签-标签同步")
@PostMapping(value = "/syncElderTag")
@DS("#sourceOrgCode")
public Result<Map> syncElderTag(@RequestParam(name = "sourceOrgCode") String sourceOrgCode, @RequestBody ElderTagSyncDto dto) {
//处理接口地址
String fullPath = "";
if ("all".equals(dto.getSyncOption()) || "media".equals(dto.getSyncOption()) || StringUtils.isNotBlank(dto.getUpIds())) {
JSONObject deptInfo = elderTagService.getDeptInfo("master", sourceOrgCode);
String url = deptInfo.getString("url");
String contextPath = deptInfo.getString("contextPath");
String baseUrl = url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
String normalizedContextPath = contextPath.startsWith("/") ? contextPath : "/" + contextPath;
normalizedContextPath = normalizedContextPath.endsWith("/")
? normalizedContextPath.substring(0, normalizedContextPath.length() - 1)
: normalizedContextPath;
//接口协议域名上下文路径
fullPath = baseUrl + normalizedContextPath;
}
//同步-新增服务指令
if (StringUtils.isNotBlank(dto.getSyncIds())) {
elderTagService.syncElderTag(dto.getSyncIds(), dto.getSyncOrgCodes(), dto.getSyncOption(), fullPath, sourceOrgCode);
}
//待更新的指令
if (StringUtils.isNotBlank(dto.getUpIds())) {
ElderTagMQDto elderMQDto = new ElderTagMQDto();
QueryWrapper<ElderTag> qw = new QueryWrapper<>();
qw.in("id", dto.getUpIds().split(","));
List<ElderTag> elderTags = elderTagService.list(qw);
elderMQDto.setElderTagList(BeanUtil.copyToList(elderTags, ElderTagAsyncMQDto.class));
List<ElderTagAsyncMQDto> upElderTagList = elderMQDto.getElderTagList();
for (int i = 0; i < upElderTagList.size(); i++) {
upElderTagList.get(i).setApi(fullPath);
}
new Thread(() -> {
for (String code : dto.getSyncOrgCodes().split(",")) {
try {
AsyncMain asyncMain = new AsyncMain();
asyncMain.setType("elderTag");
asyncMain.setOrgCode(sourceOrgCode);
asyncMain.setDescr("长者标签同步");
asyncMainService.saveData("master", asyncMain);
elderMQDto.setAsyncId(asyncMain.getId());
AsyncStatus asyncStatus_file = new AsyncStatus();
asyncStatus_file.setPkid(asyncMain.getId());
asyncStatus_file.setCode("file");
asyncStatus_file.setName("文件");
asyncStatus_file.setStatus(MQStatus.LOADING.getCode() + "");
asyncStatus_file.setMsg("同步中");
asyncStatus_file.setTargetOrgCode(code);
asyncStatusService.saveData("master", asyncStatus_file);
rabbitMQUtil.sendToExchange("hldy.eldertag", code + ".eldertag.createmedia", elderMQDto);
// 发送完后休眠 5 分钟
// Thread.sleep(TimeUnit.MINUTES.toMillis(5));
// } catch (InterruptedException e) {
} catch (Exception e) {
Thread.currentThread().interrupt();
break;
}
}
}).start();
}
//发送消息
return Result.ok();
}
}

View File

@ -0,0 +1,12 @@
package com.nu.modules.eldertag.entity;
import lombok.Data;
@Data
public class ElderTagSyncDto {
private String dataSourceCode;
private String syncIds;
private String upIds;
private String syncOrgCodes;
private String syncOption;
}

View File

@ -1,5 +1,7 @@
package com.nu.modules.eldertag.service;
import com.alibaba.fastjson.JSONObject;
import com.nu.dto.DirectiveMQDto;
import com.nu.dto.ElderTagMQDto;
import com.nu.modules.eldertag.entity.ElderTag;
import com.baomidou.mybatisplus.extension.service.IService;
@ -14,5 +16,8 @@ import java.util.List;
*/
public interface IElderTagService extends IService<ElderTag> {
JSONObject getDeptInfo(String master, String dataSourceCode);
ElderTagMQDto syncElderTag(String syncIds, String syncOrgCodes, String syncOption, String fullPath, String dataSourceCode);
}

View File

@ -1,23 +1,27 @@
package com.nu.modules.eldertag.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nu.dto.ElderTagAsyncMQDto;
import com.nu.dto.ElderTagMQDto;
import com.nu.enums.MQStatus;
import com.nu.modules.async.entity.AsyncMain;
import com.nu.modules.async.entity.AsyncStatus;
import com.nu.modules.async.service.IAsyncMainService;
import com.nu.modules.async.service.IAsyncStatusService;
import com.nu.modules.eldertag.entity.ElderTag;
import com.nu.modules.eldertag.mapper.ElderTagMapper;
import com.nu.modules.eldertag.service.IElderTagService;
import com.nu.modules.sysconfig.ISysConfigApi;
import com.nu.utils.RabbitMQUtil;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
/**
* @Description: 长者标签
@ -28,4 +32,73 @@ import java.util.Map;
@Service
public class ElderTagServiceImpl extends ServiceImpl<ElderTagMapper, ElderTag> implements IElderTagService {
@Autowired
private RabbitMQUtil rabbitMQUtil;
@Autowired
private ISysBaseAPI sysBaseAPI;
@Autowired
private IAsyncMainService asyncMainService;
@Autowired
private IAsyncStatusService asyncStatusService;
@DS("dataSourceCode")
@Override
public JSONObject getDeptInfo(String dataSourceCode, String orgCode) {
return sysBaseAPI.getOrgInfo(orgCode);
}
/**
* @param syncIds 需要同步的标签ID
* @param syncOrgCodes 需要同步的目标平台orgCode
*/
@Override
public ElderTagMQDto syncElderTag(String syncIds, String syncOrgCodes, String syncOption, String fullPath, String dataSourceCode) {
ElderTagMQDto elderMQDto = new ElderTagMQDto();
QueryWrapper<ElderTag> qw = new QueryWrapper<>();
qw.in("id", syncIds.split(","));
List<ElderTag> elderTags = baseMapper.selectList(qw);
elderMQDto.setElderTagList(BeanUtil.copyToList(elderTags, ElderTagAsyncMQDto.class));
if ("all".equals(syncOption) || "media".equals(syncOption)) {
elderMQDto.setIzSyncMedia(true);
elderMQDto.getElderTagList().stream().forEach(d -> {
d.setApi(fullPath);
});
}
//给对应业务平台发送消息
Arrays.stream(syncOrgCodes.split(",")).
forEach(orgCode ->
{
AsyncMain asyncMain = new AsyncMain();
asyncMain.setType("elderTag");
asyncMain.setOrgCode(dataSourceCode);
asyncMain.setDescr("长者标签同步");
asyncMainService.saveData("master", asyncMain);
elderMQDto.setAsyncId(asyncMain.getId());
AsyncStatus asyncStatus_data = new AsyncStatus();
asyncStatus_data.setPkid(asyncMain.getId());
asyncStatus_data.setCode("data");
asyncStatus_data.setName("数据");
asyncStatus_data.setStatus(MQStatus.LOADING.getCode() + "");
asyncStatus_data.setMsg("同步中");
asyncStatus_data.setTargetOrgCode(orgCode);
asyncStatusService.saveData("master", asyncStatus_data);
if ("all".equals(syncOption) || "media".equals(syncOption)) {
AsyncStatus asyncStatus_file = new AsyncStatus();
asyncStatus_file.setPkid(asyncMain.getId());
asyncStatus_file.setCode("file");
asyncStatus_file.setName("文件");
asyncStatus_file.setStatus(MQStatus.LOADING.getCode() + "");
asyncStatus_file.setMsg("同步中");
asyncStatus_file.setTargetOrgCode(orgCode);
asyncStatusService.saveData("master", asyncStatus_file);
}
rabbitMQUtil.sendToExchange("hldy.eldertag", orgCode + ".eldertag.synceldertag", elderMQDto);
});
return elderMQDto;
}
}

View File

@ -1,6 +1,10 @@
package com.nu.mq.eldertag.listener;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nu.dto.ElderTagAsyncMQDto;
import com.nu.dto.StatusMQDto;
import com.nu.enums.MQStatus;
import com.nu.modules.async.entity.AsyncStatus;
import com.nu.modules.async.service.IAsyncMainService;
import com.nu.modules.async.service.IAsyncStatusService;
import com.nu.modules.canaddeldertag.entity.CanAddElderTag;
@ -42,168 +46,18 @@ public class ElderTaggMQListener {
canAddElderTagService.save(canAddElderTag);
}
// /**
// * 业务平台新增指令/编辑未授权指令 传给 管理平台进行审核
// *
// * @param dto
// */
//// @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "hldy.eldettag.audit"), exchange = @Exchange(name = "hldy.eldettag", type = ExchangeTypes.DIRECT), key = "hldy.eldettag.audit"), errorHandler = "elderTaggMQErrorHandler")
// public void auditBizDirective2(DirectiveAsyncMQDto dto) {
// //先处理各字典项 只新增不修改
// String instructionTagId = dto.getInstructionTagId();
// String categoryId = dto.getCategoryId();
// String typeId = dto.getTypeId();
// String orgCode = dto.getSysOrgCode();
// //分类标签
// {
// QueryWrapper<InstructionTag> instructionTagQW = new QueryWrapper<>();
// instructionTagQW.eq("id", instructionTagId);
// InstructionTag instructionObj = instructionTagService.getOne(instructionTagQW);
// if (instructionObj == null) {
// //新增分类标签
// InstructionTag instructionTag = new InstructionTag();
// instructionTag.setId(instructionTagId);
// instructionTag.setInstructionName(dto.getInstructionName());
// instructionTag.setSort(999);
// instructionTag.setStatus("1");
// instructionTag.setIzEnabled("1");
// instructionTag.setDelFlag("0");
// instructionTag.setSysOrgCode(orgCode);
// instructionTagService.save(instructionTag);
// }
// }
// //服务类别
// {
// QueryWrapper<ConfigServiceCategory> categoryQW = new QueryWrapper<>();
// categoryQW.eq("id", categoryId);
// ConfigServiceCategory categoryObj = categoryService.getOne(categoryQW);
// if (categoryObj == null) {
// //新增服务类别
// ConfigServiceCategory configServiceCategory = new ConfigServiceCategory();
// configServiceCategory.setId(categoryId);
// configServiceCategory.setInstructionId(instructionTagId);
// configServiceCategory.setCategoryName(dto.getCategoryName());
// configServiceCategory.setSort(999);
// configServiceCategory.setStatus("1");
// configServiceCategory.setIzEnabled("1");
// configServiceCategory.setDelFlag("0");
// configServiceCategory.setSysOrgCode(orgCode);
// categoryService.save(configServiceCategory);
// }
// }
// //服务类型
// {
// QueryWrapper<ConfigServiceType> typeQW = new QueryWrapper<>();
// typeQW.eq("id", typeId);
// ConfigServiceType typeObj = typeService.getOne(typeQW);
// if (typeObj == null) {
// //新增服务类别
// ConfigServiceType configServiceType = new ConfigServiceType();
// configServiceType.setId(typeId);
// configServiceType.setInstructionId(instructionTagId);
// configServiceType.setCategoryId(categoryId);
// configServiceType.setTypeName(dto.getTypeName());
// configServiceType.setSort(999);
// configServiceType.setStatus("1");
// configServiceType.setIzEnabled("1");
// configServiceType.setDelFlag("0");
// configServiceType.setSysOrgCode(orgCode);
// typeService.save(configServiceType);
// }
// }
// //体型标签
// {
// String bodyTagsObj = dto.getBodyTagsObj();
// JSONArray jsonArray = JSON.parseArray(bodyTagsObj);
// //体型标签-服务指令中间表
// bodyTagService.removeAllByDirectiveId(dto.getId());
// List<DirectiveBodyTagRelation> btrList = Lists.newArrayList();
// for (int i = 0; i < jsonArray.size(); i++) {
// JSONObject item = jsonArray.getJSONObject(i);
// String bodyTagId = item.getString("id");
// String bodyTagLabel = item.getString("label");
// //处理每一个体型标签
// {
// QueryWrapper<DirectiveBodyTag> bodyTagQW = new QueryWrapper<>();
// bodyTagQW.eq("id", bodyTagId);
// DirectiveBodyTag bodyTagObj = bodyTagService.getOne(bodyTagQW);
// if (bodyTagObj == null) {
// DirectiveBodyTag directiveBodyTag = new DirectiveBodyTag();
// directiveBodyTag.setId(bodyTagId);
// directiveBodyTag.setTagName(bodyTagLabel);
// directiveBodyTag.setSort(999);
// directiveBodyTag.setStatus("1");
// directiveBodyTag.setIzEnabled("1");
// directiveBodyTag.setDelFlag("0");
// directiveBodyTag.setSysOrgCode(orgCode);
// //新增
// bodyTagService.save(directiveBodyTag);
// }
// DirectiveBodyTagRelation btr = new DirectiveBodyTagRelation();
// btr.setDirectiveId(dto.getId());
// btr.setTagId(bodyTagId);
// btrList.add(btr);
// }
// }
// //中间关系表
// bodyTagService.insertAllRelation(btrList);
// }
// //情绪标签
// {
// String emotionTagsObj = dto.getEmotionTagsObj();
// JSONArray jsonArray = JSON.parseArray(emotionTagsObj);
// //体型标签-服务指令中间表
// emotionTagService.removeAllByDirectiveId(dto.getId());
// List<DirectiveEmotionTagRelation> etrList = Lists.newArrayList();
// for (int i = 0; i < jsonArray.size(); i++) {
// JSONObject item = jsonArray.getJSONObject(i);
// String emotionTagId = item.getString("id");
// String emotionTagLabel = item.getString("label");
// //处理每一个体型标签
// {
// QueryWrapper<DirectiveEmotionTag> emotionTagQW = new QueryWrapper<>();
// emotionTagQW.eq("id", emotionTagId);
// DirectiveEmotionTag emotionTagObj = emotionTagService.getOne(emotionTagQW);
// if (emotionTagObj == null) {
// DirectiveEmotionTag directiveEmotionTag = new DirectiveEmotionTag();
// directiveEmotionTag.setId(emotionTagId);
// directiveEmotionTag.setTagName(emotionTagLabel);
// directiveEmotionTag.setSort(999);
// directiveEmotionTag.setStatus("1");
// directiveEmotionTag.setIzEnabled("1");
// directiveEmotionTag.setDelFlag("0");
// directiveEmotionTag.setSysOrgCode(orgCode);
// //新增
// emotionTagService.save(directiveEmotionTag);
// }
// DirectiveEmotionTagRelation etr = new DirectiveEmotionTagRelation();
// etr.setDirectiveId(dto.getId());
// etr.setTagId(emotionTagId);
// etrList.add(etr);
// }
// }
// //中间关系表
// emotionTagService.insertAllRelation(etrList);
// }
//
// //存储服务指令
// ConfigServiceDirective directive = new ConfigServiceDirective();
// BeanUtils.copyProperties(dto, directive);
// directiveService.save(directive);
// }
//
// @RabbitListener(bindings = @QueueBinding(value = @Queue(name = "fwzl.async.result"), exchange = @Exchange(name = "hldy.fwzl", type = ExchangeTypes.DIRECT), key = "fwzl.async.result"), errorHandler = "elderTaggMQErrorHandler")
// public void handleNu002AsyncMessageStatus(StatusMQDto dto) {
// LambdaQueryWrapper<AsyncStatus> qw = new LambdaQueryWrapper<>();
// qw.eq(AsyncStatus::getPkid, dto.getAsyncId());
// qw.eq(AsyncStatus::getCode, dto.getCode());
// AsyncStatus asyncStatus = asyncStatusService.getOne(qw);
// if (dto.getStatus() == MQStatus.SUCCESS.getCode()) {
// asyncStatus.setStatus(dto.getStatus() + "");
// } else {
// asyncStatus.setStatus("500");
// }
// asyncStatus.setMsg(dto.getMessage());
// asyncStatusService.updateById(asyncStatus);
// }
@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "eldertag.async.result"), exchange = @Exchange(name = "hldy.eldertag", type = ExchangeTypes.DIRECT), key = "eldertag.async.result"), errorHandler = "elderTaggMQErrorHandler")
public void handleNu002AsyncMessageStatus(StatusMQDto dto) {
LambdaQueryWrapper<AsyncStatus> qw = new LambdaQueryWrapper<>();
qw.eq(AsyncStatus::getPkid, dto.getAsyncId());
qw.eq(AsyncStatus::getCode, dto.getCode());
AsyncStatus asyncStatus = asyncStatusService.getOne(qw);
if (dto.getStatus() == MQStatus.SUCCESS.getCode()) {
asyncStatus.setStatus(dto.getStatus() + "");
} else {
asyncStatus.setStatus("500");
}
asyncStatus.setMsg(dto.getMessage());
asyncStatusService.updateById(asyncStatus);
}
}