Browse Source

update: 车辆管理模块

zhongwei
liwen 11 months ago
parent
commit
46463b4ad0
  1. 8
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/controller/CarController.java
  2. 4
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMaintenanceMapper.xml
  3. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml
  4. 2
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarUsedRecordMapper.xml
  5. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarCheckRecordService.java
  6. 14
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarMaintenanceService.java
  7. 22
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java
  8. 7
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarUsedRecordService.java
  9. 24
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java
  10. 29
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java
  11. 73
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarServiceImpl.java
  12. 17
      hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarUsedRecordServiceImpl.java

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

@ -53,21 +53,21 @@ public class CarController extends BladeController {
@ApiOperation(value = "新增车辆")
@ApiOperationSupport(order = 1)
public R saveCar(@Valid @RequestBody CarEntity carEntity) {
return R.status(carService.save(carEntity));
return carService.saveCar(carEntity);
}
@PostMapping("/updateCar")
@ApiOperation(value = "修改车辆")
@ApiOperationSupport(order = 2)
public R updateCar(@Valid @RequestBody CarEntity carEntity) {
return R.status(carService.updateById(carEntity));
return carService.updateCar(carEntity);
}
@PostMapping("/removeCar")
@ApiOperation(value = "删除车辆")
@ApiOperationSupport(order = 3)
public R removeCar(@RequestParam Long id) {
return R.status(carService.removeById(id));
return R.status(carService.removeCar(id));
}
@GetMapping("/carDetail")
@ -101,7 +101,7 @@ public class CarController extends BladeController {
@ApiOperation(value = "修改车辆维保记录")
@ApiOperationSupport(order = 7)
public R updateCarMaintenance(@Valid @RequestBody CarMaintenanceEntity carMaintenanceEntity) {
return R.status(carMaintenanceService.updateById(carMaintenanceEntity));
return carMaintenanceService.updateCarMaintenance(carMaintenanceEntity);
}
@PostMapping("/removeCarMaintenance")

4
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMaintenanceMapper.xml

@ -26,13 +26,13 @@
WHERE
t1.is_deleted = 0
<if test="param.unit != null and param.unit != ''">
AND t2.unit = #{param.unit}
AND t2.unit like concat('%', #{param.unit}, '%')
</if>
<if test="param.startTime != null and param.startTime != ''">
AND t1.start_time >= #{param.startTime}
</if>
<if test="param.endTime != null and param.endTime != ''">
AND t1.end_time &lt; #{param.endTime}
AND t1.end_time &lt;= #{param.endTime}
</if>
<if test="param.carId != null and param.carId != ''">
AND t1.car_id = #{param.carId}

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarMapper.xml

@ -4,7 +4,7 @@
<select id="selectCarByYear" resultType="com.hnac.hzims.safeproduct.vo.CarMilesYearVO">
SELECT
t1.unit, t1.car_brand, t1.plate_number
DISTINCT t1.unit, t1.car_brand, t1.plate_number
FROM
hzims_car t1
LEFT JOIN hzims_car_used_record t2 ON t1.id = t2.car_id

2
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/mapper/CarUsedRecordMapper.xml

@ -26,7 +26,7 @@
WHERE
t1.is_deleted = 0
<if test="param.unit != null and param.unit != ''">
AND t1.unit = #{param.unit}
AND t1.unit like concat('%', #{param.unit}, '%')
</if>
<if test="param.carId != null and param.carId != ''">
AND t1.car_id = #{param.carId}

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

@ -68,4 +68,11 @@ public interface ICarCheckRecordService extends IService<CarCheckRecordEntity> {
* @param response 响应类
*/
void exportCarCheckRecordData(Long id, HttpServletResponse response);
/**
* 删除关联车检记录
* @param carId 车辆id
* @return true-成功false-失败
*/
boolean removeRelativeCarCheckRecord(Long carId);
}

14
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarMaintenanceService.java

@ -65,4 +65,18 @@ public interface ICarMaintenanceService extends IService<CarMaintenanceEntity> {
* @return 车辆维保记录列表
*/
List<CarMaintenanceEntity> getCarMaintenanceByCarIdAndTime(Long carId, String lastTime, String nextTime);
/**
* 更新车辆维保记录
* @param carMaintenanceEntity 车辆维保记录实体类
* @return 结果封装类
*/
R updateCarMaintenance(CarMaintenanceEntity carMaintenanceEntity);
/**
* 删除关联车辆维保记录
* @param carId 车辆id
* @return true-成功false-失败
*/
boolean removeRelativeCarMaintenance(Long carId);
}

22
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/ICarService.java

@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.hnac.hzims.safeproduct.entity.CarEntity;
import com.hnac.hzims.safeproduct.vo.CarMilesYearVO;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import java.util.List;
@ -40,4 +41,25 @@ public interface ICarService extends IService<CarEntity> {
* @return 车辆列表数据
*/
List<CarEntity> getCarListByMaintenanceTime(String today, String yesterday);
/**
* 新增车辆
* @param carEntity 车辆实体类
* @return 结果封装类
*/
R saveCar(CarEntity carEntity);
/**
* 更新车辆
* @param carEntity 车辆实体类
* @return 结果封装类
*/
R updateCar(CarEntity carEntity);
/**
* 删除车辆
* @param id 车辆id
* @return true-成功false-失败
*/
boolean removeCar(Long id);
}

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

@ -62,4 +62,11 @@ public interface ICarUsedRecordService extends IService<CarUsedRecordEntity> {
* @param response 响应类
*/
void exportCarUsedRecordData(Long id, HttpServletResponse response);
/**
* 删除关联用车记录
* @param carId 车辆id
* @return true-成功false-失败
*/
boolean removeRelativeCarUsedRecord(Long carId);
}

24
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarCheckRecordServiceImpl.java

@ -30,6 +30,7 @@ import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车检记录服务实现类
@ -193,4 +194,27 @@ public class CarCheckRecordServiceImpl extends ServiceImpl<CarCheckRecordMapper,
String pdfPath = savePath + "/车检记录单.pdf";
BaseUtil.exportDocument(templateFile, params, wordPath, pdfPath, response);
}
/**
* 删除关联车检记录
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean removeRelativeCarCheckRecord(Long carId) {
QueryWrapper<CarCheckRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarCheckRecordEntity::getCarId, carId);
List<CarCheckRecordEntity> list = this.list(queryWrapper);
// 若无关联车检记录,返回true
if (CollectionUtils.isEmpty(list)) {
return true;
}
List<Long> ids = list.stream().map(CarCheckRecordEntity::getId).collect(Collectors.toList());
for (Long id : ids) {
boolean removeCarCheckRecord = removeCarCheckRecord(id);
if (!removeCarCheckRecord) {
return false;
}
}
return true;
}
}

29
hzims-service/safeproduct/src/main/java/com/hnac/hzims/safeproduct/service/impl/CarMaintenanceServiceImpl.java

@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 车辆维保记录服务实现类
@ -133,6 +134,34 @@ public class CarMaintenanceServiceImpl extends ServiceImpl<CarMaintenanceMapper,
}
/**
* 更新车辆维保记录
*/
@Override
public R updateCarMaintenance(CarMaintenanceEntity carMaintenanceEntity) {
String maintenanceStatus = carMaintenanceEntity.getMaintenanceStatus();
if (maintenanceStatus.equals(CarMaintenanceStatusEnum.MAINTAINED.getValue())) {
return R.fail("已确认的维保记录无法被修改");
}
return R.status(this.updateById(carMaintenanceEntity));
}
/**
* 删除关联车辆维保记录
*/
@Override
public boolean removeRelativeCarMaintenance(Long carId) {
QueryWrapper<CarMaintenanceEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarMaintenanceEntity::getCarId, carId);
List<CarMaintenanceEntity> list = this.list(queryWrapper);
// 若无关联车辆维保记录,返回true
if (CollectionUtils.isEmpty(list)) {
return true;
}
List<Long> ids = list.stream().map(CarMaintenanceEntity::getId).collect(Collectors.toList());
return this.removeByIds(ids);
}
/**
* 查询是否存在同月编号
* @param currentMonth 当月
* @return 存在则返回上一编号否则返回null

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

@ -7,10 +7,16 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnac.hzims.safeproduct.dto.CarMilesYearDTO;
import com.hnac.hzims.safeproduct.entity.CarEntity;
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.vo.CarMilesYearVO;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
@ -27,6 +33,15 @@ import java.util.stream.Collectors;
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements ICarService {
@Autowired
ICarMaintenanceService carMaintenanceService;
@Autowired
ICarUsedRecordService carUsedRecordService;
@Autowired
ICarCheckRecordService carCheckRecordService;
/**
* 年度里程数页面
*/
@ -100,8 +115,9 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
res.add(carMilesYearVO);
}
});
carPage.setRecords(res);
return carPage;
page.setRecords(res);
page.setTotal(res.size());
return page;
}
/**
@ -125,4 +141,57 @@ public class CarServiceImpl extends ServiceImpl<CarMapper, CarEntity> implements
.ge(CarEntity::getMaintenanceNextTime, yesterday);
return this.list(queryWrapper);
}
/**
* 新增车辆
*/
@Override
public R saveCar(CarEntity carEntity) {
QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarEntity::getPlateNumber, carEntity.getPlateNumber());
CarEntity car = this.getOne(queryWrapper);
if (car == null) {
return R.status(this.save(carEntity));
}
return R.fail("车牌号已存在");
}
/**
* 更新车辆
*/
@Override
public R updateCar(CarEntity carEntity) {
QueryWrapper<CarEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarEntity::getPlateNumber, carEntity.getPlateNumber())
.ne(CarEntity::getId, carEntity.getId());
CarEntity car = this.getOne(queryWrapper);
if (car == null) {
return R.status(this.updateById(carEntity));
}
return R.fail("车牌号已存在");
}
/**
* 删除车辆
*/
@Transactional(rollbackFor = Exception.class)
@Override
public boolean removeCar(Long id) {
boolean remove = this.removeById(id);
if (remove) {
// 删除关联维保记录
boolean removeCarMaintenance = carMaintenanceService.removeRelativeCarMaintenance(id);
if (!removeCarMaintenance) {
return false;
}
// 删除关联用车记录
boolean removeCarUsedRecord = carUsedRecordService.removeRelativeCarUsedRecord(id);
if (!removeCarUsedRecord) {
return false;
}
// 删除关联车检记录
return carCheckRecordService.removeRelativeCarCheckRecord(id);
}
return false;
}
}

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

@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 用车记录服务实现类
@ -119,6 +120,22 @@ public class CarUsedRecordServiceImpl extends ServiceImpl<CarUsedRecordMapper, C
}
/**
* 删除关联用车记录
*/
@Override
public boolean removeRelativeCarUsedRecord(Long carId) {
QueryWrapper<CarUsedRecordEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(CarUsedRecordEntity::getCarId, carId);
List<CarUsedRecordEntity> list = this.list(queryWrapper);
// 若无关联用车记录,返回true
if (CollectionUtils.isEmpty(list)) {
return true;
}
List<Long> ids = list.stream().map(CarUsedRecordEntity::getId).collect(Collectors.toList());
return this.removeByIds(ids);
}
/**
* 查询是否存在同月编号
* @param currentMonth 当月
* @return 存在则返回上一编号否则返回null

Loading…
Cancel
Save