|
@@ -6,22 +6,20 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.aliyun.dingtalkcontact_1_0.models.SearchUserResponse;
|
|
import com.aliyun.dingtalkcontact_1_0.models.SearchUserResponse;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.management.platform.entity.*;
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
import com.management.platform.entity.vo.SysRichFunction;
|
|
|
-import com.management.platform.entity.vo.WorktimeItem;
|
|
|
|
|
import com.management.platform.mapper.*;
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.*;
|
|
import com.management.platform.service.*;
|
|
|
import com.management.platform.util.*;
|
|
import com.management.platform.util.*;
|
|
|
-import org.apache.commons.io.FileUtils;
|
|
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.format.annotation.DateTimeFormat;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -2534,4 +2532,152 @@ public class UserCorpwxTimeController {
|
|
|
msg.setData(userCorpwxTime);
|
|
msg.setData(userCorpwxTime);
|
|
|
return msg;
|
|
return msg;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @RequestMapping("/getUserFictitiousAttendanceList")
|
|
|
|
|
+ public HttpRespMsg getUserFictitiousAttendanceList(String month, Integer pageIndex, Integer pageSize){
|
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (pageIndex == null || pageIndex < 1) {
|
|
|
|
|
+ pageIndex = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (pageSize == null || pageSize < 1) {
|
|
|
|
|
+ pageSize = 20;
|
|
|
|
|
+ }
|
|
|
|
|
+ String token = request.getHeader("TOKEN");
|
|
|
|
|
+ User loginUser = userMapper.selectById(token);
|
|
|
|
|
+ if (loginUser == null) {
|
|
|
|
|
+ httpRespMsg.setError("未获取到登录用户");
|
|
|
|
|
+ return httpRespMsg;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (month == null || month.trim().isEmpty()) {
|
|
|
|
|
+ month = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
|
|
|
|
+ }
|
|
|
|
|
+ LocalDate monthStart = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
|
|
+ LocalDate monthEnd = monthStart.plusMonths(1).minusDays(1);
|
|
|
|
|
+ int daysInMonth = monthStart.lengthOfMonth();
|
|
|
|
|
+ List<SysRichFunction> functionList = sysFunctionMapper.getRoleFunctions(loginUser.getRoleId(), "全部员工假勤数据");
|
|
|
|
|
+ QueryWrapper<UserCorpwxTime> monthQuery = new QueryWrapper<UserCorpwxTime>()
|
|
|
|
|
+ .eq("company_id", loginUser.getCompanyId())
|
|
|
|
|
+ .between("create_date", monthStart, monthEnd);
|
|
|
|
|
+ if (functionList == null || functionList.isEmpty()) {
|
|
|
|
|
+ Integer manageDeptId = loginUser.getManageDeptId();
|
|
|
|
|
+ List<Integer> deptIds = new ArrayList<>();
|
|
|
|
|
+ if (manageDeptId != null && manageDeptId != 0) {
|
|
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", loginUser.getCompanyId()));
|
|
|
|
|
+ deptIds = departmentService.getAllManagedDeptIdList(loginUser, allDeptList);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (deptIds.isEmpty()) {
|
|
|
|
|
+ monthQuery.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ List<User> deptUserList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", loginUser.getCompanyId()).in("department_id", deptIds));
|
|
|
|
|
+ List<String> deptCorpwxUserIds = deptUserList.stream().map(User::getCorpwxUserid).filter(org.springframework.util.StringUtils::hasText).collect(Collectors.toList());
|
|
|
|
|
+ List<String> deptNames = deptUserList.stream().map(User::getName).filter(org.springframework.util.StringUtils::hasText).collect(Collectors.toList());
|
|
|
|
|
+ if (!deptCorpwxUserIds.isEmpty() && !deptNames.isEmpty()) {
|
|
|
|
|
+ monthQuery.and(q -> q.in("corpwx_userid", deptCorpwxUserIds).or().in("name", deptNames));
|
|
|
|
|
+ } else if (!deptCorpwxUserIds.isEmpty()) {
|
|
|
|
|
+ monthQuery.in("corpwx_userid", deptCorpwxUserIds);
|
|
|
|
|
+ } else if (!deptNames.isEmpty()) {
|
|
|
|
|
+ monthQuery.in("name", deptNames);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ monthQuery.in("corpwx_userid", Collections.singletonList("__NONE__"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ monthQuery.orderByAsc("create_date", "name");
|
|
|
|
|
+ Page<UserCorpwxTime> page = new Page<>(pageIndex, pageSize);
|
|
|
|
|
+ IPage<UserCorpwxTime> monthPage = userCorpwxTimeMapper.selectPage(page, monthQuery);
|
|
|
|
|
+ List<UserCorpwxTime> monthList = monthPage.getRecords();
|
|
|
|
|
+
|
|
|
|
|
+ List<LocalDate> restDayDates = WorkDayCalculateUtils.getNonWorkDaysListInRange(
|
|
|
|
|
+ monthStart.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")),
|
|
|
|
|
+ monthEnd.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
|
|
|
|
|
+ );
|
|
|
|
|
+ List<String> restDayList = restDayDates.stream().map(d -> d.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, List<UserCorpwxTime>> grouped = monthList.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(item -> item.getCorpwxUserid() != null ? item.getCorpwxUserid() : item.getName(), LinkedHashMap::new, Collectors.toList()));
|
|
|
|
|
+
|
|
|
|
|
+ List<Map<String, Object>> attendanceList = new ArrayList<>();
|
|
|
|
|
+ DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
|
|
+ for (Map.Entry<String, List<UserCorpwxTime>> entry : grouped.entrySet()) {
|
|
|
|
|
+ List<UserCorpwxTime> userTimes = entry.getValue();
|
|
|
|
|
+ if (userTimes.isEmpty()) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ UserCorpwxTime first = userTimes.get(0);
|
|
|
|
|
+ Map<String, Object> row = new HashMap<>();
|
|
|
|
|
+ row.put("userId", first.getCorpwxUserid());
|
|
|
|
|
+ row.put("employeeName", first.getName());
|
|
|
|
|
+ row.put("jobNumber", null);
|
|
|
|
|
+ User sysUser = null;
|
|
|
|
|
+ if (first.getCorpwxUserid() != null) {
|
|
|
|
|
+ sysUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", first.getCorpwxUserid()).eq("company_id", loginUser.getCompanyId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sysUser == null && first.getName() != null) {
|
|
|
|
|
+ sysUser = userMapper.selectOne(new QueryWrapper<User>().eq("name", first.getName()).eq("company_id", loginUser.getCompanyId()));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (sysUser != null) {
|
|
|
|
|
+ row.put("userId", sysUser.getId());
|
|
|
|
|
+ row.put("employeeName", sysUser.getName());
|
|
|
|
|
+ row.put("jobNumber", sysUser.getJobNumber());
|
|
|
|
|
+ Department dept = null;
|
|
|
|
|
+ if (sysUser.getDepartmentId() != null) {
|
|
|
|
|
+ dept = departmentMapper.selectById(sysUser.getDepartmentId());
|
|
|
|
|
+ }
|
|
|
|
|
+ row.put("departmentName", dept == null ? "" : dept.getCorpwxDeptid());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ row.put("departmentName", "");
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, UserCorpwxTime> dayMap = userTimes.stream().collect(Collectors.toMap(t -> t.getCreateDate().format(df), t -> t, (a, b) -> a));
|
|
|
|
|
+ List<String> attendanceArray = new ArrayList<>();
|
|
|
|
|
+ double holidayCount = 0;
|
|
|
|
|
+ for (int i = 1; i <= daysInMonth; i++) {
|
|
|
|
|
+ LocalDate date = monthStart.withDayOfMonth(i);
|
|
|
|
|
+ String dateStr = date.format(df);
|
|
|
|
|
+ UserCorpwxTime time = dayMap.get(dateStr);
|
|
|
|
|
+ String value = "";
|
|
|
|
|
+ Double leaveTime = 0D;
|
|
|
|
|
+ if (time != null) {
|
|
|
|
|
+ String leaveType = time.getAskLeaveType() == null ? "" : String.valueOf(time.getAskLeaveType());
|
|
|
|
|
+ leaveTime = time.getAskLeaveTime() == null ? 0D : time.getAskLeaveTime();
|
|
|
|
|
+ if (leaveTime > 0 || !leaveType.isEmpty()) {
|
|
|
|
|
+ value = leaveType.isEmpty() ? String.valueOf(leaveTime) : leaveType+leaveTime;
|
|
|
|
|
+ holidayCount += leaveTime;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (leaveTime > 0 || !value.isEmpty()) {
|
|
|
|
|
+ attendanceArray.add(value.isEmpty() ? String.valueOf(leaveTime) : value);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ attendanceArray.add("");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ row.put("fictitiousAttendanceArray", attendanceArray);
|
|
|
|
|
+ row.put("holidayCount", holidayCount);
|
|
|
|
|
+ attendanceList.add(row);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ int total = (int) monthPage.getTotal();
|
|
|
|
|
+ List<Map<String, Object>> pageList = attendanceList;
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
|
|
+ List<String> dateList = new ArrayList<>();
|
|
|
|
|
+ List<String> weekList = new ArrayList<>();
|
|
|
|
|
+ for (int i = 1; i <= daysInMonth; i++) {
|
|
|
|
|
+ LocalDate date = monthStart.withDayOfMonth(i);
|
|
|
|
|
+ dateList.add(String.valueOf(i));
|
|
|
|
|
+ weekList.add(date.getDayOfWeek().getDisplayName(TextStyle.SHORT, Locale.CHINESE).replace("星期", ""));
|
|
|
|
|
+ }
|
|
|
|
|
+ result.put("dateList", dateList);
|
|
|
|
|
+ result.put("weekList", weekList);
|
|
|
|
|
+ result.put("restDayList", restDayList);
|
|
|
|
|
+ result.put("list", pageList);
|
|
|
|
|
+ result.put("total", total);
|
|
|
|
|
+ httpRespMsg.data = result;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ httpRespMsg.setError("获取员工假勤数据失败:" + e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ return httpRespMsg;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|