|
|
@@ -85,8 +85,8 @@ public class WorkOvertimeController {
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
- //生产车间主任代工位提交加班申请,只会按照同一工位依次提交,若申请中员工id不为同一工位,则报错返回,若相同则设置为申请工位id
|
|
|
- if (user.getRoleId() == 33) {
|
|
|
+ //生产车间主任(生产车间主管)代工位提交加班申请,只会按照同一工位依次提交,若申请中员工id不为同一工位,则报错返回,若相同则设置为申请工位id
|
|
|
+ if (Objects.equals(user.getId(), departmentMapper.selectById(31).getManagerId())) {
|
|
|
String[] employeeIds = workOvertime.getEmployeeIds().split(",");
|
|
|
Integer Workstaion = null;
|
|
|
for (int i = 0; i < employeeIds.length; i++) {
|
|
|
@@ -100,7 +100,7 @@ public class WorkOvertimeController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if (Workstaion == null) {
|
|
|
+ if (Workstaion != null) {
|
|
|
workOvertime.setWorkstationId(Workstaion);
|
|
|
}
|
|
|
}
|
|
|
@@ -203,7 +203,7 @@ public class WorkOvertimeController {
|
|
|
User targetUser = userMapper.selectById(token);
|
|
|
List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", targetUser.getCompanyId()));
|
|
|
Company company = companyMapper.selectById(targetUser.getCompanyId());
|
|
|
-
|
|
|
+
|
|
|
//非管理员只能看到自己的
|
|
|
if (!targetUser.getRoleName().equals("超级管理员") && !targetUser.getRoleName().equals("系统管理员") && !sysFunctionService.hasPriviledge(targetUser.getRoleId(),"查看全部人员加班")) {
|
|
|
applicant = token;
|
|
|
@@ -229,87 +229,88 @@ public class WorkOvertimeController {
|
|
|
if (!StringUtils.isEmpty(mealType)) {
|
|
|
queryWrapper.like("meal_type", mealType);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 按日期正序排列
|
|
|
queryWrapper.orderByAsc("work_date", "id");
|
|
|
-
|
|
|
+
|
|
|
// 获取所有数据(不分页)
|
|
|
List<WorkOvertime> overtimeList = workOvertimeService.list(queryWrapper);
|
|
|
-
|
|
|
- // 查询所有加班时段设置
|
|
|
- List<OvertimeSetting> overtimeSettings = overtimeSettingMapper.selectList(new QueryWrapper<OvertimeSetting>());
|
|
|
-
|
|
|
- // 获取所有加班人员ID
|
|
|
- Set<String> overtimeUserIds = new HashSet<>();
|
|
|
- for (WorkOvertime overtime : overtimeList) {
|
|
|
- String[] array = overtime.getEmployeeIds().split(",");
|
|
|
- for (String id : array) {
|
|
|
- overtimeUserIds.add(id.trim());
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
List<ExcelUtil.OvertimeStatisticsData> exportDataList = new ArrayList<>();
|
|
|
-
|
|
|
- if (!overtimeUserIds.isEmpty()) {
|
|
|
- // 查询加班员工信息
|
|
|
- List<User> overtimeUsers = userMapper.selectList(new QueryWrapper<User>().in("id", overtimeUserIds));
|
|
|
-
|
|
|
- // 获取这些员工所属的部门作为工位
|
|
|
- Set<Integer> departmentIds = overtimeUsers.stream()
|
|
|
- .map(User::getDepartmentId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toSet());
|
|
|
-
|
|
|
- List<Department> workstations = new ArrayList<>();
|
|
|
- if (!departmentIds.isEmpty()) {
|
|
|
- workstations = departmentMapper.selectList(new QueryWrapper<Department>().in("department_id", departmentIds));
|
|
|
- }
|
|
|
-
|
|
|
- // 按日期分组数据
|
|
|
- Map<String, List<WorkOvertime>> dateGroupedData = overtimeList.stream()
|
|
|
- .collect(Collectors.groupingBy(overtime ->
|
|
|
- overtime.getWorkDate() != null ?
|
|
|
- overtime.getWorkDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) : ""));
|
|
|
-
|
|
|
- // 构建导出数据
|
|
|
- for (Map.Entry<String, List<WorkOvertime>> dateEntry : dateGroupedData.entrySet()) {
|
|
|
- String date = dateEntry.getKey();
|
|
|
- List<WorkOvertime> dateOvertimes = dateEntry.getValue();
|
|
|
-
|
|
|
- List<ExcelUtil.WorkstationData> workstationDataList = new ArrayList<>();
|
|
|
-
|
|
|
- // 为每个工位创建时段数据行
|
|
|
- for (Department workstation : workstations) {
|
|
|
- String workstationName = workstation.getDepartmentName();
|
|
|
-
|
|
|
- // 查找该工位在该日期的加班数据
|
|
|
- List<WorkOvertime> workstationOvertimes = dateOvertimes.stream()
|
|
|
- .filter(overtime -> {
|
|
|
- // 根据员工所属部门判断工位
|
|
|
- String[] empIds = overtime.getEmployeeIds() != null ? overtime.getEmployeeIds().split(",") : new String[0];
|
|
|
- for (String empId : empIds) {
|
|
|
- Optional<User> user = overtimeUsers.stream().filter(u -> u.getId().equals(empId.trim())).findFirst();
|
|
|
- if (user.isPresent() && user.get().getDepartmentId() != null &&
|
|
|
- user.get().getDepartmentId().equals(workstation.getDepartmentId())) {
|
|
|
- return true;
|
|
|
- }
|
|
|
+
|
|
|
+ // 按日期分组数据
|
|
|
+ Map<String, List<WorkOvertime>> dateGroupedData = overtimeList.stream()
|
|
|
+ .collect(Collectors.groupingBy(overtime ->
|
|
|
+ overtime.getWorkDate() != null ?
|
|
|
+ overtime.getWorkDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) : ""));
|
|
|
+
|
|
|
+ // 构建导出数据
|
|
|
+ for (Map.Entry<String, List<WorkOvertime>> dateEntry : dateGroupedData.entrySet()) {
|
|
|
+ String date = dateEntry.getKey();
|
|
|
+ List<WorkOvertime> dateOvertimes = new ArrayList<>();
|
|
|
+ /*
|
|
|
+ * 合并工位,日期,时间相同的申请
|
|
|
+ * */
|
|
|
+ for (WorkOvertime workOvertime : dateEntry.getValue()) {
|
|
|
+ if (workOvertime.getWorkstationId() != null && workOvertime.getTimeTypeId() != null) {
|
|
|
+ boolean exist = false;
|
|
|
+ for(WorkOvertime item : dateOvertimes){
|
|
|
+ if( workOvertime.getWorkstationId().equals(item.getWorkstationId()) && workOvertime.getTimeTypeId().equals(item.getTimeTypeId())){
|
|
|
+ exist = true;
|
|
|
+ if(item.getEmployeeIds() != null && !item.getEmployeeIds().isEmpty()){
|
|
|
+ item.setEmployeeIds(item.getEmployeeIds() + "," + workOvertime.getEmployeeIds());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ item.setEmployeeIds(workOvertime.getEmployeeIds());
|
|
|
+ }
|
|
|
+ if(item.getContent() != null && !item.getContent().isEmpty()){
|
|
|
+ item.setContent(item.getContent() + "," + workOvertime.getContent());
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ item.setEmployeeIds(workOvertime.getContent());
|
|
|
}
|
|
|
- return false;
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- // 如果该工位有加班数据,则根据OvertimeSetting中的时段创建数据行
|
|
|
- if (!workstationOvertimes.isEmpty()) {
|
|
|
- for (OvertimeSetting setting : overtimeSettings) {
|
|
|
- ExcelUtil.WorkstationData workstationData = createWorkstationData(workstation.getDepartmentId(),
|
|
|
- workstationName, workstationOvertimes, setting, overtimeUsers);
|
|
|
- workstationDataList.add(workstationData);
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
+ if(!exist){
|
|
|
+ dateOvertimes.add(workOvertime);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- exportDataList.add(new ExcelUtil.OvertimeStatisticsData(date, workstationDataList));
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /*
|
|
|
+ * 每日加班申请按照部门id-加班时段排序
|
|
|
+ * */
|
|
|
+ dateOvertimes.sort((s1,s2) ->{
|
|
|
+ int res = -1;
|
|
|
+ if(s1.getWorkstationId() != null && s2.getWorkstationId() != null){
|
|
|
+ res = s1.getWorkstationId().compareTo(s2.getWorkstationId());
|
|
|
+ }
|
|
|
+ if(res == 0){
|
|
|
+ if (s1.getTimeTypeId() != null && s2.getTimeTypeId() != null) {
|
|
|
+ res = s1.getTimeTypeId().compareTo(s2.getTimeTypeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ });
|
|
|
+
|
|
|
+ List<ExcelUtil.WorkstationData> workstationDataList = new ArrayList<>();
|
|
|
+ for (WorkOvertime workOvertime : dateOvertimes) {
|
|
|
+ ExcelUtil.WorkstationData overtimeStatisticsData = createWorkstationData(workOvertime);
|
|
|
+ if(overtimeStatisticsData == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ workstationDataList.add(overtimeStatisticsData);
|
|
|
+ }
|
|
|
+
|
|
|
+ exportDataList.add(new ExcelUtil.OvertimeStatisticsData(date, workstationDataList));
|
|
|
+
|
|
|
}
|
|
|
+ exportDataList.sort(Comparator.comparing( ExcelUtil.OvertimeStatisticsData::getDate));
|
|
|
+
|
|
|
|
|
|
// 生成Excel文件
|
|
|
String fileName = "生产制造部周末加班统计表_" + company.getCompanyName() + "_" + System.currentTimeMillis();
|
|
|
@@ -327,73 +328,58 @@ public class WorkOvertimeController {
|
|
|
/**
|
|
|
* 创建工位数据
|
|
|
*/
|
|
|
- private ExcelUtil.WorkstationData createWorkstationData(Integer departmentId, String workstationName,
|
|
|
- List<WorkOvertime> overtimes,
|
|
|
- OvertimeSetting setting,
|
|
|
- List<User> userList) {
|
|
|
- String timeSlot = setting.getStartTime() + "-" + setting.getEndTime();
|
|
|
- // 筛选符合时段的加班数据 - 精确匹配时段
|
|
|
- List<WorkOvertime> timeSlotOvertimes = overtimes.stream()
|
|
|
- .filter(overtime ->{
|
|
|
- String overtimeSlot = overtime.getStartTime() + "-" + overtime.getEndTime();
|
|
|
- return timeSlot.equals(overtimeSlot);
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
-
|
|
|
- int lunchCount = 0, dinnerCount = 0, snackCount = 0;
|
|
|
- List<String> allEmployees = new ArrayList<>();
|
|
|
- List<String> allTasks = new ArrayList<>();
|
|
|
-
|
|
|
- for (WorkOvertime overtime : timeSlotOvertimes) {
|
|
|
- //只统计该工位下的人员
|
|
|
- String[] allOvertimeSheetEmployeeIds = overtime.getEmployeeIds() != null ? overtime.getEmployeeIds().split(",") : new String[0];
|
|
|
- List<User> curStationUserList = new ArrayList<>();
|
|
|
- for (String empId : allOvertimeSheetEmployeeIds) {
|
|
|
- Optional<User> user = userList.stream().filter(u -> u.getId().equals(empId.trim())).findFirst();
|
|
|
- if (user.isPresent()) {
|
|
|
- User user2 = user.get();
|
|
|
- if (user2.getDepartmentId() != null && user2.getDepartmentId().equals(departmentId)) {
|
|
|
- curStationUserList.add(user2);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ private ExcelUtil.WorkstationData createWorkstationData(WorkOvertime overtime) {
|
|
|
+ String workstationName = "";
|
|
|
|
|
|
+ System.out.println("555555555555555555555555555555555555");
|
|
|
+ try{
|
|
|
+ workstationName = departmentMapper.selectById(overtime.getWorkstationId()).getDepartmentName();
|
|
|
+ }
|
|
|
+ catch (Exception e){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ List<String> employees = new ArrayList<>();
|
|
|
+ if (overtime.getEmployeeIds() != null && !overtime.getEmployeeIds().trim().isEmpty()) {
|
|
|
+ System.out.println(overtime.getEmployeeIds());
|
|
|
+ employees = Arrays.stream(overtime.getEmployeeIds().split(","))
|
|
|
+ .map(employeeId ->{
|
|
|
+ return userMapper.selectById(employeeId).getName();
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
- int employeeCount = curStationUserList.size();
|
|
|
-
|
|
|
- // 根据mealType字段判断用餐类型
|
|
|
- String mealTypeNames = overtime.getMealType() != null ? overtime.getMealType() : "";
|
|
|
- String[] mealTypes = mealTypeNames.split(",");
|
|
|
-
|
|
|
- // 遍历餐别,如果包含对应餐别则人数累加
|
|
|
- for (String meal : mealTypes) {
|
|
|
- meal = meal.trim();
|
|
|
- if (meal.contains("中餐")) {
|
|
|
- lunchCount += employeeCount;
|
|
|
- }
|
|
|
- if (meal.contains("晚餐")) {
|
|
|
- dinnerCount += employeeCount;
|
|
|
- }
|
|
|
- if (meal.contains("夜宵")) {
|
|
|
- snackCount += employeeCount;
|
|
|
- }
|
|
|
+ int employeeCount = employees.size();
|
|
|
+
|
|
|
+ // 根据mealType字段判断用餐类型
|
|
|
+ String mealTypeNames = overtime.getMealType() != null ? overtime.getMealType() : "";
|
|
|
+ String[] mealTypes = mealTypeNames.split(",");
|
|
|
+ int lunchCount = 0,dinnerCount = 0,snackCount = 0;
|
|
|
+
|
|
|
+ // 遍历餐别,如果包含对应餐别则人数累加
|
|
|
+ for (String meal : mealTypes) {
|
|
|
+ meal = meal.trim();
|
|
|
+ if (meal.contains("中餐")) {
|
|
|
+ lunchCount += employeeCount;
|
|
|
}
|
|
|
-
|
|
|
- // 收集员工姓名
|
|
|
- for (User user : curStationUserList) {
|
|
|
- allEmployees.add(user.getName());
|
|
|
+ if (meal.contains("晚餐")) {
|
|
|
+ dinnerCount += employeeCount;
|
|
|
}
|
|
|
-
|
|
|
- // 收集任务安排
|
|
|
- if (overtime.getContent() != null && !overtime.getContent().trim().isEmpty()) {
|
|
|
- allTasks.add(overtime.getContent());
|
|
|
+ if (meal.contains("夜宵")) {
|
|
|
+ snackCount += employeeCount;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- String employees = allEmployees.stream().distinct().collect(Collectors.joining(","));
|
|
|
- String taskArrangement = allTasks.stream().distinct().collect(Collectors.joining(";"));
|
|
|
+
|
|
|
+ String timeSlot = "";
|
|
|
+ if (overtime.getTimeTypeId() != null) {
|
|
|
+ OvertimeSetting set = overtimeSettingMapper.selectById(overtime.getTimeTypeId());
|
|
|
+ if (set != null) {
|
|
|
+ timeSlot = String.format("%s-%s",set.getStartTime(),set.getEndTime());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String taskArrangement = overtime.getContent();
|
|
|
String cooperationPersonnel = "";
|
|
|
return new ExcelUtil.WorkstationData(workstationName, lunchCount, dinnerCount, snackCount,
|
|
|
- timeSlot, employees, taskArrangement, cooperationPersonnel);
|
|
|
+ timeSlot, employees.toString(), taskArrangement, cooperationPersonnel);
|
|
|
}
|
|
|
}
|