| | |
| | | import com.xiaopeng.maintenance.service.IXpSchedulingService; |
| | | import com.xiaopeng.maintenance.service.IXpShiftService; |
| | | import com.xiaopeng.maintenance.vo.*; |
| | | import org.apache.poi.hssf.usermodel.*; |
| | | import org.apache.poi.ss.usermodel.CellType; |
| | | import org.apache.poi.ss.usermodel.HorizontalAlignment; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | |
| | | /** |
| | | * 给每天的字段赋值 |
| | | * |
| | | * @param day |
| | | * @param dto |
| | | * @param map |
| | |
| | | |
| | | /** |
| | | * 给每天的字段赋值 |
| | | * |
| | | * @param day |
| | | * @param dto |
| | | * @param shiftName |
| | |
| | | List<XpSchedulingDetail> list = this.list(new QueryWrapper<XpSchedulingDetail>().eq("is_deleted", 0).last(" and DATE_FORMAT(plan_time,'%Y-%m') = '" + month + "'")); |
| | | //保存排班数据 |
| | | XpScheduling xpScheduling = xpSchedulingService.getOne(new QueryWrapper<XpScheduling>().eq("is_deleted", 0).last(" and DATE_FORMAT(scheduling_date,'%Y-%m') = '" + month + "'")); |
| | | if(null == xpScheduling){ |
| | | if (null == xpScheduling) { |
| | | xpScheduling = new XpScheduling(); |
| | | xpScheduling.setDeleted(false); |
| | | xpScheduling.setCreateTime(LocalDateTime.now()); |
| | |
| | | && s.getPlanTime().equals(parse) |
| | | ).findAny().orElse(null); |
| | | //构建存储对象 |
| | | if(null == schedulingDetail){ |
| | | if (null == schedulingDetail) { |
| | | schedulingDetail = new XpSchedulingDetail(); |
| | | schedulingDetail.setCreateBy(userId.toString()); |
| | | schedulingDetail.setCreateTime(LocalDateTime.now()); |
| | | schedulingDetail.setUpdateBy(userId.toString()); |
| | | schedulingDetail.setUpdateTime(LocalDateTime.now()); |
| | | schedulingDetail.setDeleted(false); |
| | | }else{ |
| | | } else { |
| | | //构建通知消息 |
| | | Long old_shiftId = schedulingDetail.getShiftId(); |
| | | if(!old_shiftId.equals(shiftId)){ |
| | | if (!old_shiftId.equals(shiftId)) { |
| | | //获取车队的所有人员 |
| | | XpShift xpShift1 = xpShifts.stream().filter(s -> s.getId().equals(old_shiftId)).findAny().orElse(null); |
| | | XpShift xpShift2 = xpShifts.stream().filter(s -> s.getId().equals(shiftId)).findAny().orElse(null); |
| | | |
| | | List<Long> operationsIds = xpFleetOperationsClient.getOperationsIdsByFleetId(fleetId).getData(); |
| | | if(null != operationsIds && !operationsIds.isEmpty()){ |
| | | if (null != operationsIds && !operationsIds.isEmpty()) { |
| | | List<XpOperationsUser> data1 = xpOperationUserClient.listByIds(operationsIds).getData(); |
| | | for (XpOperationsUser xpOperationsUser : data1) { |
| | | String nickName = xpOperationsUser.getNickName(); |
| | |
| | | schedulingDetail.setShiftId(shiftId); |
| | | |
| | | XpShift xpShift = xpShifts.stream().filter(s -> s.getId().equals(shiftId)).findAny().orElse(null); |
| | | if(null != xpShift){ |
| | | if (null != xpShift) { |
| | | schedulingDetail.setIsAllDay(xpShift.getShiftName().contains("全天")); |
| | | schedulingDetail.setPlanTime(parse); |
| | | schedulingDetails.add(schedulingDetail); |
| | |
| | | } |
| | | } |
| | | //批量保存排班明细数据 |
| | | if(!schedulingDetails.isEmpty()){ |
| | | if (!schedulingDetails.isEmpty()) { |
| | | this.saveOrUpdateBatch(schedulingDetails); |
| | | } |
| | | //异步处理消息通知数据 |
| | |
| | | |
| | | /** |
| | | * 构建推送消息对象 |
| | | * |
| | | * @param message |
| | | * @param xpOperationsUser |
| | | * @return |
| | | */ |
| | | private AliPushMessageDTO buildPushMessage(String message, XpOperationsUser xpOperationsUser){ |
| | | private AliPushMessageDTO buildPushMessage(String message, XpOperationsUser xpOperationsUser) { |
| | | JSONObject body = new JSONObject(); |
| | | body.put("content", message); |
| | | body.put("strategy", 4); |
| | |
| | | |
| | | /** |
| | | * 构建消息存储 |
| | | * |
| | | * @param body |
| | | * @param xpOperationsUser |
| | | * @return |
| | | */ |
| | | private XpOperationsUserNotification buildXpOperationsUserNotification(String message, String body, XpOperationsUser xpOperationsUser){ |
| | | private XpOperationsUserNotification buildXpOperationsUserNotification(String message, String body, XpOperationsUser xpOperationsUser) { |
| | | XpOperationsUserNotification operationsUserNotification = new XpOperationsUserNotification(); |
| | | operationsUserNotification.setNotificationType(NotificationTypeEnum.SCHEDULE_CHANGED.getCode()); |
| | | operationsUserNotification.setNotificationContent(message); |
| | |
| | | |
| | | /** |
| | | * 异步处理消息推送 |
| | | * |
| | | * @param pushMessage |
| | | * @param notifications |
| | | */ |
| | | private void pushMessage(List<AliPushMessageDTO> pushMessage, List<XpOperationsUserNotification> notifications) { |
| | | if(pushMessage.isEmpty()){ |
| | | if (pushMessage.isEmpty()) { |
| | | return; |
| | | } |
| | | ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出排班数据 |
| | | * |
| | | * @param month |
| | | * @param response |
| | | */ |
| | |
| | | PageInfo<SchedulingDetailDto> pageInfo = new PageInfo<>(0, 10000); |
| | | List<SchedulingDetailDto> schedulingDetailDtos = this.baseMapper.pageList(pageInfo, month); |
| | | List<ExportSchedulingDetailDto> exportSchedulingDetailDtos = new ArrayList<>(); |
| | | HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); |
| | | // for (int i = 0; i < titles.size(); i++) { |
| | | // HSSFSheet hssfSheet = hssfWorkbook.createSheet(); |
| | | // hssfSheet.setColumnWidth(0, 6 * 256); |
| | | // hssfSheet.setDefaultRowHeightInPoints(20f); |
| | | // |
| | | // HSSFRow hssfRow = hssfSheet.createRow(0);//设置第一行数据(标题) |
| | | // HSSFCellStyle style = hssfWorkbook.createCellStyle(); |
| | | // HSSFFont font = hssfWorkbook.createFont(); |
| | | // font.setBold(true); |
| | | // style.setFont(font); |
| | | // style.setAlignment(HorizontalAlignment.CENTER); |
| | | // for (int l = 0; l < titles.get(i).size(); l++) { |
| | | // HSSFCell hssfCell = hssfRow.createCell(l); |
| | | // hssfCell.setCellType(CellType.STRING);//设置表格类型 |
| | | // hssfCell.setCellValue(titles.get(i).get(l)); |
| | | // hssfCell.setCellStyle(style); |
| | | // hssfSheet.setColumnWidth(l, 20 * 256); |
| | | // } |
| | | // |
| | | // //将数据添加到表格中 |
| | | // List<String> data = null; |
| | | // for (int l = 0; l < datas.get(i).size(); l++) { |
| | | // hssfRow = hssfSheet.createRow(l + 1); |
| | | // data = datas.get(i).get(l); |
| | | // for (int j = 0; j < data.size(); j++) { |
| | | // HSSFCell hssfCell = hssfRow.createCell(j); |
| | | // hssfCell.setCellType(CellType.STRING);//设置表格类型 |
| | | // hssfCell.setCellValue(data.get(j)); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | |
| | | //获取月份的最大天数 |
| | | LocalDate parse1 = LocalDate.parse(month + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | int dayOfMonth = parse1.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth(); |
| | |
| | | for (int i = 1; i <= dayOfMonth; i++) { |
| | | LocalDate parse = LocalDate.parse(month + "-" + String.format("%02d", i), DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | String week = ""; |
| | | switch (parse.getDayOfWeek()){ |
| | | switch (parse.getDayOfWeek()) { |
| | | case MONDAY: |
| | | week = "一"; |
| | | break; |
| | |
| | | exportSchedulingDetailDto.setMorning(morning + ""); |
| | | exportSchedulingDetailDto.setMidDay(midDay + ""); |
| | | exportSchedulingDetailDto.setEvening(evening + ""); |
| | | }else{ |
| | | } else { |
| | | for (int i = 1; i <= 31; i++) { |
| | | String shiftName = "休"; |
| | | setEnglishDay(i, exportSchedulingDetailDto, shiftName); |
| | |
| | | excelUtil.exportExcel(response, exportSchedulingDetailDtos, "排班计划[日期:" + split[0] + "年" + split[1] + "月]"); |
| | | |
| | | } |
| | | |
| | | |
| | | } |