Commit 8366cd02 authored by nie'hong's avatar nie'hong

完善工时统计

parent f7f2c246
......@@ -50,7 +50,8 @@ public interface StatisticsService {
*
* @param startDate
* @param endDate
* @param isConclusion
* @param userId
* @param deptId
* @return
*/
List<UserWorkTimeStatisticsByProject> getUserWorkTimeStatisticsReport(Integer userId, Integer deptId, String startDate, String endDate);
......
......@@ -698,8 +698,7 @@ public class StatisticsServiceImpl implements StatisticsService {
}
}
}
// 将查询结果封装在一起
projectStatisticsByMonths.addAll(0, projectStatisticsByMonths1);
String startDate = "";
String endDate = "";
......@@ -720,10 +719,14 @@ public class StatisticsServiceImpl implements StatisticsService {
List<String> yearMonthList = this.getYearMonthList(startDate, endDate);
// 部门主键不为空时,日期格式只有某月。为空时,日期格式为某年统计的第一个月为某年某月,其余为某月
this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, projectId);
this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, projectId, true);
this.conversionDateFormat(projectStatisticsByMonths1, yearMonthList, projectId, false);
// 将查询结果封装在一起
projectStatisticsByMonths.addAll(0, projectStatisticsByMonths1);
// 计算项目工时和成本合计
this.addProjectStisticsTotalTime(projectStatisticsByMonths, "项目合计");
this.addProjectStatisticsTotalTime(projectStatisticsByMonths, "项目合计");
return projectStatisticsByMonths;
}
......@@ -921,15 +924,15 @@ public class StatisticsServiceImpl implements StatisticsService {
map.replace("isAll", true);
List<ProjectStatisticsByMonth> projectStatisticsByMonths2 = workProjectTimeCostMapper.selectListStatistics(map);
// 计算项目合计
this.addProjectStisticsTotalTime(projectStatisticsByMonths, "合计");
this.addProjectStisticsTotalTime(projectStatisticsByMonths1, "合计");
this.addProjectStisticsTotalTime(projectStatisticsByMonths2, "合计");
this.addProjectStatisticsTotalTime(projectStatisticsByMonths, "合计");
this.addProjectStatisticsTotalTime(projectStatisticsByMonths1, "合计");
this.addProjectStatisticsTotalTime(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);
this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, null, true);
this.conversionDateFormat(projectStatisticsByMonths1, yearMonthList, null, true);
this.conversionDateFormat(projectStatisticsByMonths2, yearMonthList, null, false);
HSSFWorkbook sheets = new HSSFWorkbook();
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
......@@ -1110,7 +1113,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// 部门主键不为空时,日期格式只有某月。为空时,日期格式为某年统计的第一个月为某年某月,其余为某月
public void conversionDateFormat(List<ProjectStatisticsByMonth> projectStatisticsByMonths, List<String> yearMonthList, Integer projectId) {
public 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++) {
......@@ -1118,9 +1121,7 @@ public class StatisticsServiceImpl implements StatisticsService {
String date = new String();
if (i < statisticsDateAndWorkTimes.size()) {
date = statisticsDateAndWorkTimes.get(i).getDate();
}
// 项目统计报表中截至当前月份中如果某个月份没有统计数据,补充当月工时为0
else {
}else {
break;
}
// 时间不连续,创建对象
......@@ -1128,6 +1129,10 @@ public class StatisticsServiceImpl implements StatisticsService {
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime.setDate(s);
statisticsDateAndWorkTime.setYear(Integer.valueOf(s.substring(0, 4)));
if (isTotal) {
statisticsDateAndWorkTime.setTotalTime(new BigDecimal("0"));
statisticsDateAndWorkTime.setCost(new BigDecimal("0"));
}
statisticsDateAndWorkTimes.add(i, statisticsDateAndWorkTime);
}
SimpleDateFormat format = new SimpleDateFormat("yyyy年M月");
......@@ -1210,7 +1215,7 @@ public class StatisticsServiceImpl implements StatisticsService {
RegionUtil.setBorderTop(borderStyle, region, sheet); //上边框
}
public void addProjectStisticsTotalTime(List<ProjectStatisticsByMonth> projectStatisticsByMonths, String statisticsName) {
public void addProjectStatisticsTotalTime(List<ProjectStatisticsByMonth> projectStatisticsByMonths, String statisticsName) {
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
// 一条统计的
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
......
......@@ -93,21 +93,8 @@ public class StatisticsController extends BaseController {
String deptName = sheets.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
// 文件名
String fileName = deptName + "-" + param.getYear() + "年" + param.getMonth() + "月工时汇总";
//响应类型为application/octet- stream情况下使用了这个头信息的话,那就意味着不想直接显示内容
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
//attachment为以附件方式下载
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(
fileName + ".xls",
"utf-8"));
response.setHeader("Cache-Control", "No-cache");
response.flushBuffer();
sheets.write(response.getOutputStream());
sheets.close();
} catch (Exception e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.SERVER_ERROR);
}
this.downExcel(response,sheets,fileName);
}
......@@ -134,42 +121,27 @@ public class StatisticsController extends BaseController {
// 获取excel
HSSFWorkbook sheets = statisticsService.exportUserStatistics(userId, deptId, startDate, endDate);
// 获取excel中的第2行第2列中的部门名称
// String deptName = sheets.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
// 文件名
// String fileName = deptName + "-" + param.getYear() + "年" + param.getMonth() + "月工时汇总";
//响应类型为application/octet- stream情况下使用了这个头信息的话,那就意味着不想直接显示内容
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
String fileName = "导出人员工时统计";
//attachment为以附件方式下载
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(
fileName + ".xls",
"utf-8"));
response.setHeader("Cache-Control", "No-cache");
response.flushBuffer();
sheets.write(response.getOutputStream());
sheets.close();
} catch (Exception e) {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.SERVER_ERROR);
}
String fileName = "人员工时统计";
this.downExcel(response,sheets,fileName);
}
@ApiOperation(value = "导出项目统计明细", notes = "导出项目明细表")
@GetMapping("/exportProjectStatistics")
public void exportProjectStatistics(Integer userId, Integer year, @RequestParam("projectIds") List<Integer> projectIds, HttpServletResponse response) {
log.info("StatisticsController[]exportUserStatistics[]input.param" + userId + year + projectIds);
// 获取excel
HSSFWorkbook sheets = statisticsService.exportProjectStatistics(userId, year, projectIds);
// 获取excel中的第2行第2列中的部门名称
// String deptName = sheets.getSheet("Sheet1").getRow(1).getCell(1).getStringCellValue();
// 文件名
// String fileName = deptName + "-" + param.getYear() + "年" + param.getMonth() + "月工时汇总";
String fileName = "项目工时统计明细";
//attachment为以附件方式下载
downExcel(response, sheets, fileName);
}
// 导出Excel
public void downExcel(HttpServletResponse response, HSSFWorkbook sheets, String fileName) {
//响应类型为application/octet- stream情况下使用了这个头信息的话,那就意味着不想直接显示内容
response.setContentType(MediaType.APPLICATION_OCTET_STREAM_VALUE);
String fileName = "导出项目工时统计明细";
//attachment为以附件方式下载
try {
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(
......@@ -184,4 +156,5 @@ public class StatisticsController extends BaseController {
throw new BaseCustomException(BASE_RESP_CODE_ENUM.SERVER_ERROR);
}
}
}
\ No newline at end of file
}
\ No newline at end of file
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