|
@@ -8,14 +8,25 @@ import com.redxun.dto.user.OsGroupDto;
|
|
|
import com.redxun.dto.user.OsUserDto;
|
|
|
import com.redxun.feign.org.OrgClient;
|
|
|
import com.redxun.feign.org.UserClient;
|
|
|
+import com.redxun.knowledge.entity.vo.UserInfoVo;
|
|
|
+import com.redxun.knowledge.mapper.CommonMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 文件名: UserService
|
|
@@ -36,6 +47,9 @@ public class UserService {
|
|
|
@Autowired
|
|
|
private OrgClient orgClient;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private CommonMapper commonMapper;
|
|
|
+
|
|
|
@Value("${uploaderHead.male}")
|
|
|
private String male;
|
|
|
|
|
@@ -168,4 +182,61 @@ public class UserService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public void downLoadXlsx(HttpServletResponse response) {
|
|
|
+ try {
|
|
|
+ //创建一个空的工作薄
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook();
|
|
|
+ //在工作薄中创建一个工作表
|
|
|
+ XSSFSheet sheet = workbook.createSheet("知识创建统计");
|
|
|
+ //设置列宽
|
|
|
+ sheet.setColumnWidth(0, 5 * 256);
|
|
|
+ sheet.setColumnWidth(1, 8 * 256);
|
|
|
+ sheet.setColumnWidth(2, 15 * 256);
|
|
|
+ sheet.setColumnWidth(3, 15 * 256);
|
|
|
+ sheet.setColumnWidth(4, 30 * 256);
|
|
|
+ //处理标题
|
|
|
+ String[] titles = new String[]{"用户名", "创建数量", "部门信息"};
|
|
|
+
|
|
|
+ //创建标题行
|
|
|
+ Row titleRow = sheet.createRow(0);
|
|
|
+ Cell cell = null;
|
|
|
+ for (int i = 0; i < titles.length; i++) {
|
|
|
+ cell = titleRow.createCell(i);
|
|
|
+ cell.setCellValue(titles[i]);
|
|
|
+ }
|
|
|
+ //处理内容
|
|
|
+ List<UserInfoVo> userList = commonMapper.findUserInfo();
|
|
|
+ int rowIndex = 1;
|
|
|
+ Row row = null;
|
|
|
+ for (UserInfoVo user : userList) {
|
|
|
+ row = sheet.createRow(rowIndex);
|
|
|
+ cell = row.createCell(0);
|
|
|
+ cell.setCellValue(user.getFullName());
|
|
|
+
|
|
|
+ cell = row.createCell(1);
|
|
|
+ cell.setCellValue(user.getCount());
|
|
|
+
|
|
|
+ cell = row.createCell(2);
|
|
|
+ String deptPath = user.getPath();
|
|
|
+ if (StringUtils.isNotEmpty(deptPath)) {
|
|
|
+ deptPath = deptPath.substring(deptPath.indexOf(".") + 1);
|
|
|
+ String[] split = deptPath.split("\\.");
|
|
|
+ String pathName = Arrays.stream(split).map(e -> this.findDeptByDeptId(e).getName()).collect(Collectors.joining(">"));
|
|
|
+ cell.setCellValue(pathName);
|
|
|
+ }
|
|
|
+
|
|
|
+ rowIndex++;
|
|
|
+ }
|
|
|
+ //导出的文件名称
|
|
|
+ String filename = "创建知识数据.xlsx";
|
|
|
+ //设置文件的打开方式和mime类型
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" +
|
|
|
+ new String(filename.getBytes(), "ISO8859-1"));
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ workbook.write(outputStream);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|