Parcourir la source

excel模板导出和数据导出列宽

大数据与最优化研究所 il y a 2 jours
Parent
commit
18dfb8dda1

+ 14 - 3
src/main/java/com/xjrsoft/module/form/controller/FormExecuteController.java

@@ -260,7 +260,7 @@ public class FormExecuteController {
         // 设置第每列的列宽度
         for (ImportConfig importConfig : importConfigs) {
             if(importConfig.getWidth() == 0){
-                sheet.setColumnWidth(importConfig.getSortCode(), importConfig.getLabel().length() * 4 * 256);
+                sheet.setColumnWidth(importConfig.getSortCode(), importConfig.getLabel().length() * 3 * 256);
 //                sheet.autoSizeColumn(importConfig.getSortCode());
             }else {
                 sheet.setColumnWidth(importConfig.getSortCode(), importConfig.getWidth() * 256);
@@ -314,6 +314,18 @@ public class FormExecuteController {
                         value = LocalDateTimeUtil.format(time);
                     }
 
+                    // 检查类层次结构
+
+                    if (value instanceof Integer) {
+                        value = Integer.toString((Integer) value);
+                    }
+                    if (value instanceof Double) {
+                        value = Double.toString((Double) value);
+                    }
+                    if (value instanceof Long) {
+                        value = Long.toString((Long) value);
+                    }
+
                     Cell cell = dataRow.createCell(i);
                     cell.setCellValue((String)value);
                     cell.setCellStyle(cellStyle);
@@ -463,16 +475,15 @@ public class FormExecuteController {
             }
         }
 
-
         FormRelease formRelease = formReleaseService.getById(releaseId);
         FormReleaseConfig formReleaseConfig = JSONUtil.toBean(formRelease.getConfigJson(), FormReleaseConfig.class);
         // 配置excel第一行字段名
         List<List<String>> head = new ArrayList<>();
 //        List<ColumnConfig> columnConfigs = formReleaseConfig.getListConfig().getColumnConfigs();
-        List<ImportConfig> importConfigs = formReleaseConfig.getListConfig().getImportConfigs();
 //        for (ColumnConfig config : columnConfigs) {
 //            head.add(Collections.singletonList(config.getLabel()));
 //        }
+        List<ImportConfig> importConfigs = formReleaseConfig.getListConfig().getImportConfigs();
         for (ImportConfig config : importConfigs) {
             head.add(Collections.singletonList(config.getLabel()));
         }

+ 2 - 0
src/main/java/com/xjrsoft/module/form/dto/UpdateFormReleaseDto.java

@@ -3,6 +3,7 @@ package com.xjrsoft.module.form.dto;
 import com.xjrsoft.module.form.entity.MenuConfig;
 import com.xjrsoft.module.generator.entity.ListConfig;
 import lombok.Data;
+import lombok.EqualsAndHashCode;
 
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
@@ -12,6 +13,7 @@ import javax.validation.constraints.NotNull;
  * @Date: 2022/5/11 11:23
  */
 @Data
+@EqualsAndHashCode(callSuper = false)
 public class UpdateFormReleaseDto {
 
     @NotNull(message = "发布id不能为空")

+ 21 - 9
src/main/java/com/xjrsoft/module/form/service/impl/FormExecuteServiceImpl.java

@@ -503,18 +503,27 @@ public class FormExecuteServiceImpl implements IFormExecuteService {
             // 根据表单配置获取字典数据
             Map<String, Map<String, Object>> formDicData = FormDataTransUtil.formConfigGetDicData(formDesignConfig);
 
+            int row = 1;
             for (Map<String, Object> data : dataList) {
                 Entity where = Entity.create(tableName);
                 // 处理字段值
-                Map<String, Object> toSaveFormData = handleFormDataForSave(data, formDesignConfig, tableName, new ArrayList<>(), formDicData);
-
-                //formData 默认插入雪花Id主键
-                pk.ifPresent(column -> toSaveFormData.put(column.getName(), IdUtil.getSnowflakeNextId()));
-                where.putAll(toSaveFormData);
-                //如果有审计字段  默认填充值
-                putAuditEntityInsertData(where, columns);
-
-                toSaveList.add(where);
+                try {
+                    Map<String, Object> toSaveFormData = handleFormDataForSave(data, formDesignConfig, tableName, new ArrayList<>(), formDicData);
+                    //formData 默认插入雪花Id主键
+                    pk.ifPresent(column -> toSaveFormData.put(column.getName(), IdUtil.getSnowflakeNextId()));
+                    where.putAll(toSaveFormData);
+                    //如果有审计字段  默认填充值
+                    putAuditEntityInsertData(where, columns);
+
+                    toSaveList.add(where);
+                }catch (MyException e){
+                    String msg = e.getMsg();
+                    if(msg.toLowerCase().contains("字典值不匹配-".toLowerCase())){
+                        String value = msg.substring(msg.indexOf('-') + 1);
+                        throw new MyException("第" + row + "行的" + value + "值不属于可使用的值!");
+                    }
+                }
+                row++;
             }
             try {
                 Boolean result = SqlRunnerAdapter.db().dynamicInsertBatch(tableName, toSaveList);
@@ -2366,6 +2375,9 @@ public class FormExecuteServiceImpl implements IFormExecuteService {
                     List<Object> mapKey = FormDataTransUtil.getMapKey(dicData, formData.get(bindField));
                     if (!mapKey.isEmpty()) {
                         resultData.put(bindField, mapKey.stream().findFirst().get());
+                    }else{
+                        String label = config.getLabel();
+                        throw new MyException("字典值不匹配-" + label);
                     }
                 }
             }

+ 0 - 10
src/main/java/com/xjrsoft/module/generator/entity/ImportConfig.java

@@ -1,25 +1,17 @@
 package com.xjrsoft.module.generator.entity;
 
-import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
-import org.hibernate.validator.constraints.Length;
-
-import javax.validation.constraints.NotNull;
 
 @Data
 public class ImportConfig {
     /**
      * 字段
      */
-    @NotNull(message = "字段不能为空!")
-    @Length(max = 30, message = "字段长度不能超过30!")
     private String fieldName;
 
     /**
      * 字段名称
      */
-    @NotNull(message = "字段名称不能为空!")
-    @Length(max = 20, message = "字段名称不能超过20!")
     private String label;
 
     /**
@@ -30,9 +22,7 @@ public class ImportConfig {
     /**
      * 是否必填
      */
-    @ApiModelProperty("是否必填")
     private Boolean required;
 
-    @ApiModelProperty("排序码")
     private Integer sortCode;
 }