| | |
| | | import com.sinata.appointment.constants.IntegrationConstant; |
| | | import com.sinata.appointment.constants.QrcodeTicketStatus; |
| | | import com.sinata.appointment.constants.SystemSettingKeys; |
| | | import com.sinata.appointment.config.HikvisionQrcodeProperties; |
| | | import com.sinata.appointment.entity.ApprovalInstance; |
| | | import com.sinata.appointment.entity.ApprovalTask; |
| | | import com.sinata.appointment.entity.AppointmentOrder; |
| | | import com.sinata.appointment.entity.AppointmentVisitor; |
| | | import com.sinata.appointment.entity.AppointmentVehicle; |
| | | import com.sinata.appointment.entity.BizVisitReason; |
| | | import com.sinata.appointment.entity.MpUser; |
| | | import com.sinata.appointment.entity.MpVisitor; |
| | | import com.sinata.appointment.entity.QrcodeTicket; |
| | | import com.sinata.appointment.mapper.AppointmentOrderMapper; |
| | | import com.sinata.appointment.mapper.AppointmentVehicleMapper; |
| | | import com.sinata.appointment.mapper.AppointmentVisitorMapper; |
| | | import com.sinata.appointment.mapper.ApprovalInstanceMapper; |
| | | import com.sinata.appointment.mapper.ApprovalTaskMapper; |
| | |
| | | private final ApprovalInstanceMapper approvalInstanceMapper; |
| | | private final ApprovalTaskMapper approvalTaskMapper; |
| | | private final AppointmentVisitorMapper appointmentVisitorMapper; |
| | | private final AppointmentVehicleMapper appointmentVehicleMapper; |
| | | private final MpVisitorMapper mpVisitorMapper; |
| | | private final MpUserMapper mpUserMapper; |
| | | private final BizVisitReasonMapper bizVisitReasonMapper; |
| | | private final SysBizSettingCacheService sysBizSettingCacheService; |
| | | private final HikvisionQrcodeProperties hikvisionQrcodeProperties; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void onOrderFullyApproved(AppointmentOrder order) { |
| | |
| | | .eq(AppointmentVisitor::getDelFlag, 0) |
| | | .eq(AppointmentVisitor::getOrderId, order.getId()) |
| | | .orderByAsc(AppointmentVisitor::getId)); |
| | | Map<Long, String> driverPlateMap = loadDriverPlateMap(order.getId()); |
| | | Map<Long, MpVisitor> visitorProfileMap = loadVisitorProfileMap(visitors); |
| | | Map<Long, QrcodeTicket> existingTicketMap = loadActiveUnusedTicketMap(order.getId(), visitors); |
| | | int validMinutes = getMaxConsecutiveDays() * 24 * 60; |
| | | int validMinutes = resolveValidMinutes(); |
| | | LocalDateTime generateTime = resolveGenerateTime(order); |
| | | LocalDateTime expireTime = generateTime.plusMinutes(validMinutes); |
| | | String visitPurpose = buildVisitPurpose(order); |
| | |
| | | continue; |
| | | } |
| | | MpVisitor visitorProfile = visitorProfileMap.get(visitor.getMpVisitorId()); |
| | | visitor.setPlateNo(driverPlateMap.get(visitor.getMpVisitorId())); |
| | | String ticketUuid = UUID.randomUUID().toString().replace("-", ""); |
| | | String visitorIdCardPlain = resolveVisitorIdCardPlain(visitor, visitorProfile); |
| | | String payload = |
| | |
| | | existingTicketMap.put(visitor.getMpVisitorId(), ticket); |
| | | createdCount++; |
| | | log.info( |
| | | "{} raw-payload orderId={} mpVisitorId={} payload={}", |
| | | "{} raw-payload orderId={} mpVisitorId={} ticketUuid={} payloadLength={}", |
| | | IntegrationConstant.HIKVISION_QRCODE_EVENT, |
| | | order.getId(), |
| | | visitor.getMpVisitorId(), |
| | | payload); |
| | | ticketUuid, |
| | | payload == null ? 0 : payload.length()); |
| | | } |
| | | |
| | | if (visitors.isEmpty()) { |
| | |
| | | return result; |
| | | } |
| | | |
| | | private Map<Long, String> loadDriverPlateMap(Long orderId) { |
| | | if (orderId == null) { |
| | | return Map.of(); |
| | | } |
| | | List<AppointmentVehicle> rows = |
| | | appointmentVehicleMapper.selectList( |
| | | new LambdaQueryWrapper<AppointmentVehicle>() |
| | | .eq(AppointmentVehicle::getDelFlag, 0) |
| | | .eq(AppointmentVehicle::getOrderId, orderId) |
| | | .orderByAsc(AppointmentVehicle::getId)); |
| | | if (rows.isEmpty()) { |
| | | return Map.of(); |
| | | } |
| | | Map<Long, List<String>> grouped = new LinkedHashMap<>(); |
| | | for (AppointmentVehicle row : rows) { |
| | | if (row.getDriverVisitorId() == null || !StringUtils.hasText(row.getPlateNo())) { |
| | | continue; |
| | | } |
| | | grouped.computeIfAbsent(row.getDriverVisitorId(), key -> new java.util.ArrayList<>()).add(row.getPlateNo().trim()); |
| | | } |
| | | Map<Long, String> result = new LinkedHashMap<>(); |
| | | for (Map.Entry<Long, List<String>> entry : grouped.entrySet()) { |
| | | result.put(entry.getKey(), String.join(",", entry.getValue())); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private Map<Long, QrcodeTicket> loadActiveUnusedTicketMap(Long orderId, List<AppointmentVisitor> visitors) { |
| | | if (orderId == null || visitors == null || visitors.isEmpty()) { |
| | | return new LinkedHashMap<>(); |
| | |
| | | } |
| | | } |
| | | |
| | | private int resolveValidMinutes() { |
| | | Integer configured = hikvisionQrcodeProperties.getValidMinutes(); |
| | | if (configured != null && configured > 0) { |
| | | return configured; |
| | | } |
| | | return getMaxConsecutiveDays() * 24 * 60; |
| | | } |
| | | |
| | | private String buildVisitPurpose(AppointmentOrder order) { |
| | | String code = trimToNull(order.getVisitReasonCode()); |
| | | if (!StringUtils.hasText(code)) { |
| | | return ""; |
| | | } |
| | | if (AppointmentBizConstants.VISIT_REASON_OTHER.equalsIgnoreCase(code)) { |
| | | String other = trimToNull(order.getVisitReasonOther()); |
| | | return StringUtils.hasText(other) ? "其他-" + other : "其他"; |
| | | return "其他"; |
| | | } |
| | | BizVisitReason reason = |
| | | bizVisitReasonMapper.selectOne( |