服务指令同步

This commit is contained in:
1378012178@qq.com 2025-07-30 13:39:09 +08:00
parent 0fb358ba4c
commit 9a1e035d1a
4 changed files with 117 additions and 71 deletions

View File

@ -9,6 +9,7 @@ import com.beust.jcommander.internal.Maps;
import com.nu.dto.DirectiveAsyncMQDto;
import com.nu.modules.directivetag.body.service.IDirectiveBodyTagService;
import com.nu.modules.servicedirective.entity.ConfigServiceDirective;
import com.nu.modules.servicedirective.entity.DirectiveSyncDto;
import com.nu.modules.servicedirective.service.IConfigServiceDirectiveService;
import com.nu.utils.RabbitMQUtil;
import io.swagger.annotations.Api;
@ -250,10 +251,10 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
if ("2".equals(dto.getStatus())) {
configServiceDirectiveService.auditPass(dto);
}
//通知业务平台修改审核状态
DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
BeanUtils.copyProperties(dto, directiveAsyncMQDto);
rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.auditresult", directiveAsyncMQDto);
//管理平台不存数据了这个需求不要了 通知业务平台修改审核状态
// DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
// BeanUtils.copyProperties(dto, directiveAsyncMQDto);
// rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.auditresult", directiveAsyncMQDto);
return Result.OK(Maps.newHashMap());
}
@ -340,64 +341,82 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
* @param dto
* @return
*/
@AutoLog(value = "服务指令-同步媒体资源给服务指令对应的业务平台")
@ApiOperation(value = "服务指令-同步媒体资源给服务指令对应的业务平台", notes = "服务指令-同步媒体资源给服务指令对应的业务平台")
@RequestMapping(value = "/syncMediaForBiz", method = {RequestMethod.PUT, RequestMethod.POST})
public Result<Map> syncMediaForBiz(@RequestBody ConfigServiceDirective dto) {
//处理媒体资源放在保存方法之前
configServiceDirectiveService.handleMediaFile(dto);
//保存
ConfigServiceDirective configServiceDirective = new ConfigServiceDirective();
BeanUtils.copyProperties(dto, configServiceDirective);
configServiceDirectiveService.updateById(configServiceDirective);
// @AutoLog(value = "服务指令-同步媒体资源给服务指令对应的业务平台")
// @ApiOperation(value = "服务指令-同步媒体资源给服务指令对应的业务平台", notes = "服务指令-同步媒体资源给服务指令对应的业务平台")
// @RequestMapping(value = "/syncMediaForBiz", method = {RequestMethod.PUT, RequestMethod.POST})
// public Result<Map> syncMediaForBiz(@RequestBody ConfigServiceDirective dto) {
// //处理媒体资源放在保存方法之前
// configServiceDirectiveService.handleMediaFile(dto);
// //保存
// ConfigServiceDirective configServiceDirective = new ConfigServiceDirective();
// BeanUtils.copyProperties(dto, configServiceDirective);
// configServiceDirectiveService.updateById(configServiceDirective);
//
// DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
// BeanUtils.copyProperties(dto, directiveAsyncMQDto);
// rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.createmedia", directiveAsyncMQDto);
// return Result.OK(Maps.newHashMap());
// }
DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
BeanUtils.copyProperties(dto, directiveAsyncMQDto);
rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.createmedia", directiveAsyncMQDto);
return Result.OK(Maps.newHashMap());
}
@AutoLog(value = "服务指令-同步媒体资源给所有业务平台")
@ApiOperation(value = "服务指令-同步媒体资源给所有业务平台", notes = "服务指令-同步媒体资源给所有业务平台")
@RequestMapping(value = "/syncMediaForAllBiz", method = {RequestMethod.PUT, RequestMethod.POST})
public Result<Map> syncMediaForAllBiz(@RequestBody ConfigServiceDirective dto) {
//处理媒体资源放在保存方法之前
configServiceDirectiveService.handleMediaFile(dto);
//保存
ConfigServiceDirective configServiceDirective = new ConfigServiceDirective();
BeanUtils.copyProperties(dto, configServiceDirective);
configServiceDirectiveService.updateById(configServiceDirective);
DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
BeanUtils.copyProperties(dto, directiveAsyncMQDto);
List<JSONObject> orgList = sysBaseAPI.queryOpeDept();
List<String> codes = orgList.stream().map(o -> o.getString("code")).collect(Collectors.toList());
//启动线程循环 codes 5 分钟通知一个平台
new Thread(() -> {
for (String code : codes) {
try {
rabbitMQUtil.sendToExchange("hldy.directive", code + ".directive.createmedia", directiveAsyncMQDto);
// 发送完后休眠 5 分钟
Thread.sleep(TimeUnit.MINUTES.toMillis(5));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
}
}).start();
return Result.OK(Maps.newHashMap());
}
// @AutoLog(value = "服务指令-同步媒体资源给所有业务平台")
// @ApiOperation(value = "服务指令-同步媒体资源给所有业务平台", notes = "服务指令-同步媒体资源给所有业务平台")
// @RequestMapping(value = "/syncMediaForAllBiz", method = {RequestMethod.PUT, RequestMethod.POST})
// public Result<Map> syncMediaForAllBiz(@RequestBody ConfigServiceDirective dto) {
// //处理媒体资源放在保存方法之前
// configServiceDirectiveService.handleMediaFile(dto);
// //保存
// ConfigServiceDirective configServiceDirective = new ConfigServiceDirective();
// BeanUtils.copyProperties(dto, configServiceDirective);
// configServiceDirectiveService.updateById(configServiceDirective);
//
// DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
// BeanUtils.copyProperties(dto, directiveAsyncMQDto);
//
// List<JSONObject> orgList = sysBaseAPI.queryOpeDept();
// List<String> codes = orgList.stream().map(o -> o.getString("code")).collect(Collectors.toList());
//
// //启动线程循环 codes 5 分钟通知一个平台
// new Thread(() -> {
// for (String code : codes) {
// try {
// rabbitMQUtil.sendToExchange("hldy.directive", code + ".directive.createmedia", directiveAsyncMQDto);
// // 发送完后休眠 5 分钟
// Thread.sleep(TimeUnit.MINUTES.toMillis(5));
// } catch (InterruptedException e) {
// Thread.currentThread().interrupt();
// break;
// }
// }
// }).start();
//
// return Result.OK(Maps.newHashMap());
// }
/**
* @param dataSourceCode 源数据机构编码
* @param syncIds 新增指令的id逗号拼接
* @param upIds 更新指令的id逗号拼接
* @param syncOrgCodes 同步给哪些机构
* @param syncOption 新增指令需要更新哪些内容 all(业务字段+指令资源 business业务字段 media指令资源
* @return
*/
@AutoLog(value = "服务指令-指令同步")
@ApiOperation(value = "服务指令-指令同步", notes = "服务指令-指令同步")
@GetMapping(value = "/syncDirective")
@PostMapping(value = "/syncDirective")
@DS("#dataSourceCode")
public Result<Map> syncDirective(@RequestParam(name = "dataSourceCode") String dataSourceCode, @RequestParam(name = "syncIds") String syncIds, @RequestParam(name = "syncOrgCodes") String syncOrgCodes) {
//服务指令
configServiceDirectiveService.syncDirective(syncIds, syncOrgCodes);
public Result<Map> syncDirective(@RequestParam(name = "dataSourceCode") String dataSourceCode,@RequestBody DirectiveSyncDto dto) {
//同步-新增服务指令
configServiceDirectiveService.syncDirective(dto.getSyncIds(), dto.getSyncOrgCodes(), dto.getSyncOption());
//给新增的指令同步指令资源
if ("all".equals(dto.getSyncOption()) || "media".equals(dto.getSyncOption())) {
}
//同步 - 更新指令资源字段
if (StringUtils.isNotBlank(dto.getUpIds())) {
}
//发送消息
return Result.ok();
}

View File

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

View File

@ -62,5 +62,5 @@ public interface IConfigServiceDirectiveService extends IService<ConfigServiceDi
void auditPass(ConfigServiceDirective dto);
//同步服务指令
void syncDirective(String syncIds, String syncOrgCodes);
void syncDirective(String syncIds, String syncOrgCodes, String syncOption);
}

View File

@ -405,7 +405,7 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
* @param syncOrgCodes 需要同步的目标平台orgCode
*/
@Override
public void syncDirective(String syncIds, String syncOrgCodes) {
public void syncDirective(String syncIds, String syncOrgCodes, String syncOption) {
DirectiveMQDto directiveMQDto = new DirectiveMQDto();
List<ConfigServiceDirective> directives;
List<String> directiveIds = Arrays.asList(syncIds.split(","));
@ -419,6 +419,15 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
directives = baseMapper.pageList(null, param);
if (directives != null && !directives.isEmpty()) {
directives.stream().forEach(record -> {
//只同步业务字段的话清空指令资源字段的值
if ("business".equals(syncOption)) {
record.setPreviewFile(null);
record.setImmediateFile(null);
record.setMp3File(null);
record.setMp4File(null);
record.setServiceContent(null);
}
List<DirectiveBodyTag> bodyTagList = record.getBodyTagList();
record.setBodyTags(bodyTagList.stream().map(DirectiveBodyTag::getId).collect(Collectors.joining(",")));
@ -431,26 +440,32 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
//分类标签
{
List<String> instructionTagIds = directives.stream().map(ConfigServiceDirective::getInstructionTagId).filter(instructionTagId -> instructionTagId != null && !instructionTagId.isEmpty()).distinct().collect(Collectors.toList());
QueryWrapper<InstructionTag> qw = new QueryWrapper<>();
qw.in("id", instructionTagIds);
List<InstructionTag> list = instructionTagService.list(qw);
directiveMQDto.setInstructionList(BeanUtil.copyToList(list, InstructionTagMQDto.class));
if (!instructionTagIds.isEmpty()) {
QueryWrapper<InstructionTag> qw = new QueryWrapper<>();
qw.in("id", instructionTagIds);
List<InstructionTag> list = instructionTagService.list(qw);
directiveMQDto.setInstructionList(BeanUtil.copyToList(list, InstructionTagMQDto.class));
}
}
//服务类别
{
List<String> categoryIds = directives.stream().map(ConfigServiceDirective::getCategoryId).filter(categoryId -> categoryId != null && !categoryId.isEmpty()).distinct().collect(Collectors.toList());
QueryWrapper<ConfigServiceCategory> qw = new QueryWrapper<>();
qw.in("id", categoryIds);
List<ConfigServiceCategory> list = categoryService.list(qw);
directiveMQDto.setCategoryList(BeanUtil.copyToList(list, CategoryMQDto.class));
if (!categoryIds.isEmpty()) {
QueryWrapper<ConfigServiceCategory> qw = new QueryWrapper<>();
qw.in("id", categoryIds);
List<ConfigServiceCategory> list = categoryService.list(qw);
directiveMQDto.setCategoryList(BeanUtil.copyToList(list, CategoryMQDto.class));
}
}
//服务类型
{
List<String> typeIds = directives.stream().map(ConfigServiceDirective::getTypeId).filter(typeId -> typeId != null && !typeId.isEmpty()).distinct().collect(Collectors.toList());
QueryWrapper<ConfigServiceType> qw = new QueryWrapper<>();
qw.in("id", typeIds);
List<ConfigServiceType> list = typeService.list(qw);
directiveMQDto.setTypeList(BeanUtil.copyToList(list, DirectiveTypeMQDto.class));
if (!typeIds.isEmpty()) {
QueryWrapper<ConfigServiceType> qw = new QueryWrapper<>();
qw.in("id", typeIds);
List<ConfigServiceType> list = typeService.list(qw);
directiveMQDto.setTypeList(BeanUtil.copyToList(list, DirectiveTypeMQDto.class));
}
}
//体型标签
{