80 lines
2.3 KiB
Java
80 lines
2.3 KiB
Java
package com.muyu.service.impl;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.muyu.domain.Vehicle;
|
|
import com.muyu.mapper.VehicleMapper;
|
|
import com.muyu.service.VehicleInstanceService;
|
|
import com.muyu.service.VehicleService;
|
|
import com.muyu.utils.VehicleUtils;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
import java.util.stream.Stream;
|
|
|
|
/**
|
|
* <p>
|
|
* 车辆 服务实现类
|
|
* </p>
|
|
*
|
|
* @author DongZeLiang
|
|
* @since 2022-07-05
|
|
*/
|
|
@Log4j2
|
|
@Service
|
|
public class VechileServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> implements VehicleService {
|
|
|
|
|
|
@Autowired
|
|
private VehicleInstanceService vehicleInstanceService;
|
|
|
|
/**
|
|
* 根据数量生成测试车辆
|
|
*
|
|
* @param sum 数量
|
|
*/
|
|
@Override
|
|
@Transactional
|
|
public void generate(Integer sum) {
|
|
List<Vehicle> vehicleList = Stream.generate(Vehicle::gen).limit(sum).toList();
|
|
this.saveBatch(vehicleList);
|
|
vehicleList.forEach(vehicleInstanceService::init);
|
|
}
|
|
|
|
/**
|
|
* 创建IVN
|
|
*
|
|
* @param vinStr VIN
|
|
*/
|
|
@Override
|
|
@Transactional
|
|
public void create (String vinStr) {
|
|
String[] vinList = vinStr.split("\n");
|
|
StringBuilder errorMsg = new StringBuilder();
|
|
for (String vin : vinList) {
|
|
if (vin.length() != 17){
|
|
errorMsg.append("vin[").append(vin).append("]").append("不为17位\n");
|
|
}else {
|
|
LambdaQueryWrapper<Vehicle> queryWrapper = new LambdaQueryWrapper<>();
|
|
queryWrapper.eq(Vehicle::getVin, vin);
|
|
long count = this.count(queryWrapper);
|
|
if (count == 1){
|
|
errorMsg.append("vin[").append(vin).append("]").append("已经存在\n");
|
|
}
|
|
}
|
|
}
|
|
if (errorMsg.length() != 0){
|
|
throw new RuntimeException(errorMsg.toString());
|
|
}
|
|
List<Vehicle> vehicleList = Arrays.stream(vinList).map(Vehicle::create).toList();
|
|
this.saveBatch(vehicleList);
|
|
vehicleList.forEach(vehicleInstanceService::init);
|
|
}
|
|
|
|
|
|
}
|