长者标签
This commit is contained in:
parent
63da8e002c
commit
53cd3038e0
|
@ -0,0 +1,49 @@
|
|||
package com.nu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 长者标签
|
||||
* @Author: zmy
|
||||
* @Date: 2025-08-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
public class ElderTagAsyncMQDto implements Serializable {
|
||||
|
||||
/**id*/
|
||||
private String id;
|
||||
/**标签类型*/
|
||||
private String type;
|
||||
/**标签名称*/
|
||||
private String tagName;
|
||||
/**价格*/
|
||||
private BigDecimal price;
|
||||
/**图标*/
|
||||
private String pic;
|
||||
/**图标md5值*/
|
||||
private String picMd5;
|
||||
/**排序*/
|
||||
private Integer sort;
|
||||
/**是否启用*/
|
||||
private String izEnabled;
|
||||
/**是否删除*/
|
||||
private String delFlag;
|
||||
/**创建人*/
|
||||
private String createBy;
|
||||
/**创建日期*/
|
||||
private Date createTime;
|
||||
/**更新人*/
|
||||
private String updateBy;
|
||||
/**更新日期*/
|
||||
private Date updateTime;
|
||||
/**所属机构*/
|
||||
private String sysOrgCode;
|
||||
/**资源请求接口域名+项目上下文路径 */
|
||||
private String api;
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.nu.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class ElderTagMQDto {
|
||||
private boolean izInc;//是否为增量 否则为全量
|
||||
private String orgCode;//机构编码
|
||||
private String idStr;
|
||||
private List<String> idList;
|
||||
|
||||
//同步主表id
|
||||
private String asyncId;
|
||||
//同步子表code
|
||||
private String code;
|
||||
|
||||
//指令集合
|
||||
private List<ElderTagAsyncMQDto> elderTagList;
|
||||
//是否同步指令资源
|
||||
private boolean izSyncMedia;
|
||||
}
|
|
@ -0,0 +1,101 @@
|
|||
package com.nu.utils;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class NuFileUtils {
|
||||
|
||||
private static String uploadpath;
|
||||
|
||||
// 通过Setter注入静态字段
|
||||
@Value("${jeecg.path.upload}")
|
||||
public void setUploadpath(String path) {
|
||||
uploadpath = path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将文件转存到静态资源目录中
|
||||
*
|
||||
* @param targetDir 目标目录
|
||||
* @param filePath 文件路径
|
||||
* @return 如果路径有变化返回新路径,否则返回null
|
||||
*/
|
||||
public static Map<String, String> processFile(String targetDir, String filePath) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 检查文件路径是否以目标目录开头
|
||||
if (!filePath.startsWith(targetDir + "/")) {
|
||||
// 获取文件名(路径的最后一部分)
|
||||
String fileName = filePath.substring(filePath.lastIndexOf('/') + 1);
|
||||
|
||||
// 构建新的完整路径
|
||||
String newRelativePath = targetDir + "/" + fileName;
|
||||
String oldFullPath = uploadpath + "/" + filePath;
|
||||
String newFullPath = uploadpath + "/" + newRelativePath;
|
||||
|
||||
// 创建目标目录(如果不存在)
|
||||
File targetDirectory = new File(uploadpath + "/" + targetDir);
|
||||
if (!targetDirectory.exists()) {
|
||||
targetDirectory.mkdirs();
|
||||
}
|
||||
|
||||
// 移动文件
|
||||
File oldFile = new File(oldFullPath);
|
||||
if (oldFile.exists()) {
|
||||
// 计算原文件的MD5
|
||||
String md5 = calculateMD5(oldFile);
|
||||
|
||||
File newFile = new File(newFullPath);
|
||||
|
||||
// 如果目标文件已存在,先删除
|
||||
if (newFile.exists()) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
||||
// 移动文件
|
||||
Files.move(oldFile.toPath(), newFile.toPath());
|
||||
|
||||
// 返回包含新路径和MD5的Map
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("path", newRelativePath);
|
||||
result.put("md5", md5);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理异常,可以根据实际需求记录日志或抛出
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String calculateMD5(File file) throws Exception {
|
||||
try (InputStream is = Files.newInputStream(file.toPath())) {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
while ((read = is.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, read);
|
||||
}
|
||||
byte[] md5 = md.digest();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : md5) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-elder-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nu-elder-local-api</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nursing-unit-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-system-local-api</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nursing-unit-elder</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nu-elder-api</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>nu-elder-local-api</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nursing-unit-base-core</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,47 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nursing-unit-elder</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nu-elder-biz</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-elder-local-api</artifactId>
|
||||
<version>${nursingunit.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework.boot</groupId>
|
||||
<artifactId>hibernate-re</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 企业微信/钉钉 api -->
|
||||
<dependency>
|
||||
<groupId>org.jeecgframework</groupId>
|
||||
<artifactId>weixin4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-admin-biz</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-admin-biz</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,259 @@
|
|||
package com.nu.modules.eldertag.controller;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.nu.dto.DirectiveAsyncMQDto;
|
||||
import com.nu.dto.ElderTagAsyncMQDto;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.api.vo.Result;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.jeecg.common.system.query.QueryGenerator;
|
||||
import com.nu.modules.eldertag.entity.ElderTag;
|
||||
import com.nu.modules.eldertag.service.IElderTagService;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.jeecg.common.system.base.controller.JeecgController;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
|
||||
/**
|
||||
* @Description: 长者标签
|
||||
* @Author: zmy
|
||||
* @Date: 2025-08-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Api(tags = "长者标签")
|
||||
@RestController
|
||||
@RequestMapping("/elder/elderTag")
|
||||
@Slf4j
|
||||
public class ElderTagController extends JeecgController<ElderTag, IElderTagService> {
|
||||
@Autowired
|
||||
private IElderTagService elderTagService;
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param elderTag
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "长者标签-分页列表查询")
|
||||
@ApiOperation(value = "长者标签-分页列表查询", notes = "长者标签-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<ElderTag>> queryPageList(ElderTag elderTag,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<ElderTag> queryWrapper = QueryGenerator.initQueryWrapper(elderTag, req.getParameterMap());
|
||||
queryWrapper.orderByAsc("sort");
|
||||
Page<ElderTag> page = new Page<ElderTag>(pageNo, pageSize);
|
||||
IPage<ElderTag> pageList = elderTagService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表查询-更换数据源
|
||||
*
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "长者标签-分页列表查询", notes = "长者标签-分页列表查询")
|
||||
@GetMapping(value = "/listByDS")
|
||||
@DS("#dataSourceCode")
|
||||
public Result<IPage<ElderTag>> queryPageListByDS(@RequestParam(name = "dataSourceCode") String dataSourceCode, ElderTag et, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest req) {
|
||||
if (StringUtils.isBlank(dataSourceCode)) {
|
||||
return Result.ok(new Page<ElderTag>());
|
||||
}
|
||||
QueryWrapper<ElderTag> queryWrapper = QueryGenerator.initQueryWrapper(et, req.getParameterMap());
|
||||
if (StringUtils.isNotBlank(et.getExcludeIds())) {
|
||||
queryWrapper.notIn("id", et.getExcludeIds().split(","));
|
||||
}
|
||||
queryWrapper.orderByAsc("sort");
|
||||
Page<ElderTag> page = new Page<ElderTag>(pageNo, pageSize);
|
||||
IPage<ElderTag> list = elderTagService.page(page, queryWrapper);
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询目标平台已有标签
|
||||
*
|
||||
* @param dataSourceCode
|
||||
* @return
|
||||
*/
|
||||
@GetMapping(value = "/idListByDS")
|
||||
@DS("#dataSourceCode")
|
||||
public Result<IPage<ElderTag>> idListByDS(@RequestParam(name = "dataSourceCode") String dataSourceCode, ElderTag et) {
|
||||
if (StringUtils.isBlank(dataSourceCode)) {
|
||||
return Result.ok(new Page<>());
|
||||
}
|
||||
QueryWrapper<ElderTag> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.select("id");
|
||||
if (StringUtils.isNotBlank(et.getExcludeIds())) {
|
||||
queryWrapper.notIn("id", et.getExcludeIds().split(","));
|
||||
}
|
||||
Page<ElderTag> page = new Page<>(1, -1);
|
||||
IPage<ElderTag> list = elderTagService.page(page, queryWrapper);
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param elderTag
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "长者标签-添加")
|
||||
@ApiOperation(value = "长者标签-添加", notes = "长者标签-添加")
|
||||
@RequiresPermissions("eldertag:nu_elder_tag:add")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody ElderTag elderTag) {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
elderTag.setId(deptInfo.getString("code") + IdUtil.simpleUUID());
|
||||
elderTag.setSysOrgCode(deptInfo.getString("code"));
|
||||
//处理静态资源
|
||||
elderTagService.handleMediaFile(elderTag);
|
||||
elderTagService.save(elderTag);
|
||||
|
||||
//同步给管理平台
|
||||
{
|
||||
ElderTagAsyncMQDto elderTagAsyncMQDto = new ElderTagAsyncMQDto();
|
||||
BeanUtils.copyProperties(elderTag, elderTagAsyncMQDto);
|
||||
rabbitMQUtil.sendToExchange("hldy.eldettag", "hldy.eldettag.newadd", elderTagAsyncMQDto);
|
||||
}
|
||||
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param elderTag
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "长者标签-编辑")
|
||||
@ApiOperation(value = "长者标签-编辑", notes = "长者标签-编辑")
|
||||
@RequiresPermissions("eldertag:nu_elder_tag:edit")
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody ElderTag elderTag) {
|
||||
//处理静态资源
|
||||
elderTagService.handleMediaFile(elderTag);
|
||||
elderTagService.updateById(elderTag);
|
||||
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "长者标签-通过id删除")
|
||||
@ApiOperation(value = "长者标签-通过id删除", notes = "长者标签-通过id删除")
|
||||
@RequiresPermissions("eldertag:nu_elder_tag:delete")
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
elderTagService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "长者标签-批量删除")
|
||||
@ApiOperation(value = "长者标签-批量删除", notes = "长者标签-批量删除")
|
||||
@RequiresPermissions("eldertag:nu_elder_tag:deleteBatch")
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
this.elderTagService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "长者标签-通过id查询")
|
||||
@ApiOperation(value = "长者标签-通过id查询", notes = "长者标签-通过id查询")
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<ElderTag> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
ElderTag elderTag = elderTagService.getById(id);
|
||||
if (elderTag == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(elderTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param elderTag
|
||||
*/
|
||||
@RequiresPermissions("eldertag:nu_elder_tag:exportXls")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, ElderTag elderTag) {
|
||||
return super.exportXls(request, elderTag, ElderTag.class, "长者标签");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions("eldertag:nu_elder_tag:importExcel")
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, ElderTag.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "长者标签-标签同步")
|
||||
@ApiOperation(value = "长者标签-标签同步", notes = "长者标签-标签同步")
|
||||
@PostMapping(value = "/syncElderTag")
|
||||
public Result<Map> syncElderTag(@RequestParam(name = "sourceOrgCode") String sourceOrgCode, @RequestBody ElderTag dto) {
|
||||
//同步
|
||||
if (StringUtils.isNotBlank(dto.getSyncIds())) {
|
||||
new Thread(() -> {
|
||||
service.syncElderTag(sourceOrgCode, dto.getSyncIds());
|
||||
}).start();
|
||||
}
|
||||
//发送消息
|
||||
return Result.ok();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.nu.modules.eldertag.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Date;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import org.jeecg.common.constant.ProvinceCityArea;
|
||||
import org.jeecg.common.util.SpringContextUtils;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import org.jeecg.common.aspect.annotation.Dict;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* @Description: 长者标签
|
||||
* @Author: zmy
|
||||
* @Date: 2025-08-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("nu_elder_tag")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="nu_elder_tag对象", description="长者标签")
|
||||
public class ElderTag implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**id*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "id")
|
||||
private java.lang.String id;
|
||||
/**标签类型*/
|
||||
@Excel(name = "标签类型", width = 15)
|
||||
@ApiModelProperty(value = "标签类型")
|
||||
@Dict(dicCode = "elder_tag_type")
|
||||
private java.lang.String type;
|
||||
/**标签名称*/
|
||||
@Excel(name = "标签名称", width = 15)
|
||||
@ApiModelProperty(value = "标签名称")
|
||||
private java.lang.String tagName;
|
||||
/**价格*/
|
||||
@Excel(name = "价格", width = 15)
|
||||
@ApiModelProperty(value = "价格")
|
||||
private java.math.BigDecimal price;
|
||||
/**图标*/
|
||||
@Excel(name = "图标", width = 15)
|
||||
@ApiModelProperty(value = "图标")
|
||||
private java.lang.String pic;
|
||||
/**图标md5值*/
|
||||
@ApiModelProperty(value = "图标md5值")
|
||||
private java.lang.String picMd5;
|
||||
/**排序*/
|
||||
@Excel(name = "排序", width = 15)
|
||||
@ApiModelProperty(value = "排序")
|
||||
private java.lang.Integer sort;
|
||||
/**是否启用*/
|
||||
@Excel(name = "是否启用", width = 15)
|
||||
@ApiModelProperty(value = "是否启用")
|
||||
@Dict(dicCode = "iz_enabled")
|
||||
private java.lang.String izEnabled;
|
||||
/**是否删除*/
|
||||
@Excel(name = "是否删除", width = 15)
|
||||
@ApiModelProperty(value = "是否删除")
|
||||
@TableLogic
|
||||
private java.lang.String delFlag;
|
||||
/**创建人*/
|
||||
@ApiModelProperty(value = "创建人")
|
||||
private java.lang.String createBy;
|
||||
/**创建日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建日期")
|
||||
private java.util.Date createTime;
|
||||
/**更新人*/
|
||||
@ApiModelProperty(value = "更新人")
|
||||
private java.lang.String updateBy;
|
||||
/**更新日期*/
|
||||
@JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "更新日期")
|
||||
private java.util.Date updateTime;
|
||||
/**所属机构*/
|
||||
@ApiModelProperty(value = "所属机构")
|
||||
private java.lang.String sysOrgCode;
|
||||
|
||||
/**需要排除的id */
|
||||
@TableField(exist = false)
|
||||
private String excludeIds;
|
||||
/**需要同步的id */
|
||||
@TableField(exist = false)
|
||||
private String SyncIds;
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.nu.modules.eldertag.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.nu.modules.eldertag.entity.ElderTag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 长者标签
|
||||
* @Author: zmy
|
||||
* @Date: 2025-08-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface ElderTagMapper extends BaseMapper<ElderTag> {
|
||||
|
||||
List<ElderTag> allData();
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.nu.modules.eldertag.mapper.ElderTagMapper">
|
||||
|
||||
<select id="allData" resultType="com.nu.modules.eldertag.entity.ElderTag">
|
||||
select id from nu_elder_tag
|
||||
</select>
|
||||
</mapper>
|
|
@ -0,0 +1,24 @@
|
|||
package com.nu.modules.eldertag.service;
|
||||
|
||||
import com.nu.dto.ElderTagMQDto;
|
||||
import com.nu.modules.eldertag.entity.ElderTag;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description: 长者标签
|
||||
* @Author: zmy
|
||||
* @Date: 2025-08-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
public interface IElderTagService extends IService<ElderTag> {
|
||||
|
||||
void handleMediaFile(ElderTag elderTag);
|
||||
|
||||
ElderTagMQDto syncElderTag(String sourceOrgCode, String syncIds);
|
||||
|
||||
List<ElderTag> allData();
|
||||
|
||||
void insertAllDirectives(List<ElderTag> needAddETList);
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
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.nu.dto.*;
|
||||
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.mq.eldertag.listener.ElderTagMQListener;
|
||||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import com.nu.utils.NuFileUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 长者标签
|
||||
* @Author: zmy
|
||||
* @Date: 2025-08-13
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class ElderTagServiceImpl extends ServiceImpl<ElderTagMapper, ElderTag> implements IElderTagService {
|
||||
|
||||
@Lazy
|
||||
@Autowired
|
||||
private ElderTagMQListener elderTagMQListener;
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
|
||||
/**
|
||||
* 将资源放到静态目录中
|
||||
*
|
||||
* @param elderTag
|
||||
*/
|
||||
@Override
|
||||
public void handleMediaFile(ElderTag elderTag) {
|
||||
//需要存储的路径
|
||||
String mediaFileSavePath = "/eldertag/" + elderTag.getTagName() + elderTag.getId();
|
||||
//图标
|
||||
String previewFile = elderTag.getPic();
|
||||
// 处理文件并获取更新后的路径
|
||||
Map<String, String> newFileMap = NuFileUtils.processFile(mediaFileSavePath, previewFile);
|
||||
if (newFileMap != null) {
|
||||
elderTag.setPic(newFileMap.get("path"));
|
||||
elderTag.setPicMd5(newFileMap.get("md5"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@DS("#sourceOrgCode")
|
||||
public ElderTagMQDto syncElderTag(String sourceOrgCode, String syncIds) {
|
||||
ElderTagMQDto etMQDto = new ElderTagMQDto();
|
||||
QueryWrapper<ElderTag> qw = new QueryWrapper<>();
|
||||
qw.in("id",syncIds.split(","));
|
||||
List<ElderTag> elderTags = baseMapper.selectList(qw);
|
||||
etMQDto.setElderTagList(BeanUtil.copyToList(elderTags, ElderTagAsyncMQDto.class));
|
||||
elderTagMQListener.handleIncremental2( etMQDto);
|
||||
|
||||
String apiAddress = "";
|
||||
//查询源数据平台的接口api地址
|
||||
{
|
||||
//各平台api地址都存在管理系统中 管理系统api地址在系统参数配置中 “ope_open_url”
|
||||
JSONObject opeOpenUrl = sysConfigApi.getByKeyByDS("master", "ope_open_url");
|
||||
String opeApiAddress = opeOpenUrl.getString("configValue");
|
||||
if (opeApiAddress.endsWith("/")) {
|
||||
opeApiAddress = opeApiAddress.substring(0, opeApiAddress.length() - 1);
|
||||
}
|
||||
String bizApiAddress = opeApiAddress + "/api/baseInfo/getOrgApiAddress?orgCode=" + sourceOrgCode;
|
||||
|
||||
try {
|
||||
String res = HttpRequestUtil.doGet(bizApiAddress, HttpRequestUtil.createDefaultHeaders());
|
||||
JSONObject jsonResponse = JSON.parseObject(res);
|
||||
JSONObject result = jsonResponse.getJSONObject("result");
|
||||
apiAddress = result.getString("url");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
elderTagMQListener.handleCreateMedia2(etMQDto, apiAddress);
|
||||
//给对应业务平台发送消息
|
||||
return etMQDto;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ElderTag> allData() {
|
||||
return baseMapper.allData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertAllDirectives(List<ElderTag> needAddETList) {
|
||||
needAddETList.stream().forEach(et -> {
|
||||
baseMapper.insert(et);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.nu.modules.mq.eldertag.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("elderTagMQErrorHandler")
|
||||
public class ElderTagMQExceptionHandler 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);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.nu.modules.mq.eldertag.listener;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.jeecg.common.system.api.ISysBaseAPI;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component("elderTagAsyncDQNP")
|
||||
public class DynamicQueueNameProvider {
|
||||
|
||||
@Autowired
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
public String getCreateMediaQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".eldertag.createmedia";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getCreateMediaKeyName() {
|
||||
return getCreateMediaQueueName();
|
||||
}
|
||||
|
||||
public String getSyncElderTagQueueName() {
|
||||
JSONObject deptInfo = sysBaseAPI.getDeptInfo();
|
||||
String orgCode = deptInfo.getString("code");
|
||||
if (StringUtils.isNotBlank(orgCode)) {
|
||||
return orgCode + ".eldertag.synceldertag";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public String getSyncElderTagKeyName() {
|
||||
return getSyncElderTagQueueName();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,289 @@
|
|||
package com.nu.modules.mq.eldertag.listener;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.nu.dto.ElderTagMQDto;
|
||||
import com.nu.dto.StatusMQDto;
|
||||
import com.nu.enums.MQStatus;
|
||||
import com.nu.modules.eldertag.entity.ElderTag;
|
||||
import com.nu.modules.eldertag.service.IElderTagService;
|
||||
import com.nu.modules.mediaasyncerrorlog.entity.MediaAsyncErrorLog;
|
||||
import com.nu.modules.mediaasyncerrorlog.service.IMediaAsyncErrorLogService;
|
||||
import com.nu.utils.FileDownloader;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import com.nu.utils.SafetyUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
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.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ElderTagMQListener {
|
||||
|
||||
@Value("${jeecg.path.upload}")
|
||||
private String upLoadPath;
|
||||
@Autowired
|
||||
private RabbitMQUtil rabbitMQUtil;
|
||||
@Autowired
|
||||
private IElderTagService elderTagService;
|
||||
@Autowired
|
||||
private IMediaAsyncErrorLogService mediaAsyncErrorLogService;
|
||||
|
||||
@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "#{elderTagAsyncDQNP.getSyncElderTagQueueName()}"), exchange = @Exchange(name = "hldy.eldertag", type = ExchangeTypes.DIRECT), key = "#{elderTagAsyncDQNP.getSyncElderTagKeyName()}"), errorHandler = "elderTagMQErrorHandler")
|
||||
@Transactional(rollbackFor = {Exception.class})
|
||||
public void handleAuditResult(ElderTagMQDto dto) {
|
||||
dto.setIzInc(true);
|
||||
dto.setIdStr(dto.getElderTagList().stream().map(d -> d.getId()).collect(Collectors.joining(",")));
|
||||
try {
|
||||
//增量处理数据
|
||||
handleIncremental(dto);
|
||||
//数据处理出错的话就不能继续处理标签资源了 所以方法放到这个位置
|
||||
handleCreateMedia(dto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//返回错误日志
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
statusMQDto.setStatus(MQStatus.PROCESS_FAILED.getCode());
|
||||
statusMQDto.setMessage(e.getMessage());
|
||||
statusMQDto.setAsyncId(dto.getAsyncId());
|
||||
statusMQDto.setCode("data");
|
||||
rabbitMQUtil.sendToExchange("hldy.eldertag", "eldertag.async.result", statusMQDto);
|
||||
//这里就不会再执行文件的逻辑 要把文件按同步失败处理
|
||||
StatusMQDto statusMQDtoFile = new StatusMQDto();
|
||||
statusMQDtoFile.setStatus(MQStatus.PROCESS_FAILED.getCode());
|
||||
statusMQDtoFile.setMessage("文件同步失败,不再处理资源");
|
||||
statusMQDtoFile.setAsyncId(dto.getAsyncId());
|
||||
statusMQDtoFile.setCode("file");
|
||||
rabbitMQUtil.sendToExchange("hldy.eldertag", "eldertag.async.result", statusMQDtoFile);
|
||||
throw new RuntimeException("数据同步失败");
|
||||
}
|
||||
//在这里返回数据成功和日志
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
statusMQDto.setStatus(MQStatus.SUCCESS.getCode());
|
||||
statusMQDto.setMessage("数据同步成功!");
|
||||
statusMQDto.setAsyncId(dto.getAsyncId());
|
||||
statusMQDto.setCode("data");
|
||||
rabbitMQUtil.sendToExchange("hldy.eldertag", "eldertag.async.result", statusMQDto);
|
||||
//资源日志在handleCreateMedia中有处理
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取标签资源
|
||||
*
|
||||
* @param mqDto
|
||||
*/
|
||||
@RabbitListener(bindings = @QueueBinding(value = @Queue(name = "#{elderTagAsyncDQNP.getCreateMediaQueueName()}"), exchange = @Exchange(name = "hldy.eldertag", type = ExchangeTypes.DIRECT), key = "#{elderTagAsyncDQNP.getCreateMediaKeyName()}"), errorHandler = "elderTagMQErrorHandler")
|
||||
public void handleCreateMedia(ElderTagMQDto mqDto) {
|
||||
try {
|
||||
mqDto.getElderTagList().stream().forEach(dto -> {
|
||||
//查询现有长者标签
|
||||
QueryWrapper<ElderTag> qw = new QueryWrapper<>();
|
||||
qw.eq("id", dto.getId());
|
||||
ElderTag currentElderTag = elderTagService.getOne(qw);
|
||||
|
||||
//更新长者标签媒体资源字段
|
||||
ElderTag et = new ElderTag();
|
||||
et.setId(dto.getId());
|
||||
|
||||
//拉取媒体资源至本地目录
|
||||
{
|
||||
//接口协议域名+上下文访问路径
|
||||
String baseUrl = dto.getApi();
|
||||
|
||||
//处理长者标签图片
|
||||
if (StringUtils.isNotBlank(dto.getPicMd5()) && !dto.getPicMd5().equals(currentElderTag.getPicMd5())) {
|
||||
String pic = dto.getPic();
|
||||
if (StringUtils.isNotBlank(pic)) {
|
||||
String url = baseUrl + "/sys/common/open/static/" + URLEncoder.encode(pic, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey();
|
||||
if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) {
|
||||
upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1);
|
||||
}
|
||||
String filePath = pic.substring(0, pic.lastIndexOf("/"));
|
||||
String fileName = pic.substring(pic.lastIndexOf("/") + 1);
|
||||
if (filePath.startsWith("/") || filePath.startsWith("\\")) {
|
||||
filePath = filePath.substring(1);
|
||||
}
|
||||
try {
|
||||
FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName);
|
||||
et.setPic(dto.getPic());//长者标签图片
|
||||
et.setPicMd5(dto.getPicMd5());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog();
|
||||
mediaAsyncErrorLog.setMediaid(pic);
|
||||
mediaAsyncErrorLog.setMsg(e.getMessage());
|
||||
mediaAsyncErrorLogService.save(mediaAsyncErrorLog);
|
||||
throw new RuntimeException("长者标签图片文件拉取错误,标签id" + currentElderTag.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
elderTagService.updateById(et);
|
||||
}
|
||||
});
|
||||
//在这里返回数据成功和日志
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
statusMQDto.setStatus(MQStatus.SUCCESS.getCode());
|
||||
statusMQDto.setMessage("文件同步成功!");
|
||||
statusMQDto.setAsyncId(mqDto.getAsyncId());
|
||||
statusMQDto.setCode("file");
|
||||
rabbitMQUtil.sendToExchange("hldy.eldertag", "eldertag.async.result", statusMQDto);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
//返回错误日志
|
||||
StatusMQDto statusMQDto = new StatusMQDto();
|
||||
statusMQDto.setStatus(MQStatus.PROCESS_FAILED.getCode());
|
||||
statusMQDto.setMessage(e.getMessage());
|
||||
statusMQDto.setAsyncId(mqDto.getAsyncId());
|
||||
statusMQDto.setCode("file");
|
||||
rabbitMQUtil.sendToExchange("hldy.eldertag", "eldertag.async.result", statusMQDto);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理增量同步数据
|
||||
*
|
||||
* @param dto
|
||||
* @throws Exception
|
||||
*/
|
||||
private void handleIncremental(ElderTagMQDto dto) {
|
||||
//增量:传过来的是已勾选的全部数据,需将重复部分去除
|
||||
//先查出所有标签id 然后进行去重
|
||||
List<ElderTag> tempList = elderTagService.allData();
|
||||
Set<String> existingIds = tempList.stream().map(ElderTag::getId).map(String::valueOf).collect(Collectors.toSet());
|
||||
|
||||
String idStr = dto.getIdStr();
|
||||
List<String> inputIds = Arrays.asList(idStr.split(","));
|
||||
|
||||
List<String> uniqueIds = inputIds.stream().filter(id -> !existingIds.contains(id)).collect(Collectors.toList());
|
||||
|
||||
dto.setIdList(uniqueIds);
|
||||
|
||||
handleData(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理数据
|
||||
* 每一项都会筛选 只留下需要新增的数据
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
private void handleData(ElderTagMQDto dto) {
|
||||
if (dto.getIdList() != null && !dto.getIdList().isEmpty()) {
|
||||
//长者标签
|
||||
List<ElderTag> needAddETList = Lists.newArrayList();
|
||||
//需要新增的标签id
|
||||
List<String> needAddIds = dto.getIdList();
|
||||
//传来的全部标签集合
|
||||
List<ElderTag> allData = BeanUtil.copyToList(dto.getElderTagList(), ElderTag.class);
|
||||
//获取到需要新增的标签集合
|
||||
for (ElderTag elderTag : allData) {
|
||||
if (needAddIds.contains(elderTag.getId())) {
|
||||
//这里都是新增的标签 不存储标签资源字段 在标签资源mq中会存储这个值
|
||||
elderTag.setPic(null);
|
||||
elderTag.setPicMd5(null);
|
||||
needAddETList.add(elderTag);
|
||||
}
|
||||
}
|
||||
//新增到数据库
|
||||
if (needAddETList != null && !needAddETList.isEmpty()) {
|
||||
elderTagService.insertAllDirectives(needAddETList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DS("master")
|
||||
public void handleCreateMedia2(ElderTagMQDto mqDto, String apiAddress) {
|
||||
try {
|
||||
mqDto.getElderTagList().stream().forEach(dto -> {
|
||||
//查询现有长者标签
|
||||
QueryWrapper<ElderTag> qw = new QueryWrapper<>();
|
||||
qw.eq("id", dto.getId());
|
||||
ElderTag currentElderTag = elderTagService.getOne(qw);
|
||||
|
||||
//更新长者标签媒体资源字段
|
||||
ElderTag et = new ElderTag();
|
||||
et.setId(dto.getId());
|
||||
|
||||
//拉取媒体资源至本地目录
|
||||
{
|
||||
//处理长者标签图片
|
||||
if (StringUtils.isNotBlank(dto.getPicMd5()) && !dto.getPicMd5().equals(currentElderTag.getPicMd5())) {
|
||||
String pic = dto.getPic();
|
||||
if (StringUtils.isNotBlank(pic)) {
|
||||
String url = apiAddress + "/sys/common/open/static/" + URLEncoder.encode(pic, StandardCharsets.UTF_8).replace("%2F", "/") + "?name=" + SafetyUtil.getSecureKey();
|
||||
if (upLoadPath.endsWith("/") || upLoadPath.endsWith("\\")) {
|
||||
upLoadPath = upLoadPath.substring(0, upLoadPath.length() - 1);
|
||||
}
|
||||
String filePath = pic.substring(0, pic.lastIndexOf("/"));
|
||||
String fileName = pic.substring(pic.lastIndexOf("/") + 1);
|
||||
if (filePath.startsWith("/") || filePath.startsWith("\\")) {
|
||||
filePath = filePath.substring(1);
|
||||
}
|
||||
try {
|
||||
FileDownloader.downloadFile(url, upLoadPath + File.separator + filePath, fileName);
|
||||
et.setPic(dto.getPic());//长者标签图片
|
||||
et.setPicMd5(dto.getPicMd5());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
MediaAsyncErrorLog mediaAsyncErrorLog = new MediaAsyncErrorLog();
|
||||
mediaAsyncErrorLog.setMediaid(pic);
|
||||
mediaAsyncErrorLog.setMsg(e.getMessage());
|
||||
mediaAsyncErrorLogService.save(mediaAsyncErrorLog);
|
||||
throw new RuntimeException("长者标签图片文件拉取错误,标签id" + currentElderTag.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
elderTagService.updateById(et);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理增量同步数据
|
||||
*
|
||||
* @param dto
|
||||
* @throws Exception
|
||||
*/
|
||||
@DS("master")
|
||||
public void handleIncremental2(ElderTagMQDto dto) {
|
||||
//增量:传过来的是已勾选的全部数据,需将重复部分去除
|
||||
//先查出所有标签id 然后进行去重
|
||||
List<ElderTag> tempList = elderTagService.allData();
|
||||
Set<String> existingIds = tempList.stream().map(ElderTag::getId).map(String::valueOf).collect(Collectors.toSet());
|
||||
|
||||
dto.setIzInc(true);
|
||||
dto.setIdStr(dto.getElderTagList().stream().map(d -> d.getId()).collect(Collectors.joining(",")));
|
||||
String idStr = dto.getIdStr();
|
||||
List<String> inputIds = Arrays.asList(idStr.split(","));
|
||||
|
||||
List<String> uniqueIds = inputIds.stream().filter(id -> !existingIds.contains(id)).collect(Collectors.toList());
|
||||
|
||||
dto.setIdList(uniqueIds);
|
||||
|
||||
handleData(dto);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nursing-unit-parent</artifactId>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<description>长者模块</description>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>nursing-unit-elder</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>nu-elder-api</module>
|
||||
<module>nu-elder-biz</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -29,6 +29,7 @@ import com.nu.modules.servicetype.service.IConfigServiceTypeService;
|
|||
import com.nu.modules.sysconfig.ISysConfigApi;
|
||||
import com.nu.mq.directive.listener.DirectiveMQListener;
|
||||
import com.nu.utils.HttpRequestUtil;
|
||||
import com.nu.utils.NuFileUtils;
|
||||
import com.nu.utils.RabbitMQUtil;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
@ -59,9 +60,6 @@ import java.util.stream.Collectors;
|
|||
@Service
|
||||
public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigServiceDirectiveMapper, ConfigServiceDirective> implements IConfigServiceDirectiveService {
|
||||
|
||||
@Value(value = "${jeecg.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
@Autowired
|
||||
private ISysConfigApi sysConfigApi;
|
||||
@Autowired
|
||||
|
@ -280,8 +278,6 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
*/
|
||||
@Override
|
||||
public void handleMediaFile(ConfigServiceDirective configServiceDirective) {
|
||||
//上传根路径
|
||||
String path = uploadpath;
|
||||
//需要存储的路径
|
||||
String mediaFileSavePath = configServiceDirective.getMediaFileSavePath() + configServiceDirective.getId();
|
||||
//服务指令图片
|
||||
|
@ -294,10 +290,10 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
String mp4File = configServiceDirective.getMp4File();
|
||||
|
||||
// 处理每个文件并获取更新后的路径
|
||||
Map<String, String> newPreviewFileMap = processFile(path, mediaFileSavePath, previewFile);
|
||||
Map<String, String> newImmediateFileMap = processFile(path, mediaFileSavePath, immediateFile);
|
||||
Map<String, String> newMp3FileMap = processFile(path, mediaFileSavePath, mp3File);
|
||||
Map<String, String> newMp4FileMap = processFile(path, mediaFileSavePath, mp4File);
|
||||
Map<String, String> newPreviewFileMap = NuFileUtils.processFile(mediaFileSavePath, previewFile);
|
||||
Map<String, String> newImmediateFileMap = NuFileUtils.processFile(mediaFileSavePath, immediateFile);
|
||||
Map<String, String> newMp3FileMap = NuFileUtils.processFile(mediaFileSavePath, mp3File);
|
||||
Map<String, String> newMp4FileMap = NuFileUtils.processFile(mediaFileSavePath, mp4File);
|
||||
|
||||
// 如果有变化,更新ConfigServiceDirective对象
|
||||
if (newPreviewFileMap != null) {
|
||||
|
@ -318,83 +314,6 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个文件,检查路径是否需要迁移
|
||||
*
|
||||
* @param basePath 基础路径
|
||||
* @param targetDir 目标目录
|
||||
* @param filePath 文件路径
|
||||
* @return 如果路径有变化返回新路径,否则返回null
|
||||
*/
|
||||
private Map<String, String> processFile(String basePath, String targetDir, String filePath) {
|
||||
if (StringUtils.isBlank(filePath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
// 检查文件路径是否以目标目录开头
|
||||
if (!filePath.startsWith(targetDir + "/")) {
|
||||
// 获取文件名(路径的最后一部分)
|
||||
String fileName = filePath.substring(filePath.lastIndexOf('/') + 1);
|
||||
|
||||
// 构建新的完整路径
|
||||
String newRelativePath = targetDir + "/" + fileName;
|
||||
String oldFullPath = basePath + "/" + filePath;
|
||||
String newFullPath = basePath + "/" + newRelativePath;
|
||||
|
||||
// 创建目标目录(如果不存在)
|
||||
File targetDirectory = new File(basePath + "/" + targetDir);
|
||||
if (!targetDirectory.exists()) {
|
||||
targetDirectory.mkdirs();
|
||||
}
|
||||
|
||||
// 移动文件
|
||||
File oldFile = new File(oldFullPath);
|
||||
if (oldFile.exists()) {
|
||||
// 计算原文件的MD5
|
||||
String md5 = calculateMD5(oldFile);
|
||||
|
||||
File newFile = new File(newFullPath);
|
||||
|
||||
// 如果目标文件已存在,先删除
|
||||
if (newFile.exists()) {
|
||||
newFile.delete();
|
||||
}
|
||||
|
||||
// 移动文件
|
||||
Files.move(oldFile.toPath(), newFile.toPath());
|
||||
|
||||
// 返回包含新路径和MD5的Map
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("path", newRelativePath);
|
||||
result.put("md5", md5);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 处理异常,可以根据实际需求记录日志或抛出
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String calculateMD5(File file) throws Exception {
|
||||
try (InputStream is = Files.newInputStream(file.toPath())) {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
byte[] buffer = new byte[8192];
|
||||
int read;
|
||||
while ((read = is.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, read);
|
||||
}
|
||||
byte[] md5 = md.digest();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : md5) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void auditPass(DirectiveAsyncMQDto dto) {
|
||||
|
@ -479,7 +398,7 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
if ("enabled".equals(filterIzEnabled) && !insUsing) {
|
||||
continue;
|
||||
}
|
||||
TreeNode instNode = new TreeNode(inst.getId(), "", "", inst.getId(), inst.getInstructionName(), 1, "", inst.getIzEnabled(), inst.getSort(), insUsing,true);
|
||||
TreeNode instNode = new TreeNode(inst.getId(), "", "", inst.getId(), inst.getInstructionName(), 1, "", inst.getIzEnabled(), inst.getSort(), insUsing, true);
|
||||
List<ConfigServiceCategory> catList = catMap.get(inst.getId());
|
||||
if (catList != null) {
|
||||
catList.sort(Comparator.comparingInt(ConfigServiceCategory::getSort));
|
||||
|
@ -488,7 +407,7 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
if ("enabled".equals(filterIzEnabled) && !catUsing) {
|
||||
continue;
|
||||
}
|
||||
TreeNode catNode = new TreeNode(inst.getId(), cat.getId(), "", cat.getId(), cat.getCategoryName(), 2, "", cat.getIzEnabled(), cat.getSort(), insUsing && catUsing,insUsing);
|
||||
TreeNode catNode = new TreeNode(inst.getId(), cat.getId(), "", cat.getId(), cat.getCategoryName(), 2, "", cat.getIzEnabled(), cat.getSort(), insUsing && catUsing, insUsing);
|
||||
List<ConfigServiceType> typeList = typeMap.get(cat.getId());
|
||||
if (typeList != null) {
|
||||
typeList.sort(Comparator.comparingInt(ConfigServiceType::getSort));
|
||||
|
@ -497,7 +416,7 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
if ("enabled".equals(filterIzEnabled) && !typUsing) {
|
||||
continue;
|
||||
}
|
||||
TreeNode typeNode = new TreeNode(inst.getId(), cat.getId(), tp.getId(), tp.getId(), tp.getTypeName(), 3, "", tp.getIzEnabled(), tp.getSort(), insUsing && catUsing && typUsing,insUsing && catUsing );
|
||||
TreeNode typeNode = new TreeNode(inst.getId(), cat.getId(), tp.getId(), tp.getId(), tp.getTypeName(), 3, "", tp.getIzEnabled(), tp.getSort(), insUsing && catUsing && typUsing, insUsing && catUsing);
|
||||
List<ConfigServiceDirective> dirList = directiveMap.get(tp.getId());
|
||||
if (dirList != null) {
|
||||
dirList.sort(Comparator.comparingInt(ConfigServiceDirective::getSort));
|
||||
|
@ -505,12 +424,12 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
if ("enabled".equals(filterIzEnabled) && "1".equals(dir.getIzEnabled())) {
|
||||
continue;
|
||||
}
|
||||
TreeNode dirNode = new TreeNode(inst.getId(), cat.getId(), tp.getId(), dir.getId(), dir.getDirectiveName(), 4, cycleTypeMap.get(dir.getCycleType()), dir.getIzEnabled(), dir.getSort(), insUsing && catUsing && typUsing,insUsing && catUsing && typUsing);
|
||||
TreeNode tagNode = new TreeNode(inst.getId(), cat.getId(), tp.getId(), IdUtil.simpleUUID(), "标签", 5, cycleTypeMap.get(dir.getCycleType()), dir.getIzEnabled(), dir.getSort(), insUsing && catUsing && typUsing,insUsing && catUsing && typUsing);
|
||||
tagNode.setBodyTagList(dir.getBodyTagList());
|
||||
tagNode.setEmotionTagList(dir.getEmotionTagList());
|
||||
TreeNode dirNode = new TreeNode(inst.getId(), cat.getId(), tp.getId(), dir.getId(), dir.getDirectiveName(), 4, cycleTypeMap.get(dir.getCycleType()), dir.getIzEnabled(), dir.getSort(), insUsing && catUsing && typUsing, insUsing && catUsing && typUsing);
|
||||
// TreeNode tagNode = new TreeNode(inst.getId(), cat.getId(), tp.getId(), IdUtil.simpleUUID(), "标签", 5, cycleTypeMap.get(dir.getCycleType()), dir.getIzEnabled(), dir.getSort(), insUsing && catUsing && typUsing,insUsing && catUsing && typUsing);
|
||||
// tagNode.setBodyTagList(dir.getBodyTagList());
|
||||
// tagNode.setEmotionTagList(dir.getEmotionTagList());
|
||||
typeNode.addChild(dirNode);
|
||||
dirNode.addChild(tagNode);
|
||||
// dirNode.addChild(tagNode);
|
||||
}
|
||||
}
|
||||
catNode.addChild(typeNode);
|
||||
|
@ -614,7 +533,7 @@ public class ConfigServiceDirectiveServiceImpl extends ServiceImpl<ConfigService
|
|||
{
|
||||
directiveMQDto.setEmotionTagList(BeanUtil.copyToList(emotionTagService.selectAll(directiveIds, null), EmotionTagMQDto.class));
|
||||
}
|
||||
directiveMQListener.handleIncremental2("master", directiveMQDto);
|
||||
directiveMQListener.handleIncremental2(directiveMQDto);
|
||||
|
||||
String apiAddress = "";
|
||||
//查询源数据平台的接口api地址
|
||||
|
|
|
@ -839,8 +839,8 @@ public class DirectiveMQListener {
|
|||
// }
|
||||
// }
|
||||
|
||||
@DS("ds")
|
||||
public void handleIncremental2(String ds, DirectiveMQDto dto) {
|
||||
@DS("master")
|
||||
public void handleIncremental2(DirectiveMQDto dto) {
|
||||
dto.setIzInc(true);
|
||||
dto.setIdStr(dto.getDirectiveList().stream().map(d -> d.getId()).collect(Collectors.joining(",")));
|
||||
//增量:传过来的是已勾选的全部数据,需将重复部分去除
|
||||
|
|
|
@ -54,6 +54,12 @@
|
|||
<artifactId>nu-services-biz</artifactId>
|
||||
<version>${nursingunit.version}</version>
|
||||
</dependency>
|
||||
<!-- 长者 模块 -->
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
<artifactId>nu-elder-biz</artifactId>
|
||||
<version>${nursingunit.version}</version>
|
||||
</dependency>
|
||||
<!-- 系统订单 模块 -->
|
||||
<dependency>
|
||||
<groupId>com.nursingunit.boot</groupId>
|
||||
|
|
Loading…
Reference in New Issue