From dff5c1cb8ca04058d331179aa1b1df969d5803d4 Mon Sep 17 00:00:00 2001 From: SjS Date: Wed, 16 Apr 2025 17:36:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9E=8B=E5=8F=B7=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/AsDeviceServiceImpl.java | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java index d3841f2..719af22 100644 --- a/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java +++ b/AutoSprout-watering/src/main/java/com/ruoyi/device/service/impl/AsDeviceServiceImpl.java @@ -39,6 +39,7 @@ import java.io.UnsupportedEncodingException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.Objects; import java.util.regex.Matcher; @@ -280,14 +281,14 @@ public class AsDeviceServiceImpl extends ServiceImpl i public int insertAsDevice(AsDevice asDevice) { asDevice.setCreateTime(DateUtils.getNowDate()); - AsDevice device = setValue(asDevice); + AsDevice device = setDeviceValue(asDevice); AsDevice vo = asDeviceMapper.selectAsDeviceByMac(asDevice.getMac()); ServiceUtil.assertion(vo!=null,"该设备已存在,不允许重复!"); return asDeviceMapper.insertAsDevice(device); } - public AsDevice setValue(AsDevice asDevice){ + public AsDevice setDeviceValue(AsDevice asDevice){ // 前缀校验 AsModel asModel = new AsModel(); asModel.setPre(asDevice.getPre()); @@ -506,34 +507,18 @@ public class AsDeviceServiceImpl extends ServiceImpl i */ @Override public Boolean bandDevice(AsDevice asDevice) { - AsDevice device = asDeviceMapper.selectAsDeviceByMac(asDevice.getMac()); - /* 根据mac号获取到设备详情*/ - Boolean execute = transactionTemplate.execute(e -> { - if(ObjectUtils.isEmpty(device)){ - asDevice.setDeviceName(defaultName); - int i = bandSn(asDevice); - ServiceUtil.assertion(i == 0, "录入失败!"); - }else{ - if(ObjectUtils.isNotEmpty(device.getUserId()) && device.getUserId()>0){ - throw new ServiceException("该设备已经绑定用户,请先解绑!"); - } - device.setUserId(asDevice.getUserId()); - AsUser asUser = asUserService.selectUserById(asDevice.getUserId()); - ServiceUtil.assertion(ObjectUtils.isEmpty(asUser), "用户不存在!"); - device.setUserName(asUser.getUserName()); - device.setBluetoothId(asDevice.getBluetoothId()); - device.setBluetoothName(asDevice.getBluetoothName()); - device.setPre(asDevice.getPre()); - int i = asDeviceMapper.updateAsDevice(device); - ServiceUtil.assertion(i == 0, "绑定失败!"); - + int i = asDeviceMapper.insertAsDevice(asDevice); + ServiceUtil.assertion(i == 0, "绑定失败!"); +// Boolean execute = transactionTemplate.execute(e -> { +// asDevice.setDeviceName(defaultName); +// int i = bandSn(asDevice); +// ServiceUtil.assertion(i == 0, "录入失败!"); +// setDeviceValue(asDevice); // 切换默认设备 - toggleDevice(asDevice.getUserId(), device.getDeviceId()); - } - logger.info("=================【绑定设备】成功=================="); - return Boolean.TRUE; - }); - if(Boolean.FALSE.equals(execute))throw new ServiceException("绑定失败"); + // toggleDevice(asDevice.getUserId(), asDevice.getDeviceId()); +// return Boolean.TRUE; +// }); +// if(Boolean.FALSE.equals(execute))throw new ServiceException("绑定失败"); return true; } @@ -694,10 +679,6 @@ public class AsDeviceServiceImpl extends ServiceImpl i { throw new ServiceException(code+"-----"+ paramsObj.getString("msg")); } - int insert = asDeviceMapper.insert(asDevice); - if(insert==0){ - throw new ServiceException("录入失败,插入数据失败!"); - } } return 1; }