1
This commit is contained in:
parent
3f891bf327
commit
43420aa8b2
@ -100,5 +100,14 @@ public interface CarMainService extends IService<CarMain> {
|
||||
**/
|
||||
CarMainRespVO compute(CarMainReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 根据客户信息+车牌号查这个客户是否已有这个车
|
||||
* @author vinjor-M
|
||||
* @date 14:41 2024/11/13
|
||||
* @param userId 用户id
|
||||
* @param carNumber 车牌号
|
||||
* @return cn.iocoder.yudao.module.custom.entity.CarMain
|
||||
**/
|
||||
CarMain selectByUserIdAndCarNumber(Long userId,String carNumber);
|
||||
|
||||
}
|
@ -309,6 +309,28 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
|
||||
return respVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据客户信息+车牌号查这个客户是否已有这个车
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param carNumber 车牌号
|
||||
* @return cn.iocoder.yudao.module.custom.entity.CarMain
|
||||
* @author vinjor-M
|
||||
* @date 14:41 2024/11/13
|
||||
**/
|
||||
@Override
|
||||
public CarMain selectByUserIdAndCarNumber(Long userId, String carNumber) {
|
||||
LambdaQueryWrapper<CarMain> queryWrapper = new LambdaQueryWrapper<CarMain>()
|
||||
.eq(CarMain::getUserId,userId)
|
||||
.eq(CarMain::getLicenseNumber,carNumber);
|
||||
List<CarMain> rtnList = this.list(queryWrapper);
|
||||
if(rtnList.isEmpty()){
|
||||
return null;
|
||||
}else{
|
||||
return rtnList.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据品牌型号获取保养规则
|
||||
*
|
||||
|
@ -95,11 +95,12 @@ public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, Custo
|
||||
@Override
|
||||
public void saveCustomerAndCar(CustomerMainSaveReqVO saveReqVO) throws Exception {
|
||||
chekData(saveReqVO);
|
||||
saveReqVO.getCar().setLicenseNumber(saveReqVO.getCar().getLicenseNumber().toUpperCase());
|
||||
//用户信息
|
||||
AdminUserRespDTO userDTO = adminUserApi.getUserByUsername(saveReqVO.getPhoneNumber());
|
||||
UserDTO user = BeanUtils.toBean(userDTO, UserDTO.class);
|
||||
if (null == userDTO){
|
||||
user = new UserDTO();
|
||||
//客户信息不存在,直接新增客户、新增车辆及绑定关系
|
||||
UserDTO user = new UserDTO();
|
||||
//如果不存在创建用户;
|
||||
user.setUsername(saveReqVO.getPhoneNumber());
|
||||
user.setNickname(saveReqVO.getCusName());
|
||||
@ -107,24 +108,54 @@ public class CustomerCarServiceImpl extends ServiceImpl<CustomerCarMapper, Custo
|
||||
user.setPassword(PASSWORD_DEFAULT);
|
||||
user.setMobile(saveReqVO.getPhoneNumber());
|
||||
user.setUserType(USER_TYPE_CUS);
|
||||
//创建客户
|
||||
//创建用户
|
||||
Long userId = adminUserApi.createUser(user);
|
||||
saveReqVO.setUserId(userId);
|
||||
//创建客户信息
|
||||
CustomerMain customerMain = BeanUtils.toBean(saveReqVO,CustomerMain.class);
|
||||
customerMain.setId(null);
|
||||
customerMain.setDataFrom("02");
|
||||
customerMainService.save(customerMain);
|
||||
//创建车辆信息
|
||||
CarMain carMain = saveReqVO.getCar();
|
||||
carMain.setUserId(userId);
|
||||
carMainService.save(carMain);
|
||||
//客户和车的关联关系
|
||||
CustomerCar customerCar = new CustomerCar();
|
||||
customerCar.setCusId(customerMain.getId());
|
||||
customerCar.setCarId(carMain.getId());
|
||||
//默认车主
|
||||
customerCar.setIsOwner("1");
|
||||
this.save(customerCar);
|
||||
} else {
|
||||
saveReqVO.setUserId(user.getId());
|
||||
//已有 用户
|
||||
Long userId = userDTO.getId();
|
||||
saveReqVO.setUserId(userId);
|
||||
//查是否存在客户信息
|
||||
CustomerMain customerMain = customerMainService.getCustomerByUserId(userId);
|
||||
if(null==customerMain){
|
||||
//不存在客户信息,新增客户
|
||||
customerMain = BeanUtils.toBean(saveReqVO,CustomerMain.class);
|
||||
customerMain.setId(null);
|
||||
customerMain.setDataFrom("02");
|
||||
customerMainService.save(customerMain);
|
||||
}
|
||||
//根据客户信息+车牌号查这个客户是否已有这个车
|
||||
CarMain carMain = carMainService.selectByUserIdAndCarNumber(userId,saveReqVO.getCar().getLicenseNumber());
|
||||
if(null==carMain){
|
||||
//这个客户不存在这个车辆信息,新增
|
||||
carMain = saveReqVO.getCar();
|
||||
carMain.setUserId(userId);
|
||||
carMainService.save(carMain);
|
||||
//客户和车的关联关系
|
||||
CustomerCar customerCar = new CustomerCar();
|
||||
customerCar.setCusId(customerMain.getId());
|
||||
customerCar.setCarId(carMain.getId());
|
||||
//默认车主
|
||||
customerCar.setIsOwner("1");
|
||||
this.save(customerCar);
|
||||
}
|
||||
}
|
||||
//客户信息
|
||||
CustomerMain customerMain = BeanUtils.toBean(saveReqVO,CustomerMain.class);
|
||||
customerMain.setDataFrom("02");
|
||||
//车辆信息
|
||||
CarMain carMain = saveReqVO.getCar();
|
||||
customerMainService.save(customerMain);
|
||||
carMainService.save(carMain);
|
||||
//关联关系
|
||||
CustomerCar customerCar = new CustomerCar();
|
||||
customerCar.setCusId(customerMain.getId());
|
||||
customerCar.setCarId(carMain.getId());
|
||||
save(customerCar);
|
||||
}
|
||||
|
||||
private void chekData(CustomerMainSaveReqVO saveReqVO) throws Exception {
|
||||
|
Loading…
Reference in New Issue
Block a user