package com.shrj.partybuilder.backstage.controller.organStatement;
import com.shrj.partybuilder.backstage.dto.organStatement.OrganStatementDto;
import com.shrj.partybuilder.backstage.service.organStatement.OrganTeamMembersService;
import com.shrj.partybuilder.backstage.service.report.impl.ReportOutServiceImpl;
import com.shrj.partybuilder.backstage.vo.organStatement.OrganTeamExcelVo;
import com.shrj.partybuilder.backstage.vo.report.OrganTreeVo;
import com.shrj.partybuilder.common.utils.ExcelUtilz;
import com.shrj.wbaostd.authmodule.auth.UserDetailsImpl;
import com.shrj.wbaostd.basemodule.common.R;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.oauth2.provider.OAuth2Authentication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
- 接口层
- @author chenzhijian
- @email chenzhijian
- @date 2022-07-11 11:23:45
/
@Slf4j
@RestController
@RequestMapping(“/bus/organStatement/team”)
@RequiredArgsConstructor
public class OrganTeamMembersController {
@Resource
OrganTeamMembersService organTeamMembersService;
@Resource
private ReportOutServiceImpl reportOutServiceImpl;
//这是党组织班子成员报表查询列表的后台拦截处理方法
/*
- 党组织班子成员报表
- @param organs 选择的组织id
- @param oAuth2Authentication
/
@GetMapping(“/list”)
public R TeamList(
@RequestParam(name = “organs”, required = false) ArrayList organs,
OAuth2Authentication oAuth2Authentication
){
ArrayList arrList;
// 按选择的组织查询,遍历organs把id转为name再查
if (organs!= null && organs.size() >0){
arrList = organTeamMembersService.getArrList(organs);
}else {
// 未选择组织,默认查全部
UserDetailsImpl details = (UserDetailsImpl)oAuth2Authentication.getUserAuthentication().getPrincipal();
String organId = details.getOrganId();
//根据当前登录的用户的组织id获取组织树
OrganTreeVo vo = reportOutServiceImpl.getOwnAndSonOrganTree(organId);
//根据组织树和组织id获取自身和子组织的组织id
List ownAndSonOrganIdByTree = reportOutServiceImpl
.getOwnAndSonOrganIdByTree(vo, organId, false, false);
arrList = organTeamMembersService.getArrList((ArrayList) ownAndSonOrganIdByTree);
}
return R.ok().put(“organStatementDto”, arrList);
}
/* - 党组织班子成员报表Excel导出
- @param field 选择显示的字段
- @param organs 选择的组织
- @param response
- @param oAuth2Authentication
*/
@GetMapping(“/TeamExcel”)
public void getTeamsExcel(
@RequestParam(name = “organs”, required = false) List organs,
@RequestParam(name = “field”, required = false) List field,
HttpServletResponse response,
OAuth2Authentication oAuth2Authentication) {
R result = this.TeamList((ArrayList) organs, oAuth2Authentication);
if (result.getCode() == 0) {
// 设置流的字符集及文件类型
response.setCharacterEncoding(“utf-8”);
response.setContentType(“application/msword”);
try {
response.setHeader(“Content-Disposition”, “attachment;filename=”
.concat(String.valueOf(URLEncoder.encode(“集团党组织班子成员明细表.xlsx”, “UTF-8”))));
// 写入数据
ExcelUtilz excelUtilz = new ExcelUtilz();
List data = (List) result.get(“organStatementDto”);
if (data == null) {
return;
}
List collect = data.stream().map(OrganStatementDto::toTeamExcelVo).collect(Collectors.toList());
excelUtilz.outExcel(response.getOutputStream(), “sheet1”,
excelUtilz.teamMembersInfoHead(field),
excelUtilz.contentDataByIndex(collect, field));
} catch (Exception e) {
log.error(“导出excel出错”);
}
}
}
}