|
|
@@ -53,185 +53,6 @@ public class CreateFiveDailyReportOrderJob implements JobHandler {
|
|
|
@Resource
|
|
|
private DeptService deptService;
|
|
|
|
|
|
- /* @Override
|
|
|
- @TenantIgnore
|
|
|
- public String execute(String param) throws Exception {
|
|
|
-
|
|
|
- // 查询所有瑞都的项目任务 以‘井号-时间’ 为唯一键 当天创建时间 内没有生成过日报 就自动生成
|
|
|
- IotFiveDailyReportPageReqVO pageReqVO = new IotFiveDailyReportPageReqVO();
|
|
|
- PageResult<IotFiveDailyReportDO> dailyReportsPage = iotFiveDailyReportService.getIotFiveDailyReportPage(pageReqVO);
|
|
|
- List<IotFiveDailyReportDO> dailyReports = dailyReportsPage.getList();
|
|
|
-
|
|
|
- LocalDateTime currentDate = LocalDateTime.now();
|
|
|
- String currentFormatDateStr = LocalDateTimeUtil.format(currentDate, "yyyy-MM-dd");
|
|
|
- // 次日的日期
|
|
|
- LocalDateTime nextDay = currentDate.plusDays(1);
|
|
|
- // 需要生成日报的 任务(井号) 集合
|
|
|
- Set<Long> taskIds = new HashSet<>();
|
|
|
- if (CollUtil.isNotEmpty(dailyReports)) {
|
|
|
- dailyReports.forEach(report -> {
|
|
|
- // 查询当天生成的日报
|
|
|
- LocalDateTime createDate = report.getCreateTime();
|
|
|
- String formatDateStr = LocalDateTimeUtil.format(createDate, "yyyy-MM-dd");
|
|
|
- if (formatDateStr.equals(currentFormatDateStr)) {
|
|
|
- taskIds.add(report.getTaskId());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // 查询5#国所有的 施工队伍 key部门id value部门名称
|
|
|
- Map<Long, String> teamPair = new HashMap<>();
|
|
|
- Set<Long> allFiveChildDeptIds = deptService.getChildDeptIdListFromCache(388l);
|
|
|
- if (CollUtil.isNotEmpty(allFiveChildDeptIds)) {
|
|
|
- DeptListReqVO reqVO = new DeptListReqVO();
|
|
|
- reqVO.setDeptIds(allFiveChildDeptIds);
|
|
|
- List<DeptDO> fiveDepartments = deptService.getDeptList(reqVO);
|
|
|
- if (CollUtil.isNotEmpty(fiveDepartments)) {
|
|
|
- fiveDepartments.forEach(dept -> {
|
|
|
- if ("3".equals(dept.getType())) {
|
|
|
- // 组装队伍集合
|
|
|
- teamPair.put(dept.getId(), dept.getName());
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 查询 5#公司 相关的项目任务 根据每个任务的填报人进行工单生成和推送
|
|
|
- IotProjectTaskPageReqVO taskReqVO = new IotProjectTaskPageReqVO();
|
|
|
- taskReqVO.setCompanyId(388l);
|
|
|
- taskReqVO.setJobFlag("Y");
|
|
|
- List<IotProjectTaskDO> tasks = iotProjectTaskService.projectTasks(taskReqVO);
|
|
|
- List<IotProjectTaskDO> qualifiedTasks = new ArrayList<>();
|
|
|
- // 未施工完成的任务id集合
|
|
|
- Set<Long> unfinishedTaskIds = new HashSet<>();
|
|
|
- if (CollUtil.isNotEmpty(tasks)) {
|
|
|
- tasks.forEach(task -> {
|
|
|
- qualifiedTasks.add(task);
|
|
|
- // 生成所有所有未施工完成的任务id集合
|
|
|
- unfinishedTaskIds.add(task.getId());
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- Set<Long> userIds = new HashSet<>();
|
|
|
- List<IotFiveDailyReportDO> reports = new ArrayList<>();
|
|
|
- Map<Long, Long> taskSubmitterPair = new HashMap<>();
|
|
|
- // key任务id value施工队伍id
|
|
|
- Map<Long, Long> taskTeamIdPair = new HashMap<>();
|
|
|
- Set<Long> teamDepartmentIds = new HashSet<>();
|
|
|
- if (CollUtil.isNotEmpty(qualifiedTasks)) {
|
|
|
- qualifiedTasks.forEach(task -> {
|
|
|
- // 查询当前任务的 工单填报人
|
|
|
- Set<Long> submitterIds = task.getResponsiblePerson();
|
|
|
- Set<Long> teamDeptIds = task.getDeptIds();
|
|
|
- if (CollUtil.isNotEmpty(submitterIds)) {
|
|
|
- // 查询工单填报人所在部门
|
|
|
- userIds.addAll(submitterIds);
|
|
|
- taskSubmitterPair.put(task.getId(), new ArrayList<>(submitterIds).get(0));
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(teamDeptIds)) {
|
|
|
- taskTeamIdPair.put(task.getId(), new ArrayList<>(teamDeptIds).get(0));
|
|
|
- teamDepartmentIds.addAll(teamDeptIds);
|
|
|
- }
|
|
|
- });
|
|
|
- // 查询所有任务配置的工单填报人的信息
|
|
|
- Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(userIds);
|
|
|
- Set<Long> deptIds = new HashSet<>();
|
|
|
- if (CollUtil.isNotEmpty(users)) {
|
|
|
- // 统一查询所有用户所属的部门信息
|
|
|
- users.forEach((userId, user) -> {
|
|
|
- deptIds.add(user.getDeptId());
|
|
|
- });
|
|
|
- }
|
|
|
- // 查询所有任务施工队伍的 deptId
|
|
|
- Map<Long, DeptDO> deptPair = deptService.getDeptMap(teamDepartmentIds);
|
|
|
- // 以任务为维度 生成 5#国 日报 部门为任务配置的工单填报人对应的部门
|
|
|
- qualifiedTasks.forEach(task -> {
|
|
|
- if (!taskIds.contains(task.getId()) && CollUtil.isNotEmpty(task.getResponsiblePerson())) {
|
|
|
- // 生成当天的日报
|
|
|
- IotFiveDailyReportDO report = new IotFiveDailyReportDO();
|
|
|
- if (taskSubmitterPair.containsKey(task.getId())) {
|
|
|
- Long userId = taskSubmitterPair.get(task.getId());
|
|
|
- if (users.containsKey(userId)) {
|
|
|
- AdminUserRespDTO user = users.get(userId);
|
|
|
- // 取任务施工队伍的 deptId
|
|
|
- if (taskTeamIdPair.containsKey(task.getId())) {
|
|
|
- report.setDeptId(taskTeamIdPair.get(task.getId()));
|
|
|
- } else {
|
|
|
- report.setDeptId(user.getDeptId());
|
|
|
- }
|
|
|
- // 根据用户部门名称 生成日报标题
|
|
|
- if (deptPair.containsKey(report.getDeptId())) {
|
|
|
- DeptDO dept = deptPair.get(report.getDeptId());
|
|
|
- String deptName = dept.getName();
|
|
|
- String[] multiLangDeptNames = deptName.split("~~");
|
|
|
- report.setReportName(multiLangDeptNames[0] + "/" + currentFormatDateStr + "日报填报" );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 修改开始:创建专门用于日报的日期时间,将时分秒固定为08:00:00
|
|
|
- // 将日期部分保持不变,时间部分设置为08:00:00
|
|
|
- LocalDate currentLocalDate = currentDate.toLocalDate();
|
|
|
- LocalDate nextLocalDate = nextDay.toLocalDate();
|
|
|
-
|
|
|
- LocalDateTime dailyReportStartTime = LocalDateTime.of(currentLocalDate, LocalTime.of(8, 0, 0));
|
|
|
- LocalDateTime dailyReportEndTime = LocalDateTime.of(nextLocalDate, LocalTime.of(8, 0, 0));
|
|
|
-
|
|
|
- report.setProjectId(task.getProjectId());
|
|
|
- report.setTaskId(task.getId());
|
|
|
- report.setDeviceIds(task.getDeviceIds());
|
|
|
- report.setStartTime(LocalTime.of(8, 0, 0));
|
|
|
- report.setEndTime(LocalTime.of(8, 0, 0));
|
|
|
- report.setConstructionStartDate(dailyReportStartTime);
|
|
|
- report.setConstructionEndDate(dailyReportEndTime);
|
|
|
- Set<Long> submitters = task.getResponsiblePerson();
|
|
|
- report.setCreator(String.valueOf(new ArrayList<>(submitters).get(0)));
|
|
|
- report.setCreateTime(LocalDateTime.now());
|
|
|
- reports.add(report);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- if (CollUtil.isNotEmpty(reports)) {
|
|
|
- iotFiveDailyReportService.batchAddDailyReports(reports);
|
|
|
- }
|
|
|
-
|
|
|
- // 向日报 填报人 发送 站内信 钉钉消息
|
|
|
- if (CollUtil.isNotEmpty(reports)) {
|
|
|
- List<IotFiveDailyReportDO> msgReports = new ArrayList<>();
|
|
|
- // 如果日报是平台井 只发送主井任务
|
|
|
- reports.forEach(report -> {
|
|
|
- msgReports.add(report);
|
|
|
- });
|
|
|
- // 先查询所有 日报填报人的手机号
|
|
|
- Set<Long> personIds = new HashSet<>(convertList(msgReports, report -> Long.valueOf(report.getCreator())));
|
|
|
- Map<Long, AdminUserRespDTO> users = adminUserApi.getUserMap(personIds);
|
|
|
- // 建立日报与 用户手机号的 对应关系
|
|
|
- Map<Long, String> orderMobilePair = new HashMap<>();
|
|
|
- msgReports.forEach(report -> {
|
|
|
- if (users.containsKey(Long.valueOf(report.getCreator()))) {
|
|
|
- AdminUserRespDTO user = users.get(Long.valueOf(report.getCreator()));
|
|
|
- orderMobilePair.put(report.getId(), user.getMobile());
|
|
|
- }
|
|
|
- });
|
|
|
- // 异步多线程发送 站内信 钉钉 消息
|
|
|
- msgReports.forEach(order -> {
|
|
|
- CountDownLatch latch = new CountDownLatch(msgReports.size());
|
|
|
- pmsThreadPoolTaskExecutor.execute(() -> {
|
|
|
- try {
|
|
|
- if (orderMobilePair.containsKey(order.getId())) {
|
|
|
- String mobile = orderMobilePair.get(order.getId());
|
|
|
- pmsMessage.sendMessage(order.getId(), order.getReportName(), PmsConstants.DAILY_REPORT,
|
|
|
- Long.valueOf(order.getCreator()), mobile);
|
|
|
- }
|
|
|
- } finally {
|
|
|
- latch.countDown();
|
|
|
- }
|
|
|
- });
|
|
|
- });
|
|
|
- }
|
|
|
- return "创建成功";
|
|
|
- } */
|
|
|
-
|
|
|
@Override
|
|
|
@TenantIgnore
|
|
|
public String execute(String param) throws Exception {
|