xuezizhuo 1 jaar geleden
bovenliggende
commit
9b087b2d14

+ 0 - 4
ruoyi-admin/src/main/java/com/ruoyi/web/controller/dragForm/CommonController.java

@@ -89,10 +89,6 @@ public class CommonController extends BaseController {
     /**
      * 通用导出excel
      */
-//    @GetMapping("/export")
-//    public void export(HttpServletResponse response, @RequestParam("tableName") String tableName, @RequestParam("sqlKey") String sqlKey) throws Exception {
-//        commonService.export(response, tableName, sqlKey);
-//    }
     @PostMapping("/export")
     public void export(HttpServletResponse response,@RequestBody CommonEntity commonEntity) throws Exception {
         commonService.export(response, commonEntity);

+ 6 - 4
ruoyi-system/src/main/java/com/ruoyi/system/entity/CommonEntity.java

@@ -3,6 +3,7 @@ package com.ruoyi.system.entity;
 import com.ruoyi.common.core.domain.BaseEntity;
 import org.springframework.web.multipart.MultipartFile;
 
+import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 
@@ -43,13 +44,14 @@ public class CommonEntity extends BaseEntity {
     /**
      * excelMap
      */
-    private Map<String, Object> execlMap;
+    private List<Map<String, Object>> execlMap;
+
 
 
     public CommonEntity() {
     }
 
-    public CommonEntity(Map<String, Object> basicMap, Map<String, Object> queryMap, Map<String, Object> conditionMap, Map<String, Object> resultMap, Map<String, Object> commMap, Map<String, Object> execlMap) {
+    public CommonEntity(Map<String, Object> basicMap, Map<String, Object> queryMap, Map<String, Object> conditionMap, Map<String, Object> resultMap, Map<String, Object> commMap, List<Map<String, Object>> execlMap) {
         this.basicMap = basicMap;
         this.queryMap = queryMap;
         this.conditionMap = conditionMap;
@@ -110,11 +112,11 @@ public class CommonEntity extends BaseEntity {
         this.commMap = commMap;
     }
 
-    public Map<String, Object> getExeclMap() {
+    public List<Map<String, Object>> getExeclMap() {
         return execlMap;
     }
 
-    public void setExeclMap(Map<String, Object> execlMap) {
+    public void setExeclMap(List<Map<String, Object>> execlMap) {
         this.execlMap = execlMap;
     }
 }

+ 14 - 14
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/CommonServiceImpl.java

@@ -107,27 +107,27 @@ public class CommonServiceImpl implements ICommonService {
         String tableName = commonEntity.getQueryMap().get("tableName").toString();
         //查询标题信息
         TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(sqlKey);
+
         //查询列表信息
-//        List<CommonEntity> commonEntities = commonMapper.selectList(tableName, new HashMap<>());
-        List<CommonEntity> commonEntities = new ArrayList<>();
-        CommonEntity commonEntity1 = new CommonEntity();
+        List<Map<String,Object>> mapList = null;
         //根据条件获取列表信息
-        if (StringUtils.hasLength(commonEntity.getExeclMap().get("dataList").toString())) {
-            for (CommonEntity dataList : (List<CommonEntity>) commonEntity.getExeclMap().get("dataList")) {
-                System.out.println(dataList);
-                commonEntities.add(dataList);
-            }
+        if (commonEntity.getExeclMap().size()>0) {
+            mapList = commonEntity.getExeclMap();
         } else {
-            commonEntities = queryTableList(commonEntity, tableSql);
+            List<Map<String,Object>> maps = new ArrayList<>();
+            List<CommonEntity> commonEntities = queryTableList(commonEntity, tableSql);
+            commonEntities.stream().forEach(c -> maps.add(c.getResultMap()));
+            mapList = maps;
         }
-        commonEntities.add(commonEntity1);
+
         //获取列表标题和字段
         Map<String, String> map = (Map) JSONObject.parseObject(tableSql.getTableExportField());
         // 创建Excel文档
         XSSFWorkbook workbook = new XSSFWorkbook();
-        XSSFSheet sheet = workbook.createSheet("Sheet10");
-
+        XSSFSheet sheet = workbook.createSheet("Sheet1");
+        //标题
         List<String> titleList = new ArrayList<>();
+        //字段
         List<String> fieldList = new ArrayList<>();
         for (Map.Entry<String, String> entry : map.entrySet()) {
             fieldList.add(entry.getKey());
@@ -140,10 +140,10 @@ public class CommonServiceImpl implements ICommonService {
         }
         int rowIndex = 1;
         //获取列表信息
-        for (int w = 0; w < commonEntities.size(); w++) {
+        for (int w = 0; w < mapList.size(); w++) {
             XSSFRow row = sheet.createRow(rowIndex++);
             for (int e = 0; e < fieldList.size(); e++) {
-                Object val = commonEntities.get(w).getResultMap().get(toUnderScoreCase(fieldList.get(e)));
+                Object val = mapList.get(w).get(toUnderScoreCase(fieldList.get(e)));
                 row.createCell(e).setCellValue((val == null ? "" : val).toString());
             }
         }