检测客户信息同步

This commit is contained in:
lzttt 2024-10-24 13:13:41 +08:00
parent b910772e5b
commit 92ba31ac12
3 changed files with 187 additions and 60 deletions

View File

@ -195,7 +195,7 @@ public class InspectionInfoServiceImpl extends ServiceImpl<InspectionInfoMapper,
customerInfo.setCustomerName(user.getNickname());
customerInfo.setSex("0");
customerInfo.setUserAge(user.getUserAge());
customerInfoService.save(customerInfo);
customerInfoService.insertPartnerCustomerInfo(customerInfo);
}
//追加订单明细记录
orderInfoDetailService.save(new OrderInfoDetail(orderInfo.getId(),"线下订单创建",new Date(),0L,"1"));

View File

@ -1,6 +1,14 @@
package cn.iocoder.yudao.module.partner.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.module.custom.entity.CarMain;
import cn.iocoder.yudao.module.custom.entity.CustomerCar;
import cn.iocoder.yudao.module.custom.entity.CustomerMain;
import cn.iocoder.yudao.module.custom.entity.UserCar;
import cn.iocoder.yudao.module.custom.service.CarMainService;
import cn.iocoder.yudao.module.custom.service.CustomerCarService;
import cn.iocoder.yudao.module.custom.service.CustomerMainService;
import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO;
import cn.iocoder.yudao.module.inspection.service.AppInspectionPartnerService;
import cn.iocoder.yudao.module.partner.entity.PartnerCustomerInfo;
import cn.iocoder.yudao.module.partner.mapper.PartnerCustomerInfoMapper;
@ -27,10 +35,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import static cn.iocoder.yudao.common.BaseConstants.SIGN_CREATE;
/**
* 客户信息Service业务层处理
@ -55,6 +65,12 @@ public class PartnerCustomerInfoServiceImpl extends ServiceImpl<PartnerCustomerI
private PartnerCustomerInfoMapper customerInfoMapper;
@Autowired
private PartnerCustomerInfoMapper partnerCustomerInfoMapper;
@Resource
private CustomerMainService customerMainService;
@Autowired
private CarMainService carMainService;
@Resource
private CustomerCarService customerCarService;
/**
* 查询客户信息列表
@ -112,83 +128,179 @@ public class PartnerCustomerInfoServiceImpl extends ServiceImpl<PartnerCustomerI
@Override
@Transactional(rollbackFor = Exception.class)
public int insertPartnerCustomerInfo(PartnerCustomerInfo partnerCustomerInfo) throws Exception {
// 获取当前商户信息
ShopMallPartners partners = partnerService.shopInfo();
LambdaQueryWrapper<PartnerCustomerInfo> queryWrapper =new LambdaQueryWrapper<>();
queryWrapper.eq(PartnerCustomerInfo::getPartnerId,partners.getPartnerId()).eq(PartnerCustomerInfo::getCustomerPhone,partnerCustomerInfo.getCustomerPhone());
// 检查客户是否已存在
LambdaQueryWrapper<PartnerCustomerInfo> 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<Long> 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<Long> 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<Long> ids = new HashSet<>();
ids.add(sysRole.getId());
permissionService.assignUserRole(user.getId(),ids);
permissionService.assignUserRole(user.getId(), ids);
}
// 车辆信息处理
List<ShopUserCar> userCarList = partnerCustomerInfo.getUserCarList();
if (CollectionUtil.isNotEmpty(userCarList)){
List<CarMain> saveCarList = new ArrayList<>();
List<CustomerCar> saveCustomerCarList = new ArrayList<>();
List<ShopUserCar> saveUserCarList = new ArrayList<>();
UserCar userCar1 = new UserCar();
if (CollectionUtil.isNotEmpty(userCarList)) {
for (ShopUserCar shopUserCar : userCarList) {
LambdaQueryWrapper<ShopUserCar> 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<ShopUserCar> 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;
}
/**
* 修改客户信息
*

View File

@ -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);
}
}