Commit 12d60b59 authored by nie'hong's avatar nie'hong

完善工时统计

parent 5b9caf00
......@@ -109,7 +109,7 @@
<select id="selectListByMonth" resultMap="projectStatisticsByMonth">
select <if test="projectId == null">'合计' AS project_name,</if> <if test="projectId != null"> project_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date, sum(total_time) AS total_time, sum(cost) AS cost
select <if test="projectId == null">'合计' AS project_name,</if> <if test="projectId != null"> project_name,'合计' AS dept_name,</if> group_CONCAT(DISTINCT YEAR (statistics_start),'年',MONTH (statistics_start),'月') AS date, 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
<where>
<if test="projectId != null ">
......@@ -148,6 +148,7 @@
</if>
</where>
group by ptc.project_id,project_name,year(statistics_start),MONTH(statistics_start) <if test="projectId != null "> ,d.dept_name</if>
</select>
</mapper>
\ No newline at end of file
......@@ -639,7 +639,7 @@ public class StatisticsServiceImpl implements StatisticsService {
UserWorkTimeStatisticsByProject userWorkTimeStatisticsByProject1 = userWorkTimeStatisticsByProjectList.get(0);
List<ProjectWorkTimeAndType> projectWorkTimeAndType1 = userWorkTimeStatisticsByProject1.getProjectWorkTimeAndType();
for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
projectWorkTimeAndType.setProjectName(types.get(projectWorkTimeAndType.getProjectType()-1).getName());
projectWorkTimeAndType.setProjectName(types.get(projectWorkTimeAndType.getProjectType() - 1).getName());
}
collect = projectWorkTimeAndType1.stream().map(ProjectWorkTimeAndType::getProjectType).collect(Collectors.toList());
}
......@@ -703,32 +703,35 @@ public class StatisticsServiceImpl implements StatisticsService {
for (int i = 1; i < projectWorkTimeAndType1.size(); i++) {
ProjectWorkTimeAndType projectWorkTimeAndType2 = projectWorkTimeAndType1.get(i);
String projectName = projectWorkTimeAndType2.getProjectName();
ProjectWorkTimeAndType projectWorkTimeAndType3 = projectWorkTimeAndType1.get(i - 1);
String projectName1 = projectWorkTimeAndType3.getProjectName();
if (projectName.equals(projectName1)) {
projectWorkTimeAndType1.get(i - 1).setOverTime(projectWorkTimeAndType2.getOverTime());
projectWorkTimeAndType1.remove(i);
}
// 获取前一个对象
ProjectWorkTimeAndType projectWorkTimeAndTypes = projectWorkTimeAndType1.get(i - 1);
if (projectWorkTimeAndTypes.getNormalTime() != null) {
totalTime += projectWorkTimeAndTypes.getNormalTime();
}
if (projectWorkTimeAndTypes.getOverTime() != null) {
totalTime += projectWorkTimeAndTypes.getOverTime();
for (ProjectWorkTimeAndType projectWorkTimeAndType : projectWorkTimeAndType1) {
if (projectWorkTimeAndType.getNormalTime() != null) {
totalTime += projectWorkTimeAndType.getNormalTime();
}
if (projectWorkTimeAndType.getOverTime() != null) {
totalTime += projectWorkTimeAndType.getOverTime();
}
}
// 最后一个对象
if (projectWorkTimeAndType1.size() != 0) {
ProjectWorkTimeAndType projectWorkTimeAndTypes = projectWorkTimeAndType1.get(projectWorkTimeAndType1.size() - 1);
if (projectWorkTimeAndTypes.getOverTime() != null) {
totalTime += projectWorkTimeAndTypes.getOverTime();
}
if (projectWorkTimeAndTypes.getNormalTime() != null) {
totalTime += projectWorkTimeAndTypes.getNormalTime();
}
}
// if (projectWorkTimeAndType1.size() != 0) {
// ProjectWorkTimeAndType projectWorkTimeAndTypes = projectWorkTimeAndType1.get(projectWorkTimeAndType1.size() - 1);
// if (projectWorkTimeAndTypes.getOverTime() != null) {
// totalTime += projectWorkTimeAndTypes.getOverTime();
// }
// if (projectWorkTimeAndTypes.getNormalTime() != null) {
// totalTime += projectWorkTimeAndTypes.getNormalTime();
// }
// }
userProjectWorkTimeStatistic.setTotalTime(totalTime);
}
......@@ -794,7 +797,7 @@ public class StatisticsServiceImpl implements StatisticsService {
statisticsDateAndWorkTime1.setDate("");
statisticsDateAndWorkTimes1.add(statisticsDateAndWorkTime1);
for (int i = 0; i < statisticsDateAndWorkTimes.size(); i++) {
if ( !statisticsDateAndWorkTimes.get(i).getDate().equals(statisticsDateAndWorkTimes1.get(i).getDate())) {
if (!statisticsDateAndWorkTimes.get(i).getDate().equals(statisticsDateAndWorkTimes1.get(i).getDate())) {
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime.setTotalTime(new BigDecimal("0"));
statisticsDateAndWorkTime.setCost(new BigDecimal("0"));
......@@ -804,24 +807,29 @@ public class StatisticsServiceImpl implements StatisticsService {
continue;
}
}
statisticsDateAndWorkTimes1.remove(statisticsDateAndWorkTimes1.size()-1);
statisticsDateAndWorkTimes1.remove(statisticsDateAndWorkTimes1.size() - 1);
}
}
}
// 将查询结果封装在一起
projectStatisticsByMonths.addAll(0,projectStatisticsByMonths1);
projectStatisticsByMonths.addAll(0, projectStatisticsByMonths1);
List<String> yearMonthList = new ArrayList<>();
if (projectId != null) {
String startDate = new String();
String endDate = new String();
if (deptId == null) {
// 整个项目所占时间,未结项目截止时间为当月,已结项目截止时间为最后一次统计的时间
String startDate = projectStatisticsByMonths.get(0).getStatisticsDateAndWorkTimes().get(0).getDate();
String endDate = workProjectMapper.getLastDate(projectId);
yearMonthList = this.getYearMonthList(startDate,endDate);
startDate = projectStatisticsByMonths.get(0).getStatisticsDateAndWorkTimes().get(0).getDate();
endDate = workProjectMapper.getLastDate(projectId);
} else {
startDate = DateUtil.convertDateToStr(DateUtil.getFirstDayOfYear(new Date()), "yyyy年M月");
endDate = DateUtil.convertDateToStr(new Date(), "yyyy年M月");
}
List<String> yearMonthList = this.getYearMonthList(startDate, endDate);
// 部门主键不为空时,日期格式只有某月。为空时,日期格式为某年统计的第一个月为某年某月,其余为某月
this.conversionDateFormat(projectStatisticsByMonths,yearMonthList, deptId);
this.conversionDateFormat(projectStatisticsByMonths, yearMonthList, projectId);
// 计算项目工时和成本合计
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
......@@ -933,39 +941,46 @@ public class StatisticsServiceImpl implements StatisticsService {
// 部门主键不为空时,日期格式只有某月。为空时,日期格式为某年统计的第一个月为某年某月,其余为某月
public void conversionDateFormat(List<ProjectStatisticsByMonth> projectStatisticsByMonths,List<String> yearMonthList, Integer deptId) {
public void conversionDateFormat(List<ProjectStatisticsByMonth> projectStatisticsByMonths, List<String> yearMonthList, Integer projectId) {
for (ProjectStatisticsByMonth projectStatisticsByMonth : projectStatisticsByMonths) {
List<ProjectStatisticsByMonth.StatisticsDateAndWorkTime> statisticsDateAndWorkTimes = projectStatisticsByMonth.getStatisticsDateAndWorkTimes();
// 部门主键不为空时,日期格式只有某月
if (deptId != null) {
for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
String date = statisticsDateAndWorkTime.getDate();
StringBuilder stringBuilder = new StringBuilder(date);
// 删除年份
stringBuilder.delete(0, 5);
statisticsDateAndWorkTime.setDate(stringBuilder.toString());
}
} else {
// if (deptId != null) {
// for (ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime : statisticsDateAndWorkTimes) {
// String date = statisticsDateAndWorkTime.getDate();
// StringBuilder stringBuilder = new StringBuilder(date);
// // 删除年份
// stringBuilder.delete(0, 5);
// statisticsDateAndWorkTime.setDate(stringBuilder.toString());
// }
// } else {
for (int i = 0; i < yearMonthList.size(); i++) {
String s = yearMonthList.get(i);
String date = "";
String date = new String();
if (i < statisticsDateAndWorkTimes.size()) {
date = statisticsDateAndWorkTimes.get(i).getDate();
} else {
break;
}
// 时间不连续,创建对象
if (!s.equals(date)) {
ProjectStatisticsByMonth.StatisticsDateAndWorkTime statisticsDateAndWorkTime = new ProjectStatisticsByMonth.StatisticsDateAndWorkTime();
statisticsDateAndWorkTime.setDate(s);
statisticsDateAndWorkTime.setTotalTime(new BigDecimal("0"));
statisticsDateAndWorkTime.setCost(new BigDecimal("0"));
statisticsDateAndWorkTimes.add(i,statisticsDateAndWorkTime);
statisticsDateAndWorkTimes.add(i, statisticsDateAndWorkTime);
}
SimpleDateFormat format = new SimpleDateFormat("yyyy年M月");
Date parse = null;
try {
parse = format.parse(s);
if (DateUtil.getMonth(parse) != 1 && i != 0) {
String s1 = yearMonthList.get(i-1);
// 在查询部门所有项目统计时,将除开统计首月和月份为一月的时间格式中的年分删除
if (projectId != null && DateUtil.getMonth(parse) != 0 && i != 0) {
String s1 = yearMonthList.get(i);
String substring = s1.substring(5);
statisticsDateAndWorkTimes.get(i).setDate(substring);
} else if (projectId == null) { // 在查询某个项目全周期统计时,删除所有时间中的年份
String s1 = yearMonthList.get(i);
String substring = s1.substring(5);
statisticsDateAndWorkTimes.get(i).setDate(substring);
}
......@@ -986,7 +1001,7 @@ public class StatisticsServiceImpl implements StatisticsService {
// statisticsDateAndWorkTimes.get(i).setDate(dateBuilder1.toString());
// }
// }
}
// }
}
}
......@@ -1024,8 +1039,8 @@ public class StatisticsServiceImpl implements StatisticsService {
Calendar calendar = DateUtil.convertStrToCalendar(startDate, pattern);
Calendar calendar2 = DateUtil.convertStrToCalendar(endDate, pattern);
list.add(startDate);
for (;!calendar.equals(calendar2); ) {
calendar.add(Calendar.MONTH,1);
for (; !calendar.equals(calendar2); ) {
calendar.add(Calendar.MONTH, 1);
String format = sdf.format(calendar.getTime());
list.add(format);
}
......
......@@ -32,7 +32,7 @@
<!-- MAVEN构建 -->
<build>
<finalName>${project.artifactId}-${moduleVersion.wisenergy-web-admin}</finalName>
<finalName>${project.artifactId}-${moduleVersion.wisenergy-web-admin}-测试</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
......
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