Parcourir la source

add export excel

张延森 il y a 6 ans
Parent
révision
1f5b0efdd6

+ 6
- 0
pom.xml Voir le fichier

@@ -118,6 +118,12 @@
118 118
 			<!-- go to https://search.maven.org/search?q=tencentcloud-sdk-java and get the latest version. -->
119 119
 			<version>3.0.75</version>
120 120
 		</dependency>
121
+		<!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
122
+		<dependency>
123
+			<groupId>com.alibaba</groupId>
124
+			<artifactId>easyexcel</artifactId>
125
+			<version>1.1.1</version>
126
+		</dependency>
121 127
 	</dependencies>
122 128
 
123 129
 	<build>

+ 58
- 4
src/main/java/com.huiju.welcome/controller/TaMainUsherRecordController.java Voir le fichier

@@ -1,5 +1,8 @@
1 1
 package com.huiju.welcome.controller;
2 2
 
3
+import com.alibaba.excel.ExcelWriter;
4
+import com.alibaba.excel.metadata.Sheet;
5
+import com.alibaba.excel.support.ExcelTypeEnum;
3 6
 import com.alibaba.fastjson.JSONArray;
4 7
 import com.alibaba.fastjson.JSONObject;
5 8
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -8,10 +11,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
8 11
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
9 12
 import com.huiju.welcome.common.base.BaseController;
10 13
 import com.huiju.welcome.common.base.ResponseBean;
11
-import com.huiju.welcome.model.SysUser;
12
-import com.huiju.welcome.model.TaCustomer;
13
-import com.huiju.welcome.model.TaFollowupRecord;
14
-import com.huiju.welcome.model.TaMainUsherRecord;
14
+import com.huiju.welcome.model.*;
15 15
 import com.huiju.welcome.service.*;
16 16
 import com.huiju.welcome.utils.DateUtils;
17 17
 import com.huiju.welcome.utils.JWTUtils;
@@ -23,7 +23,12 @@ import org.slf4j.LoggerFactory;
23 23
 import org.springframework.beans.factory.annotation.Autowired;
24 24
 import org.springframework.web.bind.annotation.*;
25 25
 
26
+import javax.servlet.ServletOutputStream;
26 27
 import javax.servlet.http.HttpServletRequest;
28
+import javax.servlet.http.HttpServletResponse;
29
+import java.io.IOException;
30
+import java.time.LocalDateTime;
31
+import java.time.format.DateTimeFormatter;
27 32
 import java.util.List;
28 33
 
29 34
 /**
@@ -49,6 +54,9 @@ public class TaMainUsherRecordController extends BaseController {
49 54
     @Autowired
50 55
     private ITaPersonService iTaPersonService;
51 56
 
57
+    @Autowired
58
+    private ITaCustomerService iTaCustomerService;
59
+
52 60
     /**
53 61
      * 保存对象
54 62
      * @param taMainUsherRecord 实体对象
@@ -214,6 +222,16 @@ public class TaMainUsherRecordController extends BaseController {
214 222
         return responseBean;
215 223
     }
216 224
 
225
+    /**
226
+     * 列表查询的参数必须要跟导出接口的参数一致
227
+     * @param pageNum
228
+     * @param pageSize
229
+     * @param customerName
230
+     * @param phone
231
+     * @param platNumber
232
+     * @param agentUserId
233
+     * @return
234
+     */
217 235
     @RequestMapping(value="/customerList",method= RequestMethod.GET)
218 236
     public ResponseBean customer(@RequestParam(defaultValue = "1") int pageNum,
219 237
                                  @RequestParam(defaultValue = "10") int pageSize,
@@ -224,6 +242,42 @@ public class TaMainUsherRecordController extends BaseController {
224 242
         ResponseBean result = iTaMainUsherRecordService.customerPage(pageNum, pageSize,customerName,phone,platNumber, agentUserId);
225 243
         return result;
226 244
     }
245
+
246
+    /**
247
+     * 导出接口的参数必须要跟列表查询的参数一致
248
+     * @param customerName
249
+     * @param phone
250
+     * @param platNumber
251
+     * @param agentUserId
252
+     * @param response
253
+     */
254
+    @RequestMapping(value="/excel/customerList",method= RequestMethod.GET)
255
+    public void exportCustomer(@RequestParam(value = "customerName" ,required = false)String customerName,
256
+                               @RequestParam(value = "phone" ,required = false)String phone,
257
+                               @RequestParam(value = "platNumber" ,required = false)String platNumber,
258
+                               @RequestParam(value = "agentUserId", required = false) Integer agentUserId,
259
+                               HttpServletResponse response) {
260
+        List<CustomerExcel> result = iTaCustomerService.getCustomersEqualCustomerPage(customerName, phone, platNumber, agentUserId);
261
+
262
+        try {
263
+            ServletOutputStream out = response.getOutputStream();
264
+
265
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
266
+            String fileName = LocalDateTime.now().format(formatter) + "-" + StringUtils.ifNull(null == agentUserId ? null : String.valueOf(agentUserId), "全部");
267
+
268
+            response.setContentType("multipart/form-data");
269
+            response.setCharacterEncoding("utf-8");
270
+            response.setHeader("Content-disposition", "attachment;filename="+fileName+".xlsx");
271
+            ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX, true);
272
+            Sheet sheet1 = new Sheet(1, 0, CustomerExcel.class);
273
+            writer.write(result, sheet1);
274
+            writer.finish();
275
+
276
+            out.flush();
277
+        } catch (IOException e) {
278
+            e.printStackTrace();
279
+        }
280
+    }
227 281
     
228 282
     /**
229 283
      * 修改对象

+ 2
- 0
src/main/java/com.huiju.welcome/mapper/TaCustomerMapper.java Voir le fichier

@@ -22,6 +22,8 @@ public interface TaCustomerMapper extends BaseMapper<TaCustomer> {
22 22
     TaCustomer getCustomerOf(@Param("personId") Integer personId, @Param("realId") Integer realId);
23 23
     IPage<TaCustomer> customerPage(IPage<TaCustomer> pg, @Param("customerName") String customerName, @Param("phone") String phone, @Param("platNumber") String platNumber, @Param("agentUserId") Integer agentUserId);
24 24
 
25
+    List<TaCustomer> getCustomersEqualCustomerPage(@Param("customerName") String customerName,  @Param("phone") String phone, @Param("platNumber") String platNumber, @Param("agentUserId") Integer agentUserId);
26
+
25 27
     List<TaCustomer> getSomeCustMayBe(@Param("plateNumber") String plateNumber, @Param("phone") String phone);
26 28
 
27 29
     IPage<TaCustomer> getCustomerListOfFront(IPage<TaCustomer> page,@Param("consultantId") Integer consultantId,@Param("nameOrPhone") String nameOrPhone);

+ 92
- 0
src/main/java/com.huiju.welcome/model/CustomerExcel.java Voir le fichier

@@ -0,0 +1,92 @@
1
+package com.huiju.welcome.model;
2
+
3
+import com.alibaba.excel.annotation.ExcelProperty;
4
+import com.alibaba.excel.metadata.BaseRowModel;
5
+import lombok.Data;
6
+
7
+@Data
8
+public class CustomerExcel extends BaseRowModel {
9
+    @ExcelProperty(value = "#" ,index = 0)
10
+    Integer customerId;
11
+
12
+    @ExcelProperty(value = "姓名" ,index = 1)
13
+    String customerName;
14
+
15
+    @ExcelProperty(value = "性别" ,index = 2)
16
+    String sex;
17
+
18
+    @ExcelProperty(value = "年龄" ,index = 3)
19
+    String customerAge;
20
+
21
+    @ExcelProperty(value = "手机号码" ,index = 4)
22
+    String phone;
23
+
24
+    @ExcelProperty(value = "身份证号" ,index = 5)
25
+    String idcard;
26
+
27
+    @ExcelProperty(value = "车牌号码" ,index = 6)
28
+    String plateNumber;
29
+
30
+    @ExcelProperty(value = "车辆品牌" ,index = 7)
31
+    String carModel;
32
+
33
+    @ExcelProperty(value = "置业顾问" ,index = 8)
34
+    String consultant;
35
+
36
+    @ExcelProperty(value = "客户来源" ,index = 9)
37
+    String channel;
38
+
39
+    @ExcelProperty(value = "来访目的" ,index = 10)
40
+    String purpose;
41
+
42
+    @ExcelProperty(value = "是否在银城购买过房子" ,index = 11)
43
+    String haveHouse;
44
+
45
+    @ExcelProperty(value = "老业务小区" ,index = 12)
46
+    String oldCommunity;
47
+
48
+    @ExcelProperty(value = "现居住区域" ,index = 13)
49
+    String nowArea;
50
+
51
+    @ExcelProperty(value = "现居住城市" ,index = 14)
52
+    String nowCity;
53
+
54
+    @ExcelProperty(value = "现居住小区" ,index = 15)
55
+    String nowCommunity;
56
+
57
+    @ExcelProperty(value = "家庭主收入人员工作区域" ,index = 16)
58
+    String familyWork;
59
+
60
+    @ExcelProperty(value = "城市名称" ,index = 17)
61
+    String cityName;
62
+
63
+    @ExcelProperty(value = "家庭主收入人员工作单位" ,index = 18)
64
+    String familyCompany;
65
+
66
+    @ExcelProperty(value = "家庭主收入人员工作行业" ,index = 19)
67
+    String familyIndustry;
68
+
69
+    @ExcelProperty(value = "家庭主收入人员职务" ,index = 20)
70
+    String familyDuty;
71
+
72
+    @ExcelProperty(value = "家庭本市置业次数" ,index = 21)
73
+    String housePurchasing;
74
+
75
+    @ExcelProperty(value = "家庭本市房产数量" ,index = 22)
76
+    String houseProperty;
77
+
78
+    @ExcelProperty(value = "现居住面积" ,index = 23)
79
+    String houseLivingArea;
80
+
81
+    @ExcelProperty(value = "现居住户型" ,index = 24)
82
+    String houseType;
83
+
84
+    @ExcelProperty(value = "目前家庭结构" ,index = 25)
85
+    String familyStructure;
86
+
87
+    @ExcelProperty(value = "意向等级" ,index = 26)
88
+    String favorLevel;
89
+
90
+    @ExcelProperty(value = "备 注" ,index = 27)
91
+    String remark;
92
+}

+ 2
- 0
src/main/java/com.huiju.welcome/service/ITaCustomerService.java Voir le fichier

@@ -44,4 +44,6 @@ public interface ITaCustomerService extends IService<TaCustomer> {
44 44
     TaCustomer getWithLastVisit(Integer id);
45 45
 
46 46
     IPage<TaCustomer> getCustomerListOfFront(int pageNumber, int pageSize, Integer consultantId, String nameOrPhone);
47
+
48
+    List<CustomerExcel> getCustomersEqualCustomerPage(String customerName, String phone, String platNumber, Integer agentUserId);
47 49
 }

+ 62
- 3
src/main/java/com.huiju.welcome/service/impl/TaCustomerServiceImpl.java Voir le fichier

@@ -69,10 +69,10 @@ public class TaCustomerServiceImpl extends ServiceImpl<TaCustomerMapper, TaCusto
69 69
     ISysParamService iSysParamService;
70 70
 
71 71
     @Autowired
72
-    MiniApp miniApp;
73
-    
72
+    ISysDictService iSysDictService;
73
+
74 74
     @Autowired
75
-    private ISysDictService iSysDictService;
75
+    MiniApp miniApp;
76 76
 
77 77
     @Override
78 78
     public List<TaPerson> getGroup(Integer customerId) {
@@ -390,6 +390,65 @@ public class TaCustomerServiceImpl extends ServiceImpl<TaCustomerMapper, TaCusto
390 390
         return taCustomerMapper.getCustomerListOfFront(page, consultantId, nameOrPhone);
391 391
     }
392 392
 
393
+    @Override
394
+    public List<CustomerExcel> getCustomersEqualCustomerPage(String customerName, String phone, String platNumber, Integer agentUserId) {
395
+        List<CustomerExcel> result = new ArrayList<>();
396
+        List<TaCustomer> customers = taCustomerMapper.getCustomersEqualCustomerPage(customerName, phone, platNumber, agentUserId);
397
+        List<SysDict> dict = iSysDictService.list();
398
+
399
+        if (null != customers) {
400
+            for (int i = 0; i < customers.size(); i ++) {
401
+                TaCustomer customer = customers.get(i);
402
+
403
+                CustomerExcel item = new CustomerExcel();
404
+                item.setCustomerId(customer.getCustomerId());
405
+                item.setCustomerName(customer.getCustomerName());
406
+                item.setSex(null == customer.getSex() ? "未知" : (2 == customer.getSex() ? "女" : "男"));
407
+                item.setCustomerAge(getItemNameOfDict(dict, customer.getCustomerAge()));
408
+                item.setPhone(customer.getPhone());
409
+                item.setIdcard(customer.getIdcard());
410
+                item.setPlateNumber(customer.getPlateNumber());
411
+                item.setCarModel(customer.getCarModel());
412
+                item.setConsultant(customer.getRealtyConsultant());
413
+                item.setChannel("1".equals(customer.getChannel()) ? "预约": "未约");
414
+                item.setPurpose("1".equals(customer.getPurpose()) ? "看房": "其他");
415
+                item.setHaveHouse(null != customer.getHaveHouse() && 1 == customer.getHaveHouse() ? "是" : "否");
416
+                item.setOldCommunity(customer.getOldCommunity());
417
+                item.setNowArea(getItemNameOfDict(dict, customer.getNowArea()));
418
+                item.setNowCity(customer.getNowCity());
419
+                item.setNowCommunity(customer.getNowCommunity());
420
+                item.setFamilyWork(getItemNameOfDict(dict, customer.getFamilyWork()));
421
+                item.setCityName(customer.getCityName());
422
+                item.setFamilyCompany(customer.getFamilyCompany());
423
+                item.setFamilyIndustry(customer.getFamilyIndustry());
424
+                item.setFamilyDuty(customer.getFamilyDuty());
425
+                item.setHousePurchasing(getItemNameOfDict(dict, customer.getHousePurchasing()));
426
+                item.setHouseProperty(getItemNameOfDict(dict, customer.getHouseProperty()));
427
+                item.setHouseLivingArea(getItemNameOfDict(dict, customer.getHouseLivingArea()));
428
+                item.setHouseType(getItemNameOfDict(dict, customer.getHouseType()));
429
+                item.setFamilyStructure(getItemNameOfDict(dict, customer.getFamilyStructure()));
430
+                item.setFavorLevel(getItemNameOfDict(dict, null == customer.getFavorLevel() ? null : Integer.valueOf(customer.getFavorLevel())));
431
+                item.setRemark(customer.getRemark());
432
+
433
+                result.add(item);
434
+            }
435
+        }
436
+
437
+        return result;
438
+    }
439
+
440
+    private String getItemNameOfDict(List<SysDict> dict, Integer id) {
441
+        if (null == dict || null == id) return null;
442
+
443
+        for (int i = 0; i < dict.size(); i ++) {
444
+            if (id == dict.get(i).getId()) {
445
+                return dict.get(i).getLabel();
446
+            }
447
+        }
448
+
449
+        return null;
450
+    }
451
+
393 452
     private TaCustomer newCustomerByPerson(TaPerson taPerson) throws Exception {
394 453
         TaCustomer taCustomer = new TaCustomer();
395 454
         taCustomer.setCustomerId(taPerson.getRealId());

+ 23
- 0
src/main/resources/mapper/TaCustomerMapper.xml Voir le fichier

@@ -26,6 +26,7 @@
26 26
         "" as transferId
27 27
         from ta_customer tac
28 28
         <where>
29
+            tac.status &gt; -1
29 30
             <if test="customerName !=null and customerName != ''">
30 31
                 and tac.customer_name LIKE CONCAT('%',#{customerName},'%')
31 32
             </if>
@@ -44,6 +45,28 @@
44 45
         order by create_date desc
45 46
     </select>
46 47
 
48
+    <select id="getCustomersEqualCustomerPage" resultType="com.huiju.welcome.model.TaCustomer">
49
+        select * from ta_customer t
50
+        <where>
51
+            t.status &gt; -1
52
+            <if test="customerName !=null and customerName != ''">
53
+                and t.customer_name LIKE CONCAT('%',#{customerName},'%')
54
+            </if>
55
+
56
+            <if test="phone !=null and phone != ''">
57
+                and t.phone LIKE CONCAT('%',#{phone},'%')
58
+            </if>
59
+
60
+            <if test="platNumber !=null and platNumber != ''">
61
+                and t.plate_number LIKE CONCAT('%',#{platNumber},'%')
62
+            </if>
63
+            <if test="agentUserId != null">
64
+                and t.consultant_id = #{agentUserId}
65
+            </if>
66
+        </where>
67
+        order by consultant_id, create_date desc
68
+    </select>
69
+
47 70
     <select id="getSomeCustMayBe" resultType="com.huiju.welcome.model.TaCustomer">
48 71
         SELECT
49 72
             *