补正文件上传

This commit is contained in:
dxfeng 2025-04-10 12:04:53 +08:00
parent da8970a861
commit b68ab60bf2
1 changed files with 161 additions and 6 deletions

View File

@ -13,7 +13,6 @@ import com.engine.secret.service.UnpackZipService;
import com.engine.secret.util.ConfigUtil;
import com.engine.secret.util.FieldConvertUtil;
import com.engine.secret.util.ModeUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.weaver.formmodel.data.model.Formfield;
@ -39,6 +38,8 @@ import java.util.stream.Collectors;
*/
public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipService {
private static final String SOURCE_TYPE = "0";
int uploadCatalogue;
BaseBean baseBean = new BaseBean();
@ -58,8 +59,10 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
try {
this.imageFileMap = imageFileMap;
this.relatedFlowId = requestId;
// 构建流程表单反填字段
buildFormFields(rootNode);
offline(rootNode);
// 插入建模表单数据写入文件数据
insertDataAndFiles(rootNode);
} catch (Exception e) {
baseBean.writeLog(e);
throw new RuntimeException(e);
@ -73,20 +76,172 @@ public class OfflineZipUnpackServiceImpl extends Service implements UnpackZipSer
return returnMap;
}
/**
* 离线解析方式
* 更新补正文件数据
*
* @param rootNode
* @throws JsonProcessingException
* @throws Exception
*/
private void offline(JsonNode rootNode) throws Exception {
private void updateCorrectedMaterials(JsonNode rootNode) throws Exception {
String uploadCatalogueStr = ConfigUtil.getConfig("UPLOAD_CATALOGUE");
if (StringUtils.isBlank(uploadCatalogueStr)) {
throw new CustomizeRunTimeException("未获取到解析文件目录设置,检查配置[uf_config]");
}
uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1);
baseBean.writeLog("uploadCatalogue==" + uploadCatalogue);
List<DataConfig> dataConfigList = getDataConfig("0");
List<DataConfig> dataConfigList = getDataConfig(SOURCE_TYPE);
baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList));
// 处理文件数据
List<ApplicationResource> applicationResourceList = getApplicationResourceList(rootNode);
// key是fid 集合是该同一个fid下的文件ID信息
applicationResourceMap = applicationResourceList.stream().collect(Collectors.groupingBy(ApplicationResource::getFid));
baseBean.writeLog("applicationResourceMap==" + JSON.toJSONString(applicationResourceMap));
List<ResourceInfo> resourceInfoList = getResourceInfoList(rootNode);
// key是fid 集合是该同一个fid下的文件ID信息
resourceInfoMap = resourceInfoList.stream().collect(Collectors.groupingBy(ResourceInfo::getVirtualPath, Collectors.toMap(ResourceInfo::getId, item -> item)));
baseBean.writeLog("resourceInfoMap==" + JSON.toJSONString(resourceInfoMap));
if (CollectionUtils.isNotEmpty(dataConfigList)) {
RecordSet rs = new RecordSet();
// 遍历配置读取配置文件并插入数据
for (DataConfig dataConfig : dataConfigList) {
String mainTableName = dataConfig.getMainTableName();
String relatedField = dataConfig.getRelatedField();
String rootPath = dataConfig.getRootPath();
baseBean.writeLog("rootPath==" + rootPath);
// 字段对照关系
List<DataConfigDetail> fieldDetailList = dataConfig.getDetailList();
// 获取明细表相关信息
List<DataConfig> childDataConfigList = dataConfig.getChildDataConfig();
List<FileConfig> fileList = dataConfig.getFileList();
List<Formfield> formFieldList = ModeUtil.getFieldList(mainTableName);
Map<String, Formfield> mainTableFieldMap = formFieldList.stream().filter(item -> item.getViewtype() == 0).collect(Collectors.toMap(Formfield::getFieldname, item -> item, (k1, k2) -> k1));
if (CollectionUtils.isNotEmpty(fieldDetailList)) {
// 根据RequestId获取对应建模表单的billId
String sql = "select id from " + mainTableName + " where " + relatedField + " =?";
rs.executeQuery(sql, relatedFlowId);
if (rs.next()) {
int billId = rs.getInt("id");
if (billId < 0) {
continue;
}
dealFileList(billId, fileList, mainTableName, false);
}
}
}
}
}
/**
* 处理文件数据
*
* @param mainId
* @param fileConfigList
* @param tableName
* @param isDetail
* @throws Exception
*/
private void updateFileList(int mainId, List<FileConfig> fileConfigList, String tableName, boolean isDetail) throws Exception {
Map<String, Object> dataMap = new IgnoreCaseHashMap<>();
Map<String, Object> defaultDataMap = new IgnoreCaseHashMap<>();
for (FileConfig fileConfig : fileConfigList) {
String fieldName = fileConfig.getFieldName();
// 是否更正文件
String isFilled = fileConfig.getIsFilled();
if (!"2".equals(isFilled)) {
// 如果类型不是更正文件跳过不做处理
continue;
}
// 文件标识ID
String fileId = fileConfig.getFileId();
String fixedValue = fileConfig.getFixedValue();
String attachments = fileConfig.getAttachments();
if (StringUtils.isNotBlank(fixedValue)) {
// 默认值直接写入表单对应的字段
defaultDataMap.put(fieldName, fixedValue);
continue;
}
// 附件清单不为空则写入对应的浏览按钮ID
if (StringUtils.isNotBlank(attachments)) {
defaultDataMap.put(fieldName, attachments);
}
List<ApplicationResource> applicationResources = applicationResourceMap.get(fileId);
if (CollectionUtils.isEmpty(applicationResources)) {
baseBean.writeLog("根据fid未获取到数据fileId==" + fileId);
continue;
}
Map<String, ResourceInfo> fileResourceMap = resourceInfoMap.get(isFilled);
if (null == fileResourceMap || fileResourceMap.size() == 0) {
baseBean.writeLog("根据文件类型未获取到数据isFilled==" + isFilled);
continue;
}
List<String> fileRidList = applicationResources.stream().map(ApplicationResource::getRid).collect(Collectors.toList());
List<Integer> docIds = new ArrayList<>();
for (String rid : fileRidList) {
ResourceInfo resourceInfo = fileResourceMap.get(rid);
if (resourceInfo == null) {
baseBean.writeLog("根据文件rid未获取到数据rid==" + rid + ",isFilled==" + isFilled);
continue;
}
String fileName = resourceInfo.getFileName();
Integer imageFileId = imageFileMap.get(fileName);
// 生成文档ID
int docId = ModeUtil.createDocId(uploadCatalogue, imageFileId, user);
docIds.add(docId);
}
dataMap.put(fieldName, StringUtils.join(docIds, ","));
}
if (dataMap.size() == 0) {
baseBean.writeLog("dataMap集合为空");
return;
}
// defaultDataMap.get()
// 合并默认值数据,如果文件集合为空,则不单独插入默认值
//dataMap.putAll(defaultDataMap);
baseBean.writeLog("文件插入集合dataMap==" + JSON.toJSONString(dataMap));
// 根据主表明细表区分数据处理方式
if (isDetail) {
dataMap.put("mainid", mainId);
ModeUtil.insertData(dataMap, tableName);
} else {
dataMap.put("id", mainId);
// 根据ID更新主表数据
ModeUtil.updateDataById(dataMap, tableName);
}
}
/**
* 插入数据和文件
*
* @param rootNode
* @throws Exception
*/
private void insertDataAndFiles(JsonNode rootNode) throws Exception {
String uploadCatalogueStr = ConfigUtil.getConfig("UPLOAD_CATALOGUE");
if (StringUtils.isBlank(uploadCatalogueStr)) {
throw new CustomizeRunTimeException("未获取到解析文件目录设置,检查配置[uf_config]");
}
uploadCatalogue = Convert.toInt(uploadCatalogueStr, -1);
baseBean.writeLog("uploadCatalogue==" + uploadCatalogue);
List<DataConfig> dataConfigList = getDataConfig(SOURCE_TYPE);
baseBean.writeLog("dataConfigList==" + JSON.toJSONString(dataConfigList));
// 处理文件数据