|
|
@@ -0,0 +1,72 @@
|
|
|
+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.fnc.entity.InsPlySettleHx;
|
|
|
+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 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) {
|
|
|
+ QueryWrapper<SerCarInfo> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("licenseno", serCarInfo.getLicenseNo());
|
|
|
+ boolean exist = serCarInfoMapper.exists(queryWrapper);
|
|
|
+ if (exist) {
|
|
|
+ return HttpResult.error("该车已被人注册");
|
|
|
+ }
|
|
|
+ SysUser user = BaseController.getUser();
|
|
|
+ serCarInfo.setId(IdGenerate.nextId());
|
|
|
+ serCarInfo.setUserId(user.getId());
|
|
|
+ LocalDateTime date = LocalDateTime.now();
|
|
|
+ serCarInfo.setCreateTime(date);
|
|
|
+ serCarInfoMapper.insert(serCarInfo);
|
|
|
+ return HttpResult.ok("新增成功", serCarInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpResult updateCarInfo(SerCarInfo serCarInfo) {
|
|
|
+ // 校验年检到期时间不可早于注册时间
|
|
|
+ Instant registerInstant = serCarInfo.getRegisterTime().toInstant();
|
|
|
+ Instant expireInstant = serCarInfo.getExpireTime().toInstant();
|
|
|
+ if (expireInstant.isBefore(registerInstant)) {
|
|
|
+ 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) {
|
|
|
+ serCarInfo.setOverdueTime("0");
|
|
|
+ } else {
|
|
|
+ serCarInfo.setOverdueTime(String.valueOf(days));
|
|
|
+ }
|
|
|
+ serCarInfoMapper.updateById(serCarInfo);
|
|
|
+ return HttpResult.ok("编辑成功", serCarInfo);
|
|
|
+ }
|
|
|
+}
|