Commit 58d94ca6 authored by nie'hong's avatar nie'hong

完善工时统计

parent 7b0cd554
......@@ -262,9 +262,9 @@
SELECT t.type AS type, d.id AS dept_id,dept_name,
IF (YEAR (work_day) = YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月') , concat(YEAR(work_day),
'年')) AS statistics_time ,SUM(t.work_time)/8 AS
total_time, SUM(t.work_time * s.day_salary)/8 AS cost
total_time, SUM(t.work_time * s.day_salary)/8 AS cost,ty.sort AS ty_sort, d.sort AS d_sort
FROM work_time_order t join work_dept d on d.id = t.dept_id join work_user_salary s on s.user_id = t.user_id join work_type ty on t.type = ty.id
WHERE t.status IN (2,5) AND s.create_time < t.work_day AND s.end_time > t.work_day
WHERE t.status IN (2,5) AND s.create_time < t.work_day AND s.end_time > t.work_day AND year(t.work_day) < year(NOW())
<if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth}
</if>
......@@ -278,8 +278,31 @@
<if test="centreId != null">
AND centre_id = #{centreId}
</if>
group by t.type,d.id, dept_name, if(YEAR (work_day) = YEAR(NOW()),',month(work_day)','')
order by d.id,work_day,ty.sort
group by t.type,d.id, dept_name,year(work_day)
union
SELECT t.type AS type, d.id AS dept_id,dept_name,
IF (YEAR (work_day) = YEAR (NOW()), concat(YEAR (work_day),'年',MONTH (work_day),'月') , concat(YEAR(work_day),
'年')) AS statistics_time ,SUM(t.work_time)/8 AS
total_time, SUM(t.work_time * s.day_salary)/8 AS cost,ty.sort AS ty_sort, d.sort AS d_sort
FROM work_time_order t join work_dept d on d.id = t.dept_id join work_user_salary s on s.user_id = t.user_id join work_type ty on t.type = ty.id
WHERE t.status IN (2,5) AND s.create_time &lt; t.work_day AND s.end_time > t.work_day AND year(t.work_day) = year(NOW())
<if test="firstDayOfMonth != null">
AND work_day >= #{firstDayOfMonth}
</if>
<if test="deptId != null">
AND t.dept_id = #{deptId}
</if>
AND t.type in
<foreach collection="types" item="type" open="(" close=")" separator=",">
#{type}
</foreach>
<if test="centreId != null">
AND centre_id = #{centreId}
</if>
group by t.type,d.id, dept_name,month(work_day)
ORDER BY ty_sort, d_sort, statistics_time
</select>
<select id="getDaysByDateAndStatus" resultType="date">
......
......@@ -38,8 +38,6 @@ public class WorkType implements Serializable, Comparable<WorkType>{
private Integer sort;
@Override
public int compareTo(WorkType o) {
......
......@@ -11,6 +11,7 @@ import cn.wisenergy.model.app.*;
import cn.wisenergy.model.dto.*;
import cn.wisenergy.model.enums.*;
import cn.wisenergy.service.StatisticsService;
import cn.wisenergy.service.WorkTypeService;
import cn.wisenergy.service.WorkUserService;
import cn.wisenergy.service.utils.UserRoleLevelUtils;
import com.alibaba.excel.util.StringUtils;
......@@ -71,6 +72,9 @@ public class StatisticsServiceImpl implements StatisticsService {
@Autowired
private WorkDeptMapper workDeptMapper;
@Autowired
private WorkTypeService workTypeService;
private final static Integer EXCEL_WIDTH = 1000 * 6;
......@@ -233,18 +237,20 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Integer> types = monthlyWorkingHoursStatistics.stream().map(MonthlyWorkingHoursStatistics::getProjectType).collect(Collectors.toList());
// 如果没填写填报类型其中某项,造对象传前端
List<WorkType> workTypes = workTypeMapper.getAll();
List<WorkType> workTypes = workTypeService.getAll(1);
if (monthlyWorkingHoursStatistics.size() < workTypes.size()) {
for (WorkType workType : workTypes) {
for (int i = 0; i < workTypes.size(); i++) {
WorkType workType = workTypes.get(i);
if (!types.contains(workType.getId())) {
MonthlyWorkingHoursStatistics workingHoursStatistics = new MonthlyWorkingHoursStatistics();
workingHoursStatistics.setTypeName(workType.getName());
workingHoursStatistics.setProjectType(workType.getId());
workingHoursStatistics.setCount(0);
workingHoursStatistics.setWorkTime(0);
monthlyWorkingHoursStatistics.add(workingHoursStatistics);
monthlyWorkingHoursStatistics.add(i,workingHoursStatistics);
}
}
}
// 赋值未填报天数、被驳回未重报天
......@@ -286,7 +292,7 @@ public class StatisticsServiceImpl implements StatisticsService {
List<Integer> rank = this.getUserRank(roleUserLevel, LevelEnum.PROJECT_STATISTICS.getLevelName());
// 获取所有的类型
List<WorkType> workTypes = workTypeMapper.getAll();
List<WorkType> workTypes = workTypeService.getAll(1);
// 存储查询的类型
List<Integer> types = new ArrayList<>();
// 只存储项目和商机之外的类型
......@@ -331,18 +337,17 @@ public class StatisticsServiceImpl implements StatisticsService {
}
// 获取查询结果中的类型
List<Integer> typeList = workTimeAndCostCollects.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 如果查询结果不包含查询条件中的类型,造对象传前端
for (WorkType workType : workTypes) {
if (!typeList.contains(workType.getId())) {
// 权限级别为项目级别的用户只返回项目和商机类型的汇总
if (rank.contains(LevelRankEnum.PROJECT_LEVEL.getRank()) && rank.size() == 1 && types.contains(workType.getId())) {
continue;
if (!rank.contains(LevelRankEnum.PROJECT_LEVEL.getRank())) {
List<Integer> typeList = workTimeAndCostCollects.stream().map(WorkTimeAndCostCollect::getType).collect(Collectors.toList());
// 如果查询结果不包含查询条件中的类型,造对象传前端
for (int i = 0; i < workTypes.size(); i++) {
WorkType workType = workTypes.get(i);
if (!typeList.contains(workType.getId())) {
WorkTimeAndCostCollect workTimeAndCostCollect1 = new WorkTimeAndCostCollect();
workTimeAndCostCollect1.setType(workType.getId());
workTimeAndCostCollect1.setTypeName(workType.getName());
workTimeAndCostCollects.add(i,workTimeAndCostCollect1);
}
WorkTimeAndCostCollect workTimeAndCostCollect1 = new WorkTimeAndCostCollect();
workTimeAndCostCollect1.setType(workType.getId());
workTimeAndCostCollect1.setTypeName(workType.getName());
workTimeAndCostCollects.add(workTimeAndCostCollect1);
}
}
......@@ -798,14 +803,12 @@ public class StatisticsServiceImpl implements StatisticsService {
HSSFCell cell2 = totalRow1.createCell((i + 1) * 2 + 1);
cell2.setCellValue(projectWorkTimeAndType.get(i).getOverTime());
} else {
// 加班工时和正常工时行最后的
short lastCellNum = row_2.getLastCellNum();
// 合计行最后的列
short lastCellNum = totalRow1.getLastCellNum();
// 调休和请假的类型名单元格
row_1Cell = row_1.createCell(lastCellNum);
// 请假或调休的总计单元格
totalRow2Cell = totalRow2.createCell(lastCellNum);
// 类型名称
row_1Cell.setCellValue(projectWorkTimeAndType.get(i).getProjectName());
// 请假或调休合计
HSSFCell cell1 = totalRow1.createCell(lastCellNum);
cell1.setCellValue(projectWorkTimeAndType.get(i).getNormalTime());
......@@ -880,8 +883,9 @@ public class StatisticsServiceImpl implements StatisticsService {
CellRangeAddress cellRangeAddress3 = new CellRangeAddress(userWorkTimeStatisticsReport.size() + 1, userWorkTimeStatisticsReport.size() + 1, 0, 1);
sheet1.addMergedRegion(cellRangeAddress3);
setBorderStyle(BorderStyle.THIN, cellRangeAddress3, sheet1);
// 项目行和总计行
for (int i = 0; i < row1_lastCellNum / 2 - 1; i++) {
// 项目行和总计行,正常工时和加班工时表头列数
short lastCellNum = row_2.getLastCellNum();
for (int i = 0; i < lastCellNum / 2 ; i++) {
// 总计行
CellRangeAddress cellRangeAddress4 = new CellRangeAddress(userWorkTimeStatisticsReport.size() + 2, userWorkTimeStatisticsReport.size() + 2, i * 2, i * 2 + 1);
sheet1.addMergedRegion(cellRangeAddress4);
......
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