From 46ee062359b677be53cea7b0bbabf3cd607c8da3 Mon Sep 17 00:00:00 2001
From: BAOLH <baolh@yhzhg.cn>
Date: Fri, 06 Jun 2025 02:01:08 +0000
Subject: [PATCH] 添加企微周报填写提醒相关功能
---
eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java | 225 +++++++++++++++++++++++++++++++++++++++-----------------
1 files changed, 157 insertions(+), 68 deletions(-)
diff --git a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
index d001dcd..7e6cc26 100644
--- a/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
+++ b/eladmin-master/eladmin-system/src/main/java/me/zhengjie/modules/quartz/service/impl/WeComServiceImpl.java
@@ -8,6 +8,7 @@
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.oa.WxCpCheckinData;
+import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.attendance.domain.*;
import me.zhengjie.modules.attendance.repository.*;
@@ -46,6 +47,7 @@
import me.zhengjie.weixin.cp.bean.smartsheet.record.*;
import me.zhengjie.weixin.cp.bean.smartsheet.sheet.*;
import org.apache.commons.lang3.ObjectUtils;
+import org.apache.commons.lang3.SerializationUtils;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
@@ -260,11 +262,11 @@
}
Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime());
// 早打卡
+ // TODO:补充上班补卡记录
+ if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && !isHoliday && (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
+ cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance);
+ }
if ("上班打卡".equals(weComRecordResult.getCheckinType())) {
- // 补充上班补卡记录
- if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && !isHoliday && (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
- cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance);
- }
// 调用验证状态方法
Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime());
// 考勤记录
@@ -277,11 +279,11 @@
attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime);
}
// 晚打卡
+ // TODO:补充下班补卡记录
+ if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && !isHoliday && (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
+ cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance);
+ }
if ("下班打卡".equals(weComRecordResult.getCheckinType())) {
- // 补充下班补卡记录
- if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && !isHoliday && (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
- cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance);
- }
// 调用验证状态方法
Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime());
// 考勤记录
@@ -394,11 +396,11 @@
}
Timestamp checkInTime = unixtimeToTimestamp(weComRecordResult.getCheckinTime());
// 早打卡
+ // TODO:补充上班补卡记录
+ if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && !isHoliday && (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
+ cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance);
+ }
if ("上班打卡".equals(weComRecordResult.getCheckinType())) {
- // 补充上班补卡记录
- if (ObjectUtils.isEmpty(attendance.getActualWorkStartTime()) && !isHoliday && (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
- cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOON, attendance);
- }
// 调用验证状态方法
Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getStartClockResults(), attendance.getActualWorkStartTime());
// 考勤记录
@@ -411,11 +413,11 @@
attendance.setActualWorkStartTime(flag == true ? attendance.getActualWorkStartTime() : checkInTime);
}
// 晚打卡
+ // TODO:补充下班补卡记录
+ if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && !isHoliday && (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
+ cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance);
+ }
if ("下班打卡".equals(weComRecordResult.getCheckinType())) {
- // 补充下班补卡记录
- if (ObjectUtils.isEmpty(attendance.getActualWorkEndTime()) && !isHoliday && (attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_WAITFOR) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_LACK_OF_TIME))) {
- cardDatetimeSupplement(attendance.getUserId(), strAttendDate, Constant.CARD_REPLACEMENT_DIFFERENTIATION_GOOFF, attendance);
- }
// 调用验证状态方法
Boolean flag = getCardSupplement(attendance.getUserId(), attendance.getEndClockResults(), attendance.getActualWorkEndTime());
// 考勤记录
@@ -475,10 +477,17 @@
getMornOrNoon(user, attendance, attendDate, attendanceLeave.getLeaveStartTime(), attendanceLeave.getLeaveEndTime(), day);
}
}
- //查询出差表
- AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime());
- if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) {
- getMornOrNoon(user, attendance, attendDate, attendanceBusinessTravel.getTravelStartTime(), attendance.getRosteringWorkEndTime(), day);
+ // 查询出差表
+ List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime());
+ for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) {
+ // 上午/下午
+ if (attendanceBusinessTravel.getTravelStartTime().toLocalDateTime().isBefore(attendance.getRosteringLunchStartTime().toLocalDateTime()) && attendanceBusinessTravel.getTravelEndTime().toLocalDateTime().compareTo(attendance.getRosteringLunchStartTime().toLocalDateTime()) <= 0) {
+ getMornOrNoon(user, attendance, attendDate, attendance.getRosteringWorkStartTime(), attendance.getRosteringLunchEndTime(), day);
+ } else if (attendanceBusinessTravel.getTravelStartTime().toLocalDateTime().compareTo(attendance.getRosteringLunchEndTime().toLocalDateTime()) >= 0 && attendanceBusinessTravel.getTravelEndTime().toLocalDateTime().compareTo(attendance.getRosteringWorkEndTime().toLocalDateTime()) <= 0) {
+ getMornOrNoon(user, attendance, attendDate, attendance.getRosteringLunchStartTime(), attendance.getRosteringWorkEndTime(), day);
+ } else {
+ getMornOrNoon(user, attendance, attendDate, attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), day);
+ }
}
// 查询外出表
List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
@@ -508,7 +517,7 @@
// 查询考勤请假表
List<AttendanceLeave> attendanceLeaveList = attendanceLeaveRepository.findByUserIdAndDate(user.getId(), startDate.toLocalDateTime(), endDate.toLocalDateTime());
// 查询考勤出差表
- AttendanceBusinessTravel attendanceBusinessTravel = attendanceBusinessTravelRepository.findByUserAndDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime(), attendance.getAttendanceDate().toLocalDateTime());
+ List<AttendanceBusinessTravel> attendanceBusinessTravelList = attendanceBusinessTravelRepository.findByUserAndSEDate(user.getId(), attendance.getAttendanceDate().toLocalDateTime().withHour(0).withMinute(0).withSecond(0).withNano(0), attendance.getAttendanceDate().toLocalDateTime().withHour(23).withMinute(59).withSecond(59).withNano(999));
// 查询考勤外出表
List<AttendanceGoOut> attendanceGoOutList = attendanceGoOutRepository.findByUserAndDate(user.getId(), attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
@@ -525,13 +534,15 @@
// 调用方法修改考勤打卡状态
updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_GOOUT, day, outStartDuration, outEndDuration);
}
- if (ObjectUtils.isNotEmpty(attendanceBusinessTravel)) {
+ if (attendanceBusinessTravelList.size() > 0) {
// 统计出差
Double bussStartDuration = new Double(0.00); // 上午时长
Double bussEndDuration = new Double(0.00); // 下午时长
- // 上午时长、下午时长
- bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance);
- bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance);
+ for (AttendanceBusinessTravel attendanceBusinessTravel : attendanceBusinessTravelList) {
+ // 上午时长、下午时长
+ bussStartDuration += getStartDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance);
+ bussEndDuration += getEndDuration(attendanceBusinessTravel.getTravelStartTime(), attendanceBusinessTravel.getTravelEndTime(), attendance);
+ }
// 调用方法修改考勤打卡状态
updateAttendanceRecord(null, attendance, Constant.ATTENDANCE_STATE_BUSINESS, day, bussStartDuration, bussEndDuration);
}
@@ -704,12 +715,6 @@
if (ObjectUtils.isNotEmpty(attendance.getActualWorkStartTime()) && attendance.getActualWorkStartTime().compareTo(attendance.getRosteringLunchStartTime()) <= 0) {
Integer actualTime = calculateTimes(attendance.getActualWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime());
result1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
- } else if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
- // 因出差的特殊性(不需打卡),所以时长按照排班时间计算
- if (ObjectUtils.isNotEmpty(attendance.getRosteringWorkStartTime()) && attendance.getRosteringWorkStartTime().compareTo(attendance.getRosteringLunchStartTime()) <= 0) {
- Integer actualTime = calculateTimes(attendance.getRosteringWorkStartTime().toLocalDateTime(), attendance.getRosteringLunchStartTime().toLocalDateTime());
- result1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
- }
}
// 下午休排班结束时间到下午排班结束时间的时长
Integer workNoonTime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
@@ -719,13 +724,8 @@
if (ObjectUtils.isNotEmpty(attendance.getActualWorkEndTime()) && attendance.getActualWorkEndTime().compareTo(attendance.getRosteringLunchEndTime()) >= 0) {
Integer actualTime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getActualWorkEndTime().toLocalDateTime());
noonResult1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
- } else if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS) || attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_BUSINESS)) {
- // 因出差的特殊性(不需打卡),所以时长按照排班时间计算
- if (ObjectUtils.isNotEmpty(attendance.getRosteringWorkEndTime()) && attendance.getRosteringWorkEndTime().compareTo(attendance.getRosteringLunchEndTime()) >= 0) {
- Integer actualTime = calculateTimes(attendance.getRosteringLunchEndTime().toLocalDateTime(), attendance.getRosteringWorkEndTime().toLocalDateTime());
- noonResult1 = Double.valueOf(new BigDecimal((float) actualTime / 3600).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
- }
}
+
// 没打卡的情况下,修改考勤打卡状态
if (attendance.getStartClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED) && attendance.getEndClockResults().equals(Constant.ATTENDANCE_STATE_NOTSIGNED)) {
// duration为null说明是考勤信息按钮
@@ -1094,6 +1094,39 @@
/**
* 发送企微每周报告
*/
+ public void remindWeeklyReport() {
+ // 校验当天
+ LocalDate todayDate = LocalDate.now();
+ SysConfigHoliday todayHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(todayDate.toString());
+ if (isNonWorkingDay(todayDate, todayHolidayConfig)) {
+ return;
+ }
+
+ // 校验第二天
+ LocalDate tomorrowDate = todayDate.plusDays(1);
+ SysConfigHoliday tomorrowHolidayConfig = sysConfigHolidayRepository.findByHolidayDate(tomorrowDate.toString());
+ if (isWorkingDay(tomorrowDate, tomorrowHolidayConfig)) {
+ return;
+ }
+
+ try {
+ // 获取企微机器人参数
+ Map<String, String> robotParamMap = dictDetailRepository.findByDictName(Constant.WECOM_ROBOT_PARAM).stream().collect(Collectors.toMap(DictDetail::getLabel, DictDetail::getValue));
+ if (robotParamMap.containsKey(Constant.REMIND_REPORT_WEBHOOK_KEY) && robotParamMap.containsKey(Constant.REMIND_REPORT_MSG)) {
+ // 发送消息
+ WxCpDefaultConfigImpl wxCpDefaultConfig = new WxCpDefaultConfigImpl();
+ wxCpDefaultConfig.setWebhookKey(robotParamMap.get(Constant.REMIND_REPORT_WEBHOOK_KEY));
+ wxCpService.setWxCpConfigStorage(wxCpDefaultConfig);
+ wxCpService.getGroupRobotService().sendText(robotParamMap.get(Constant.REMIND_REPORT_MSG), Arrays.asList("@all"), Arrays.asList());
+ }
+ } catch (WxErrorException wxErrorException) {
+ wxErrorException.printStackTrace();
+ }
+ }
+
+ /**
+ * 发送企微每周报告
+ */
public void toWecomSheetPushReport() {
// 校验当天
LocalDate todayDate = LocalDate.now();
@@ -1116,6 +1149,7 @@
// 个人报告
UserQueryCriteria userQueryCriteria = new UserQueryCriteria();
userQueryCriteria.setEnabled(true);
+ userQueryCriteria.setWeComIdNotNull(true);
userQueryCriteria.getDeptIds().add(7L);
// 先查找是否存在子节点
List<Dept> data = deptService.findByPid(7L);
@@ -1126,6 +1160,7 @@
// 项目报告
ProjectQueryCriteria projectQueryCriteria = new ProjectQueryCriteria();
+ projectQueryCriteria.setProjectDistinguish(Constant.PROJECT_DISTINGUISH_PRODUCT);
projectQueryCriteria.setProjectStatusIn(Arrays.asList(Constant.PROJECT_STATUS_NOT_STARTED, Constant.PROJECT_STATUS_UNDER_WAY));
List<Long> projectIds = projectRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, projectQueryCriteria, criteriaBuilder)).stream().map(p -> p.getId()).collect(Collectors.toList());
toWeComSheetPushProjectReport(projectIds);
@@ -1175,6 +1210,8 @@
sheetQueryRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID));
WxCpSheetInfo sheetInfo = wxCpOaWeDocSmartsheetService.sheetInfo(sheetQueryRequest);
Gson gson = new Gson();
+ // 特殊参数:开发-公共事务、公司-公共事务的项目名称细化到任务详情一级
+ Set<Long> specialProjectType = new HashSet<>(Arrays.asList(46L, 47L));
for (Long userId : userIds) {
// 查询用户信息
@@ -1188,7 +1225,8 @@
// 开始查询
List<TaskDaliyMongo> daliyMongoList = mongoTemplate.find(query, TaskDaliyMongo.class);
- List<TaskDaliyMongoDto> daliyMongoDtoList = daliyMongoList.stream().collect(
+ // TODO:本段代码Collectors.reducing修改了源数据,需要处理前用map深拷贝对象再操作
+ List<TaskDaliyMongoDto> daliyMongoDtoList = daliyMongoList.stream().map(i -> SerializationUtils.clone(i)).collect(
Collectors.groupingBy(
(TaskDaliyMongo taskDaliyMongo) -> {
Project project;
@@ -1199,7 +1237,7 @@
projectMap.put(taskDaliyMongo.getTaskUserMongo().getTask().getProjectId(), project);
}
- if (project.getProjectTypeId().equals(46L) || project.getProjectTypeId().equals(47L)) {
+ if (specialProjectType.contains(project.getProjectTypeId())) {
return "task_" + taskDaliyMongo.getTaskUserMongo().getTask().getId();
} else {
return "project_" + taskDaliyMongo.getTaskUserMongo().getTask().getProjectId();
@@ -1236,26 +1274,31 @@
return dto;
}).sorted(Comparator.comparing(TaskDaliyMongoDto::getProjectId)).collect(Collectors.toList());
- // 统计请假加班信息
+ // 统计请假信息
AttendanceLeaveQueryCriteria leaveQueryCriteria = new AttendanceLeaveQueryCriteria();
leaveQueryCriteria.setUserId(userId);
+ leaveQueryCriteria.setApprovalStatus(Constant.APPROVAL_STATUS_PASSED);
leaveQueryCriteria.setLeaveStartTimeGreaterThan(leaveQueryStartTime);
leaveQueryCriteria.setLeaveEndTimeLessThan(leaveQueryEndTime);
List<AttendanceLeave> leaveList = attendanceLeaveRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,leaveQueryCriteria,criteriaBuilder));
- Double leaveCountHour = leaveList.stream().map(leave -> {
+ BigDecimal leaveCountHour = leaveList.stream().map(leave -> {
if (leave.getLeaveDurationUnit().equals(Constant.LEAVE_TIME_TYPE_DAY)) {
return new BigDecimal(8).multiply(new BigDecimal(leave.getLeaveDuration()));
} else {
return new BigDecimal(leave.getLeaveDuration());
}
- }).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur)).doubleValue();
- // 统计请假加班信息
+ }).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur));
+ // 统计换休信息
AttendanceOvertimeQueryCriteria overtimeQueryCriteria = new AttendanceOvertimeQueryCriteria();
overtimeQueryCriteria.setUserId(userId);
+ overtimeQueryCriteria.setApprovalStatus(Constant.OVERTIME_PASS);
overtimeQueryCriteria.setOvertimeStartTimeGreaterThan(overtimeQueryStartTime);
overtimeQueryCriteria.setOvertimeEndTimeLessThan(overtimeQueryEndTime);
List<AttendanceOvertime> overtimeList = attendanceOvertimeRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,overtimeQueryCriteria,criteriaBuilder));
- Double overtimeCountHour = overtimeList.stream().map(overtime -> new BigDecimal(overtime.getOvertimeDuration())).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur)).doubleValue();
+ BigDecimal overtimeCountHour = overtimeList.stream().map(overtime -> new BigDecimal(overtime.getOvertimeDuration())).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur));
+ // 统计加班信息
+ BigDecimal workOvertimeCountHour = daliyMongoList.stream().collect(Collectors.groupingBy(TaskDaliyMongo::getFillDate, Collectors.summingDouble(TaskDaliyMongo::getConsumedHours)))
+ .values().stream().map(i -> new BigDecimal(i).subtract(new BigDecimal(8)).max(BigDecimal.ZERO)).reduce(BigDecimal.ZERO, (res, cur) -> res.add(cur));
// 项目周报
SheetProperties weeklyReportProjectSheet = sheetInfo.getSheetList().stream().reduce(null, (res, cur) -> cur.getTitle().equals(reportParamMap.get(Constant.WEEKLY_REPORT_PROJECT_SHEET_NAME)) ? cur : res);
@@ -1277,15 +1320,20 @@
Map<String, List<Record>> filterRecordMap = daliyMongoDtoList.stream().map(item -> {
Record record = recordInfo.getRecords().stream().filter(r -> {
LocalDate createDate = Instant.ofEpochMilli(Long.parseLong(r.getValues().get("提交日期").toString())).atZone(ZoneId.systemDefault()).toLocalDate();
- List<RecordOption> projectNames = ((List<?>) r.getValues().get("项目名称")).stream().map(o -> RecordOption.fromJson(gson.toJson(o))).collect(Collectors.toList());
- List<RecordCellUserValue> submitters = ((List<?>) r.getValues().get("提交人")).stream().map(o -> RecordCellUserValue.fromJson(gson.toJson(o))).collect(Collectors.toList());
- return createDate.equals(endTime.toLocalDateTime().toLocalDate()) && projectNames.get(0).getText().equals(item.getProjectName()) && submitters.get(0).getUserId().equals(item.getUserNickName());
+ RecordOption projectNameRecord = ((List<?>) r.getValues().get("项目名称")).stream().map(o -> RecordOption.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordOption::new);
+ RecordCellUserValue submitterRecord = ((List<?>) r.getValues().get("提交人")).stream().map(o -> RecordCellUserValue.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordCellUserValue::new);
+ String projectName = specialProjectType.contains(projectMap.get(item.getProjectId()).getProjectTypeId()) ? item.getProjectName().concat("-").concat(item.getTaskName()) : item.getProjectName();
+ return createDate.equals(endTime.toLocalDateTime().toLocalDate()) && projectNameRecord.getText().equals(projectName) && submitterRecord.getUserId().equals(item.getUserNickName());
}).findFirst().orElseGet(Record::new);
Map<String, Object> values = new HashMap<>(10);
// 项目名称
RecordOption projectName = new RecordOption();
- projectName.setText(item.getProjectName());
+ if (specialProjectType.contains(projectMap.get(item.getProjectId()).getProjectTypeId())) {
+ projectName.setText(item.getProjectName().concat("-").concat(item.getTaskName()));
+ } else {
+ projectName.setText(item.getProjectName());
+ }
values.put("项目名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(projectName)).getValue());
// 项目负责人
RecordCellUserValue projectLeader = new RecordCellUserValue();
@@ -1294,10 +1342,15 @@
// 项目进度
RecordOption projectProgress = new RecordOption();
projectProgress.setText("按期");
+ if (ObjectUtils.isNotEmpty(projectMap.get(item.getProjectId()).getPlanEndDate()) && projectMap.get(item.getProjectId()).getPlanEndDate().toLocalDateTime().toLocalDate().compareTo(LocalDate.parse(item.getFillDate())) < 0) {
+ projectProgress.setText("延迟");
+ }
values.put("项目进度", new Record.TypedValue(Record.DataType.FIELD_TYPE_SELECT, Arrays.asList(projectProgress)).getValue());
// 预计结束日期
- String endTimestamp = String.valueOf(projectRepository.findById(item.getProjectId()).get().getPlanEndDate().getTime());
- values.put("预计结束日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, endTimestamp).getValue());
+ if (ObjectUtils.isNotEmpty(projectMap.get(item.getProjectId()).getPlanEndDate())) {
+ String endTimestamp = String.valueOf(projectMap.get(item.getProjectId()).getPlanEndDate().getTime());
+ values.put("预计结束日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, endTimestamp).getValue());
+ }
// 本周实际投入
values.put("本周实际投入", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, item.getConsumedHours()).getValue());
// 提交人
@@ -1339,7 +1392,7 @@
}
// 假勤周报
- if (!leaveCountHour.equals(0) || !overtimeCountHour.equals(0)) {
+ if (!(leaveCountHour.compareTo(BigDecimal.ZERO) == 0) || !(overtimeCountHour.compareTo(BigDecimal.ZERO) == 0) || !(workOvertimeCountHour.compareTo(BigDecimal.ZERO) == 0)) {
SheetProperties weeklyReportAttendanceSheet = sheetInfo.getSheetList().stream().reduce(null, (res, cur) -> cur.getTitle().equals(reportParamMap.get(Constant.WEEKLY_REPORT_ATTENDANCE_SHEET_NAME)) ? cur : res);
if (ObjectUtils.isNotEmpty(weeklyReportAttendanceSheet)) {
// 获取旧记录
@@ -1358,7 +1411,8 @@
// 制作假勤周报数据
Record record = recordInfo.getRecords().stream().filter(r -> {
LocalDate createDate = Instant.ofEpochMilli(Long.parseLong(r.getValues().get("提交日期").toString())).atZone(ZoneId.systemDefault()).toLocalDate();
- return createDate.equals(endTime.toLocalDateTime().toLocalDate());
+ RecordCellTextValue userNameRecord = ((List<?>) r.getValues().get("人员名称")).stream().map(o -> RecordCellTextValue.fromJson(gson.toJson(o))).findFirst().orElseGet(RecordCellTextValue::new);
+ return user.getNickName().equals(userNameRecord.getText()) && createDate.equals(endTime.toLocalDateTime().toLocalDate());
}).findFirst().orElseGet(Record::new);
Map<String, Object> values = new HashMap<>(3);
// 人员名称
@@ -1367,9 +1421,11 @@
userName.setText(user.getNickName());
values.put("人员名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(userName)).getValue());
// 加班
- values.put("加班(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, overtimeCountHour).getValue());
+ values.put("加班(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, workOvertimeCountHour.doubleValue()).getValue());
+ // 换休
+ values.put("换休(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, overtimeCountHour.doubleValue()).getValue());
// 请假
- values.put("请假(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, leaveCountHour).getValue());
+ values.put("请假(H)", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, leaveCountHour.doubleValue()).getValue());
// 提交日期
String submitTimestamp = String.valueOf(endTime.getTime());
values.put("提交日期", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, submitTimestamp).getValue());
@@ -1401,6 +1457,8 @@
}
} catch (WxErrorException wxErrorException) {
wxErrorException.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
} else {
throw new BadRequestException("企微周报参数缺失");
@@ -1494,15 +1552,17 @@
projectName.setText(project.getName());
values.put("项目名称", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectName)).getValue());
// 项目负责人
- RecordCellTextValue projectLeader = new RecordCellTextValue();
- String leaderName = Arrays.stream(project.getLiableUserId().split(",")).filter(f -> StringUtils.isNotBlank(f)).map(m -> {
- Long userId = Long.parseLong(m.replace("-", ""));
- User user = userRepository.findById(userId).orElseGet(User::new);
- return Optional.ofNullable(user.getNickName()).orElse("");
- }).collect(Collectors.joining(","));
- projectLeader.setType("text");
- projectLeader.setText(leaderName);
- values.put("项目负责人", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectLeader)).getValue());
+ if (StringUtils.isNotBlank(project.getLiableUserId())) {
+ RecordCellTextValue projectLeader = new RecordCellTextValue();
+ String leaderName = Arrays.stream(project.getLiableUserId().split(",")).filter(f -> StringUtils.isNotBlank(f)).map(m -> {
+ Long userId = Long.parseLong(m.replace("-", ""));
+ User user = userRepository.findById(userId).orElseGet(User::new);
+ return Optional.ofNullable(user.getNickName()).orElse("");
+ }).collect(Collectors.joining(","));
+ projectLeader.setType("text");
+ projectLeader.setText(leaderName);
+ values.put("项目负责人", new Record.TypedValue(Record.DataType.FIELD_TYPE_TEXT, Arrays.asList(projectLeader)).getValue());
+ }
// 计划成本
ProjectCostSummary projectCostSummary = projectCostRepository.findSummaryByProjectId(projectId);
List<ProjectCostOther> projectCostOtherList = projectCostOtherRepository.findByProjectId(projectId);
@@ -1521,11 +1581,15 @@
}).reduce(BigDecimal.ZERO, BigDecimal::add);
values.put("实际成本", new Record.TypedValue(Record.DataType.FIELD_TYPE_CURRENCY, actualCost.doubleValue()).getValue());
// 预计开始时间
- String planStartTimestamp = String.valueOf(project.getPlanStartDate().getTime());
- values.put("预计开始时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planStartTimestamp).getValue());
+ if (ObjectUtils.isNotEmpty(project.getPlanStartDate())) {
+ String planStartTimestamp = String.valueOf(project.getPlanStartDate().getTime());
+ values.put("预计开始时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planStartTimestamp).getValue());
+ }
// 预计结束时间
- String planEndTimestamp = String.valueOf(project.getPlanEndDate().getTime());
- values.put("预计结束时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planEndTimestamp).getValue());
+ if (ObjectUtils.isNotEmpty(project.getPlanEndDate())) {
+ String planEndTimestamp = String.valueOf(project.getPlanEndDate().getTime());
+ values.put("预计结束时间", new Record.TypedValue(Record.DataType.FIELD_TYPE_DATE_TIME, planEndTimestamp).getValue());
+ }
// 计划投入人月
BigDecimal planManMonth = taskUserMongoList.stream().map(p -> new BigDecimal(p.getTaskHours())).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(160), 2, BigDecimal.ROUND_CEILING);
values.put("计划投入人月", new Record.TypedValue(Record.DataType.FIELD_TYPE_NUMBER, planManMonth.doubleValue()).getValue());
@@ -1585,7 +1649,7 @@
sheetCreateRequest.setDocId(reportParamMap.get(Constant.WEEKLY_REPORT_DOC_ID));
SheetProperties sheetProperties = new SheetProperties();
sheetProperties.setTitle(project.getName());
- sheetProperties.setIndex(4);
+ sheetProperties.setIndex(3);
sheetCreateRequest.setProperties(sheetProperties);
// 执行新建项目独立报告Sheet
WxCpSheetCreateData sheetCreateData = wxCpOaWeDocSmartsheetService.sheetCreate(sheetCreateRequest);
@@ -1606,6 +1670,29 @@
taskId.setFieldTitle("任务ID");
taskId.setFieldType("FIELD_TYPE_TEXT");
fieldList.add(taskId);
+ // 优先级
+ Field taskLevel = new Field();
+ taskLevel.setFieldTitle("优先级");
+ taskLevel.setFieldType("FIELD_TYPE_SINGLE_SELECT");
+ SingleSelectFieldProperty taskLevelProp = new SingleSelectFieldProperty();
+ taskLevelProp.setIsQuickAdd(false);
+ FieldOption highOption = new FieldOption();
+ highOption.setText("高");
+ highOption.setStyle(18);
+ FieldOption mediumOption = new FieldOption();
+ mediumOption.setText("中");
+ mediumOption.setStyle(23);
+ FieldOption lowOption = new FieldOption();
+ lowOption.setText("低");
+ lowOption.setStyle(14);
+ taskLevelProp.setOptions(Arrays.asList(highOption, mediumOption, lowOption));
+ taskLevel.setPropertySingleSelect(taskLevelProp);
+ fieldList.add(taskLevel);
+ // 备注
+ Field remark = new Field();
+ remark.setFieldTitle("备注");
+ remark.setFieldType("FIELD_TYPE_TEXT");
+ fieldList.add(remark);
// 完成度
Field completePercent = new Field();
completePercent.setFieldTitle("完成度");
@@ -1905,6 +1992,8 @@
}
} catch (WxErrorException wxErrorException) {
wxErrorException.printStackTrace();
+ } catch (Exception e) {
+ e.printStackTrace();
}
} else {
throw new BadRequestException("企微项目WBS及独立报告参数缺失");
--
Gitblit v1.9.3