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

完善工时统计

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