增加:下载置标标签时同时填充表单数据

master
guoxin 1 year ago
parent 26f0bbc904
commit 84cd539ff5
  1. 46
      shandan-system/src/main/java/com/keyware/shandan/system/controller/SysFileController.java

@ -1,6 +1,8 @@
package com.keyware.shandan.system.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.ZipUtil;
import com.keyware.shandan.bianmu.service.DataLabelsService;
import com.keyware.shandan.common.controller.BaseController;
@ -11,10 +13,12 @@ import com.keyware.shandan.frame.properties.CustomProperties;
import com.keyware.shandan.system.constants.FormTypeEnum;
import com.keyware.shandan.system.entity.SysFile;
import com.keyware.shandan.system.entity.SysFileChunk;
import com.keyware.shandan.system.entity.SysFormConfig;
import com.keyware.shandan.system.entity.SysSetting;
import com.keyware.shandan.system.service.SysFileService;
import com.keyware.shandan.system.service.SysFormConfigService;
import com.keyware.shandan.system.service.SysSettingService;
import com.keyware.shandan.system.utils.DictUtil;
import com.keyware.shandan.system.utils.FileChunkUploadUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
@ -26,9 +30,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.*;
/**
* <p>
@ -265,8 +267,44 @@ public class SysFileController extends BaseController<SysFileService, SysFile, S
File labelFile = FileUtil.file(file.getParentFile().getAbsolutePath() + File.separator + fileName);
labelFile.createNewFile();
Set<String> lines = new HashSet<>();
List<SysFormConfig> formConfig = formConfigService.listByFormType(FormTypeEnum.fileUploadForm);
formConfig.forEach(conf -> {
Object filedValue = ReflectUtil.getFieldValue(sysFile, conf.getFieldName());
String value = String.valueOf(filedValue);
if(filedValue != null){
switch (conf.getFieldType()) {
case "dict":
value = DictUtil.getDictName(conf.getDictType(), value);
break;
case "radio": // 0-否-;1-是-
String partner = conf.getDictType();
String[] ss = partner.split(";");
for (String s : ss) {
String p = value + "-";
if (s.startsWith(p)) {
value = s.replace(p, "").replace("-", "");
break;
}
}
break;
case "date":
Date date = (Date) filedValue;
value = date == null ? "" : DateUtil.format(date, "yyyy-MM-dd HH:mm:ss");
break;
case "input":
case "textarea":
default:
value = filedValue.toString();
}
}else{
value = "";
}
lines.add(conf.getShowTitle() + ": " + value);
});
sysFile.getLabels().forEach(label -> {
lines.add(label.getLabel());
lines.add(label.getFieldTitle() + ": " + label.getLabel());
});
FileUtil.writeLines(lines, labelFile, "UTF-8");
return labelFile;