From 0683b116ec62b4dff8570dba196b0ad749581a8a Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期二, 18 二月 2025 09:57:58 +0800
Subject: [PATCH] jtt808初始化

---
 server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java |   82 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 79 insertions(+), 3 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java b/server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java
index d9e52f8..8cc0ddf 100644
--- a/server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java
+++ b/server/services/src/main/java/com/doumee/service/business/impl/BikesServiceImpl.java
@@ -2,9 +2,14 @@
 
 import com.doumee.biz.system.SystemDictDataBiz;
 import com.doumee.core.constants.Constants;
+import com.doumee.core.constants.ResponseStatus;
+import com.doumee.core.exception.BusinessException;
+import com.doumee.core.model.LoginUserInfo;
 import com.doumee.core.model.PageData;
 import com.doumee.core.model.PageWrap;
+import com.doumee.core.utils.StringTools;
 import com.doumee.core.utils.Utils;
+import com.doumee.dao.business.BaseParamMapper;
 import com.doumee.dao.business.BikesMapper;
 import com.doumee.dao.business.join.BikesJoinMapper;
 import com.doumee.dao.business.model.*;
@@ -19,15 +24,15 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.doumee.service.system.SystemDictDataService;
+import com.github.xiaoymin.knife4j.core.util.StrUtil;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.shiro.SecurityUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -41,6 +46,8 @@
     @Autowired
     private BikesMapper bikesMapper;
     @Autowired
+    private BaseParamMapper baseParamMapper;
+    @Autowired
     private BikesJoinMapper bikesJoinMapper;
 
 
@@ -49,6 +56,33 @@
 
     @Override
     public String create(Bikes bikes) {
+        if(StringUtils.isBlank(bikes.getParamId() )
+                ||StringUtils.isBlank(bikes.getCode())
+                ||StringUtils.isBlank(bikes.getDeviceSn())){
+            throw  new BusinessException(ResponseStatus.BAD_REQUEST);
+        }
+        if(baseParamMapper.selectCount(new QueryWrapper<BaseParam>().lambda().eq(BaseParam::getIsdeleted,Constants.ZERO)
+                .eq(BaseParam::getType,Constants.FOUR)) ==0){
+            throw   new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇烽�夋嫨姝g‘鐨勭數杞︾被鍨嬶紒");
+        }
+        QueryWrapper<Bikes> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(Bikes::getCode,bikes.getCode())
+                .eq(Bikes::getIsdeleted,Constants.ZERO)
+                .eq(Bikes::getType,Constants.ONE);
+        Integer count = bikesMapper.selectCount(wrapper);
+        if (count > 0){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"杞︾墝鍙峰彿宸插瓨鍦�");
+        }
+        LoginUserInfo user =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        bikes.setId(UUID.randomUUID().toString());
+        bikes.setCreateDate(new Date());
+        bikes.setCreator(user.getId());
+        bikes.setEditDate(bikes.getCreateDate());
+        bikes.setEditor(user.getId());
+        bikes.setStatus(Constants.ZERO);
+        bikes.setIsdeleted(Constants.ZERO);
+        bikes.setType(Constants.ONE);//鍙兘鏂板鐢佃溅鏁版嵁
         bikesMapper.insert(bikes);
         return bikes.getId();
     }
@@ -74,6 +108,27 @@
 
     @Override
     public void updateById(Bikes bikes) {
+        QueryWrapper<Bikes> wrapper = new QueryWrapper<>();
+        wrapper.lambda()
+                .eq(Bikes::getCode,bikes.getCode())
+                .eq(Bikes::getIsdeleted,Constants.ZERO)
+                .ne(Bikes::getId,bikes.getId())
+                .eq(Bikes::getType,Constants.ONE);
+        Integer count = bikesMapper.selectCount(wrapper);
+        if (count > 0){
+            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"杞︾墝鍙峰彿宸插瓨鍦�");
+        }
+        if(StringUtils.isNotBlank(bikes.getParamId()) &&
+                baseParamMapper.selectCount(new QueryWrapper<BaseParam>().lambda().eq(BaseParam::getIsdeleted,Constants.ZERO)
+                .eq(BaseParam::getType,Constants.FOUR)) ==0){
+            throw   new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"瀵逛笉璧凤紝璇烽�夋嫨姝g‘鐨勭數杞︾被鍨嬶紒");
+        }
+        LoginUserInfo user =(LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
+        bikes.setEditDate(new Date());
+        bikes.setEditor(user.getId());
+        bikes.setStatus(Constants.ZERO);
+        bikes.setIsdeleted(Constants.ZERO);
+        bikes.setType(null);//鍙兘鏂板鐢佃溅鏁版嵁
         bikesMapper.updateById(bikes);
     }
 
@@ -91,6 +146,27 @@
     public Bikes findById(String id) {
         return bikesMapper.selectById(id);
     }
+    @Override
+    public  void updateByJtt( Bikes m){
+        if(StringUtils.isBlank(m.getDeviceSn() )){
+            return;
+        }
+        String tSn = StringTools.leftPad(m.getDeviceSn(),12,'0') ;
+        Bikes bikes = bikesJoinMapper.selectOne(new QueryWrapper<Bikes>().lambda()
+                        .eq(Bikes::getDeviceSn,tSn)
+                        .eq(Bikes::getIsdeleted,Constants.ZERO)
+                        .eq(Bikes::getType,Constants.ONE)
+                        .last("limit 1"));
+        if(bikes == null){
+            return;
+        }
+        bikesJoinMapper.update(null,new UpdateWrapper<Bikes>().lambda()
+                 .set(m.getLatitude()!=null,Bikes::getLatitude,m.getLatitude())
+                 .set(m.getVoltage()!=null,Bikes::getVoltage,m.getVoltage())
+                 .set(m.getLongitude()!=null,Bikes::getLongitude,m.getLongitude())
+                 .set(m.getHeartDate()!=null,Bikes::getHeartDate,m.getHeartDate())
+                .eq(Bikes::getId,bikes.getId()));
+    }
 
     @Override
     public Bikes findOne(Bikes bikes) {

--
Gitblit v1.9.3