Browse Source

导出第一部分

傅行帆 3 years ago
parent
commit
b6c04de1ac

+ 82
- 0
src/main/java/com/yunzhi/marketing/excel/searchHouse/BuyRoom.java View File

@@ -0,0 +1,82 @@
1
+package com.yunzhi.marketing.excel.searchHouse;
2
+
3
+import com.alibaba.excel.annotation.ExcelProperty;
4
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
5
+import lombok.Data;
6
+
7
+import java.time.LocalDateTime;
8
+
9
+@Data
10
+public class BuyRoom {
11
+
12
+
13
+    @ColumnWidth(15)
14
+    @ExcelProperty(value = "姓名", index = 0)
15
+    private String nickname;
16
+
17
+    @ColumnWidth(15)
18
+    @ExcelProperty(value = "电话", index = 0)
19
+    private String phone;
20
+
21
+    @ColumnWidth(15)
22
+    @ExcelProperty(value = "性别", index = 0)
23
+    private String gender;
24
+
25
+    @ColumnWidth(15)
26
+    @ExcelProperty(value = "意向区域", index = 0)
27
+    private String intentArea;
28
+
29
+
30
+    @ColumnWidth(15)
31
+    @ExcelProperty(value = "购房预算", index = 0)
32
+    private String maxPrice;
33
+
34
+
35
+    @ColumnWidth(15)
36
+    @ExcelProperty(value = "房屋类型", index = 0)
37
+    private String isNew;
38
+
39
+
40
+    @ColumnWidth(15)
41
+    @ExcelProperty(value = "意向居室", index = 0)
42
+    private String layout;
43
+
44
+
45
+    @ColumnWidth(15)
46
+    @ExcelProperty(value = "购房目的", index = 0)
47
+    private String purpose;
48
+
49
+
50
+    @ColumnWidth(15)
51
+    @ExcelProperty(value = "侧重优势", index = 0)
52
+    private String advantage;
53
+
54
+    @ColumnWidth(15)
55
+    @ExcelProperty(value = "社区要求", index = 0)
56
+    private String facility;
57
+
58
+    @ColumnWidth(15)
59
+    @ExcelProperty(value = "面积要求", index = 0)
60
+    private String area;
61
+
62
+    @ColumnWidth(15)
63
+    @ExcelProperty(value = "朝向要求", index = 0)
64
+    private String orientation;
65
+
66
+    @ColumnWidth(15)
67
+    @ExcelProperty(value = "楼层要求", index = 0)
68
+    private String isHigh;
69
+
70
+    @ColumnWidth(15)
71
+    @ExcelProperty(value = "房龄要求", index = 0)
72
+    private String buildingAge;
73
+
74
+    @ColumnWidth(15)
75
+    @ExcelProperty(value = "客户备注", index = 0)
76
+    private String remark;
77
+
78
+    @ColumnWidth(15)
79
+    @ExcelProperty(value = "提交时间", index = 0)
80
+    private LocalDateTime createdTime;
81
+
82
+}

+ 92
- 0
src/main/java/com/yunzhi/marketing/xlk/controller/SearchHouseController.java View File

@@ -1,5 +1,9 @@
1 1
 package com.yunzhi.marketing.xlk.controller;
2 2
 
3
+import com.alibaba.excel.EasyExcel;
4
+import com.alibaba.excel.ExcelWriter;
5
+import com.alibaba.excel.write.metadata.WriteSheet;
6
+import com.alibaba.fastjson.JSONArray;
3 7
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
4 8
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
5 9
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -9,12 +13,16 @@ import com.yunzhi.marketing.base.ResponseBean;
9 13
 import com.yunzhi.marketing.common.CommConstant;
10 14
 import com.yunzhi.marketing.common.StringUtils;
11 15
 import com.yunzhi.marketing.entity.*;
16
+import com.yunzhi.marketing.excel.IntentionUser;
17
+import com.yunzhi.marketing.excel.handler.CustomCellWriteHandler;
18
+import com.yunzhi.marketing.excel.searchHouse.BuyRoom;
12 19
 import com.yunzhi.marketing.service.*;
13 20
 import com.yunzhi.marketing.xlk.dto.SearchHouseDTO;
14 21
 import com.yunzhi.marketing.xlk.dto.SearchHouseReplayDTO;
15 22
 import com.yunzhi.marketing.xlk.entity.Curriculum;
16 23
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
17 24
 import com.yunzhi.marketing.xlk.service.ISearchHouseService;
25
+import com.yunzhi.marketing.xlk.vo.ExportSearchHouseVO;
18 26
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
19 27
 import io.swagger.annotations.Api;
20 28
 import io.swagger.annotations.ApiOperation;
@@ -26,7 +34,10 @@ import org.springframework.beans.factory.annotation.Autowired;
26 34
 import org.springframework.web.bind.annotation.*;
27 35
 
28 36
 import javax.servlet.http.HttpServletRequest;
37
+import javax.servlet.http.HttpServletResponse;
38
+import java.io.IOException;
29 39
 import java.time.LocalDateTime;
40
+import java.util.ArrayList;
30 41
 import java.util.HashMap;
31 42
 import java.util.List;
32 43
 import java.util.Map;
@@ -98,6 +109,87 @@ public class SearchHouseController extends BaseController {
98 109
         return responseBean;
99 110
     }
100 111
 
112
+    /**
113
+     * 导出数据列表
114
+     * @return
115
+     */
116
+    @ApiOperation(value = "admin-导出帮我找房列表", notes = "admin-导出帮我找房列表")
117
+    @RequestMapping(value="/admin/exportHouse",method= RequestMethod.GET)
118
+    public void exportHouse(@RequestParam(value ="type") Integer type,
119
+                                    @RequestParam(value ="name", required = false) String name,
120
+                                    @RequestParam(value ="phone", required = false) String phone,
121
+                                    @RequestParam(value ="status", required = false) String status,
122
+                                    @RequestHeader("authorization") String token, HttpServletRequest request, HttpServletResponse response) throws IOException {
123
+        response.setContentType("application/octet-stream");
124
+        response.setCharacterEncoding("utf-8");
125
+        response.setHeader("Content-disposition", "attachment;filename=意向客户.xlsx");
126
+        SearchHouseVO searchHouse = new SearchHouseVO();
127
+        searchHouse.setOrgId(getOrgId(request));
128
+        searchHouse.setType(type);
129
+        searchHouse.setNickname(name);
130
+        searchHouse.setPhone(phone);
131
+        searchHouse.setStatus(status);
132
+        List<ExportSearchHouseVO> result = iSearchHouseService.selectExportHouseList(searchHouse);
133
+
134
+        if (searchHouse.getType() == 4) {
135
+
136
+            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), BuyRoom.class).registerWriteHandler(new CustomCellWriteHandler()).build();
137
+            // 设置 sheet, 同一个sheet只需要设置一次
138
+            WriteSheet writeSheet = EasyExcel.writerSheet("项目详情统计").build();
139
+            List<BuyRoom> list = new ArrayList<>();
140
+            result.forEach(e -> {
141
+                BuyRoom buyRoom = new BuyRoom();
142
+                BeanUtils.copyProperties(e,buyRoom);
143
+                list.add(buyRoom);
144
+            });
145
+            excelWriter.write(list, writeSheet);
146
+            // finish 会帮忙关闭流
147
+            excelWriter.finish();
148
+        }else if (searchHouse.getType() == 1) {
149
+
150
+            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), BuyRoom.class).registerWriteHandler(new CustomCellWriteHandler()).build();
151
+            // 设置 sheet, 同一个sheet只需要设置一次
152
+            WriteSheet writeSheet = EasyExcel.writerSheet("项目详情统计").build();
153
+            List<BuyRoom> list = new ArrayList<>();
154
+            result.forEach(e -> {
155
+                BuyRoom buyRoom = new BuyRoom();
156
+                BeanUtils.copyProperties(e,buyRoom);
157
+                list.add(buyRoom);
158
+            });
159
+            excelWriter.write(list, writeSheet);
160
+            // finish 会帮忙关闭流
161
+            excelWriter.finish();
162
+        }else if (searchHouse.getType() == 3) {
163
+
164
+            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), BuyRoom.class).registerWriteHandler(new CustomCellWriteHandler()).build();
165
+            // 设置 sheet, 同一个sheet只需要设置一次
166
+            WriteSheet writeSheet = EasyExcel.writerSheet("项目详情统计").build();
167
+            List<BuyRoom> list = new ArrayList<>();
168
+            result.forEach(e -> {
169
+                BuyRoom buyRoom = new BuyRoom();
170
+                BeanUtils.copyProperties(e,buyRoom);
171
+                list.add(buyRoom);
172
+            });
173
+            excelWriter.write(list, writeSheet);
174
+            // finish 会帮忙关闭流
175
+            excelWriter.finish();
176
+        }else if (searchHouse.getType() == 3) {
177
+
178
+            ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream(), BuyRoom.class).registerWriteHandler(new CustomCellWriteHandler()).build();
179
+            // 设置 sheet, 同一个sheet只需要设置一次
180
+            WriteSheet writeSheet = EasyExcel.writerSheet("项目详情统计").build();
181
+            List<BuyRoom> list = new ArrayList<>();
182
+            result.forEach(e -> {
183
+                BuyRoom buyRoom = new BuyRoom();
184
+                BeanUtils.copyProperties(e,buyRoom);
185
+                list.add(buyRoom);
186
+            });
187
+            excelWriter.write(list, writeSheet);
188
+            // finish 会帮忙关闭流
189
+            excelWriter.finish();
190
+        }
191
+    }
192
+
101 193
     /**
102 194
      * 保存对象
103 195
      * @param searchHouseDTO 实体对象

+ 3
- 0
src/main/java/com/yunzhi/marketing/xlk/mapper/SearchHouseMapper.java View File

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.baomidou.mybatisplus.core.metadata.IPage;
5 5
 import com.yunzhi.marketing.entity.TaBuilding;
6 6
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
7
+import com.yunzhi.marketing.xlk.vo.ExportSearchHouseVO;
7 8
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
8 9
 import org.apache.ibatis.annotations.Mapper;
9 10
 import org.apache.ibatis.annotations.Param;
@@ -33,4 +34,6 @@ public interface SearchHouseMapper extends BaseMapper<SearchHouse> {
33 34
                                            @Param("minPrice") Integer minPrice,
34 35
                                            @Param("maxPrice") Integer maxPrice,
35 36
                                            @Param("limit") Integer limit);
37
+
38
+    List<ExportSearchHouseVO> selectExportHouseList(@Param("params") SearchHouseVO searchHouse);
36 39
 }

+ 8
- 0
src/main/java/com/yunzhi/marketing/xlk/service/ISearchHouseService.java View File

@@ -6,6 +6,7 @@ import com.yunzhi.marketing.base.ResponseBean;
6 6
 import com.yunzhi.marketing.entity.TaBuilding;
7 7
 import com.yunzhi.marketing.xlk.dto.SearchHouseDTO;
8 8
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
9
+import com.yunzhi.marketing.xlk.vo.ExportSearchHouseVO;
9 10
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
10 11
 
11 12
 import java.util.List;
@@ -37,4 +38,11 @@ public interface ISearchHouseService extends IService<SearchHouse> {
37 38
      * @return
38 39
      */
39 40
     List<TaBuilding> getRecommendBuildings(Integer orgId, SearchHouseDTO searchHouseDTO);
41
+
42
+    /**
43
+     * 获取导出的数据集合
44
+     * @param searchHouse
45
+     * @return
46
+     */
47
+    List<ExportSearchHouseVO> selectExportHouseList(SearchHouseVO searchHouse);
40 48
 }

+ 63
- 0
src/main/java/com/yunzhi/marketing/xlk/service/impl/SearchHouseServiceImpl.java View File

@@ -1,5 +1,8 @@
1 1
 package com.yunzhi.marketing.xlk.service.impl;
2 2
 
3
+import com.alibaba.fastjson.JSON;
4
+import com.alibaba.fastjson.JSONArray;
5
+import com.alibaba.fastjson.JSONObject;
3 6
 import com.baomidou.mybatisplus.core.metadata.IPage;
4 7
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
5 8
 import com.yunzhi.marketing.base.ResponseBean;
@@ -12,11 +15,15 @@ import com.yunzhi.marketing.xlk.dto.SearchHouseDTO;
12 15
 import com.yunzhi.marketing.xlk.entity.SearchHouse;
13 16
 import com.yunzhi.marketing.xlk.mapper.SearchHouseMapper;
14 17
 import com.yunzhi.marketing.xlk.service.ISearchHouseService;
18
+import com.yunzhi.marketing.xlk.vo.ExportSearchHouseVO;
19
+import com.yunzhi.marketing.xlk.vo.QuestionnaireVO;
15 20
 import com.yunzhi.marketing.xlk.vo.SearchHouseVO;
16 21
 import io.swagger.models.auth.In;
17 22
 import org.springframework.beans.factory.annotation.Autowired;
18 23
 import org.springframework.stereotype.Service;
19 24
 
25
+import java.lang.reflect.Field;
26
+import java.lang.reflect.Method;
20 27
 import java.util.List;
21 28
 
22 29
 /**
@@ -117,6 +124,62 @@ public class SearchHouseServiceImpl extends ServiceImpl<SearchHouseMapper, Searc
117 124
         return searchHouseMapper.getRecommendBuildings(orgId, cityId, null, minPriceW, maxPriceW, minPrice, maxPrice, limit);
118 125
     }
119 126
 
127
+    /**
128
+     * 获取导出的数据集合
129
+     *
130
+     * @param searchHouse
131
+     * @return
132
+     */
133
+    @Override
134
+    public List<ExportSearchHouseVO> selectExportHouseList(SearchHouseVO searchHouse) {
135
+        List<ExportSearchHouseVO> searchHouseVOS = searchHouseMapper.selectExportHouseList(searchHouse);
136
+        searchHouseVOS.forEach(e -> {
137
+            String questionnaire = e.getQuestionnaire();
138
+            List<QuestionnaireVO> questionnaireVO = JSON.parseArray(questionnaire,QuestionnaireVO.class);
139
+            questionnaireVO.forEach(s -> {
140
+                try {
141
+                    Field declaredField = e.getClass().getDeclaredField(s.getKey());
142
+                    String name = declaredField.getName();
143
+                    String subName = name.substring(0, 1).toUpperCase() + name.substring(1);
144
+                    Method method = e.getClass().getMethod("set" + subName,String.class);
145
+                    String result = String.valueOf(s.getResult());
146
+                    String type = s.getType();
147
+                    String resultId = null == s.getResultId() ? null : String.valueOf(s.getResultId());
148
+                    if (searchHouse.getType() == 4) {
149
+                        if (name == "maxPrice"){
150
+                            Integer price = Integer.valueOf(result) / 10000;
151
+                            result = String.valueOf(price);
152
+                        }
153
+                    }else if (searchHouse.getType() == 1) {
154
+                        if (name == "maxPrice"){
155
+                            Integer price = Integer.valueOf(result) / 10000;
156
+                            result = String.valueOf(price);
157
+                        }
158
+                        if (type == "checkbox") {
159
+                            result = resultId;
160
+                        }
161
+                        if (type == "checkboxs") {
162
+                            JSONArray optionArr = JSONArray.parseArray(String.valueOf(s.getOptions()));
163
+                        }
164
+                    }else if (searchHouse.getType() == 3) {
165
+                        if (name == "maxPrice"){
166
+                            Integer price = Integer.valueOf(result) / 10000;
167
+                            result = String.valueOf(price);
168
+                        }
169
+                        if (type == "checkbox") {
170
+                            result = resultId;
171
+                        }
172
+                    }
173
+                    method.invoke(e,result);
174
+                } catch (Exception ex) {
175
+                    ex.printStackTrace();
176
+                }
177
+            });
178
+
179
+        });
180
+        return searchHouseVOS;
181
+    }
182
+
120 183
     private Integer[] getUnitPriceRange(Integer minPriceW, Integer maxPriceW, Integer areaResultId) {
121 184
         long minPrice = minPriceW * 10000;
122 185
         long maxPrice = maxPriceW * 10000;

+ 196
- 0
src/main/java/com/yunzhi/marketing/xlk/vo/ExportSearchHouseVO.java View File

@@ -0,0 +1,196 @@
1
+package com.yunzhi.marketing.xlk.vo;
2
+
3
+import com.baomidou.mybatisplus.annotation.IdType;
4
+import com.baomidou.mybatisplus.annotation.TableField;
5
+import com.baomidou.mybatisplus.annotation.TableId;
6
+import com.baomidou.mybatisplus.annotation.TableName;
7
+import com.yunzhi.marketing.entity.TaBuilding;
8
+import com.yunzhi.marketing.xlk.entity.SearchHouse;
9
+import lombok.Data;
10
+import lombok.EqualsAndHashCode;
11
+import lombok.experimental.Accessors;
12
+
13
+import java.io.Serializable;
14
+import java.time.LocalDateTime;
15
+import java.util.List;
16
+
17
+/**
18
+ * <p>
19
+ * 帮我找房 
20
+ * </p>
21
+ *
22
+ * @author jobob
23
+ * @since 2021-05-19
24
+ */
25
+@Data
26
+@EqualsAndHashCode(callSuper = false)
27
+@Accessors(chain = true)
28
+@TableName("xlk_search_house")
29
+public class ExportSearchHouseVO implements Serializable {
30
+
31
+    /**
32
+     * 主键
33
+     */
34
+    @TableId(type = IdType.UUID)
35
+    private String id;
36
+
37
+    /**
38
+     * 创建人小程序人员
39
+     */
40
+    private String personId;
41
+
42
+    /**
43
+     * 创建时间
44
+     */
45
+    @TableField("CREATED_TIME")
46
+    private LocalDateTime createdTime;
47
+
48
+    /**
49
+     * 更新人
50
+     */
51
+    @TableField("UPDATED_BY")
52
+    private String updatedBy;
53
+
54
+    /**
55
+     * 更新时间
56
+     */
57
+    @TableField("UPDATED_TIME")
58
+    private LocalDateTime updatedTime;
59
+
60
+    /**
61
+     * 公司id
62
+     */
63
+    @TableField("ORG_ID")
64
+    private Integer orgId;
65
+
66
+    /**
67
+     * 意向区域
68
+     */
69
+    private String intentArea;
70
+
71
+    /**
72
+     * 总预算范围最小价格
73
+     */
74
+    private String minPrice;
75
+
76
+    /**
77
+     * 总预算范围最大价格
78
+     */
79
+    private String maxPrice;
80
+
81
+
82
+    /**
83
+     * 0待回访,1已回访,2无效
84
+     */
85
+    private String status;
86
+
87
+    /**
88
+     * 审核结果
89
+     */
90
+    private String auditRemark;
91
+
92
+    /**
93
+     * 备注
94
+     */
95
+    private String remark;
96
+
97
+    /**
98
+     * 问卷json字符串
99
+     */
100
+    private String questionnaire;
101
+
102
+    private String avatarurl;
103
+
104
+    private String nickname;
105
+
106
+    private String phone;
107
+
108
+    private String gender;
109
+
110
+    private String name;
111
+
112
+    /**
113
+     * 房屋现状
114
+     */
115
+    private String houseStatus;
116
+
117
+    /**
118
+     * 房屋面积
119
+     */
120
+    private String area;
121
+
122
+    /**
123
+     * 家装模式
124
+     */
125
+    private String type;
126
+
127
+    /**
128
+     * 家装侧重点
129
+     */
130
+    private String important;
131
+    /**
132
+     * 家装风格
133
+     */
134
+    private String style;
135
+    /**
136
+     * 关键诉求
137
+     */
138
+    private String mostImportant;
139
+
140
+    /**
141
+     * 特殊功能区
142
+     */
143
+    private String special;
144
+
145
+    /**
146
+     * 是否智能家居
147
+     */
148
+    private String samrt;
149
+
150
+    /**
151
+     * 房屋类型
152
+     */
153
+    private String isNew;
154
+
155
+    /**
156
+     * 意向居室
157
+     */
158
+    private String layout;
159
+
160
+    /***
161
+     * 购房目的
162
+     */
163
+    private String purpose;
164
+
165
+    /**
166
+     * 侧重优势
167
+     */
168
+    private String advantage;
169
+
170
+    /**
171
+     * 社区要求
172
+     */
173
+    private String facility;
174
+
175
+    /**
176
+     * 朝向要求
177
+     */
178
+    private String orientation;
179
+
180
+    /**
181
+     * 楼层要求
182
+     */
183
+    private String isHigh;
184
+
185
+    /**
186
+     * 楼龄要求
187
+     */
188
+    private String buildingAge;
189
+
190
+    /**
191
+     * 租房偏好
192
+     */
193
+    private String preference;
194
+
195
+
196
+}

+ 17
- 0
src/main/java/com/yunzhi/marketing/xlk/vo/QuestionnaireVO.java View File

@@ -0,0 +1,17 @@
1
+package com.yunzhi.marketing.xlk.vo;
2
+
3
+import lombok.Data;
4
+
5
+@Data
6
+public class QuestionnaireVO {
7
+
8
+    private String key;
9
+
10
+    private String type;
11
+
12
+    private Object result;
13
+
14
+    private Object resultId;
15
+
16
+    private Object options;
17
+}

+ 26
- 0
src/main/resources/mapper/xlk/SearchHouseMapper.xml View File

@@ -63,4 +63,30 @@
63 63
             t.is_main ASC
64 64
         LIMIT #{limit}
65 65
     </select>
66
+    <select id="selectExportHouseList" resultType="com.yunzhi.marketing.xlk.vo.ExportSearchHouseVO">
67
+        SELECT
68
+        t.*,
69
+        p.avatarurl,
70
+        p.`nickname`,
71
+        p.phone,
72
+        p.gender,
73
+        CONCAT(cc.name,c.name) as `name`
74
+        FROM
75
+        xlk_search_house t
76
+        LEFT JOIN ta_person p ON t.person_id = p.person_id
77
+        LEFT JOIN td_city c on t.intent_area = c.id
78
+        LEFT JOIN td_city cc on cc.id = c.parentid
79
+        WHERE t.ORG_ID = #{params.orgId}
80
+        and t.type = #{params.type}
81
+        <if test="params.nickname != null and params.nickname != ''">
82
+            and p.nickname like concat('%', #{params.nickname}, '%')
83
+        </if>
84
+        <if test="params.phone != null and params.phone != ''">
85
+            and p.phone like concat('%', #{params.phone}, '%')
86
+        </if>
87
+        <if test="params.status != null and params.status != ''">
88
+            and t.status = #{params.status}
89
+        </if>
90
+        order by CREATED_TIME desc
91
+    </select>
66 92
 </mapper>