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

完善工时统计

parent 2df1d160
...@@ -108,8 +108,8 @@ ...@@ -108,8 +108,8 @@
<select id="selectListByMonth" resultMap="projectStatisticsByMonth"> <select id="selectListByMonth" resultMap="projectStatisticsByMonth">
select <if test="projectId == null">'合计' AS project_name,</if> <if test="projectId != null || projectIds != null"> project_name,'合计' AS dept_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,year(statistics_start) AS year, sum(total_time) AS total_time, sum(cost) AS cost select <if test="projectId == null and projectIds == null">'合计' AS project_name,</if> <if test="projectId != null"> project_name, dept_name,</if> <if test=" projectIds != null"> project_name, dept_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,year(statistics_start) AS year, sum(total_time) AS total_time, sum(cost) AS cost
from work_project_time_cost ptc join work_project p on ptc.project_id = p.id join work_dept d on ptc.dept_id = d.id from work_project_time_cost ptc join work_project p on ptc.project_id = p.id join work_dept d on p.dept_id = d.id
<where> <where>
<if test="projectId != null "> <if test="projectId != null ">
ptc.project_id = #{projectId} ptc.project_id = #{projectId}
...@@ -131,13 +131,13 @@ ...@@ -131,13 +131,13 @@
AND p.manager_id = #{managerId} AND year(statistics_start) = #{year} AND p.manager_id = #{managerId} AND year(statistics_start) = #{year}
</if> </if>
</where> </where>
group by <if test="projectId != null"> project_name,</if> year(statistics_start),MONTH(statistics_start) group by <if test="projectId != null and projectIds == null"> project_name,</if> <if test="projectId == null and projectIds != null"> project_name,dept_name,</if>year(statistics_start),MONTH(statistics_start)
</select> </select>
<select id="selectListStatistics" resultMap="projectStatisticsByMonth"> <select id="selectListStatistics" resultMap="projectStatisticsByMonth">
select ptc.project_id AS project_id, project_name, select ptc.project_id AS project_id, project_name,
group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,year(statistics_start) AS year, group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date,year(statistics_start) AS year,
sum(total_time) AS total_time, sum(cost) AS cost <if test="projectId != null "> ,d.dept_name AS dept_name</if> <if test="projectIds != null">,d.dept_name AS dept_name,u.name </if> sum(total_time) AS total_time, sum(cost) AS cost <if test="projectId != null || (projectIds != null and !isAll)"> ,d.dept_name AS dept_name</if> <if test="projectIds != null and isAll">,d.dept_name AS dept_name,u.name AS user_name </if>
from work_project_time_cost ptc join work_project p on ptc.project_id = p.id join work_dept d on ptc.dept_id = d.id join work_user u on ptc.user_id = u.id from work_project_time_cost ptc join work_project p on ptc.project_id = p.id join work_dept d on ptc.dept_id = d.id join work_user u on ptc.user_id = u.id
<where> <where>
<if test="projectId != null "> <if test="projectId != null ">
...@@ -148,6 +148,7 @@ ...@@ -148,6 +148,7 @@
<foreach collection="projectIds" open="(" close=")" separator="," item="projectId"> <foreach collection="projectIds" open="(" close=")" separator="," item="projectId">
#{projectId} #{projectId}
</foreach> </foreach>
AND year(statistics_start) = #{year}
</if> </if>
<if test="deptId != null and managerId == null"> <if test="deptId != null and managerId == null">
AND p.dept_id = #{deptId} AND year(statistics_start) = #{year} AND p.dept_id = #{deptId} AND year(statistics_start) = #{year}
...@@ -159,7 +160,7 @@ ...@@ -159,7 +160,7 @@
AND p.manager_id = #{managerId} AND year(statistics_start) = #{year} AND p.manager_id = #{managerId} AND year(statistics_start) = #{year}
</if> </if>
</where> </where>
group by ptc.project_id,project_name,year(statistics_start),MONTH(statistics_start) <if test="projectId != null "> ,d.dept_name</if> <if test="projectIds != null">,d.dept_name AS dept_name,u.name </if> group by ptc.project_id,project_name,year(statistics_start),MONTH(statistics_start) <if test="projectId != null || (projectIds != null and !isAll) "> ,d.dept_name</if> <if test="projectIds != null and isAll">,d.dept_name ,u.name </if>
</select> </select>
......
...@@ -17,7 +17,9 @@ import com.alibaba.excel.util.StringUtils; ...@@ -17,7 +17,9 @@ import com.alibaba.excel.util.StringUtils;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import com.github.pagehelper.util.StringUtil; import com.github.pagehelper.util.StringUtil;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.usermodel.*;
...@@ -25,7 +27,6 @@ import org.apache.poi.ss.util.CellRangeAddress; ...@@ -25,7 +27,6 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.ss.util.RegionUtil; import org.apache.poi.ss.util.RegionUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
...@@ -504,6 +505,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -504,6 +505,7 @@ public class StatisticsServiceImpl implements StatisticsService {
return sum; return sum;
} }
@SneakyThrows
@Override @Override
public List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) { public List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate) {
log.info("StatisticsServiceImpl[]getUserWorkTimeStatisticsReport[]" + userId + deptId + startDate + endDate); log.info("StatisticsServiceImpl[]getUserWorkTimeStatisticsReport[]" + userId + deptId + startDate + endDate);
...@@ -542,17 +544,16 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -542,17 +544,16 @@ public class StatisticsServiceImpl implements StatisticsService {
// 存各个项目下所有人的加班工时和平常工时 // 存各个项目下所有人的加班工时和平常工时
List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics1; List<UserWorkTimeStatisticsByProject> userProjectWorkTimeStatistics1;
// 查询项目
List<WorkProject> projects = workProjectMapper.getListByCriteria(map);
// 所有项目的统计 // 所有项目的统计
map.put("isAll", false); map.put("isAll", false);
userProjectWorkTimeStatistics = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map); userProjectWorkTimeStatistics = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map);
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject = new UserWorkTimeStatisticsByProject();
List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = new ArrayList<>(); // 拷贝属性
userWorkTimeStatisticsByProjects.addAll(userProjectWorkTimeStatistics); BeanUtils.copyProperties(userWorkTimeStatisticsByProject, userProjectWorkTimeStatistics.get(0));
userWorkTimeStatisticsByProjects.get(0).setUserName("总计"); // 总计
userWorkTimeStatisticsByProject.setUserName("总计");
userProjectWorkTimeStatistics.addAll(userWorkTimeStatisticsByProjects); // 将合计和总计
userProjectWorkTimeStatistics.add(userWorkTimeStatisticsByProject);
// 所有项目下所有人员的统计 // 所有项目下所有人员的统计
map.replace("isAll", true); map.replace("isAll", true);
userProjectWorkTimeStatistics1 = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map); userProjectWorkTimeStatistics1 = workTimeOrderMapper.getUserProjectWorkTimeStatistics(map);
...@@ -572,92 +573,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -572,92 +573,6 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
} }
// 查询结果为空,新建一个“合计”对象添加到集合
if (CollectionUtils.isEmpty(userProjectWorkTimeStatistics)) {
List<ProjectWorkTimeAndType> projectWorkTimeAndTypes = new ArrayList<>();
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject = new UserWorkTimeStatisticsByProject();
userWorkTimeStatisticsByProject.setUserName("合计");
userWorkTimeStatisticsByProject.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
userProjectWorkTimeStatistics.add(userWorkTimeStatisticsByProject);
}
// // 查询除开项目于、商机、请假、调休这几种类型的工单
//
// List<Integer> queryType = new ArrayList<>();
// for (WorkType type : types) {
// if (type.getId() > 4) {
// queryType.add(type.getId());
// }
// }
//
// // 部门级别以上的用户可以查询所管理项目的成员所填的其他类型的工单
// if (rank.contains(LevelRankEnum.DEPARTMENT_LEVEL.getRank()) || rank.contains(LevelRankEnum.CENTRAL_LEVEL.getRank())) {
// // 获取其他类型统计信息
// map.replace("isAll", false);
// map.put("queryType", queryType);
// List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjectList = workTimeOrderMapper.selectListByType(map);
// log.info(new Date().getTime() + "");
// // 获取查询结果的类型
// List<Integer> collect = new ArrayList<>();
// if (CollectionUtil.isNotEmpty(userWorkTimeStatisticsByProjectList)) {
// UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsByProjectList.get(0);
// List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType();
// for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
// projectWorkTimeAndType.setProjectName(types.get(projectWorkTimeAndType.getProjectType() - 1).getName());
// }
// collect = projectWorkTimeAndType1.stream().map(ProjectWorkTimeAndType::getProjectType).collect(Collectors.toList());
// }
//
// // 缺少类型,造对象传前端
// UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = new UserWorkTimeStatisticsByProject();
// List<ProjectWorkTimeAndType> projectWorkTimeAndTypes = new ArrayList<>();
// for (int i = 4; i < types.size(); i++) {
// if (!collect.contains(types.get(i).getId())) {
// ProjectWorkTimeAndType projectWorkTimeAndType = new ProjectWorkTimeAndType();
// projectWorkTimeAndType.setNormalTime(0);
// projectWorkTimeAndType.setOverTime(0);
// projectWorkTimeAndType.setProjectType(types.get(i).getId());
// projectWorkTimeAndType.setProjectName(types.get(i).getName());
// projectWorkTimeAndTypes.add(projectWorkTimeAndType);
// }
// }
// userWorkTimeStatisticsByProject1.setProjectWorkTimeAndType(projectWorkTimeAndTypes);
// userWorkTimeStatisticsByProjectList.add(userWorkTimeStatisticsByProject1);
//
// // 将项目和商机统计信息和除开项目、商机、请假、调休类型的其他类型统计信息合并
// userProjectWorkTimeStatistics.get(0).getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProjectList.get(0).getProjectWorkTimeAndType());
//
// // 查询各个项目下所有人的其他除了项目、商机、请假、调休类型的加班工时和平常工时
// map.replace("isAll", true);
// List<UserWorkTimeStatisticsByProject> userWorkTimeStatisticsByProjects = workTimeOrderMapper.selectListByType(map);
// log.info(new Date().getTime() + "");
// for (UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject : userWorkTimeStatisticsByProjects) {
// if (!userProjectWorkTimeStatistics1.contains(userWorkTimeStatisticsByProject)) {
// UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject2 = new UserWorkTimeStatisticsByProject();
// userWorkTimeStatisticsByProject2.setUserName(userWorkTimeStatisticsByProject.getUserName());
// userWorkTimeStatisticsByProject2.setUserId(userWorkTimeStatisticsByProject.getUserId());
// List<ProjectWorkTimeAndType> projectWorkTimeAndTypes1 = new ArrayList<>();
// userWorkTimeStatisticsByProject2.setProjectWorkTimeAndType(projectWorkTimeAndTypes1);
// userProjectWorkTimeStatistics1.add(userWorkTimeStatisticsByProject2);
// }
// for (UserWorkTimeStatisticsByProject workTimeStatisticsByProject : userProjectWorkTimeStatistics1) {
// if (userWorkTimeStatisticsByProject.getUserId() != null && userWorkTimeStatisticsByProject.getUserId().equals(workTimeStatisticsByProject.getUserId())) {
// workTimeStatisticsByProject.getProjectWorkTimeAndType().addAll(userWorkTimeStatisticsByProject.getProjectWorkTimeAndType());
// }
// }
// }
// // 赋值类型名称
// for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userWorkTimeStatisticsByProjects) {
// List<ProjectWorkTimeAndType> projectWorkTimeAndType = userProjectWorkTimeStatistic.getProjectWorkTimeAndType();
// for (ProjectWorkTimeAndType workTimeAndType : projectWorkTimeAndType) {
// workTimeAndType.setProjectName(types.get(workTimeAndType.getProjectType() - 1).getName());
// }
// }
// }
//
// userProjectWorkTimeStatistics.addAll(0, userProjectWorkTimeStatistics1);
// 取出单人的项目工时统计 // 取出单人的项目工时统计
for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userProjectWorkTimeStatistics) { for (UserWorkTimeStatisticsByProject userProjectWorkTimeStatistic : userProjectWorkTimeStatistics) {
int totalTime = 0; int totalTime = 0;
...@@ -805,24 +720,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -805,24 +720,7 @@ public class StatisticsServiceImpl implements StatisticsService {
this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, projectId); this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, projectId);
// 计算项目工时和成本合计 // 计算项目工时和成本合计
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) { this.addProjectStisticsTotalTime(projectStatisticsByMonths, "项目合计");
// 一条统计的
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
// 项目合计对象
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime1 = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime1.setDate("项目合计");
BigDecimal totalTime = new BigDecimal("0.000");
BigDecimal cost = new BigDecimal("0.000");
// 统计项目工时和成本
for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
totalTime = totalTime.add(statisticsDateAndWorkTime.getTotalTime());
cost = cost.add(statisticsDateAndWorkTime.getCost());
}
// 项目合计对象赋值
statisticsDateAndWorkTime1.setTotalTime(totalTime);
statisticsDateAndWorkTime1.setCost(cost);
statisticsDateAndWorkTimes.add(statisticsDateAndWorkTime1);
}
return projectStatisticsByMonths; return projectStatisticsByMonths;
} }
...@@ -856,10 +754,10 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -856,10 +754,10 @@ public class StatisticsServiceImpl implements StatisticsService {
row_1Cell2.setCellValue("人员"); row_1Cell2.setCellValue("人员");
// 合计行 // 合计行
HSSFRow totalRow1 = sheet1.createRow(userWorkTimeStatisticsReport.size() + 2); HSSFRow totalRow1 = sheet1.createRow(userWorkTimeStatisticsReport.size() + 1);
totalRow1.createCell(0).setCellValue("合计"); totalRow1.createCell(0).setCellValue("合计");
// 总计 // 总计
HSSFRow totalRow2 = sheet1.createRow(userWorkTimeStatisticsReport.size() + 3); HSSFRow totalRow2 = sheet1.createRow(userWorkTimeStatisticsReport.size() + 2);
totalRow2.createCell(0).setCellValue("总计"); totalRow2.createCell(0).setCellValue("总计");
// 项目行 // 项目行
HSSFRow row_2 = sheet1.createRow(2); HSSFRow row_2 = sheet1.createRow(2);
...@@ -867,7 +765,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -867,7 +765,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 项目名称 // 项目名称
HSSFCell row_1Cell; HSSFCell row_1Cell;
HSSFCell totalRow2Cell; HSSFCell totalRow2Cell;
if (i < projectWorkTimeAndType.size() - 2) { if (!"请假".equals(projectWorkTimeAndType.get(i).getProjectName()) && !"调休".equals(projectWorkTimeAndType.get(i).getProjectName())) {
// 项目名称或类型名称 // 项目名称或类型名称
row_1Cell = row_1.createCell((i + 1) * 2); row_1Cell = row_1.createCell((i + 1) * 2);
totalRow2Cell = totalRow2.createCell((i + 1) * 2); totalRow2Cell = totalRow2.createCell((i + 1) * 2);
...@@ -915,10 +813,15 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -915,10 +813,15 @@ public class StatisticsServiceImpl implements StatisticsService {
totalRow2Cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime()); totalRow2Cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime());
} }
// 所有项目的合计 // 所有项目的合计
String lastProjectName = projectWorkTimeAndType.get(projectWorkTimeAndType.size() - 1).getProjectName();
short row1_lastCellNum = row_1.getLastCellNum(); short row1_lastCellNum = row_1.getLastCellNum();
row_1.createCell(row1_lastCellNum).setCellValue("合计"); if (lastProjectName.equals("请假") || lastProjectName.equals("调休")) {
row_1.createCell(row1_lastCellNum).setCellValue("合计");
} else {
row_1.createCell(row1_lastCellNum + 1).setCellValue("合计");
}
for (int i = 0; i < userWorkTimeStatisticsReport.size() - 1; i++) { for (int i = 0; i < userWorkTimeStatisticsReport.size() - 2; i++) {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsReport.get(i); UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsReport.get(i);
List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType(); List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType();
HSSFRow row_i = sheet1.createRow(i + 3); HSSFRow row_i = sheet1.createRow(i + 3);
...@@ -931,7 +834,8 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -931,7 +834,8 @@ public class StatisticsServiceImpl implements StatisticsService {
// 项目的工时 // 项目的工时
for (int j = 0; j < projectWorkTimeAndType1.size(); j++) { for (int j = 0; j < projectWorkTimeAndType1.size(); j++) {
for (int k = 2; k < row1_lastCellNum; k++) { for (int k = 2; k < row1_lastCellNum; k++) {
if (row_1.getCell(k) != null && k < row1_lastCellNum - 2 && projectWorkTimeAndType1.get(j).getProjectName().equals(row_1.getCell(k).getStringCellValue())) { // 除开请假和调休
if (row_1.getCell(k) != null && !projectWorkTimeAndType1.get(j).getProjectName().equals("请假") && !projectWorkTimeAndType1.get(j).getProjectName().equals("调休") && projectWorkTimeAndType1.get(j).getProjectName().equals(row_1.getCell(k).getStringCellValue())) {
if (projectWorkTimeAndType1.get(j).getNormalTime() != null) { if (projectWorkTimeAndType1.get(j).getNormalTime() != null) {
HSSFCell cell_k_1 = row_i.createCell(k); HSSFCell cell_k_1 = row_i.createCell(k);
cell_k_1.setCellValue(projectWorkTimeAndType1.get(j).getNormalTime()); cell_k_1.setCellValue(projectWorkTimeAndType1.get(j).getNormalTime());
...@@ -942,7 +846,7 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -942,7 +846,7 @@ public class StatisticsServiceImpl implements StatisticsService {
} }
break; break;
} }
if (row_1.getCell(k) != null && k >= row1_lastCellNum - 2 && projectWorkTimeAndType1.get(j).getProjectName().equals(row_1.getCell(k).getStringCellValue())) { if (row_1.getCell(k) != null && projectWorkTimeAndType1.get(j).getProjectName().equals(row_1.getCell(k).getStringCellValue())) {
if (projectWorkTimeAndType1.get(j).getNormalTime() != null) { if (projectWorkTimeAndType1.get(j).getNormalTime() != null) {
HSSFCell cell_k_1 = row_i.createCell(k); HSSFCell cell_k_1 = row_i.createCell(k);
cell_k_1.setCellValue(projectWorkTimeAndType1.get(j).getNormalTime()); cell_k_1.setCellValue(projectWorkTimeAndType1.get(j).getNormalTime());
...@@ -955,48 +859,6 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -955,48 +859,6 @@ public class StatisticsServiceImpl implements StatisticsService {
row_i.createCell(row1_lastCellNum).setCellValue(userWorkTimeStatisticsByProject1.getTotalTime()); row_i.createCell(row1_lastCellNum).setCellValue(userWorkTimeStatisticsByProject1.getTotalTime());
} }
// 合计行
// int lastRowNum = sheet1.getLastRowNum();
// HSSFRow lastRow = sheet1.createRow(lastRowNum + 1);
// lastRow.createCell(0).setCellValue("合计");
// // 总计行
// HSSFRow row = sheet1.createRow(lastRowNum + 2);
// row.createCell(0).setCellValue("总计");
// for (int i = 0; i < projectWorkTimeAndType.size(); i++) {
// // 合计行的正常工时和加班工时
// if (i < projectWorkTimeAndType.size() - 2) {
// HSSFCell cell_i_2 = lastRow.createCell((i + 1) * 2 + 1);
// cell_i_2.setCellValue(projectWorkTimeAndType.get(i).getOverTime());
//
// HSSFCell cell_i_1 = lastRow.createCell((i + 1) * 2);
// cell_i_1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
//
// // 总计行一个项目的总工时
// HSSFCell cell = row.createCell((i + 1) * 2);
// cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime());
// } else {
// // 合计行的请假调休
// HSSFCell cell_i_1 = lastRow.createCell((i + 1) * 2 - 1);
// cell_i_1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
//
// // 总计行请假调休的总工时
// HSSFCell cell = row.createCell((i + 1) * 2 - 1);
// cell.setCellValue(projectWorkTimeAndType.get(i).getTotalTime());
// }
//
// }
// // 合计行的最后一列是所有项目的合计
// short lastRowLastCellNum = lastRow.getLastCellNum();
// // 合计行和总计行的最后一列
// HSSFCell lastRowLastCell = lastRow.createCell(lastRowLastCellNum);
// HSSFCell cell = row.createCell(lastRowLastCellNum);
// // 合计行和总计行的合计都是所有项目的合计工时
// lastRowLastCell.setCellValue(userWorkTimeStatisticsByProject.getTotalTime());
// cell.setCellValue(userWorkTimeStatisticsByProject.getTotalTime());
// 合并单元格,第一行 // 合并单元格,第一行
CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, row1_lastCellNum + 1); CellRangeAddress cellRangeAddress = new CellRangeAddress(0, 0, 0, row1_lastCellNum + 1);
sheet1.addMergedRegion(cellRangeAddress); sheet1.addMergedRegion(cellRangeAddress);
...@@ -1048,8 +910,107 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1048,8 +910,107 @@ public class StatisticsServiceImpl implements StatisticsService {
map.put("year", year); map.put("year", year);
map.put("projectIds", projectIds); map.put("projectIds", projectIds);
List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map); List<ProjectStatisticsByMonth> projectStatisticsByMonths = workProjectTimeCostMapper.selectListByMonth(map);
// workProjectTimeCostMapper.projectStatisticsByMonth(); map.put("isAll", false);
return null; List<ProjectStatisticsByMonth> projectStatisticsByMonths1 = workProjectTimeCostMapper.selectListStatistics(map);
map.replace("isAll", true);
List<ProjectStatisticsByMonth> projectStatisticsByMonths2 = workProjectTimeCostMapper.selectListStatistics(map);
// 计算项目合计
this.addProjectStisticsTotalTime(projectStatisticsByMonths, "合计");
this.addProjectStisticsTotalTime(projectStatisticsByMonths1, "合计");
this.addProjectStisticsTotalTime(projectStatisticsByMonths2, "合计");
List<String> yearMonthList = this.getYearMonthList(year + "年1月", year + "年12月");
// 转换日期格式,由yyyy年M月>M月
this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, null);
this.conversionDateFormat(projectStatisticsByMonths1, yearMonthList, null);
this.conversionDateFormat(projectStatisticsByMonths2, yearMonthList, null);
HSSFWorkbook sheets = new HSSFWorkbook();
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
// 项目名作为sheet名
String projectName = projectStatisticsByMonth.getProjectName();
HSSFSheet sheet = sheets.createSheet(projectName);
// 普通样式
HSSFCellStyle ordinaryCellStyle = this.createOrdinaryCellStyle(sheets);
// 将人员所在部门列宽加宽
sheet.setColumnWidth(0, EXCEL_WIDTH);
// 第一行,部门、项目、时间
String deptName = projectStatisticsByMonth.getDeptName();
String date = year + "年";
HSSFRow row_0 = sheet.createRow(0);
row_0.createCell(0).setCellValue("部门:" + deptName + " 项目:" + projectName + " 时间:" + date);
// 合并第一行的前五个单元格
CellRangeAddress cellRangeAddress2 = new CellRangeAddress(0, 0, 0, 4);
sheet.addMergedRegion(cellRangeAddress2);
setBorderStyle(BorderStyle.THIN, cellRangeAddress2, sheet);
// 人员所在部门、序号,一个部门重复一次
for (ProjectStatisticsByMonth statisticsByMonth : projectStatisticsByMonths1) {
if (!statisticsByMonth.getProjectName().equals(projectName)) {
continue;
}
// 参与项目的其中一个部门
String deptName1 = statisticsByMonth.getDeptName();
int lastRowNum = sheet.getLastRowNum();
HSSFRow row_last = sheet.createRow(lastRowNum + 1);
// 部门的表头
row_last.createCell(0).setCellValue("人员所在部门");
row_last.createCell(1).setCellValue("序号");
row_last.createCell(2).setCellValue("人员");
for (int i = 0; i < 12; i++) {
row_last.createCell(i + 3).setCellValue(i + 1 + "月");
}
row_last.createCell(15).setCellValue("合计");
// 部门下的人员的统计
for (int i = 0, k = 0; i < projectStatisticsByMonths2.size(); i++) {
ProjectStatisticsByMonth projectStatisticsByMonth1 = projectStatisticsByMonths2.get(i);
if (projectStatisticsByMonth1.getDeptName().equals(deptName1) && projectStatisticsByMonth1.getProjectName().equals(projectName)) {
k++;
int lastRowNum1 = sheet.getLastRowNum();
HSSFRow row = sheet.createRow(lastRowNum1 + 1);
// 写入人员所在部门、序号、姓名内容
row.createCell(0).setCellValue(projectStatisticsByMonth1.getDeptName());
row.createCell(1).setCellValue(k);
row.createCell(2).setCellValue(projectStatisticsByMonth1.getUserName());
// 一个人的统计月份与工时
this.writeWorkTimeToExcel(projectStatisticsByMonth1, row, row_last);
}
}
// 一个部门的合计
int lastRowNum1 = sheet.getLastRowNum();
HSSFRow row_total = sheet.createRow(lastRowNum1 + 1);
row_total.createCell(0).setCellValue("合计");
// 合并合计单元格
CellRangeAddress cellRangeAddress1 = new CellRangeAddress(lastRowNum1 + 1, lastRowNum1 + 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress1);
setBorderStyle(BorderStyle.THIN, cellRangeAddress1, sheet);
// 写入部门的工时
this.writeWorkTimeToExcel(statisticsByMonth, row_total, row_last);
}
// 一个项目的总计
int lastRowNum1 = sheet.getLastRowNum();
HSSFRow row = sheet.createRow(lastRowNum1 + 1);
row.createCell(0).setCellValue("总合计");
// 合并单元格
CellRangeAddress cellRangeAddress = new CellRangeAddress(lastRowNum1 + 1, lastRowNum1 + 1, 0, 2);
sheet.addMergedRegion(cellRangeAddress);
setBorderStyle(BorderStyle.THIN, cellRangeAddress, sheet);
// 写入项目的总合计工时
HSSFRow row1 = sheet.getRow(1);
this.writeWorkTimeToExcel(projectStatisticsByMonth, row, row1);
for (Row cells : sheet) {
for (Cell cell : cells) {
cell.setCellStyle(ordinaryCellStyle);
}
}
}
return sheets;
} }
//获取一个月应上班日期,如果是当月,时间截至到当天 //获取一个月应上班日期,如果是当月,时间截至到当天
...@@ -1062,10 +1023,10 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1062,10 +1023,10 @@ public class StatisticsServiceImpl implements StatisticsService {
Date now = new Date(); Date now = new Date();
if (DateUtil.getYear(date) == DateUtil.getYear(now) && DateUtil.getMonth(date) == DateUtil.getMonth(now) && toToday) { if (DateUtil.getYear(date) == DateUtil.getYear(now) && DateUtil.getMonth(date) == DateUtil.getMonth(now) && toToday) {
endDate = DateUtil.getStartOfDay(now); endDate = DateUtil.getStartOfDay(now);
System.out.println("endDate1 = " + DateUtils.dateToStringWithPattern(endDate,"yyyy-MM-dd")); System.out.println("endDate1 = " + DateUtils.dateToStringWithPattern(endDate, "yyyy-MM-dd"));
} else { } else {
endDate = DateUtil.getLastDayByMonth2(date); endDate = DateUtil.getLastDayByMonth2(date);
System.out.println("endDate2 = " +DateUtils.dateToStringWithPattern(endDate,"yyyy-MM-dd")); System.out.println("endDate2 = " + DateUtils.dateToStringWithPattern(endDate, "yyyy-MM-dd"));
} }
// 当月月第一天到截止时间的日期集合 // 当月月第一天到截止时间的日期集合
List<Date> workDays = DateUtil.getDatesBetweenTwoDate(startDate, endDate); List<Date> workDays = DateUtil.getDatesBetweenTwoDate(startDate, endDate);
...@@ -1151,15 +1112,13 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1151,15 +1112,13 @@ public class StatisticsServiceImpl implements StatisticsService {
date = statisticsDateAndWorkTimes.get(i).getDate(); date = statisticsDateAndWorkTimes.get(i).getDate();
} }
// 项目统计报表中截至当前月份中如果某个月份没有统计数据,补充当月工时为0 // 项目统计报表中截至当前月份中如果某个月份没有统计数据,补充当月工时为0
// else { else {
// break; break;
// } }
// 时间不连续,创建对象 // 时间不连续,创建对象
if (!s.equals(date)) { if (!s.equals(date)) {
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime(); ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime.setDate(s); statisticsDateAndWorkTime.setDate(s);
statisticsDateAndWorkTime.setTotalTime(new BigDecimal("0"));
statisticsDateAndWorkTime.setCost(new BigDecimal("0"));
statisticsDateAndWorkTime.setYear(Integer.valueOf(s.substring(0, 4))); statisticsDateAndWorkTime.setYear(Integer.valueOf(s.substring(0, 4)));
statisticsDateAndWorkTimes.add(i, statisticsDateAndWorkTime); statisticsDateAndWorkTimes.add(i, statisticsDateAndWorkTime);
} }
...@@ -1243,4 +1202,43 @@ public class StatisticsServiceImpl implements StatisticsService { ...@@ -1243,4 +1202,43 @@ public class StatisticsServiceImpl implements StatisticsService {
RegionUtil.setBorderTop(borderStyle, region, sheet); //上边框 RegionUtil.setBorderTop(borderStyle, region, sheet); //上边框
} }
public void addProjectStisticsTotalTime(List<ProjectStatisticsByMonth> projectStatisticsByMonths, String statisticsName) {
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
// 一条统计的
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
// 项目合计对象
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime1 = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime1.setDate(statisticsName);
BigDecimal totalTime = new BigDecimal("0.000");
BigDecimal cost = new BigDecimal("0.000");
// 统计项目工时和成本
for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
if (statisticsDateAndWorkTime.getTotalTime() != null) {
totalTime = totalTime.add(statisticsDateAndWorkTime.getTotalTime());
}
if (statisticsDateAndWorkTime.getCost() != null) {
cost = cost.add(statisticsDateAndWorkTime.getCost());
}
}
// 项目合计对象赋值
statisticsDateAndWorkTime1.setTotalTime(totalTime);
statisticsDateAndWorkTime1.setCost(cost);
statisticsDateAndWorkTimes.add(statisticsDateAndWorkTime1);
}
}
// 写入对应时间的工时
public void writeWorkTimeToExcel(ProjectStatisticsByMonth projectStatisticsByMonth1, HSSFRow row, HSSFRow lastRow) {
// 一个人的统计月份与工时
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth1.getStatisticsDateAndWorkTimes();
// 月份匹配,写入工时
for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
for (int j = 3; j < 16; j++) {
if (statisticsDateAndWorkTime.getDate().equals(lastRow.getCell(j).getStringCellValue()) && statisticsDateAndWorkTime.getTotalTime() != null) {
row.createCell(j).setCellValue(Double.valueOf(statisticsDateAndWorkTime.getTotalTime().stripTrailingZeros().toPlainString()));
}
}
}
}
} }
...@@ -12,14 +12,14 @@ import cn.wisenergy.service.StatisticsService; ...@@ -12,14 +12,14 @@ import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkDeptService; import cn.wisenergy.service.WorkDeptService;
import cn.wisenergy.web.admin.controller.common.BaseController; import cn.wisenergy.web.admin.controller.common.BaseController;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder; import java.net.URLEncoder;
...@@ -156,11 +156,9 @@ public class StatisticsController extends BaseController { ...@@ -156,11 +156,9 @@ public class StatisticsController extends BaseController {
} }
} }
@ApiOperation(value = "导出项目工时统计", notes = "导出项目工时统计")
// @ApiImplicitParams({@ApiImplicitParam(name = "userId",value = "用户主键"),
// @ApiImplicitParam(name = "projectIds",value = "项目主键集合",allowMultiple = true)})
@GetMapping("/exportProjectStatistics") @GetMapping("/exportProjectStatistics")
public void exportProjectStatistics(Integer userId, Integer year, @ApiParam("projectIds") List<Integer> projectIds, HttpServletResponse response) { public void exportProjectStatistics(Integer userId, Integer year, @RequestParam("projectIds") List<Integer> projectIds, HttpServletResponse response) {
log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + year + projectIds); log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + year + projectIds);
// 获取excel // 获取excel
HSSFWorkbook sheets = statisticsService.exportProjectStatistics(userId, year, projectIds); HSSFWorkbook sheets = statisticsService.exportProjectStatistics(userId, year, projectIds);
......
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