generated from dxfeng/secondev-wugang-dxfeng
入职管理-附件批量上传重命名
This commit is contained in:
parent
2e89689b26
commit
c54d35851e
|
|
@ -1,4 +1,4 @@
|
|||
package com.weaver.seconddev.portal.action.entry;
|
||||
package com.weaver.seconddev.entry.action;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
|
@ -6,16 +6,15 @@ 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.file.ud.api.FileDownloadService;
|
||||
import com.weaver.seconddev.entry.mapper.FormatEntryFilesMapper;
|
||||
import com.weaver.seconddev.portal.entity.param.BaseParam;
|
||||
import com.weaver.seconddev.portal.mapper.action.entry.FormatEntryFilesMapper;
|
||||
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.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
|
@ -36,8 +35,6 @@ public class FormatEntryFilesAction implements EsbServerlessRpcRemoteInterface {
|
|||
|
||||
@Autowired
|
||||
FileClientService fileClientService;
|
||||
@Autowired
|
||||
FileDownloadService fileDownloadService;
|
||||
|
||||
@Override
|
||||
public WeaResult<Map<String, Object>> execute(Map<String, Object> params) {
|
||||
|
|
@ -109,12 +106,15 @@ public class FormatEntryFilesAction implements EsbServerlessRpcRemoteInterface {
|
|||
continue;
|
||||
}
|
||||
Date uploadTime = fileObj.getUploadTime();
|
||||
LocalDate localDate = DateUtil.toLocalDate(uploadTime);
|
||||
LocalDateTime localDate = DateUtil.toLocalDateTime(uploadTime);
|
||||
if (null == localDate) {
|
||||
localDate = DateUtil.toLocalDate(new Date());
|
||||
localDate = DateUtil.toLocalDateTime(new Date());
|
||||
}
|
||||
String formatDate = DateUtil.formatDate(localDate, DateTimeFormatter.ofPattern("yyyyMMddHHmm"));
|
||||
String newFileName = prefix + "-" + fileName + "-" + formatDate;
|
||||
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);
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.weaver.seconddev.entry.controller;
|
||||
|
||||
import com.weaver.common.authority.annotation.WeaPermission;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.seconddev.entry.service.EntryManageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/07/31
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/secondev/entry/manage")
|
||||
@WeaPermission(publicPermission = true)
|
||||
public class EntryManageController {
|
||||
|
||||
@Autowired
|
||||
EntryManageService entryManageService;
|
||||
@GetMapping("/checkJobNum")
|
||||
public WeaResult<Map<String, Object>> checkJobNum(@RequestParam("jobNum") String jobNum) {
|
||||
return entryManageService.checkJobNum(jobNum);
|
||||
}
|
||||
|
||||
@PostMapping("/uploadFiles")
|
||||
private WeaResult<Map<String, Object>> uploadFiles(@RequestBody Map<String, String> params) {
|
||||
return entryManageService.uploadFiles(params);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
package com.weaver.seconddev.entry.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/07/31
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Data
|
||||
public class FileUploadLoad {
|
||||
|
||||
public FileUploadLoad(String fileName, String formatDate, Long fileId) {
|
||||
this.fileId = fileId;
|
||||
this.formatDate = formatDate;
|
||||
|
||||
// 获取文件后缀
|
||||
String suffix = "";
|
||||
String fileNameWithoutSuffix = fileName;
|
||||
if (fileName.contains(".")) {
|
||||
int lastDotIndex = fileName.lastIndexOf(".");
|
||||
suffix = fileName.substring(lastDotIndex);
|
||||
fileNameWithoutSuffix = fileName.substring(0, lastDotIndex);
|
||||
}
|
||||
|
||||
// 按"-"分割文件名
|
||||
String[] split = fileNameWithoutSuffix.split("-");
|
||||
|
||||
// 判断是否包含时间字符串(最后一个部分是否为时间格式)
|
||||
boolean hasDateFormat = false;
|
||||
if (split.length > 0) {
|
||||
String lastPart = split[split.length - 1];
|
||||
// 简单判断是否为时间格式(12位数字)
|
||||
if (lastPart.matches("\\d{12}")) {
|
||||
hasDateFormat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasDateFormat && split.length >= 3) {
|
||||
// 包含时间格式,直接使用
|
||||
this.jobNum = split[0];
|
||||
this.userName = split[1];
|
||||
// 重新组合文件类型部分(处理可能包含"-"的文件类型名称)
|
||||
StringBuilder fileTypeBuilder = new StringBuilder();
|
||||
for (int i = 2; i < split.length - 1; i++) {
|
||||
if (fileTypeBuilder.length() > 0) {
|
||||
fileTypeBuilder.append("-");
|
||||
}
|
||||
fileTypeBuilder.append(split[i]);
|
||||
}
|
||||
this.fileTypeName = fileTypeBuilder.toString();
|
||||
// 文件名保持原样
|
||||
this.fileName = fileName;
|
||||
} else if (!hasDateFormat && split.length >= 3) {
|
||||
// 不包含时间格式,需要添加formatDate
|
||||
this.jobNum = split[0];
|
||||
this.userName = split[1];
|
||||
// 重新组合文件类型部分(处理可能包含"-"的文件类型名称)
|
||||
StringBuilder fileTypeBuilder = new StringBuilder();
|
||||
for (int i = 2; i < split.length; i++) {
|
||||
if (fileTypeBuilder.length() > 0) {
|
||||
fileTypeBuilder.append("-");
|
||||
}
|
||||
fileTypeBuilder.append(split[i]);
|
||||
}
|
||||
this.fileTypeName = fileTypeBuilder.toString();
|
||||
// 添加时间格式到文件名
|
||||
this.fileName = fileNameWithoutSuffix + "-" + formatDate + suffix;
|
||||
} else if (!hasDateFormat && split.length == 2) {
|
||||
// 特殊情况:只有工号和姓名,没有文件类型
|
||||
this.jobNum = split[0];
|
||||
this.userName = split[1];
|
||||
this.fileTypeName = "";
|
||||
// 添加时间格式到文件名
|
||||
this.fileName = fileNameWithoutSuffix + "-" + formatDate + suffix;
|
||||
} else {
|
||||
// 其他情况,设置默认值
|
||||
this.jobNum = split.length > 0 ? split[0] : "";
|
||||
this.userName = split.length > 1 ? split[1] : "";
|
||||
this.fileTypeName = "";
|
||||
// 添加时间格式到文件名
|
||||
this.fileName = fileNameWithoutSuffix + (split.length > 0 ? "-" + formatDate : "") + suffix;
|
||||
}
|
||||
}
|
||||
|
||||
private String fileName;
|
||||
private String formatDate;
|
||||
private String userName;
|
||||
private String jobNum;
|
||||
private String fileTypeName;
|
||||
private Long fileId;
|
||||
private String uploadTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package com.weaver.seconddev.entry.enums;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/07/31
|
||||
* @version: 1.0
|
||||
*/
|
||||
public enum FileUploadType {
|
||||
// ['身份证正面', '身份证反面', '护照', '学历证明', '半身形象照', '寸照', '银行卡', '体检报告', '健康证', '离职证明', '其他附件']
|
||||
IDENTITY_CARD_FRONT("身份证正面","sfzzpzfm"),
|
||||
IDENTITY_CARD_BACK("身份证反面","sfzfmghm"),
|
||||
PASSPORT("护照","hzzp"),
|
||||
EDUCATION_PROOF("学历证明","zgxlbyzszp"),
|
||||
FACE_IMAGE("半身形象照","xxzbs"),
|
||||
PORTRAIT("寸照","czycbdz"),
|
||||
BANK_CARD("银行卡","yxkzm"),
|
||||
PHYSICAL_EXAMINATION_REPORT("体检报告","tjbg"),
|
||||
HEALTH_CERTIFICATE("健康证","jkz"),
|
||||
RESIGNATION_PROOF("离职证明","sjdwlzzm"),
|
||||
OTHER_ATTACHMENT("其他附件","qtfj");
|
||||
|
||||
private final String name;
|
||||
private final String dbName;
|
||||
|
||||
FileUploadType(String name, String dbName) {
|
||||
this.name = name;
|
||||
this.dbName = dbName;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDbName() {
|
||||
return dbName;
|
||||
}
|
||||
|
||||
public static FileUploadType getByName(String name) {
|
||||
for (FileUploadType value : FileUploadType.values()) {
|
||||
if (value.getName().equals(name)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
package com.weaver.seconddev.entry.mapper;
|
||||
|
||||
import com.weaver.seconddev.portal.entity.param.BaseParam;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/07/31
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface EntryManageMapper {
|
||||
|
||||
/**
|
||||
* 根据工号查询员工ID
|
||||
*
|
||||
* @param param
|
||||
* @param jobNum
|
||||
* @return
|
||||
*/
|
||||
Long getEntryRecordIdByJobNum(@Param("param") BaseParam param, @Param("jobNum") String jobNum);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.weaver.seconddev.portal.mapper.action.entry;
|
||||
package com.weaver.seconddev.entry.mapper;
|
||||
|
||||
import com.weaver.seconddev.portal.entity.param.BaseParam;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.weaver.seconddev.entry.service;
|
||||
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/07/31
|
||||
* @version: 1.0
|
||||
*/
|
||||
public interface EntryManageService {
|
||||
|
||||
/**
|
||||
* 校验工号
|
||||
*
|
||||
* @param jobNum 工号
|
||||
* @return
|
||||
*/
|
||||
WeaResult<Map<String, Object>> checkJobNum(String jobNum);
|
||||
|
||||
/**
|
||||
* 上传文件
|
||||
*
|
||||
* @param fileIds 文件ID
|
||||
* @return
|
||||
*/
|
||||
WeaResult<Map<String, Object>> uploadFiles(Map<String, String> params);
|
||||
}
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
package com.weaver.seconddev.entry.service.impl;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.weaver.common.base.entity.result.WeaResult;
|
||||
import com.weaver.eteams.file.client.file.FileObj;
|
||||
import com.weaver.eteams.file.client.remote.FileClientService;
|
||||
import com.weaver.seconddev.entry.entity.FileUploadLoad;
|
||||
import com.weaver.seconddev.entry.enums.FileUploadType;
|
||||
import com.weaver.seconddev.entry.mapper.EntryManageMapper;
|
||||
import com.weaver.seconddev.entry.service.EntryManageService;
|
||||
import com.weaver.seconddev.portal.constant.ApplicationConfigConstant;
|
||||
import com.weaver.seconddev.portal.entity.param.BaseParam;
|
||||
import com.weaver.seconddev.portal.mapper.portal.EbuilderBaseMapper;
|
||||
import com.weaver.seconddev.portal.util.DateUtil;
|
||||
import com.weaver.seconddev.portal.util.PapiUtil;
|
||||
import com.weaver.teams.security.context.UserContext;
|
||||
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.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author:dxfeng
|
||||
* @createTime: 2025/07/31
|
||||
* @version: 1.0
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class EntryManageServiceImpl implements EntryManageService {
|
||||
|
||||
@Autowired
|
||||
EntryManageMapper entryManageMapper;
|
||||
|
||||
@Autowired
|
||||
FileClientService fileClientService;
|
||||
|
||||
@Autowired
|
||||
EbuilderBaseMapper ebuilderBaseMapper;
|
||||
|
||||
BaseParam baseParam = new BaseParam();
|
||||
|
||||
@Override
|
||||
public WeaResult<Map<String, Object>> checkJobNum(String jobNum) {
|
||||
Map<String, Object> dataMap = new HashMap<>();
|
||||
dataMap.put("isExist", false);
|
||||
if (StringUtils.isBlank(jobNum)) {
|
||||
return WeaResult.fail("工号获取异常", true);
|
||||
}
|
||||
|
||||
Long empIdByJobNum = entryManageMapper.getEntryRecordIdByJobNum(baseParam, jobNum);
|
||||
dataMap.put("isExist", null != empIdByJobNum);
|
||||
dataMap.put("empId", empIdByJobNum);
|
||||
return WeaResult.success(dataMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WeaResult<Map<String, Object>> uploadFiles(Map<String, String> params) {
|
||||
String fileIds = params.get("fileIds");
|
||||
if (StringUtils.isBlank(fileIds)) {
|
||||
return WeaResult.fail("请选择文件后上传", true);
|
||||
}
|
||||
String[] fieldArray = fileIds.split(",");
|
||||
List<FileUploadLoad> fileUploadLoadList = new ArrayList<>();
|
||||
for (String fieldStr : fieldArray) {
|
||||
Long field = Convert.toLong(fieldStr);
|
||||
FileObj fileObj = fileClientService.get(field);
|
||||
if (null == fileObj) {
|
||||
log.error("文件不存在,field={}", field);
|
||||
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"));
|
||||
|
||||
FileUploadLoad fileUploadLoad = new FileUploadLoad(fileObj.getName(), formatDate,field);
|
||||
fileObj.setName(fileUploadLoad.getFileName());
|
||||
fileClientService.update(fileObj);
|
||||
log.error("fileUploadLoad==={}", fileUploadLoad);
|
||||
fileUploadLoadList.add(fileUploadLoad);
|
||||
}
|
||||
|
||||
log.error("fileUploadLoadList==={}", fileUploadLoadList);
|
||||
Map<String, List<FileUploadLoad>> fileUploadMap = fileUploadLoadList.stream().collect(Collectors.groupingBy(FileUploadLoad::getJobNum));
|
||||
|
||||
|
||||
JSONArray datas = new JSONArray();
|
||||
for (Map.Entry<String, List<FileUploadLoad>> entry : fileUploadMap.entrySet()) {
|
||||
String jobNum = entry.getKey();
|
||||
// 入职记录ID
|
||||
Long entryRecordId = entryManageMapper.getEntryRecordIdByJobNum(baseParam, jobNum);
|
||||
if (null == entryRecordId) {
|
||||
continue;
|
||||
}
|
||||
List<FileUploadLoad> personFileUploadLoadList = entry.getValue();
|
||||
|
||||
// 根据文件类型分组,并将同一类别的附件ID用逗号分隔
|
||||
Map<String, String> fileTypeMap = personFileUploadLoadList.stream().collect(Collectors.groupingBy(FileUploadLoad::getFileTypeName, Collectors.mapping(item -> item.getFileId().toString(), Collectors.joining(","))));
|
||||
// 组合更新的JOSN对象
|
||||
JSONObject mainDataObj = new JSONObject();
|
||||
mainDataObj.put("id", entryRecordId);
|
||||
fileTypeMap.forEach((fileTypeName, ids) -> {
|
||||
FileUploadType byName = FileUploadType.getByName(fileTypeName);
|
||||
if (null != byName) {
|
||||
// 构建更新数据
|
||||
mainDataObj.put(byName.getDbName(), ids);
|
||||
}
|
||||
});
|
||||
JSONObject dataObj = new JSONObject();
|
||||
dataObj.put("mainTable", mainDataObj);
|
||||
log.error("dataObj===" + dataObj);
|
||||
datas.add(dataObj);
|
||||
}
|
||||
|
||||
Long objId = ebuilderBaseMapper.getObjIdByTableName(baseParam, "uf_jcl_rzgl");
|
||||
Long userId = UserContext.getCurrentUser().getEmployeeId();
|
||||
|
||||
String updateMsg = updateEbTable(datas, String.valueOf(objId), String.valueOf(userId));
|
||||
log.error("updateMsg===" + updateMsg);
|
||||
Map<String, Object> actionMap = new HashMap<>();
|
||||
actionMap.put("updateMsg", updateMsg);
|
||||
return WeaResult.success(actionMap);
|
||||
}
|
||||
|
||||
private String updateEbTable(JSONArray datas, String objId, String userId) {
|
||||
JSONObject dataJson = new JSONObject();
|
||||
JSONObject operationinfo = new JSONObject();
|
||||
operationinfo.put("fieldNoFindIgnore", "true");
|
||||
operationinfo.put("doAction", "false");
|
||||
JSONObject header = new JSONObject();
|
||||
header.put("objId", objId);
|
||||
|
||||
dataJson.put("datas", datas);
|
||||
dataJson.put("header", header);
|
||||
dataJson.put("operationinfo", operationinfo);
|
||||
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("datajson", dataJson);
|
||||
jsonObject.put("userid", userId);
|
||||
// 请求授权
|
||||
String papiCode = PapiUtil.getPapiCode(ApplicationConfigConstant.APP_URL, ApplicationConfigConstant.CORP_ID, "A1a");
|
||||
String papiToken = PapiUtil.getPapiToken(ApplicationConfigConstant.APP_URL, ApplicationConfigConstant.ORGANIZATION_APP_KEY, ApplicationConfigConstant.ORGANIZATION_APP_SECRET, papiCode);
|
||||
jsonObject.put("access_token", papiToken);
|
||||
|
||||
log.error("jsonObject===" + jsonObject);
|
||||
|
||||
return HttpRequest.post(ApplicationConfigConstant.APP_URL + "/papi/openapi/api/ebuilder/form/dataset/v2/updateFormData")
|
||||
.header("Content-Type", "application/json")
|
||||
.body(jsonObject.toJSONString())
|
||||
.execute()
|
||||
.body();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ package com.weaver.seconddev.portal.util;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.time.temporal.TemporalAdjusters;
|
||||
|
|
@ -219,6 +220,24 @@ public class DateUtil {
|
|||
return date.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
||||
}
|
||||
|
||||
public static LocalDateTime toLocalDateTime(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 格式化LocalDateTime为指定格式的字符串
|
||||
*/
|
||||
public static String formatDateTime(LocalDateTime dateTime, DateTimeFormatter formatter) {
|
||||
if (dateTime == null || formatter == null) {
|
||||
return null;
|
||||
}
|
||||
return dateTime.format(formatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将LocalDate转换为java.util.Date
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
<?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.entry.mapper.EntryManageMapper">
|
||||
|
||||
<select id="getEntryRecordIdByJobNum" resultType="java.lang.Long">
|
||||
select t1.id from ${param.e10_common}.uf_jcl_rzgl t1
|
||||
where t1.tenant_key = #{param.tenantKey} and t1.delete_type = 0
|
||||
and t1.job_num = #{jobNum}
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue