Compare commits

...

2 Commits

Author SHA1 Message Date
dbc65a28a7 Merge branch 'dev' of http://122.51.230.86:3000/dianliang/lanan-system into dev
# Conflicts:
#	dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java
2024-10-12 17:58:24 +08:00
0ef3bbe501 将客户信息授权给某个修理厂service 2024-10-12 17:45:13 +08:00
4 changed files with 200 additions and 1895 deletions

View File

@ -38,7 +38,7 @@ public class UserCarController {
**/
@GetMapping("/empowerUserInfo")
@Operation(summary = "授权个人信息到某企业")
public CommonResult<?> empowerUserInfo(@RequestParam("tenantId") String tenantId) {
public CommonResult<?> empowerUserInfo(@RequestParam("tenantId") Long tenantId) {
userCarService.empowerUserInfo(tenantId);
return CommonResult.success(true);
}
@ -78,4 +78,4 @@ public class UserCarController {
public CommonResult<?> delById(String id) {
return CommonResult.success(userCarService.removeById(id));
}
}
}

View File

@ -47,5 +47,5 @@ public interface UserCarService extends IService<UserCar> {
* @date 12:40 2024/10/12
* @param tenantId 租户id
**/
void empowerUserInfo(String tenantId);
}
void empowerUserInfo(Long tenantId);
}

View File

@ -1,25 +1,44 @@
package cn.iocoder.yudao.module.custom.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.UUID;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.common.DictBaseConstants;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
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.mapper.UserCarMapper;
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.service.UserCarService;
import cn.iocoder.yudao.module.custom.vo.DrivelicenseVO;
import cn.iocoder.yudao.module.custom.vo.UserCarVO;
import cn.iocoder.yudao.module.custom.vo.*;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.api.user.dto.UserDTO;
import cn.iocoder.yudao.util.VehicleLicenseOCR;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static cn.iocoder.yudao.common.BaseConstants.SIGN_CREATE;
/**
* 用户车辆信息表--用户个人录入的 Service 实现类
*
@ -31,6 +50,15 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
@Resource
private UserCarMapper userCarMapper;
@Resource
private CustomerMainService customerMainService;
@Resource
private AdminUserApi userApi;
@Resource
private CarMainService carMainService;
@Resource
private CustomerCarService customerCarService;
/**
* 创建或更新车辆信息
@ -89,6 +117,93 @@ public class UserCarServiceImpl extends ServiceImpl<UserCarMapper, UserCar> impl
* @date 12:40 2024/10/12
**/
@Override
public void empowerUserInfo(String tenantId) {
@Transactional(rollbackFor = Exception.class)
public void empowerUserInfo(Long tenantId) {
/*1、基础数据准备*/
//获取当前登录用户信息
Long userId = SecurityFrameworkUtils.getLoginUserId();
AdminUserRespDTO loginUser = userApi.getUser(userId);
//获取当前登录用户车辆信息
List<UserCarVO> carList = getMyCar();
//需要保存的关联关系
List<CustomerCar> saveCustomerCarList = new ArrayList<>();
//需要保存的车辆信息
List<CarMain> saveCarList = new ArrayList<>();
//提前为客户id赋值
String customerId = UUID.randomUUID().toString().replace("-", "");
/*2、数据转换将用户表关联信息转换成客户表关联信息 */
//转换客户数据
CustomerMain customerMain = new CustomerMain();
customerMain.setId(customerId);
customerMain.setUserId(userId);
customerMain.setCusName(loginUser.getNickname());
customerMain.setSex(String.valueOf(loginUser.getSex()));
customerMain.setPhoneNumber(loginUser.getMobile());
customerMain.setTenantId(tenantId);
customerMain.setTypeCode("01");
customerMain.setDataFrom("04");
customerMain.setIsHangAccount("0");
//转换车辆及关联关系数据
if (CollUtil.isNotEmpty(carList)){
carList.forEach(item ->{
CarMain carItem = new CarMain();
CustomerCar customerCarItem = new CustomerCar();
String carId = UUID.randomUUID().toString().replace("-", "");
//车辆信息
carItem.setId(carId);
carItem.setEngineNumber(item.getEngineNumber());
carItem.setVin(item.getVin());
carItem.setLicenseNumber(item.getLicenseNumber());
carItem.setCarModel(item.getCarModel());
carItem.setMaintenanceDate(convertToLocalDateTime(item.getMaintenanceDate()));
carItem.setMaintenanceMileage(convertToBigDecimal(item.getMaintenanceMileage()));
carItem.setInspectionDate(convertToLocalDateTime(item.getInspectionDate()));
carItem.setInsuranceDate(convertToLocalDateTime(item.getInsuranceDate()));
carItem.setCheckDate(convertToLocalDateTime(item.getCheckDate()));
carItem.setNextMaintenanceDate(convertToLocalDateTime(item.getNextMaintenanceDate()));
carItem.setNextMaintenanceMileage(convertToBigDecimal(item.getNextMaintenanceMileage()));
carItem.setNextInspectionDate(convertToLocalDateTime(item.getNextInspectionDate()));
carItem.setInsuranceExpiryDate(convertToLocalDateTime(item.getInsuranceExpiryDate()));
carItem.setNextCheckDate(convertToLocalDateTime(item.getNextCheckDate()));
carItem.setCarBrand(item.getCarBrand());
carItem.setCarNature(item.getCarNature());
carItem.setCarCategory(item.getCarCategory());
carItem.setCarRegisterDate(convertToLocalDateTime(item.getCarRegisterDate()));
carItem.setCarLicenseImg(item.getCarLicenseImg());
//客户与车辆关联关系
customerCarItem.setCusId(customerId);
customerCarItem.setCarId(carId);
customerCarItem.setIsOwner(item.getIsOwner());
saveCarList.add(carItem);
saveCustomerCarList.add(customerCarItem);
});
}
/*3、数据保存*/
//保存客户信息
customerMainService.save(customerMain);
//保存车辆信息
carMainService.saveBatch(saveCarList);
//保存客户与车辆关联关系
customerCarService.saveBatch(saveCustomerCarList);
}
}
/* Date转换为LocalDateTime */
private LocalDateTime convertToLocalDateTime(Date carRegisterDate) {
if (carRegisterDate != null) {
return LocalDateTime.ofInstant(carRegisterDate.toInstant(), ZoneId.systemDefault());
}
return null;
}
/* Long转换为BigDecimal */
private BigDecimal convertToBigDecimal(Long value) {
if (value != null) {
return BigDecimal.valueOf(value);
}
return null;
}
}

File diff suppressed because it is too large Load Diff