瀏覽代碼

更新 excel 列宽, 动态添加字段

wuweihao 3 年之前
父節點
當前提交
a174737b39

+ 3 - 1
README.md

@@ -8,4 +8,6 @@
     
     对外域名:8.135.106.227:8014 ->  sit-isolation.4dage.com  香洲区隔离酒店
     doc: https://sit-isolation.4dage.com/doc.html#/home
-    web: https://sit-isolation.4dage.com/backstage/index.html#/login
+    web: https://sit-isolation.4dage.com/backstage/index.html#/login
+    
+    admin GLJD#admin 

+ 6 - 86
gis_cms/src/main/java/com/gis/cms/entity/vo/HotelExcel.java

@@ -43,102 +43,22 @@ public class HotelExcel implements Serializable {
     private Integer touchSecond;
 
 
-
-
-//    @ApiModelProperty(value = "联系人, 允许多个")
-//    private String contact;
-
-    @ApiModelProperty(value = "备注")
-    private String remark;
-
     @ApiModelProperty(value = "签约情况")
-    private Integer caseSign ;
+    private String caseSign ;
 
     @ApiModelProperty(value = "验收情况")
-    private Integer caseAccept ;
+    private String caseAccept ;
 
 
     @ApiModelProperty(value = "三区两通道搭建情况")
-    private Integer caseBuild ;
+    private String caseBuild ;
 
 
     @ApiModelProperty(value = "物资情况")
-    private Integer caseSupplies ;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c1;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c2;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c3;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c4;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c5;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c6;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c7;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c8;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c9;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c10;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c11;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c12;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c13;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c14;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c15;
-
-    @ApiModelProperty(value = "联系人-1")
-    private String c16;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+    private String caseSupplies ;
 
+    @ApiModelProperty(value = "备注")
+    private String remark;
 
 
 

+ 7 - 1
gis_cms/src/main/java/com/gis/cms/mapper/HotelMapper.java

@@ -7,6 +7,7 @@ import com.gis.cms.entity.po.HotelEntity;
 import com.gis.cms.entity.vo.HotelExcel;
 import com.gis.cms.entity.vo.HotelVo;
 import com.gis.common.base.mapper.provider.BaseProvider;
+import io.swagger.annotations.ApiModelProperty;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.SelectProvider;
@@ -28,6 +29,11 @@ public interface HotelMapper extends BaseMapper<HotelEntity> {
     @Select("select * from tb_hotel")
     List<HotelVo> apiList();
 
-    @Select("select * from tb_hotel where is_delete=0")
+
+    @Select("select id, unit, name, total, room_isolation, used, usable, touch, touch_second,remark, " +
+            "IF(case_sign=1, '是', '否') case_sign," +
+            "IF(case_accept=1, '是', '否') case_accept," +
+            "IF(case_build=1, '是', '否') case_build," +
+            "IF(case_supplies=1, '是', '否') case_supplies  from tb_hotel where is_delete=0")
     List<HotelExcel> getExcelList();
 }

+ 43 - 33
gis_cms/src/main/java/com/gis/cms/service/impl/HotelServiceImpl.java

@@ -1,6 +1,8 @@
 package com.gis.cms.service.impl;
 
 import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -30,6 +32,7 @@ import com.gis.common.util.DateUtils;
 import com.gis.common.util.ExcelUtils;
 import com.gis.common.util.Result;
 import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -297,7 +300,8 @@ public class HotelServiceImpl extends ServiceImpl<HotelMapper, HotelEntity> impl
     @Override
     public Result exportExcel(){
 //        List<HotelExcel> rows = baseMapper.getExcelList();
-        List<HotelExcel> rows = getRows();
+//        List<HotelExcel> rows = getRows();
+        List<JSONObject> rows = getRows_2();
         String filePath = "/excel/" + DateUtils.getDateTime() +  ".xlsx";
 
         //LinkedHashMap 中的数据是根据put先后顺序来的,HashMap数据时无序的
@@ -312,12 +316,11 @@ public class HotelServiceImpl extends ServiceImpl<HotelMapper, HotelEntity> impl
         rowTitle.put("usable", "房间可用");
         rowTitle.put("touch", "密接人数");
         rowTitle.put("touchSecond", "次密人数数");
-        rowTitle.put("remark", "备注");
         rowTitle.put("caseSign", "签约情况");
         rowTitle.put("caseAccept", "验收情况");
         rowTitle.put("caseBuild", "三区两通道搭建情况");
         rowTitle.put("caseSupplies", "物资情况");
-
+        rowTitle.put("remark", "备注");
 
         rowTitle.putAll(getContactTypeTitle());
 
@@ -342,17 +345,19 @@ public class HotelServiceImpl extends ServiceImpl<HotelMapper, HotelEntity> impl
         // 封装联系人title
         LinkedHashMap<String, String> rowTitle = new LinkedHashMap<>();
         for (ContactTypeVo vo : contactTypes) {
-                rowTitle.put("c"+vo.getId(), vo.getName());
+                rowTitle.put(vo.getId().toString(), vo.getName());
         }
         return rowTitle;
     }
 
 
+
+
     /**
      * 获取酒店行
      * @return
      */
-    private List<HotelExcel> getRows(){
+    private List<JSONObject> getRows_2(){
 
         // 获取酒店
         List<HotelExcel> rows = baseMapper.getExcelList();
@@ -375,15 +380,15 @@ public class HotelServiceImpl extends ServiceImpl<HotelMapper, HotelEntity> impl
                 // 封装统一联系类型 的 联系人信息
                 StringBuilder builder = new StringBuilder();
                 for (ContactEntity entity : contactList) {
-                     if (StrUtil.isNotBlank(entity.getName())){
-                         builder.append(entity.getName());
-                     }
-                     if (StrUtil.isNotBlank(entity.getPhone())){
-                         if (StrUtil.isNotBlank(builder)){
-                             builder.append(",");
-                         }
-                         builder.append(entity.getPhone()).append(";\r\n");
-                     }
+                    if (StrUtil.isNotBlank(entity.getName())){
+                        builder.append(entity.getName());
+                    }
+                    if (StrUtil.isNotBlank(entity.getPhone())){
+                        if (StrUtil.isNotBlank(builder)){
+                            builder.append(",");
+                        }
+                        builder.append(entity.getPhone()).append(";\r\n ");
+                    }
                 }
 
                 // 合并后的联系人信息
@@ -394,41 +399,46 @@ public class HotelServiceImpl extends ServiceImpl<HotelMapper, HotelEntity> impl
 
 
         // 将联系人信息添加到酒店详情
-        List<HotelExcel> newRows = new ArrayList<>();
+        List<JSONObject> newRows = new ArrayList<>();
         for (HotelExcel row : rows) {
+            // 转json
+//            row.setCaseAccept();
+//            row.setCaseBuild();
+//            row.setCaseSign();
+//            row.setCaseSupplies();
+            JSONObject rowJson = (JSONObject)JSONObject.toJSON(row);
 
             for (Map.Entry<Long, Map<String, String>> entry : resMap.entrySet()) {
                 if (row.getId().equals(entry.getKey())){
                     // 类型人类型
                     Map<String, String> value = entry.getValue();
-                    row.setC1(value.get("1"));
-                    row.setC2(value.get("2"));
-                    row.setC3(value.get("3"));
-                    row.setC4(value.get("4"));
-                    row.setC5(value.get("5"));
-                    row.setC6(value.get("6"));
-                    row.setC7(value.get("7"));
-                    row.setC8(value.get("8"));
-                    row.setC9(value.get("9"));
-                    row.setC10(value.get("10"));
-                    row.setC11(value.get("11"));
-                    row.setC12(value.get("12"));
-                    row.setC13(value.get("13"));
-                    row.setC14(value.get("14"));
-                    row.setC15(value.get("15"));
-                    row.setC16(value.get("16"));
+                    // 添加字段
+                    for (Map.Entry<String, String> typeKey : value.entrySet()) {
+                        rowJson.put(typeKey.getKey(), typeKey.getValue());
+                    }
                 }
             }
-            newRows.add(row);
+            newRows.add(rowJson);
         }
 
 
 
 
-    return newRows;
+        return newRows;
+
+
+
+    }
+
 
+    @Test
+    public void test(){
+        HotelExcel excel = new HotelExcel();
+        excel.setName("小明");
 
+        JSONObject jsonObject = (JSONObject)JSONObject.toJSON(excel);
 
+        System.out.println(jsonObject);
     }
 
 

+ 9 - 6
gis_common/src/main/java/com/gis/common/util/ExcelUtils.java

@@ -1,5 +1,6 @@
 package com.gis.common.util;
 
+import cn.hutool.core.util.NumberUtil;
 import cn.hutool.poi.excel.ExcelUtil;
 import cn.hutool.poi.excel.ExcelWriter;
 import lombok.extern.slf4j.Slf4j;
@@ -26,25 +27,27 @@ public class ExcelUtils {
         ExcelWriter writer = ExcelUtil.getWriter(savePath);
 
         //自定义标题别名
-//        int i = 0;
+        int i = 0;
         if (rowTitle != null) {
             for (Map.Entry<String, String> a : rowTitle.entrySet()) {
                 writer.addHeaderAlias(a.getKey(), a.getValue());
-                // 列宽
-                // writer.setColumnWidth(i, 100);
-//                writer.setRowHeight(i, 100);
+                // 列宽-特殊处理
+                if ("name".equals(a.getKey()) || "remark".equals(a.getKey()) || NumberUtil.isNumber(a.getKey())){
+                    writer.setColumnWidth(i, 20);
+                }
 
-//                i ++;
+                i ++;
 
             }
         }
 
         // 一次性写出内容,使用默认样式,强制输出标题
         writer.write(rows, true);
-//        writer.setRowHeight(36, 100);
         // 关闭writer,释放内存
         writer.close();
         log.info("excel完成:" +  savePath);
 
     }
+
+
 }

+ 3 - 0
pom.xml

@@ -234,6 +234,9 @@
         <version>${mybatis-plus.version}</version>
       </dependency>
 
+
+
+
     </dependencies>
   </dependencyManagement>
 </project>