From 671ee57cf9535591cdbca88b5c52213be96c1b8b Mon Sep 17 00:00:00 2001 From: Vinjor Date: Mon, 14 Oct 2024 18:36:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E4=BF=A1=E6=81=AF=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/custom/entity/CarMain.java | 25 ++--- .../module/custom/service/CarMainService.java | 13 ++- .../service/impl/CarMainServiceImpl.java | 35 ++++++- .../service/impl/UserCarServiceImpl.java | 91 +++++++++++++------ .../impl/RepairOrderInfoServiceImpl.java | 12 +-- 5 files changed, 114 insertions(+), 62 deletions(-) diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CarMain.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CarMain.java index aed4e4c7..d065cd44 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CarMain.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/entity/CarMain.java @@ -1,24 +1,15 @@ package cn.iocoder.yudao.module.custom.entity; import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; -import lombok.*; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.format.annotation.DateTimeFormat; import java.math.BigDecimal; -import java.util.*; import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import java.time.LocalDateTime; -import com.baomidou.mybatisplus.annotation.*; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import org.springframework.format.annotation.DateTimeFormat; import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; @@ -37,6 +28,10 @@ public class CarMain extends TenantBaseDO { */ @TableId(type = IdType.ASSIGN_UUID) private String id; + /** + * 用户ID + */ + private Long userId; /** * 发动机号码 */ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CarMainService.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CarMainService.java index 42ade09f..a5c4a534 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CarMainService.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/CarMainService.java @@ -1,18 +1,13 @@ package cn.iocoder.yudao.module.custom.service; -import javax.validation.*; - import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.custom.entity.CarMain; -import cn.iocoder.yudao.module.custom.vo.CarBrandRespVO; import cn.iocoder.yudao.module.custom.vo.CarMainReqVO; import cn.iocoder.yudao.module.custom.vo.CarMainRespVO; -import cn.iocoder.yudao.module.custom.vo.CustomerMainSaveReqVO; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.IService; -import java.time.LocalDateTime; import java.util.List; /** @@ -60,6 +55,14 @@ public interface CarMainService extends IService { */ IPage getCarMainPage(CarMainReqVO pageReqVO); + /** + * 根据userId查询在某租户下的所有车辆列表 + * @author vinjor-M + * @date 11:56 2024/10/14 + * @param userId 用户ID + * @return java.util.List + **/ + List selectListByUserId(Long userId); /** * 保险/年检/保养提醒列表 * @author PQZ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CarMainServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CarMainServiceImpl.java index 765acafe..25097d52 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CarMainServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/CarMainServiceImpl.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.custom.service.impl; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; +import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.module.custom.entity.CarBrand; import cn.iocoder.yudao.module.custom.entity.CarMain; import cn.iocoder.yudao.module.custom.entity.CarModel; @@ -13,9 +14,13 @@ import cn.iocoder.yudao.module.custom.service.CarBrandService; import cn.iocoder.yudao.module.custom.service.CarMainService; import cn.iocoder.yudao.module.custom.service.CarModelService; import cn.iocoder.yudao.module.custom.service.CustomerCarService; -import cn.iocoder.yudao.module.custom.vo.*; +import cn.iocoder.yudao.module.custom.vo.BrandAndModelDTO; +import cn.iocoder.yudao.module.custom.vo.CarMainReqVO; +import cn.iocoder.yudao.module.custom.vo.CarMainRespVO; +import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO; import cn.iocoder.yudao.module.label.entity.BusiLabel; import cn.iocoder.yudao.module.label.service.BusiLabelService; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -24,7 +29,6 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; -import java.time.Duration; import java.time.LocalDateTime; import java.time.Period; import java.util.ArrayList; @@ -190,6 +194,23 @@ public class CarMainServiceImpl extends ServiceImpl impl return baseMapper.findPage(page, pageReqVO); } + /** + * 根据userId查询在某租户下的所有车辆列表 + * + * @param userId 用户ID + * @return java.util.List + * @author vinjor-M + * @date 11:56 2024/10/14 + **/ + @Override + public List selectListByUserId(Long userId) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(CarMain::getUserId,userId) + .groupBy(CarMain::getLicenseNumber) + .orderByDesc(BaseDO::getCreateTime); + return this.list(queryWrapper); + } + /** * 保险/年检/保养提醒列表 * @@ -214,6 +235,7 @@ public class CarMainServiceImpl extends ServiceImpl impl public void bindCustomAndCar(CarMainReqVO saveReqVO) { List customerCars = new ArrayList<>(); List cusList = saveReqVO.getCusList(); + List updateCarMainList = new ArrayList<>(); if (ObjectUtil.isNotEmpty(cusList)) { //组装数据 cusList.forEach(item -> { @@ -222,9 +244,18 @@ public class CarMainServiceImpl extends ServiceImpl impl customerCar.setCusId(item.getId()); customerCar.setIsOwner(item.getIsOwner()); customerCars.add(customerCar); + //组装车辆更新数据 + CarMain updateObj = new CarMain(); + updateObj.setId(saveReqVO.getId()); + updateObj.setUserId(item.getUserId()); + updateCarMainList.add(updateObj); }); + } customerCarService.bindCustomerCar(saveReqVO.getId(), CUS_SIGN_CAR, customerCars); + if(!updateCarMainList.isEmpty()){ + this.updateBatchById(updateCarMainList); + } } /** diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java index fec606fc..053a66f1 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/custom/service/impl/UserCarServiceImpl.java @@ -5,10 +5,11 @@ 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.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.custom.entity.CarMain; import cn.iocoder.yudao.module.custom.entity.CustomerCar; import cn.iocoder.yudao.module.custom.entity.CustomerMain; @@ -18,10 +19,10 @@ 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.*; +import cn.iocoder.yudao.module.custom.vo.DrivelicenseVO; +import cn.iocoder.yudao.module.custom.vo.UserCarVO; 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; @@ -33,11 +34,9 @@ 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; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 用户车辆信息表--用户个人录入的 Service 实现类 @@ -118,24 +117,44 @@ public class UserCarServiceImpl extends ServiceImpl impl **/ @Override @Transactional(rollbackFor = Exception.class) + @TenantIgnore public void empowerUserInfo(Long tenantId) { /*1、基础数据准备*/ //获取当前登录用户信息 Long userId = SecurityFrameworkUtils.getLoginUserId(); AdminUserRespDTO loginUser = userApi.getUser(userId); //获取当前登录用户车辆信息 - List carList = getMyCar(); + List carList = this.getMyCar(); + //所有车牌号list + List licenseNoList = carList.stream().map(UserCar::getLicenseNumber).collect(Collectors.toList()); //需要保存的关联关系 List saveCustomerCarList = new ArrayList<>(); //需要保存的车辆信息 List saveCarList = new ArrayList<>(); - //提前为客户id赋值 - String customerId = UUID.randomUUID().toString().replace("-", ""); - + //查是否已有客户信息,若有则更新,没有则插入 + final CustomerMain[] oldMain = {null}; + //查已有的车辆信息,若有则更新,没有则插入 + final Map[] carMap = new Map[]{new HashMap<>()}; + TenantUtils.execute(tenantId, () -> { + //客户在这个租户下的信息 + oldMain[0] = customerMainService.getCustomerByUserId(userId); + //客户在这个租户下的车辆信息 + List oldCarMainList=carMainService.selectListByUserId(userId); + carMap[0] = oldCarMainList.stream().collect(Collectors.toMap(CarMain::getLicenseNumber, Function.identity())); + }); + String customerId; + CustomerMain customerMain; /*2、数据转换,将用户表关联信息转换成客户表关联信息 */ //转换客户数据 - CustomerMain customerMain = new CustomerMain(); - customerMain.setId(customerId); + if(null== oldMain[0]){ + customerId = UUID.randomUUID().toString().replace("-", ""); + customerMain = new CustomerMain(); + customerMain.setId(customerId); + }else{ + customerId = oldMain[0].getId(); + customerMain = oldMain[0]; + } + //提前为客户id赋值 customerMain.setUserId(userId); customerMain.setCusName(loginUser.getNickname()); customerMain.setSex(String.valueOf(loginUser.getSex())); @@ -148,12 +167,25 @@ public class UserCarServiceImpl extends ServiceImpl impl if (CollUtil.isNotEmpty(carList)){ carList.forEach(item ->{ CarMain carItem = new CarMain(); - CustomerCar customerCarItem = new CustomerCar(); - String carId = UUID.randomUUID().toString().replace("-", ""); + if(carMap[0].containsKey(item.getLicenseNumber())){ + //更新 + BeanUtil.copyProperties(carMap[0].get(item.getLicenseNumber()),carItem); + }else{ + //插入 + carItem = new CarMain(); + String carId = UUID.randomUUID().toString().replace("-", ""); + carItem.setId(carId); + CustomerCar customerCarItem = new CustomerCar(); + //客户与车辆关联关系 + customerCarItem.setCusId(customerId); + customerCarItem.setCarId(carId); + customerCarItem.setIsOwner(item.getIsOwner()); + saveCustomerCarList.add(customerCarItem); + } //车辆信息 - carItem.setId(carId); carItem.setEngineNumber(item.getEngineNumber()); carItem.setVin(item.getVin()); + carItem.setUserId(userId); carItem.setLicenseNumber(item.getLicenseNumber()); carItem.setCarModel(item.getCarModel()); carItem.setMaintenanceDate(convertToLocalDateTime(item.getMaintenanceDate())); @@ -171,23 +203,22 @@ public class UserCarServiceImpl extends ServiceImpl impl 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); + TenantUtils.execute(tenantId, () -> { + //保存客户信息 + customerMainService.saveOrUpdate(customerMain); + //保存或更新车辆信息 + if(!saveCarList.isEmpty()){ + carMainService.saveOrUpdateBatch(saveCarList); + } + if(!saveCustomerCarList.isEmpty()){ + //保存客户与车辆关联关系 + customerCarService.saveBatch(saveCustomerCarList); + } + }); } /* Date转换为LocalDateTime */ diff --git a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java index c0c4ea72..cdd659fd 100644 --- a/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java +++ b/dl-module-base/src/main/java/cn/iocoder/yudao/module/order/service/impl/RepairOrderInfoServiceImpl.java @@ -1,30 +1,23 @@ package cn.iocoder.yudao.module.order.service.impl; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; -import cn.iocoder.yudao.framework.security.core.LoginUser; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; -import cn.iocoder.yudao.module.company.service.CompanyService; import cn.iocoder.yudao.module.custom.service.CustomerBalanceService; import cn.iocoder.yudao.module.custom.service.CustomerCouponService; import cn.iocoder.yudao.module.order.entity.RepairOrderInfo; import cn.iocoder.yudao.module.order.mapper.RepairOrderInfoMapper; import cn.iocoder.yudao.module.order.service.RepairOrderInfoService; -import cn.iocoder.yudao.module.order.vo.*; +import cn.iocoder.yudao.module.order.vo.RepairOrderCensusVO; import cn.iocoder.yudao.module.order.vo.RepairOrderInfoPageReqVO; import cn.iocoder.yudao.module.order.vo.RepairOrderInfoRespVO; import cn.iocoder.yudao.module.order.vo.RepairOrderInfoSaveReqVO; -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.dal.dataobject.user.AdminUserDO; import cn.iocoder.yudao.module.system.service.user.AdminUserService; -import cn.iocoder.yudao.module.tickets.entity.Tickets; import cn.iocoder.yudao.module.tickets.service.TicketsService; import cn.iocoder.yudao.util.WechatPayConfig; import cn.iocoder.yudao.util.WechatPayRequest; -import cn.iocoder.yudao.util.WechatPayUrlEnum; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.TypeReference; @@ -45,7 +38,6 @@ import java.math.BigDecimal; import java.security.*; import java.time.LocalDateTime; import java.util.*; -import java.util.stream.Collectors; import static cn.iocoder.yudao.common.BaseConstants.*; @@ -305,7 +297,7 @@ public class RepairOrderInfoServiceImpl extends ServiceImpl().and(item -> { item.eq(RepairOrderInfo::getUserId, loginUserId) - .isNotNull(RepairOrderInfo::getCommentDesc); + .isNotNull(RepairOrderInfo::getCommentStar); })); }