| | |
| | | package com.xiaopeng.maintenance.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.dto.pushMessage.AliPushMessageDTO; |
| | | import com.xiaopeng.api.feignClient.account.XpOperationUserClient; |
| | | import com.xiaopeng.api.feignClient.account.XpOperationUserNotificationClient; |
| | | import com.xiaopeng.api.feignClient.maintenance.XpCheckLocationClient; |
| | | import com.xiaopeng.api.feignClient.pushMessage.XpAliPushMessageClient; |
| | | import com.xiaopeng.api.feignClient.pushMessage.XpPushMessageClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetClient; |
| | | import com.xiaopeng.api.feignClient.vehicleConvoy.XpFleetOperationsClient; |
| | | import com.xiaopeng.api.model.account.XpOperationsUser;import com.xiaopeng.api.model.maintenance.*; |
| | | import com.xiaopeng.api.model.account.XpOperationsUser; |
| | | import com.xiaopeng.api.model.account.XpOperationsUserNotification; |
| | | import com.xiaopeng.api.model.maintenance.*; |
| | | import com.xiaopeng.api.model.vehicleConvoy.XpFleet; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.enums.NotificationTypeEnum; |
| | | import com.xiaopeng.common.core.utils.poi.ExcelUtil; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.maintenance.dto.ExportSchedulingDetailDto; |
| | |
| | | import java.time.format.TextStyle; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | private XpFleetOperationsClient xpFleetOperationsClient; |
| | | @Resource |
| | | private XpOperationUserClient xpOperationUserClient; |
| | | @Resource |
| | | private XpAliPushMessageClient xpAliPushMessageClient; |
| | | @Resource |
| | | private XpOperationUserNotificationClient xpOperationUserNotificationClient; |
| | | |
| | | @Override |
| | | public ShiftAttendanceVO shiftAttendance(ShiftAttendanceDTO dto) { |
| | |
| | | //构建排班明细数据 |
| | | List<SaveSchedulingDetailVo> datas = vo.getDatas(); |
| | | List<XpSchedulingDetail> schedulingDetails = new ArrayList<>(); |
| | | //存放推送消息 |
| | | List<AliPushMessageDTO> pushMessage = new ArrayList<>(); |
| | | //存放通知数据 |
| | | List<XpOperationsUserNotification> notifications = new ArrayList<>(); |
| | | for (SaveSchedulingDetailVo data : datas) { |
| | | Long fleetId = data.getFleetId(); |
| | | List<SaveSchedulingDetailDay> days = data.getDays(); |
| | |
| | | for (XpOperationsUser xpOperationsUser : data1) { |
| | | String nickName = xpOperationsUser.getNickName(); |
| | | String message = nickName + "请注意," + month + "你的排班由" + xpShift1.getShiftName() + "变更为了" + xpShift2.getShiftName() + "。详情请联系平台管理员。"; |
| | | |
| | | //构建消息推送对象 |
| | | AliPushMessageDTO aliPushMessageDTO = buildPushMessage(message, xpOperationsUser); |
| | | pushMessage.add(aliPushMessageDTO); |
| | | //构建消息存储 |
| | | XpOperationsUserNotification operationsUserNotification = buildXpOperationsUserNotification(message, aliPushMessageDTO.getBody(), xpOperationsUser); |
| | | notifications.add(operationsUserNotification); |
| | | } |
| | | } |
| | | } |
| | |
| | | if(schedulingDetails.isEmpty()){ |
| | | this.saveOrUpdateBatch(schedulingDetails); |
| | | } |
| | | //异步处理消息通知数据 |
| | | pushMessage(pushMessage, notifications); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构建推送消息对象 |
| | | * @param message |
| | | * @param xpOperationsUser |
| | | * @return |
| | | */ |
| | | private AliPushMessageDTO buildPushMessage(String message, XpOperationsUser xpOperationsUser){ |
| | | JSONObject body = new JSONObject(); |
| | | body.put("content", message); |
| | | body.put("strategy", 4); |
| | | body.put("type", 0); |
| | | body.put("id", 0); |
| | | |
| | | AliPushMessageDTO aliPushMessageDTO = new AliPushMessageDTO(); |
| | | aliPushMessageDTO.setDeviceType(xpOperationsUser.getDeviceType()); |
| | | aliPushMessageDTO.setAccount(xpOperationsUser.getPhoneNumber()); |
| | | aliPushMessageDTO.setTitle("排班变更提示"); |
| | | aliPushMessageDTO.setBody(body.toJSONString()); |
| | | aliPushMessageDTO.setPushType("NOTICE"); |
| | | return aliPushMessageDTO; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 构建消息存储 |
| | | * @param body |
| | | * @param xpOperationsUser |
| | | * @return |
| | | */ |
| | | private XpOperationsUserNotification buildXpOperationsUserNotification(String message, String body, XpOperationsUser xpOperationsUser){ |
| | | XpOperationsUserNotification operationsUserNotification = new XpOperationsUserNotification(); |
| | | operationsUserNotification.setNotificationType(NotificationTypeEnum.SCHEDULE_CHANGED.getCode()); |
| | | operationsUserNotification.setNotificationContent(message); |
| | | operationsUserNotification.setOperationsUserId(xpOperationsUser.getId()); |
| | | operationsUserNotification.setReadStatus(0); |
| | | operationsUserNotification.setNotificationExt(body); |
| | | return operationsUserNotification; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 异步处理消息推送 |
| | | * @param pushMessage |
| | | * @param notifications |
| | | */ |
| | | private void pushMessage(List<AliPushMessageDTO> pushMessage, List<XpOperationsUserNotification> notifications) { |
| | | if(pushMessage.isEmpty()){ |
| | | return; |
| | | } |
| | | ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | executor.execute(() -> { |
| | | xpOperationUserNotificationClient.addNotificationBatch(notifications); |
| | | for (AliPushMessageDTO aliPushMessageDTO : pushMessage) { |
| | | xpAliPushMessageClient.pushMessage(aliPushMessageDTO); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 导出排班数据 |
| | | * @param month |
| | | * @param response |