Browse Source

fix: 解决删除车辆未删除所有关联数据的问题

zhongwei
liwen 12 months ago
parent
commit
2ddb01132c
  1. 2
      hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarEntity.java
  2. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarAnnualInspectionService.java
  3. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarInsuranceService.java
  4. 17
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarAnnualInspectionServiceImpl.java
  5. 19
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarInsuranceServiceImpl.java
  6. 32
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

2
hzims-service-api/safeproduct-api/src/main/java/com/hnac/hzims/safeproduct/entity/CarEntity.java

@ -64,12 +64,10 @@ public class CarEntity extends BaseEntity {
@ApiModelProperty("下期年检时间")
private Date nextAnnualInspectionTime;
@NotNull
@Size(max = 50, message = "年检状态长度不能超过50")
@ApiModelProperty("年检状态")
private String annualInspectionStatus;
@NotNull
@Size(max = 50, message = "保险状态长度不能超过50")
@ApiModelProperty("保险状态")
private String insuranceStatus;

8
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarAnnualInspectionService.java

@ -37,4 +37,12 @@ public interface ICarAnnualInspectionService extends IService<CarAnnualInspectio
* @return 年检记录数据
*/
IPage<CarAnnualInspectionPageVO> getCarAnnualInspectionPage(Map<String, Object> param, Query query);
/**
* 删除关联年检记录
* @param carId 车辆id
* @return true-成功false-失败
*/
boolean removeRelativeCarAnnualInspection(Long carId);
}

7
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarInsuranceService.java

@ -38,4 +38,11 @@ public interface ICarInsuranceService extends IService<CarInsuranceEntity> {
* @return 车保记录数据
*/
IPage<CarInsurancePageVO> getCarInsurancePage(Map<String, Object> param, Query query);
/**
* 删除关联车保记录
* @param carId 车辆id
* @return true-成功false-失败
*/
boolean removeRelativeCarInsurance(Long carId);
}

17
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarAnnualInspectionServiceImpl.java

@ -22,6 +22,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 年检记录服务实现类
@ -93,6 +94,22 @@ public class CarAnnualInspectionServiceImpl extends ServiceImpl<CarAnnualInspect
}
/**
* 删除关联年检记录
*/
@Override
public boolean removeRelativeCarAnnualInspection(Long carId) {
QueryWrapper<CarAnnualInspectionEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarAnnualInspectionEntity::getCarId, carId);
List<CarAnnualInspectionEntity> list = this.list(queryWrapper);
// 若无关联年检记录,返回true
if (CollectionUtils.isEmpty(list)) {
return true;
}
List<Long> ids = list.stream().map(CarAnnualInspectionEntity::getId).collect(Collectors.toList());
return this.removeByIds(ids);
}
/**
* 查询是否存在同月编号
* @param currentMonth 当月
* @return 存在则返回上一编号否则返回null

19
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarInsuranceServiceImpl.java

@ -21,6 +21,7 @@ import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车保记录服务实现类
@ -55,7 +56,7 @@ public class CarInsuranceServiceImpl extends ServiceImpl<CarInsuranceMapper, Car
carEntity.setInsurancePayLastTime(carInsuranceEntity.getInsuranceTime());
carEntity.setInsurancePayNextTime(carInsuranceEntity.getNextInsuranceTime());
// 更新年检状态
carEntity.setAnnualInspectionStatus(CarInsuranceStatusEnum.INSURED.getValue());
carEntity.setInsuranceStatus(CarInsuranceStatusEnum.INSURED.getValue());
return carService.updateById(carEntity);
}
}
@ -90,6 +91,22 @@ public class CarInsuranceServiceImpl extends ServiceImpl<CarInsuranceMapper, Car
}
/**
* 删除关联车保记录
*/
@Override
public boolean removeRelativeCarInsurance(Long carId) {
QueryWrapper<CarInsuranceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarInsuranceEntity::getCarId, carId);
List<CarInsuranceEntity> list = this.list(queryWrapper);
// 若无关联用车记录,返回true
if (CollectionUtils.isEmpty(list)) {
return true;
}
List<Long> ids = list.stream().map(CarInsuranceEntity::getId).collect(Collectors.toList());
return this.removeByIds(ids);
}
/**
* 查询是否存在同月编号
* @param currentMonth 当月
* @return 存在则返回上一编号否则返回null

32
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java

@ -12,12 +12,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.common.logs.utils.StringUtils;
import com.hnac.hzims.safeproduct.dto.CarMilesYearDTO;
import com.hnac.hzims.safeproduct.entity.CarEntity;
import com.hnac.hzims.safeproduct.enums.CarMaintenanceStatusEnum;
import com.hnac.hzims.safeproduct.mapper.CarMapper;
import com.hnac.hzims.safeproduct.service.ICarCheckRecordService;
import com.hnac.hzims.safeproduct.service.ICarMaintenanceService;
import com.hnac.hzims.safeproduct.service.ICarService;
import com.hnac.hzims.safeproduct.service.ICarUsedRecordService;
import com.hnac.hzims.safeproduct.service.*;
import com.hnac.hzims.safeproduct.vo.CarMilesYearVO;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Query;
@ -55,6 +51,12 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
@Autowired
ICarCheckRecordService carCheckRecordService;
@Autowired
ICarInsuranceService carInsuranceService;
@Autowired
ICarAnnualInspectionService carAnnualInspectionService;
/**
* 年度里程数页面
*/
@ -195,15 +197,29 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
// 删除关联维保记录
boolean removeCarMaintenance = carMaintenanceService.removeRelativeCarMaintenance(id);
if (!removeCarMaintenance) {
return false;
throw new ServiceException("关联维保记录删除失败");
}
// 删除关联用车记录
boolean removeCarUsedRecord = carUsedRecordService.removeRelativeCarUsedRecord(id);
if (!removeCarUsedRecord) {
return false;
throw new ServiceException("关联用车记录删除失败");
}
// 删除关联车检记录
return carCheckRecordService.removeRelativeCarCheckRecord(id);
boolean removeCarCheckRecord = carCheckRecordService.removeRelativeCarCheckRecord(id);
if (!removeCarCheckRecord) {
throw new ServiceException("关联车检记录删除失败");
}
// 删除关联年检记录
boolean removeCarAnnualInspection = carAnnualInspectionService.removeRelativeCarAnnualInspection(id);
if (!removeCarAnnualInspection) {
throw new ServiceException("关联年检记录删除失败");
}
// 删除关联车保记录
boolean removeCarInsurance = carInsuranceService.removeRelativeCarInsurance(id);
if (!removeCarInsurance) {
throw new ServiceException("关联车保记录删除失败");
}
return true;
}
return false;
}

Loading…
Cancel
Save