|
@@ -9,6 +9,7 @@ import com.ydtech.modules.ser.dao.SerCarInfoMapper;
|
|
|
import com.ydtech.modules.ser.model.SerCarInfo;
|
|
import com.ydtech.modules.ser.model.SerCarInfo;
|
|
|
import com.ydtech.modules.ser.service.SerCarInfoService;
|
|
import com.ydtech.modules.ser.service.SerCarInfoService;
|
|
|
import com.ydtech.utils.idgen.IdGenerate;
|
|
import com.ydtech.utils.idgen.IdGenerate;
|
|
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import java.time.*;
|
|
import java.time.*;
|
|
@@ -30,43 +31,83 @@ public class SerCarInfoServiceImpl implements SerCarInfoService {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public HttpResult addCarInfo(SerCarInfo serCarInfo) {
|
|
public HttpResult addCarInfo(SerCarInfo serCarInfo) {
|
|
|
|
|
+ // 设置id、userId、createdTime
|
|
|
|
|
+ SysUser user = BaseController.getUser();
|
|
|
|
|
+ serCarInfo.setId(IdGenerate.nextId());
|
|
|
|
|
+ serCarInfo.setUserId(user.getId());
|
|
|
|
|
+ LocalDateTime currentTime = LocalDateTime.now();
|
|
|
|
|
+ serCarInfo.setCreateTime(currentTime);
|
|
|
|
|
+
|
|
|
|
|
+ //查询车辆是否重复
|
|
|
QueryWrapper<SerCarInfo> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<SerCarInfo> queryWrapper = new QueryWrapper<>();
|
|
|
queryWrapper.eq("licenseno", serCarInfo.getLicenseNo());
|
|
queryWrapper.eq("licenseno", serCarInfo.getLicenseNo());
|
|
|
boolean exist = serCarInfoMapper.exists(queryWrapper);
|
|
boolean exist = serCarInfoMapper.exists(queryWrapper);
|
|
|
if (exist) {
|
|
if (exist) {
|
|
|
return HttpResult.error("该车已被其他用户添加,请检查");
|
|
return HttpResult.error("该车已被其他用户添加,请检查");
|
|
|
}
|
|
}
|
|
|
- SysUser user = BaseController.getUser();
|
|
|
|
|
- serCarInfo.setId(IdGenerate.nextId());
|
|
|
|
|
- serCarInfo.setUserId(user.getId());
|
|
|
|
|
- LocalDateTime date = LocalDateTime.now();
|
|
|
|
|
- serCarInfo.setCreateTime(date);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 校验年检到期时间不可早于注册时间
|
|
|
|
|
+ if (serCarInfo.getRegisterTime() == null && serCarInfo.getExpireTime() == null) {
|
|
|
|
|
+ return HttpResult.error("注册时间与到期时间不可为空");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Instant registerInstant = serCarInfo.getRegisterTime().toInstant();
|
|
|
|
|
+ Instant expireInstant = serCarInfo.getExpireTime().toInstant();
|
|
|
|
|
+ Instant nowInstant = new Date().toInstant();
|
|
|
|
|
+ if (expireInstant.isBefore(registerInstant)) {
|
|
|
|
|
+ return HttpResult.error("年检到期时间不可早于注册时间");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 计算逾期时间 距离时间
|
|
|
|
|
+ if (expireInstant.equals(nowInstant)) {
|
|
|
|
|
+ serCarInfo.setOverdueTime("0");
|
|
|
|
|
+ serCarInfo.setDistanceTime("0");
|
|
|
|
|
+ } else if (expireInstant.isBefore(nowInstant)) {
|
|
|
|
|
+ Duration duration = Duration.between(expireInstant, nowInstant);
|
|
|
|
|
+ serCarInfo.setOverdueTime(String.valueOf(duration.toDays()));
|
|
|
|
|
+ serCarInfo.setDistanceTime("0");
|
|
|
|
|
+ } else if (nowInstant.isBefore(expireInstant)) {
|
|
|
|
|
+ Duration duration = Duration.between(nowInstant, expireInstant);
|
|
|
|
|
+ serCarInfo.setOverdueTime("0");
|
|
|
|
|
+ serCarInfo.setDistanceTime(String.valueOf(duration.toDays()));
|
|
|
|
|
+ }
|
|
|
serCarInfoMapper.insert(serCarInfo);
|
|
serCarInfoMapper.insert(serCarInfo);
|
|
|
return HttpResult.ok("新增车辆信息成功", serCarInfo);
|
|
return HttpResult.ok("新增车辆信息成功", serCarInfo);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public HttpResult updateCarInfo(SerCarInfo serCarInfo) {
|
|
public HttpResult updateCarInfo(SerCarInfo serCarInfo) {
|
|
|
|
|
+ //查询车辆是否重复
|
|
|
|
|
+ QueryWrapper<SerCarInfo> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ queryWrapper.eq("licenseno", serCarInfo.getLicenseNo());
|
|
|
|
|
+ queryWrapper.ne("userid", BaseController.getUser().getId());
|
|
|
|
|
+ boolean exist = serCarInfoMapper.exists(queryWrapper);
|
|
|
|
|
+ if (exist) {
|
|
|
|
|
+ return HttpResult.error("该车已被其他用户添加,请检查");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// 校验年检到期时间不可早于注册时间
|
|
// 校验年检到期时间不可早于注册时间
|
|
|
if (serCarInfo.getRegisterTime() == null && serCarInfo.getExpireTime() == null) {
|
|
if (serCarInfo.getRegisterTime() == null && serCarInfo.getExpireTime() == null) {
|
|
|
return HttpResult.error("注册时间与到期时间不可为空");
|
|
return HttpResult.error("注册时间与到期时间不可为空");
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
Instant registerInstant = serCarInfo.getRegisterTime().toInstant();
|
|
Instant registerInstant = serCarInfo.getRegisterTime().toInstant();
|
|
|
Instant expireInstant = serCarInfo.getExpireTime().toInstant();
|
|
Instant expireInstant = serCarInfo.getExpireTime().toInstant();
|
|
|
|
|
+ Instant nowInstant = new Date().toInstant();
|
|
|
if (expireInstant.isBefore(registerInstant)) {
|
|
if (expireInstant.isBefore(registerInstant)) {
|
|
|
return HttpResult.error("年检到期时间不可早于注册时间");
|
|
return HttpResult.error("年检到期时间不可早于注册时间");
|
|
|
}
|
|
}
|
|
|
- serCarInfo.setExpireTime(serCarInfo.getExpireTime());
|
|
|
|
|
- // 计算逾期时间
|
|
|
|
|
- Date expireDate = serCarInfo.getExpireTime();
|
|
|
|
|
- LocalDateTime expireTime = expireDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
|
|
- LocalDateTime currentTime = LocalDateTime.now();
|
|
|
|
|
- Duration duration = Duration.between(expireTime, currentTime);
|
|
|
|
|
- long days = duration.toDays();
|
|
|
|
|
- if (days <= 0 ) {
|
|
|
|
|
|
|
+ // 计算逾期时间 距离时间
|
|
|
|
|
+ if (expireInstant.equals(nowInstant)) {
|
|
|
|
|
+ serCarInfo.setOverdueTime("0");
|
|
|
|
|
+ serCarInfo.setDistanceTime("0");
|
|
|
|
|
+ } else if (expireInstant.isBefore(nowInstant)) {
|
|
|
|
|
+ Duration duration = Duration.between(expireInstant, nowInstant);
|
|
|
|
|
+ serCarInfo.setOverdueTime(String.valueOf(duration.toDays()));
|
|
|
|
|
+ serCarInfo.setDistanceTime("0");
|
|
|
|
|
+ } else if (nowInstant.isBefore(expireInstant)) {
|
|
|
|
|
+ Duration duration = Duration.between(nowInstant, expireInstant);
|
|
|
serCarInfo.setOverdueTime("0");
|
|
serCarInfo.setOverdueTime("0");
|
|
|
- } else {
|
|
|
|
|
- serCarInfo.setOverdueTime(String.valueOf(days));
|
|
|
|
|
|
|
+ serCarInfo.setDistanceTime(String.valueOf(duration.toDays()));
|
|
|
}
|
|
}
|
|
|
serCarInfoMapper.updateById(serCarInfo);
|
|
serCarInfoMapper.updateById(serCarInfo);
|
|
|
return HttpResult.ok("编辑成功", serCarInfo);
|
|
return HttpResult.ok("编辑成功", serCarInfo);
|