| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- package com.ydtech.modules.ser.service.impl;
- import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.modules.admin.model.SysUser;
- import com.ydtech.modules.base.controller.BaseController;
- import com.ydtech.modules.ser.dao.SerCarInfoMapper;
- import com.ydtech.modules.ser.model.SerCarInfo;
- import com.ydtech.modules.ser.service.SerCarInfoService;
- import com.ydtech.utils.idgen.IdGenerate;
- import io.swagger.models.auth.In;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.time.*;
- import java.util.Date;
- import java.util.List;
- @Service
- public class SerCarInfoServiceImpl implements SerCarInfoService {
- @Autowired
- SerCarInfoMapper serCarInfoMapper;
- @Override
- public HttpResult queryCarInfoByUserId() {
- LambdaQueryWrapper<SerCarInfo> queryWrapper = new LambdaQueryWrapper();
- SysUser user = BaseController.getUser();
- queryWrapper.eq(SerCarInfo::getUserId,user.getId());
- List<SerCarInfo> list= serCarInfoMapper.selectList(queryWrapper);
- return HttpResult.ok(list);
- }
- @Override
- 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.eq("licenseno", serCarInfo.getLicenseNo());
- boolean exist = serCarInfoMapper.exists(queryWrapper);
- if (exist) {
- return HttpResult.error("该车已被其他用户添加,请检查");
- }
- // 校验年检到期时间不可早于注册时间
- 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);
- return HttpResult.ok("新增车辆信息成功", serCarInfo);
- }
- @Override
- 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) {
- 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.updateById(serCarInfo);
- return HttpResult.ok("编辑成功", serCarInfo);
- }
- }
|