Commit dbb662f8 authored by nie'hong's avatar nie'hong

完善工时统计

parent be48dd2a
......@@ -19,6 +19,7 @@
<result column="modify_time" property="modifyTime"/>
<result column="business_id" property="businessId"/>
<result column="business_name" property="businessName"/>
<result column="conclusion_time" property="conclusionTime"/>
</resultMap>
<!-- 通用查询结果列 -->
......@@ -132,14 +133,13 @@
from
<include refid="table"/>
<where>
<if test="ids != null">
AND id IN
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</if>
<if test="null !=isConclusion">
<if test="null != isConclusion">
AND is_conclusion = #{isConclusion}
</if>
</where>
......
......@@ -342,6 +342,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取查询结果中的类型
assert workTimeAndCostCollects != null;
List<Integer> typeList = workTimeAndCostCollects.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
if (typeList.size() < workTypes.size()) {
int j;
......@@ -396,8 +397,7 @@ public class StatisticsServiceImpl implements StatisticsService {
PageInfo dayWorkTimeOfMonth = this.getDayWorkTimeOfMonth(param);
// 返回一个“暂无数据”的Excel
if (CollectionUtil.isEmpty(dayWorkTimeOfMonth.getList())) {
HSSFWorkbook sheets = this.creatEmptyHSSFWorkbook();
return sheets;
return this.creatEmptyHSSFWorkbook();
}
Date date = DateUtil.convertStrToDate(param.getYear() + "-" + param.getMonth(), "yyyy-MM");
// 传参的时间当月总天数
......@@ -484,7 +484,7 @@ public class StatisticsServiceImpl implements StatisticsService {
for (int j = 0; j < list.size(); j++) {
HSSFRow row = sheet.getRow(j + 1);
for (int r = 0; r < dayCount; r++) {
HSSFCell cell = null;
HSSFCell cell;
if (row.getCell(r + 3) == null) {
cell = row.createCell(r + 3);
} else {
......@@ -511,7 +511,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 将字符串中的1到9的数字相加
Integer getNumberOfString(String value) {
private Integer getNumberOfString(String value) {
value = value.trim();
if (StringUtil.isEmpty(value)) {
return null;
......@@ -545,7 +545,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 不是中心级不能选择部门,只能查看自己部门的信息
if (!rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank()) && deptId != user.getDeptId()) {
if (!rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank()) && !deptId.equals(user.getDeptId())) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.NO_AUTHORITY);
}
......@@ -759,8 +759,7 @@ public class StatisticsServiceImpl implements StatisticsService {
log.info("StatisticsServiceImpl[]exportUserStatistics[]param{}" + userId + deptId + startDate + endDate);
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsReport = this.getUserWorkTimeStatisticsReport(userId, deptId, startDate, endDate);
if (CollectionUtil.isEmpty(userWorkTimeStatisticsReport)) {
HSSFWorkbook sheets = this.creatEmptyHSSFWorkbook();
return sheets;
return this.creatEmptyHSSFWorkbook();
}
// 部门信息
WorkDept dept = workDeptMapper.getById(deptId);
......@@ -891,27 +890,27 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 合并单元格,第一行
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, row1_lastCellNum + 1);
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, row1_lastCellNum);
sheet1.addMergedRegion(cellRangeAddress);
setBorderStyle(BorderStyle.THIN, cellRangeAddress, sheet1);
setBorderStyle(cellRangeAddress, sheet1);
// 序号
CellRangeAddress cellRangeAddress1 = new CellRangeAddress(1, 2, 0, 0);
sheet1.addMergedRegion(cellRangeAddress1);
setBorderStyle(BorderStyle.THIN, cellRangeAddress1, sheet1);
setBorderStyle(cellRangeAddress1, sheet1);
// 人员
CellRangeAddress cellRangeAddress2 = new CellRangeAddress(1, 2, 1, 1);
sheet1.addMergedRegion(cellRangeAddress2);
setBorderStyle(BorderStyle.THIN, cellRangeAddress2, sheet1);
setBorderStyle(cellRangeAddress2, sheet1);
// 项目名后的合计
short lastCellNum1 = row_1.getLastCellNum();
CellRangeAddress cellRangeAddress6 = new CellRangeAddress(1, 2, lastCellNum1 - 1, lastCellNum1 - 1);
sheet1.addMergedRegion(cellRangeAddress6);
setBorderStyle(BorderStyle.THIN, cellRangeAddress6, sheet1);
setBorderStyle(cellRangeAddress6, sheet1);
// 合计行
CellRangeAddress cellRangeAddress3 = new CellRangeAddress(userWorkTimeStatisticsReport.size() + 1, userWorkTimeStatisticsReport.size() + 1, 0, 1);
sheet1.addMergedRegion(cellRangeAddress3);
setBorderStyle(BorderStyle.THIN, cellRangeAddress3, sheet1);
setBorderStyle(cellRangeAddress3, sheet1);
// 项目行和总计行,正常工时和加班工时表头列数
short lastCellNum = row_2.getLastCellNum();
for (int i = 0; i < lastCellNum / 2; i++) {
......@@ -921,11 +920,11 @@ public class StatisticsServiceImpl implements StatisticsService {
// 总计行
CellRangeAddress cellRangeAddress4 = new CellRangeAddress(userWorkTimeStatisticsReport.size() + 2, userWorkTimeStatisticsReport.size() + 2, i * 2, i * 2 + 1);
sheet1.addMergedRegion(cellRangeAddress4);
setBorderStyle(BorderStyle.THIN, cellRangeAddress4, sheet1);
setBorderStyle(cellRangeAddress4, sheet1);
if (i > 0) {
CellRangeAddress cellRangeAddress5 = new CellRangeAddress(1, 1, i * 2, i * 2 + 1);
sheet1.addMergedRegion(cellRangeAddress5);
setBorderStyle(BorderStyle.THIN, cellRangeAddress5, sheet1);
setBorderStyle(cellRangeAddress5, sheet1);
}
}
// 样式
......@@ -954,7 +953,7 @@ public class StatisticsServiceImpl implements StatisticsService {
public HSSFWorkbook exportProjectStatistics(Integer userId, Integer year, String projectIds) {
log.info("StatisticsServiceImpl[]exportProjectStatistics[]param{}" + userId + year + projectIds);
// 将项目主键解析出来
List<Integer> projectIdList = Arrays.asList(projectIds.split(",")).stream().map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
List<Integer> projectIdList = Arrays.stream(projectIds.split(",")).map(s -> Integer.parseInt(s.trim())).collect(Collectors.toList());
// year为空,为今年
if (year == null) {
year = DateUtil.getYear(new Date());
......@@ -974,22 +973,34 @@ public class StatisticsServiceImpl implements StatisticsService {
// 个人对于项目的贡献
map.replace("isAll", true);
List<ProjectStatisticsByMonth> projectStatisticsByMonths2 = workProjectTimeCostMapper.selectListStatistics(map);
// 所有部门
List<WorkDept> depts = workDeptMapper.getDeptByCondition(null);
// 补齐未查找到数据的项目
List<Integer> projectCollect = projectStatisticsByMonths.stream().map(ProjectStatisticsByMonth::getProjectId).collect(Collectors.toList());
projectIdList.removeAll(projectCollect);
List<WorkProject> projectsByIds = workProjectMapper.getProjectsByIds(projectIdList, null);
for (WorkProject projectsById : projectsByIds) {
ProjectStatisticsByMonth projectStatisticsByMonth = new ProjectStatisticsByMonth();
projectStatisticsByMonth.setProjectId(projectsById.getId());
projectStatisticsByMonth.setProjectName(projectsById.getProjectName());
projectStatisticsByMonth.setStatisticsDateAndWorkTimes(new ArrayList<>());
projectStatisticsByMonths.add(projectStatisticsByMonth);
if (CollectionUtil.isNotEmpty(projectIdList)) {
List<WorkProject> projectsByIds = workProjectMapper.getProjectsByIds(projectIdList, null);
for (WorkProject projectsById : projectsByIds) {
String deptName = "";
for (WorkDept dept : depts) {
if (dept.getId() == projectsById.getDeptId()) {
deptName = dept.getDeptName();
}
}
ProjectStatisticsByMonth projectStatisticsByMonth = new ProjectStatisticsByMonth();
projectStatisticsByMonth.setProjectId(projectsById.getId());
projectStatisticsByMonth.setProjectName(projectsById.getProjectName());
projectStatisticsByMonth.setDeptName(deptName);
projectStatisticsByMonth.setStatisticsDateAndWorkTimes(new ArrayList<>());
projectStatisticsByMonths.add(projectStatisticsByMonth);
}
}
// 如果没有项目统计数据,返回Excel显示暂无数据
if (CollectionUtil.isEmpty(projectStatisticsByMonths)) {
HSSFWorkbook sheets = creatEmptyHSSFWorkbook();
return sheets;
return creatEmptyHSSFWorkbook();
}
// 计算项目合计
this.addProjectStatisticsTotalTime(projectStatisticsByMonths, "合计");
......@@ -1002,6 +1013,8 @@ public class StatisticsServiceImpl implements StatisticsService {
this.conversionDateFormat(projectStatisticsByMonths1, yearMonthList, null, true);
this.conversionDateFormat(projectStatisticsByMonths2, yearMonthList, null, false);
HSSFWorkbook sheets = new HSSFWorkbook();
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
// 项目名作为sheet名
......@@ -1009,11 +1022,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// sheet名不能存在“/”
String s = projectName.replaceAll("/", "_");
HSSFSheet sheet = sheets.createSheet(s);
// 项目无部门下的数据,改sheet页为空白
if (!collect1.contains(projectStatisticsByMonth.getProjectId())) {
sheet.createRow(0).createCell(0).setCellValue("暂无数据");
continue;
}
// 普通样式
HSSFCellStyle ordinaryCellStyle = this.createOrdinaryCellStyle(sheets);
// 将人员所在部门列宽加宽
......@@ -1026,7 +1035,13 @@ public class StatisticsServiceImpl implements StatisticsService {
// 合并第一行的前五个单元格
CellRangeAddress cellRangeAddress2 = new CellRangeAddress(0, 0, 0, 15);
sheet.addMergedRegion(cellRangeAddress2);
setBorderStyle(BorderStyle.THIN, cellRangeAddress2, sheet);
setBorderStyle(cellRangeAddress2, sheet);
// 项目无部门下的数据,改sheet页为空白
if (!collect1.contains(projectStatisticsByMonth.getProjectId())) {
sheet.createRow(1).createCell(0).setCellValue("暂无数据");
continue;
}
// 人员所在部门、序号,一个部门重复一次
for (ProjectStatisticsByMonth statisticsByMonth : projectStatisticsByMonths1) {
......@@ -1068,7 +1083,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 合并合计单元格
CellRangeAddress cellRangeAddress1 = new CellRangeAddress(lastRowNum1 + 1, lastRowNum1 + 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress1);
setBorderStyle(BorderStyle.THIN, cellRangeAddress1, sheet);
setBorderStyle(cellRangeAddress1, sheet);
// 写入部门的工时
this.writeWorkTimeToExcel(statisticsByMonth, row_total, row_last);
}
......@@ -1079,7 +1094,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 合并单元格
CellRangeAddress cellRangeAddress = new CellRangeAddress(lastRowNum1 + 1, lastRowNum1 + 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress);
setBorderStyle(BorderStyle.THIN, cellRangeAddress, sheet);
setBorderStyle(cellRangeAddress, sheet);
// 写入项目的总合计工时
HSSFRow row1 = sheet.getRow(1);
......@@ -1157,14 +1172,14 @@ public class StatisticsServiceImpl implements StatisticsService {
}
//获取用户某月已填报的日期,如果一天中只有被驳回则不为已填报
public List<Date> currentMonthFilledDays(Integer userId, Date date) {
private List<Date> currentMonthFilledDays(Integer userId, Date date) {
log.info("StatisticsServiceImpl[]currentMonthFilledDays[]input.method");
List<Date> currentMonthFilledDays = workTimeOrderMapper.getDaysByDateAndStatus(userId, date);
return currentMonthFilledDays;
}
// 设置单元格基本样式
HSSFCellStyle createOrdinaryCellStyle(HSSFWorkbook sheets) {
private HSSFCellStyle createOrdinaryCellStyle(HSSFWorkbook sheets) {
HSSFCellStyle cellStyle = sheets.createCellStyle();
// cellStyle.setFillBackgroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
cellStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.WHITE.getIndex());
......@@ -1192,7 +1207,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 部门主键不为空时,日期格式只有某月。为空时,日期格式为某年统计的第一个月为某年某月,其余为某月
public void conversionDateFormat(List<ProjectStatisticsByMonth> projectStatisticsByMonths, List<String> yearMonthList, Integer projectId, boolean isTotal) {
private void conversionDateFormat(List<ProjectStatisticsByMonth> projectStatisticsByMonths, List<String> yearMonthList, Integer projectId, boolean isTotal) {
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
for (int i = 0; i < yearMonthList.size(); i++) {
......@@ -1235,17 +1250,16 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取用户权限
public List<String> getUserAuthority(List<UserRoleLevelDto> roleUserLevel) {
private List<String> getUserAuthority(List<UserRoleLevelDto> roleUserLevel) {
if (CollectionUtil.isEmpty(roleUserLevel)) {
return null;
}
// 获取权限名
List<String> collect = roleUserLevel.stream().map(UserRoleLevelDto::getLevelName).collect(Collectors.toList());
return collect;
return roleUserLevel.stream().map(UserRoleLevelDto::getLevelName).collect(Collectors.toList());
}
// 获取用户当前权限对应的级别
public List<Integer> getUserRank(List<UserRoleLevelDto> workLevels, String levelName) {
private List<Integer> getUserRank(List<UserRoleLevelDto> workLevels, String levelName) {
List<Integer> rank = new ArrayList<>();
if (CollectionUtil.isEmpty(workLevels)) {
return rank;
......@@ -1259,7 +1273,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取开始时间到结束时间这个时间段的所有年月集合
List<String> getYearMonthList(String startDate, String endDate) {
private List<String> getYearMonthList(String startDate, String endDate) {
String pattern = "yyyy年M月";
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
List<String> list = new ArrayList<>();
......@@ -1277,22 +1291,21 @@ public class StatisticsServiceImpl implements StatisticsService {
return list;
}
public String simpleDateToYearMonthDay(String simple) {
private String simpleDateToYearMonthDay(String simple) {
String date1 = simple.replaceFirst("-", "年");
String date2 = date1.replaceFirst("-", "月");
String date3 = date2 + "日";
return date3;
return date2 + "日";
}
//合并单元格后添加边框
public static void setBorderStyle(BorderStyle borderStyle, CellRangeAddress region, HSSFSheet sheet) {
RegionUtil.setBorderBottom(borderStyle, region, sheet); //下边框
RegionUtil.setBorderLeft(borderStyle, region, sheet); //左边框
RegionUtil.setBorderRight(borderStyle, region, sheet); //右边框
RegionUtil.setBorderTop(borderStyle, region, sheet); //上边框
private static void setBorderStyle(CellRangeAddress region, HSSFSheet sheet) {
RegionUtil.setBorderBottom(BorderStyle.THIN, region, sheet); //下边框
RegionUtil.setBorderLeft(BorderStyle.THIN, region, sheet); //左边框
RegionUtil.setBorderRight(BorderStyle.THIN, region, sheet); //右边框
RegionUtil.setBorderTop(BorderStyle.THIN, region, sheet); //上边框
}
public void addProjectStatisticsTotalTime(List<ProjectStatisticsByMonth> projectStatisticsByMonths, String statisticsName) {
private void addProjectStatisticsTotalTime(List<ProjectStatisticsByMonth> projectStatisticsByMonths, String statisticsName) {
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
// 一条统计的
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
......@@ -1318,7 +1331,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 写入对应时间的工时
public void writeWorkTimeToExcel(ProjectStatisticsByMonth projectStatisticsByMonth1, HSSFRow row, HSSFRow lastRow) {
private void writeWorkTimeToExcel(ProjectStatisticsByMonth projectStatisticsByMonth1, HSSFRow row, HSSFRow lastRow) {
// 一个人的统计月份与工时
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth1.getStatisticsDateAndWorkTimes();
// 月份匹配,写入工时
......@@ -1331,7 +1344,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
public void closeSheets(HSSFWorkbook sheets) {
private void closeSheets(HSSFWorkbook sheets) {
try {
sheets.close();
} catch (IOException e) {
......@@ -1340,7 +1353,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 返回一个空的Excel
public HSSFWorkbook creatEmptyHSSFWorkbook() {
private HSSFWorkbook creatEmptyHSSFWorkbook() {
HSSFWorkbook sheets = new HSSFWorkbook();
HSSFSheet sheet = sheets.createSheet();
sheet.createRow(0).createCell(0).setCellValue("暂无数据");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment