From 92ba31ac12c9ce873dd688f030afeb045532b912 Mon Sep 17 00:00:00 2001 From: lzttt <1803073139@qq.com> Date: Thu, 24 Oct 2024 13:13:41 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=AE=A2=E6=88=B7=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/InspectionInfoServiceImpl.java | 2 +- .../impl/PartnerCustomerInfoServiceImpl.java | 230 +++++++++++++----- .../cn/iocoder/yudao/util/StringUtils.java | 15 ++ 3 files changed, 187 insertions(+), 60 deletions(-) diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java index 36caf35a..04941ab3 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/module/inspection/service/impl/InspectionInfoServiceImpl.java @@ -195,7 +195,7 @@ public class InspectionInfoServiceImpl extends ServiceImpl queryWrapper =new LambdaQueryWrapper<>(); - queryWrapper.eq(PartnerCustomerInfo::getPartnerId,partners.getPartnerId()).eq(PartnerCustomerInfo::getCustomerPhone,partnerCustomerInfo.getCustomerPhone()); + + // 检查客户是否已存在 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(PartnerCustomerInfo::getPartnerId, partners.getPartnerId()) + .eq(PartnerCustomerInfo::getCustomerPhone, partnerCustomerInfo.getCustomerPhone()); + PartnerCustomerInfo customerInfo = this.getOne(queryWrapper); - if (ObjectUtils.isNotEmpty(customerInfo)){ + if (ObjectUtils.isNotEmpty(customerInfo)) { throw new Exception("客户已存在"); } + + // 查找或创建用户 AdminUserDO user = userService.selectUserByPhone(partnerCustomerInfo.getCustomerPhone()); - if (ObjectUtils.isEmpty(user)){ + if (ObjectUtils.isEmpty(user)) { RoleDO role = roleService.queryRole("jcyh"); - - UserSaveReqVO userSaveReqVO = new UserSaveReqVO(); - user = new AdminUserDO(); - BeanUtils.copyProperties(partnerCustomerInfo,user); - userSaveReqVO.setUsername(partnerCustomerInfo.getCustomerPhone()); - userSaveReqVO.setNickname(partnerCustomerInfo.getCustomerName()); - userSaveReqVO.setPassword("123456"); - Long uid = userService.createUser(userSaveReqVO); - user.setId(uid); - Set ids = new HashSet<>(); - ids.add(role.getId()); - permissionService.assignUserRole(uid,ids); - + if (role != null) { + UserSaveReqVO userSaveReqVO = new UserSaveReqVO(); + user = new AdminUserDO(); + BeanUtils.copyProperties(partnerCustomerInfo, user); + userSaveReqVO.setUsername(partnerCustomerInfo.getCustomerPhone()); + userSaveReqVO.setNickname(partnerCustomerInfo.getCustomerName()); + userSaveReqVO.setPassword("123456"); + Long uid = userService.createUser(userSaveReqVO); + user.setId(uid); + Set ids = new HashSet<>(); + ids.add(role.getId()); + permissionService.assignUserRole(uid, ids); + } else { + throw new RuntimeException("无法找到角色 'jcyh'"); + } } - if (!StringUtils.isEmpty(partnerCustomerInfo.getCustomerPhone())&&!StringUtils.isEmpty(partnerCustomerInfo.getRoleCode())){ + + // 角色分配 + if (!StringUtils.isEmpty(partnerCustomerInfo.getRoleCode())) { RoleDO sysRole = roleService.queryRole(partnerCustomerInfo.getRoleCode()); Set ids = new HashSet<>(); ids.add(sysRole.getId()); - permissionService.assignUserRole(user.getId(),ids); - + permissionService.assignUserRole(user.getId(), ids); } + + // 车辆信息处理 List userCarList = partnerCustomerInfo.getUserCarList(); - if (CollectionUtil.isNotEmpty(userCarList)){ + List saveCarList = new ArrayList<>(); + List saveCustomerCarList = new ArrayList<>(); + List saveUserCarList = new ArrayList<>(); + + UserCar userCar1 = new UserCar(); + if (CollectionUtil.isNotEmpty(userCarList)) { for (ShopUserCar shopUserCar : userCarList) { - LambdaQueryWrapper queryWrapper1 =new LambdaQueryWrapper<>(); - queryWrapper1.eq(ShopUserCar::getUserId,user.getId()).eq(ShopUserCar::getCarNo,shopUserCar.getCarNo()); - ShopUserCar one = userCarService.getOne(queryWrapper1); - if (ObjectUtils.isNotEmpty(one)){ - //保养日期 - if (null!=shopUserCar.getMaintenanceDate()){ - one.setMaintenanceDate(shopUserCar.getMaintenanceDate()); - } - if (null!=shopUserCar.getMaintenanceMileage()){ - one.setMaintenanceMileage(shopUserCar.getMaintenanceMileage()); - } - if (null!=shopUserCar.getInspectionDate()){ - one.setInspectionDate(shopUserCar.getInspectionDate()); - } + // 生成车辆ID + String carId = UUID.randomUUID().toString().replace("-", ""); + CarMain carMain = new CarMain(); + carMain.setId(carId); + carMain.setUserId(user.getId()); + carMain.setLicenseNumber(shopUserCar.getCarNo()); + carMain.setEngineNumber(userCar1.getEngineNumber()); + carMain.setVin(userCar1.getVin()); + carMain.setCarModel(shopUserCar.getCarModel()); + // 设置其它车辆信息 + carMain.setMaintenanceDate(convertToLocalDateTime(shopUserCar.getMaintenanceDate())); + carMain.setMaintenanceMileage(convertToBigDecimal(shopUserCar.getMaintenanceMileage())); + carMain.setInspectionDate(convertToLocalDateTime(shopUserCar.getInspectionDate())); + carMain.setInsuranceDate(convertToLocalDateTime(shopUserCar.getInsuranceDate())); + carMain.setNextMaintenanceDate(convertToLocalDateTime(shopUserCar.getNextMaintenanceDate())); + carMain.setNextMaintenanceMileage(convertToBigDecimal(shopUserCar.getNextMaintenanceMileage())); + carMain.setNextInspectionDate(convertToLocalDateTime(shopUserCar.getNextInspectionDate())); + carMain.setInsuranceExpiryDate(convertToLocalDateTime(shopUserCar.getInsuranceExpiryDate())); + carMain.setCarBrand(shopUserCar.getCarBrand()); + carMain.setCarNature(shopUserCar.getCarNature()); + carMain.setCarCategory(userCar1.getCarCategory()); + carMain.setCarRegisterDate(convertToLocalDateTime(shopUserCar.getCarRegisterDate())); + carMain.setCarLicenseImg(shopUserCar.getCarLicenseImg()); + carMain.setCheckDate(convertToLocalDateTime(shopUserCar.getCheckDate())); + carMain.setNextCheckDate(convertToLocalDateTime(shopUserCar.getNextCheckDate())); - if (null!=shopUserCar.getInsuranceDate()){ - one.setInsuranceDate(shopUserCar.getInsuranceDate()); - } - if (null!=shopUserCar.getNextMaintenanceDate()){ - one.setNextMaintenanceDate(shopUserCar.getNextMaintenanceDate()); - } - if (null!=shopUserCar.getNextMaintenanceMileage()){ - one.setNextMaintenanceMileage(shopUserCar.getNextMaintenanceMileage()); - } - if (null!=shopUserCar.getNextInspectionDate()){ - one.setNextInspectionDate(shopUserCar.getNextInspectionDate()); - } - if (null!=shopUserCar.getInsuranceExpiryDate()){ - one.setInsuranceExpiryDate(shopUserCar.getInsuranceExpiryDate()); - } - userCarService.updateById(one); - }else { - shopUserCar.setUserId(user.getId()); - userCarService.save(shopUserCar); - } + // 保存车辆信息 + saveCarList.add(carMain); + // 客户与车辆的关联关系 + CustomerCar customerCar = new CustomerCar(); + customerCar.setId(UUID.randomUUID().toString().replace("-", "")); + customerCar.setCusId(user.getId().toString()); + customerCar.setCarId(carId); + customerCar.setIsOwner(userCar1.getIsOwner()); // 是否为车主 + saveCustomerCarList.add(customerCar); + + // 保存用户车辆信息 + ShopUserCar userCar = new ShopUserCar(); + userCar.setUserId(user.getId()); + userCar.setCarNo(shopUserCar.getCarNo()); + userCar.setCarModel(shopUserCar.getCarModel()); + userCar.setMaintenanceDate(shopUserCar.getMaintenanceDate()); + userCar.setMaintenanceMileage(shopUserCar.getMaintenanceMileage()); + userCar.setInspectionDate(shopUserCar.getInspectionDate()); + userCar.setInsuranceDate(shopUserCar.getInsuranceDate()); + userCar.setNextMaintenanceDate(shopUserCar.getNextMaintenanceDate()); + userCar.setNextMaintenanceMileage(shopUserCar.getNextMaintenanceMileage()); + userCar.setNextInspectionDate(shopUserCar.getNextInspectionDate()); + userCar.setInsuranceExpiryDate(shopUserCar.getInsuranceExpiryDate()); + saveUserCarList.add(userCar); } } + + // 验证手机号 + if (!StringUtils.isMobile(partnerCustomerInfo.getCustomerPhone())) { + throw new Exception("手机号不符合规范"); + } + + // 创建客户信息 + CustomerMain customerMain = new CustomerMain(); + customerMain.setId(UUID.randomUUID().toString().replace("-", "")); + customerMain.setUserId(user.getId()); + customerMain.setCusName(partnerCustomerInfo.getCustomerName()); + customerMain.setPhoneNumber(partnerCustomerInfo.getCustomerPhone()); + customerMain.setSex(partnerCustomerInfo.getSex()); + customerMain.setIsHangAccount("0"); + customerMain.setTypeCode("01"); + // 设置客户初始来源 + customerMain.setDataFrom("01"); + // 设置注册方式 + customerMain.setInviterType("01"); + + // 保存客户信息 + customerMainService.saveOrUpdate(customerMain); + + // 保存车辆信息和客户与车辆关联关系 + carMainService.saveOrUpdateBatch(saveCarList); + customerCarService.saveBatch(saveCustomerCarList); + + // 保存用户车辆信息 + for (ShopUserCar userCar : saveUserCarList) { + // 检查是否已存在 + LambdaQueryWrapper queryWrapper1 = new LambdaQueryWrapper<>(); + queryWrapper1.eq(ShopUserCar::getUserId, userCar.getUserId()).eq(ShopUserCar::getCarNo, userCar.getCarNo()); + ShopUserCar existingUserCar = userCarService.getOne(queryWrapper1); + if (existingUserCar != null) { + // 更新用户车辆信息 + userCarService.updateById(userCar); + } else { + // 保存新用户车辆信息 + userCarService.save(userCar); + } + } + + // 填充 partnerCustomerInfo partnerCustomerInfo.setPartnerId(partners.getPartnerId()); partnerCustomerInfo.setUserId(user.getId()); + + // 插入 partner_customer_info return baseMapper.insertPartnerCustomerInfo(partnerCustomerInfo); } + /* Date转换为LocalDateTime */ + private LocalDateTime convertToLocalDateTime(Date date) { + if (date != null) { + return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); + } + return null; + } + + /* Long转换为BigDecimal */ + private BigDecimal convertToBigDecimal(Long value) { + if (value != null) { + return BigDecimal.valueOf(value); + } + return null; + } + + + + /** * 修改客户信息 * diff --git a/dl-module-inspection/src/main/java/cn/iocoder/yudao/util/StringUtils.java b/dl-module-inspection/src/main/java/cn/iocoder/yudao/util/StringUtils.java index 1995674b..9651b5dc 100644 --- a/dl-module-inspection/src/main/java/cn/iocoder/yudao/util/StringUtils.java +++ b/dl-module-inspection/src/main/java/cn/iocoder/yudao/util/StringUtils.java @@ -607,4 +607,19 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils } return sb.toString(); } + + /** + * 手机号格式验证 + * @author lzt + * @param customerPhone 手机号 + * @return 验证结果 + * @date 2024年10月22日 + */ + public static boolean isMobile(String customerPhone) { + if (customerPhone == null || customerPhone.length() != 11) { + return false; + } + String regex = "^1[358]\\d{9}$"; + return customerPhone.matches(regex); + } }