| | |
| | | package com.sinata.appointment.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.sinata.appointment.constants.AppointmentFieldCodes; |
| | | import com.sinata.appointment.constants.BizErrorCode; |
| | | import com.sinata.appointment.dto.MiniVisitorCreateRequest; |
| | |
| | | ? SensitiveDataUtil.encryptIdCard(input.idCard()) |
| | | : ""); |
| | | row.setGender(input.gender() == null ? "" : input.gender()); |
| | | row.setIsDefault(hasAnyActiveVisitor(current.getId()) ? 0 : 1); |
| | | mpVisitorMapper.insert(row); |
| | | } |
| | | |
| | |
| | | mpVisitorMapper.updateById(row); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void setDefault(Long id, String uuid) { |
| | | MpUser current = miniAuthApplicationService.currentMpUser(); |
| | | MpVisitor row = loadOwnedVisitor(id, uuid, current.getId()); |
| | | mpVisitorMapper.update( |
| | | null, |
| | | new LambdaUpdateWrapper<MpVisitor>() |
| | | .eq(MpVisitor::getMpUserId, current.getId()) |
| | | .eq(MpVisitor::getDelFlag, 0) |
| | | .set(MpVisitor::getIsDefault, 0)); |
| | | row.setIsDefault(1); |
| | | mpVisitorMapper.updateById(row); |
| | | } |
| | | |
| | | public MiniVisitorDetailVo detail(Long id, String uuid) { |
| | | MpUser current = miniAuthApplicationService.currentMpUser(); |
| | | MpVisitor row = loadOwnedVisitor(id, uuid, current.getId()); |
| | |
| | | ? SensitiveDataUtil.decryptIdCard(row.getIdCardCipher()) |
| | | : ""); |
| | | vo.setGender(row.getGender()); |
| | | vo.setIsDefault(isDefault(row)); |
| | | return vo; |
| | | } |
| | | |
| | |
| | | new LambdaQueryWrapper<MpVisitor>() |
| | | .eq(MpVisitor::getMpUserId, current.getId()) |
| | | .eq(MpVisitor::getDelFlag, 0) |
| | | .orderByDesc(MpVisitor::getIsDefault) |
| | | .orderByDesc(MpVisitor::getCreateTime) |
| | | .orderByDesc(MpVisitor::getId)); |
| | | return rows.stream().map(row -> toListVo(row, requiredCodes)).collect(Collectors.toList()); |
| | |
| | | vo.setIdCardMasked(null); |
| | | } |
| | | vo.setVisitorCompany(row.getVisitorCompany()); |
| | | vo.setIsDefault(isDefault(row)); |
| | | vo.setMissingFieldCodes(resolveMissingFieldCodes(row, requiredCodes)); |
| | | return vo; |
| | | } |
| | | |
| | | private boolean isDefault(MpVisitor row) { |
| | | return row != null && row.getIsDefault() != null && row.getIsDefault() == 1; |
| | | } |
| | | |
| | | private boolean hasAnyActiveVisitor(Long mpUserId) { |
| | | return mpVisitorMapper.selectCount( |
| | | new LambdaQueryWrapper<MpVisitor>() |
| | | .eq(MpVisitor::getMpUserId, mpUserId) |
| | | .eq(MpVisitor::getDelFlag, 0)) |
| | | > 0; |
| | | } |
| | | |
| | | private List<String> resolveMissingFieldCodes(MpVisitor row, Set<String> requiredCodes) { |
| | | List<String> missing = new ArrayList<>(); |
| | | for (String code : requiredCodes) { |