信息变更流程-附件名称格式化

This commit is contained in:
dxfeng 2025-08-08 10:01:40 +08:00
parent dcba5c39f3
commit eb5c93cb81
3 changed files with 157 additions and 0 deletions

View File

@ -0,0 +1,124 @@
package com.weaver.seconddev.employee.action;
import cn.hutool.core.convert.Convert;
import com.alibaba.fastjson.JSON;
import com.weaver.common.base.entity.result.WeaResult;
import com.weaver.esb.api.rpc.EsbServerlessRpcRemoteInterface;
import com.weaver.eteams.file.client.file.FileObj;
import com.weaver.eteams.file.client.remote.FileClientService;
import com.weaver.seconddev.employee.mapper.FormatChangeMapper;
import com.weaver.seconddev.portal.entity.param.BaseParam;
import com.weaver.seconddev.portal.util.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2025/08/08
* @version: 1.0
*/
@Slf4j
@Service("FormatChangeFilesAction")
public class FormatChangeFilesAction implements EsbServerlessRpcRemoteInterface {
@Autowired
FormatChangeMapper formatEntryFilesMapper;
@Autowired
FileClientService fileClientService;
@Override
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
log.error("params=>:{}", params);
Long rzjlid = Convert.toLong(params.get("rzjlid"));
log.error("rzjlid=>:{}", rzjlid);
if (null == rzjlid) {
return WeaResult.success();
}
// 查询入职管理表数据信息
BaseParam baseParam = new BaseParam();
Map<String, Object> entryRecord = formatEntryFilesMapper.getChangeRecord(baseParam, rzjlid);
if (entryRecord.isEmpty()) {
log.error("entryRecord is null,{}", params);
return WeaResult.success();
}
log.error("entryRecord=>:{}", JSON.toJSONString(entryRecord));
String username = Convert.toStr(entryRecord.get("username"));
String jobNum = Convert.toStr(entryRecord.get("job_num"));
log.error("userName=={}", username);
log.error("jobNum=={}", jobNum);
if (StringUtils.isBlank(jobNum)) {
log.error("jobNum is null,{}", params);
return WeaResult.success();
}
String prefix = username + "-" + jobNum;
renameFile(Convert.toStr(entryRecord.get("sfzzpzfm")), prefix, "身份证正面");
renameFile(Convert.toStr(entryRecord.get("sfzfmghm")), prefix, "身份证反面");
renameFile(Convert.toStr(entryRecord.get("hzzp")), prefix, "护照");
renameFile(Convert.toStr(entryRecord.get("zgxlbyzszp")), prefix, "学历证明");
renameFile(Convert.toStr(entryRecord.get("xxzbs")), prefix, "半身形象照");
renameFile(Convert.toStr(entryRecord.get("czycbdz")), prefix, "寸照");
renameFile(Convert.toStr(entryRecord.get("yxkzm")), prefix, "银行卡");
renameFile(Convert.toStr(entryRecord.get("tjbg")), prefix, "体检报告");
renameFile(Convert.toStr(entryRecord.get("jkz")), prefix, "健康证");
renameFile(Convert.toStr(entryRecord.get("sjdwlzzm")), prefix, "离职证明");
renameFile(Convert.toStr(entryRecord.get("qtfj")), prefix, "其他附件");
return WeaResult.success(params);
}
/**
* 重命名文件
*
* @param fileIds 文件ID
* @param prefix 前缀
* @param fileName 文件名
*/
private void renameFile(String fileIds, String prefix, String fileName) {
if (StringUtils.isBlank(fileIds)) {
return;
}
int index = 1;
String[] split = fileIds.split(",");
if (split.length > 0) {
for (String s : split) {
Long fileId = Convert.toLong(s);
if (null == fileId) {
log.error("fileId is null,{}", s);
continue;
}
FileObj fileObj = fileClientService.get(fileId);
if (null == fileObj) {
log.error("fileObj is null,{}", fileId);
continue;
}
Date uploadTime = fileObj.getUploadTime();
LocalDateTime localDate = DateUtil.toLocalDateTime(uploadTime);
if (null == localDate) {
localDate = DateUtil.toLocalDateTime(new Date());
}
String formatDate = DateUtil.formatDateTime(localDate, DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
int lastDotIndex = fileName.lastIndexOf(".");
String suffix = fileName.substring(lastDotIndex);
String fileNameWithoutSuffix = fileName.substring(0, lastDotIndex);
String newFileName = prefix + "-" + fileNameWithoutSuffix + "-" + formatDate + suffix;
fileObj.setName(newFileName);
fileClientService.update(fileObj);
}
}
}
}

View File

@ -0,0 +1,19 @@
package com.weaver.seconddev.employee.mapper;
import com.weaver.seconddev.portal.entity.param.BaseParam;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.Map;
/**
* @author:dxfeng
* @createTime: 2025/08/08
* @version: 1.0
*/
@Mapper
public interface FormatChangeMapper {
Map<String,Object> getChangeRecord(@Param("param") BaseParam param, @Param("id") Long id);
}

View File

@ -0,0 +1,14 @@
<?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.weaver.seconddev.employee.mapper.FormatChangeMapper">
<select id="getChangeRecord" resultType="java.util.Map">
select
t1.id,t1.username,t1.glzzyg,t1.job_num,t1.sfzzpzfm,t1.sfzfmghm,t1.xwzszp,t1.zgxlbyzszp,
t1.hzzp,t1.xxzbs,t1.sbzmwj,t1.yxkzm,t1.tjbg,t1.sjdwlzzm,t1.czycbdz,t1.jkz,t1.qtfj
from ${param.e10_common}.uf_jcl_employee_xxbgsq t1
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
and t1.id = #{id}
</select>
</mapper>