Merge branch 'version_performance_2.0' of http://gitlab.ldxinyong.com/enterpriseManagement/lz_management into version_performance_2.0
This commit is contained in:
commit
e6202146b0
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.poi.excel.ExcelUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import cn.hutool.poi.excel.StyleSet;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.lz.common.utils.PageUtils;
|
||||
import com.lz.common.utils.R;
|
||||
@ -21,6 +22,8 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@ -38,7 +41,7 @@ import java.util.List;
|
||||
* @Date: 2020/12/1 10:26
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/performance")
|
||||
@RequestMapping("/file")
|
||||
@Slf4j
|
||||
@Api(value="导出excel接口", tags={"导出表格"})
|
||||
public class ExportController {
|
||||
@ -46,39 +49,21 @@ public class ExportController {
|
||||
private ChartResultService chartResultService;
|
||||
|
||||
|
||||
@PostMapping("/export/levelDetail")
|
||||
@GetMapping("/export/levelDetail")
|
||||
@ApiOperation("导出等级详情")
|
||||
public void levelDetail(@RequestBody @ApiParam(name = "body",value = "body请求体",required = true) ChartResultReq req,HttpServletResponse response){
|
||||
List<LevelDetailExportRes> levelDetailExportRes = Lists.newArrayList();
|
||||
public void levelDetail(ChartResultReq req,HttpServletResponse response){
|
||||
try {
|
||||
//Long userId = getUserId();
|
||||
Long userId = 313L;
|
||||
req.setLoginUserId(userId);
|
||||
levelDetailExportRes = chartResultService.selectLevelDetailList(req);
|
||||
//获取数据
|
||||
List data = chartResultService.selectLevelDetailList(req);
|
||||
//导出
|
||||
buildExcelExport(data,response);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取报表等级详情数据异常" ,e);
|
||||
log.error("导出等级详情异常,e: ",e);
|
||||
}
|
||||
List<String> rowHead = CollUtil.newArrayList("序号", "工号", "员工姓名", "当月状态", "一级部门", "二级部门", "三级部门", "职位", "员工月度绩效考核评分","员工月度绩效考核结果等级");
|
||||
List<LevelDetailExportRes> data = Lists.newArrayList();
|
||||
|
||||
ExcelWriter writer = ExcelUtil.getWriter();
|
||||
buildData(LevelDetailExportRes.class,null,writer);
|
||||
writer.merge(1, "员工信息表");
|
||||
writer.write(data, true);
|
||||
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
String name = "test测试";
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xls");
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
out = response.getOutputStream();
|
||||
writer.flush(out, true);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
IoUtil.close(out);
|
||||
|
||||
}
|
||||
|
||||
@ -103,4 +88,51 @@ public class ExportController {
|
||||
writer.addHeaderAlias(field.getName(), tags.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private void buildExcelExport(List data, HttpServletResponse response){
|
||||
//设置表头表尾及数据
|
||||
List<String> rowHead = CollUtil.newArrayList("序号", "工号", "员工姓名", "当月状态", "一级部门", "二级部门", "三级部门", "职位", "员工月度绩效考核评分","员工月度绩效考核结果等级");
|
||||
ExcelWriter writer = ExcelUtil.getWriter();
|
||||
writer.setColumnWidth(-1,15);
|
||||
writer.passRows(4);
|
||||
buildData(LevelDetailExportRes.class,rowHead,writer);
|
||||
writer.merge(0,2,0,9,"绩效考核总表",false);
|
||||
writer.merge(3,3,0,1,"考核月份",false);
|
||||
writer.write(data, true);
|
||||
writer.merge(7 + data.size(),8 + data.size(),0,0,"签字",false);
|
||||
|
||||
//设置下拉框数据
|
||||
String[] values = { "当月入职", "当月离职", "当月跨部门调动", "当月转正", "已转正", "试用期"};
|
||||
Sheet sheet = writer.getSheet();
|
||||
int firstRow = 4;
|
||||
int lastRow = 4;
|
||||
int firstCol = 3;
|
||||
int lastCol = 3;
|
||||
CellRangeAddressList addressList = new CellRangeAddressList(firstRow, lastRow, firstCol, lastCol);
|
||||
StyleSet styleSet = writer.getStyleSet();
|
||||
CellStyle cellStyle = styleSet.getCellStyle();
|
||||
cellStyle.setDataFormat((short) BuiltinFormats.getBuiltinFormat("text"));
|
||||
DataValidationHelper helper = sheet.getDataValidationHelper();
|
||||
DataValidationConstraint constraint = helper.createExplicitListConstraint(values);
|
||||
DataValidation dataValidation = helper.createValidation(constraint, addressList);
|
||||
writer.addValidationData(dataValidation);
|
||||
|
||||
//响应
|
||||
String name = "test测试";
|
||||
response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + name + ".xls");
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
out = response.getOutputStream();
|
||||
writer.flush(out, true);
|
||||
}
|
||||
catch (IOException e) {
|
||||
log.error("生成excel文档异常,e: ",e);
|
||||
}
|
||||
finally {
|
||||
writer.close();
|
||||
}
|
||||
IoUtil.close(out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
package com.lz.modules.performance.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: djc
|
||||
* @Desc:
|
||||
* @Date: 2020/12/2 10:15
|
||||
*/
|
||||
@Data
|
||||
public class LevelDetailExportDto {
|
||||
//序号
|
||||
private Long id;
|
||||
//工号
|
||||
private String staffNo;
|
||||
//姓名
|
||||
private String staffName;
|
||||
//员工id
|
||||
private Long staffId;
|
||||
//当月状态
|
||||
private int staffType;
|
||||
//所属部门
|
||||
private Long departmentId;
|
||||
//一级部门
|
||||
private String departmentOne;
|
||||
//二级部门
|
||||
private String departmentTwo;
|
||||
//三级部门
|
||||
private String departmentThree;
|
||||
//职位
|
||||
private String position;
|
||||
//员工月度绩效考核评分
|
||||
private String allScore;
|
||||
//员工月度绩效考核结果等级
|
||||
private String scoreLevel;
|
||||
|
||||
}
|
||||
@ -2,6 +2,8 @@ package com.lz.modules.performance.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: djc
|
||||
* @Desc:
|
||||
@ -13,4 +15,14 @@ public class StaffTypeDto {
|
||||
private int staffType;
|
||||
//员工id
|
||||
private Long staffId;
|
||||
//职位
|
||||
private String position;
|
||||
//人员状态
|
||||
private Long staffStatus;
|
||||
//入职日期
|
||||
private Date entryTime;
|
||||
//转正日期
|
||||
private Date officialTime;
|
||||
//离职时间
|
||||
private Date resignationTime;
|
||||
}
|
||||
|
||||
@ -15,20 +15,16 @@ public class LevelDetailExportRes {
|
||||
private String staffNo;
|
||||
//姓名
|
||||
private String staffName;
|
||||
//员工id
|
||||
private Long staffId;
|
||||
//当月状态
|
||||
private int staffType;
|
||||
//所属部门
|
||||
private Long departmentId;
|
||||
//一级部门
|
||||
private int departmentOne;
|
||||
private String departmentOne;
|
||||
//二级部门
|
||||
private int departmentTwo;
|
||||
private String departmentTwo;
|
||||
//三级部门
|
||||
private int departmentThree;
|
||||
private String departmentThree;
|
||||
//职位
|
||||
private String departmentName;
|
||||
private String position;
|
||||
//员工月度绩效考核评分
|
||||
private String allScore;
|
||||
//员工月度绩效考核结果等级
|
||||
|
||||
@ -12,10 +12,7 @@ import com.lz.common.utils.StringUtil;
|
||||
import com.lz.modules.app.entity.DepartmentsEntity;
|
||||
import com.lz.modules.app.entity.DepartmentsStaffRelateEntity;
|
||||
import com.lz.modules.app.entity.StaffEntity;
|
||||
import com.lz.modules.app.service.DepartmentsService;
|
||||
import com.lz.modules.app.service.DepartmentsStaffRelateService;
|
||||
import com.lz.modules.app.service.StaffOccupationService;
|
||||
import com.lz.modules.app.service.StaffService;
|
||||
import com.lz.modules.app.service.*;
|
||||
import com.lz.modules.flow.dao.EvaluationGroupMapper;
|
||||
import com.lz.modules.flow.dao.FlowChartMapper;
|
||||
import com.lz.modules.flow.dao.FlowStartMapper;
|
||||
@ -24,6 +21,7 @@ import com.lz.modules.flow.entity.FlowStart;
|
||||
import com.lz.modules.flow.service.EvaluationGroupService;
|
||||
import com.lz.modules.flow.service.FlowChartService;
|
||||
import com.lz.modules.flow.service.FlowStartService;
|
||||
import com.lz.modules.performance.dto.LevelDetailExportDto;
|
||||
import com.lz.modules.performance.dto.StaffTypeDto;
|
||||
import com.lz.modules.performance.enums.ResultFlowProcessEnum;
|
||||
import com.lz.modules.performance.req.AssessDetailReq;
|
||||
@ -40,6 +38,8 @@ import com.lz.modules.sys.entity.app.ResultRecord;
|
||||
import com.lz.modules.sys.service.app.ResultRecordService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -80,6 +80,8 @@ public class ChartResultServiceImpl implements ChartResultService {
|
||||
private EvaluationGroupMapper evaluationGroupMapper;
|
||||
@Autowired
|
||||
private StaffOccupationService staffOccupationService;
|
||||
@Autowired
|
||||
private StaffWorkTransferRecordService staffWorkTransferRecordService;
|
||||
|
||||
private static final Long processId = 1L;
|
||||
|
||||
@ -243,18 +245,60 @@ public class ChartResultServiceImpl implements ChartResultService {
|
||||
@Override
|
||||
public List<LevelDetailExportRes> selectLevelDetailList(ChartResultReq req) {
|
||||
List<String> mandepartmentIds = getMandepartmentIds(req.getDepartmentIds(), req.getLoginUserId());
|
||||
List<LevelDetailExportRes> levelDetailExportRes = resultRecordMapper.selectLevelDetailList(mandepartmentIds, req.getStartId(), req.getScoreLevel());
|
||||
List<LevelDetailExportDto> levelDetailExportDtos = resultRecordMapper.selectLevelDetailList(mandepartmentIds, req.getStartId(), req.getScoreLevel());
|
||||
|
||||
if(CollectionUtils.isEmpty(levelDetailExportRes)){
|
||||
if(CollectionUtils.isEmpty(levelDetailExportDtos)){
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
List<Long> staffIds = levelDetailExportRes.stream().map(LevelDetailExportRes::getStaffId).collect(Collectors.toList());
|
||||
List<String> depIds = levelDetailExportRes.stream().map(levelDetailExportRes1 -> levelDetailExportRes1.getDepartmentId().toString()).collect(Collectors.toList());
|
||||
List<Long> staffIds = levelDetailExportDtos.stream().map(LevelDetailExportDto::getStaffId).collect(Collectors.toList());
|
||||
List<String> depIds = levelDetailExportDtos.stream().map(levelDetailExportDto -> levelDetailExportDto.getDepartmentId().toString()).collect(Collectors.toList());
|
||||
|
||||
List<StaffTypeDto> staffTypeDtos = staffOccupationService.selectStaffTypesByStaffIds(staffIds);
|
||||
//状态
|
||||
Map<Long,Integer> types = Maps.newHashMap();
|
||||
//职位
|
||||
Map<Long,String> positions = Maps.newHashMap();
|
||||
|
||||
for(StaffTypeDto dto: staffTypeDtos){
|
||||
types.put(dto.getStaffId(),dto.getStaffType());
|
||||
positions.put(dto.getStaffId(),dto.getPosition());
|
||||
}
|
||||
Map<Long, List<String>> map = departmentsService.selectDepartmentTreeByDepIds(depIds);
|
||||
|
||||
//TODO 整合数据
|
||||
for(LevelDetailExportDto res: levelDetailExportDtos){
|
||||
Integer integer = types.get(res.getStaffId());
|
||||
String position = positions.get(res.getStaffId());
|
||||
if(integer !=null){
|
||||
res.setStaffType(integer);
|
||||
}
|
||||
if(StringUtil.isNotBlank(position)){
|
||||
res.setPosition(position);
|
||||
}
|
||||
List<String> names = map.get(res.getDepartmentId());
|
||||
if(CollectionUtils.isNotEmpty(names)){
|
||||
Collections.reverse(names);
|
||||
int size = names.size();
|
||||
if(size>0 && StringUtils.isNotBlank(names.get(0))){
|
||||
res.setDepartmentOne(names.get(0));
|
||||
}
|
||||
if(size>1 && StringUtils.isNotBlank(names.get(1))){
|
||||
res.setDepartmentTwo(names.get(1));
|
||||
}
|
||||
if(size>2 && StringUtils.isNotBlank(names.get(2))){
|
||||
res.setDepartmentThree(names.get(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 人员变动信息 人员状态
|
||||
//staffWorkTransferRecordService
|
||||
|
||||
//拷贝为excel格式
|
||||
List<LevelDetailExportRes> levelDetailExportRes = levelDetailExportDtos.stream().map(levelDetailExportDto -> {
|
||||
LevelDetailExportRes res = new LevelDetailExportRes();
|
||||
BeanUtils.copyProperties(levelDetailExportDto,res);
|
||||
return res;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
return levelDetailExportRes;
|
||||
|
||||
|
||||
@ -16,6 +16,7 @@ import com.lz.modules.app.req.ReportListReq;
|
||||
import com.lz.modules.app.req.ResultRecordReq;
|
||||
import com.lz.modules.app.resp.OwnResultResp;
|
||||
import com.lz.modules.flow.model.ResultRecordDto;
|
||||
import com.lz.modules.performance.dto.LevelDetailExportDto;
|
||||
import com.lz.modules.performance.dto.ToScoreDingTalkDto;
|
||||
import com.lz.modules.performance.req.AssessDetailReq;
|
||||
import com.lz.modules.performance.req.OwnResultReq;
|
||||
@ -109,7 +110,7 @@ public interface ResultRecordMapper extends BaseMapper<ResultRecord> {
|
||||
|
||||
List<ResultRecord> selectResultRecordsByStartId(Long startId);
|
||||
|
||||
List<LevelDetailExportRes> selectLevelDetailList(@Param("departmentIds") List<String> departmentIds, @Param("startId")Long startId, @Param("scoreLevel")String scoreLevel);
|
||||
List<LevelDetailExportDto> selectLevelDetailList(@Param("departmentIds") List<String> departmentIds, @Param("startId")Long startId, @Param("scoreLevel")String scoreLevel);
|
||||
|
||||
|
||||
}
|
||||
@ -619,7 +619,7 @@
|
||||
and start_id = #{startId}
|
||||
</select>
|
||||
|
||||
<select id="selectLevelDetailList" resultType="com.lz.modules.performance.res.LevelDetailExportRes">
|
||||
<select id="selectLevelDetailList" resultType="com.lz.modules.performance.dto.LevelDetailExportDto">
|
||||
SELECT r.id,all_score,department_id,staff_name,staff_id,score_level,job_number staffNo from lz_result_record r
|
||||
LEFT JOIN lz_staff s
|
||||
on r.staff_id = s.id
|
||||
|
||||
@ -73,8 +73,8 @@
|
||||
</select>
|
||||
|
||||
<select id="selectStaffTypesByStaffIds" resultType="com.lz.modules.performance.dto.StaffTypeDto">
|
||||
select staff_id,staff_type from lz_staff_occupation
|
||||
where is_delete = 0 and staff_status = 0 and
|
||||
select staff_id,staff_type,position,staff_status,entry_time,official_time from lz_staff_occupation
|
||||
where is_delete = 0 and
|
||||
staff_id in
|
||||
<foreach collection="staffIds" item="staff_id" open="(" close=")"
|
||||
separator=",">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user