|
|
@@ -1,5 +1,8 @@
|
|
|
package com.fdkankan.manage_jp.service.impl;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
@@ -22,6 +25,7 @@ import com.fdkankan.manage_jp.vo.request.RequestCompany;
|
|
|
import com.fdkankan.manage_jp.vo.request.UserListParam;
|
|
|
import com.fdkankan.manage_jp.vo.request.UserParam;
|
|
|
import com.fdkankan.manage_jp.vo.response.LoginVo;
|
|
|
+import com.fdkankan.manage_jp.vo.response.UserExcelVo;
|
|
|
import com.fdkankan.manage_jp.vo.response.UserVo;
|
|
|
import com.fdkankan.redis.constant.RedisKey;
|
|
|
import com.fdkankan.redis.util.RedisUtil;
|
|
|
@@ -30,6 +34,9 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
@@ -260,4 +267,35 @@ public class UserServiceImpl extends ServiceImpl<IUserMapper, User> implements I
|
|
|
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void export(UserParam param, HttpServletRequest req, HttpServletResponse resp) {
|
|
|
+ List<UserExcelVo> exportSceneLists = this.getBaseMapper().getExPortList(param);
|
|
|
+ try {
|
|
|
+ this.commonExport(req,resp,"用户数据",exportSceneLists, UserExcelVo.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void commonExport(HttpServletRequest request, HttpServletResponse response,String name,List<?> result,Class<?> clazz) throws Exception {
|
|
|
+ response.setContentType("application/vnd.ms-excel");
|
|
|
+ response.setCharacterEncoding("utf-8");
|
|
|
+ String fileName = name + ".xlsx";
|
|
|
+ fileName = URLEncoder.encode(fileName, "UTF-8");
|
|
|
+ response.setHeader("Content-disposition", "attachment;filename=" + fileName);
|
|
|
+ ExcelWriter excelWriter = null;
|
|
|
+ try {
|
|
|
+ excelWriter = EasyExcel.write(response.getOutputStream(), clazz).build();
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet(name).build();
|
|
|
+ excelWriter.write(result, writeSheet);
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ if(excelWriter != null){
|
|
|
+ excelWriter.finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|