服务指令同步

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.dto.DirectiveAsyncMQDto;
import com.nu.modules.directivetag.body.service.IDirectiveBodyTagService; import com.nu.modules.directivetag.body.service.IDirectiveBodyTagService;
import com.nu.modules.servicedirective.entity.ConfigServiceDirective; import com.nu.modules.servicedirective.entity.ConfigServiceDirective;
import com.nu.modules.servicedirective.entity.DirectiveSyncDto;
import com.nu.modules.servicedirective.service.IConfigServiceDirectiveService; import com.nu.modules.servicedirective.service.IConfigServiceDirectiveService;
import com.nu.utils.RabbitMQUtil; import com.nu.utils.RabbitMQUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
@ -250,10 +251,10 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
if ("2".equals(dto.getStatus())) { if ("2".equals(dto.getStatus())) {
configServiceDirectiveService.auditPass(dto); configServiceDirectiveService.auditPass(dto);
} }
//通知业务平台修改审核状态 //管理平台不存数据了这个需求不要了 通知业务平台修改审核状态
DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto(); // DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
BeanUtils.copyProperties(dto, directiveAsyncMQDto); // BeanUtils.copyProperties(dto, directiveAsyncMQDto);
rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.auditresult", directiveAsyncMQDto); // rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.auditresult", directiveAsyncMQDto);
return Result.OK(Maps.newHashMap()); return Result.OK(Maps.newHashMap());
} }
@ -340,64 +341,82 @@ public class ConfigServiceDirectiveController extends JeecgController<ConfigServ
* @param dto * @param dto
* @return * @return
*/ */
@AutoLog(value = "服务指令-同步媒体资源给服务指令对应的业务平台") // @AutoLog(value = "服务指令-同步媒体资源给服务指令对应的业务平台")
@ApiOperation(value = "服务指令-同步媒体资源给服务指令对应的业务平台", notes = "服务指令-同步媒体资源给服务指令对应的业务平台") // @ApiOperation(value = "服务指令-同步媒体资源给服务指令对应的业务平台", notes = "服务指令-同步媒体资源给服务指令对应的业务平台")
@RequestMapping(value = "/syncMediaForBiz", method = {RequestMethod.PUT, RequestMethod.POST}) // @RequestMapping(value = "/syncMediaForBiz", method = {RequestMethod.PUT, RequestMethod.POST})
public Result<Map> syncMediaForBiz(@RequestBody ConfigServiceDirective dto) { // public Result<Map> syncMediaForBiz(@RequestBody ConfigServiceDirective dto) {
//处理媒体资源放在保存方法之前 // //处理媒体资源放在保存方法之前
configServiceDirectiveService.handleMediaFile(dto); // configServiceDirectiveService.handleMediaFile(dto);
//保存 // //保存
ConfigServiceDirective configServiceDirective = new ConfigServiceDirective(); // ConfigServiceDirective configServiceDirective = new ConfigServiceDirective();
BeanUtils.copyProperties(dto, configServiceDirective); // BeanUtils.copyProperties(dto, configServiceDirective);
configServiceDirectiveService.updateById(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(); // @AutoLog(value = "服务指令-同步媒体资源给所有业务平台")
BeanUtils.copyProperties(dto, directiveAsyncMQDto); // @ApiOperation(value = "服务指令-同步媒体资源给所有业务平台", notes = "服务指令-同步媒体资源给所有业务平台")
rabbitMQUtil.sendToExchange("hldy.directive", dto.getSysOrgCode() + ".directive.createmedia", directiveAsyncMQDto); // @RequestMapping(value = "/syncMediaForAllBiz", method = {RequestMethod.PUT, RequestMethod.POST})
return Result.OK(Maps.newHashMap()); // public Result<Map> syncMediaForAllBiz(@RequestBody ConfigServiceDirective dto) {
} // //处理媒体资源放在保存方法之前
// configServiceDirectiveService.handleMediaFile(dto);
@AutoLog(value = "服务指令-同步媒体资源给所有业务平台") // //保存
@ApiOperation(value = "服务指令-同步媒体资源给所有业务平台", notes = "服务指令-同步媒体资源给所有业务平台") // ConfigServiceDirective configServiceDirective = new ConfigServiceDirective();
@RequestMapping(value = "/syncMediaForAllBiz", method = {RequestMethod.PUT, RequestMethod.POST}) // BeanUtils.copyProperties(dto, configServiceDirective);
public Result<Map> syncMediaForAllBiz(@RequestBody ConfigServiceDirective dto) { // configServiceDirectiveService.updateById(configServiceDirective);
//处理媒体资源放在保存方法之前 //
configServiceDirectiveService.handleMediaFile(dto); // DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto();
//保存 // BeanUtils.copyProperties(dto, directiveAsyncMQDto);
ConfigServiceDirective configServiceDirective = new ConfigServiceDirective(); //
BeanUtils.copyProperties(dto, configServiceDirective); // List<JSONObject> orgList = sysBaseAPI.queryOpeDept();
configServiceDirectiveService.updateById(configServiceDirective); // List<String> codes = orgList.stream().map(o -> o.getString("code")).collect(Collectors.toList());
//
DirectiveAsyncMQDto directiveAsyncMQDto = new DirectiveAsyncMQDto(); // //启动线程循环 codes 5 分钟通知一个平台
BeanUtils.copyProperties(dto, directiveAsyncMQDto); // new Thread(() -> {
// for (String code : codes) {
List<JSONObject> orgList = sysBaseAPI.queryOpeDept(); // try {
List<String> codes = orgList.stream().map(o -> o.getString("code")).collect(Collectors.toList()); // rabbitMQUtil.sendToExchange("hldy.directive", code + ".directive.createmedia", directiveAsyncMQDto);
// // 发送完后休眠 5 分钟
//启动线程循环 codes 5 分钟通知一个平台 // Thread.sleep(TimeUnit.MINUTES.toMillis(5));
new Thread(() -> { // } catch (InterruptedException e) {
for (String code : codes) { // Thread.currentThread().interrupt();
try { // break;
rabbitMQUtil.sendToExchange("hldy.directive", code + ".directive.createmedia", directiveAsyncMQDto); // }
// 发送完后休眠 5 分钟 // }
Thread.sleep(TimeUnit.MINUTES.toMillis(5)); // }).start();
} catch (InterruptedException e) { //
Thread.currentThread().interrupt(); // return Result.OK(Maps.newHashMap());
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 = "服务指令-指令同步") @AutoLog(value = "服务指令-指令同步")
@ApiOperation(value = "服务指令-指令同步", notes = "服务指令-指令同步") @ApiOperation(value = "服务指令-指令同步", notes = "服务指令-指令同步")
@GetMapping(value = "/syncDirective") @PostMapping(value = "/syncDirective")
@DS("#dataSourceCode") @DS("#dataSourceCode")
public Result<Map> syncDirective(@RequestParam(name = "dataSourceCode") String dataSourceCode, @RequestParam(name = "syncIds") String syncIds, @RequestParam(name = "syncOrgCodes") String syncOrgCodes) { public Result<Map> syncDirective(@RequestParam(name = "dataSourceCode") String dataSourceCode,@RequestBody DirectiveSyncDto dto) {
//服务指令 //同步-新增服务指令
configServiceDirectiveService.syncDirective(syncIds, syncOrgCodes); 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(); 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 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 * @param syncOrgCodes 需要同步的目标平台orgCode
*/ */
@Override @Override
public void syncDirective(String syncIds, String syncOrgCodes) { public void syncDirective(String syncIds, String syncOrgCodes, String syncOption) {
DirectiveMQDto directiveMQDto = new DirectiveMQDto(); DirectiveMQDto directiveMQDto = new DirectiveMQDto();
List<ConfigServiceDirective> directives; List<ConfigServiceDirective> directives;
List<String> directiveIds = Arrays.asList(syncIds.split(",")); List<String> directiveIds = Arrays.asList(syncIds.split(","));
@ -419,6 +419,15 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
directives = baseMapper.pageList(null, param); directives = baseMapper.pageList(null, param);
if (directives != null && !directives.isEmpty()) { if (directives != null && !directives.isEmpty()) {
directives.stream().forEach(record -> { 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(); List<DirectiveBodyTag> bodyTagList = record.getBodyTagList();
record.setBodyTags(bodyTagList.stream().map(DirectiveBodyTag::getId).collect(Collectors.joining(","))); record.setBodyTags(bodyTagList.stream().map(DirectiveBodyTag::getId).collect(Collectors.joining(",")));
@ -431,27 +440,33 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
//分类标签 //分类标签
{ {
List<String> instructionTagIds = directives.stream().map(ConfigServiceDirective::getInstructionTagId).filter(instructionTagId -> instructionTagId != null && !instructionTagId.isEmpty()).distinct().collect(Collectors.toList()); List<String> instructionTagIds = directives.stream().map(ConfigServiceDirective::getInstructionTagId).filter(instructionTagId -> instructionTagId != null && !instructionTagId.isEmpty()).distinct().collect(Collectors.toList());
if (!instructionTagIds.isEmpty()) {
QueryWrapper<InstructionTag> qw = new QueryWrapper<>(); QueryWrapper<InstructionTag> qw = new QueryWrapper<>();
qw.in("id", instructionTagIds); qw.in("id", instructionTagIds);
List<InstructionTag> list = instructionTagService.list(qw); List<InstructionTag> list = instructionTagService.list(qw);
directiveMQDto.setInstructionList(BeanUtil.copyToList(list, InstructionTagMQDto.class)); 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()); List<String> categoryIds = directives.stream().map(ConfigServiceDirective::getCategoryId).filter(categoryId -> categoryId != null && !categoryId.isEmpty()).distinct().collect(Collectors.toList());
if (!categoryIds.isEmpty()) {
QueryWrapper<ConfigServiceCategory> qw = new QueryWrapper<>(); QueryWrapper<ConfigServiceCategory> qw = new QueryWrapper<>();
qw.in("id", categoryIds); qw.in("id", categoryIds);
List<ConfigServiceCategory> list = categoryService.list(qw); List<ConfigServiceCategory> list = categoryService.list(qw);
directiveMQDto.setCategoryList(BeanUtil.copyToList(list, CategoryMQDto.class)); 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()); List<String> typeIds = directives.stream().map(ConfigServiceDirective::getTypeId).filter(typeId -> typeId != null && !typeId.isEmpty()).distinct().collect(Collectors.toList());
if (!typeIds.isEmpty()) {
QueryWrapper<ConfigServiceType> qw = new QueryWrapper<>(); QueryWrapper<ConfigServiceType> qw = new QueryWrapper<>();
qw.in("id", typeIds); qw.in("id", typeIds);
List<ConfigServiceType> list = typeService.list(qw); List<ConfigServiceType> list = typeService.list(qw);
directiveMQDto.setTypeList(BeanUtil.copyToList(list, DirectiveTypeMQDto.class)); directiveMQDto.setTypeList(BeanUtil.copyToList(list, DirectiveTypeMQDto.class));
} }
}
//体型标签 //体型标签
{ {
directiveMQDto.setBodyTagList(BeanUtil.copyToList(bodyTagService.selectAll(directiveIds, null), BodyTagMQDto.class)); directiveMQDto.setBodyTagList(BeanUtil.copyToList(bodyTagService.selectAll(directiveIds, null), BodyTagMQDto.class));