diff --git a/src/com/engine/organization/service/DepartmentService.java b/src/com/engine/organization/service/DepartmentService.java index 04791771..e88ef1f1 100644 --- a/src/com/engine/organization/service/DepartmentService.java +++ b/src/com/engine/organization/service/DepartmentService.java @@ -7,6 +7,7 @@ import com.engine.organization.entity.job.vo.SingleJobTreeVO; import com.engine.organization.entity.searchtree.SearchTreeParams; import com.engine.organization.util.MenuBtn; import com.engine.organization.util.page.PageInfo; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.util.List; import java.util.Map; @@ -160,4 +161,12 @@ public interface DepartmentService { */ int moveDepartment(DepartmentMoveParam moveParam); + /** + * @Description: 部门导出 + * @Author: liang.cheng + * @Date: 2023/9/21 11:37 AM + * @param: [] + * @return: org.apache.poi.xssf.usermodel.XSSFWorkbook + */ + XSSFWorkbook departmentExport(); } diff --git a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java index ccf18268..13dc87f4 100644 --- a/src/com/engine/organization/service/impl/DepartmentServiceImpl.java +++ b/src/com/engine/organization/service/impl/DepartmentServiceImpl.java @@ -39,6 +39,7 @@ import com.engine.organization.util.*; import com.engine.organization.util.coderule.CodeRuleUtil; import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.detach.DetachUtil; +import com.engine.organization.util.excel.ExcelUtil; import com.engine.organization.util.page.Column; import com.engine.organization.util.page.PageInfo; import com.engine.organization.util.page.PageUtil; @@ -46,6 +47,7 @@ import com.engine.organization.util.tree.SearchTreeUtil; import com.google.common.collect.Lists; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang.StringUtils; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.common.DateUtil; import weaver.conn.RecordSet; import weaver.general.StringUtil; @@ -696,6 +698,58 @@ public class DepartmentServiceImpl extends Service implements DepartmentService return 1; } + @Override + public XSSFWorkbook departmentExport() { + + String orderSql = PageInfoSortUtil.getSortSql("", " showorder "); + List allList = getDepartmentMapper().listAll(orderSql); + Map poMaps = allList.stream().collect(Collectors.toMap(DepartmentPO::getId, item -> item)); + List dtoList = allList.stream().map(e -> + DepartmentListDTO + .builder() + .id(e.getId()) + .departmentMark(e.getDepartmentMark()) + .departmentName(e.getDepartmentName()) + .departmentCode(e.getDepartmentCode()) + .subCompanyName(0 == e.getSubCompanyId1() ? "" : MapperProxyFactory.getProxy(CompMapper.class).listById(e.getSubCompanyId1()).getSubCompanyName()) + .supDepName(null == poMaps.get(e.getSupDepId()) ? "" : poMaps.get(e.getSupDepId()).getDepartmentName()) + .bmfzr(DepartmentBO.getEmployeeNameById(e.getId())) + .canceled(null == e.getCanceled() ? 0 : e.getCanceled()) + .build()).collect(Collectors.toList()); + + // 1.工作簿名称 + String sheetName = HrmI18nUtil.getI18nLabel(85368, "部门档案数据"); + // 2.表头(后面动态获取) + List> excelSheetData = new ArrayList<>(); + + String[] header = { + HrmI18nUtil.getI18nLabel( -93270, "部门名称"), + HrmI18nUtil.getI18nLabel( -93272, "编号"), + HrmI18nUtil.getI18nLabel( -93274, "部门简称"), + HrmI18nUtil.getI18nLabel( -93275, "所属分部"), + HrmI18nUtil.getI18nLabel( -93278, "上级部门"), + HrmI18nUtil.getI18nLabel( -93279, "部门负责人"), + HrmI18nUtil.getI18nLabel( -93280, "启用状态") + }; + excelSheetData.add(Arrays.asList(header)); + + //数据 + List> rows = new LinkedList<>(); + for (DepartmentListDTO vo : dtoList) { + List row = new LinkedList<>(); + row.add(vo.getDepartmentCode()); + row.add(vo.getDepartmentName()); + row.add(vo.getDepartmentMark()); + row.add(vo.getSubCompanyName()); + row.add(vo.getSupDepName()); + row.add(vo.getBmfzr()); + row.add(vo.getCanceled() == 0 ? "启用" : "未启用"); + rows.add(row); + } + excelSheetData.addAll(rows); + return ExcelUtil.genWorkbookV2(excelSheetData, sheetName); + } + /** * 获取所有子部门id * diff --git a/src/com/engine/organization/web/DepartmentController.java b/src/com/engine/organization/web/DepartmentController.java index bba9f0c9..06083838 100644 --- a/src/com/engine/organization/web/DepartmentController.java +++ b/src/com/engine/organization/web/DepartmentController.java @@ -2,6 +2,7 @@ package com.engine.organization.web; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alipay.oceanbase.jdbc.StringUtils; import com.engine.common.util.ParamUtil; import com.engine.common.util.ServiceUtil; import com.engine.organization.entity.DeleteParam; @@ -10,18 +11,25 @@ import com.engine.organization.entity.searchtree.SearchTreeParams; import com.engine.organization.util.response.ReturnResult; import com.engine.organization.wrapper.DepartmentWrapper; import io.swagger.v3.oas.annotations.parameters.RequestBody; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.hrm.HrmUserVarify; import weaver.hrm.User; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.StreamingOutput; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @Author weaver_cl @@ -333,4 +341,28 @@ public class DepartmentController { } } + + @GET + @Path("/export") + @Produces(MediaType.APPLICATION_OCTET_STREAM) + public Response departmentExport(@Context HttpServletRequest request, @Context HttpServletResponse response) { + + User user = HrmUserVarify.getUser(request, response); + XSSFWorkbook workbook = getDepartmentWrapper(user).departmentExport(); + String time = LocalDate.now().toString(); + String fileName = "部门导出" + time; + try { + fileName = URLEncoder.encode(fileName + ".xlsx", "UTF-8"); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + StreamingOutput output = outputStream -> { + workbook.write(outputStream); + outputStream.flush(); + }; + response.setContentType("application/octet-stream"); + return Response.ok(output).header("Content-disposition", "attachment;filename=" + fileName).header("Cache-Control", "no-cache").build(); + } + + } diff --git a/src/com/engine/organization/wrapper/DepartmentWrapper.java b/src/com/engine/organization/wrapper/DepartmentWrapper.java index 0fb057db..aa51b966 100644 --- a/src/com/engine/organization/wrapper/DepartmentWrapper.java +++ b/src/com/engine/organization/wrapper/DepartmentWrapper.java @@ -21,6 +21,7 @@ import com.engine.organization.util.db.MapperProxyFactory; import com.engine.organization.util.page.PageInfo; import com.engine.organization.util.response.ReturnResult; import org.apache.commons.lang.StringUtils; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; import weaver.hrm.User; import java.util.Collection; @@ -259,4 +260,9 @@ public class DepartmentWrapper extends OrganizationWrapper { }.getClass(), departmentPO.getDepartmentName(), JSON.toJSONString(moveParam), departmentPO, getDepartmentMapper().getDeptById(departmentPO.getId())); return moveDepartment; } + + + public XSSFWorkbook departmentExport() { + return getDepartmentService(user).departmentExport(); + } }