车辆计算内容

This commit is contained in:
PQZ 2024-08-13 17:00:58 +08:00
parent 58f3d3d4a3
commit 1f753ffa37
11 changed files with 253 additions and 51 deletions

View File

@ -25,10 +25,10 @@ public class BaseConstants {
public static final String PASSWORD_DEFAULT = "123456";
/**租户下部门名称*/
public static final String DEPT_NAME_CORP_NAME = "政企客户";
/**计算下次保险时间*/
public static final String COMPUTE_TYPE_BX = "bx";
/**计算下次保养时间*/
public static final String COMPUTE_TYPE_BY = "by";
/**私家车*/
public static final String CAR_CATEGORY_PRIVATE = "01";
/**货车*/
public static final String CAR_CATEGORY_TRUCK = "02";
/**计算下次检测时间*/
public static final String COMPUTE_TYPE_JC = "jc";
/**企业管理-员工管理表名称*/

View File

@ -120,6 +120,21 @@ public class CarMainController {
return success(pageResult);
}
/**
* 测算车辆下一次保养/检测/保险时间
* @author PQZ
* @date 11:48 2024/8/13
* @param pageReqVO CarMainReqVO
* @return cn.iocoder.yudao.framework.common.pojo.CommonResult<cn.iocoder.yudao.module.custom.vo.CarMainRespVO>
**/
@PostMapping("/compute")
@Operation(summary = "测算车辆下一次保养/检测/保险时间")
public CommonResult<CarMainRespVO> compute(@RequestBody CarMainReqVO pageReqVO) {
CarMainRespVO result = carMainService.compute(pageReqVO);
return success(result);
}
/**
* 导出车辆信息
*

View File

@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
@ -80,5 +82,9 @@ public class CarBrand extends BaseDO {
*/
@Schema(description = "品牌键值", example = "1")
private String brandValue;
/**保养里程规则*/
private BigDecimal ruleMileage;
/**保养时间规则(月)*/
private Integer ruleTime;
}

View File

@ -4,6 +4,8 @@ import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO;
import com.alibaba.excel.annotation.ExcelProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
@ -64,5 +66,9 @@ public class CarModel extends BaseDO {
* 品牌id
*/
private String brandId;
/**保养里程规则*/
private BigDecimal ruleMileage;
/**保养时间规则(月)*/
private Integer ruleTime;
}

View File

@ -76,7 +76,7 @@ public interface CarMainService extends IService<CarMain> {
* @param reqVO TODO
* @return java.time.LocalDateTime
**/
LocalDateTime compute(CarMainReqVO reqVO);
CarMainRespVO compute(CarMainReqVO reqVO);
}

View File

@ -3,15 +3,17 @@ 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.module.custom.entity.CarBrand;
import cn.iocoder.yudao.module.custom.entity.CarMain;
import cn.iocoder.yudao.module.custom.entity.CarModel;
import cn.iocoder.yudao.module.custom.entity.CustomerCar;
import cn.iocoder.yudao.module.custom.mapper.CarMainMapper;
import cn.iocoder.yudao.module.custom.mapper.CustomerCarMapper;
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.CarMainReqVO;
import cn.iocoder.yudao.module.custom.vo.CarMainRespVO;
import cn.iocoder.yudao.module.custom.vo.CustomerMainRespVO;
import cn.iocoder.yudao.module.custom.vo.*;
import cn.iocoder.yudao.module.label.entity.BusiLabel;
import cn.iocoder.yudao.module.label.service.BusiLabelService;
import com.baomidou.mybatisplus.core.metadata.IPage;
@ -21,12 +23,14 @@ import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.List;
import static cn.iocoder.yudao.common.BaseConstants.COMPUTE_TYPE_BX;
import static cn.iocoder.yudao.common.BaseConstants.CUS_SIGN_CAR;
import static cn.iocoder.yudao.common.BaseConstants.*;
/**
* 车辆信息 Service 实现类
@ -34,7 +38,7 @@ import static cn.iocoder.yudao.common.BaseConstants.CUS_SIGN_CAR;
* @author 后台管理员
*/
@Service
public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> implements CarMainService{
public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> implements CarMainService {
@Autowired
private CustomerCarMapper customerCarMapper;
@ -45,6 +49,11 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
@Autowired
private BusiLabelService busiLabelService;
@Resource
private CarBrandService carBrandService;
@Resource
private CarModelService carModelService;
/**
* 创建车辆信息
@ -57,11 +66,14 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
//车牌号license_number车架号vin发动机号码engine_number 重复校验
int checkResult = isDataKeyValueRepeat(createReqVO);
//如果查重失败
if (checkResult != 0){
switch (checkResult){
case 1: return CommonResult.error(4051,"该车牌号已在系统中登记");
case 2: return CommonResult.error(4052,"该车架号已在系统中登记");
case 3: return CommonResult.error(4053,"该发动机号码已在系统中登记");
if (checkResult != 0) {
switch (checkResult) {
case 1:
return CommonResult.error(4051, "该车牌号已在系统中登记");
case 2:
return CommonResult.error(4052, "该车架号已在系统中登记");
case 3:
return CommonResult.error(4053, "该发动机号码已在系统中登记");
}
}
@ -71,10 +83,10 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
CarMain carMain = BeanUtils.toBean(createReqVO, CarMain.class);
carMain.setCarBrand(brandAndModel.get(0));
//判断是否仅填入了品牌
if(brandAndModel.size()>1){
if (brandAndModel.size() > 1) {
//填入了型号
carMain.setCarModel(brandAndModel.get(1));
}else {
} else {
carMain.setCarModel("");
}
//todo 计算下次保养时间下次保养里程下次年检时间保险到期时间
@ -89,15 +101,18 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
* @param updateReqVO 更新信息
*/
@Override
public CommonResult<String> updateCarMain(CarMainReqVO updateReqVO){
public CommonResult<String> updateCarMain(CarMainReqVO updateReqVO) {
//车牌号license_number车架号vin发动机号码engine_number 重复校验
int checkResult = isDataKeyValueRepeat(updateReqVO);
//如果查重失败
if (checkResult != 0){
switch (checkResult){
case 1: return CommonResult.error(4051,"该车牌号已在系统中登记");
case 2: return CommonResult.error(4052,"该车架号已在系统中登记");
case 3: return CommonResult.error(4053,"该发动机号码已在系统中登记");
if (checkResult != 0) {
switch (checkResult) {
case 1:
return CommonResult.error(4051, "该车牌号已在系统中登记");
case 2:
return CommonResult.error(4052, "该车架号已在系统中登记");
case 3:
return CommonResult.error(4053, "该发动机号码已在系统中登记");
}
}
@ -107,10 +122,10 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
CarMain carMain = BeanUtils.toBean(updateReqVO, CarMain.class);
carMain.setCarBrand(brandAndModel.get(0));
//判断是否仅填入了品牌
if(brandAndModel.size()>1){
if (brandAndModel.size() > 1) {
//填入了型号
carMain.setCarModel(brandAndModel.get(1));
}else {
} else {
carMain.setCarModel("");
}
//todo 计算下次保养时间下次保养里程下次年检时间保险到期时间
@ -127,7 +142,7 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
public void deleteCarMain(String id) {
//判断车辆是否发生过业务
CarMain target = baseMapper.selectById(id);
if (ObjectUtil.isEmpty(target.getRecentlyHandledBusiness()) && !"".equals(target.getRecentlyHandledBusiness()) ){
if (ObjectUtil.isEmpty(target.getRecentlyHandledBusiness()) && !"".equals(target.getRecentlyHandledBusiness())) {
}
// 逻辑删除
@ -172,7 +187,7 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
//取分页参数
Page<CarMainReqVO> page = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
//分页查询
return baseMapper.findPage(page,pageReqVO);
return baseMapper.findPage(page, pageReqVO);
}
/**
@ -185,7 +200,7 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
public void bindCustomAndCar(CarMainReqVO saveReqVO) {
List<CustomerCar> customerCars = new ArrayList<>();
List<CustomerMainRespVO> cusList = saveReqVO.getCusList();
if (ObjectUtil.isNotEmpty(cusList)){
if (ObjectUtil.isNotEmpty(cusList)) {
//组装数据
cusList.forEach(item -> {
CustomerCar customerCar = new CustomerCar();
@ -195,44 +210,169 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
customerCars.add(customerCar);
});
}
customerCarService.bindCustomerCar(saveReqVO.getId(),CUS_SIGN_CAR,customerCars);
customerCarService.bindCustomerCar(saveReqVO.getId(), CUS_SIGN_CAR, customerCars);
}
/**
* 测算车辆下一次保养/检测/保险时间
* @author PQZ
* @date 7:45 2024/8/9
*
* @param reqVO CarMainReqVO
* @return java.time.LocalDateTime
* @author PQZ
* @date 7:45 2024/8/9
**/
@Override
public LocalDateTime compute(CarMainReqVO reqVO) {
LocalDateTime resultTime;
public CarMainRespVO compute(CarMainReqVO reqVO) {
CarMainRespVO respVO = new CarMainRespVO();
/*1、测算车辆保险到期时间车辆保险购买时间不可为空*/
if (null != reqVO.getInsuranceDate()) {
respVO.setInsuranceExpiryDate(reqVO.getInsuranceDate().plusYears(1));
}
/*2、测算车辆年检临期(车辆类型及车辆注册时间不可为空)*/
if (null != reqVO.getCarCategory() && null != reqVO.getCarRegisterDate()) {
respVO.setNextInspectionDate(computeNextInsp(reqVO.getInspectionDate(), reqVO.getCarCategory(), reqVO.getCarRegisterDate()));
}
/*3、测算车辆保养里程及下次保养时间*/
List<String> brandAndModel = reqVO.getBrandAndModel();
//根据品牌型号获取保养规则
BrandAndModelDTO rule = getBrandAndModel(brandAndModel);
//设置保养里程
if (null != reqVO.getMaintenanceMileage()) {
respVO.setNextMaintenanceMileage(reqVO.getMaintenanceMileage().add(rule.getRuleMileage()));
}
//设置保养时间
if (null != reqVO.getMaintenanceDate()) {
respVO.setNextMaintenanceDate(reqVO.getMaintenanceDate().plusMonths(rule.getRuleTime()));
}
return respVO;
}
return null;
/**
* 根据品牌型号获取保养规则
*
* @param brandAndModel List<String>品牌型号集合
* @return cn.iocoder.yudao.module.custom.vo.BrandAndModelDTO
* @author PQZ
* @date 11:41 2024/8/13
**/
private BrandAndModelDTO getBrandAndModel(List<String> brandAndModel) {
BrandAndModelDTO result = new BrandAndModelDTO();
int ruleTime = 0;
BigDecimal ruleMileage = new BigDecimal(0);
if (null != brandAndModel && brandAndModel.size() > 0) {
//优先以车辆型号绑定的里程及保养时间为准
if (brandAndModel.size() > 1) {
//取车辆型号id
String modelId = brandAndModel.get(1);
//查询车辆型号
CarModel carModel = carModelService.getById(modelId);
if (null != carModel) {
ruleTime = carModel.getRuleTime();
ruleMileage = carModel.getRuleMileage();
}
} else {
//没有选择型号情况以车辆品牌绑定规则为准
String brandId = brandAndModel.get(0);
//查询车辆品牌
CarBrand carBrand = carBrandService.getById(brandId);
if (null != carBrand){
ruleTime = carBrand.getRuleTime();
ruleMileage = carBrand.getRuleMileage();
}
}
}
result.setRuleTime(ruleTime);
result.setRuleMileage(ruleMileage);
return result;
}
/**
* 计算车辆下次年检时间
*
* @param inspectionDate 年检时间
* @param carCategory 车辆类型
* @param carRegisterDate 车辆类别
* @return java.time.LocalDateTime
* @author PQZ
* @date 9:51 2024/8/13
**/
private LocalDateTime computeNextInsp(LocalDateTime inspectionDate, String carCategory, LocalDateTime carRegisterDate) {
/*1、基础参数定义*/
LocalDateTime resultTime = null;
//车辆是否存在年检时间
boolean isInspNull = null != inspectionDate;
//当前时间
LocalDateTime currentTime = LocalDateTime.now();
//计算当前时间与车辆注册日期的差值
Period period = Period.between(carRegisterDate.toLocalDate(), currentTime.toLocalDate());
//年份差值
int yearPeriod = period.getYears();
if (CAR_CATEGORY_PRIVATE.equals(carCategory)) {
/*2、计算私家车类型车辆下次年检日期*/
//私家车计算规则第610年需要年检过后1年1检
if (yearPeriod < 6) {
//小于6年情况在第六年车检
resultTime = carRegisterDate.plusYears(6);
} else if (yearPeriod < 10) {
//大于6年小于10年情况
resultTime = carRegisterDate.plusYears(10);
} else {
//大于10情况,一年一检
if (isInspNull) {
resultTime = inspectionDate.plusYears(1);
}
}
} else if (CAR_CATEGORY_TRUCK.equals(carCategory)) {
/*2、计算货车类型车辆下次年检日期*/
//货车测算必须传入年检时间
if (isInspNull) {
if (yearPeriod <= 10) {
//10年内一年一检
resultTime = inspectionDate.plusYears(1);
} else {
//大于10年半年一检
resultTime = inspectionDate.plusMonths(6);
}
}
} else {
/*3、计算非营运车辆下次年检日期*/
//非营运车辆必须传入年检时间
if (isInspNull) {
if (yearPeriod <= 5) {
//5年内一年一检
resultTime = inspectionDate.plusYears(1);
} else {
//大于5年半年一检
resultTime = inspectionDate.plusMonths(6);
}
}
}
return resultTime;
}
/**
* 车牌号车架号发动机号码 查重
*
* @param reqVO
* @return 0无重复1车牌号重复2车架号重复发动机号码重复
*/
private int isDataKeyValueRepeat(CarMainReqVO reqVO){
private int isDataKeyValueRepeat(CarMainReqVO reqVO) {
//车牌号license_number 查重
if(ObjectUtil.isNotEmpty(reqVO.getLicenseNumber())){
if (ObjectUtil.isNotEmpty(reqVO.getLicenseNumber())) {
CarMain target = new CarMain();
target.setLicenseNumber(reqVO.getLicenseNumber());
List<CarMain> results = baseMapper.isDataKeyValueRepeat(target);
//判断是否登记过这个车牌号的车辆
if (results.size()>0){
if (results.size() > 0) {
//无id是新增有相应登记记录
if(ObjectUtil.isEmpty(reqVO.getId()) ){
if (ObjectUtil.isEmpty(reqVO.getId())) {
return 1;
}
//有id是修改如果登记过比较id查验是否是当前要修改的车辆本身
for (CarMain item: results) {
if (!item.getId().equals(reqVO.getId())){
for (CarMain item : results) {
if (!item.getId().equals(reqVO.getId())) {
return 1;
}
@ -241,19 +381,19 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
}
//车架号vin 查重
}
if (ObjectUtil.isNotEmpty(reqVO.getVin())){
if (ObjectUtil.isNotEmpty(reqVO.getVin())) {
CarMain target = new CarMain();
target.setVin(reqVO.getVin());
List<CarMain> results = baseMapper.isDataKeyValueRepeat(target);
//判断是否登记过这个车架号的车辆
if (results.size()>0){
if (results.size() > 0) {
//无id是新增有相应登记记录
if(ObjectUtil.isEmpty(reqVO.getId()) ){
if (ObjectUtil.isEmpty(reqVO.getId())) {
return 2;
}
//有id是修改如果登记过比较id查验是否是当前要修改的车辆本身
for (CarMain item: results) {
if (!item.getId().equals(reqVO.getId())){
for (CarMain item : results) {
if (!item.getId().equals(reqVO.getId())) {
return 2;
}
@ -262,19 +402,19 @@ public class CarMainServiceImpl extends ServiceImpl<CarMainMapper, CarMain> impl
}
//发动机号码engine_number 查重
}
if (ObjectUtil.isNotEmpty(reqVO.getEngineNumber())){
if (ObjectUtil.isNotEmpty(reqVO.getEngineNumber())) {
CarMain target = new CarMain();
target.setEngineNumber(reqVO.getEngineNumber());
List<CarMain> results = baseMapper.isDataKeyValueRepeat(target);
//判断是否登记过这个发动机号的车辆
if (results.size()>0){
if (results.size() > 0) {
//无id是新增有相应登记记录
if(ObjectUtil.isEmpty(reqVO.getId()) ){
if (ObjectUtil.isEmpty(reqVO.getId())) {
return 3;
}
//有id是修改如果登记过比较id查验是否是当前要修改的车辆本身
for (CarMain item: results) {
if (!item.getId().equals(reqVO.getId())){
for (CarMain item : results) {
if (!item.getId().equals(reqVO.getId())) {
return 3;
}

View File

@ -0,0 +1,19 @@
package cn.iocoder.yudao.module.custom.vo;
import lombok.Data;
import java.math.BigDecimal;
/**
* 保养里程及规则DTO
* @author PQZ
* @date 11:37 2024/8/13
**/
@Data
public class BrandAndModelDTO{
/**保养里程规则*/
private BigDecimal ruleMileage;
/**保养时间规则(月)*/
private Integer ruleTime;
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.custom.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
@ -47,5 +49,9 @@ public class CarBrandReqVO extends PageParam {
@Schema(description = "品牌键值")
private String brandValue;
/**保养里程规则*/
private BigDecimal ruleMileage;
/**保养时间规则(月)*/
private Integer ruleTime;
}

View File

@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.custom.vo;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.*;
import java.math.BigDecimal;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
@ -41,6 +43,10 @@ public class CarModelReqVO extends PageParam {
@Schema(description = "品牌id", example = "李四")
private String brandId;
/**保养里程规则*/
private BigDecimal ruleMileage;
/**保养时间规则(月)*/
private Integer ruleTime;

View File

@ -15,6 +15,8 @@
tbcb.logo_img,
tbcb.english_name,
tbcb.abb_name,
tbcb.rule_mileage,
tbcb.rule_time,
tbcb.brand_value,
tbcb.deleted,
tbcb.tenant_id

View File

@ -7,6 +7,8 @@
tbcmod.sort,
tbcmod.model_name,
tbcmod.model_value,
tbcmod.rule_mileage,
tbcmod.rule_time,
tbcmod.remark,
tbcmod.creator,
tbcmod.create_time,